use of org.hisp.dhis.dxf2.importsummary.ImportStatus.ERROR in project dhis2-core by dhis2.
the class CsvMetadataImportIntegrationTest method testOrgUnitImport_MoveToParentNotInHierarchy.
@Test
void testOrgUnitImport_MoveToParentNotInHierarchy() throws Exception {
User user = createAndInjectAdminUser("F_ORGANISATIONUNIT_MOVE", "F_ORGANISATIONUNIT_ADD");
user.setOrganisationUnits(singleton(organisationUnitService.getOrganisationUnitByCode("L2a")));
userService.updateUser(user);
ImportReport report = runImport("metadata/organisationUnits_move.csv", CsvImportClass.ORGANISATION_UNIT, null, params -> params.setImportStrategy(ImportStrategy.UPDATE));
assertEquals(Status.ERROR, report.getStatus());
assertEquals(1, report.getErrorReportsCount());
assertTrue(report.hasErrorReport(error -> error.getErrorCode() == ErrorCode.E1523));
}
use of org.hisp.dhis.dxf2.importsummary.ImportStatus.ERROR in project dhis2-core by dhis2.
the class MetadataImportServiceTest method testMetadataSyncWithDeletedDataSetSection.
@Test
void testMetadataSyncWithDeletedDataSetSection() 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_AND_UPDATE, metadata);
ImportReport report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
dbmsManager.clearSession();
DataSet dataset = dataSetService.getDataSet("em8Bg4LCr5k");
assertNotNull(dataset.getSections());
assertNotNull(manager.get(Section.class, "JwcV2ZifEQf"));
metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_removed_section.json").getInputStream(), RenderFormat.JSON);
params = createParams(ImportStrategy.UPDATE, metadata);
params.setMetadataSyncImport(true);
dbmsManager.clearSession();
report = importService.importMetadata(params);
report.forEachErrorReport(errorReport -> log.error("Error report:" + errorReport));
assertEquals(Status.OK, report.getStatus());
dataset = manager.get(DataSet.class, "em8Bg4LCr5k");
assertEquals(1, dataset.getSections().size());
assertNull(manager.get(Section.class, "JwcV2ZifEQf"));
metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_all_section_removed.json").getInputStream(), RenderFormat.JSON);
params = createParams(ImportStrategy.CREATE_AND_UPDATE, metadata);
params.setMetadataSyncImport(true);
dbmsManager.clearSession();
report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
dataset = manager.get(DataSet.class, "em8Bg4LCr5k");
assertTrue(dataset.getSections().isEmpty());
}
use of org.hisp.dhis.dxf2.importsummary.ImportStatus.ERROR in project dhis2-core by dhis2.
the class EventSecurityTest method testAddEventSimpleUserFullAccess10.
/**
* program = DATA READ programStage = orgUnit = Accessible status = ERROR
*/
@Test
void testAddEventSimpleUserFullAccess10() {
programA.setPublicAccess(AccessStringHelper.DATA_READ_WRITE);
programStageA.setPublicAccess(AccessStringHelper.DATA_READ_WRITE);
manager.update(programA);
manager.update(programStageA);
Event event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid());
ImportSummary importSummary = eventService.addEvent(event, ImportOptions.getDefaultImportOptions(), false);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
assertEquals(event.getEvent(), importSummary.getReference());
programA.setPublicAccess(AccessStringHelper.DATA_READ);
programStageA.setPublicAccess(AccessStringHelper.DEFAULT);
manager.update(programA);
manager.update(programStageA);
User user = createUser("user1").setOrganisationUnits(Sets.newHashSet(organisationUnitA));
injectSecurityContext(user);
assertTrue(programStageInstanceService.programStageInstanceExists(event.getEvent()));
ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance(event.getUid());
assertNotNull(programStageInstance);
Event eventFromPsi = eventService.getEvent(programStageInstance);
assertNotNull(eventFromPsi);
assertEquals(event.getUid(), eventFromPsi.getEvent());
}
use of org.hisp.dhis.dxf2.importsummary.ImportStatus.ERROR in project dhis2-core by dhis2.
the class CsvMetadataImportIntegrationTest method testOrgUnitImport_MoveFromParentNotInHierarchy.
@Test
void testOrgUnitImport_MoveFromParentNotInHierarchy() throws Exception {
User user = createAndInjectAdminUser("F_ORGANISATIONUNIT_MOVE", "F_ORGANISATIONUNIT_ADD");
user.setOrganisationUnits(singleton(organisationUnitService.getOrganisationUnitByCode("L2b")));
userService.updateUser(user);
ImportReport report = runImport("metadata/organisationUnits_move.csv", CsvImportClass.ORGANISATION_UNIT, null, params -> params.setImportStrategy(ImportStrategy.UPDATE));
assertEquals(Status.ERROR, report.getStatus());
assertEquals(1, report.getErrorReportsCount());
assertTrue(report.hasErrorReport(error -> error.getErrorCode() == ErrorCode.E1522));
}
use of org.hisp.dhis.dxf2.importsummary.ImportStatus.ERROR in project dhis2-core by dhis2.
the class MetadataVersionDelegateTest method testShouldReturnEmptyMetadataDifference.
@Test
void testShouldReturnEmptyMetadataDifference() {
when(metadataSystemSettingService.getRemoteInstanceUserName()).thenReturn(username);
when(metadataSystemSettingService.getRemoteInstancePassword()).thenReturn(password);
String response = "{\"name\":\"testVersion\",\"created\":\"2016-05-26T11:43:59.787+0000\",\"type\":\"BEST_EFFORT\",\"id\":\"ktwh8PHNwtB\",\"hashCode\":\"12wa32d4f2et3tyt5yu6i\"}";
MetadataVersion metadataVersion = new MetadataVersion("testVersion", VersionType.BEST_EFFORT);
metadataVersion.setHashCode("12wa32d4f2et3tyt5yu6i");
String url = "http://localhost:9080/api/metadata/version/history?baseline=testVersion";
when(metadataSystemSettingService.getMetaDataDifferenceURL("testVersion")).thenReturn(url);
AvailabilityStatus availabilityStatus = new AvailabilityStatus(true, "test_message", null);
when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
DhisHttpResponse dhisHttpResponse = new DhisHttpResponse(httpResponse, response, HttpStatus.BAD_REQUEST.value());
try (MockedStatic<HttpUtils> mocked = mockStatic(HttpUtils.class)) {
mocked.when(() -> HttpUtils.httpGET(baselineUrl, true, username, password, null, VERSION_TIMEOUT, true)).thenReturn(dhisHttpResponse);
assertThrows(MetadataVersionServiceException.class, () -> target.getMetaDataDifference(metadataVersion), "Client Error. Http call failed with status code: 400 Caused by: " + dhisHttpResponse.getResponse());
}
}
Aggregations