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();
}
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();
}
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();
}
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;
}
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;
}
}
Aggregations