use of org.meveo.model.wf.Workflow in project meveo by meveo-org.
the class WorkflowJob method getCustomFields.
@Override
public Map<String, CustomFieldTemplate> getCustomFields() {
Map<String, CustomFieldTemplate> result = new HashMap<String, CustomFieldTemplate>();
CustomFieldTemplate filterCF = new CustomFieldTemplate();
filterCF.setCode("wfJob_filter");
filterCF.setAppliesTo("JOB_WorkflowJob");
filterCF.setActive(true);
filterCF.setDescription("Filter");
filterCF.setFieldType(CustomFieldTypeEnum.ENTITY);
filterCF.setEntityClazz(Filter.class.getName());
filterCF.setValueRequired(true);
result.put("wfJob_filter", filterCF);
CustomFieldTemplate worklowCF = new CustomFieldTemplate();
worklowCF.setCode("wfJob_workflow");
worklowCF.setAppliesTo("JOB_WorkflowJob");
worklowCF.setActive(true);
worklowCF.setDescription("Workflow");
worklowCF.setFieldType(CustomFieldTypeEnum.ENTITY);
worklowCF.setEntityClazz(Workflow.class.getName());
worklowCF.setValueRequired(true);
result.put("wfJob_workflow", worklowCF);
CustomFieldTemplate nbRuns = new CustomFieldTemplate();
nbRuns.setCode("wfJob_nbRuns");
nbRuns.setAppliesTo("JOB_WorkflowJob");
nbRuns.setActive(true);
nbRuns.setDescription(resourceMessages.getString("jobExecution.nbRuns"));
nbRuns.setFieldType(CustomFieldTypeEnum.LONG);
nbRuns.setValueRequired(false);
nbRuns.setDefaultValue("1");
result.put("wfJob_nbRuns", nbRuns);
CustomFieldTemplate waitingMillis = new CustomFieldTemplate();
waitingMillis.setCode("wfJob_waitingMillis");
waitingMillis.setAppliesTo("JOB_WorkflowJob");
waitingMillis.setActive(true);
waitingMillis.setDescription(resourceMessages.getString("jobExecution.waitingMillis"));
waitingMillis.setFieldType(CustomFieldTypeEnum.LONG);
waitingMillis.setValueRequired(false);
waitingMillis.setDefaultValue("0");
result.put("wfJob_waitingMillis", waitingMillis);
return result;
}
use of org.meveo.model.wf.Workflow in project meveo by meveo-org.
the class CustomEntityInstanceService method transitionsFromPreviousState.
public boolean transitionsFromPreviousState(String cftCode, CustomEntityInstance instance) throws ELException {
Workflow workflow = workflowService.findByCetCodeAndWFType(instance.getCetCode(), cftCode);
if (workflow != null) {
List<WFTransition> transitions = new ArrayList<>();
List<String> statusWF = new ArrayList<>();
List<WFTransition> wfTransitions = workflow.getTransitions();
if (CollectionUtils.isNotEmpty(wfTransitions)) {
for (WFTransition wfTransition : wfTransitions) {
wfTransition = wfTransitionService.findById(wfTransition.getId());
boolean isTransitionApplicable = MeveoValueExpressionWrapper.evaluateToBooleanOneVariable(wfTransition.getConditionEl(), "entity", instance);
String targetStatus = instance.getCfValues().getValuesByCode().get(cftCode).get(0).getStringValue();
String startStatus = (String) instance.getCfValuesOldNullSafe().getValue(cftCode);
boolean isSameTargetStatus = wfTransition.getToStatus().equals(targetStatus);
boolean isSameStartStatus = wfTransition.getFromStatus().equals(startStatus);
if (isTransitionApplicable && isSameTargetStatus && isSameStartStatus) {
transitions.add(wfTransition);
statusWF.add(wfTransition.getToStatus());
}
}
}
if (CollectionUtils.isEmpty(transitions)) {
log.debug("Update refused because no transition matched");
return false;
}
for (WFTransition wfTransition : transitions) {
if (CollectionUtils.isNotEmpty(wfTransition.getWfActions())) {
for (WFAction action : wfTransition.getWfActions()) {
WFAction wfAction = wfActionService.findById(action.getId());
if (action.getConditionEl() == null || MeveoValueExpressionWrapper.evaluateToBooleanOneVariable(action.getConditionEl(), "entity", instance)) {
Object actionResult;
if (wfAction.getActionScript() != null) {
try {
actionResult = workflowService.executeActionScript(instance, wfAction);
} catch (BusinessException e) {
log.error("Error execution workflow action script", e);
}
} else if (StringUtils.isNotBlank(wfAction.getActionEl())) {
actionResult = workflowService.executeExpression(wfAction.getActionEl(), instance);
} else {
log.error("WFAction {} has no action EL or action script", wfAction.getId());
continue;
}
// TODO: Log action result ?
}
}
}
}
}
return true;
}
use of org.meveo.model.wf.Workflow in project meveo by meveo-org.
the class CustomEntityInstanceService method targetStates.
/**
* Returns the target states from a origin state of a given CEI where applicationEL evaluates to true.
*/
public List<String> targetStates(CustomEntityInstance cei) throws ELException {
List<String> targetStates = new ArrayList<>();
Map<String, Set<String>> map = getValueCetCodeAndWfTypeFromWF();
if (cei.getCfValues() != null && cei.getCfValues().getValuesByCode() != null) {
for (String key : cei.getCfValues().getValuesByCode().keySet()) {
CustomFieldTemplate customFieldTemplate = customFieldTemplateService.findByCodeAndAppliesTo(key, "CE_" + cei.getCetCode());
if (customFieldTemplate != null && !map.isEmpty() && map.keySet().contains(cei.getCetCode()) && map.values().contains(customFieldTemplate.getCode()) && MeveoValueExpressionWrapper.evaluateToBooleanOneVariable(customFieldTemplate.getApplicableOnEl(), "entity", cei)) {
Workflow workflow = workflowService.findByCetCodeAndWFType(cei.getCetCode(), customFieldTemplate.getCode());
if (CollectionUtils.isNotEmpty(workflow.getTransitions())) {
for (WFTransition wfTransition : workflow.getTransitions()) {
targetStates.add(wfTransition.getToStatus());
}
}
}
}
}
return targetStates;
}
use of org.meveo.model.wf.Workflow in project meveo by meveo-org.
the class WorkflowService method executeWorkflow.
/**
* Execute a concrete workflow on the given entity
*
* @param entity Entity to execute worklows on
* @param workflowCode A concrete worklfow to execute
*
* @return Updated entity
* @throws BusinessException business exception
*/
public BusinessEntity executeWorkflow(BusinessEntity entity, String workflowCode) throws BusinessException {
Workflow workflow = findByCode(workflowCode);
if (workflow == null) {
throw new EntityNotFoundException("Cant find Workflow entity by code:" + workflowCode);
}
entity = executeWorkflow(entity, workflow);
return entity;
}
use of org.meveo.model.wf.Workflow in project meveo by meveo-org.
the class WorkflowApi method find.
/*
* (non-Javadoc)
*
* @see org.meveo.api.ApiService#find(java.lang.String)
*/
@Override
public WorkflowDto find(String workflowCode) throws EntityDoesNotExistsException, MissingParameterException, InvalidParameterException, MeveoApiException {
if (StringUtils.isBlank(workflowCode)) {
missingParameters.add("workflowCode");
handleMissingParameters();
}
Workflow workflow = workflowService.findByCode(workflowCode);
if (workflow == null) {
throw new EntityDoesNotExistsException(Workflow.class, workflowCode);
}
return new WorkflowDto(workflow);
}
Aggregations