Search in sources :

Example 26 with TrackedEntityType

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

the class TrackedEntityAttributeValidationHookTest method shouldFailValidationWhenValueIsNullAndAttributeIsMandatory.

@Test
void shouldFailValidationWhenValueIsNullAndAttributeIsMandatory() {
    TrackedEntity trackedEntity = TrackedEntity.builder().attributes(Collections.singletonList(Attribute.builder().attribute("trackedEntityAttribute").build())).trackedEntityType("trackedEntityType").build();
    TrackedEntityTypeAttribute trackedEntityTypeAttribute = new TrackedEntityTypeAttribute();
    TrackedEntityAttribute trackedEntityAttribute = new TrackedEntityAttribute();
    trackedEntityAttribute.setUid("trackedEntityAttribute");
    trackedEntityAttribute.setValueType(ValueType.TEXT);
    trackedEntityTypeAttribute.setTrackedEntityAttribute(trackedEntityAttribute);
    trackedEntityTypeAttribute.setMandatory(true);
    TrackedEntityType trackedEntityType = new TrackedEntityType();
    trackedEntityType.setTrackedEntityTypeAttributes(Collections.singletonList(trackedEntityTypeAttribute));
    when(validationContext.getTrackedEntityAttribute("trackedEntityAttribute")).thenReturn(trackedEntityAttribute);
    when(validationContext.getTrackedEntityType(anyString())).thenReturn(trackedEntityType);
    ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
    trackedEntityAttributeValidationHook.validateTrackedEntity(reporter, trackedEntity);
    assertTrue(reporter.hasErrors());
    assertEquals(1, reporter.getReportList().size());
    assertEquals(TrackerErrorCode.E1076, reporter.getReportList().get(0).getErrorCode());
}
Also used : TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) TrackedEntityTypeAttribute(org.hisp.dhis.trackedentity.TrackedEntityTypeAttribute) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 27 with TrackedEntityType

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

the class TrackedEntityAttributeValidationHookTest method shouldFailMissingAttributeValue.

@Test
void shouldFailMissingAttributeValue() {
    String tea = "tea";
    String tet = "tet";
    TrackedEntity trackedEntity = TrackedEntity.builder().attributes(Collections.singletonList(Attribute.builder().attribute(tea).build())).trackedEntityType(tet).build();
    TrackedEntityType trackedEntityType = new TrackedEntityType();
    TrackedEntityTypeAttribute trackedEntityTypeAttribute = new TrackedEntityTypeAttribute();
    trackedEntityTypeAttribute.setMandatory(true);
    TrackedEntityAttribute trackedEntityAttribute = new TrackedEntityAttribute();
    trackedEntityAttribute.setUid(tea);
    trackedEntityTypeAttribute.setTrackedEntityAttribute(trackedEntityAttribute);
    trackedEntityType.setTrackedEntityTypeAttributes(Collections.singletonList(trackedEntityTypeAttribute));
    when(validationContext.getTrackedEntityType(tet)).thenReturn(trackedEntityType);
    when(validationContext.getTrackedEntityAttribute(tea)).thenReturn(trackedEntityAttribute);
    ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
    trackedEntityAttributeValidationHook.validateTrackedEntity(reporter, trackedEntity);
    assertTrue(reporter.hasErrors());
    assertEquals(1, reporter.getReportList().size());
    assertEquals(1, reporter.getReportList().stream().filter(e -> e.getErrorCode() == TrackerErrorCode.E1076).count());
}
Also used : TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) TrackedEntityTypeAttribute(org.hisp.dhis.trackedentity.TrackedEntityTypeAttribute) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 28 with TrackedEntityType

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

the class DeduplicationServiceMergeIntegrationTest method shouldManualMergeWithUserGroupOfProgram.

@Test
void shouldManualMergeWithUserGroupOfProgram() throws PotentialDuplicateConflictException, PotentialDuplicateForbiddenException {
    OrganisationUnit ou = createOrganisationUnit("OU_A");
    organisationUnitService.addOrganisationUnit(ou);
    User user = creteUser(new HashSet<>(Collections.singletonList(ou)), "F_TRACKED_ENTITY_MERGE");
    Sharing sharing = getUserSharing(user, AccessStringHelper.FULL);
    TrackedEntityType trackedEntityType = createTrackedEntityType('A');
    trackedEntityTypeService.addTrackedEntityType(trackedEntityType);
    trackedEntityType.setSharing(sharing);
    trackedEntityTypeService.updateTrackedEntityType(trackedEntityType);
    TrackedEntityInstance original = createTrackedEntityInstance(ou);
    TrackedEntityInstance duplicate = createTrackedEntityInstance(ou);
    original.setTrackedEntityType(trackedEntityType);
    duplicate.setTrackedEntityType(trackedEntityType);
    trackedEntityInstanceService.addTrackedEntityInstance(original);
    trackedEntityInstanceService.addTrackedEntityInstance(duplicate);
    Program program = createProgram('A');
    Program program1 = createProgram('B');
    programService.addProgram(program);
    programService.addProgram(program1);
    program.setSharing(sharing);
    program1.setSharing(sharing);
    ProgramInstance programInstance1 = createProgramInstance(program, original, ou);
    ProgramInstance programInstance2 = createProgramInstance(program1, duplicate, ou);
    programInstanceService.addProgramInstance(programInstance1);
    programInstanceService.addProgramInstance(programInstance2);
    programInstanceService.updateProgramInstance(programInstance1);
    programInstanceService.updateProgramInstance(programInstance2);
    original.getProgramInstances().add(programInstance1);
    duplicate.getProgramInstances().add(programInstance2);
    trackedEntityInstanceService.updateTrackedEntityInstance(original);
    trackedEntityInstanceService.updateTrackedEntityInstance(duplicate);
    PotentialDuplicate potentialDuplicate = new PotentialDuplicate(original.getUid(), duplicate.getUid());
    deduplicationService.addPotentialDuplicate(potentialDuplicate);
    DeduplicationMergeParams deduplicationMergeParams = DeduplicationMergeParams.builder().potentialDuplicate(potentialDuplicate).original(original).duplicate(duplicate).build();
    Date lastUpdatedOriginal = trackedEntityInstanceService.getTrackedEntityInstance(original.getUid()).getLastUpdated();
    deduplicationService.autoMerge(deduplicationMergeParams);
    assertEquals(deduplicationService.getPotentialDuplicateByUid(potentialDuplicate.getUid()).getStatus(), DeduplicationStatus.MERGED);
    assertTrue(trackedEntityInstanceService.getTrackedEntityInstance(original.getUid()).getLastUpdated().getTime() > lastUpdatedOriginal.getTime());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) User(org.hisp.dhis.user.User) Program(org.hisp.dhis.program.Program) Sharing(org.hisp.dhis.user.sharing.Sharing) ProgramInstance(org.hisp.dhis.program.ProgramInstance) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 29 with TrackedEntityType

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

the class DeduplicationServiceTest method setUp.

@BeforeEach
void setUp() {
    PotentialDuplicate potentialDuplicate = new PotentialDuplicate("original", "duplicate");
    deduplicationMergeParams = DeduplicationMergeParams.builder().potentialDuplicate(potentialDuplicate).original(trackedEntityInstanceA).duplicate(trackedEntityInstanceB).mergeObject(MergeObject.builder().build()).build();
    String uidPerson = "uidPerson";
    TrackedEntityType trackedEntityPerson = new TrackedEntityType();
    trackedEntityPerson.setName("Person");
    trackedEntityPerson.setUid(uidPerson);
    when(trackedEntityInstanceA.getTrackedEntityType()).thenReturn(trackedEntityPerson);
    when(trackedEntityInstanceB.getTrackedEntityType()).thenReturn(trackedEntityPerson);
    when(deduplicationHelper.getUserAccessErrors(any(), any(), any())).thenReturn(null);
    setUpPrograms();
    setAttributeValues();
}
Also used : TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 30 with TrackedEntityType

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

the class DeduplicationServiceTest method shouldNotBeAutoMergeableDifferentTrackedEntityType.

@Test
void shouldNotBeAutoMergeableDifferentTrackedEntityType() throws PotentialDuplicateConflictException, PotentialDuplicateForbiddenException {
    String uidOther = "uidOther";
    TrackedEntityType trackedEntityOther = new TrackedEntityType();
    trackedEntityOther.setName("Other");
    trackedEntityOther.setUid(uidOther);
    when(trackedEntityInstanceB.getTrackedEntityType()).thenReturn(trackedEntityOther);
    assertThrows(PotentialDuplicateConflictException.class, () -> deduplicationService.autoMerge(deduplicationMergeParams));
    verify(deduplicationHelper, times(0)).generateMergeObject(trackedEntityInstanceA, trackedEntityInstanceB);
    verify(potentialDuplicateStore, times(0)).update(any());
    verify(potentialDuplicateStore, times(0)).auditMerge(deduplicationMergeParams);
}
Also used : TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) Test(org.junit.jupiter.api.Test)

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