Search in sources :

Example 1 with WorkflowWizard

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

the class WorkflowManagementAdminService method listWorkflows.

/**
 * List workflows
 *
 * @return
 * @throws WorkflowException
 */
public WorkflowWizard[] listWorkflows() throws WorkflowException {
    List<WorkflowWizard> workflowWizards = new ArrayList<>();
    List<Workflow> workflowBeans = null;
    int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    try {
        workflowBeans = WorkflowServiceDataHolder.getInstance().getWorkflowService().listWorkflows(tenantId);
        for (Workflow workflow : workflowBeans) {
            WorkflowWizard workflowTmp = getWorkflow(workflow);
            workflowWizards.add(workflowTmp);
        }
    } catch (InternalWorkflowException e) {
        log.error("Server error when listing workflows", e);
        throw new WorkflowException("Server error occurred when listing workflows");
    }
    return workflowWizards.toArray(new WorkflowWizard[workflowWizards.size()]);
}
Also used : InternalWorkflowException(org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException) InternalWorkflowException(org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException) WorkflowException(org.wso2.carbon.identity.workflow.mgt.exception.WorkflowException) ArrayList(java.util.ArrayList) AbstractWorkflow(org.wso2.carbon.identity.workflow.mgt.workflow.AbstractWorkflow) Workflow(org.wso2.carbon.identity.workflow.mgt.bean.Workflow) WorkflowWizard(org.wso2.carbon.identity.workflow.mgt.dto.WorkflowWizard)

Example 2 with WorkflowWizard

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

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

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

the class WorkflowUIUtil method loadTemplateParameters.

/**
 * Load parameters of a workflow template
 *
 * @param requestParameterMap parameter map
 * @param workflowWizard      Workflow object
 */
public static void loadTemplateParameters(Map<String, String[]> requestParameterMap, WorkflowWizard workflowWizard) {
    Map<String, Parameter> templateParameterMap = new HashMap<>();
    Template template = workflowWizard.getTemplate();
    if (template != null) {
        ParametersMetaData parametersMetaData = template.getParametersMetaData();
        if (parametersMetaData != null && parametersMetaData.getParameterMetaData() != null) {
            ParameterMetaData[] parameterMetaData = parametersMetaData.getParameterMetaData();
            for (ParameterMetaData metaData : parameterMetaData) {
                if (requestParameterMap.get(metaData.getName()) != null) {
                    String value = requestParameterMap.get(metaData.getName())[0];
                    Parameter parameter = new Parameter();
                    parameter.setParamName(metaData.getName());
                    parameter.setHolder(WorkflowUIConstants.ParameterHolder.TEMPLATE);
                    templateParameterMap.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 = new Parameter();
                            parameter.setParamName(metaData.getName());
                            parameter.setHolder(WorkflowUIConstants.ParameterHolder.TEMPLATE);
                            parameter.setQName(entry.getKey());
                            templateParameterMap.put(entry.getKey(), parameter);
                            String[] values = entry.getValue();
                            if (values != null && values.length > 0) {
                                String aValue = values[0];
                                parameter.setParamValue(aValue);
                            }
                        }
                    }
                }
            }
        }
    }
    Collection<Parameter> values = templateParameterMap.values();
    Parameter[] parameters = values.toArray(new Parameter[values.size()]);
    workflowWizard.setTemplateParameters(parameters);
}
Also used : HashMap(java.util.HashMap) ParametersMetaData(org.wso2.carbon.identity.workflow.mgt.stub.metadata.bean.ParametersMetaData) Template(org.wso2.carbon.identity.workflow.mgt.stub.metadata.Template) 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 5 with WorkflowWizard

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

the class UserApprovalTestBase method addWorkflow.

private void addWorkflow() throws Exception {
    String workflowDescription = "TestWorkflowDescription";
    WorkflowWizard workflowDTO = getWorkflowDTO(addUserWorkflowName, workflowDescription);
    log.info("Adding workflow " + addUserWorkflowName + " to tenant:" + this.tenant);
    this.client.addWorkflow(workflowDTO);
    WorkflowWizard[] workflows = this.client.listWorkflows();
    for (WorkflowWizard workflow : workflows) {
        if (this.addUserWorkflowName.equals(workflow.getWorkflowName()) && workflowDescription.equals(workflow.getWorkflowDescription())) {
            // setting for future tests
            this.workflowId = workflow.getWorkflowId();
            break;
        }
    }
}
Also used : WorkflowWizard(org.wso2.carbon.identity.workflow.mgt.stub.metadata.WorkflowWizard)

Aggregations

Parameter (org.wso2.carbon.identity.workflow.mgt.stub.bean.Parameter)4 WorkflowWizard (org.wso2.carbon.identity.workflow.mgt.stub.metadata.WorkflowWizard)4 ArrayList (java.util.ArrayList)3 InternalWorkflowException (org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException)3 WorkflowException (org.wso2.carbon.identity.workflow.mgt.exception.WorkflowException)3 Template (org.wso2.carbon.identity.workflow.mgt.stub.metadata.Template)3 WorkflowImpl (org.wso2.carbon.identity.workflow.mgt.stub.metadata.WorkflowImpl)3 AbstractWorkflow (org.wso2.carbon.identity.workflow.mgt.workflow.AbstractWorkflow)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Parameter (org.wso2.carbon.identity.workflow.mgt.bean.Parameter)2 Workflow (org.wso2.carbon.identity.workflow.mgt.bean.Workflow)2 WorkflowWizard (org.wso2.carbon.identity.workflow.mgt.dto.WorkflowWizard)2 ParameterMetaData (org.wso2.carbon.identity.workflow.mgt.stub.metadata.bean.ParameterMetaData)2 ParametersMetaData (org.wso2.carbon.identity.workflow.mgt.stub.metadata.bean.ParametersMetaData)2 RemoteException (java.rmi.RemoteException)1 Test (org.testng.annotations.Test)1 Template (org.wso2.carbon.identity.workflow.mgt.dto.Template)1 WorkflowImpl (org.wso2.carbon.identity.workflow.mgt.dto.WorkflowImpl)1 WorkflowRuntimeException (org.wso2.carbon.identity.workflow.mgt.exception.WorkflowRuntimeException)1