Search in sources :

Example 6 with Classification

use of net.geoprism.registry.model.Classification in project geoprism-registry by terraframe.

the class ClassificationService method getChildren.

@Request(RequestType.SESSION)
public JsonObject getChildren(String sessionId, String classificationCode, String code, Integer pageSize, Integer pageNumber) {
    ClassificationType type = ClassificationType.getByCode(classificationCode);
    if (code != null) {
        Classification parent = Classification.get(type, code);
        return parent.getChildren(pageSize, pageNumber).toJSON();
    }
    Classification root = type.getRoot();
    List<Classification> roots = new LinkedList<Classification>();
    if (root != null) {
        roots.add(root);
    }
    return new Page<Classification>(roots.size(), pageNumber, pageSize, roots).toJSON();
}
Also used : Classification(net.geoprism.registry.model.Classification) ClassificationType(net.geoprism.registry.model.ClassificationType) LinkedList(java.util.LinkedList) Request(com.runwaysdk.session.Request)

Example 7 with Classification

use of net.geoprism.registry.model.Classification in project geoprism-registry by terraframe.

the class ClassificationService method addChild.

@Request(RequestType.SESSION)
public void addChild(String sessionId, String classificationCode, String parentCode, String childCode) {
    ClassificationType type = ClassificationType.getByCode(classificationCode);
    Classification parent = Classification.get(type, parentCode);
    Classification child = Classification.get(type, childCode);
    parent.addChild(child);
}
Also used : Classification(net.geoprism.registry.model.Classification) ClassificationType(net.geoprism.registry.model.ClassificationType) Request(com.runwaysdk.session.Request)

Example 8 with Classification

use of net.geoprism.registry.model.Classification in project geoprism-registry by terraframe.

the class UpdateValueOverTimeView method persistValue.

private void persistValue(ValueOverTime vot, UpdateChangeOverTimeAttributeView cotView, VertexServerGeoObject go, List<ValueOverTime> looseVotc) {
    if (this.newValue == null) {
        return;
    }
    if (cotView.getAttributeName().equals("geometry")) {
        Geometry convertedValue = null;
        if (!this.newValue.isJsonNull()) {
            GeoJSONReader reader = new GeoJSONReader();
            convertedValue = reader.read(this.newValue.toString());
            if (!go.isValidGeometry(convertedValue)) {
                GeometryTypeException ex = new GeometryTypeException();
                ex.setActualType(convertedValue.getGeometryType());
                ex.setExpectedType(go.getType().getGeometryType().name());
                throw ex;
            }
        }
        if (vot != null) {
            vot.setValue(convertedValue);
        } else {
            looseVotc.add(new ValueOverTime(this.newStartDate, this.newEndDate, convertedValue));
        }
    } else {
        ServerGeoObjectType type = go.getType();
        AttributeType attype = type.getAttribute(cotView.getAttributeName()).get();
        if (attype instanceof AttributeLocalType) {
            LocalizedValue convertedValue = null;
            if (!this.newValue.isJsonNull()) {
                convertedValue = LocalizedValue.fromJSON(this.newValue.getAsJsonObject());
            }
            final Set<Locale> locales = LocalizationFacade.getInstalledLocales();
            if (vot != null) {
                if (convertedValue != null) {
                    GraphObjectDAO votEmbeddedValue = (GraphObjectDAO) vot.getValue();
                    votEmbeddedValue.setValue(MdAttributeLocalInfo.DEFAULT_LOCALE, convertedValue.getValue(MdAttributeLocalInfo.DEFAULT_LOCALE));
                    for (Locale locale : locales) {
                        if (convertedValue.contains(locale)) {
                            votEmbeddedValue.setValue(locale.toString(), convertedValue.getValue(locale));
                        }
                    }
                } else {
                    vot.setValue(null);
                }
            } else {
                if (convertedValue != null) {
                    MdAttributeEmbeddedDAOIF mdAttrEmbedded = (MdAttributeEmbeddedDAOIF) go.getMdAttributeDAO(attype.getName());
                    VertexObjectDAO votEmbeddedValue = VertexObjectDAO.newInstance((MdVertexDAOIF) mdAttrEmbedded.getEmbeddedMdClassDAOIF());
                    votEmbeddedValue.setValue(MdAttributeLocalInfo.DEFAULT_LOCALE, convertedValue.getValue(MdAttributeLocalInfo.DEFAULT_LOCALE));
                    for (Locale locale : locales) {
                        if (convertedValue.contains(locale)) {
                            votEmbeddedValue.setValue(locale.toString(), convertedValue.getValue(locale));
                        }
                    }
                    looseVotc.add(new ValueOverTime(this.newStartDate, this.newEndDate, votEmbeddedValue));
                } else {
                    looseVotc.add(new ValueOverTime(this.newStartDate, this.newEndDate, null));
                }
            }
        } else // else if (attype.getName().equals(DefaultAttribute.EXISTS.getName()))
        // {
        // if (this.newValue.isJsonNull())
        // {
        // if (vot != null)
        // {
        // vot.setValue(null);
        // }
        // else
        // {
        // looseVotc.add(new ValueOverTime(this.newStartDate, this.newEndDate,
        // null));
        // }
        // }
        // else
        // {
        // JsonArray ja = this.newValue.getAsJsonArray();
        // 
        // if (ja.size() > 0)
        // {
        // String code = ja.get(0).getAsString();
        // 
        // if (code == null || code.length() == 0)
        // {
        // if (vot != null)
        // {
        // vot.setValue(null);
        // }
        // else
        // {
        // looseVotc.add(new ValueOverTime(this.newStartDate, this.newEndDate,
        // null));
        // }
        // }
        // else
        // {
        // Term value = ( (AttributeTermType) attype ).getTermByCode(code).get();
        // GeoObjectStatus gos =
        // ConversionService.getInstance().termToGeoObjectStatus(value);
        // 
        // if (vot != null)
        // {
        // vot.setValue(gos.getOid());
        // }
        // else
        // {
        // looseVotc.add(new ValueOverTime(this.newStartDate, this.newEndDate,
        // gos.getOid()));
        // }
        // }
        // }
        // }
        // }
        {
            Object convertedValue = null;
            if (!this.newValue.isJsonNull()) {
                if (attype instanceof AttributeDateType) {
                    long epoch = this.newValue.getAsLong();
                    convertedValue = new Date(epoch);
                } else if (attype instanceof AttributeTermType) {
                    JsonArray ja = this.newValue.getAsJsonArray();
                    if (ja.size() > 0) {
                        String code = ja.get(0).getAsString();
                        Term root = ((AttributeTermType) attype).getRootTerm();
                        String parent = TermConverter.buildClassifierKeyFromTermCode(root.getCode());
                        String classifierKey = Classifier.buildKey(parent, code);
                        Classifier classifier = Classifier.getByKey(classifierKey);
                        convertedValue = classifier.getOid();
                    }
                } else if (attype instanceof AttributeClassificationType) {
                    JsonObject object = this.newValue.getAsJsonObject();
                    String code = object.get("code").getAsString();
                    Classification classification = Classification.get((AttributeClassificationType) attype, code);
                    convertedValue = new AttributeGraphRef.ID(classification.getOid(), classification.getVertex().getRID());
                } else if (attype instanceof AttributeBooleanType) {
                    convertedValue = this.newValue.getAsBoolean();
                } else if (attype instanceof AttributeFloatType) {
                    convertedValue = this.newValue.getAsDouble();
                } else if (attype instanceof AttributeIntegerType) {
                    convertedValue = this.newValue.getAsLong();
                } else {
                    convertedValue = this.newValue.getAsString();
                }
            }
            if (vot != null) {
                vot.setValue(convertedValue);
            } else {
                looseVotc.add(new ValueOverTime(this.newStartDate, this.newEndDate, convertedValue));
            }
        }
    }
}
Also used : Locale(java.util.Locale) AttributeIntegerType(org.commongeoregistry.adapter.metadata.AttributeIntegerType) JsonObject(com.google.gson.JsonObject) Classifier(net.geoprism.ontology.Classifier) AttributeDateType(org.commongeoregistry.adapter.metadata.AttributeDateType) AttributeFloatType(org.commongeoregistry.adapter.metadata.AttributeFloatType) AttributeGraphRef(com.runwaysdk.dataaccess.graph.attributes.AttributeGraphRef) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) Classification(net.geoprism.registry.model.Classification) AttributeBooleanType(org.commongeoregistry.adapter.metadata.AttributeBooleanType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) MdAttributeEmbeddedDAOIF(com.runwaysdk.dataaccess.MdAttributeEmbeddedDAOIF) GeometryTypeException(net.geoprism.registry.GeometryTypeException) Term(org.commongeoregistry.adapter.Term) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) Date(java.util.Date) Geometry(com.vividsolutions.jts.geom.Geometry) JsonArray(com.google.gson.JsonArray) ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) AttributeLocalType(org.commongeoregistry.adapter.metadata.AttributeLocalType) GeoJSONReader(org.wololo.jts2geojson.GeoJSONReader) GraphObjectDAO(com.runwaysdk.dataaccess.graph.GraphObjectDAO) VertexObjectDAO(com.runwaysdk.dataaccess.graph.VertexObjectDAO) JsonObject(com.google.gson.JsonObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType)

Example 9 with Classification

use of net.geoprism.registry.model.Classification in project geoprism-registry by terraframe.

the class ClassificationTest method testAddGetChildApplyWithParent.

@Test
@Request
public void testAddGetChildApplyWithParent() {
    Classification parent = Classification.newInstance(type);
    parent.setCode(PARENT_CODE);
    parent.apply(null);
    try {
        Classification child = Classification.newInstance(type);
        child.setCode(CHILD_CODE);
        child.apply(parent);
        try {
            Page<Classification> children = parent.getChildren(20, 1);
            Assert.assertEquals(Long.valueOf(1), children.getCount());
            Classification result = children.getResults().get(0);
            Assert.assertEquals(child.getOid(), result.getOid());
        } finally {
            child.delete();
        }
    } finally {
        parent.delete();
    }
}
Also used : Classification(net.geoprism.registry.model.Classification) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 10 with Classification

use of net.geoprism.registry.model.Classification in project geoprism-registry by terraframe.

the class ClassificationTest method testGetAncestor.

@Test
@Request
public void testGetAncestor() {
    Classification grandParent = Classification.newInstance(type);
    grandParent.setCode(GRANDPARENT_CODE);
    grandParent.apply(null);
    try {
        Classification parent = Classification.newInstance(type);
        parent.setCode(PARENT_CODE);
        parent.apply(grandParent);
        try {
            Classification child = Classification.newInstance(type);
            child.setCode(CHILD_CODE);
            child.apply(parent);
            try {
                List<Classification> ancestors = child.getAncestors(null);
                Assert.assertEquals(3, ancestors.size());
            } finally {
                child.delete();
            }
        } finally {
            parent.delete();
        }
    } finally {
        grandParent.delete();
    }
}
Also used : Classification(net.geoprism.registry.model.Classification) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Aggregations

Classification (net.geoprism.registry.model.Classification)27 Request (com.runwaysdk.session.Request)19 ClassificationType (net.geoprism.registry.model.ClassificationType)14 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)9 AttributeClassificationType (org.commongeoregistry.adapter.metadata.AttributeClassificationType)8 AttributeTermType (org.commongeoregistry.adapter.metadata.AttributeTermType)8 Classifier (net.geoprism.ontology.Classifier)7 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)7 Term (org.commongeoregistry.adapter.Term)6 AbstractClassification (com.runwaysdk.system.AbstractClassification)5 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)5 JsonObject (com.google.gson.JsonObject)4 EdgeObject (com.runwaysdk.business.graph.EdgeObject)4 GraphObject (com.runwaysdk.business.graph.GraphObject)4 VertexObject (com.runwaysdk.business.graph.VertexObject)4 LineString (com.vividsolutions.jts.geom.LineString)4 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)4 Test (org.junit.Test)4 JsonArray (com.google.gson.JsonArray)3 MdClassificationDAOIF (com.runwaysdk.dataaccess.MdClassificationDAOIF)3