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