Search in sources :

Example 41 with GraphQuery

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

the class BusinessObject method get.

public static BusinessObject get(BusinessType type, String attributeName, Object value) {
    MdVertexDAOIF mdVertex = type.getMdVertexDAO();
    MdAttributeDAOIF mdAttribute = mdVertex.definesAttribute(attributeName);
    StringBuilder statement = new StringBuilder();
    statement.append("SELECT FROM " + mdVertex.getDBClassName());
    statement.append(" WHERE " + mdAttribute.getColumnName() + " = :" + attributeName);
    GraphQuery<VertexObject> query = new GraphQuery<VertexObject>(statement.toString());
    query.setParameter(attributeName, value);
    VertexObject result = query.getSingleResult();
    if (result != null) {
        return new BusinessObject(result, type);
    }
    return null;
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) VertexObject(com.runwaysdk.business.graph.VertexObject) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Example 42 with GraphQuery

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

the class Classification method getChildren.

public Page<Classification> getChildren(Integer pageSize, Integer pageNumber) {
    StringBuilder cStatement = new StringBuilder();
    cStatement.append("SELECT out('" + this.type.getMdEdge().getDBClassName() + "').size()");
    cStatement.append(" FROM :rid");
    GraphQuery<Integer> cQuery = new GraphQuery<Integer>(cStatement.toString());
    cQuery.setParameter("rid", this.getVertex().getRID());
    Integer count = cQuery.getSingleResult();
    StringBuilder statement = new StringBuilder();
    statement.append("SELECT EXPAND(out('" + this.type.getMdEdge().getDBClassName() + "')");
    statement.append(") FROM :rid");
    statement.append(" ORDER BY code");
    if (pageSize != null && pageNumber != null) {
        int first = pageSize * (pageNumber - 1);
        int rows = pageSize;
        statement.append(" SKIP " + first + " LIMIT " + rows);
    }
    GraphQuery<VertexObject> query = new GraphQuery<VertexObject>(statement.toString());
    query.setParameter("rid", this.getVertex().getRID());
    List<Classification> results = query.getResults().stream().map(vertex -> {
        return new Classification(this.type, vertex);
    }).collect(Collectors.toList());
    return new Page<Classification>(count, pageNumber, pageSize, results);
}
Also used : JsonObject(com.google.gson.JsonObject) Term(org.commongeoregistry.adapter.Term) AbstractClassification(com.runwaysdk.system.AbstractClassification) GraphQuery(com.runwaysdk.business.graph.GraphQuery) Transaction(com.runwaysdk.dataaccess.transaction.Transaction) VertexObject(com.runwaysdk.business.graph.VertexObject) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) CannotDeleteClassificationWithChildrenException(net.geoprism.registry.CannotDeleteClassificationWithChildrenException) IOException(java.io.IOException) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) JsonParser(com.google.gson.JsonParser) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) VertexObjectDAO(com.runwaysdk.dataaccess.graph.VertexObjectDAO) ApplicationResource(com.runwaysdk.resource.ApplicationResource) AbstractVertexRestriction(net.geoprism.registry.query.graph.AbstractVertexRestriction) Page(net.geoprism.registry.view.Page) JsonElement(com.google.gson.JsonElement) List(java.util.List) JsonArray(com.google.gson.JsonArray) LocalizedValueConverter(net.geoprism.registry.conversion.LocalizedValueConverter) JsonSerializable(net.geoprism.registry.view.JsonSerializable) EdgeObject(com.runwaysdk.business.graph.EdgeObject) InputStream(java.io.InputStream) VertexObject(com.runwaysdk.business.graph.VertexObject) AbstractClassification(com.runwaysdk.system.AbstractClassification) Page(net.geoprism.registry.view.Page) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Example 43 with GraphQuery

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

the class Classification method getByOid.

public static Classification getByOid(ClassificationType type, String oid) {
    StringBuilder builder = new StringBuilder();
    builder.append("SELECT FROM " + type.getMdVertex().getDBClassName());
    builder.append(" WHERE oid = :oid");
    GraphQuery<VertexObject> query = new GraphQuery<VertexObject>(builder.toString());
    query.setParameter("oid", oid);
    VertexObject result = query.getSingleResult();
    if (result != null) {
        return new Classification(type, result);
    }
    return null;
}
Also used : VertexObject(com.runwaysdk.business.graph.VertexObject) AbstractClassification(com.runwaysdk.system.AbstractClassification) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Example 44 with GraphQuery

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

the class Classification method getAncestors.

public List<Classification> getAncestors(String rootCode) {
    GraphQuery<VertexObject> query = null;
    if (rootCode != null && rootCode.length() > 0) {
        StringBuilder statement = new StringBuilder();
        statement.append("SELECT expand($res)");
        statement.append(" LET $a = (TRAVERSE in(\"" + this.type.getMdEdge().getDBClassName() + "\") FROM :rid WHILE (code != :code))");
        statement.append(", $b = (SELECT FROM " + this.type.getMdVertex().getDBClassName() + " WHERE code = :code)");
        statement.append(", $res = (UNIONALL($a,$b))");
        query = new GraphQuery<VertexObject>(statement.toString());
        query.setParameter("rid", this.vertex.getRID());
        query.setParameter("code", rootCode);
    } else {
        StringBuilder statement = new StringBuilder();
        statement.append("TRAVERSE in(\"" + this.type.getMdEdge().getDBClassName() + "\") FROM :rid");
        query = new GraphQuery<VertexObject>(statement.toString());
        query.setParameter("rid", this.vertex.getRID());
    }
    List<Classification> results = query.getResults().stream().map(vertex -> {
        return new Classification(this.type, vertex);
    }).collect(Collectors.toList());
    return results;
}
Also used : JsonObject(com.google.gson.JsonObject) Term(org.commongeoregistry.adapter.Term) AbstractClassification(com.runwaysdk.system.AbstractClassification) GraphQuery(com.runwaysdk.business.graph.GraphQuery) Transaction(com.runwaysdk.dataaccess.transaction.Transaction) VertexObject(com.runwaysdk.business.graph.VertexObject) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) CannotDeleteClassificationWithChildrenException(net.geoprism.registry.CannotDeleteClassificationWithChildrenException) IOException(java.io.IOException) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) JsonParser(com.google.gson.JsonParser) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) VertexObjectDAO(com.runwaysdk.dataaccess.graph.VertexObjectDAO) ApplicationResource(com.runwaysdk.resource.ApplicationResource) AbstractVertexRestriction(net.geoprism.registry.query.graph.AbstractVertexRestriction) Page(net.geoprism.registry.view.Page) JsonElement(com.google.gson.JsonElement) List(java.util.List) JsonArray(com.google.gson.JsonArray) LocalizedValueConverter(net.geoprism.registry.conversion.LocalizedValueConverter) JsonSerializable(net.geoprism.registry.view.JsonSerializable) EdgeObject(com.runwaysdk.business.graph.EdgeObject) InputStream(java.io.InputStream) VertexObject(com.runwaysdk.business.graph.VertexObject) AbstractClassification(com.runwaysdk.system.AbstractClassification)

Example 45 with GraphQuery

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

the class Classification method get.

public static Classification get(ClassificationType type, String code) {
    StringBuilder builder = new StringBuilder();
    builder.append("SELECT FROM " + type.getMdVertex().getDBClassName());
    builder.append(" WHERE code = :code");
    GraphQuery<VertexObject> query = new GraphQuery<VertexObject>(builder.toString());
    query.setParameter("code", code);
    VertexObject result = query.getSingleResult();
    if (result != null) {
        return new Classification(type, result);
    }
    return null;
}
Also used : VertexObject(com.runwaysdk.business.graph.VertexObject) AbstractClassification(com.runwaysdk.system.AbstractClassification) 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