Search in sources :

Example 26 with EdgeObject

use of com.runwaysdk.business.graph.EdgeObject in project geoprism-registry by terraframe.

the class VertexServerGeoObject method internalGetParentGeoObjects.

protected static ServerParentTreeNode internalGetParentGeoObjects(VertexServerGeoObject child, String[] parentTypes, boolean recursive, ServerHierarchyType htIn, Date date) {
    ServerParentTreeNode tnRoot = new ServerParentTreeNode(child, htIn, date, null, null);
    Map<String, Object> parameters = new HashedMap<String, Object>();
    parameters.put("rid", child.getVertex().getRID());
    StringBuilder statement = new StringBuilder();
    statement.append("SELECT EXPAND( inE(");
    if (htIn != null) {
        statement.append("'" + htIn.getMdEdge().getDBClassName() + "'");
    }
    statement.append(")");
    if (date != null || (parentTypes != null && parentTypes.length > 0)) {
        statement.append("[");
        if (date != null) {
            statement.append(" :date BETWEEN startDate AND endDate");
            parameters.put("date", date);
        }
        if (parentTypes != null && parentTypes.length > 0) {
            if (date != null) {
                statement.append(" AND");
            }
            statement.append("(");
            for (int i = 0; i < parentTypes.length; i++) {
                ServerGeoObjectType type = ServerGeoObjectType.get(parentTypes[i]);
                final String paramName = "p" + Integer.toString(i);
                if (i > 0) {
                    statement.append(" OR ");
                }
                statement.append("out.@class = :" + paramName);
                parameters.put(paramName, type.getMdVertex().getDBClassName());
            }
            statement.append(")");
        }
        statement.append("]");
    }
    statement.append(") FROM :rid");
    GraphQuery<EdgeObject> query = new GraphQuery<EdgeObject>(statement.toString(), parameters);
    List<EdgeObject> edges = query.getResults();
    for (EdgeObject edge : edges) {
        MdEdgeDAOIF mdEdge = (MdEdgeDAOIF) edge.getMdClass();
        if (HierarchicalRelationshipType.isEdgeAHierarchyType(mdEdge)) {
            final VertexObject parentVertex = edge.getParent();
            MdVertexDAOIF mdVertex = (MdVertexDAOIF) parentVertex.getMdClass();
            ServerHierarchyType ht = ServerHierarchyType.get(mdEdge);
            ServerGeoObjectType parentType = ServerGeoObjectType.get(mdVertex);
            VertexServerGeoObject parent = new VertexServerGeoObject(parentType, parentVertex, date);
            ServerParentTreeNode tnParent;
            if (recursive) {
                tnParent = internalGetParentGeoObjects(parent, parentTypes, recursive, ht, date);
            } else {
                tnParent = new ServerParentTreeNode(parent, ht, date, null, edge.getOid());
            }
            tnRoot.addParent(tnParent);
        }
    }
    return tnRoot;
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) MdEdgeDAOIF(com.runwaysdk.dataaccess.MdEdgeDAOIF) ServerParentTreeNode(net.geoprism.registry.model.ServerParentTreeNode) VertexObject(com.runwaysdk.business.graph.VertexObject) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) EdgeObject(com.runwaysdk.business.graph.EdgeObject) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) LineString(com.vividsolutions.jts.geom.LineString) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) Point(com.vividsolutions.jts.geom.Point) 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) HashedMap(org.apache.commons.collections4.map.HashedMap) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Example 27 with EdgeObject

use of com.runwaysdk.business.graph.EdgeObject in project geoprism-registry by terraframe.

the class VertexServerGeoObject method addParent.

@Override
public ServerParentTreeNode addParent(ServerGeoObjectIF parent, ServerHierarchyType hierarchyType, Date startDate, Date endDate) {
    if (!hierarchyType.getUniversalType().equals(AllowedIn.CLASS)) {
        hierarchyType.validateUniversalRelationship(this.getType(), parent.getType());
    }
    ValueOverTimeCollection votc = this.getParentCollection(hierarchyType);
    votc.add(new ValueOverTime(startDate, endDate, parent));
    SortedSet<EdgeObject> newEdges = this.setParentCollection(hierarchyType, votc);
    ServerParentTreeNode node = new ServerParentTreeNode(this, hierarchyType, startDate, null, null);
    node.addParent(new ServerParentTreeNode(parent, hierarchyType, startDate, null, newEdges.first().getOid()));
    return node;
}
Also used : ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) ServerParentTreeNode(net.geoprism.registry.model.ServerParentTreeNode) EdgeObject(com.runwaysdk.business.graph.EdgeObject) ValueOverTimeCollection(com.runwaysdk.dataaccess.graph.attributes.ValueOverTimeCollection)

Example 28 with EdgeObject

use of com.runwaysdk.business.graph.EdgeObject in project geoprism-registry by terraframe.

the class VertexServerGeoObject method setParentCollection.

public SortedSet<EdgeObject> setParentCollection(ServerHierarchyType hierarchyType, ValueOverTimeCollection votc) {
    SortedSet<EdgeObject> newEdges = new TreeSet<EdgeObject>(new EdgeComparator());
    SortedSet<EdgeObject> edges = this.getEdges(hierarchyType);
    for (EdgeObject edge : edges) {
        final Date startDate = edge.getObjectValue(GeoVertex.START_DATE);
        final Date endDate = edge.getObjectValue(GeoVertex.END_DATE);
        VertexObject parentVertex = edge.getParent();
        MdVertexDAOIF mdVertex = (MdVertexDAOIF) parentVertex.getMdClass();
        ServerGeoObjectType parentType = ServerGeoObjectType.get(mdVertex);
        final VertexServerGeoObject edgeGo = new VertexServerGeoObject(parentType, parentVertex, startDate);
        ValueOverTime inVot = null;
        for (ValueOverTime vot : votc) {
            if (vot.getOid() == edge.getOid()) {
                inVot = vot;
                break;
            }
        }
        if (inVot == null) {
            edge.delete();
        } else {
            VertexServerGeoObject inGo = (VertexServerGeoObject) inVot.getValue();
            boolean hasValueChange = false;
            if ((inGo == null && edgeGo != null) || (inGo != null && edgeGo == null)) {
                hasValueChange = true;
            } else if ((inGo != null && edgeGo != null) && !inGo.equals(edgeGo)) {
                hasValueChange = true;
            }
            if (hasValueChange) {
                edge.delete();
                EdgeObject newEdge = this.getVertex().addParent(inGo.getVertex(), hierarchyType.getMdEdge());
                newEdge.setValue(GeoVertex.START_DATE, startDate);
                newEdge.setValue(GeoVertex.END_DATE, endDate);
                newEdge.apply();
                newEdges.add(newEdge);
            } else {
                boolean hasChanges = false;
                if (startDate != inVot.getStartDate()) {
                    hasChanges = true;
                    edge.setValue(GeoVertex.START_DATE, startDate);
                }
                if (endDate != inVot.getEndDate()) {
                    hasChanges = true;
                    edge.setValue(GeoVertex.END_DATE, endDate);
                }
                if (hasChanges) {
                    edge.apply();
                }
            }
        }
    }
    for (ValueOverTime vot : votc) {
        boolean isNew = true;
        for (EdgeObject edge : edges) {
            if (vot.getOid() == edge.getOid()) {
                isNew = false;
            }
        }
        if (isNew) {
            EdgeObject newEdge = this.getVertex().addParent(((VertexServerGeoObject) vot.getValue()).getVertex(), hierarchyType.getMdEdge());
            newEdge.setValue(GeoVertex.START_DATE, vot.getStartDate());
            newEdge.setValue(GeoVertex.END_DATE, vot.getEndDate());
            newEdge.apply();
            newEdges.add(newEdge);
        }
    }
    return newEdges;
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) VertexObject(com.runwaysdk.business.graph.VertexObject) EdgeObject(com.runwaysdk.business.graph.EdgeObject) TreeSet(java.util.TreeSet) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) Date(java.util.Date) LocalDate(java.time.LocalDate)

Example 29 with EdgeObject

use of com.runwaysdk.business.graph.EdgeObject in project geoprism-registry by terraframe.

the class UpdateParentValueOverTimeView method getEdgeByDate.

protected EdgeObject getEdgeByDate(SortedSet<EdgeObject> looseVotc, Date startDate, Date endDate) {
    for (EdgeObject edge : looseVotc) {
        Date edgeStartDate = edge.getObjectValue(GeoVertex.START_DATE);
        Date edgeEndDate = edge.getObjectValue(GeoVertex.END_DATE);
        if (edgeStartDate.equals(startDate) && edgeEndDate.equals(endDate)) {
            return edge;
        }
    }
    return null;
}
Also used : EdgeObject(com.runwaysdk.business.graph.EdgeObject) Date(java.util.Date)

Example 30 with EdgeObject

use of com.runwaysdk.business.graph.EdgeObject in project geoprism-registry by terraframe.

the class UpdateParentView method execute.

@Override
public void execute(VertexServerGeoObject go) {
    final ServerHierarchyType hierarchyType = ServerHierarchyType.get(this.getHierarchyCode());
    SortedSet<EdgeObject> looseVotc = go.getEdges(hierarchyType);
    for (UpdateValueOverTimeView vot : this.valuesOverTime) {
        ((UpdateParentValueOverTimeView) vot).executeParent(this, go, looseVotc);
    }
    // The edge work has already been applied at this point. We just need to validate what's in the DB
    this.validateValuesOverTime(looseVotc);
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) EdgeObject(com.runwaysdk.business.graph.EdgeObject)

Aggregations

EdgeObject (com.runwaysdk.business.graph.EdgeObject)31 VertexObject (com.runwaysdk.business.graph.VertexObject)15 MdVertexDAOIF (com.runwaysdk.dataaccess.MdVertexDAOIF)15 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)15 GraphQuery (com.runwaysdk.business.graph.GraphQuery)11 Date (java.util.Date)10 ValueOverTime (com.runwaysdk.dataaccess.graph.attributes.ValueOverTime)9 LineString (com.vividsolutions.jts.geom.LineString)7 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)7 TreeSet (java.util.TreeSet)7 HashedMap (org.apache.commons.collections4.map.HashedMap)7 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)6 MdEdgeDAOIF (com.runwaysdk.dataaccess.MdEdgeDAOIF)5 ServerParentGraphNode (net.geoprism.registry.model.ServerParentGraphNode)5 ServerParentTreeNode (net.geoprism.registry.model.ServerParentTreeNode)5 GraphObject (com.runwaysdk.business.graph.GraphObject)3 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)3 Point (com.vividsolutions.jts.geom.Point)3 LocalDate (java.time.LocalDate)3 AbstractServerGeoObject (net.geoprism.registry.model.AbstractServerGeoObject)3