Search in sources :

Example 11 with SynchronizationConfig

use of net.geoprism.registry.SynchronizationConfig in project geoprism-registry by terraframe.

the class DHIS2ServiceTest method exportCustomAttribute.

private void exportCustomAttribute(TestGeoObjectTypeInfo got, TestGeoObjectInfo go, TestAttributeTypeInfo attr) throws InterruptedException {
    DHIS2SyncLevel level2 = new DHIS2SyncLevel();
    level2.setGeoObjectType(got.getServerObject().getCode());
    level2.setSyncType(DHIS2SyncLevel.Type.ALL);
    level2.setLevel(1);
    Collection<DHIS2AttributeMapping> mappings = getDefaultMappings();
    DHIS2AttributeMapping mapping;
    if (attr.getType().equals(AttributeTermType.TYPE)) {
        mapping = new DHIS2TermAttributeMapping();
        mapping.setAttributeMappingStrategy(DHIS2TermAttributeMapping.class.getName());
        Map<String, String> terms = new HashMap<String, String>();
        terms.put(AllAttributesDataset.AT_GO_TERM.fetchRootAsClassifier().getClassifierId(), "TEST_EXTERNAL_ID");
        terms.put(AllAttributesDataset.TERM_TERM_VAL1.fetchClassifier().getClassifierId(), "TEST_EXTERNAL_ID");
        terms.put(AllAttributesDataset.TERM_TERM_VAL2.fetchClassifier().getClassifierId(), "TEST_EXTERNAL_ID");
        ((DHIS2TermAttributeMapping) mapping).setTerms(terms);
    } else {
        mapping = new DHIS2AttributeMapping();
        mapping.setAttributeMappingStrategy(DHIS2AttributeMapping.class.getName());
    }
    mapping.setCgrAttrName(attr.getAttributeName());
    mapping.setDhis2AttrName(attr.getAttributeName());
    mapping.setExternalId("TEST_EXTERNAL_ID");
    mappings.add(mapping);
    level2.setMappings(mappings);
    SynchronizationConfig config = createSyncConfig(this.system, level2);
    JsonObject jo = syncService.run(testData.clientSession.getSessionId(), config.getOid());
    ExportHistory hist = ExportHistory.get(jo.get("historyId").getAsString());
    SchedulerTestUtils.waitUntilStatus(hist.getOid(), AllJobStatus.SUCCESS);
    LinkedList<Dhis2Payload> payloads = this.dhis2.getPayloads();
    Assert.assertEquals(2, payloads.size());
    for (int level = 0; level < payloads.size(); ++level) {
        Dhis2Payload payload = payloads.get(level);
        JsonObject joPayload = JsonParser.parseString(payload.getData()).getAsJsonObject();
        JsonArray orgUnits = joPayload.get("organisationUnits").getAsJsonArray();
        Assert.assertEquals(1, orgUnits.size());
        JsonObject orgUnit = orgUnits.get(0).getAsJsonObject();
        Assert.assertEquals(level, orgUnit.get("level").getAsInt());
        Assert.assertEquals("MULTI_POLYGON", orgUnit.get("featureType").getAsString());
        if (level == 0) {
            Assert.assertEquals(AllAttributesDataset.GO_ALL.getCode(), orgUnit.get("code").getAsString());
        } else {
            Assert.assertEquals(go.getCode(), orgUnit.get("code").getAsString());
            Assert.assertTrue(orgUnit.has("attributeValues"));
            JsonArray attributeValues = orgUnit.get("attributeValues").getAsJsonArray();
            Assert.assertEquals(1, attributeValues.size());
            JsonObject attributeValue = attributeValues.get(0).getAsJsonObject();
            Assert.assertNotNull(attributeValue.get("lastUpdated").getAsString());
            Assert.assertNotNull(attributeValue.get("created").getAsString());
            AttributeType attrDto = attr.fetchDTO();
            if (attrDto instanceof AttributeIntegerType) {
                Assert.assertEquals(go.getServerObject().getValue(attr.getAttributeName()), attributeValue.get("value").getAsLong());
            } else if (attrDto instanceof AttributeFloatType) {
                Assert.assertEquals(go.getServerObject().getValue(attr.getAttributeName()), attributeValue.get("value").getAsDouble());
            } else if (attrDto instanceof AttributeDateType) {
                // TODO : If we fetch the object from the database in this manner the
                // miliseconds aren't included on the date. But if we fetch the object
                // via a query (as in DataExportJob) then the miliseconds ARE
                // included...
                // String expected =
                // DHIS2GeoObjectJsonAdapters.DHIS2Serializer.formatDate((Date)
                // go.getServerObject().getValue(attr.getAttributeName()));
                String expected = DHIS2GeoObjectJsonAdapters.DHIS2Serializer.formatDate(AllAttributesDataset.GO_DATE_VALUE);
                String actual = attributeValue.get("value").getAsString();
                Assert.assertEquals(expected, actual);
            } else if (attrDto instanceof AttributeBooleanType) {
                Assert.assertEquals(go.getServerObject().getValue(attr.getAttributeName()), attributeValue.get("value").getAsBoolean());
            } else if (attrDto instanceof AttributeTermType) {
                String dhis2Id = attributeValue.get("value").getAsString();
                // Term term = (Term)
                // go.getServerObject().getValue(attr.getAttributeName());
                Assert.assertEquals("TEST_EXTERNAL_ID", dhis2Id);
            } else {
                Assert.assertEquals(go.getServerObject().getValue(attr.getAttributeName()), attributeValue.get("value").getAsString());
            }
            Assert.assertEquals("TEST_EXTERNAL_ID", attributeValue.get("attribute").getAsJsonObject().get("id").getAsString());
        }
    }
}
Also used : AttributeIntegerType(org.commongeoregistry.adapter.metadata.AttributeIntegerType) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) Dhis2Payload(net.geoprism.registry.etl.DHIS2TestService.Dhis2Payload) AttributeFloatType(org.commongeoregistry.adapter.metadata.AttributeFloatType) AttributeDateType(org.commongeoregistry.adapter.metadata.AttributeDateType) JsonArray(com.google.gson.JsonArray) ExportHistory(net.geoprism.registry.etl.export.ExportHistory) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) SynchronizationConfig(net.geoprism.registry.SynchronizationConfig) AttributeBooleanType(org.commongeoregistry.adapter.metadata.AttributeBooleanType) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType)

Example 12 with SynchronizationConfig

use of net.geoprism.registry.SynchronizationConfig in project geoprism-registry by terraframe.

the class DHIS2ServiceTest method testApplySyncConfig.

@Request
@Test
public void testApplySyncConfig() throws Exception {
    SynchronizationConfig config = createSyncConfig(this.system, null, false);
    SynchronizationConfigService service = new SynchronizationConfigService();
    JsonObject json = config.toJSON();
    json.remove("oid");
    JsonObject configToJson = service.apply(testData.clientSession.getSessionId(), json.toString());
    String oid = configToJson.get(SynchronizationConfig.OID).getAsString();
    SynchronizationConfig.get(oid);
}
Also used : SynchronizationConfigService(net.geoprism.registry.service.SynchronizationConfigService) JsonObject(com.google.gson.JsonObject) SynchronizationConfig(net.geoprism.registry.SynchronizationConfig) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 13 with SynchronizationConfig

use of net.geoprism.registry.SynchronizationConfig in project geoprism-registry by terraframe.

the class DHIS2ServiceTest method testExportGeoObjects.

@Request
@Test
public void testExportGeoObjects() throws InterruptedException {
    SynchronizationConfig config = createSyncConfig(this.system, null);
    SynchronizationConfigService service = new SynchronizationConfigService();
    JsonObject joHist = service.run(testData.clientSession.getSessionId(), config.getOid());
    ExportHistory hist = ExportHistory.get(joHist.get("historyId").getAsString());
    SchedulerTestUtils.waitUntilStatus(hist.getOid(), AllJobStatus.SUCCESS);
    hist = ExportHistory.get(hist.getOid());
    Assert.assertEquals(new Long(1), hist.getWorkTotal());
    Assert.assertEquals(new Long(1), hist.getWorkProgress());
    Assert.assertEquals(ImportStage.COMPLETE.name(), hist.getStage().get(0).name());
    LinkedList<Dhis2Payload> payloads = this.dhis2.getPayloads();
    Assert.assertEquals(1, payloads.size());
    Dhis2Payload payload = payloads.get(0);
    JsonObject data = JsonParser.parseString(payload.getData()).getAsJsonObject();
    JsonArray orgUnits = data.get("organisationUnits").getAsJsonArray();
    Assert.assertEquals(1, orgUnits.size());
    JsonObject orgUnit = orgUnits.get(0).getAsJsonObject();
    Assert.assertEquals("AllAttrGO_ALL", orgUnit.get("code").getAsString());
}
Also used : JsonArray(com.google.gson.JsonArray) ExportHistory(net.geoprism.registry.etl.export.ExportHistory) SynchronizationConfigService(net.geoprism.registry.service.SynchronizationConfigService) JsonObject(com.google.gson.JsonObject) SynchronizationConfig(net.geoprism.registry.SynchronizationConfig) Dhis2Payload(net.geoprism.registry.etl.DHIS2TestService.Dhis2Payload) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 14 with SynchronizationConfig

use of net.geoprism.registry.SynchronizationConfig in project geoprism-registry by terraframe.

the class FhirImportTest method createSyncConfig.

@Request
public static SynchronizationConfig createSyncConfig(ExternalSystem system) {
    // Define reusable objects
    final ServerHierarchyType ht = USATestData.HIER_ADMIN.getServerObject();
    final Organization org = USATestData.ORG_NPS.getServerObject();
    // Create DHIS2 Sync Config
    FhirSyncImportConfig sourceConfig = new FhirSyncImportConfig();
    sourceConfig.setLabel(new LocalizedValue("FHIR Import Test Data"));
    sourceConfig.setOrganization(org);
    sourceConfig.setImplementation(BasicFhirResourceProcessor.class.getName());
    // Serialize the FHIR Config
    GsonBuilder builder = new GsonBuilder();
    String fhirExportJsonConfig = builder.create().toJson(sourceConfig);
    // Create a SynchronizationConfig
    SynchronizationConfig config = new SynchronizationConfig();
    config.setConfiguration(fhirExportJsonConfig);
    config.setOrganization(org);
    config.setHierarchy(ht.getMdTermRelationship());
    config.setSystem(system.getOid());
    config.getLabel().setValue("FHIR Import Test");
    config.setIsImport(true);
    config.apply();
    return config;
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) Organization(net.geoprism.registry.Organization) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) GsonBuilder(com.google.gson.GsonBuilder) BasicFhirResourceProcessor(net.geoprism.registry.etl.fhir.BasicFhirResourceProcessor) SynchronizationConfig(net.geoprism.registry.SynchronizationConfig) Request(com.runwaysdk.session.Request)

Aggregations

SynchronizationConfig (net.geoprism.registry.SynchronizationConfig)14 Request (com.runwaysdk.session.Request)10 JsonObject (com.google.gson.JsonObject)5 Organization (net.geoprism.registry.Organization)4 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)4 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)4 JsonArray (com.google.gson.JsonArray)3 ExportHistory (net.geoprism.registry.etl.export.ExportHistory)3 Test (org.junit.Test)3 GsonBuilder (com.google.gson.GsonBuilder)2 Dhis2Payload (net.geoprism.registry.etl.DHIS2TestService.Dhis2Payload)2 ExternalSystemSyncConfig (net.geoprism.registry.etl.ExternalSystemSyncConfig)2 FhirSyncExportConfig (net.geoprism.registry.etl.FhirSyncExportConfig)2 BasicFhirResourceProcessor (net.geoprism.registry.etl.fhir.BasicFhirResourceProcessor)2 FhirExportSynchronizationManager (net.geoprism.registry.etl.fhir.FhirExportSynchronizationManager)2 DHIS2ExternalSystem (net.geoprism.registry.graph.DHIS2ExternalSystem)2 ExternalSystem (net.geoprism.registry.graph.ExternalSystem)2 SynchronizationConfigService (net.geoprism.registry.service.SynchronizationConfigService)2 IParser (ca.uhn.fhir.parser.IParser)1 JsonElement (com.google.gson.JsonElement)1