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());
}
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());
}
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());
}
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));
}
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());
}
Aggregations