use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.
the class SetMandatoryFieldValidator method checkMandatoryDataElement.
private List<ProgramRuleIssue> checkMandatoryDataElement(Event event, List<EventActionRule> actionRules, TrackerBundle bundle) {
ProgramStage programStage = bundle.getPreheat().get(ProgramStage.class, event.getProgramStage());
Map<String, EventActionRule> mandatoryDataElementsByActionRule = actionRules.stream().filter(eventActionRule -> eventActionRule.getAttributeType() == AttributeType.DATA_ELEMENT).collect(Collectors.toMap(EventActionRule::getField, Function.identity()));
return validateMandatoryDataValue(programStage, event, Lists.newArrayList(mandatoryDataElementsByActionRule.keySet())).stream().map(e -> new ProgramRuleIssue(mandatoryDataElementsByActionRule.get(e).getRuleUid(), TrackerErrorCode.E1301, Lists.newArrayList(e), IssueType.ERROR)).collect(Collectors.toList());
}
use of org.hisp.dhis.tracker.bundle.TrackerBundle 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);
}
use of org.hisp.dhis.tracker.bundle.TrackerBundle 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);
}
}
use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.
the class PreCheckSecurityOwnershipValidationHook method checkWriteEnrollmentAccess.
private void checkWriteEnrollmentAccess(ValidationErrorReporter reporter, Enrollment enrollment, Program program, TrackerImportValidationContext context, OrganisationUnit ownerOrgUnit) {
TrackerBundle bundle = reporter.getValidationContext().getBundle();
User user = bundle.getUser();
checkNotNull(user, USER_CANT_BE_NULL);
checkNotNull(program, PROGRAM_CANT_BE_NULL);
checkProgramWriteAccess(reporter, enrollment, user, program);
if (program.isRegistration()) {
String trackedEntity = context.getStrategy(enrollment).isDelete() ? context.getProgramInstance(enrollment.getEnrollment()).getEntityInstance().getUid() : enrollment.getTrackedEntity();
checkNotNull(program.getTrackedEntityType(), TRACKED_ENTITY_TYPE_CANT_BE_NULL);
checkTeiTypeAndTeiProgramAccess(reporter, enrollment, user, trackedEntity, ownerOrgUnit, program);
}
}
use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.
the class DuplicateRelationshipsPreProcessorTest method test_on_identical_rels_1_is_removed.
/*
* Verifies that:
*
* - given 2 identical relationships
*
* - one is removed
*/
@Test
void test_on_identical_rels_1_is_removed() {
String relType = REL_TYPE_NONBIDIRECTIONAL_UID;
String fromTeiUid = CodeGenerator.generateUid();
String toTeiUid = CodeGenerator.generateUid();
Relationship relationship1 = Relationship.builder().relationship(CodeGenerator.generateUid()).relationshipType(relType).from(RelationshipItem.builder().trackedEntity(fromTeiUid).build()).to(RelationshipItem.builder().trackedEntity(toTeiUid).build()).build();
Relationship relationship2 = Relationship.builder().relationship(CodeGenerator.generateUid()).relationshipType(relType).from(RelationshipItem.builder().trackedEntity(fromTeiUid).build()).to(RelationshipItem.builder().trackedEntity(toTeiUid).build()).build();
TrackerBundle bundle = TrackerBundle.builder().preheat(this.preheat).relationships(Lists.newArrayList(relationship1, relationship2)).build();
preProcessor.process(bundle);
assertThat(bundle.getRelationships(), hasSize(1));
}
Aggregations