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;
}
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();
}
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");
}
}
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);
}
}
}
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;
}
Aggregations