use of org.meveo.model.wf.WFTransition 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.WFTransition 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.WFTransition in project meveo by meveo-org.
the class WfTransitionBean method duplicateWfTransition.
@ActionMethod
public String duplicateWfTransition(WFTransition wfTransition) {
try {
workflowOrder = wfService.refreshOrRetrieve(workflowOrder);
this.wfTransition = wfTransitionService.duplicate(wfTransition, workflowOrder);
// Set max priority +1
int priority = 1;
if (operationList.size() > 0) {
for (WFTransition wfTransitionInList : operationList) {
if (CATCH_ALL_PRIORITY != wfTransitionInList.getPriority() && priority <= wfTransitionInList.getPriority()) {
priority = wfTransitionInList.getPriority() + 1;
}
}
}
this.wfTransition.setPriority(priority);
this.setObjectId(this.wfTransition.getId());
editWfTransition(this.wfTransition);
return "mm_workflowDetail";
} catch (Exception e) {
log.error("Failed to duplicate WF transition!", e);
messages.error(new BundleKey("messages", "error.duplicate.unexpected"));
return null;
}
}
use of org.meveo.model.wf.WFTransition in project meveo by meveo-org.
the class WfTransitionBean method createCatchAll.
private WFTransition createCatchAll() throws BusinessException {
WFTransition catchAllDefault = new WFTransition();
catchAllDefault.setPriority(CATCH_ALL_PRIORITY);
catchAllDefault.setDescription(CATCH_ALL);
catchAllDefault.setFromStatus("ACKNOWLEDGED");
catchAllDefault.setToStatus("IN_PROGRESS");
catchAllDefault.setWorkflow(workflowOrder);
wfTransitionService.create(catchAllDefault);
return catchAllDefault;
}
use of org.meveo.model.wf.WFTransition in project meveo by meveo-org.
the class WorkflowBean method duplicateWfTransition.
@ActionMethod
public void duplicateWfTransition(WFTransition wfTransition) {
try {
this.wfTransition = wFTransitionService.duplicate(wfTransition, entity);
// Set max priority +1
int priority = 1;
if (entity.getTransitions().size() > 0) {
for (WFTransition wfTransitionInList : entity.getTransitions()) {
if (WfTransitionBean.CATCH_ALL_PRIORITY != wfTransitionInList.getPriority() && priority <= wfTransitionInList.getPriority()) {
priority = wfTransitionInList.getPriority() + 1;
}
}
}
this.wfTransition.setPriority(priority);
editWfTransition(this.wfTransition);
} catch (Exception e) {
log.error("Failed to duplicate WF transition!", e);
messages.error(new BundleKey("messages", "error.duplicate.unexpected"));
}
}
Aggregations