Search in sources :

Example 1 with EdgeObject

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

the class DirectedAcyclicGraphStrategy method getChildren.

@SuppressWarnings("unchecked")
@Override
public ServerChildGraphNode getChildren(VertexServerGeoObject parent, Boolean recursive, Date date) {
    ServerChildGraphNode tnRoot = new ServerChildGraphNode(parent, this.type, date, null, null);
    Map<String, Object> parameters = new HashedMap<String, Object>();
    parameters.put("rid", parent.getVertex().getRID());
    StringBuilder statement = new StringBuilder();
    statement.append("SELECT EXPAND( outE(");
    statement.append("'" + this.type.getMdEdgeDAO().getDBClassName() + "'");
    statement.append(")");
    if (date != null) {
        statement.append("[:date BETWEEN startDate AND endDate]");
        parameters.put("date", date);
    }
    statement.append(") FROM :rid");
    GraphQuery<EdgeObject> query = new GraphQuery<EdgeObject>(statement.toString(), parameters);
    List<EdgeObject> edges = query.getResults();
    for (EdgeObject edge : edges) {
        final VertexObject childVertex = edge.getChild();
        MdVertexDAOIF mdVertex = (MdVertexDAOIF) childVertex.getMdClass();
        ServerGeoObjectType childType = ServerGeoObjectType.get(mdVertex);
        VertexServerGeoObject child = new VertexServerGeoObject(childType, childVertex, date);
        ServerChildGraphNode tnParent;
        if (recursive) {
            tnParent = this.getChildren(child, recursive, date);
            tnParent.setOid(edge.getOid());
        } else {
            tnParent = new ServerChildGraphNode(child, this.type, date, null, edge.getOid());
        }
        tnRoot.addChild(tnParent);
    }
    return tnRoot;
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) VertexObject(com.runwaysdk.business.graph.VertexObject) EdgeObject(com.runwaysdk.business.graph.EdgeObject) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) ServerChildGraphNode(net.geoprism.registry.model.ServerChildGraphNode) VertexObject(com.runwaysdk.business.graph.VertexObject) EdgeObject(com.runwaysdk.business.graph.EdgeObject) HashedMap(org.apache.commons.collections4.map.HashedMap) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Example 2 with EdgeObject

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

the class DirectedAcyclicGraphStrategy method getParentCollection.

private Set<ValueOverTime> getParentCollection(VertexServerGeoObject geoObject) {
    Set<ValueOverTime> set = new TreeSet<ValueOverTime>(new Comparator<ValueOverTime>() {

        @Override
        public int compare(ValueOverTime o1, ValueOverTime o2) {
            return o1.getOid().compareTo(o2.getOid());
        }
    });
    SortedSet<EdgeObject> edges = this.getParentEdges(geoObject);
    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);
        VertexServerGeoObject parent = new VertexServerGeoObject(parentType, parentVertex, startDate);
        set.add(new ValueOverTime(edge.getOid(), startDate, endDate, parent));
    }
    return set;
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) VertexObject(com.runwaysdk.business.graph.VertexObject) TreeSet(java.util.TreeSet) EdgeObject(com.runwaysdk.business.graph.EdgeObject) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) Date(java.util.Date)

Example 3 with EdgeObject

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

the class DirectedAcyclicGraphStrategy method getParents.

@SuppressWarnings("unchecked")
@Override
public ServerParentGraphNode getParents(VertexServerGeoObject child, Boolean recursive, Date date) {
    ServerParentGraphNode tnRoot = new ServerParentGraphNode(child, this.type, 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(");
    statement.append("'" + this.type.getMdEdgeDAO().getDBClassName() + "'");
    statement.append(")");
    if (date != null) {
        statement.append("[:date BETWEEN startDate AND endDate]");
        parameters.put("date", date);
    }
    statement.append(") FROM :rid");
    GraphQuery<EdgeObject> query = new GraphQuery<EdgeObject>(statement.toString(), parameters);
    List<EdgeObject> edges = query.getResults();
    for (EdgeObject edge : edges) {
        final VertexObject parentVertex = edge.getParent();
        MdVertexDAOIF mdVertex = (MdVertexDAOIF) parentVertex.getMdClass();
        ServerGeoObjectType parentType = ServerGeoObjectType.get(mdVertex);
        VertexServerGeoObject parent = new VertexServerGeoObject(parentType, parentVertex, date);
        ServerParentGraphNode tnParent;
        if (recursive) {
            tnParent = this.getParents(parent, recursive, date);
            tnParent.setOid(edge.getOid());
        } else {
            tnParent = new ServerParentGraphNode(parent, this.type, date, null, edge.getOid());
        }
        tnRoot.addParent(tnParent);
    }
    return tnRoot;
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) VertexObject(com.runwaysdk.business.graph.VertexObject) EdgeObject(com.runwaysdk.business.graph.EdgeObject) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) VertexObject(com.runwaysdk.business.graph.VertexObject) EdgeObject(com.runwaysdk.business.graph.EdgeObject) ServerParentGraphNode(net.geoprism.registry.model.ServerParentGraphNode) HashedMap(org.apache.commons.collections4.map.HashedMap) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Example 4 with EdgeObject

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

the class ServerHierarchyStrategy method getParents.

@SuppressWarnings("unchecked")
@Override
public ServerParentGraphNode getParents(VertexServerGeoObject child, Boolean recursive, Date date) {
    ServerParentGraphNode tnRoot = new ServerParentGraphNode(child, this.hierarchy, 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(");
    statement.append("'" + this.hierarchy.getMdEdge().getDBClassName() + "'");
    statement.append(")");
    if (date != null) {
        statement.append("[:date BETWEEN startDate AND endDate]");
        parameters.put("date", date);
    }
    statement.append(") FROM :rid");
    GraphQuery<EdgeObject> query = new GraphQuery<EdgeObject>(statement.toString(), parameters);
    List<EdgeObject> edges = query.getResults();
    for (EdgeObject edge : edges) {
        final VertexObject parentVertex = edge.getParent();
        MdVertexDAOIF mdVertex = (MdVertexDAOIF) parentVertex.getMdClass();
        ServerGeoObjectType parentType = ServerGeoObjectType.get(mdVertex);
        VertexServerGeoObject parent = new VertexServerGeoObject(parentType, parentVertex, date);
        ServerParentGraphNode tnParent;
        if (recursive) {
            tnParent = this.getParents(parent, recursive, date);
            tnParent.setOid(edge.getOid());
        } else {
            tnParent = new ServerParentGraphNode(parent, this.hierarchy, date, null, edge.getOid());
        }
        tnRoot.addParent(tnParent);
    }
    return tnRoot;
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) VertexObject(com.runwaysdk.business.graph.VertexObject) EdgeObject(com.runwaysdk.business.graph.EdgeObject) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) VertexObject(com.runwaysdk.business.graph.VertexObject) EdgeObject(com.runwaysdk.business.graph.EdgeObject) ServerParentGraphNode(net.geoprism.registry.model.ServerParentGraphNode) HashedMap(org.apache.commons.collections4.map.HashedMap) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Example 5 with EdgeObject

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

the class UndirectedGraphStrategy method setParentCollection.

private SortedSet<EdgeObject> setParentCollection(VertexServerGeoObject geoObject, Set<ValueOverTime> votc) {
    SortedSet<EdgeObject> newEdges = new TreeSet<EdgeObject>(new EdgeComparator());
    SortedSet<EdgeObject> edges = this.getParentEdges(geoObject);
    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 = geoObject.getVertex().addParent(inGo.getVertex(), this.type.getMdEdgeDAO());
                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 = geoObject.getVertex().addParent(((VertexServerGeoObject) vot.getValue()).getVertex(), this.type.getMdEdgeDAO());
            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)

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