use of org.meveo.model.wf.WFAction 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.WFAction in project meveo by meveo-org.
the class WfTransitionBean method createTree.
// Recursive function to create tree with node checked if selected
@SuppressWarnings({ "rawtypes", "unchecked" })
private TreeNode createTree(HierarchyLevel hierarchyLevel, TreeNode rootNode, List<WFAction> wfActions) {
TreeNode newNode = new DefaultTreeNode(hierarchyLevel, rootNode);
List<UserHierarchyLevel> subTree = new ArrayList<UserHierarchyLevel>(hierarchyLevel.getChildLevels());
newNode.setExpanded(true);
if (wfActions != null) {
for (WFAction wfAction1 : wfActions) {
if (wfAction1 != null && hierarchyLevel.getCode().equals(wfAction1.getUserGroupCode())) {
newNode.setSelected(true);
}
}
}
if (CollectionUtils.isNotEmpty(subTree)) {
Collections.sort(subTree);
for (HierarchyLevel userGroupTree : subTree) {
createTree(userGroupTree, newNode, wfActions);
}
}
return newNode;
}
use of org.meveo.model.wf.WFAction in project meveo by meveo-org.
the class WfTransitionBean method deleteWfAction.
@ActionMethod
public void deleteWfAction(WFAction wfAction) {
try {
WFAction action = wfActionService.findById(wfAction.getId());
wfActionService.remove(action);
entity.getWfActions().remove(wfAction);
messages.info(new BundleKey("messages", "delete.successful"));
} catch (Exception e) {
log.info("Failed to delete!", e);
messages.error(new BundleKey("messages", "error.delete.unexpected"));
}
}
use of org.meveo.model.wf.WFAction in project meveo by meveo-org.
the class WorkflowBean method addNewAction.
public void addNewAction() {
WFAction newInstance = new WFAction();
if (CollectionUtils.isNotEmpty(wfActions)) {
WFAction lastAction = wfActions.get(wfActions.size() - 1);
newInstance.setPriority(lastAction.getPriority() + 1);
} else {
newInstance.setPriority(1);
}
wfActions.add(newInstance);
}
use of org.meveo.model.wf.WFAction in project meveo by meveo-org.
the class WFTransitionService method duplicate.
public synchronized WFTransition duplicate(WFTransition entity, Workflow workflow) throws BusinessException {
entity = refreshOrRetrieve(entity);
if (workflow != null) {
entity.setWorkflow(workflow);
}
entity.getWfActions().size();
entity.getWfDecisionRules().size();
// Detach and clear ids of entity and related entities
detach(entity);
entity.setId(null);
entity.clearUuid();
List<WFAction> wfActions = entity.getWfActions();
entity.setWfActions(new ArrayList<WFAction>());
Set<WFDecisionRule> wfDecisionRules = entity.getWfDecisionRules();
entity.setWfDecisionRules(new HashSet<WFDecisionRule>());
create(entity);
workflow.getTransitions().add(entity);
if (wfActions != null) {
for (WFAction wfAction : wfActions) {
wfActionService.detach(wfAction);
wfAction.setId(null);
wfAction.clearUuid();
wfActionService.create(wfAction);
entity.getWfActions().add(wfAction);
}
}
if (wfDecisionRules != null) {
for (WFDecisionRule wfDecisionRule : wfDecisionRules) {
entity.getWfDecisionRules().add(wfDecisionRule);
}
}
update(entity);
return entity;
}
Aggregations