Search in sources :

Example 21 with AttributeType

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()));
}
Also used : LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) Test(org.junit.Test)

Example 22 with AttributeType

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()));
}
Also used : LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) Test(org.junit.Test)

Example 23 with AttributeType

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")));
}
Also used : ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) JsonObject(com.google.gson.JsonObject) SimpleFeature(org.opengis.feature.simple.SimpleFeature) AttributeLocalType(org.commongeoregistry.adapter.metadata.AttributeLocalType) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) ListTypeShapefileExporter(net.geoprism.registry.shapefile.ListTypeShapefileExporter) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) JsonObject(com.google.gson.JsonObject) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) ListTypeTest(net.geoprism.registry.service.ListTypeTest) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 24 with AttributeType

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);
}
Also used : AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) JsonObject(com.google.gson.JsonObject)

Example 25 with AttributeType

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;
}
Also used : CompositeRestriction(net.geoprism.registry.query.graph.CompositeRestriction) MdEdgeDAOIF(com.runwaysdk.dataaccess.MdEdgeDAOIF) JsonObject(com.google.gson.JsonObject) Term(org.commongeoregistry.adapter.Term) Classifier(net.geoprism.ontology.Classifier) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) ClassificationType(net.geoprism.registry.model.ClassificationType) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) Date(java.util.Date) AttributeDateType(org.commongeoregistry.adapter.metadata.AttributeDateType) AttributeValueRestriction(net.geoprism.registry.query.graph.AttributeValueRestriction) JsonArray(com.google.gson.JsonArray) MdClassificationDAOIF(com.runwaysdk.dataaccess.MdClassificationDAOIF) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) Classification(net.geoprism.registry.model.Classification) AttributeBooleanType(org.commongeoregistry.adapter.metadata.AttributeBooleanType) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType)

Aggregations

AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)55 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)27 JsonObject (com.google.gson.JsonObject)18 Locale (java.util.Locale)17 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)17 AttributeTermType (org.commongeoregistry.adapter.metadata.AttributeTermType)16 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)15 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)12 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)11 AttributeClassificationType (org.commongeoregistry.adapter.metadata.AttributeClassificationType)11 LinkedList (java.util.LinkedList)10 Classifier (net.geoprism.ontology.Classifier)10 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)10 VertexObject (com.runwaysdk.business.graph.VertexObject)9 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)9 Request (com.runwaysdk.session.Request)9 List (java.util.List)9 Test (org.junit.Test)9 JsonArray (com.google.gson.JsonArray)8 MdBusiness (com.runwaysdk.system.metadata.MdBusiness)8