Search in sources :

Example 11 with AttributeFloatType

use of org.commongeoregistry.adapter.metadata.AttributeFloatType 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)

Aggregations

AttributeFloatType (org.commongeoregistry.adapter.metadata.AttributeFloatType)11 AttributeTermType (org.commongeoregistry.adapter.metadata.AttributeTermType)9 AttributeClassificationType (org.commongeoregistry.adapter.metadata.AttributeClassificationType)7 Term (org.commongeoregistry.adapter.Term)6 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)5 MdAttributeConcrete (com.runwaysdk.system.metadata.MdAttributeConcrete)4 Locale (java.util.Locale)4 AttributeBooleanType (org.commongeoregistry.adapter.metadata.AttributeBooleanType)4 AttributeDateType (org.commongeoregistry.adapter.metadata.AttributeDateType)4 AttributeIntegerType (org.commongeoregistry.adapter.metadata.AttributeIntegerType)4 AttributeLocalType (org.commongeoregistry.adapter.metadata.AttributeLocalType)4 JsonArray (com.google.gson.JsonArray)3 JsonObject (com.google.gson.JsonObject)3 MdAttributeBoolean (com.runwaysdk.system.metadata.MdAttributeBoolean)3 MdAttributeCharacter (com.runwaysdk.system.metadata.MdAttributeCharacter)3 MdAttributeDateTime (com.runwaysdk.system.metadata.MdAttributeDateTime)3 MdAttributeDouble (com.runwaysdk.system.metadata.MdAttributeDouble)3 MdAttributeLong (com.runwaysdk.system.metadata.MdAttributeLong)3 MdBusiness (com.runwaysdk.system.metadata.MdBusiness)3 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)3