use of net.geoprism.registry.etl.DHIS2TestService.Dhis2Payload 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());
}
}
}
use of net.geoprism.registry.etl.DHIS2TestService.Dhis2Payload 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());
}
Aggregations