use of org.commongeoregistry.adapter.metadata.AttributeTermType in project geoprism-registry by terraframe.
the class VertexServerGeoObject method toGeoObject.
@Override
public GeoObject toGeoObject(Date date) {
Map<String, Attribute> attributeMap = GeoObject.buildAttributeMap(type.getType());
GeoObject geoObj = new GeoObject(type.getType(), type.getGeometryType(), attributeMap);
Map<String, AttributeType> attributes = type.getAttributeMap();
attributes.forEach((attributeName, attribute) -> {
if (attributeName.equals(DefaultAttribute.TYPE.getName())) {
// Ignore
} else if (vertex.hasAttribute(attributeName)) {
Object value = vertex.getObjectValue(attributeName, date);
if (value != null) {
if (attribute instanceof AttributeTermType) {
Classifier classifier = Classifier.get((String) value);
try {
geoObj.setValue(attributeName, classifier.getClassifierId());
} catch (UnknownTermException e) {
TermValueException ex = new TermValueException();
ex.setAttributeLabel(e.getAttribute().getLabel().getValue());
ex.setCode(e.getCode());
throw e;
}
} else if (attribute instanceof AttributeClassificationType) {
String classificationTypeCode = ((AttributeClassificationType) attribute).getClassificationType();
ClassificationType classificationType = ClassificationType.getByCode(classificationTypeCode);
Classification classification = Classification.getByOid(classificationType, (String) value);
try {
geoObj.setValue(attributeName, classification.toTerm());
} catch (UnknownTermException e) {
TermValueException ex = new TermValueException();
ex.setAttributeLabel(e.getAttribute().getLabel().getValue());
ex.setCode(e.getCode());
throw e;
}
} else {
geoObj.setValue(attributeName, value);
}
}
}
});
geoObj.setUid(vertex.getObjectValue(RegistryConstants.UUID));
geoObj.setCode(vertex.getObjectValue(DefaultAttribute.CODE.getName()));
geoObj.setGeometry(this.getGeometry());
geoObj.setDisplayLabel(this.getDisplayLabel());
geoObj.setExists(this.getExists(date));
geoObj.setInvalid(this.getInvalid());
if (// && !vertex.isAppliedToDB())
vertex.isNew()) {
geoObj.setUid(RegistryIdService.getInstance().next());
}
return geoObj;
}
use of org.commongeoregistry.adapter.metadata.AttributeTermType 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 org.commongeoregistry.adapter.metadata.AttributeTermType in project geoprism-registry by terraframe.
the class GeoObjectAtTimeShapefileExporterTest method testCreateFeatures.
@Test
@Request
public void testCreateFeatures() {
ServerGeoObjectType type = FastTestDataset.PROVINCE.getServerObject();
GeoObjectAtTimeShapefileExporter exporter = new GeoObjectAtTimeShapefileExporter(type, FastTestDataset.DEFAULT_OVER_TIME_DATE);
SimpleFeatureType featureType = exporter.createFeatureType();
FeatureCollection<SimpleFeatureType, SimpleFeature> features = exporter.features(featureType);
Assert.assertTrue(features.size() > 0);
final FeatureIterator<SimpleFeature> it = features.features();
boolean hasCentralProvince = false;
while (it.hasNext()) {
SimpleFeature feature = it.next();
if (feature.getID().equals(FastTestDataset.PROV_CENTRAL.getCode())) {
hasCentralProvince = true;
final ServerGeoObjectIF object = FastTestDataset.PROV_CENTRAL.getServerObject();
Object geometry = feature.getDefaultGeometry();
Assert.assertNotNull(geometry);
Collection<AttributeType> attributes = new ImportAttributeSerializer(Session.getCurrentLocale(), false, false, LocalizationFacade.getInstalledLocales()).attributes(type.getType());
for (AttributeType attribute : attributes) {
String attributeName = attribute.getName();
Object oValue = object.getValue(attributeName);
Object fValue = feature.getAttribute(exporter.getColumnName(attributeName));
if (attribute instanceof AttributeTermType) {
Assert.assertEquals("Attributes not equal [" + attributeName + "]", GeoObjectUtil.convertToTermString((AttributeTermType) attribute, oValue), fValue);
} else if (attribute instanceof AttributeLocalType) {
Assert.assertEquals("Attributes not equal [" + attributeName + "]", ((LocalizedValue) oValue).getValue(), fValue);
} else {
Assert.assertEquals("Attributes not equal [" + attributeName + "]", oValue, fValue);
}
}
}
}
Assert.assertTrue("Unable to find the central province feature", hasCentralProvince);
}
use of org.commongeoregistry.adapter.metadata.AttributeTermType in project geoprism-registry by terraframe.
the class XMLImporterTest method testImport.
@Request
@Test
public void testImport() throws IOException {
Organization organization = new Organization();
organization.setCode("TEST_ORG");
organization.getDisplayLabel().setValue("Test Org");
organization.apply();
try (InputStream istream = this.getClass().getResourceAsStream("/xml/test-domain.xml")) {
XMLImporter xmlImporter = new XMLImporter();
List<ServerElement> results = xmlImporter.importXMLDefinitions(organization, istream);
try {
RegistryService.getInstance().refreshMetadataCache();
Assert.assertEquals(4, results.size());
ServerGeoObjectType type = ServerGeoObjectType.get(results.get(0).getCode());
Assert.assertEquals("TEST_VILLAGE", type.getCode());
Assert.assertEquals("Test Village", type.getLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
Assert.assertEquals(GeometryType.MULTIPOINT, type.getGeometryType());
Assert.assertFalse(type.getIsPrivate());
Assert.assertFalse(type.isGeometryEditable());
Assert.assertTrue(type.getIsAbstract());
Optional<AttributeType> oattribute = type.getAttribute("TEST_TEXT");
Assert.assertTrue(oattribute.isPresent());
AttributeType attributeType = oattribute.get();
Assert.assertEquals("Test Text", attributeType.getLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
Assert.assertEquals("Test Text Description", attributeType.getDescription().getValue(LocalizedValue.DEFAULT_LOCALE));
oattribute = type.getAttribute("TEST_BOOLEAN");
Assert.assertTrue(oattribute.isPresent());
attributeType = oattribute.get();
Assert.assertEquals("Test Boolean", attributeType.getLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
Assert.assertEquals("Test Boolean Description", attributeType.getDescription().getValue(LocalizedValue.DEFAULT_LOCALE));
oattribute = type.getAttribute("TEST_INTEGER");
Assert.assertTrue(oattribute.isPresent());
attributeType = oattribute.get();
Assert.assertEquals("Test Integer", attributeType.getLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
Assert.assertEquals("Test Integer Description", attributeType.getDescription().getValue(LocalizedValue.DEFAULT_LOCALE));
oattribute = type.getAttribute("TEST_DATE");
Assert.assertTrue(oattribute.isPresent());
attributeType = oattribute.get();
Assert.assertEquals("Test Date", attributeType.getLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
Assert.assertEquals("Test Date Description", attributeType.getDescription().getValue(LocalizedValue.DEFAULT_LOCALE));
oattribute = type.getAttribute("TEST_DECIMAL");
Assert.assertTrue(oattribute.isPresent());
attributeType = oattribute.get();
Assert.assertEquals("Test Decimal", attributeType.getLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
Assert.assertEquals("Test Decimal Description", attributeType.getDescription().getValue(LocalizedValue.DEFAULT_LOCALE));
oattribute = type.getAttribute("TEST_TERM");
Assert.assertTrue(oattribute.isPresent());
attributeType = oattribute.get();
Assert.assertEquals("Test Term", attributeType.getLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
Assert.assertEquals("Test Term Description", attributeType.getDescription().getValue(LocalizedValue.DEFAULT_LOCALE));
List<Term> terms = ((AttributeTermType) attributeType).getTerms();
Assert.assertEquals(3, terms.size());
oattribute = type.getAttribute("TEST_CLASSIFICATION");
Assert.assertTrue(oattribute.isPresent());
attributeType = oattribute.get();
Assert.assertEquals("Test Classification", attributeType.getLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
Assert.assertEquals("Test Text Classification", attributeType.getDescription().getValue(LocalizedValue.DEFAULT_LOCALE));
Assert.assertEquals("TEST_PROG", ((AttributeClassificationType) attributeType).getClassificationType());
Assert.assertEquals(ROOT_CODE, ((AttributeClassificationType) attributeType).getRootTerm().getCode());
type = ServerGeoObjectType.get(results.get(1).getCode());
Assert.assertEquals("TEST_GI", type.getCode());
Assert.assertEquals("Test GI", type.getLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
Assert.assertEquals(GeometryType.MULTIPOINT, type.getGeometryType());
Assert.assertFalse(type.getIsPrivate());
Assert.assertFalse(type.isGeometryEditable());
Assert.assertFalse(type.getIsAbstract());
Assert.assertEquals("TEST_VILLAGE", type.getSuperType().getCode());
ServerHierarchyType hierarchy = ServerHierarchyType.get(results.get(3).getCode());
Assert.assertEquals("TEST_HIERARCHY", hierarchy.getCode());
Assert.assertEquals("Test Hierarchy", hierarchy.getDisplayLabel().getValue(LocalizedValue.DEFAULT_LOCALE));
Assert.assertEquals("Test Hierarchy Description", hierarchy.getDescription().getValue(LocalizedValue.DEFAULT_LOCALE));
Assert.assertEquals("Test Progress", hierarchy.getProgress());
Assert.assertEquals("Test Disclaimer", hierarchy.getDisclaimer());
Assert.assertEquals("Test Access Constraints", hierarchy.getAccessConstraints());
Assert.assertEquals("Test Use Constraints", hierarchy.getUseConstraints());
Assert.assertEquals("Test Acknowledgement", hierarchy.getAcknowledgement());
List<HierarchyNode> nodes = hierarchy.getRootGeoObjectTypes();
Assert.assertEquals(1, nodes.size());
HierarchyNode node = nodes.get(0);
Assert.assertEquals("TEST_DISTRICT", node.getGeoObjectType().getCode());
nodes = node.getChildren();
Assert.assertEquals(1, nodes.size());
node = nodes.get(0);
Assert.assertEquals("TEST_VILLAGE", node.getGeoObjectType().getCode());
} finally {
Collections.reverse(results);
for (ServerElement result : results) {
result.delete();
}
}
} finally {
organization.delete();
}
}
Aggregations