Search in sources :

Example 1 with WFAction

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;
}
Also used : WFTransition(org.meveo.model.wf.WFTransition) BusinessException(org.meveo.admin.exception.BusinessException) ArrayList(java.util.ArrayList) Workflow(org.meveo.model.wf.Workflow) WFAction(org.meveo.model.wf.WFAction)

Example 2 with WFAction

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;
}
Also used : HierarchyLevel(org.meveo.model.hierarchy.HierarchyLevel) UserHierarchyLevel(org.meveo.model.hierarchy.UserHierarchyLevel) UserHierarchyLevel(org.meveo.model.hierarchy.UserHierarchyLevel) TreeNode(org.primefaces.model.TreeNode) DefaultTreeNode(org.primefaces.model.DefaultTreeNode) DefaultTreeNode(org.primefaces.model.DefaultTreeNode) ArrayList(java.util.ArrayList) WFAction(org.meveo.model.wf.WFAction)

Example 3 with WFAction

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"));
    }
}
Also used : WFAction(org.meveo.model.wf.WFAction) BundleKey(org.jboss.seam.international.status.builder.BundleKey) ELException(org.meveo.elresolver.ELException) EntityExistsException(javax.persistence.EntityExistsException) BusinessException(org.meveo.admin.exception.BusinessException) ActionMethod(org.meveo.admin.web.interceptor.ActionMethod)

Example 4 with WFAction

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);
}
Also used : WFAction(org.meveo.model.wf.WFAction)

Example 5 with WFAction

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;
}
Also used : WFAction(org.meveo.model.wf.WFAction) WFDecisionRule(org.meveo.model.wf.WFDecisionRule)

Aggregations

WFAction (org.meveo.model.wf.WFAction)17 WFTransition (org.meveo.model.wf.WFTransition)6 ArrayList (java.util.ArrayList)4 BusinessException (org.meveo.admin.exception.BusinessException)4 BundleKey (org.jboss.seam.international.status.builder.BundleKey)3 ActionMethod (org.meveo.admin.web.interceptor.ActionMethod)3 BusinessApiException (org.meveo.api.exception.BusinessApiException)2 EntityDoesNotExistsException (org.meveo.api.exception.EntityDoesNotExistsException)2 ELException (org.meveo.elresolver.ELException)2 EntityAlreadyExistsException (org.meveo.exceptions.EntityAlreadyExistsException)2 UserHierarchyLevel (org.meveo.model.hierarchy.UserHierarchyLevel)2 WFDecisionRule (org.meveo.model.wf.WFDecisionRule)2 Workflow (org.meveo.model.wf.Workflow)2 Date (java.util.Date)1 HashSet (java.util.HashSet)1 EntityExistsException (javax.persistence.EntityExistsException)1 EntityNotFoundException (javax.persistence.EntityNotFoundException)1 NoResultException (javax.persistence.NoResultException)1 InvalidScriptException (org.meveo.admin.exception.InvalidScriptException)1 IWorkflowType (org.meveo.admin.wf.IWorkflowType)1