Search in sources :

Example 1 with Workflow

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;
}
Also used : HashMap(java.util.HashMap) Filter(org.meveo.model.filter.Filter) CustomFieldTemplate(org.meveo.model.crm.CustomFieldTemplate) Workflow(org.meveo.model.wf.Workflow)

Example 2 with Workflow

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;
}
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 3 with Workflow

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;
}
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 4 with Workflow

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

Example 5 with Workflow

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);
}
Also used : WorkflowDto(org.meveo.api.dto.payment.WorkflowDto) EntityDoesNotExistsException(org.meveo.api.exception.EntityDoesNotExistsException) Workflow(org.meveo.model.wf.Workflow)

Aggregations

Workflow (org.meveo.model.wf.Workflow)16 ArrayList (java.util.ArrayList)7 WFTransition (org.meveo.model.wf.WFTransition)5 EntityDoesNotExistsException (org.meveo.api.exception.EntityDoesNotExistsException)4 WorkflowDto (org.meveo.api.dto.payment.WorkflowDto)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 BusinessException (org.meveo.admin.exception.BusinessException)2 WFTransitionDto (org.meveo.api.dto.payment.WFTransitionDto)2 BusinessApiException (org.meveo.api.exception.BusinessApiException)2 EntityAlreadyExistsException (org.meveo.api.exception.EntityAlreadyExistsException)2 EntityAlreadyExistsException (org.meveo.exceptions.EntityAlreadyExistsException)2 CustomFieldTemplate (org.meveo.model.crm.CustomFieldTemplate)2 Filter (org.meveo.model.filter.Filter)2 WFAction (org.meveo.model.wf.WFAction)2 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 TransactionAttribute (javax.ejb.TransactionAttribute)1