Search in sources :

Example 1 with WorkflowImpl

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

the class WorkflowManagementAdminService method addWorkflow.

/**
 * Add new workflow
 *
 * @param workflow  Workflow details
 * @throws WorkflowException
 */
public void addWorkflow(WorkflowWizard workflow) throws WorkflowException {
    String id = workflow.getWorkflowId();
    if (StringUtils.isBlank(id)) {
        id = UUID.randomUUID().toString();
    }
    int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    try {
        org.wso2.carbon.identity.workflow.mgt.bean.Workflow workflowBean = new org.wso2.carbon.identity.workflow.mgt.bean.Workflow();
        workflowBean.setWorkflowId(id);
        workflowBean.setWorkflowName(workflow.getWorkflowName());
        workflowBean.setWorkflowDescription(workflow.getWorkflowDescription());
        String templateId = workflow.getTemplateId() == null ? workflow.getTemplate().getTemplateId() : workflow.getTemplateId();
        if (templateId == null) {
            throw new WorkflowException("template id can't be empty");
        }
        workflowBean.setTemplateId(templateId);
        String workflowImplId = workflow.getWorkflowImplId() == null ? workflow.getWorkflowImpl().getWorkflowImplId() : workflow.getWorkflowImplId();
        if (workflowImplId == null) {
            throw new WorkflowException("workflowimpl id can't be empty");
        }
        workflowBean.setWorkflowImplId(workflowImplId);
        List<Parameter> parameterList = new ArrayList<>();
        if (workflow.getTemplateParameters() != null) {
            parameterList.addAll(Arrays.asList(workflow.getTemplateParameters()));
        }
        if (workflow.getWorkflowImplParameters() != null) {
            parameterList.addAll(Arrays.asList(workflow.getWorkflowImplParameters()));
        }
        WorkflowServiceDataHolder.getInstance().getWorkflowService().addWorkflow(workflowBean, parameterList, tenantId);
    } catch (WorkflowRuntimeException e) {
        log.error("Error when adding workflow " + workflow.getWorkflowName(), e);
        throw new WorkflowException(e.getMessage());
    } catch (WorkflowException e) {
        log.error("Server error when adding workflow " + workflow.getWorkflowName(), e);
        throw new WorkflowException("Server error occurred when adding the workflow");
    }
}
Also used : InternalWorkflowException(org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException) WorkflowException(org.wso2.carbon.identity.workflow.mgt.exception.WorkflowException) Workflow(org.wso2.carbon.identity.workflow.mgt.bean.Workflow) ArrayList(java.util.ArrayList) AbstractWorkflow(org.wso2.carbon.identity.workflow.mgt.workflow.AbstractWorkflow) Workflow(org.wso2.carbon.identity.workflow.mgt.bean.Workflow) WorkflowRuntimeException(org.wso2.carbon.identity.workflow.mgt.exception.WorkflowRuntimeException) Parameter(org.wso2.carbon.identity.workflow.mgt.bean.Parameter)

Example 2 with WorkflowImpl

use of org.wso2.carbon.identity.workflow.mgt.dto.WorkflowImpl 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 3 with WorkflowImpl

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

the class WorkflowUIUtil method loadWorkflowImplParameters.

/**
 * Load implementaions related parameters of a workflow
 *
 * @param requestParameterMap parameter map
 * @param workflowWizard      Workflow object
 */
public static void loadWorkflowImplParameters(Map<String, String[]> requestParameterMap, WorkflowWizard workflowWizard) {
    Parameter[] workflowImplParameters = workflowWizard.getWorkflowImplParameters();
    Map<String, Parameter> workflowImplParameterMap = new HashMap<>();
    if (workflowImplParameters != null) {
        for (Parameter param : workflowImplParameters) {
            workflowImplParameterMap.put(param.getQName(), param);
        }
    }
    WorkflowImpl workflowImpl = workflowWizard.getWorkflowImpl();
    if (workflowImpl != null) {
        ParametersMetaData parametersMetaData = workflowImpl.getParametersMetaData();
        if (parametersMetaData != null && parametersMetaData.getParameterMetaData() != null) {
            ParameterMetaData[] parameterMetaData = parametersMetaData.getParameterMetaData();
            for (ParameterMetaData metaData : parameterMetaData) {
                if (requestParameterMap.get(metaData.getName()) != null) {
                    Parameter parameter = workflowImplParameterMap.get(metaData.getName());
                    String value = requestParameterMap.get(metaData.getName())[0];
                    if (parameter == null) {
                        parameter = new Parameter();
                        parameter.setParamName(metaData.getName());
                        parameter.setHolder(WorkflowUIConstants.ParameterHolder.WORKFLOW_IMPL);
                        workflowImplParameterMap.put(parameter.getParamName(), parameter);
                    }
                    parameter.setParamValue(value);
                    parameter.setQName(metaData.getName());
                } else {
                    for (Map.Entry<String, String[]> entry : requestParameterMap.entrySet()) {
                        if (entry != null && entry.getKey().startsWith(metaData.getName())) {
                            Parameter parameter = workflowImplParameterMap.get(entry.getKey());
                            if (parameter == null) {
                                parameter = new Parameter();
                                parameter.setParamName(metaData.getName());
                                parameter.setHolder(WorkflowUIConstants.ParameterHolder.WORKFLOW_IMPL);
                                parameter.setQName(entry.getKey());
                                workflowImplParameterMap.put(entry.getKey(), parameter);
                            }
                            String[] values = requestParameterMap.get(entry.getKey());
                            if (values != null && values.length > 0) {
                                String aValue = values[0];
                                parameter.setParamValue(aValue);
                            }
                        }
                    }
                }
            }
        }
    }
    Collection<Parameter> values = workflowImplParameterMap.values();
    Parameter[] parameters = values.toArray(new Parameter[values.size()]);
    workflowWizard.setWorkflowImplParameters(parameters);
}
Also used : HashMap(java.util.HashMap) ParametersMetaData(org.wso2.carbon.identity.workflow.mgt.stub.metadata.bean.ParametersMetaData) WorkflowImpl(org.wso2.carbon.identity.workflow.mgt.stub.metadata.WorkflowImpl) Parameter(org.wso2.carbon.identity.workflow.mgt.stub.bean.Parameter) Map(java.util.Map) HashMap(java.util.HashMap) ParameterMetaData(org.wso2.carbon.identity.workflow.mgt.stub.metadata.bean.ParameterMetaData)

Example 4 with WorkflowImpl

use of org.wso2.carbon.identity.workflow.mgt.dto.WorkflowImpl in project product-is by wso2.

the class UserApprovalTestBase method getWorkflowDTO.

private WorkflowWizard getWorkflowDTO(String workflowName, String workflowDescription) throws RemoteException, WorkflowAdminServiceWorkflowException {
    WorkflowWizard workflowDTO = new WorkflowWizard();
    workflowDTO.setWorkflowName(workflowName);
    workflowDTO.setWorkflowDescription(workflowDescription);
    workflowDTO.setTemplateId(templateId);
    workflowDTO.setWorkflowImplId(workflowImplId);
    Template template = client.getTemplate(templateId);
    workflowDTO.setTemplate(template);
    WorkflowImpl workflowImpl = client.getWorkflowImpl(templateId, workflowImplId);
    workflowDTO.setWorkflowImpl(workflowImpl);
    Parameter[] parametersImpl = new Parameter[2];
    Parameter parameter = new Parameter();
    parameter.setParamName("BPSProfile");
    parameter.setParamValue("embeded_bps");
    parameter.setHolder("WorkflowImpl");
    parameter.setQName("BPSProfile");
    parametersImpl[0] = parameter;
    parameter = new Parameter();
    parameter.setParamName("HTSubject");
    parameter.setParamValue("sample approval task");
    parameter.setHolder("WorkflowImpl");
    parameter.setQName("HTSubject");
    parametersImpl[1] = parameter;
    Parameter[] parametersTmp = new Parameter[1];
    parameter = new Parameter();
    parameter.setParamName("UserAndRole");
    parameter.setParamValue("admin");
    parameter.setHolder("Template");
    parameter.setQName("UserAndRole-step-1-roles");
    parametersTmp[0] = parameter;
    workflowDTO.setTemplateParameters(parametersTmp);
    workflowDTO.setWorkflowImplParameters(parametersImpl);
    return workflowDTO;
}
Also used : WorkflowImpl(org.wso2.carbon.identity.workflow.mgt.stub.metadata.WorkflowImpl) Parameter(org.wso2.carbon.identity.workflow.mgt.stub.bean.Parameter) WorkflowWizard(org.wso2.carbon.identity.workflow.mgt.stub.metadata.WorkflowWizard) Template(org.wso2.carbon.identity.workflow.mgt.stub.metadata.Template)

Example 5 with WorkflowImpl

use of org.wso2.carbon.identity.workflow.mgt.dto.WorkflowImpl in project product-is by wso2.

the class WorkflowManagementTestCase method getWorkflowDTO.

private WorkflowWizard getWorkflowDTO(String workflowName, String workflowDescription) throws RemoteException, WorkflowAdminServiceWorkflowException {
    WorkflowWizard workflowDTO = new WorkflowWizard();
    workflowDTO.setWorkflowName(workflowName);
    workflowDTO.setWorkflowDescription(workflowDescription);
    workflowDTO.setTemplateId(templateId);
    workflowDTO.setWorkflowImplId(workflowImplId);
    Template template = client.getTemplate(templateId);
    workflowDTO.setTemplate(template);
    WorkflowImpl workflowImpl = client.getWorkflowImpl(templateId, workflowImplId);
    workflowDTO.setWorkflowImpl(workflowImpl);
    Parameter[] parametersImpl = new Parameter[2];
    Parameter parameter = new Parameter();
    parameter.setParamName("BPSProfile");
    parameter.setParamValue("embeded_bps");
    parameter.setHolder("WorkflowImpl");
    parameter.setQName("BPSProfile");
    parametersImpl[0] = parameter;
    parameter = new Parameter();
    parameter.setParamName("HTSubject");
    parameter.setParamValue("sample ht");
    parameter.setHolder("WorkflowImpl");
    parameter.setQName("HTSubject");
    parametersImpl[1] = parameter;
    Parameter[] parametersTmp = new Parameter[1];
    parameter = new Parameter();
    parameter.setParamName("UserAndRole");
    parameter.setParamValue("admin");
    parameter.setHolder("Template");
    parameter.setQName("UserAndRole-step-1-roles");
    parametersTmp[0] = parameter;
    workflowDTO.setTemplateParameters(parametersTmp);
    workflowDTO.setWorkflowImplParameters(parametersImpl);
    return workflowDTO;
}
Also used : WorkflowImpl(org.wso2.carbon.identity.workflow.mgt.stub.metadata.WorkflowImpl) Parameter(org.wso2.carbon.identity.workflow.mgt.stub.bean.Parameter) WorkflowWizard(org.wso2.carbon.identity.workflow.mgt.stub.metadata.WorkflowWizard) Template(org.wso2.carbon.identity.workflow.mgt.stub.metadata.Template)

Aggregations

AbstractWorkflow (org.wso2.carbon.identity.workflow.mgt.workflow.AbstractWorkflow)4 ArrayList (java.util.ArrayList)3 WorkflowImpl (org.wso2.carbon.identity.workflow.mgt.dto.WorkflowImpl)3 Parameter (org.wso2.carbon.identity.workflow.mgt.stub.bean.Parameter)3 WorkflowImpl (org.wso2.carbon.identity.workflow.mgt.stub.metadata.WorkflowImpl)3 Parameter (org.wso2.carbon.identity.workflow.mgt.bean.Parameter)2 InternalWorkflowException (org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException)2 WorkflowException (org.wso2.carbon.identity.workflow.mgt.exception.WorkflowException)2 WorkflowListener (org.wso2.carbon.identity.workflow.mgt.listener.WorkflowListener)2 Template (org.wso2.carbon.identity.workflow.mgt.stub.metadata.Template)2 WorkflowWizard (org.wso2.carbon.identity.workflow.mgt.stub.metadata.WorkflowWizard)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Workflow (org.wso2.carbon.identity.workflow.mgt.bean.Workflow)1 Template (org.wso2.carbon.identity.workflow.mgt.dto.Template)1 WorkflowWizard (org.wso2.carbon.identity.workflow.mgt.dto.WorkflowWizard)1 WorkflowRuntimeException (org.wso2.carbon.identity.workflow.mgt.exception.WorkflowRuntimeException)1 ParameterMetaData (org.wso2.carbon.identity.workflow.mgt.stub.metadata.bean.ParameterMetaData)1 ParametersMetaData (org.wso2.carbon.identity.workflow.mgt.stub.metadata.bean.ParametersMetaData)1 AbstractTemplate (org.wso2.carbon.identity.workflow.mgt.template.AbstractTemplate)1