Search in sources :

Example 1 with AbstractWorkflow

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

the class WorkflowManagementServiceImpl method listWorkflowImpls.

@Override
public List<WorkflowImpl> listWorkflowImpls(String templateId) throws WorkflowException {
    List<WorkflowListener> workflowListenerList = WorkflowServiceDataHolder.getInstance().getWorkflowListenerList();
    for (WorkflowListener workflowListener : workflowListenerList) {
        if (workflowListener.isEnable()) {
            workflowListener.doPreListWorkflowImpls(templateId);
        }
    }
    Map<String, AbstractWorkflow> abstractWorkflowMap = WorkflowServiceDataHolder.getInstance().getWorkflowImpls().get(templateId);
    List<WorkflowImpl> workflowList = new ArrayList<>();
    if (abstractWorkflowMap != null) {
        List<AbstractWorkflow> abstractWorkflowList = new ArrayList<>(abstractWorkflowMap.values());
        for (AbstractWorkflow abstractWorkflow : abstractWorkflowList) {
            WorkflowImpl workflow = new WorkflowImpl();
            workflow.setWorkflowImplId(abstractWorkflow.getWorkflowImplId());
            workflow.setWorkflowImplName(abstractWorkflow.getWorkflowImplName());
            workflow.setParametersMetaData(abstractWorkflow.getParametersMetaData());
            workflow.setTemplateId(abstractWorkflow.getTemplateId());
            workflowList.add(workflow);
        }
    }
    for (WorkflowListener workflowListener : workflowListenerList) {
        if (workflowListener.isEnable()) {
            workflowListener.doPostListWorkflowImpls(templateId, workflowList);
        }
    }
    return workflowList;
}
Also used : WorkflowImpl(org.wso2.carbon.identity.workflow.mgt.dto.WorkflowImpl) ArrayList(java.util.ArrayList) AbstractWorkflow(org.wso2.carbon.identity.workflow.mgt.workflow.AbstractWorkflow) WorkflowListener(org.wso2.carbon.identity.workflow.mgt.listener.WorkflowListener)

Example 2 with AbstractWorkflow

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

the class WorkFlowExecutorManager method executeWorkflow.

/**
 * Called when initiate a request that can be engaged with a workflow. Here it determine if operation has engaged
 * with a workflow or not. If workflows engaged this will deploy communicate with relevant workflow engine and
 * return false which will stop continuation of operation. Otherwise this will return true.
 *
 * @param workFlowRequest Workflow request object with request attributes.
 * @return
 * @throws WorkflowException
 */
public WorkflowExecutorResult executeWorkflow(WorkflowRequest workFlowRequest) throws WorkflowException {
    WorkflowRequestAssociationDAO workflowRequestAssociationDAO = new WorkflowRequestAssociationDAO();
    List<WorkflowExecutorManagerListener> workflowListenerList = WorkflowServiceDataHolder.getInstance().getExecutorListenerList();
    for (WorkflowExecutorManagerListener workflowListener : workflowListenerList) {
        if (workflowListener.isEnable()) {
            workflowListener.doPreExecuteWorkflow(workFlowRequest);
        }
    }
    if (StringUtils.isBlank(workFlowRequest.getUuid())) {
        workFlowRequest.setUuid(UUID.randomUUID().toString());
    }
    OMElement xmlRequest = WorkflowRequestBuilder.buildXMLRequest(workFlowRequest);
    WorkflowRequestAssociationDAO requestAssociationDAO = new WorkflowRequestAssociationDAO();
    WorkflowDAO workflowDAO = new WorkflowDAO();
    List<WorkflowAssociation> associations = requestAssociationDAO.getWorkflowAssociationsForRequest(workFlowRequest.getEventType(), workFlowRequest.getTenantId());
    if (CollectionUtils.isEmpty(associations)) {
        return new WorkflowExecutorResult(ExecutorResultState.NO_ASSOCIATION);
    }
    boolean workflowEngaged = false;
    boolean requestSaved = false;
    for (WorkflowAssociation association : associations) {
        try {
            AXIOMXPath axiomxPath = new AXIOMXPath(association.getAssociationCondition());
            if (axiomxPath.booleanValueOf(xmlRequest)) {
                workflowEngaged = true;
                if (!requestSaved) {
                    WorkflowRequestDAO requestDAO = new WorkflowRequestDAO();
                    int tenant = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
                    String currentUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
                    requestDAO.addWorkflowEntry(workFlowRequest, currentUser, tenant);
                    requestSaved = true;
                }
                String relationshipId = UUID.randomUUID().toString();
                WorkflowRequest requestToSend = workFlowRequest.clone();
                requestToSend.setUuid(relationshipId);
                Workflow workflow = workflowDAO.getWorkflow(association.getWorkflowId());
                AbstractWorkflow templateImplementation = WorkflowServiceDataHolder.getInstance().getWorkflowImpls().get(workflow.getTemplateId()).get(workflow.getWorkflowImplId());
                List<Parameter> parameterList = workflowDAO.getWorkflowParams(association.getWorkflowId());
                templateImplementation.execute(requestToSend, parameterList);
                workflowRequestAssociationDAO.addNewRelationship(relationshipId, association.getWorkflowId(), workFlowRequest.getUuid(), WorkflowRequestStatus.PENDING.toString(), workFlowRequest.getTenantId());
            }
        } catch (JaxenException e) {
            String errorMsg = "Error when executing the xpath expression:" + association.getAssociationCondition() + " , on " + xmlRequest;
            log.error(errorMsg, e);
            return new WorkflowExecutorResult(ExecutorResultState.FAILED, errorMsg);
        } catch (CloneNotSupportedException e) {
            String errorMsg = "Error while cloning workflowRequest object at executor manager.";
            log.error(errorMsg, e);
            return new WorkflowExecutorResult(ExecutorResultState.FAILED, errorMsg);
        }
    }
    if (!workflowEngaged) {
        // handleCallback(workFlowRequest, WorkflowRequestStatus.SKIPPED.toString(), null, "");
        return new WorkflowExecutorResult(ExecutorResultState.CONDITION_FAILED);
    }
    WorkflowExecutorResult finalResult = new WorkflowExecutorResult(ExecutorResultState.STARTED_ASSOCIATION);
    for (WorkflowExecutorManagerListener workflowListener : workflowListenerList) {
        if (workflowListener.isEnable()) {
            workflowListener.doPostExecuteWorkflow(workFlowRequest, finalResult);
        }
    }
    return finalResult;
}
Also used : WorkflowRequestDAO(org.wso2.carbon.identity.workflow.mgt.dao.WorkflowRequestDAO) AbstractWorkflow(org.wso2.carbon.identity.workflow.mgt.workflow.AbstractWorkflow) Workflow(org.wso2.carbon.identity.workflow.mgt.bean.Workflow) OMElement(org.apache.axiom.om.OMElement) AbstractWorkflow(org.wso2.carbon.identity.workflow.mgt.workflow.AbstractWorkflow) WorkflowDAO(org.wso2.carbon.identity.workflow.mgt.dao.WorkflowDAO) WorkflowRequestAssociationDAO(org.wso2.carbon.identity.workflow.mgt.dao.WorkflowRequestAssociationDAO) JaxenException(org.jaxen.JaxenException) WorkflowExecutorManagerListener(org.wso2.carbon.identity.workflow.mgt.listener.WorkflowExecutorManagerListener) Parameter(org.wso2.carbon.identity.workflow.mgt.bean.Parameter) WorkflowAssociation(org.wso2.carbon.identity.workflow.mgt.bean.WorkflowAssociation) AXIOMXPath(org.apache.axiom.om.xpath.AXIOMXPath) WorkflowRequest(org.wso2.carbon.identity.workflow.mgt.dto.WorkflowRequest)

Example 3 with AbstractWorkflow

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

the class WorkflowManagementAdminService method getWorkflow.

private WorkflowWizard getWorkflow(org.wso2.carbon.identity.workflow.mgt.bean.Workflow workflowBean) throws WorkflowException {
    try {
        WorkflowWizard workflow = null;
        if (workflowBean != null) {
            workflow = new WorkflowWizard();
            workflow.setWorkflowId(workflowBean.getWorkflowId());
            workflow.setWorkflowName(workflowBean.getWorkflowName());
            workflow.setWorkflowDescription(workflowBean.getWorkflowDescription());
            // workflow.setTemplateId(workflowBean.getTemplateId());
            // workflow.setWorkflowImplId(workflowBean.getWorkflowImplId());
            AbstractTemplate abstractTemplate = WorkflowServiceDataHolder.getInstance().getTemplates().get(workflowBean.getTemplateId());
            Template template = new Template();
            template.setTemplateId(abstractTemplate.getTemplateId());
            template.setName(abstractTemplate.getName());
            template.setDescription(abstractTemplate.getDescription());
            template.setParametersMetaData(abstractTemplate.getParametersMetaData());
            workflow.setTemplate(template);
            AbstractWorkflow abstractWorkflow = WorkflowServiceDataHolder.getInstance().getWorkflowImpls().get(workflowBean.getTemplateId()).get(workflowBean.getWorkflowImplId());
            WorkflowImpl workflowimpl = new WorkflowImpl();
            workflowimpl.setWorkflowImplId(abstractWorkflow.getWorkflowImplId());
            workflowimpl.setWorkflowImplName(abstractWorkflow.getWorkflowImplName());
            workflowimpl.setTemplateId(abstractWorkflow.getTemplateId());
            workflowimpl.setParametersMetaData(abstractWorkflow.getParametersMetaData());
            workflow.setWorkflowImpl(workflowimpl);
            List<Parameter> workflowParams = WorkflowServiceDataHolder.getInstance().getWorkflowService().getWorkflowParameters(workflowBean.getWorkflowId());
            List<Parameter> templateParams = new ArrayList<>();
            List<Parameter> workflowImplParams = new ArrayList<>();
            for (Parameter parameter : workflowParams) {
                if (parameter.getHolder().equals(WFConstant.ParameterHolder.TEMPLATE)) {
                    templateParams.add(parameter);
                } else if (parameter.getHolder().equals(WFConstant.ParameterHolder.WORKFLOW_IMPL)) {
                    workflowImplParams.add(parameter);
                }
            }
            workflow.setTemplateParameters(templateParams.toArray(new Parameter[templateParams.size()]));
            workflow.setWorkflowImplParameters(workflowImplParams.toArray(new Parameter[workflowImplParams.size()]));
        }
        return workflow;
    } catch (InternalWorkflowException e) {
        String errorMsg = "Error occurred while reading workflow object details for given workflow id, " + e.getMessage();
        log.error(errorMsg, e);
        throw new WorkflowException(errorMsg, e);
    }
}
Also used : WorkflowImpl(org.wso2.carbon.identity.workflow.mgt.dto.WorkflowImpl) InternalWorkflowException(org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException) AbstractTemplate(org.wso2.carbon.identity.workflow.mgt.template.AbstractTemplate) InternalWorkflowException(org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException) WorkflowException(org.wso2.carbon.identity.workflow.mgt.exception.WorkflowException) ArrayList(java.util.ArrayList) Parameter(org.wso2.carbon.identity.workflow.mgt.bean.Parameter) AbstractWorkflow(org.wso2.carbon.identity.workflow.mgt.workflow.AbstractWorkflow) WorkflowWizard(org.wso2.carbon.identity.workflow.mgt.dto.WorkflowWizard) Template(org.wso2.carbon.identity.workflow.mgt.dto.Template) AbstractTemplate(org.wso2.carbon.identity.workflow.mgt.template.AbstractTemplate)

Example 4 with AbstractWorkflow

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

the class WorkflowManagementServiceImpl method getWorkflowImpl.

@Override
public WorkflowImpl getWorkflowImpl(String templateId, String workflowImplId) throws WorkflowException {
    List<WorkflowListener> workflowListenerList = WorkflowServiceDataHolder.getInstance().getWorkflowListenerList();
    for (WorkflowListener workflowListener : workflowListenerList) {
        if (workflowListener.isEnable()) {
            workflowListener.doPreGetWorkflowImpl(templateId, workflowImplId);
        }
    }
    WorkflowImpl workflowImpl = null;
    Map<String, AbstractWorkflow> abstractWorkflowMap = WorkflowServiceDataHolder.getInstance().getWorkflowImpls().get(templateId);
    if (abstractWorkflowMap != null) {
        AbstractWorkflow tmp = abstractWorkflowMap.get(workflowImplId);
        if (tmp != null) {
            workflowImpl = new WorkflowImpl();
            workflowImpl.setWorkflowImplId(tmp.getWorkflowImplId());
            workflowImpl.setWorkflowImplName(tmp.getWorkflowImplName());
            workflowImpl.setParametersMetaData(tmp.getParametersMetaData());
            workflowImpl.setTemplateId(tmp.getTemplateId());
        }
    }
    for (WorkflowListener workflowListener : workflowListenerList) {
        if (workflowListener.isEnable()) {
            workflowListener.doPostGetWorkflowImpl(templateId, workflowImplId, workflowImpl);
        }
    }
    return workflowImpl;
}
Also used : WorkflowImpl(org.wso2.carbon.identity.workflow.mgt.dto.WorkflowImpl) AbstractWorkflow(org.wso2.carbon.identity.workflow.mgt.workflow.AbstractWorkflow) WorkflowListener(org.wso2.carbon.identity.workflow.mgt.listener.WorkflowListener)

Example 5 with AbstractWorkflow

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

the class WorkflowManagementServiceImpl method addWorkflow.

@Override
public void addWorkflow(Workflow workflow, List<Parameter> parameterList, int tenantId) throws WorkflowException {
    List<WorkflowListener> workflowListenerList = WorkflowServiceDataHolder.getInstance().getWorkflowListenerList();
    for (WorkflowListener workflowListener : workflowListenerList) {
        if (workflowListener.isEnable()) {
            workflowListener.doPreAddWorkflow(workflow, parameterList, tenantId);
        }
    }
    // TODO:Workspace Name may contain spaces , so we need to remove spaces and prepare process for that
    Parameter workflowNameParameter = new Parameter(workflow.getWorkflowId(), WFConstant.ParameterName.WORKFLOW_NAME, workflow.getWorkflowName(), WFConstant.ParameterName.WORKFLOW_NAME, WFConstant.ParameterHolder.WORKFLOW_IMPL);
    if (!parameterList.contains(workflowNameParameter)) {
        parameterList.add(workflowNameParameter);
    } else {
        workflowNameParameter = parameterList.get(parameterList.indexOf(workflowNameParameter));
    }
    if (!workflowNameParameter.getParamValue().equals(workflow.getWorkflowName())) {
        workflowNameParameter.setParamValue(workflow.getWorkflowName());
    // TODO:Since the user has changed the workflow name, we have to undeploy bpel package that is already
    // deployed using previous workflow name.
    }
    AbstractWorkflow abstractWorkflow = WorkflowServiceDataHolder.getInstance().getWorkflowImpls().get(workflow.getTemplateId()).get(workflow.getWorkflowImplId());
    // deploying the template
    abstractWorkflow.deploy(parameterList);
    // add workflow to the database
    Workflow oldWorkflow = workflowDAO.getWorkflow(workflow.getWorkflowId());
    if (oldWorkflow == null) {
        workflowDAO.addWorkflow(workflow, tenantId);
        WorkflowManagementUtil.createAppRole(StringUtils.deleteWhitespace(workflow.getWorkflowName()));
    } else {
        workflowDAO.removeWorkflowParams(workflow.getWorkflowId());
        workflowDAO.updateWorkflow(workflow);
        if (!StringUtils.equals(oldWorkflow.getWorkflowName(), workflow.getWorkflowName())) {
            WorkflowManagementUtil.updateWorkflowRoleName(oldWorkflow.getWorkflowName(), workflow.getWorkflowName());
        }
    }
    workflowDAO.addWorkflowParams(parameterList, workflow.getWorkflowId(), tenantId);
    for (WorkflowListener workflowListener : workflowListenerList) {
        if (workflowListener.isEnable()) {
            workflowListener.doPostAddWorkflow(workflow, parameterList, tenantId);
        }
    }
}
Also used : Parameter(org.wso2.carbon.identity.workflow.mgt.bean.Parameter) AbstractWorkflow(org.wso2.carbon.identity.workflow.mgt.workflow.AbstractWorkflow) Workflow(org.wso2.carbon.identity.workflow.mgt.bean.Workflow) AbstractWorkflow(org.wso2.carbon.identity.workflow.mgt.workflow.AbstractWorkflow) WorkflowListener(org.wso2.carbon.identity.workflow.mgt.listener.WorkflowListener)

Aggregations

AbstractWorkflow (org.wso2.carbon.identity.workflow.mgt.workflow.AbstractWorkflow)5 Parameter (org.wso2.carbon.identity.workflow.mgt.bean.Parameter)3 WorkflowImpl (org.wso2.carbon.identity.workflow.mgt.dto.WorkflowImpl)3 WorkflowListener (org.wso2.carbon.identity.workflow.mgt.listener.WorkflowListener)3 ArrayList (java.util.ArrayList)2 Workflow (org.wso2.carbon.identity.workflow.mgt.bean.Workflow)2 OMElement (org.apache.axiom.om.OMElement)1 AXIOMXPath (org.apache.axiom.om.xpath.AXIOMXPath)1 JaxenException (org.jaxen.JaxenException)1 WorkflowAssociation (org.wso2.carbon.identity.workflow.mgt.bean.WorkflowAssociation)1 WorkflowDAO (org.wso2.carbon.identity.workflow.mgt.dao.WorkflowDAO)1 WorkflowRequestAssociationDAO (org.wso2.carbon.identity.workflow.mgt.dao.WorkflowRequestAssociationDAO)1 WorkflowRequestDAO (org.wso2.carbon.identity.workflow.mgt.dao.WorkflowRequestDAO)1 Template (org.wso2.carbon.identity.workflow.mgt.dto.Template)1 WorkflowRequest (org.wso2.carbon.identity.workflow.mgt.dto.WorkflowRequest)1 WorkflowWizard (org.wso2.carbon.identity.workflow.mgt.dto.WorkflowWizard)1 InternalWorkflowException (org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException)1 WorkflowException (org.wso2.carbon.identity.workflow.mgt.exception.WorkflowException)1 WorkflowExecutorManagerListener (org.wso2.carbon.identity.workflow.mgt.listener.WorkflowExecutorManagerListener)1 AbstractTemplate (org.wso2.carbon.identity.workflow.mgt.template.AbstractTemplate)1