use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.
the class TrackerEntityInstanceStrategyTest method verifyStrategyIgnoresPersistedTei.
@Test
void verifyStrategyIgnoresPersistedTei() {
// Create preheat params
final List<TrackedEntity> trackedEntities = rnd.objects(TrackedEntity.class, 2).collect(Collectors.toList());
final TrackerImportParams params = TrackerImportParams.builder().trackedEntities(trackedEntities).build();
// Preheat
User user = new User();
TrackerPreheat preheat = new TrackerPreheat();
preheat.setUser(user);
final List<String> rootUids = trackedEntities.stream().map(TrackedEntity::getTrackedEntity).collect(Collectors.toList());
// Add uid of non-root tei
rootUids.add("noroottei");
List<List<String>> uids = new ArrayList<>();
uids.add(rootUids);
when(trackedEntityInstanceStore.getIncludingDeleted(rootUids)).thenReturn(Lists.newArrayList(new TrackedEntityInstance() {
{
setUid(trackedEntities.get(0).getTrackedEntity());
}
}));
// when
strategy.add(params, uids, preheat);
preheat.createReferenceTree();
assertFalse(preheat.getReference(trackedEntities.get(0).getTrackedEntity()).isPresent());
assertTrue(preheat.getReference(trackedEntities.get(1).getTrackedEntity()).isPresent());
assertFalse(preheat.getReference("noroottei").isPresent());
}
use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.
the class DuplicateRelationshipsPreProcessorTest method setUp.
@BeforeEach
void setUp() {
preheat = new TrackerPreheat();
RelationshipType relationshipTypeBidirectional = new RelationshipType();
relationshipTypeBidirectional.setUid(REL_TYPE_BIDIRECTIONAL_UID);
relationshipTypeBidirectional.setBidirectional(true);
RelationshipType relationshipTypeNonBidirectional = new RelationshipType();
relationshipTypeNonBidirectional.setUid(REL_TYPE_NONBIDIRECTIONAL_UID);
preheat.put(TrackerIdentifier.UID, relationshipTypeBidirectional);
preheat.put(TrackerIdentifier.UID, relationshipTypeNonBidirectional);
this.preProcessor = new DuplicateRelationshipsPreProcessor();
}
use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.
the class EventWithoutRegistrationPreProcessorTest method testEnrollmentIsAddedIntoEventWhenItBelongsToProgramWithoutRegistration.
@Test
void testEnrollmentIsAddedIntoEventWhenItBelongsToProgramWithoutRegistration() {
// Given
Event event = new Event();
event.setProgramStage("programStageUid");
TrackerBundle bundle = TrackerBundle.builder().events(Collections.singletonList(event)).build();
ProgramInstance programInstance = new ProgramInstance();
programInstance.setUid("programInstanceUid");
Program program = new Program();
program.setUid("programUid");
ProgramStage programStage = new ProgramStage();
programStage.setUid("programStageUid");
programStage.setProgram(program);
TrackerPreheat preheat = new TrackerPreheat();
preheat.putProgramInstancesWithoutRegistration("programUid", programInstance);
preheat.put(TrackerIdentifier.UID, programStage);
bundle.setPreheat(preheat);
// When
preProcessorToTest.process(bundle);
// Then
assertEquals("programInstanceUid", bundle.getEvents().get(0).getEnrollment());
}
use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.
the class EventWithoutRegistrationPreProcessorTest method testEnrollmentIsNotAddedIntoEventWhenItProgramStageHasNoReferenceToProgram.
@Test
void testEnrollmentIsNotAddedIntoEventWhenItProgramStageHasNoReferenceToProgram() {
// Given
Event event = new Event();
event.setProgramStage("programStageUid");
TrackerBundle bundle = TrackerBundle.builder().events(Collections.singletonList(event)).build();
ProgramInstance programInstance = new ProgramInstance();
programInstance.setUid("programInstanceUid");
Program program = new Program();
program.setUid("programUid");
ProgramStage programStage = new ProgramStage();
programStage.setUid("programStageUid");
TrackerPreheat preheat = new TrackerPreheat();
preheat.putProgramInstancesWithoutRegistration("programUid", programInstance);
preheat.put(TrackerIdentifier.UID, programStage);
bundle.setPreheat(preheat);
// When
preProcessorToTest.process(bundle);
// Then
assertNull(bundle.getEvents().get(0).getEnrollment(), "programInstanceUid");
}
use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.
the class UniqueAttributesSupplier method getEntityForEnrollment.
private TrackedEntity getEntityForEnrollment(TrackerImportParams params, TrackerPreheat preheat, String teiUid) {
TrackedEntityInstance trackedEntity = preheat.getTrackedEntity(TrackerIdScheme.UID, teiUid);
// Get tei from Preheat
Optional<TrackedEntity> optionalTei = params.getTrackedEntities().stream().filter(tei -> Objects.equals(tei.getTrackedEntity(), teiUid)).findAny();
if (optionalTei.isPresent()) {
return optionalTei.get();
} else if (// Otherwise build it from Payload
trackedEntity != null) {
TrackedEntity tei = new TrackedEntity();
tei.setTrackedEntity(teiUid);
tei.setOrgUnit(trackedEntity.getOrganisationUnit().getUid());
return tei;
} else // TEI is not present. but we do not fail here.
// A validation error will be thrown in validation phase
{
TrackedEntity tei = new TrackedEntity();
tei.setTrackedEntity(teiUid);
return tei;
}
}
Aggregations