use of org.hisp.dhis.tracker.report.TrackerErrorCode.E1076 in project dhis2-core by dhis2.
the class TrackedEntityAttributeValidationHook method validateAttributes.
protected void validateAttributes(ValidationErrorReporter reporter, TrackedEntity trackedEntity, TrackedEntityInstance tei, OrganisationUnit orgUnit, TrackedEntityType trackedEntityType) {
checkNotNull(trackedEntity, TrackerImporterAssertErrors.TRACKED_ENTITY_CANT_BE_NULL);
checkNotNull(trackedEntityType, TrackerImporterAssertErrors.TRACKED_ENTITY_TYPE_CANT_BE_NULL);
Map<String, TrackedEntityAttributeValue> valueMap = new HashMap<>();
if (tei != null) {
valueMap = tei.getTrackedEntityAttributeValues().stream().collect(Collectors.toMap(v -> v.getAttribute().getUid(), v -> v));
}
for (Attribute attribute : trackedEntity.getAttributes()) {
TrackedEntityAttribute tea = reporter.getValidationContext().getTrackedEntityAttribute(attribute.getAttribute());
if (tea == null) {
reporter.addError(trackedEntity, E1006, attribute.getAttribute());
continue;
}
if (attribute.getValue() == null) {
Optional<TrackedEntityTypeAttribute> optionalTea = Optional.of(trackedEntityType).map(tet -> tet.getTrackedEntityTypeAttributes().stream()).flatMap(tetAtts -> tetAtts.filter(teaAtt -> teaAtt.getTrackedEntityAttribute().getUid().equals(attribute.getAttribute()) && teaAtt.isMandatory() != null && teaAtt.isMandatory()).findFirst());
if (optionalTea.isPresent())
reporter.addError(trackedEntity, E1076, TrackedEntityAttribute.class.getSimpleName(), attribute.getAttribute());
continue;
}
validateAttributeValue(reporter, trackedEntity, tea, attribute.getValue());
validateAttrValueType(reporter, trackedEntity, attribute, tea);
validateOptionSet(reporter, trackedEntity, tea, attribute.getValue());
validateAttributeUniqueness(reporter, trackedEntity, attribute.getValue(), tea, tei, orgUnit);
validateFileNotAlreadyAssigned(reporter, trackedEntity, attribute, valueMap);
}
}
use of org.hisp.dhis.tracker.report.TrackerErrorCode.E1076 in project dhis2-core by dhis2.
the class EnrollmentAttributeValidationHook method validateRequiredProperties.
protected void validateRequiredProperties(ValidationErrorReporter reporter, Enrollment enrollment, Attribute attribute, Program program) {
reporter.addErrorIfNull(attribute.getAttribute(), enrollment, E1075, attribute);
Optional<ProgramTrackedEntityAttribute> optionalTrackedAttr = program.getProgramAttributes().stream().filter(pa -> pa.getAttribute().getUid().equals(attribute.getAttribute()) && pa.isMandatory()).findFirst();
if (optionalTrackedAttr.isPresent()) {
reporter.addErrorIfNull(attribute.getValue(), enrollment, E1076, TrackedEntityAttribute.class.getSimpleName(), attribute.getAttribute());
}
if (attribute.getAttribute() != null) {
TrackedEntityAttribute teAttribute = reporter.getValidationContext().getTrackedEntityAttribute(attribute.getAttribute());
reporter.addErrorIfNull(teAttribute, enrollment, E1006, attribute.getAttribute());
}
}
Aggregations