Search in sources :

Example 81 with TrackerImportReport

use of org.hisp.dhis.tracker.report.TrackerImportReport in project dhis2-core by dhis2.

the class EnrollmentAttrValidationTest method initTest.

@Override
protected void initTest() throws IOException {
    setUpMetadata("tracker/tracker_basic_metadata_mandatory_attr.json");
    TrackerImportParams trackerBundleParams = fromJson("tracker/validations/enrollments_te_te-data_2.json");
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(trackerBundleParams);
    assertEquals(0, trackerImportReport.getValidationReport().getErrors().size());
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
    manager.flush();
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport)

Example 82 with TrackerImportReport

use of org.hisp.dhis.tracker.report.TrackerImportReport in project dhis2-core by dhis2.

the class EnrollmentSecurityImportValidationTest method testUserHasNoAccessToProgramTeiType.

@Test
void testUserHasNoAccessToProgramTeiType() throws IOException {
    clearSecurityContext();
    setupMetadata();
    programA.setPublicAccess(AccessStringHelper.DATA_READ_WRITE);
    programA.setTrackedEntityType(trackedEntityType);
    manager.update(programA);
    manager.flush();
    User user = createUser("user1").setOrganisationUnits(Sets.newHashSet(organisationUnitA));
    injectSecurityContext(user);
    TrackerImportParams params = createBundleFromJson("tracker/validations/enrollments_program-teitype-missmatch.json");
    params.setUser(user);
    params.setImportStrategy(TrackerImportStrategy.CREATE);
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
    assertEquals(1, trackerImportReport.getValidationReport().getErrors().size());
    assertThat(trackerImportReport.getValidationReport().getErrors(), hasItem(hasProperty("errorCode", equalTo(TrackerErrorCode.E1104))));
}
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 83 with TrackerImportReport

use of org.hisp.dhis.tracker.report.TrackerImportReport in project dhis2-core by dhis2.

the class EnrollmentSecurityImportValidationTest method setUpTest.

@Override
protected void setUpTest() throws IOException {
    renderService = _renderService;
    userService = _userService;
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("tracker/tracker_basic_metadata.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setImportStrategy(ImportStrategy.CREATE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    ObjectBundleValidationReport validationReport = objectBundleValidationService.validate(bundle);
    assertFalse(validationReport.hasErrorReports());
    ObjectBundleCommitReport commit = objectBundleService.commit(bundle);
    assertFalse(commit.hasErrorReports());
    TrackerImportParams trackerBundleParams = createBundleFromJson("tracker/validations/enrollments_te_te-data.json");
    User user = userService.getUser(ADMIN_USER_UID);
    trackerBundleParams.setUserId(user.getUid());
    injectSecurityContext(user);
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(trackerBundleParams);
    assertEquals(0, trackerImportReport.getValidationReport().getErrors().size());
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
}
Also used : ObjectBundleParams(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams) TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) ObjectBundleCommitReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleCommitReport) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) ObjectBundle(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle) User(org.hisp.dhis.user.User) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Example 84 with TrackerImportReport

use of org.hisp.dhis.tracker.report.TrackerImportReport in project dhis2-core by dhis2.

the class EnrollmentImportValidationTest method testAttributesOk.

@Test
void testAttributesOk() throws IOException {
    TrackerImportParams params = createBundleFromJson("tracker/validations/enrollments_te_attr-data.json");
    params.setImportStrategy(TrackerImportStrategy.CREATE);
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
    assertEquals(1, trackerImportReport.getBundleReport().getTypeReportMap().get(TrackerType.ENROLLMENT).getObjectReportMap().values().size());
    assertEquals(0, trackerImportReport.getValidationReport().getErrors().size());
    assertThat(trackerImportReport.getValidationReport().getErrors(), everyItem(hasProperty("errorCode", equalTo(TrackerErrorCode.E1019))));
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) Test(org.junit.jupiter.api.Test)

Example 85 with TrackerImportReport

use of org.hisp.dhis.tracker.report.TrackerImportReport in project dhis2-core by dhis2.

the class EnrollmentImportValidationTest method testEnrollmentValidationOkAll.

@Test
void testEnrollmentValidationOkAll() throws IOException {
    TrackerImportParams params = createBundleFromJson("tracker/validations/enrollments_te_enrollments-data.json");
    params.setImportStrategy(TrackerImportStrategy.CREATE);
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
    assertEquals(0, trackerImportReport.getValidationReport().getErrors().size());
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) Test(org.junit.jupiter.api.Test)

Aggregations

TrackerImportReport (org.hisp.dhis.tracker.report.TrackerImportReport)114 TrackerImportParams (org.hisp.dhis.tracker.TrackerImportParams)105 Test (org.junit.jupiter.api.Test)99 User (org.hisp.dhis.user.User)23 TrackerTest (org.hisp.dhis.tracker.TrackerTest)21 ClassPathResource (org.springframework.core.io.ClassPathResource)20 InputStream (java.io.InputStream)17 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)15 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)9 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)8 ProgramInstance (org.hisp.dhis.program.ProgramInstance)5 Date (java.util.Date)4 List (java.util.List)4 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)4 Program (org.hisp.dhis.program.Program)4 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)3 TrackedEntityAttributeValue (org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue)3 TrackerValidationReport (org.hisp.dhis.tracker.report.TrackerValidationReport)3 TrackerImportReportRequest (org.hisp.dhis.webapi.controller.tracker.TrackerImportReportRequest)3 ResponseEntity (org.springframework.http.ResponseEntity)3