Search in sources :

Example 6 with TrackerErrorReport

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

the class PreCheckSecurityOwnershipValidationHook method checkWriteCategoryOptionComboAccess.

public void checkWriteCategoryOptionComboAccess(ValidationErrorReporter reporter, TrackerDto dto, CategoryOptionCombo categoryOptionCombo) {
    TrackerBundle bundle = reporter.getValidationContext().getBundle();
    User user = bundle.getUser();
    checkNotNull(user, USER_CANT_BE_NULL);
    checkNotNull(categoryOptionCombo, TrackerImporterAssertErrors.CATEGORY_OPTION_COMBO_CANT_BE_NULL);
    for (CategoryOption categoryOption : categoryOptionCombo.getCategoryOptions()) {
        if (!aclService.canDataWrite(user, categoryOption)) {
            TrackerErrorReport error = TrackerErrorReport.builder().uid(dto.getUid()).trackerType(dto.getTrackerType()).errorCode(TrackerErrorCode.E1099).addArg(user).addArg(categoryOption).build(reporter.getValidationContext().getBundle());
            reporter.addError(error);
        }
    }
}
Also used : User(org.hisp.dhis.user.User) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) CategoryOption(org.hisp.dhis.category.CategoryOption) TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport)

Example 7 with TrackerErrorReport

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

the class PreCheckSecurityOwnershipValidationHook method validateUpdateAndDeleteEvent.

private void validateUpdateAndDeleteEvent(ValidationErrorReporter reporter, Event event, ProgramStageInstance programStageInstance, String teiUid, OrganisationUnit ownerOrgUnit) {
    TrackerImportStrategy strategy = reporter.getValidationContext().getStrategy(event);
    User user = reporter.getValidationContext().getBundle().getUser();
    checkNotNull(user, USER_CANT_BE_NULL);
    checkNotNull(programStageInstance, PROGRAM_INSTANCE_CANT_BE_NULL);
    checkNotNull(event, EVENT_CANT_BE_NULL);
    checkEventWriteAccess(reporter, event, programStageInstance.getProgramStage(), programStageInstance.getOrganisationUnit(), ownerOrgUnit, programStageInstance.getAttributeOptionCombo(), teiUid, programStageInstance.isCreatableInSearchScope());
    if (strategy.isUpdate() && EventStatus.COMPLETED == programStageInstance.getStatus() && event.getStatus() != programStageInstance.getStatus() && (!user.isSuper() && !user.isAuthorized("F_UNCOMPLETE_EVENT"))) {
        TrackerErrorReport error = TrackerErrorReport.builder().uid(event.getUid()).trackerType(TrackerType.EVENT).errorCode(E1083).addArg(user).build(reporter.getValidationContext().getBundle());
        reporter.addError(error);
    }
}
Also used : User(org.hisp.dhis.user.User) TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport)

Example 8 with TrackerErrorReport

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

the class ValidationUtils method validateGeometry.

static void validateGeometry(ValidationErrorReporter reporter, TrackerDto dto, Geometry geometry, FeatureType featureType) {
    checkNotNull(geometry, GEOMETRY_CANT_BE_NULL);
    if (featureType == null) {
        TrackerErrorReport error = TrackerErrorReport.builder().uid(dto.getUid()).trackerType(dto.getTrackerType()).errorCode(TrackerErrorCode.E1074).build(reporter.getValidationContext().getBundle());
        reporter.addError(error);
        return;
    }
    FeatureType typeFromName = FeatureType.getTypeFromName(geometry.getGeometryType());
    if (FeatureType.NONE == featureType || featureType != typeFromName) {
        TrackerErrorReport error = TrackerErrorReport.builder().uid(dto.getUid()).trackerType(dto.getTrackerType()).errorCode(TrackerErrorCode.E1012).addArg(featureType.name()).build(reporter.getValidationContext().getBundle());
        reporter.addError(error);
    }
}
Also used : FeatureType(org.hisp.dhis.organisationunit.FeatureType) TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport)

Example 9 with TrackerErrorReport

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

the class ValidationUtils method addIssuesToReporter.

public static void addIssuesToReporter(ValidationErrorReporter reporter, TrackerDto dto, List<ProgramRuleIssue> programRuleIssues) {
    programRuleIssues.stream().filter(issue -> issue.getIssueType().equals(ERROR)).forEach(issue -> {
        List<String> args = Lists.newArrayList(issue.getRuleUid());
        args.addAll(issue.getArgs());
        TrackerErrorReport error = TrackerErrorReport.builder().uid(dto.getUid()).trackerType(dto.getTrackerType()).errorCode(issue.getIssueCode()).addArgs(args.toArray()).build(reporter.getValidationContext().getBundle());
        reporter.addError(error);
    });
    programRuleIssues.stream().filter(issue -> issue.getIssueType().equals(WARNING)).forEach(issue -> {
        List<String> args = Lists.newArrayList(issue.getRuleUid());
        args.addAll(issue.getArgs());
        TrackerWarningReport warning = TrackerWarningReport.builder().uid(dto.getUid()).trackerType(dto.getTrackerType()).warningCode(issue.getIssueCode()).addArgs(args.toArray()).build(reporter.getValidationContext().getBundle());
        reporter.addWarning(warning);
    });
}
Also used : WARNING(org.hisp.dhis.tracker.programrule.IssueType.WARNING) DataValue(org.hisp.dhis.tracker.domain.DataValue) ERROR(org.hisp.dhis.tracker.programrule.IssueType.ERROR) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) StringUtils.isNotEmpty(org.apache.commons.lang3.StringUtils.isNotEmpty) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) Note(org.hisp.dhis.tracker.domain.Note) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) ProgramRuleIssue(org.hisp.dhis.tracker.programrule.ProgramRuleIssue) Event(org.hisp.dhis.tracker.domain.Event) TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) EventStatus(org.hisp.dhis.event.EventStatus) Collectors(java.util.stream.Collectors) ProgramStage(org.hisp.dhis.program.ProgramStage) TrackerErrorCode(org.hisp.dhis.tracker.report.TrackerErrorCode) List(java.util.List) FeatureType(org.hisp.dhis.organisationunit.FeatureType) TrackerDto(org.hisp.dhis.tracker.domain.TrackerDto) Geometry(org.locationtech.jts.geom.Geometry) GEOMETRY_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.GEOMETRY_CANT_BE_NULL) ValidationStrategy(org.hisp.dhis.program.ValidationStrategy) TrackerWarningReport(org.hisp.dhis.tracker.report.TrackerWarningReport) TrackerWarningReport(org.hisp.dhis.tracker.report.TrackerWarningReport) TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport)

Example 10 with TrackerErrorReport

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

the class AttributeValidationHook method validateAttributeUniqueness.

protected void validateAttributeUniqueness(ValidationErrorReporter errorReporter, TrackerDto dto, String value, TrackedEntityAttribute trackedEntityAttribute, TrackedEntityInstance trackedEntityInstance, OrganisationUnit organisationUnit) {
    checkNotNull(trackedEntityAttribute, TRACKED_ENTITY_ATTRIBUTE_CANT_BE_NULL);
    if (Boolean.FALSE.equals(trackedEntityAttribute.isUnique()))
        return;
    List<UniqueAttributeValue> uniqueAttributeValues = errorReporter.getValidationContext().getBundle().getPreheat().getUniqueAttributeValues();
    for (UniqueAttributeValue uniqueAttributeValue : uniqueAttributeValues) {
        boolean isTeaUniqueInOrgUnitScope = !trackedEntityAttribute.getOrgunitScope() || Objects.equals(organisationUnit.getUid(), uniqueAttributeValue.getOrgUnitId());
        boolean isTheSameTea = Objects.equals(uniqueAttributeValue.getAttributeUid(), trackedEntityAttribute.getUid());
        boolean hasTheSameValue = Objects.equals(uniqueAttributeValue.getValue(), value);
        boolean isNotSameTei = trackedEntityInstance == null || !Objects.equals(trackedEntityInstance.getUid(), uniqueAttributeValue.getTeiUid());
        if (isTeaUniqueInOrgUnitScope && isTheSameTea && hasTheSameValue && isNotSameTei) {
            TrackerBundle bundle = errorReporter.getValidationContext().getBundle();
            TrackerErrorReport err = TrackerErrorReport.builder().uid(dto.getUid()).trackerType(dto.getTrackerType()).errorCode(TrackerErrorCode.E1064).addArg(value).addArg(trackedEntityAttribute.getUid()).build(bundle);
            errorReporter.addError(err);
            return;
        }
    }
}
Also used : UniqueAttributeValue(org.hisp.dhis.tracker.preheat.UniqueAttributeValue) 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