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