Search in sources :

Example 1 with WorkflowRequest

use of org.wso2.carbon.identity.workflow.mgt.dto.WorkflowRequest in project carbon-identity-framework by wso2.

the class WorkflowRequestBuilder method buildXMLRequest.

/**
 * Create OM Element from workflow request parameters.
 *
 * @param workFlowRequest Workflow parameters
 * @param initParams      Non workflow parameters
 * @return
 * @throws WorkflowRuntimeException
 */
public static OMElement buildXMLRequest(WorkflowRequest workFlowRequest, Map<String, Object> initParams) throws WorkflowRuntimeException {
    WorkflowRequestBuilder requestBuilder = new WorkflowRequestBuilder(workFlowRequest.getUuid(), workFlowRequest.getEventType());
    for (RequestParameter parameter : workFlowRequest.getRequestParameters()) {
        if (parameter.isRequiredInWorkflow()) {
            switch(parameter.getValueType()) {
                case WorkflowDataType.BOOLEAN_TYPE:
                case WorkflowDataType.STRING_TYPE:
                case WorkflowDataType.INTEGER_TYPE:
                case WorkflowDataType.DOUBLE_TYPE:
                    requestBuilder.addSingleValuedParam(parameter.getName(), parameter.getValue());
                    break;
                case WorkflowDataType.STRING_LIST_TYPE:
                case WorkflowDataType.DOUBLE_LIST_TYPE:
                case WorkflowDataType.INTEGER_LIST_TYPE:
                case WorkflowDataType.BOOLEAN_LIST_TYPE:
                    requestBuilder.addListTypeParam(parameter.getName(), (List<Object>) parameter.getValue());
                    break;
                case WorkflowDataType.STRING_STRING_MAP_TYPE:
                    requestBuilder.addMapTypeParam(parameter.getName(), (Map<String, Object>) parameter.getValue());
                    break;
            }
        }
    }
    requestBuilder.setInitParams(initParams);
    return requestBuilder.buildRequest();
}
Also used : RequestParameter(org.wso2.carbon.identity.workflow.mgt.bean.RequestParameter)

Example 2 with WorkflowRequest

use of org.wso2.carbon.identity.workflow.mgt.dto.WorkflowRequest in project carbon-identity-framework by wso2.

the class AbstractWorkflowRequestHandler method startWorkFlow.

/**
 * Start a new workflow.
 *
 * @param wfParams    Parameters related to workflow
 * @param nonWfParams Other parameters
 * @param uuid        Unique ID of request
 * @return
 * @throws WorkflowException
 */
public WorkflowExecutorResult startWorkFlow(Map<String, Object> wfParams, Map<String, Object> nonWfParams, String uuid) throws WorkflowException {
    if (isWorkflowCompleted()) {
        return new WorkflowExecutorResult(ExecutorResultState.COMPLETED);
    }
    if (!isAssociated()) {
        return new WorkflowExecutorResult(ExecutorResultState.NO_ASSOCIATION);
    }
    WorkflowRequest workFlowRequest = new WorkflowRequest();
    List<RequestParameter> parameters = new ArrayList<RequestParameter>(wfParams.size() + nonWfParams.size() + 1);
    for (Map.Entry<String, Object> paramEntry : wfParams.entrySet()) {
        parameters.add(getParameter(paramEntry.getKey(), paramEntry.getValue(), true));
    }
    for (Map.Entry<String, Object> paramEntry : nonWfParams.entrySet()) {
        parameters.add(getParameter(paramEntry.getKey(), paramEntry.getValue(), false));
    }
    RequestParameter uuidParameter = new RequestParameter();
    uuidParameter.setName(WFConstant.REQUEST_ID);
    uuidParameter.setValue(uuid);
    uuidParameter.setRequiredInWorkflow(true);
    uuidParameter.setValueType(WorkflowDataType.STRING_TYPE);
    parameters.add(uuidParameter);
    workFlowRequest.setRequestParameters(parameters);
    workFlowRequest.setTenantId(CarbonContext.getThreadLocalCarbonContext().getTenantId());
    workFlowRequest.setUuid(uuid);
    engageWorkflow(workFlowRequest);
    WorkflowExecutorResult workflowExecutorResult = WorkFlowExecutorManager.getInstance().executeWorkflow(workFlowRequest);
    if (workflowExecutorResult.getExecutorResultState() == ExecutorResultState.FAILED) {
        throw new WorkflowException(workflowExecutorResult.getMessage());
    }
    return workflowExecutorResult;
}
Also used : WorkflowExecutorResult(org.wso2.carbon.identity.workflow.mgt.WorkflowExecutorResult) RequestParameter(org.wso2.carbon.identity.workflow.mgt.bean.RequestParameter) InternalWorkflowException(org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException) WorkflowException(org.wso2.carbon.identity.workflow.mgt.exception.WorkflowException) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) WorkflowRequest(org.wso2.carbon.identity.workflow.mgt.dto.WorkflowRequest)

Example 3 with WorkflowRequest

use of org.wso2.carbon.identity.workflow.mgt.dto.WorkflowRequest in project carbon-identity-framework by wso2.

the class WorkflowManagementServiceImpl method deleteWorkflowRequestCreatedByAnyUser.

/**
 * Move workflow request created by any user to DELETED state.
 *
 * @param requestId Request ID
 * @throws WorkflowException
 */
@Override
public void deleteWorkflowRequestCreatedByAnyUser(String requestId) throws WorkflowException {
    List<WorkflowListener> workflowListenerList = WorkflowServiceDataHolder.getInstance().getWorkflowListenerList();
    WorkflowRequest workflowRequest = new WorkflowRequest();
    workflowRequest.setRequestId(requestId);
    workflowRequest.setCreatedBy(workflowRequestDAO.retrieveCreatedUserOfRequest(requestId));
    for (WorkflowListener workflowListener : workflowListenerList) {
        if (workflowListener.isEnable()) {
            workflowListener.doPreDeleteWorkflowRequest(workflowRequest);
        }
    }
    workflowRequestDAO.updateStatusOfRequest(requestId, WorkflowRequestStatus.DELETED.toString());
    workflowRequestAssociationDAO.updateStatusOfRelationshipsOfPendingRequest(requestId, WFConstant.HT_STATE_SKIPPED);
    requestEntityRelationshipDAO.deleteRelationshipsOfRequest(requestId);
    for (WorkflowListener workflowListener : workflowListenerList) {
        if (workflowListener.isEnable()) {
            workflowListener.doPostDeleteWorkflowRequest(workflowRequest);
        }
    }
}
Also used : WorkflowListener(org.wso2.carbon.identity.workflow.mgt.listener.WorkflowListener) WorkflowRequest(org.wso2.carbon.identity.workflow.mgt.bean.WorkflowRequest)

Example 4 with WorkflowRequest

use of org.wso2.carbon.identity.workflow.mgt.dto.WorkflowRequest in project carbon-identity-framework by wso2.

the class WorkflowManagementServiceImpl method getRequestsFromFilter.

/**
 * get requests list according to createdUser, createdTime, and lastUpdatedTime
 *
 * @param user         User to get requests of, empty String to retrieve requests of all users
 * @param beginDate    lower limit of date range to filter
 * @param endDate      upper limit of date range to filter
 * @param dateCategory filter by created time or last updated time ?
 * @param tenantId     tenant id of currently logged in user
 * @return
 * @throws WorkflowException
 */
@Override
public WorkflowRequest[] getRequestsFromFilter(String user, String beginDate, String endDate, String dateCategory, int tenantId, String status) throws WorkflowException {
    SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT_FOR_FILTERING);
    Timestamp beginTime;
    Timestamp endTime;
    List<WorkflowListener> workflowListenerList = WorkflowServiceDataHolder.getInstance().getWorkflowListenerList();
    for (WorkflowListener workflowListener : workflowListenerList) {
        if (workflowListener.isEnable()) {
            workflowListener.doPreGetRequestsFromFilter(user, beginDate, endDate, dateCategory, tenantId, status);
        }
    }
    try {
        Date parsedBeginDate = dateFormat.parse(beginDate);
        beginTime = new java.sql.Timestamp(parsedBeginDate.getTime());
    } catch (ParseException e) {
        long millis = 0;
        Date parsedBeginDate = new Date(millis);
        beginTime = new java.sql.Timestamp(parsedBeginDate.getTime());
    }
    try {
        Date parsedEndDate = dateFormat.parse(endDate);
        endTime = new java.sql.Timestamp(parsedEndDate.getTime());
    } catch (ParseException e) {
        Date parsedEndDate = new Date();
        endTime = new java.sql.Timestamp(parsedEndDate.getTime());
    }
    WorkflowRequest[] resultList;
    if (StringUtils.isBlank(user)) {
        resultList = workflowRequestDAO.getRequestsFilteredByTime(beginTime, endTime, dateCategory, tenantId, status);
    } else {
        resultList = workflowRequestDAO.getRequestsOfUserFilteredByTime(user, beginTime, endTime, dateCategory, tenantId, status);
    }
    for (WorkflowListener workflowListener : workflowListenerList) {
        if (workflowListener.isEnable()) {
            workflowListener.doPostGetRequestsFromFilter(user, beginDate, endDate, dateCategory, tenantId, status, resultList);
        }
    }
    return resultList;
}
Also used : Timestamp(java.sql.Timestamp) ParseException(java.text.ParseException) WorkflowListener(org.wso2.carbon.identity.workflow.mgt.listener.WorkflowListener) SimpleDateFormat(java.text.SimpleDateFormat) Timestamp(java.sql.Timestamp) Date(java.util.Date) WorkflowRequest(org.wso2.carbon.identity.workflow.mgt.bean.WorkflowRequest)

Example 5 with WorkflowRequest

use of org.wso2.carbon.identity.workflow.mgt.dto.WorkflowRequest in project carbon-identity-framework by wso2.

the class WorkFlowExecutorManager method handleCallback.

/**
 * Called when callback received for a pending operation.
 *
 * @param uuid             Unique ID of request
 * @param status           Status of approval/disapproval
 * @param additionalParams Additional parameters required to execute operation.
 * @throws WorkflowException
 */
public void handleCallback(String uuid, String status, Map<String, Object> additionalParams) throws WorkflowException {
    List<WorkflowExecutorManagerListener> workflowListenerList = WorkflowServiceDataHolder.getInstance().getExecutorListenerList();
    for (WorkflowExecutorManagerListener workflowListener : workflowListenerList) {
        if (workflowListener.isEnable()) {
            workflowListener.doPreHandleCallback(uuid, status, additionalParams);
        }
    }
    WorkflowRequestAssociationDAO workflowRequestAssociationDAO = new WorkflowRequestAssociationDAO();
    String requestId = workflowRequestAssociationDAO.getRequestIdOfRelationship(uuid);
    WorkflowRequestDAO requestDAO = new WorkflowRequestDAO();
    WorkflowRequest request = requestDAO.retrieveWorkflow(requestId);
    handleCallback(request, status, additionalParams, uuid);
    for (WorkflowExecutorManagerListener workflowListener : workflowListenerList) {
        if (workflowListener.isEnable()) {
            workflowListener.doPostHandleCallback(uuid, status, additionalParams);
        }
    }
}
Also used : WorkflowRequestDAO(org.wso2.carbon.identity.workflow.mgt.dao.WorkflowRequestDAO) WorkflowRequestAssociationDAO(org.wso2.carbon.identity.workflow.mgt.dao.WorkflowRequestAssociationDAO) WorkflowExecutorManagerListener(org.wso2.carbon.identity.workflow.mgt.listener.WorkflowExecutorManagerListener) WorkflowRequest(org.wso2.carbon.identity.workflow.mgt.dto.WorkflowRequest)

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