Search in sources :

Example 1 with WorkflowRuntimeException

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

the class AbstractWorkflowRequestHandler method getParameter.

/**
 * Wraps the parameters to the WorkflowParameter
 *
 * @param name     Name of the parameter
 * @param value    Value of the parameter
 * @param required Whether it is required to sent to the workflow executor
 * @return
 */
protected RequestParameter getParameter(String name, Object value, boolean required) throws WorkflowRuntimeException {
    RequestParameter parameter = new RequestParameter();
    parameter.setName(name);
    parameter.setValue(value);
    parameter.setRequiredInWorkflow(required);
    String valueType = getParamDefinitions().get(name);
    if (valueType == null || value == null) {
        // null value as param, or undefined param
        parameter.setValueType(WorkflowDataType.OTHER_TYPE);
    } else {
        if (isValueValid(name, value, valueType)) {
            parameter.setValueType(valueType);
        } else {
            throw new WorkflowRuntimeException("Invalid value for '" + name + "', Expected: '" + valueType + "', " + "but was of " + value.getClass().getName());
        }
    }
    return parameter;
}
Also used : RequestParameter(org.wso2.carbon.identity.workflow.mgt.bean.RequestParameter) WorkflowRuntimeException(org.wso2.carbon.identity.workflow.mgt.exception.WorkflowRuntimeException)

Example 2 with WorkflowRuntimeException

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

use of org.wso2.carbon.identity.workflow.mgt.exception.WorkflowRuntimeException 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 4 with WorkflowRuntimeException

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

the class WorkflowManagementServiceImpl method addAssociation.

@Override
public void addAssociation(String associationName, String workflowId, String eventId, String condition) throws WorkflowException {
    List<WorkflowListener> workflowListenerList = WorkflowServiceDataHolder.getInstance().getWorkflowListenerList();
    for (WorkflowListener workflowListener : workflowListenerList) {
        if (workflowListener.isEnable()) {
            workflowListener.doPreAddAssociation(associationName, workflowId, eventId, condition);
        }
    }
    if (StringUtils.isBlank(workflowId)) {
        log.error("Null or empty string given as workflow id to be associated to event.");
        throw new InternalWorkflowException("Service alias cannot be null");
    }
    if (StringUtils.isBlank(eventId)) {
        log.error("Null or empty string given as 'event' to be associated with the service.");
        throw new InternalWorkflowException("Event type cannot be null");
    }
    if (StringUtils.isBlank(condition)) {
        log.error("Null or empty string given as condition expression when associating " + workflowId + " to event " + eventId);
        throw new InternalWorkflowException("Condition cannot be null");
    }
    // check for xpath syntax errors
    XPathFactory factory = XPathFactory.newInstance();
    XPath xpath = factory.newXPath();
    try {
        xpath.compile(condition);
        associationDAO.addAssociation(associationName, workflowId, eventId, condition);
    } catch (XPathExpressionException e) {
        log.error("The condition:" + condition + " is not an valid xpath expression.", e);
        throw new WorkflowRuntimeException("The condition is not a valid xpath expression.");
    }
    for (WorkflowListener workflowListener : workflowListenerList) {
        if (workflowListener.isEnable()) {
            workflowListener.doPostAddAssociation(associationName, workflowId, eventId, condition);
        }
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathFactory(javax.xml.xpath.XPathFactory) InternalWorkflowException(org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) WorkflowRuntimeException(org.wso2.carbon.identity.workflow.mgt.exception.WorkflowRuntimeException) WorkflowListener(org.wso2.carbon.identity.workflow.mgt.listener.WorkflowListener)

Example 5 with WorkflowRuntimeException

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

the class WorkflowManagementUtil method readFileFromResource.

/**
 * Reading File Content from the resource path
 *
 * @param resourceAsStream
 * @return
 * @throws URISyntaxException
 * @throws IOException
 */
public static String readFileFromResource(InputStream resourceAsStream) throws URISyntaxException, IOException {
    String content = null;
    try {
        BufferedInputStream bufferedInputStream = new BufferedInputStream(resourceAsStream);
        int c = -1;
        StringBuilder resourceFile = new StringBuilder();
        while ((c = bufferedInputStream.read()) != -1) {
            char val = (char) c;
            resourceFile.append(val);
        }
        content = resourceFile.toString();
    } catch (IOException e) {
        String errorMsg = "Error occurred while reading file from class path, " + e.getMessage();
        log.error(errorMsg, e);
        throw new WorkflowRuntimeException(errorMsg, e);
    }
    return content;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) IOException(java.io.IOException) WorkflowRuntimeException(org.wso2.carbon.identity.workflow.mgt.exception.WorkflowRuntimeException)

Aggregations

WorkflowRuntimeException (org.wso2.carbon.identity.workflow.mgt.exception.WorkflowRuntimeException)4 RequestParameter (org.wso2.carbon.identity.workflow.mgt.bean.RequestParameter)2 InternalWorkflowException (org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException)2 BufferedInputStream (java.io.BufferedInputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 XPath (javax.xml.xpath.XPath)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 XPathFactory (javax.xml.xpath.XPathFactory)1 Parameter (org.wso2.carbon.identity.workflow.mgt.bean.Parameter)1 Workflow (org.wso2.carbon.identity.workflow.mgt.bean.Workflow)1 WorkflowException (org.wso2.carbon.identity.workflow.mgt.exception.WorkflowException)1 WorkflowListener (org.wso2.carbon.identity.workflow.mgt.listener.WorkflowListener)1 AbstractWorkflow (org.wso2.carbon.identity.workflow.mgt.workflow.AbstractWorkflow)1