Search in sources :

Example 1 with WFDecisionRuleDto

use of org.meveo.api.dto.payment.WFDecisionRuleDto in project meveo by meveo-org.

the class WFTransitionApi method create.

/**
 * @param workflow
 * @param wfTransitionDto
 *
 * @throws MissingParameterException
 * @throws EntityDoesNotExistsException
 * @throws EntityAlreadyExistsException
 * @throws BusinessException
 */
public void create(Workflow workflow, WFTransitionDto wfTransitionDto) throws MissingParameterException, EntityDoesNotExistsException, EntityAlreadyExistsException, BusinessException {
    validateDto(wfTransitionDto, false);
    Set<WFDecisionRule> wfDecisionRuleList = new HashSet<>();
    if (CollectionUtils.isNotEmpty(wfTransitionDto.getListWFDecisionRuleDto())) {
        for (WFDecisionRuleDto wfDecisionRuleDto : wfTransitionDto.getListWFDecisionRuleDto()) {
            WFDecisionRule wfDecisionRule = wfDecisionRuleService.getWFDecisionRuleByNameValue(wfDecisionRuleDto.getName(), wfDecisionRuleDto.getValue());
            if (wfDecisionRule == null) {
                wfDecisionRuleList.add(createNewWFDecisionRuleByName(wfDecisionRuleDto.getName(), wfDecisionRuleDto.getValue()));
            } else {
                wfDecisionRuleList.add(wfDecisionRule);
            }
        }
    }
    WFTransition wfTransition;
    wfTransition = fromDTO(wfTransitionDto, null);
    wfTransition.setWorkflow(workflow);
    wfTransition.setWfDecisionRules(wfDecisionRuleList);
    wfTransitionService.create(wfTransition);
    if (CollectionUtils.isNotEmpty(wfTransitionDto.getListWFActionDto())) {
        int priority = 1;
        for (WFActionDto wfActionDto : wfTransitionDto.getListWFActionDto()) {
            wfActionDto.setPriority(priority);
            wfActionApi.create(wfTransition, wfActionDto);
            priority++;
        }
    }
}
Also used : WFTransition(org.meveo.model.wf.WFTransition) WFDecisionRuleDto(org.meveo.api.dto.payment.WFDecisionRuleDto) WFActionDto(org.meveo.api.dto.payment.WFActionDto) WFDecisionRule(org.meveo.model.wf.WFDecisionRule) HashSet(java.util.HashSet)

Example 2 with WFDecisionRuleDto

use of org.meveo.api.dto.payment.WFDecisionRuleDto in project meveo by meveo-org.

the class WFTransitionApi method update.

/**
 * @param wfTransitionDto
 *
 * @throws MissingParameterException
 * @throws EntityDoesNotExistsException
 * @throws EntityAlreadyExistsException
 * @throws BusinessException
 * @throws BusinessApiException
 */
public void update(Workflow workflow, WFTransitionDto wfTransitionDto) throws MissingParameterException, EntityDoesNotExistsException, EntityAlreadyExistsException, BusinessException, BusinessApiException {
    validateDto(wfTransitionDto, true);
    WFTransition wfTransition = wfTransitionService.findWFTransitionByUUID(wfTransitionDto.getUuid());
    if (wfTransition == null) {
        throw new EntityDoesNotExistsException(WFTransition.class.getName() + "with uuid=" + wfTransitionDto.getUuid());
    }
    if (workflow.equals(wfTransition.getWorkflow())) {
        throw new BusinessApiException("Workflow does not match");
    }
    Set<WFDecisionRule> wfDecisionRuleList = new HashSet<>();
    if (CollectionUtils.isNotEmpty(wfTransitionDto.getListWFDecisionRuleDto())) {
        for (WFDecisionRuleDto wfDecisionRuleDto : wfTransitionDto.getListWFDecisionRuleDto()) {
            WFDecisionRule wfDecisionRule = wfDecisionRuleService.getWFDecisionRuleByNameValue(wfDecisionRuleDto.getName(), wfDecisionRuleDto.getValue());
            if (wfDecisionRule == null) {
                wfDecisionRuleList.add(createNewWFDecisionRuleByName(wfDecisionRuleDto.getName(), wfDecisionRuleDto.getValue()));
            } else {
                wfDecisionRuleList.add(wfDecisionRule);
            }
        }
    }
    wfTransition = fromDTO(wfTransitionDto, wfTransition);
    List<WFAction> wfActionList = wfTransition.getWfActions();
    wfTransition.setWorkflow(workflow);
    wfTransition.setWfDecisionRules(wfDecisionRuleList);
    wfTransitionService.update(wfTransition);
    List<WFAction> updatedActions = new ArrayList<>();
    if (CollectionUtils.isNotEmpty(wfTransitionDto.getListWFActionDto())) {
        for (WFActionDto wfActionDto : wfTransitionDto.getListWFActionDto()) {
            if (wfActionDto.getUuid() != null) {
                WFAction wfAction = wfActionService.findWFActionByUUID(wfActionDto.getUuid());
                updatedActions.add(wfAction);
            }
        }
    }
    if (CollectionUtils.isNotEmpty(wfActionList)) {
        wfActionList.removeAll(updatedActions);
        if (CollectionUtils.isNotEmpty(wfActionList)) {
            for (WFAction wfAction : wfActionList) {
                wfActionService.remove(wfAction);
            }
        }
    }
    if (wfTransitionDto.getListWFActionDto() != null && !wfTransitionDto.getListWFActionDto().isEmpty()) {
        int priority = 1;
        for (WFActionDto wfActionDto : wfTransitionDto.getListWFActionDto()) {
            wfActionDto.setPriority(priority);
            wfActionApi.createOrUpdate(wfTransition, wfActionDto);
            priority++;
        }
    }
}
Also used : WFTransition(org.meveo.model.wf.WFTransition) EntityDoesNotExistsException(org.meveo.api.exception.EntityDoesNotExistsException) WFDecisionRuleDto(org.meveo.api.dto.payment.WFDecisionRuleDto) BusinessApiException(org.meveo.api.exception.BusinessApiException) ArrayList(java.util.ArrayList) WFAction(org.meveo.model.wf.WFAction) WFActionDto(org.meveo.api.dto.payment.WFActionDto) WFDecisionRule(org.meveo.model.wf.WFDecisionRule) HashSet(java.util.HashSet)

Example 3 with WFDecisionRuleDto

use of org.meveo.api.dto.payment.WFDecisionRuleDto in project meveo by meveo-org.

the class WFTransitionApi method validateDto.

/**
 * @param wfTransitionDto
 * @throws MissingParameterException
 */
public void validateDto(WFTransitionDto wfTransitionDto, boolean isUpdate) throws MissingParameterException {
    if (wfTransitionDto == null) {
        missingParameters.add("WFTransitionDto");
        handleMissingParameters();
    }
    if (isUpdate && StringUtils.isBlank(wfTransitionDto.getUuid())) {
        missingParameters.add("uuid");
    }
    if (StringUtils.isBlank(wfTransitionDto.getFromStatus())) {
        missingParameters.add("FromStatus");
    }
    if (StringUtils.isBlank(wfTransitionDto.getToStatus())) {
        missingParameters.add("ToStatus");
    }
    if (StringUtils.isBlank(wfTransitionDto.getDescription())) {
        missingParameters.add("Description");
    }
    if (CollectionUtils.isNotEmpty(wfTransitionDto.getListWFDecisionRuleDto())) {
        for (WFDecisionRuleDto wfDecisionRuleDto : wfTransitionDto.getListWFDecisionRuleDto()) {
            if (StringUtils.isBlank(wfDecisionRuleDto.getName())) {
                missingParameters.add("DecisionRuleName");
            }
            if (StringUtils.isBlank(wfDecisionRuleDto.getValue())) {
                missingParameters.add("DecisionRuleValue");
            }
        }
    }
    handleMissingParameters();
}
Also used : WFDecisionRuleDto(org.meveo.api.dto.payment.WFDecisionRuleDto)

Aggregations

WFDecisionRuleDto (org.meveo.api.dto.payment.WFDecisionRuleDto)3 HashSet (java.util.HashSet)2 WFActionDto (org.meveo.api.dto.payment.WFActionDto)2 WFDecisionRule (org.meveo.model.wf.WFDecisionRule)2 WFTransition (org.meveo.model.wf.WFTransition)2 ArrayList (java.util.ArrayList)1 BusinessApiException (org.meveo.api.exception.BusinessApiException)1 EntityDoesNotExistsException (org.meveo.api.exception.EntityDoesNotExistsException)1 WFAction (org.meveo.model.wf.WFAction)1