Search in sources :

Example 56 with ImportReport

use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.

the class MetadataImportServiceTest method testCorrectStatusOnImportNoErrors.

@Test
void testCorrectStatusOnImportNoErrors() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_sections.json").getInputStream(), RenderFormat.JSON);
    MetadataImportParams params = createParams(ImportStrategy.CREATE, metadata);
    ImportReport report = importService.importMetadata(params);
    assertEquals(Status.OK, report.getStatus());
}
Also used : ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 57 with ImportReport

use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.

the class MetadataImportServiceTest method testImportWithSkipSharingIsTrueAndNoPermission.

/**
 * User only have READ access to Dashboard object User try to update
 * Dashboard with: skipSharing=true, and payload doesn't include sharing
 * data. Expected: import error
 */
@Test
void testImportWithSkipSharingIsTrueAndNoPermission() {
    clearSecurityContext();
    User userA = createUser("A");
    userService.addUser(userA);
    Dashboard dashboard = new Dashboard();
    dashboard.setName("DashboardA");
    Sharing sharing = new Sharing();
    sharing.addUserAccess(new UserAccess(userA, AccessStringHelper.READ));
    dashboard.setSharing(sharing);
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = new HashMap<>();
    metadata.put(Dashboard.class, Collections.singletonList(dashboard));
    MetadataImportParams params = createParams(ImportStrategy.CREATE, metadata);
    params.setSkipSharing(false);
    // Create Dashboard
    ImportReport report = importService.importMetadata(params);
    assertEquals(Status.OK, report.getStatus());
    // Check sharing data
    IdentifiableObject savedDashboard = manager.get(Dashboard.class, dashboard.getUid());
    boolean condition = aclService.canWrite(userA, savedDashboard);
    assertFalse(condition);
    assertTrue(aclService.canRead(userA, savedDashboard));
    // Update dashboard with skipSharing=true and no sharing data in payload
    dashboard.setSharing(null);
    metadata.put(Dashboard.class, Collections.singletonList(dashboard));
    params = createParams(ImportStrategy.UPDATE, metadata);
    params.setSkipSharing(true);
    params.setUser(userA);
    report = importService.importMetadata(params);
    assertEquals(Status.ERROR, report.getStatus());
}
Also used : User(org.hisp.dhis.user.User) Sharing(org.hisp.dhis.user.sharing.Sharing) UserAccess(org.hisp.dhis.user.sharing.UserAccess) HashMap(java.util.HashMap) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) Dashboard(org.hisp.dhis.dashboard.Dashboard) List(java.util.List) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 58 with ImportReport

use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.

the class MetadataImportServiceTest method testCorrectStatusOnImportErrorsATOMIC.

@Test
void testCorrectStatusOnImportErrorsATOMIC() throws IOException {
    createUserAndInjectSecurityContext(true);
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_sections.json").getInputStream(), RenderFormat.JSON);
    MetadataImportParams params = createParams(ImportStrategy.CREATE, metadata);
    ImportReport report = importService.importMetadata(params);
    assertEquals(Status.ERROR, report.getStatus());
}
Also used : ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 59 with ImportReport

use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.

the class CsvMetadataImportIntegrationTest method testOrgUnitImport_MoveLacksMoveAuthority.

@Test
void testOrgUnitImport_MoveLacksMoveAuthority() throws Exception {
    createAndInjectAdminUser(new String[0]);
    ImportReport report = runImport("metadata/organisationUnits_move.csv", CsvImportClass.ORGANISATION_UNIT, null, params -> params.setImportStrategy(ImportStrategy.UPDATE));
    assertEquals(Status.ERROR, report.getStatus());
    assertTrue(report.hasErrorReport(error -> error.getErrorCode() == ErrorCode.E1520));
}
Also used : ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) BeforeEach(org.junit.jupiter.api.BeforeEach) UserService(org.hisp.dhis.user.UserService) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) CsvImportClass(org.hisp.dhis.dxf2.csv.CsvImportClass) ClassPathResource(org.springframework.core.io.ClassPathResource) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) SchemaService(org.hisp.dhis.schema.SchemaService) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) CsvImportOptions(org.hisp.dhis.dxf2.csv.CsvImportOptions) Collections.singleton(java.util.Collections.singleton) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) User(org.hisp.dhis.user.User) ErrorCode(org.hisp.dhis.feedback.ErrorCode) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Status(org.hisp.dhis.feedback.Status) InputStream(java.io.InputStream) CsvImportService(org.hisp.dhis.dxf2.csv.CsvImportService) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 60 with ImportReport

use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.

the class CsvMetadataImportIntegrationTest method testOrgUnitImport_Success.

@Test
void testOrgUnitImport_Success() throws Exception {
    User user = createAndInjectAdminUser("F_ORGANISATIONUNIT_MOVE", "F_ORGANISATIONUNIT_ADD");
    user.setOrganisationUnits(singleton(organisationUnitService.getOrganisationUnitByCode("L1")));
    userService.updateUser(user);
    ImportReport importReport = runImport("metadata/organisationUnits_move.csv", CsvImportClass.ORGANISATION_UNIT, null, params -> params.setImportStrategy(ImportStrategy.UPDATE));
    assertEquals(Status.OK, importReport.getStatus());
    assertEquals(1, importReport.getStats().getUpdated());
}
Also used : User(org.hisp.dhis.user.User) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)87 Test (org.junit.jupiter.api.Test)52 List (java.util.List)39 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)37 ClassPathResource (org.springframework.core.io.ClassPathResource)37 User (org.hisp.dhis.user.User)34 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)33 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)32 DhisSpringTest (org.hisp.dhis.DhisSpringTest)12 DataSet (org.hisp.dhis.dataset.DataSet)12 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)11 IOException (java.io.IOException)10 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 CsvImportOptions (org.hisp.dhis.dxf2.csv.CsvImportOptions)9 InputStream (java.io.InputStream)8 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)8 UserService (org.hisp.dhis.user.UserService)8 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)8 BeforeEach (org.junit.jupiter.api.BeforeEach)8