Search in sources :

Example 16 with TrackedEntityType

use of org.hisp.dhis.trackedentity.TrackedEntityType in project dhis2-core by dhis2.

the class ProgramSupplierAclIntegrationTest method verifyUserHasWriteAccessToTrackedEntityTypeForUserAccess.

@Test
void verifyUserHasWriteAccessToTrackedEntityTypeForUserAccess() {
    // Given
    final User user = createUser("A");
    final TrackedEntityType tet = createTrackedEntityType('A');
    manager.save(tet);
    UserAccess userAccess = new UserAccess(user, AccessStringHelper.DATA_READ_WRITE);
    tet.setUserAccesses(Collections.singleton(userAccess));
    manager.save(tet, false);
    final Program program = createProgram('A');
    program.setTrackedEntityType(tet);
    program.setPublicAccess(AccessStringHelper.DEFAULT);
    manager.save(program, false);
    manager.flush();
    // When
    final Map<String, Program> programs = programSupplier.get(getDefaultImportOptions(), singletonList(event));
    // Then
    assertThat(programs.keySet(), hasSize(1));
    assertTrue(aclService.canDataWrite(user, getTrackedEntityType(programs.get(program.getUid()))));
}
Also used : TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) User(org.hisp.dhis.user.User) Program(org.hisp.dhis.program.Program) UserAccess(org.hisp.dhis.user.UserAccess) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 17 with TrackedEntityType

use of org.hisp.dhis.trackedentity.TrackedEntityType in project dhis2-core by dhis2.

the class PreCheckDataRelationsValidationHookTest method verifyValidationSuccessForEnrollment.

@Test
void verifyValidationSuccessForEnrollment() {
    OrganisationUnit orgUnit = organisationUnit(ORG_UNIT_ID);
    when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(orgUnit);
    TrackedEntityType teiType = trackedEntityType(TEI_TYPE_ID);
    when(ctx.getProgram(PROGRAM_UID)).thenReturn(programWithRegistration(PROGRAM_UID, orgUnit, teiType));
    when(ctx.getProgramWithOrgUnitsMap()).thenReturn(Collections.singletonMap(PROGRAM_UID, Collections.singletonList(ORG_UNIT_ID)));
    when(ctx.getTrackedEntityInstance(TEI_ID)).thenReturn(trackedEntityInstance(TEI_TYPE_ID, teiType, orgUnit));
    Enrollment enrollment = Enrollment.builder().orgUnit(ORG_UNIT_ID).program(PROGRAM_UID).enrollment(CodeGenerator.generateUid()).trackedEntity(TEI_ID).build();
    hook.validateEnrollment(reporter, enrollment);
    assertFalse(reporter.hasErrors());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 18 with TrackedEntityType

use of org.hisp.dhis.trackedentity.TrackedEntityType in project dhis2-core by dhis2.

the class PreCheckDataRelationsValidationHookTest method trackedEntityType.

private TrackedEntityType trackedEntityType(String uid, char uniqueChar) {
    TrackedEntityType trackedEntityType = createTrackedEntityType(uniqueChar);
    trackedEntityType.setUid(uid);
    return trackedEntityType;
}
Also used : TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType)

Example 19 with TrackedEntityType

use of org.hisp.dhis.trackedentity.TrackedEntityType in project dhis2-core by dhis2.

the class JacksonRelationshipServiceTest method createRelationshipTypeWithTeiConstraint.

private RelationshipType createRelationshipTypeWithTeiConstraint() {
    RelationshipType relationshipType = new RelationshipType();
    relationshipType.setUid(CodeGenerator.generateUid());
    RelationshipConstraint from = new RelationshipConstraint();
    from.setRelationshipEntity(RelationshipEntity.TRACKED_ENTITY_INSTANCE);
    from.setTrackedEntityType(new TrackedEntityType("a", "b"));
    RelationshipConstraint to = rnd.nextObject(RelationshipConstraint.class);
    to.setRelationshipEntity(RelationshipEntity.TRACKED_ENTITY_INSTANCE);
    to.setTrackedEntityType(new TrackedEntityType("b", "c"));
    relationshipType.setFromConstraint(from);
    relationshipType.setToConstraint(to);
    return relationshipType;
}
Also used : TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) RelationshipConstraint(org.hisp.dhis.relationship.RelationshipConstraint) RelationshipType(org.hisp.dhis.relationship.RelationshipType)

Example 20 with TrackedEntityType

use of org.hisp.dhis.trackedentity.TrackedEntityType in project dhis2-core by dhis2.

the class PreCheckSecurityOwnershipValidationHook method validateTrackedEntity.

@Override
public void validateTrackedEntity(ValidationErrorReporter reporter, TrackedEntity trackedEntity) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    TrackerImportStrategy strategy = context.getStrategy(trackedEntity);
    TrackerBundle bundle = context.getBundle();
    User user = bundle.getUser();
    checkNotNull(user, USER_CANT_BE_NULL);
    checkNotNull(trackedEntity, TRACKED_ENTITY_CANT_BE_NULL);
    checkNotNull(trackedEntity.getOrgUnit(), ORGANISATION_UNIT_CANT_BE_NULL);
    // scope has to be checked
    if (strategy.isCreate() || strategy.isDelete()) {
        checkOrgUnitInCaptureScope(reporter, trackedEntity, context.getOrganisationUnit(trackedEntity.getOrgUnit()));
    } else // if its to update trackedEntity, search scope has to be checked
    {
        checkOrgUnitInSearchScope(reporter, trackedEntity, context.getOrganisationUnit(trackedEntity.getOrgUnit()));
    }
    if (strategy.isDelete()) {
        TrackedEntityInstance tei = context.getTrackedEntityInstance(trackedEntity.getTrackedEntity());
        if (tei.getProgramInstances().stream().anyMatch(pi -> !pi.isDeleted()) && !user.isAuthorized(Authorities.F_TEI_CASCADE_DELETE.getAuthority())) {
            TrackerErrorReport error = TrackerErrorReport.builder().uid(trackedEntity.getUid()).trackerType(TrackerType.TRACKED_ENTITY).errorCode(E1100).addArg(user).addArg(tei).build(bundle);
            reporter.addError(error);
        }
    }
    TrackedEntityType trackedEntityType = context.getTrackedEntityType(trackedEntity.getTrackedEntityType());
    checkTeiTypeWriteAccess(reporter, trackedEntity.getUid(), trackedEntityType);
}
Also used : EVENT_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.EVENT_CANT_BE_NULL) Authorities(org.hisp.dhis.security.Authorities) CategoryOption(org.hisp.dhis.category.CategoryOption) RequiredArgsConstructor(lombok.RequiredArgsConstructor) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) E1100(org.hisp.dhis.tracker.report.TrackerErrorCode.E1100) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Relationship(org.hisp.dhis.tracker.domain.Relationship) E1083(org.hisp.dhis.tracker.report.TrackerErrorCode.E1083) Program(org.hisp.dhis.program.Program) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) PROGRAM_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.PROGRAM_CANT_BE_NULL) TRACKED_ENTITY_TYPE_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.TRACKED_ENTITY_TYPE_CANT_BE_NULL) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) TRACKED_ENTITY_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.TRACKED_ENTITY_CANT_BE_NULL) USER_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.USER_CANT_BE_NULL) ProgramInstance(org.hisp.dhis.program.ProgramInstance) PROGRAM_STAGE_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.PROGRAM_STAGE_CANT_BE_NULL) User(org.hisp.dhis.user.User) ORGANISATION_UNIT_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.ORGANISATION_UNIT_CANT_BE_NULL) PROGRAM_INSTANCE_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.PROGRAM_INSTANCE_CANT_BE_NULL) Event(org.hisp.dhis.tracker.domain.Event) TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport) NonNull(lombok.NonNull) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) ENROLLMENT_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.ENROLLMENT_CANT_BE_NULL) EventStatus(org.hisp.dhis.event.EventStatus) TrackerType(org.hisp.dhis.tracker.TrackerType) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) ProgramStage(org.hisp.dhis.program.ProgramStage) TrackerErrorCode(org.hisp.dhis.tracker.report.TrackerErrorCode) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackerOwnershipManager(org.hisp.dhis.trackedentity.TrackerOwnershipManager) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) E1103(org.hisp.dhis.tracker.report.TrackerErrorCode.E1103) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) AclService(org.hisp.dhis.security.acl.AclService) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) TrackerDto(org.hisp.dhis.tracker.domain.TrackerDto) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) User(org.hisp.dhis.user.User) 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) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance)

Aggregations

TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)57 Test (org.junit.jupiter.api.Test)27 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)22 Program (org.hisp.dhis.program.Program)19 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)16 User (org.hisp.dhis.user.User)16 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)15 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)15 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)12 ProgramInstance (org.hisp.dhis.program.ProgramInstance)11 Date (java.util.Date)10 HashSet (java.util.HashSet)10 ProgramStage (org.hisp.dhis.program.ProgramStage)8 CategoryCombo (org.hisp.dhis.category.CategoryCombo)6 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)6 RelationshipType (org.hisp.dhis.relationship.RelationshipType)6 TrackedEntityTypeAttribute (org.hisp.dhis.trackedentity.TrackedEntityTypeAttribute)6 Collectors (java.util.stream.Collectors)5 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)5 CategoryOption (org.hisp.dhis.category.CategoryOption)5