use of org.wso2.carbon.identity.workflow.mgt.dto.WorkflowRequest in project carbon-identity-framework by wso2.
the class WorkflowRequestDAO method retrieveWorkflow.
/**
* Retrieve workflow request specified by the given uuid
*
* @param uuid The uuid of the request to be retrieved
* @return
* @throws WorkflowException
*/
public WorkflowRequest retrieveWorkflow(String uuid) throws InternalWorkflowException {
Connection connection = IdentityDatabaseUtil.getDBConnection(false);
PreparedStatement prepStmt = null;
ResultSet rs = null;
String query = SQLConstants.GET_WORKFLOW_REQUEST_QUERY;
try {
prepStmt = connection.prepareStatement(query);
prepStmt.setString(1, uuid);
rs = prepStmt.executeQuery();
if (rs.next()) {
byte[] requestBytes = rs.getBytes(SQLConstants.REQUEST_COLUMN);
return deserializeWorkflowRequest(requestBytes);
}
} catch (SQLException e) {
throw new InternalWorkflowException("Error when executing the sql query:" + query, e);
} catch (ClassNotFoundException | IOException e) {
throw new InternalWorkflowException("Error when deserializing the workflow request. uuid = " + uuid, e);
} finally {
IdentityDatabaseUtil.closeAllConnections(connection, null, prepStmt);
}
return null;
}
use of org.wso2.carbon.identity.workflow.mgt.dto.WorkflowRequest in project carbon-identity-framework by wso2.
the class WorkflowRequestDAO method deserializeWorkflowRequest.
/**
* Deserialize the persisted Workflow request
*
* @param serializedData Serialized request
* @return
* @throws IOException
* @throws ClassNotFoundException
*/
private WorkflowRequest deserializeWorkflowRequest(byte[] serializedData) throws IOException, ClassNotFoundException {
ByteArrayInputStream bais = new ByteArrayInputStream(serializedData);
ObjectInputStream ois = new ObjectInputStream(bais);
Object objectRead = ois.readObject();
if (objectRead != null && objectRead instanceof WorkflowRequest) {
return (WorkflowRequest) objectRead;
}
return null;
}
use of org.wso2.carbon.identity.workflow.mgt.dto.WorkflowRequest in project carbon-identity-framework by wso2.
the class WorkFlowExecutorManager method handleCallback.
private void handleCallback(WorkflowRequest request, String status, Map<String, Object> additionalParams, String requestWorkflowId) throws WorkflowException {
WorkflowRequestAssociationDAO workflowRequestAssociationDAO = new WorkflowRequestAssociationDAO();
if (request != null) {
WorkflowRequestDAO workflowRequestDAO = new WorkflowRequestDAO();
String requestId = request.getUuid();
workflowRequestAssociationDAO.updateStatusOfRelationship(requestWorkflowId, status);
workflowRequestDAO.updateLastUpdatedTimeOfRequest(requestId);
if (StringUtils.isNotBlank(requestWorkflowId) && WorkflowRequestStatus.DELETED.toString().equals(workflowRequestDAO.retrieveStatusOfWorkflow(request.getUuid()))) {
log.info("Callback received for request " + requestId + " which is already deleted by user. ");
return;
}
if (status.equals(WorkflowRequestStatus.APPROVED.toString()) && !isAllWorkflowsCompleted(workflowRequestAssociationDAO, requestId)) {
return;
}
String eventId = request.getEventType();
WorkflowRequestHandler requestHandler = WorkflowServiceDataHolder.getInstance().getRequestHandler(eventId);
if (requestHandler == null) {
throw new InternalWorkflowException("No request handlers registered for the id: " + eventId);
}
if (request.getTenantId() == MultitenantConstants.INVALID_TENANT_ID) {
throw new InternalWorkflowException("Invalid tenant id for request " + eventId + " with id" + requestId);
}
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
try {
String tenantDomain = WorkflowServiceDataHolder.getInstance().getRealmService().getTenantManager().getDomain(request.getTenantId());
carbonContext.setTenantId(request.getTenantId());
carbonContext.setTenantDomain(tenantDomain);
requestHandler.onWorkflowCompletion(status, request, additionalParams);
updateDBAtWorkflowCompletion(requestId, status);
} catch (WorkflowException e) {
updateDBAtWorkflowCompletion(requestId, WorkflowRequestStatus.FAILED.toString());
throw e;
} catch (UserStoreException e) {
updateDBAtWorkflowCompletion(requestId, WorkflowRequestStatus.FAILED.toString());
throw new InternalWorkflowException("Error when getting tenant domain for tenant id " + request.getTenantId());
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
}
Aggregations