Search in sources :

Example 11 with WorkflowRequest

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;
}
Also used : SQLException(java.sql.SQLException) InternalWorkflowException(org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException)

Example 12 with WorkflowRequest

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;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInputStream(java.io.ObjectInputStream) WorkflowRequest(org.wso2.carbon.identity.workflow.mgt.dto.WorkflowRequest)

Example 13 with WorkflowRequest

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();
        }
    }
}
Also used : WorkflowRequestDAO(org.wso2.carbon.identity.workflow.mgt.dao.WorkflowRequestDAO) InternalWorkflowException(org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException) WorkflowRequestAssociationDAO(org.wso2.carbon.identity.workflow.mgt.dao.WorkflowRequestAssociationDAO) InternalWorkflowException(org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException) WorkflowException(org.wso2.carbon.identity.workflow.mgt.exception.WorkflowException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) WorkflowRequestHandler(org.wso2.carbon.identity.workflow.mgt.extension.WorkflowRequestHandler)

Aggregations

InternalWorkflowException (org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException)5 WorkflowRequest (org.wso2.carbon.identity.workflow.mgt.bean.WorkflowRequest)4 WorkflowRequest (org.wso2.carbon.identity.workflow.mgt.dto.WorkflowRequest)4 WorkflowListener (org.wso2.carbon.identity.workflow.mgt.listener.WorkflowListener)4 RequestParameter (org.wso2.carbon.identity.workflow.mgt.bean.RequestParameter)3 WorkflowRequestAssociationDAO (org.wso2.carbon.identity.workflow.mgt.dao.WorkflowRequestAssociationDAO)3 WorkflowRequestDAO (org.wso2.carbon.identity.workflow.mgt.dao.WorkflowRequestDAO)3 WorkflowException (org.wso2.carbon.identity.workflow.mgt.exception.WorkflowException)3 IOException (java.io.IOException)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2 Timestamp (java.sql.Timestamp)2 HashMap (java.util.HashMap)2 WorkflowExecutorManagerListener (org.wso2.carbon.identity.workflow.mgt.listener.WorkflowExecutorManagerListener)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ResultSet (java.sql.ResultSet)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1