Search in sources :

Example 31 with TrackerImportParams

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));
    });
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) Test(org.junit.jupiter.api.Test)

Example 32 with TrackerImportParams

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;
    }
}
Also used : TrackedEntityAttributeValueService(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService) Attribute(org.hisp.dhis.tracker.domain.Attribute) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) RequiredArgsConstructor(lombok.RequiredArgsConstructor) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) Function(java.util.function.Function) TrackedEntityAttributeService(org.hisp.dhis.trackedentity.TrackedEntityAttributeService) Lists(com.google.common.collect.Lists) Collectors.toMap(java.util.stream.Collectors.toMap) Collectors.mapping(java.util.stream.Collectors.mapping) Map(java.util.Map) TrackerIdScheme(org.hisp.dhis.tracker.TrackerIdScheme) NonNull(lombok.NonNull) UniqueAttributeValue(org.hisp.dhis.tracker.preheat.UniqueAttributeValue) Collection(java.util.Collection) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Objects(java.util.Objects) TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Component(org.springframework.stereotype.Component) Stream(java.util.stream.Stream) TreeMap(java.util.TreeMap) Optional(java.util.Optional) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance)

Example 33 with TrackerImportParams

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);
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) JmsListener(org.springframework.jms.annotation.JmsListener)

Example 34 with TrackerImportParams

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))));
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) User(org.hisp.dhis.user.User) Test(org.junit.jupiter.api.Test)

Example 35 with TrackerImportParams

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());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) Test(org.junit.jupiter.api.Test)

Aggregations

TrackerImportParams (org.hisp.dhis.tracker.TrackerImportParams)163 Test (org.junit.jupiter.api.Test)142 TrackerImportReport (org.hisp.dhis.tracker.report.TrackerImportReport)105 TrackerTest (org.hisp.dhis.tracker.TrackerTest)46 User (org.hisp.dhis.user.User)26 ClassPathResource (org.springframework.core.io.ClassPathResource)23 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)21 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)17 InputStream (java.io.InputStream)16 TrackedEntityAttributeValue (org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue)11 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)10 List (java.util.List)9 TrackerPreheat (org.hisp.dhis.tracker.preheat.TrackerPreheat)9 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)8 Event (org.hisp.dhis.tracker.domain.Event)7 Pair (org.apache.commons.lang3.tuple.Pair)6 ProgramInstance (org.hisp.dhis.program.ProgramInstance)6 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)6 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)5 Program (org.hisp.dhis.program.Program)5