Search in sources :

Example 1 with ProgramRuleActionValidationResult

use of org.hisp.dhis.programrule.ProgramRuleActionValidationResult in project dhis2-core by dhis2.

the class ProgramRuleActionObjectBundleHook method validateProgramRuleAction.

private ProgramRuleActionValidationResult validateProgramRuleAction(ProgramRuleAction ruleAction, ObjectBundle bundle) {
    ProgramRuleActionValidationResult validationResult;
    ProgramRuleActionValidationContext validationContext = contextLoader.load(bundle.getPreheat(), bundle.getPreheatIdentifier(), ruleAction);
    ProgramRuleActionValidator validator = programRuleActionValidatorMap.get(ruleAction.getProgramRuleActionType());
    validationResult = validator.validate(ruleAction, validationContext);
    return validationResult;
}
Also used : ProgramRuleActionValidationResult(org.hisp.dhis.programrule.ProgramRuleActionValidationResult) ProgramRuleActionValidator(org.hisp.dhis.programrule.action.validation.ProgramRuleActionValidator) ProgramRuleActionValidationContext(org.hisp.dhis.programrule.action.validation.ProgramRuleActionValidationContext)

Example 2 with ProgramRuleActionValidationResult

use of org.hisp.dhis.programrule.ProgramRuleActionValidationResult in project dhis2-core by dhis2.

the class BaseProgramRuleActionValidator method handleTrackedEntityAttribute.

private ProgramRuleActionValidationResult handleTrackedEntityAttribute(ProgramRuleActionValidationContext validationContext, ProgramRuleAction programRuleAction, Program program) {
    ProgramRule rule = validationContext.getProgramRule();
    TrackedEntityAttribute attribute = validationContext.getTrackedEntityAttribute();
    if (attribute == null) {
        log.debug(String.format("TrackedEntityAttribute: %s associated with program rule: %s does not exist", programRuleAction.getAttribute().getUid(), rule.getName()));
        return ProgramRuleActionValidationResult.builder().valid(false).errorReport(new ErrorReport(TrackedEntityAttribute.class, ErrorCode.E4046, programRuleAction.getAttribute().getUid(), rule.getName())).build();
    }
    List<String> trackedEntityAttributes = program.getProgramAttributes().stream().map(att -> att.getAttribute().getUid()).collect(Collectors.toList());
    if (!trackedEntityAttributes.contains(attribute.getUid())) {
        log.debug(String.format("TrackedEntityAttribute: %s is not linked to any ProgramTrackedEntityAttribute", attribute.getUid()));
        return ProgramRuleActionValidationResult.builder().valid(false).errorReport(new ErrorReport(TrackedEntityAttribute.class, ErrorCode.E4048, attribute.getUid(), rule.getName())).build();
    }
    return ProgramRuleActionValidationResult.builder().valid(true).build();
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) ErrorReport(org.hisp.dhis.feedback.ErrorReport) ProgramRuleActionValidationResult(org.hisp.dhis.programrule.ProgramRuleActionValidationResult) Set(java.util.Set) Collectors(java.util.stream.Collectors) ProgramRuleAction(org.hisp.dhis.programrule.ProgramRuleAction) Program(org.hisp.dhis.program.Program) ProgramStage(org.hisp.dhis.program.ProgramStage) DataElement(org.hisp.dhis.dataelement.DataElement) ProgramRule(org.hisp.dhis.programrule.ProgramRule) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) Optional(java.util.Optional) ErrorCode(org.hisp.dhis.feedback.ErrorCode) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ProgramRule(org.hisp.dhis.programrule.ProgramRule) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute)

Example 3 with ProgramRuleActionValidationResult

use of org.hisp.dhis.programrule.ProgramRuleActionValidationResult in project dhis2-core by dhis2.

the class HideOptionProgramRuleActionValidator method validate.

@Override
public ProgramRuleActionValidationResult validate(ProgramRuleAction programRuleAction, ProgramRuleActionValidationContext validationContext) {
    // First checking the validity of DataElement and TEA
    ProgramRuleActionValidationResult result = super.validate(programRuleAction, validationContext);
    ProgramRule rule = validationContext.getProgramRule();
    if (!result.isValid()) {
        return result;
    }
    if (!programRuleAction.hasOption()) {
        log.debug(String.format("Option cannot be null for program rule: %s ", rule.getName()));
        return ProgramRuleActionValidationResult.builder().valid(false).errorReport(new ErrorReport(Option.class, ErrorCode.E4040, rule.getName())).build();
    }
    Option option = validationContext.getOption();
    if (option == null) {
        log.debug(String.format("Option %s associated with program rule %s does not exist", programRuleAction.getOption().getUid(), rule.getName()));
        return ProgramRuleActionValidationResult.builder().valid(false).errorReport(new ErrorReport(Option.class, ErrorCode.E4041, programRuleAction.getOption().getUid(), rule.getName())).build();
    }
    return ProgramRuleActionValidationResult.builder().valid(true).build();
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) ProgramRuleActionValidationResult(org.hisp.dhis.programrule.ProgramRuleActionValidationResult) ProgramRule(org.hisp.dhis.programrule.ProgramRule) Option(org.hisp.dhis.option.Option)

Example 4 with ProgramRuleActionValidationResult

use of org.hisp.dhis.programrule.ProgramRuleActionValidationResult in project dhis2-core by dhis2.

the class ShowHideOptionGroupProgramRuleActionValidator method validate.

@Override
public ProgramRuleActionValidationResult validate(ProgramRuleAction programRuleAction, ProgramRuleActionValidationContext validationContext) {
    ProgramRule rule = validationContext.getProgramRule();
    // First checking the validity of DataElement and TEA
    ProgramRuleActionValidationResult result = super.validate(programRuleAction, validationContext);
    if (!result.isValid()) {
        return result;
    }
    if (!programRuleAction.hasOptionGroup()) {
        log.debug(String.format("OptionGroup cannot be null for program rule: %s ", rule.getName()));
        return ProgramRuleActionValidationResult.builder().valid(false).errorReport(new ErrorReport(Option.class, ErrorCode.E4040, rule.getName())).build();
    }
    OptionGroup optionGroup = validationContext.getOptionGroup();
    if (optionGroup == null) {
        optionGroup = validationContext.getProgramRuleActionValidationService().getOptionService().getOptionGroup(programRuleAction.getOptionGroup().getUid());
    }
    if (optionGroup == null) {
        log.debug(String.format("OptionGroup: %s associated with program rule: %s does not exist", programRuleAction.getOptionGroup().getUid(), rule.getName()));
        return ProgramRuleActionValidationResult.builder().valid(false).errorReport(new ErrorReport(Option.class, ErrorCode.E4043, programRuleAction.getOptionGroup().getUid(), rule.getName())).build();
    }
    return ProgramRuleActionValidationResult.builder().valid(true).build();
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) ProgramRuleActionValidationResult(org.hisp.dhis.programrule.ProgramRuleActionValidationResult) OptionGroup(org.hisp.dhis.option.OptionGroup) ProgramRule(org.hisp.dhis.programrule.ProgramRule)

Aggregations

ProgramRuleActionValidationResult (org.hisp.dhis.programrule.ProgramRuleActionValidationResult)4 ErrorReport (org.hisp.dhis.feedback.ErrorReport)3 ProgramRule (org.hisp.dhis.programrule.ProgramRule)3 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Slf4j (lombok.extern.slf4j.Slf4j)1 DataElement (org.hisp.dhis.dataelement.DataElement)1 ErrorCode (org.hisp.dhis.feedback.ErrorCode)1 Option (org.hisp.dhis.option.Option)1 OptionGroup (org.hisp.dhis.option.OptionGroup)1 Program (org.hisp.dhis.program.Program)1 ProgramStage (org.hisp.dhis.program.ProgramStage)1 ProgramRuleAction (org.hisp.dhis.programrule.ProgramRuleAction)1 ProgramRuleActionValidationContext (org.hisp.dhis.programrule.action.validation.ProgramRuleActionValidationContext)1 ProgramRuleActionValidator (org.hisp.dhis.programrule.action.validation.ProgramRuleActionValidator)1 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)1 Component (org.springframework.stereotype.Component)1