Search in sources :

Example 1 with E1076

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);
    }
}
Also used : Attribute(org.hisp.dhis.tracker.domain.Attribute) Constant(org.hisp.dhis.tracker.util.Constant) HashMap(java.util.HashMap) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) E1084(org.hisp.dhis.tracker.report.TrackerErrorCode.E1084) E1085(org.hisp.dhis.tracker.report.TrackerErrorCode.E1085) TRACKED_ENTITY_ATTRIBUTE_VALUE_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.TRACKED_ENTITY_ATTRIBUTE_VALUE_CANT_BE_NULL) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Map(java.util.Map) E1090(org.hisp.dhis.tracker.report.TrackerErrorCode.E1090) ATTRIBUTE_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.ATTRIBUTE_CANT_BE_NULL) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) DhisConfigurationProvider(org.hisp.dhis.external.conf.DhisConfigurationProvider) FileResource(org.hisp.dhis.fileresource.FileResource) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) E1077(org.hisp.dhis.tracker.report.TrackerErrorCode.E1077) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) E1076(org.hisp.dhis.tracker.report.TrackerErrorCode.E1076) Set(java.util.Set) E1112(org.hisp.dhis.tracker.report.TrackerErrorCode.E1112) TrackedAttributeValidationService(org.hisp.dhis.tracker.validation.service.attribute.TrackedAttributeValidationService) Collectors(java.util.stream.Collectors) TrackedEntityTypeAttribute(org.hisp.dhis.trackedentity.TrackedEntityTypeAttribute) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ValidationUtils.dataValueIsValid(org.hisp.dhis.system.util.ValidationUtils.dataValueIsValid) Component(org.springframework.stereotype.Component) E1009(org.hisp.dhis.tracker.report.TrackerErrorCode.E1009) E1006(org.hisp.dhis.tracker.report.TrackerErrorCode.E1006) Optional(java.util.Optional) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) HashMap(java.util.HashMap) Attribute(org.hisp.dhis.tracker.domain.Attribute) TrackedEntityTypeAttribute(org.hisp.dhis.trackedentity.TrackedEntityTypeAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) TrackedEntityTypeAttribute(org.hisp.dhis.trackedentity.TrackedEntityTypeAttribute)

Example 2 with E1076

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());
    }
}
Also used : Attribute(org.hisp.dhis.tracker.domain.Attribute) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Program(org.hisp.dhis.program.Program) E1019(org.hisp.dhis.tracker.report.TrackerErrorCode.E1019) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) E1018(org.hisp.dhis.tracker.report.TrackerErrorCode.E1018) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Map(java.util.Map) TrackerIdScheme(org.hisp.dhis.tracker.TrackerIdScheme) ReferenceTrackerEntity(org.hisp.dhis.tracker.preheat.ReferenceTrackerEntity) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) E1076(org.hisp.dhis.tracker.report.TrackerErrorCode.E1076) Set(java.util.Set) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) TrackedAttributeValidationService(org.hisp.dhis.tracker.validation.service.attribute.TrackedAttributeValidationService) Streams(com.google.common.collect.Streams) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) E1075(org.hisp.dhis.tracker.report.TrackerErrorCode.E1075) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Component(org.springframework.stereotype.Component) E1006(org.hisp.dhis.tracker.report.TrackerErrorCode.E1006) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) Optional(java.util.Optional) Collections(java.util.Collections) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute)

Aggregations

Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)2 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)2 TrackedEntityAttributeValue (org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue)2 Attribute (org.hisp.dhis.tracker.domain.Attribute)2 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)2 E1006 (org.hisp.dhis.tracker.report.TrackerErrorCode.E1006)2 E1076 (org.hisp.dhis.tracker.report.TrackerErrorCode.E1076)2 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)2 TrackerImportValidationContext (org.hisp.dhis.tracker.validation.TrackerImportValidationContext)2 TrackedAttributeValidationService (org.hisp.dhis.tracker.validation.service.attribute.TrackedAttributeValidationService)2 Component (org.springframework.stereotype.Component)2 Maps (com.google.common.collect.Maps)1 Streams (com.google.common.collect.Streams)1