Search in sources :

Example 16 with GraphQuery

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

the class VertexServerGeoObject method getEdge.

public EdgeObject getEdge(ServerGeoObjectIF parent, ServerHierarchyType hierarchyType, Date startDate, Date endDate) {
    String statement = "SELECT FROM " + hierarchyType.getMdEdge().getDBClassName();
    statement += " WHERE out = :parent";
    statement += " AND in = :child";
    if (startDate != null) {
        statement += " AND startDate = :startDate";
    }
    if (endDate != null) {
        statement += " AND endDate = :endDate";
    }
    GraphQuery<EdgeObject> query = new GraphQuery<EdgeObject>(statement);
    query.setParameter("parent", ((VertexComponent) parent).getVertex().getRID());
    query.setParameter("child", this.getVertex().getRID());
    if (startDate != null) {
        query.setParameter("startDate", startDate);
    }
    if (endDate != null) {
        query.setParameter("endDate", endDate);
    }
    return query.getSingleResult();
}
Also used : EdgeObject(com.runwaysdk.business.graph.EdgeObject) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) LineString(com.vividsolutions.jts.geom.LineString) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Example 17 with GraphQuery

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

the class VertexServerGeoObject method getVertex.

public static VertexObject getVertex(ServerGeoObjectType type, String uuid) {
    String statement = "SELECT FROM " + type.getMdVertex().getDBClassName();
    statement += " WHERE uuid = :uuid";
    GraphQuery<GeoVertex> query = new GraphQuery<GeoVertex>(statement);
    query.setParameter("uuid", uuid);
    return query.getSingleResult();
}
Also used : MultiLineString(com.vividsolutions.jts.geom.MultiLineString) LineString(com.vividsolutions.jts.geom.LineString) GraphQuery(com.runwaysdk.business.graph.GraphQuery) GeoVertex(net.geoprism.registry.graph.GeoVertex)

Example 18 with GraphQuery

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

the class VertexServerGeoObject method getExternalIdEdge.

private EdgeObject getExternalIdEdge(ExternalSystem system) {
    MdEdgeDAOIF mdEdge = MdEdgeDAO.getMdEdgeDAO(GeoVertex.EXTERNAL_ID);
    String statement = "SELECT expand(inE('" + mdEdge.getDBClassName() + "')[out = :parent])";
    statement += " FROM :child";
    GraphQuery<EdgeObject> query = new GraphQuery<EdgeObject>(statement);
    query.setParameter("parent", system.getRID());
    query.setParameter("child", this.getVertex().getRID());
    return query.getSingleResult();
}
Also used : MdEdgeDAOIF(com.runwaysdk.dataaccess.MdEdgeDAOIF) EdgeObject(com.runwaysdk.business.graph.EdgeObject) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) LineString(com.vividsolutions.jts.geom.LineString) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Example 19 with GraphQuery

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

the class VertexServerGeoObject method internalGetParentOverTime.

protected static ServerParentTreeNodeOverTime internalGetParentOverTime(VertexServerGeoObject child, String[] parentTypes, boolean recursive) {
    final ServerGeoObjectType cType = child.getType();
    final List<ServerHierarchyType> hierarchies = cType.getHierarchies();
    ServerParentTreeNodeOverTime response = new ServerParentTreeNodeOverTime(cType);
    for (ServerHierarchyType ht : hierarchies) {
        response.add(ht);
    }
    Map<String, Object> parameters = new HashedMap<String, Object>();
    parameters.put("rid", child.getVertex().getRID());
    StringBuilder statement = new StringBuilder();
    statement.append("SELECT EXPAND(inE()");
    if (parentTypes != null && parentTypes.length > 0) {
        statement.append("[");
        for (int i = 0; i < parentTypes.length; i++) {
            ServerGeoObjectType type = ServerGeoObjectType.get(parentTypes[i]);
            if (i > 0) {
                statement.append(" OR ");
            }
            statement.append("out.@class = :a" + i);
            parameters.put("a" + Integer.toString(i), type.getMdVertex().getDBClassName());
        }
        statement.append("]");
    }
    statement.append(") FROM :rid");
    statement.append(" ORDER BY startDate ASC");
    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)) {
            ServerHierarchyType ht = ServerHierarchyType.get(mdEdge);
            VertexObject parentVertex = edge.getParent();
            MdVertexDAOIF mdVertex = (MdVertexDAOIF) parentVertex.getMdClass();
            ServerGeoObjectType parentType = ServerGeoObjectType.get(mdVertex);
            Date date = edge.getObjectValue(GeoVertex.START_DATE);
            Date endDate = edge.getObjectValue(GeoVertex.END_DATE);
            String oid = edge.getObjectValue(GeoVertex.OID);
            ServerParentTreeNode tnRoot = new ServerParentTreeNode(child, null, date, null, oid);
            tnRoot.setEndDate(endDate);
            tnRoot.setOid(oid);
            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, oid);
            }
            tnRoot.addParent(tnParent);
            response.add(ht, tnRoot);
        }
    }
    return response;
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) MdEdgeDAOIF(com.runwaysdk.dataaccess.MdEdgeDAOIF) VertexObject(com.runwaysdk.business.graph.VertexObject) ServerParentTreeNode(net.geoprism.registry.model.ServerParentTreeNode) 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) Date(java.util.Date) LocalDate(java.time.LocalDate) 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) ServerParentTreeNodeOverTime(net.geoprism.registry.view.ServerParentTreeNodeOverTime) HashedMap(org.apache.commons.collections4.map.HashedMap) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Example 20 with GraphQuery

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

the class VertexServerGeoObject method buildAncestorQuery.

// @Override
// public Map<String, LocationInfo> getAncestorMap(ServerHierarchyType
// hierarchy, boolean includeInheritedTypes)
// {
// TreeMap<String, LocationInfo> map = new TreeMap<String, LocationInfo>();
// 
// GraphQuery<VertexObject> query = buildAncestorQuery(hierarchy);
// 
// List<VertexObject> results = query.getResults();
// results.forEach(result -> {
// MdVertexDAOIF mdClass = (MdVertexDAOIF) result.getMdClass();
// ServerGeoObjectType vType = ServerGeoObjectType.get(mdClass);
// VertexServerGeoObject object = new VertexServerGeoObject(type, result,
// this.date);
// 
// map.put(vType.getUniversal().getKey(), object);
// 
// if (includeInheritedTypes && vType.isRoot(hierarchy))
// {
// ServerHierarchyType inheritedHierarchy =
// vType.getInheritedHierarchy(hierarchy);
// 
// if (inheritedHierarchy != null)
// {
// map.putAll(object.getAncestorMap(inheritedHierarchy, true));
// }
// }
// });
// 
// return map;
// }
private GraphQuery<VertexObject> buildAncestorQuery(ServerHierarchyType hierarchy) {
    String dbClassName = this.getMdClass().getDBClassName();
    if (this.date == null) {
        StringBuilder statement = new StringBuilder();
        statement.append("MATCH ");
        statement.append("{class:" + dbClassName + ", where: (@rid=:rid)}");
        statement.append(".in('" + hierarchy.getMdEdge().getDBClassName() + "')");
        statement.append("{as: ancestor, where: (exists=true AND invalid=false), while: (true)}");
        statement.append("RETURN $elements");
        GraphQuery<VertexObject> query = new GraphQuery<VertexObject>(statement.toString());
        query.setParameter("rid", this.vertex.getRID());
        return query;
    } else {
        StringBuilder statement = new StringBuilder();
        statement.append("MATCH ");
        statement.append("{class:" + dbClassName + ", where: (@rid=:rid)}");
        statement.append(".(inE('" + hierarchy.getMdEdge().getDBClassName() + "'){where: (:date BETWEEN startDate AND endDate)}.outV())");
        statement.append("{as: ancestor, where: (invalid=false AND exists_cot CONTAINS (value=true AND :date BETWEEN startDate AND endDate )), while: (true)}");
        statement.append("RETURN $elements");
        GraphQuery<VertexObject> query = new GraphQuery<VertexObject>(statement.toString());
        query.setParameter("rid", this.vertex.getRID());
        query.setParameter("date", this.date);
        return query;
    }
}
Also used : VertexObject(com.runwaysdk.business.graph.VertexObject) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) LineString(com.vividsolutions.jts.geom.LineString) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Aggregations

GraphQuery (com.runwaysdk.business.graph.GraphQuery)55 MdVertexDAOIF (com.runwaysdk.dataaccess.MdVertexDAOIF)34 VertexObject (com.runwaysdk.business.graph.VertexObject)29 MdAttributeDAOIF (com.runwaysdk.dataaccess.MdAttributeDAOIF)23 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)17 EdgeObject (com.runwaysdk.business.graph.EdgeObject)16 LineString (com.vividsolutions.jts.geom.LineString)11 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)11 LinkedList (java.util.LinkedList)11 JsonObject (com.google.gson.JsonObject)10 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)9 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)9 HashedMap (org.apache.commons.collections4.map.HashedMap)8 JsonArray (com.google.gson.JsonArray)7 MdEdgeDAOIF (com.runwaysdk.dataaccess.MdEdgeDAOIF)7 List (java.util.List)7 Page (net.geoprism.registry.view.Page)7 AbstractClassification (com.runwaysdk.system.AbstractClassification)6 HashMap (java.util.HashMap)6 Collectors (java.util.stream.Collectors)6