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;
}
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();
}
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();
}
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();
}
Aggregations