Search in sources :

Example 21 with VertexServerGeoObject

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

the class GeoObjectAtTimeShapefileExporter method features.

public FeatureCollection<SimpleFeatureType, SimpleFeature> features(SimpleFeatureType featureType) {
    final int BLOCK_SIZE = 2000;
    List<SimpleFeature> features = new ArrayList<SimpleFeature>();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
    VertexServerGeoObject prev = null;
    do {
        final VertexSelectGeoObjectQuery query = new VertexSelectGeoObjectQuery(type, this.date, prev);
        query.setLimit(BLOCK_SIZE);
        final List<VertexServerGeoObject> objects = query.getResults();
        prev = null;
        for (VertexServerGeoObject object : objects) {
            if (!object.getInvalid()) {
                builder.set(GEOM, object.getGeometry());
                this.attributes.forEach(attribute -> {
                    String name = attribute.getName();
                    String columnName = this.getColumnName(name);
                    Object value = attribute.isChangeOverTime() ? object.getValue(name, this.date) : object.getValue(name);
                    if (attribute instanceof AttributeTermType) {
                        builder.set(columnName, GeoObjectUtil.convertToTermString((AttributeTermType) attribute, value));
                    } else if (attribute instanceof AttributeClassificationType) {
                        builder.set(columnName, GeoObjectUtil.convertToTermString((AttributeClassificationType) attribute, value));
                    } else if (attribute instanceof AttributeLocalType) {
                        builder.set(columnName, ((LocalizedValue) value).getValue());
                    } else {
                        builder.set(columnName, value);
                    }
                });
                AttributeType attribute = this.getType().getAttribute(DefaultAttribute.DISPLAY_LABEL.getName()).get();
                LocalizedValue label = object.getDisplayLabel(this.date);
                builder.set(this.getColumnName(attribute.getName() + " " + MdAttributeLocalInfo.DEFAULT_LOCALE), label.getValue(LocalizedValue.DEFAULT_LOCALE));
                for (Locale locale : locales) {
                    builder.set(this.getColumnName(attribute.getName() + " " + locale.toString()), label.getValue(locale));
                }
                SimpleFeature feature = builder.buildFeature(object.getCode());
                features.add(feature);
            }
            prev = object;
            Thread.yield();
        }
    } while (prev != null);
    return new ListFeatureCollection(featureType, features);
}
Also used : Locale(java.util.Locale) ArrayList(java.util.ArrayList) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) SimpleFeature(org.opengis.feature.simple.SimpleFeature) AttributeLocalType(org.commongeoregistry.adapter.metadata.AttributeLocalType) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) ListFeatureCollection(org.geotools.data.collection.ListFeatureCollection) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) VertexSelectGeoObjectQuery(net.geoprism.registry.query.graph.VertexSelectGeoObjectQuery) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 22 with VertexServerGeoObject

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

the class UpdateParentValueOverTimeView method executeParent.

public void executeParent(UpdateChangeOverTimeAttributeView cotView, VertexServerGeoObject go, SortedSet<EdgeObject> looseVotc) {
    UpdateParentView parentView = (UpdateParentView) cotView;
    final ServerHierarchyType hierarchyType = ServerHierarchyType.get(parentView.getHierarchyCode());
    if (this.action.equals(UpdateActionType.DELETE)) {
        EdgeObject edge = this.getEdgeByOid(looseVotc, this.oid);
        if (edge == null) {
            ExecuteOutOfDateChangeRequestException ex = new ExecuteOutOfDateChangeRequestException();
            throw ex;
        }
        edge.delete();
        looseVotc.remove(edge);
    } else if (this.action.equals(UpdateActionType.UPDATE)) {
        EdgeObject edge = this.getEdgeByOid(looseVotc, this.oid);
        if (edge == null) {
            ExecuteOutOfDateChangeRequestException ex = new ExecuteOutOfDateChangeRequestException();
            throw ex;
        }
        final VertexServerGeoObject newParent = this.getNewValueAsGO();
        final String parentCode = newParent == null ? null : newParent.getCode();
        String currentCode = edge.getParent().getObjectValue(DefaultAttribute.CODE.getName());
        // Parent values can only be changed by deleting the current edge and creating a new one unfortunately
        if (this.newValue != null && (currentCode != parentCode)) {
            Date _newStartDate = this.newStartDate;
            Date _newEndDate = this.newEndDate;
            if (_newStartDate == null) {
                _newStartDate = edge.getObjectValue(GeoVertex.START_DATE);
            }
            if (_newEndDate == null) {
                _newEndDate = edge.getObjectValue(GeoVertex.END_DATE);
            }
            edge.delete();
            looseVotc.remove(edge);
            if (newParent != null) {
                // We unfortunately can't use this method because we have to bypass the votc reordering and validation
                // go.addParent(newParent, hierarchyType, _newStartDate, _newEndDate);
                EdgeObject newEdge = go.getVertex().addParent(((VertexComponent) newParent).getVertex(), hierarchyType.getMdEdge());
                newEdge.setValue(GeoVertex.START_DATE, _newStartDate);
                newEdge.setValue(GeoVertex.END_DATE, _newEndDate);
                newEdge.apply();
                looseVotc.add(newEdge);
            }
            return;
        }
        if (newStartDate != null) {
            edge.setValue(GeoVertex.START_DATE, newStartDate);
        }
        if (newEndDate != null) {
            edge.setValue(GeoVertex.END_DATE, newEndDate);
        }
        edge.apply();
    } else if (this.action.equals(UpdateActionType.CREATE)) {
        final VertexServerGeoObject newParent = this.getNewValueAsGO();
        if (newParent == null || this.newStartDate == null || this.newEndDate == null) {
            throw new InvalidChangeRequestException();
        }
        EdgeObject edge = go.getEdge(newParent, hierarchyType, this.newStartDate, this.newEndDate);
        if (edge != null) {
            ExecuteOutOfDateChangeRequestException ex = new ExecuteOutOfDateChangeRequestException();
            throw ex;
        }
        // We unfortunately can't use this method because we have to bypass the votc reordering and validation
        // go.addParent(newParent, hierarchyType, this.newStartDate, this.newEndDate);
        EdgeObject newEdge = go.getVertex().addParent(((VertexComponent) newParent).getVertex(), hierarchyType.getMdEdge());
        newEdge.setValue(GeoVertex.START_DATE, this.newStartDate);
        newEdge.setValue(GeoVertex.END_DATE, this.newEndDate);
        newEdge.apply();
        looseVotc.add(newEdge);
    } else {
        throw new UnsupportedOperationException("Unsupported action type [" + this.action + "].");
    }
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) InvalidChangeRequestException(net.geoprism.registry.action.InvalidChangeRequestException) EdgeObject(com.runwaysdk.business.graph.EdgeObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) Date(java.util.Date) ExecuteOutOfDateChangeRequestException(net.geoprism.registry.action.ExecuteOutOfDateChangeRequestException) VertexComponent(net.geoprism.registry.model.graph.VertexComponent)

Example 23 with VertexServerGeoObject

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

the class UpdateParentValueOverTimeView method getNewValueAsGO.

public VertexServerGeoObject getNewValueAsGO() {
    if (this.newValue != null && !this.newValue.isJsonNull()) {
        String[] newValueSplit = (this.getNewValue().getAsString()).split(VALUE_SPLIT_TOKEN);
        String parentTypeCode = newValueSplit[0];
        String parentCode = newValueSplit[1];
        ServerGeoObjectType parentType = ServerGeoObjectType.get(parentTypeCode);
        final VertexServerGeoObject parent = new VertexGeoObjectStrategy(parentType).getGeoObjectByCode(parentCode);
        return parent;
    }
    return null;
}
Also used : VertexGeoObjectStrategy(net.geoprism.registry.conversion.VertexGeoObjectStrategy) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject)

Example 24 with VertexServerGeoObject

use of net.geoprism.registry.model.graph.VertexServerGeoObject 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 25 with VertexServerGeoObject

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

the class RelationshipVisualizationService method tree.

@Request(RequestType.SESSION)
public JsonElement tree(String sessionId, Date date, String relationshipType, String graphTypeCode, String geoObjectCode, String geoObjectTypeCode) {
    final GeoObjectTypePermissionServiceIF typePermissions = ServiceFactory.getGeoObjectTypePermissionService();
    final ServerGeoObjectType type = ServiceFactory.getMetadataCache().getGeoObjectType(geoObjectTypeCode).get();
    JsonObject view = new JsonObject();
    JsonArray jaEdges = new JsonArray();
    view.add("edges", jaEdges);
    JsonArray jaVerticies = new JsonArray();
    view.add("verticies", jaVerticies);
    if (typePermissions.canRead(type.getOrganization().getCode(), type, type.getIsPrivate())) {
        VertexServerGeoObject rootGo = (VertexServerGeoObject) ServiceFactory.getGeoObjectService().getGeoObjectByCode(geoObjectCode, type);
        final GraphType graphType = GraphType.getByCode(relationshipType, graphTypeCode);
        jaVerticies.add(serializeVertex(rootGo, (graphType instanceof UndirectedGraphType) ? "PARENT" : "SELECTED"));
        Set<String> setEdges = new HashSet<String>();
        Set<String> setVerticies = new HashSet<String>();
        if (graphType instanceof UndirectedGraphType) {
            // get parent and get children return the same thing for an undirected
            // graph
            fetchChildrenData(false, rootGo, graphType, date, jaEdges, jaVerticies, setEdges, setVerticies);
        } else if (graphType instanceof DirectedAcyclicGraphType) {
            // Out is children
            fetchParentsData(false, rootGo, graphType, date, jaEdges, jaVerticies, setEdges, setVerticies);
            // In is parents
            fetchChildrenData(false, rootGo, graphType, date, jaEdges, jaVerticies, setEdges, setVerticies);
        } else {
            // Out is children
            fetchParentsData(true, rootGo, graphType, date, jaEdges, jaVerticies, setEdges, setVerticies);
            // In is parents
            fetchChildrenData(false, rootGo, graphType, date, jaEdges, jaVerticies, setEdges, setVerticies);
        }
    }
    return view;
}
Also used : JsonArray(com.google.gson.JsonArray) DirectedAcyclicGraphType(net.geoprism.registry.DirectedAcyclicGraphType) GraphType(net.geoprism.registry.model.GraphType) UndirectedGraphType(net.geoprism.registry.UndirectedGraphType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) DirectedAcyclicGraphType(net.geoprism.registry.DirectedAcyclicGraphType) JsonObject(com.google.gson.JsonObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) GeoObjectTypePermissionServiceIF(net.geoprism.registry.permission.GeoObjectTypePermissionServiceIF) UndirectedGraphType(net.geoprism.registry.UndirectedGraphType) HashSet(java.util.HashSet) Request(com.runwaysdk.session.Request)

Aggregations

VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)51 VertexObject (com.runwaysdk.business.graph.VertexObject)20 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)19 JsonObject (com.google.gson.JsonObject)18 Request (com.runwaysdk.session.Request)13 Date (java.util.Date)12 LinkedList (java.util.LinkedList)11 ChangeRequest (net.geoprism.registry.action.ChangeRequest)11 JsonArray (com.google.gson.JsonArray)10 ValueOverTime (com.runwaysdk.dataaccess.graph.attributes.ValueOverTime)10 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)10 MdVertexDAOIF (com.runwaysdk.dataaccess.MdVertexDAOIF)9 GraphQuery (com.runwaysdk.business.graph.GraphQuery)8 UpdateAttributeAction (net.geoprism.registry.action.geoobject.UpdateAttributeAction)8 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)8 QueryFactory (com.runwaysdk.query.QueryFactory)6 SimpleDateFormat (java.text.SimpleDateFormat)6 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)6 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)6 MdAttributeDAOIF (com.runwaysdk.dataaccess.MdAttributeDAOIF)5