Search in sources :

Example 1 with WFTransition

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;
}
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 WFTransition

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;
}
Also used : WFTransition(org.meveo.model.wf.WFTransition) Set(java.util.Set) HashSet(java.util.HashSet) CustomFieldTemplate(org.meveo.model.crm.CustomFieldTemplate) ArrayList(java.util.ArrayList) Workflow(org.meveo.model.wf.Workflow)

Example 3 with WFTransition

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

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

Example 5 with WFTransition

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

Aggregations

WFTransition (org.meveo.model.wf.WFTransition)23 BundleKey (org.jboss.seam.international.status.builder.BundleKey)8 ArrayList (java.util.ArrayList)6 ActionMethod (org.meveo.admin.web.interceptor.ActionMethod)6 WFAction (org.meveo.model.wf.WFAction)6 Workflow (org.meveo.model.wf.Workflow)5 BusinessException (org.meveo.admin.exception.BusinessException)4 HashSet (java.util.HashSet)3 ELException (org.meveo.elresolver.ELException)3 EntityAlreadyExistsException (org.meveo.exceptions.EntityAlreadyExistsException)3 WFActionDto (org.meveo.api.dto.payment.WFActionDto)2 WFDecisionRuleDto (org.meveo.api.dto.payment.WFDecisionRuleDto)2 BusinessApiException (org.meveo.api.exception.BusinessApiException)2 EntityDoesNotExistsException (org.meveo.api.exception.EntityDoesNotExistsException)2 WFDecisionRule (org.meveo.model.wf.WFDecisionRule)2 Date (java.util.Date)1 Set (java.util.Set)1 TransactionAttribute (javax.ejb.TransactionAttribute)1 EntityExistsException (javax.persistence.EntityExistsException)1 EntityNotFoundException (javax.persistence.EntityNotFoundException)1