Search in sources :

Example 11 with TrackerErrorReport

use of org.hisp.dhis.tracker.report.TrackerErrorReport in project dhis2-core by dhis2.

the class AttributeValidationHook method validateAttrValueType.

protected void validateAttrValueType(ValidationErrorReporter errorReporter, TrackerDto dto, Attribute attr, TrackedEntityAttribute teAttr) {
    checkNotNull(attr, ATTRIBUTE_CANT_BE_NULL);
    checkNotNull(teAttr, TRACKED_ENTITY_ATTRIBUTE_CANT_BE_NULL);
    ValueType valueType = teAttr.getValueType();
    TrackerImportValidationContext context = errorReporter.getValidationContext();
    String error;
    if (valueType.equals(ValueType.ORGANISATION_UNIT)) {
        error = context.getOrganisationUnit(attr.getValue()) == null ? " Value " + attr.getValue() + " is not a valid org unit value" : null;
    } else if (valueType.equals(ValueType.USERNAME)) {
        error = context.usernameExists(attr.getValue()) ? null : " Value " + attr.getValue() + " is not a valid username value";
    } else {
        // org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:945)
        try {
            error = teAttrService.validateValueType(teAttr, attr.getValue());
        } catch (Exception e) {
            error = e.getMessage();
        }
    }
    if (error != null) {
        TrackerBundle bundle = context.getBundle();
        TrackerErrorReport err = TrackerErrorReport.builder().uid(dto.getUid()).trackerType(dto.getTrackerType()).errorCode(TrackerErrorCode.E1007).addArg(valueType.toString()).addArg(error).build(bundle);
        errorReporter.addError(err);
    }
}
Also used : ValueType(org.hisp.dhis.common.ValueType) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport)

Example 12 with TrackerErrorReport

use of org.hisp.dhis.tracker.report.TrackerErrorReport in project dhis2-core by dhis2.

the class ReportSummaryDeleteIntegrationTest method testNonExistentEnrollment.

@Test
void testNonExistentEnrollment() throws IOException {
    TrackerImportParams params = fromJson("tracker/non_existent_enrollment_basic_data_for_deletion.json");
    params.setImportStrategy(TrackerImportStrategy.DELETE);
    TrackerImportReport importReport = trackerImportService.importTracker(params);
    assertEquals(TrackerStatus.ERROR, importReport.getStatus());
    assertTrue(importReport.getValidationReport().hasErrors());
    List<TrackerErrorReport> trackerErrorReports = importReport.getValidationReport().getErrors();
    assertEquals(TrackerErrorCode.E1081, trackerErrorReports.get(0).getErrorCode());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 13 with TrackerErrorReport

use of org.hisp.dhis.tracker.report.TrackerErrorReport in project dhis2-core by dhis2.

the class PreCheckSecurityOwnershipValidationHook method checkProgramReadAccess.

private void checkProgramReadAccess(ValidationErrorReporter reporter, TrackerDto dto, User user, Program program) {
    checkNotNull(user, USER_CANT_BE_NULL);
    checkNotNull(program, PROGRAM_CANT_BE_NULL);
    if (!aclService.canDataRead(user, program)) {
        TrackerErrorReport error = TrackerErrorReport.builder().uid(dto.getUid()).trackerType(dto.getTrackerType()).errorCode(TrackerErrorCode.E1096).addArg(user).addArg(program).build(reporter.getValidationContext().getBundle());
        reporter.addError(error);
    }
}
Also used : TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport)

Example 14 with TrackerErrorReport

use of org.hisp.dhis.tracker.report.TrackerErrorReport in project dhis2-core by dhis2.

the class PreCheckSecurityOwnershipValidationHook method validateEnrollment.

@Override
public void validateEnrollment(ValidationErrorReporter reporter, Enrollment enrollment) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    TrackerImportStrategy strategy = context.getStrategy(enrollment);
    TrackerBundle bundle = context.getBundle();
    User user = bundle.getUser();
    Program program = strategy.isUpdateOrDelete() ? context.getProgramInstance(enrollment.getEnrollment()).getProgram() : context.getProgram(enrollment.getProgram());
    OrganisationUnit ownerOrgUnit = context.getOwnerOrganisationUnit(enrollment.getTrackedEntity(), enrollment.getProgram());
    checkNotNull(user, USER_CANT_BE_NULL);
    checkNotNull(enrollment, ENROLLMENT_CANT_BE_NULL);
    checkNotNull(program, PROGRAM_CANT_BE_NULL);
    checkEnrollmentOrgUnit(reporter, context, strategy, enrollment, program);
    if (strategy.isDelete()) {
        boolean hasNonDeletedEvents = context.programInstanceHasEvents(enrollment.getEnrollment());
        boolean hasNotCascadeDeleteAuthority = !user.isAuthorized(Authorities.F_ENROLLMENT_CASCADE_DELETE.getAuthority());
        if (hasNonDeletedEvents && hasNotCascadeDeleteAuthority) {
            TrackerErrorReport error = TrackerErrorReport.builder().uid(enrollment.getUid()).trackerType(TrackerType.ENROLLMENT).errorCode(E1103).addArg(user).addArg(enrollment.getEnrollment()).build(bundle);
            reporter.addError(error);
        }
    }
    checkWriteEnrollmentAccess(reporter, enrollment, program, context, ownerOrgUnit);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) Program(org.hisp.dhis.program.Program) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport)

Example 15 with TrackerErrorReport

use of org.hisp.dhis.tracker.report.TrackerErrorReport in project dhis2-core by dhis2.

the class PreCheckSecurityOwnershipValidationHook method checkOrgUnitInSearchScope.

private void checkOrgUnitInSearchScope(ValidationErrorReporter reporter, TrackerDto dto, OrganisationUnit orgUnit) {
    TrackerBundle bundle = reporter.getValidationContext().getBundle();
    User user = bundle.getUser();
    checkNotNull(user, USER_CANT_BE_NULL);
    checkNotNull(orgUnit, ORGANISATION_UNIT_CANT_BE_NULL);
    if (!organisationUnitService.isInUserSearchHierarchyCached(user, orgUnit)) {
        TrackerErrorReport error = TrackerErrorReport.builder().uid(dto.getUid()).trackerType(dto.getTrackerType()).errorCode(TrackerErrorCode.E1003).addArg(orgUnit).addArg(user).build(reporter.getValidationContext().getBundle());
        reporter.addError(error);
    }
}
Also used : User(org.hisp.dhis.user.User) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport)

Aggregations

TrackerErrorReport (org.hisp.dhis.tracker.report.TrackerErrorReport)20 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)9 User (org.hisp.dhis.user.User)7 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)5 TrackerImportValidationContext (org.hisp.dhis.tracker.validation.TrackerImportValidationContext)5 Relationship (org.hisp.dhis.tracker.domain.Relationship)4 CategoryOption (org.hisp.dhis.category.CategoryOption)3 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)3 Program (org.hisp.dhis.program.Program)3 ProgramStage (org.hisp.dhis.program.ProgramStage)3 TrackerImportStrategy (org.hisp.dhis.tracker.TrackerImportStrategy)3 Event (org.hisp.dhis.tracker.domain.Event)3 TrackerErrorCode (org.hisp.dhis.tracker.report.TrackerErrorCode)3 Test (org.junit.jupiter.api.Test)3 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 Collectors (java.util.stream.Collectors)2 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)2 EventStatus (org.hisp.dhis.event.EventStatus)2 FeatureType (org.hisp.dhis.organisationunit.FeatureType)2 ProgramInstance (org.hisp.dhis.program.ProgramInstance)2