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