use of org.commongeoregistry.adapter.metadata.AttributeType in project geoprism-registry by terraframe.
the class ConversionTest method testAttributeTypeBooleanTree.
// Heads up: clean up
// @Test
// public void testAttributeTypeDateLeaf()
// {
// String sessionId = testData.adminClientRequest.getSessionId();
//
// Calendar calendar = Calendar.getInstance();
// calendar.clear();
// calendar.set(2019, Calendar.JANUARY, 12, 20, 21, 32);
//
// // Add a new custom attribute
// AttributeType testDate = AttributeType.factory("testDate", new LocalizedValue("testDateLocalName"), new LocalizedValue("testDateLocalDescrip"), AttributeDateType.TYPE, false, false, false);
// testDate = ServiceFactory.getRegistryService().createAttributeType(sessionId, USATestData.DISTRICT.getCode(), testDate.toJSON().toString());
//
// // Create a new GeoObject with the custom attribute
// GeoObject geoObj = ServiceFactory.getRegistryService().newGeoObjectInstance(sessionId, USATestData.DISTRICT.getCode());
// geoObj.setCode(testGo.getCode());
// geoObj.setDisplayLabel(LocalizedValue.DEFAULT_LOCALE, "Test Label");
// geoObj.setUid(ServiceFactory.getRegistryService().getUIDS(sessionId, 1)[0]);
// geoObj.setValue(testDate.getName(), calendar.getTime());
//
// ServiceFactory.getRegistryService().createGeoObject(sessionId, geoObj.toJSON().toString());
//
// // Get the object with the custom attribute
// GeoObject result = ServiceFactory.getRegistryService().getGeoObjectByCode(sessionId, testGo.getCode(), USATestData.DISTRICT.getCode());
//
// Assert.assertNotNull(result);
// Assert.assertEquals(geoObj.getValue(testDate.getName()), result.getValue(testDate.getName()));
// }
@Test
public void testAttributeTypeBooleanTree() {
String sessionId = testData.clientRequest.getSessionId();
// Add a new custom attribute
AttributeType testBoolean = AttributeType.factory("testBoolean", new LocalizedValue("testBooleanLocalName"), new LocalizedValue("testBooleanLocalDescrip"), AttributeBooleanType.TYPE, false, false, false);
testBoolean = ServiceFactory.getRegistryService().createAttributeType(sessionId, USATestData.STATE.getCode(), testBoolean.toJSON().toString());
// Create a new GeoObject with the custom attribute
GeoObject geoObj = ServiceFactory.getRegistryService().newGeoObjectInstance(sessionId, USATestData.STATE.getCode());
geoObj.setCode(testGo.getCode());
geoObj.setDisplayLabel(LocalizedValue.DEFAULT_LOCALE, "Test Label");
geoObj.setUid(ServiceFactory.getRegistryService().getUIDS(sessionId, 1)[0]);
geoObj.setValue(testBoolean.getName(), new Boolean(true));
ServiceFactory.getRegistryService().createGeoObject(sessionId, geoObj.toJSON().toString(), TestDataSet.DEFAULT_OVER_TIME_DATE, TestDataSet.DEFAULT_END_TIME_DATE);
// Get the object with the custom attribute
GeoObject result = ServiceFactory.getRegistryService().getGeoObjectByCode(sessionId, testGo.getCode(), USATestData.STATE.getCode(), TestDataSet.DEFAULT_OVER_TIME_DATE);
Assert.assertNotNull(result);
Assert.assertEquals(geoObj.getValue(testBoolean.getName()), result.getValue(testBoolean.getName()));
}
use of org.commongeoregistry.adapter.metadata.AttributeType in project geoprism-registry by terraframe.
the class ConversionTest method testAttributeTypeFloatTree.
// Heads up: clean up
// @Test
// public void testAttributeTypeBooleanLeaf()
// {
// String sessionId = testData.adminClientRequest.getSessionId();
//
// // Add a new custom attribute
// AttributeType testBoolean = AttributeType.factory("testBoolean", new LocalizedValue("testBooleanLocalName"), new LocalizedValue("testBooleanLocalDescrip"), AttributeBooleanType.TYPE, false, false, false);
// testBoolean = ServiceFactory.getRegistryService().createAttributeType(sessionId, USATestData.DISTRICT.getCode(), testBoolean.toJSON().toString());
//
// // Create a new GeoObject with the custom attribute
// GeoObject geoObj = ServiceFactory.getRegistryService().newGeoObjectInstance(sessionId, USATestData.DISTRICT.getCode());
// geoObj.setCode(testGo.getCode());
// geoObj.setDisplayLabel(LocalizedValue.DEFAULT_LOCALE, "Test Label");
// geoObj.setUid(ServiceFactory.getRegistryService().getUIDS(sessionId, 1)[0]);
// geoObj.setValue(testBoolean.getName(), new Boolean(true));
//
// ServiceFactory.getRegistryService().createGeoObject(sessionId, geoObj.toJSON().toString());
//
// // Get the object with the custom attribute
// GeoObject result = ServiceFactory.getRegistryService().getGeoObjectByCode(sessionId, testGo.getCode(), USATestData.DISTRICT.getCode());
//
// Assert.assertNotNull(result);
// Assert.assertEquals(geoObj.getValue(testBoolean.getName()), result.getValue(testBoolean.getName()));
// }
@Test
public void testAttributeTypeFloatTree() {
String sessionId = testData.clientRequest.getSessionId();
// Add a new custom attribute
AttributeType testFloat = AttributeType.factory("testFloat", new LocalizedValue("testFloatLocalName"), new LocalizedValue("testFloatLocalDescrip"), AttributeFloatType.TYPE, false, false, false);
testFloat = ServiceFactory.getRegistryService().createAttributeType(sessionId, USATestData.STATE.getCode(), testFloat.toJSON().toString());
// Create a new GeoObject with the custom attribute
GeoObject geoObj = ServiceFactory.getRegistryService().newGeoObjectInstance(sessionId, USATestData.STATE.getCode());
geoObj.setCode(testGo.getCode());
geoObj.setDisplayLabel(LocalizedValue.DEFAULT_LOCALE, "Test Label");
geoObj.setUid(ServiceFactory.getRegistryService().getUIDS(sessionId, 1)[0]);
geoObj.setValue(testFloat.getName(), new Double(234.2));
ServiceFactory.getRegistryService().createGeoObject(sessionId, geoObj.toJSON().toString(), TestDataSet.DEFAULT_OVER_TIME_DATE, TestDataSet.DEFAULT_END_TIME_DATE);
// Get the object with the custom attribute
GeoObject result = ServiceFactory.getRegistryService().getGeoObjectByCode(sessionId, testGo.getCode(), USATestData.STATE.getCode(), TestDataSet.DEFAULT_OVER_TIME_DATE);
Assert.assertNotNull(result);
Assert.assertEquals(geoObj.getValue(testFloat.getName()), result.getValue(testFloat.getName()));
}
use of org.commongeoregistry.adapter.metadata.AttributeType in project geoprism-registry by terraframe.
the class ListTypeGeoObjectShapefileExporterTest method testCreateFeatures.
@Test
@Request
public void testCreateFeatures() {
ServerGeoObjectIF object = FastTestDataset.PROV_CENTRAL.getServerObject();
ServerGeoObjectType type = object.getType();
ListTypeShapefileExporter exporter = new ListTypeShapefileExporter(version, mdBusiness, mdAttributes, new JsonObject());
SimpleFeatureType featureType = exporter.createFeatureType();
FeatureCollection<SimpleFeatureType, SimpleFeature> features = exporter.features(featureType);
Assert.assertEquals(2, features.size());
FeatureIterator<SimpleFeature> it = features.features();
SimpleFeature feature = null;
while (it.hasNext()) {
SimpleFeature f = it.next();
if (object.getCode().equals(f.getAttribute(GeoObject.CODE))) {
feature = f;
}
}
Assert.assertNotNull(feature);
Assert.assertEquals("Attributes not equal [code]", object.getCode(), feature.getAttribute(GeoObject.CODE));
Object geometry = feature.getDefaultGeometry();
Assert.assertNotNull(geometry);
ImportAttributeSerializer serializer = new ImportAttributeSerializer(Session.getCurrentLocale(), false, false, LocalizationFacade.getInstalledLocales());
Collection<AttributeType> attributes = serializer.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.assertEquals(FastTestDataset.CAMBODIA.getCode(), feature.getAttribute(exporter.getColumnName("fastadmincodefastcountry")));
Assert.assertEquals(FastTestDataset.CAMBODIA.getDisplayLabel(), feature.getAttribute(exporter.getColumnName("fastadmincodefastcountryDefaultLocale")));
}
use of org.commongeoregistry.adapter.metadata.AttributeType in project geoprism-registry by terraframe.
the class BusinessType method createAttributeType.
public AttributeType createAttributeType(String attributeTypeJSON) {
JsonObject attrObj = JsonParser.parseString(attributeTypeJSON).getAsJsonObject();
AttributeType attrType = AttributeType.parse(attrObj);
return createAttributeType(attrType);
}
use of org.commongeoregistry.adapter.metadata.AttributeType in project geoprism-registry by terraframe.
the class ListType method getRestriction.
public BasicVertexRestriction getRestriction(ServerGeoObjectType type, Date forDate) {
String filterJson = this.getFilterJson();
if (filterJson != null && filterJson.length() > 0) {
JsonArray filters = JsonParser.parseString(filterJson).getAsJsonArray();
CompositeRestriction restriction = new CompositeRestriction();
for (int i = 0; i < filters.size(); i++) {
JsonObject filter = filters.get(i).getAsJsonObject();
String attributeName = filter.get("attribute").getAsString();
String operation = filter.get("operation").getAsString();
AttributeType attributeType = type.getAttribute(attributeName).get();
MdAttributeDAOIF mdAttribute = type.getMdVertex().definesAttribute(attributeName);
if (attributeType instanceof AttributeDateType) {
String value = filter.get("value").getAsString();
Date date = GeoRegistryUtil.parseDate(value, false);
restriction.add(new AttributeValueRestriction(mdAttribute, operation, date, forDate));
} else if (attributeType instanceof AttributeBooleanType) {
String value = filter.get("value").getAsString();
Boolean bVal = Boolean.valueOf(value);
restriction.add(new AttributeValueRestriction(mdAttribute, operation, bVal, forDate));
} else if (attributeType instanceof AttributeTermType) {
String code = filter.get("value").getAsString();
Term root = ((AttributeTermType) attributeType).getRootTerm();
String parent = TermConverter.buildClassifierKeyFromTermCode(root.getCode());
String classifierKey = Classifier.buildKey(parent, code);
Classifier classifier = Classifier.getByKey(classifierKey);
restriction.add(new AttributeValueRestriction(mdAttribute, operation, classifier.getOid(), forDate));
} else if (attributeType instanceof AttributeClassificationType) {
JsonObject object = filter.get("value").getAsJsonObject();
Term term = Term.fromJSON(object);
MdClassificationDAOIF mdClassification = ((MdAttributeClassificationDAOIF) mdAttribute).getMdClassificationDAOIF();
MdEdgeDAOIF mdEdge = mdClassification.getReferenceMdEdgeDAO();
ClassificationType classificationType = new ClassificationType(mdClassification);
Classification classification = Classification.get(classificationType, term.getCode());
restriction.add(new AttributeValueRestriction(mdAttribute, operation, classification.getVertex().getRID(), forDate));
} else {
String value = filter.get("value").getAsString();
restriction.add(new AttributeValueRestriction(mdAttribute, operation, value, forDate));
}
}
if (restriction.getRestrictions().size() > 0) {
return restriction;
}
}
return null;
}
Aggregations