use of org.hisp.dhis.tracker.TrackerImportParams in project dhis2-core by dhis2.
the class TrackerImportParamsBuilderTest method testProgramStageIdentifier.
@Test
void testProgramStageIdentifier() {
Arrays.stream(TrackerIdScheme.values()).forEach(e -> {
paramMap.put("programStageIdScheme", Collections.singletonList(e.name()));
TrackerImportParams params = TrackerImportParamsBuilder.build(paramMap);
assertThat(params.getIdentifiers().getProgramStageIdScheme().getIdScheme(), is(e));
});
}
use of org.hisp.dhis.tracker.TrackerImportParams 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;
}
}
use of org.hisp.dhis.tracker.TrackerImportParams in project dhis2-core by dhis2.
the class TrackerMessageManager method consume.
@JmsListener(destination = Topics.TRACKER_IMPORT_JOB_TOPIC_NAME, containerFactory = "jmsQueueListenerContainerFactory")
public void consume(TextMessage message) throws JMSException, JsonProcessingException {
String payload = message.getText();
TrackerMessage trackerMessage = objectMapper.readValue(payload, TrackerMessage.class);
TrackerImportParams trackerImportParams = trackerMessage.getTrackerImportParams();
JobConfiguration jobConfiguration = new JobConfiguration("", JobType.TRACKER_IMPORT_JOB, trackerImportParams.getUserId(), true);
jobConfiguration.setUid(trackerMessage.getUid());
trackerImportParams.setJobConfiguration(jobConfiguration);
TrackerImportThread trackerImportThread = trackerImportThreadFactory.getObject();
trackerImportThread.setTrackerImportParams(trackerImportParams);
SecurityContextHolder.getContext().setAuthentication(AuthenticationSerializer.deserialize(trackerMessage.getAuthentication()));
taskExecutor.executeTask(trackerImportThread);
}
use of org.hisp.dhis.tracker.TrackerImportParams in project dhis2-core by dhis2.
the class EnrollmentImportValidationTest method testNoWriteAccessToOrg.
@Test
void testNoWriteAccessToOrg() throws IOException {
TrackerImportParams params = createBundleFromJson("tracker/validations/enrollments_te_enrollments-data.json");
User user = userService.getUser(USER_2);
params.setUser(user);
params.setImportStrategy(TrackerImportStrategy.CREATE);
TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
assertEquals(4, trackerImportReport.getValidationReport().getErrors().size());
assertThat(trackerImportReport.getValidationReport().getErrors(), hasItem(hasProperty("errorCode", equalTo(TrackerErrorCode.E1000))));
}
use of org.hisp.dhis.tracker.TrackerImportParams in project dhis2-core by dhis2.
the class EnrollmentImportValidationTest method testEnrollmentDeleteOk.
@Test
void testEnrollmentDeleteOk() throws IOException {
TrackerImportParams paramsCreate = createBundleFromJson("tracker/validations/enrollments_te_enrollments-data.json");
paramsCreate.setImportStrategy(TrackerImportStrategy.CREATE);
TrackerImportReport trackerImportReport = trackerImportService.importTracker(paramsCreate);
assertEquals(0, trackerImportReport.getValidationReport().getErrors().size());
assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
manager.flush();
manager.clear();
TrackerImportParams paramsDelete = createBundleFromJson("tracker/validations/enrollments_te_enrollments-data-delete.json");
paramsDelete.setImportStrategy(TrackerImportStrategy.DELETE);
TrackerImportReport trackerImportReportDelete = trackerImportService.importTracker(paramsDelete);
assertEquals(0, trackerImportReportDelete.getValidationReport().getErrors().size());
assertEquals(TrackerStatus.OK, trackerImportReportDelete.getStatus());
assertEquals(1, trackerImportReportDelete.getStats().getDeleted());
}
Aggregations