Search in sources :

Example 46 with ERROR

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

Example 47 with ERROR

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());
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) List(java.util.List) Section(org.hisp.dhis.dataset.Section) ProgramStageSection(org.hisp.dhis.program.ProgramStageSection) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 48 with ERROR

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());
}
Also used : User(org.hisp.dhis.user.User) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Event(org.hisp.dhis.dxf2.events.event.Event) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 49 with ERROR

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

Example 50 with ERROR

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());
    }
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) DhisHttpResponse(org.hisp.dhis.system.util.DhisHttpResponse) AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) HttpUtils(org.hisp.dhis.system.util.HttpUtils) Test(org.junit.jupiter.api.Test)

Aggregations

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)33 Test (org.junit.jupiter.api.Test)25 User (org.hisp.dhis.user.User)21 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)20 IOException (java.io.IOException)15 Event (org.hisp.dhis.dxf2.events.event.Event)14 List (java.util.List)12 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)11 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)9 ImportStrategy (org.hisp.dhis.importexport.ImportStrategy)9 ClassPathResource (org.springframework.core.io.ClassPathResource)9 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)8 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)7 GetMapping (org.springframework.web.bind.annotation.GetMapping)7 ArrayList (java.util.ArrayList)6 FileResource (org.hisp.dhis.fileresource.FileResource)6 SchemaService (org.hisp.dhis.schema.SchemaService)6 UserService (org.hisp.dhis.user.UserService)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 InputStream (java.io.InputStream)4