Search in sources :

Example 6 with UnknownTermException

use of org.commongeoregistry.adapter.dataaccess.UnknownTermException 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;
}
Also used : Attribute(org.commongeoregistry.adapter.dataaccess.Attribute) DefaultAttribute(org.commongeoregistry.adapter.constants.DefaultAttribute) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) LineString(com.vividsolutions.jts.geom.LineString) Classifier(net.geoprism.ontology.Classifier) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) ClassificationType(net.geoprism.registry.model.ClassificationType) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) TermValueException(net.geoprism.registry.io.TermValueException) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) Classification(net.geoprism.registry.model.Classification) AbstractClassification(com.runwaysdk.system.AbstractClassification) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) AbstractServerGeoObject(net.geoprism.registry.model.AbstractServerGeoObject) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) VertexObject(com.runwaysdk.business.graph.VertexObject) EdgeObject(com.runwaysdk.business.graph.EdgeObject) AbstractServerGeoObject(net.geoprism.registry.model.AbstractServerGeoObject) GraphObject(com.runwaysdk.business.graph.GraphObject) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) UnknownTermException(org.commongeoregistry.adapter.dataaccess.UnknownTermException)

Aggregations

TermValueException (net.geoprism.registry.io.TermValueException)6 UnknownTermException (org.commongeoregistry.adapter.dataaccess.UnknownTermException)6 VertexObject (com.runwaysdk.business.graph.VertexObject)4 Classifier (net.geoprism.ontology.Classifier)4 AttributeTermType (org.commongeoregistry.adapter.metadata.AttributeTermType)4 MdVertexDAOIF (com.runwaysdk.dataaccess.MdVertexDAOIF)3 EdgeObject (com.runwaysdk.business.graph.EdgeObject)2 GraphObject (com.runwaysdk.business.graph.GraphObject)2 MdAttributeClassificationDAOIF (com.runwaysdk.dataaccess.MdAttributeClassificationDAOIF)2 MdAttributeTermDAOIF (com.runwaysdk.dataaccess.MdAttributeTermDAOIF)2 MdBusinessDAOIF (com.runwaysdk.dataaccess.MdBusinessDAOIF)2 AbstractClassification (com.runwaysdk.system.AbstractClassification)2 LineString (com.vividsolutions.jts.geom.LineString)2 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)2 BusinessType (net.geoprism.registry.BusinessType)2 TermReferenceProblem (net.geoprism.registry.etl.TermReferenceProblem)2 AbstractServerGeoObject (net.geoprism.registry.model.AbstractServerGeoObject)2 Classification (net.geoprism.registry.model.Classification)2 ClassificationType (net.geoprism.registry.model.ClassificationType)2 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)2