Search in sources :

Example 76 with ID

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.ID in project dhis2-core by dhis2.

the class ProgramStageInstanceBasicCheckTest method failOnProgramStageInstanceAndInvalidImportOption.

@Test
void failOnProgramStageInstanceAndInvalidImportOption() {
    Map<String, ProgramStageInstance> programStageInstanceMap = new HashMap<>();
    ProgramStageInstance psi = new ProgramStageInstance();
    programStageInstanceMap.put(event.getEvent(), psi);
    ImportOptions importOptions = ImportOptions.getDefaultImportOptions();
    importOptions.setImportStrategy(ImportStrategy.CREATE);
    when(workContext.getImportOptions()).thenReturn(importOptions);
    when(workContext.getProgramStageInstanceMap()).thenReturn(programStageInstanceMap);
    ImportSummary summary = rule.check(new ImmutableEvent(event), workContext);
    assertHasError(summary, event, "Event ID " + event.getEvent() + " was already used and/or deleted. This event can not be modified.");
}
Also used : HashMap(java.util.HashMap) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) Test(org.junit.jupiter.api.Test) BaseValidationTest(org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest)

Example 77 with ID

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.ID in project dhis2-core by dhis2.

the class GmlImportServiceTest method setUpTest.

@Override
public void setUpTest() throws IOException {
    inputStream = new ClassPathResource("gml/testGmlPayload.gml").getInputStream();
    /*
         * Create orgunits present in testGmlPayload.gml and set ID properties.
         * Name - FeatureType - ID property Bo - Poly - Name Bonthe - Multi -
         * Code Ole Johan Dahls Hus - Point - Uid Blindern - Point (pos) - Name
         * Forskningsparken - Poly (list) - Name
         *
         * Note: some of these are included to cover different coordinate
         * element schemes such as <posList>, <coordinates> and <pos>.
         */
    userService = _userService;
    boOrgUnit = createOrganisationUnit('A');
    boOrgUnit.setName("Bo");
    organisationUnitService.addOrganisationUnit(boOrgUnit);
    bontheOrgUnit = createOrganisationUnit('B');
    // Match on Code, therefore wrong
    bontheOrgUnit.setName("AA Bonthe");
    // name
    bontheOrgUnit.setCode("CODE_BONTHE");
    organisationUnitService.addOrganisationUnit(bontheOrgUnit);
    ojdOrgUnit = createOrganisationUnit('C');
    ojdOrgUnit.setUid("ImspTQPwCqd");
    // Match on UID,
    ojdOrgUnit.setName("AA Ole Johan Dahls Hus");
    // therefore wrong name
    organisationUnitService.addOrganisationUnit(ojdOrgUnit);
    bliOrgUnit = createOrganisationUnit('D');
    bliOrgUnit.setName("Blindern");
    organisationUnitService.addOrganisationUnit(bliOrgUnit);
    forskOrgUnit = createOrganisationUnit('E');
    forskOrgUnit.setName("Forskningsparken");
    organisationUnitService.addOrganisationUnit(forskOrgUnit);
    user = createAndInjectAdminUser();
    id = new JobConfiguration("gmlImportTest", JobType.METADATA_IMPORT, user.getUid(), true);
    importOptions = new ImportOptions().setImportStrategy(ImportStrategy.UPDATE);
    importOptions.setDryRun(false);
    importOptions.setPreheatCache(true);
}
Also used : ClassPathResource(org.springframework.core.io.ClassPathResource) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions)

Example 78 with ID

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.ID in project dhis2-core by dhis2.

the class GmlImportServiceTest method testImportGml.

// -------------------------------------------------------------------------
// Tests
// -------------------------------------------------------------------------
@Test
void testImportGml() {
    MetadataImportParams importParams = new MetadataImportParams();
    importParams.setId(id);
    importParams.setUser(user);
    gmlImportService.importGml(inputStream, importParams);
    assertNotNull(boOrgUnit.getGeometry());
    assertNotNull(bontheOrgUnit.getGeometry());
    assertNotNull(ojdOrgUnit.getGeometry());
    assertNotNull(bliOrgUnit.getGeometry());
    assertNotNull(forskOrgUnit.getGeometry());
    // Check if data is correct
    assertEquals(1, getCoordinates(boOrgUnit).size());
    assertEquals(18, getCoordinates(bontheOrgUnit).size());
    assertEquals(1, getCoordinates(ojdOrgUnit).size());
    assertEquals(1, getCoordinates(bliOrgUnit).size());
    assertEquals(1, getCoordinates(forskOrgUnit).size());
    assertEquals(76, getCoordinates(boOrgUnit).get(0).getNumberOfCoordinates());
    assertEquals(189, getCoordinates(bontheOrgUnit).get(1).getNumberOfCoordinates());
    assertEquals(1, getCoordinates(ojdOrgUnit).get(0).getNumberOfCoordinates());
    assertEquals(1, getCoordinates(bliOrgUnit).get(0).getNumberOfCoordinates());
    assertEquals(76, getCoordinates(forskOrgUnit).get(0).getNumberOfCoordinates());
}
Also used : MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 79 with ID

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.ID in project dhis2-core by dhis2.

the class MetadataVersionDelegateTest method testShouldDownloadMetadataVersion.

@Test
void testShouldDownloadMetadataVersion() {
    when(metadataSystemSettingService.getDownloadVersionSnapshotURL("testVersion")).thenReturn(downloadUrl);
    when(synchronizationManager.isRemoteServerAvailable()).thenReturn(new AvailabilityStatus(true, "test_message", null));
    when(metadataSystemSettingService.getRemoteInstanceUserName()).thenReturn(username);
    when(metadataSystemSettingService.getRemoteInstancePassword()).thenReturn(password);
    try (MockedStatic<HttpUtils> mocked = mockStatic(HttpUtils.class)) {
        String response = "{\"name\":\"testVersion\",\"created\":\"2016-05-26T11:43:59.787+0000\",\"type\":\"BEST_EFFORT\",\"id\":\"ktwh8PHNwtB\",\"hashCode\":\"12wa32d4f2et3tyt5yu6i\"}";
        DhisHttpResponse dhisHttpResponse = new DhisHttpResponse(httpResponse, response, HttpStatus.OK.value());
        mocked.when(() -> HttpUtils.httpGET(downloadUrl, true, username, password, null, DOWNLOAD_TIMEOUT, true)).thenReturn(dhisHttpResponse);
        MetadataVersion metadataVersion = new MetadataVersion("testVersion", VersionType.BEST_EFFORT);
        metadataVersion.setHashCode("12wa32d4f2et3tyt5yu6i");
        String actualVersionSnapShot = target.downloadMetadataVersionSnapshot(metadataVersion);
        assertEquals(response, actualVersionSnapShot);
    }
}
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)

Example 80 with ID

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.ID 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)41 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)39 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)26 InputStream (java.io.InputStream)24 User (org.hisp.dhis.user.User)21 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)18 IOException (java.io.IOException)17 Event (org.hisp.dhis.dxf2.events.event.Event)16 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)15 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)13 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)12 GetMapping (org.springframework.web.bind.annotation.GetMapping)12 ArrayList (java.util.ArrayList)11 List (java.util.List)11 DataElement (org.hisp.dhis.dataelement.DataElement)10 Test (org.junit.jupiter.api.Test)10 TrackedEntityInstanceParams (org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams)9 Lists (com.google.common.collect.Lists)8 Collectors (java.util.stream.Collectors)8 HashMap (java.util.HashMap)7