Search in sources :

Example 21 with GraphQuery

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

the class VertexServerGeoObject method getVertexByCode.

public static VertexObject getVertexByCode(ServerGeoObjectType type, String code) {
    String statement = "SELECT FROM " + type.getMdVertex().getDBClassName();
    statement += " WHERE code = :code";
    GraphQuery<GeoVertex> query = new GraphQuery<GeoVertex>(statement);
    query.setParameter("code", code);
    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 22 with GraphQuery

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

the class AbstractGraphPageQuery method getCount.

public Long getCount() {
    final MdVertexDAOIF mdVertex = MdVertexDAO.getMdVertexDAO(this.type);
    StringBuilder statement = new StringBuilder();
    statement.append("SELECT COUNT(*) FROM " + mdVertex.getDBClassName() + "");
    Map<String, Object> parameters = new HashMap<String, Object>();
    if (criteria.has("filters")) {
        JsonObject filters = criteria.get("filters").getAsJsonObject();
        this.addCriteria(mdVertex, filters, statement, parameters);
    }
    final GraphQuery<Long> query = new GraphQuery<Long>(statement.toString(), parameters);
    return query.getSingleResult();
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) JsonObject(com.google.gson.JsonObject) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Example 23 with GraphQuery

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

the class AbstractGraphPageQuery method getPage.

public Page<T> getPage() {
    int pageSize = 10;
    int pageNumber = 1;
    Long count = this.getCount();
    final MdVertexDAOIF mdVertex = MdVertexDAO.getMdVertexDAO(this.type);
    StringBuilder statement = new StringBuilder();
    statement.append("SELECT ");
    this.addSelectAttributes(mdVertex, statement);
    statement.append(" FROM " + mdVertex.getDBClassName() + "");
    Map<String, Object> parameters = new HashMap<String, Object>();
    if (criteria.has("filters")) {
        JsonObject filters = criteria.get("filters").getAsJsonObject();
        this.addCriteria(mdVertex, filters, statement, parameters);
    }
    if (criteria.has("sortField") && criteria.has("sortOrder")) {
        String field = criteria.get("sortField").getAsString();
        SortOrder order = criteria.get("sortOrder").getAsInt() == 1 ? SortOrder.ASC : SortOrder.DESC;
        MdAttributeDAOIF mdAttribute = mdVertex.definesAttribute(field);
        statement.append(" ORDER BY " + this.getColumnName(mdAttribute) + " " + order.name());
    } else if (criteria.has("multiSortMeta")) {
        JsonArray sorts = criteria.get("multiSortMeta").getAsJsonArray();
        for (int i = 0; i < sorts.size(); i++) {
            JsonObject sort = sorts.get(i).getAsJsonObject();
            String field = sort.get("field").getAsString();
            SortOrder order = sort.get("order").getAsInt() == 1 ? SortOrder.ASC : SortOrder.DESC;
            MdAttributeDAOIF mdAttribute = mdVertex.definesAttribute(field);
            if (i == 0) {
                statement.append(" ORDER BY " + this.getColumnName(mdAttribute) + " " + order.name());
            } else {
                statement.append(", " + this.getColumnName(mdAttribute) + " " + order.name());
            }
        }
    }
    if (criteria.has("first") && criteria.has("rows")) {
        int first = criteria.get("first").getAsInt();
        int rows = criteria.get("rows").getAsInt();
        statement.append(" SKIP " + first + " LIMIT " + rows);
        pageNumber = (first / rows) + 1;
    }
    final GraphQuery<K> query = new GraphQuery<K>(statement.toString(), parameters);
    return new Page<T>(count, pageNumber, pageSize, this.getResults(query));
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) SortOrder(com.runwaysdk.query.OrderBy.SortOrder) Page(net.geoprism.registry.view.Page) JsonArray(com.google.gson.JsonArray) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) JsonObject(com.google.gson.JsonObject) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Example 24 with GraphQuery

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

the class LocationService method getGeoObjects.

// @Request(RequestType.SESSION)
// public LocationInformation getLocationInformation(String sessionId, String code, String typeCode, Date date, String childTypeCode, String hierarchyCode)
// {
// LocationInformation information = new LocationInformation();
// 
// ServerGeoObjectIF go = this.service.getGeoObjectByCode(code, typeCode);
// go.setDate(date);
// 
// ServerGeoObjectType type = go.getType();
// List<ServerHierarchyType> hierarchies = type.getHierarchies();
// 
// ServerHierarchyType hierarchy = null;
// 
// if (hierarchyCode == null || hierarchyCode.length() == 0)
// {
// hierarchy = hierarchies.get(0);
// }
// else
// {
// hierarchy = ServerHierarchyType.get(hierarchyCode);
// }
// 
// List<ServerGeoObjectType> childTypes = type.getChildren(hierarchy);
// ServerGeoObjectType childType = null;
// 
// if (childTypes.size() > 0)
// {
// /*
// * If a typeCode is given and it is an option based on the hierarchy than
// * use that type otherwise use the first type code
// */
// childType = childTypes.get(0);
// 
// if (childTypeCode != null && childTypeCode.length() > 0)
// {
// for (ServerGeoObjectType child : childTypes)
// {
// if (child.getCode().equals(childTypeCode))
// {
// childType = child;
// }
// }
// }
// }
// 
// if (childType != null)
// {
// information.setChildType(childType.getType());
// 
// List<VertexServerGeoObject> children = this.getGeoObjects(go.getCode(), childType.getCode(), hierarchy.getCode(), date);
// 
// for (VertexServerGeoObject child : children)
// {
// information.addChild(child.toGeoObject());
// }
// }
// 
// information.setChildTypes(childTypes);
// information.setHierarchies(hierarchies);
// information.setHierarchy(hierarchy.getCode());
// information.setEntity(go.toGeoObject());
// 
// return information;
// }
// @Request(RequestType.SESSION)
// public JsonObject getChildrenGeoJson(String sessionId, String typeCode,
// String parentId, String hierarchyCode)
// {
// List<VertexServerGeoObject> children = parentId != null ?
// this.getGeoObjects(typeCode, parentId, hierarchyCode) :
// this.getGeoObjects(typeCode);
// 
// return children;
// }
private List<VertexServerGeoObject> getGeoObjects(String typeCode, Date date) {
    ServerGeoObjectType type = ServerGeoObjectType.get(typeCode);
    MdVertexDAOIF mdVertex = type.getMdVertex();
    StringBuilder statement = new StringBuilder();
    statement.append("SELECT FROM " + mdVertex.getDBClassName());
    statement.append(" ORDER BY code");
    GraphQuery<VertexObject> query = new GraphQuery<VertexObject>(statement.toString());
    List<VertexObject> vObjects = query.getResults();
    List<VertexServerGeoObject> response = new LinkedList<VertexServerGeoObject>();
    for (VertexObject vObject : vObjects) {
        VertexServerGeoObject vSGO = new VertexServerGeoObject(type, vObject);
        vSGO.setDate(date);
        response.add(vSGO);
    }
    return response;
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) VertexObject(com.runwaysdk.business.graph.VertexObject) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) GraphQuery(com.runwaysdk.business.graph.GraphQuery) LinkedList(java.util.LinkedList)

Example 25 with GraphQuery

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

the class RegistryService method getGeoObjectSuggestions.

/*
   * 
   * select $filteredLabel,* from province0 let $dateLabel =
   * first(displayLabel_cot[(date('2020-05-01', 'yyyy-MM-dd') BETWEEN startDate
   * AND endDate) AND (date('2020-05-01', 'yyyy-MM-dd') BETWEEN startDate AND
   * endDate)]), $filteredLabel = COALESCE($dateLabel.value.defaultLocale) where
   * ( displayLabel_cot CONTAINS ( (date('2020-05-01', 'yyyy-MM-dd') BETWEEN
   * startDate AND endDate) AND (date('2020-05-01', 'yyyy-MM-dd') BETWEEN
   * startDate AND endDate) AND COALESCE(value.defaultLocale).toLowerCase() LIKE
   * '%' + 'a' + '%' ) OR code.toLowerCase() LIKE '%' + 'a' + '%' ) AND
   * invalid=false AND ( exists_cot CONTAINS ( (date('2020-05-01', 'yyyy-MM-dd')
   * BETWEEN startDate AND endDate) AND (date('2020-05-01', 'yyyy-MM-dd')
   * BETWEEN startDate AND endDate) AND value=true ) ) ORDER BY $filteredLabel
   * ASC LIMIT 10
   */
@Request(RequestType.SESSION)
public JsonArray getGeoObjectSuggestions(String sessionId, String text, String typeCode, String parentCode, String parentTypeCode, String hierarchyCode, Date startDate, Date endDate) {
    final ServerGeoObjectType type = ServerGeoObjectType.get(typeCode);
    ServerHierarchyType ht = hierarchyCode != null ? ServerHierarchyType.get(hierarchyCode) : null;
    final ServerGeoObjectType parentType = ServerGeoObjectType.get(parentTypeCode);
    List<String> conditions = new ArrayList<String>();
    StringBuilder statement = new StringBuilder();
    statement.append("select $filteredLabel,@class as clazz,* from " + type.getMdVertex().getDBClassName() + " ");
    statement.append("let $dateLabel = first(displayLabel_cot");
    if (startDate != null && endDate != null) {
        statement.append("[(:startDate BETWEEN startDate AND endDate) AND (:endDate BETWEEN startDate AND endDate)]");
    }
    statement.append("), ");
    statement.append("$filteredLabel = " + AbstractVertexRestriction.localize("$dateLabel.value") + " ");
    statement.append("where ");
    // Must be a child of parent type
    if (parentTypeCode != null && parentTypeCode.length() > 0) {
        StringBuilder parentCondition = new StringBuilder();
        parentCondition.append("(@rid in ( TRAVERSE outE('" + ht.getMdEdge().getDBClassName() + "')");
        if (startDate != null && endDate != null) {
            parentCondition.append("[(:startDate BETWEEN startDate AND endDate) AND (:endDate BETWEEN startDate AND endDate)]");
        }
        parentCondition.append(".inV() FROM (select from " + parentType.getMdVertex().getDBClassName() + " where code='" + parentCode + "') )) ");
        conditions.add(parentCondition.toString());
    }
    // Must have display label we expect
    if (text != null && text.length() > 0) {
        StringBuilder textCondition = new StringBuilder();
        textCondition.append("(displayLabel_cot CONTAINS (");
        if (startDate != null && endDate != null) {
            textCondition.append("  (:startDate BETWEEN startDate AND endDate) AND (:endDate BETWEEN startDate AND endDate) AND ");
        }
        textCondition.append(AbstractVertexRestriction.localize("value") + ".toLowerCase() LIKE '%' + :text + '%'");
        textCondition.append(")");
        textCondition.append(" OR code.toLowerCase() LIKE '%' + :text + '%')");
        conditions.add(textCondition.toString());
    }
    // Must not be invalid
    conditions.add("invalid=false");
    // Must exist at date
    {
        StringBuilder existCondition = new StringBuilder();
        existCondition.append("(exists_cot CONTAINS (");
        if (startDate != null && endDate != null) {
            existCondition.append("  (:startDate BETWEEN startDate AND endDate) AND (:endDate BETWEEN startDate AND endDate) AND ");
        }
        existCondition.append("value=true");
        existCondition.append("))");
        conditions.add(existCondition.toString());
    }
    statement.append(StringUtils.join(conditions, " AND "));
    statement.append(" ORDER BY $filteredLabel ASC LIMIT 10");
    GraphQuery<VertexObject> query = new GraphQuery<VertexObject>(statement.toString());
    if (startDate != null && endDate != null) {
        query.setParameter("startDate", startDate);
        query.setParameter("endDate", endDate);
    }
    if (text != null) {
        query.setParameter("text", text.toLowerCase().trim());
    } else {
        query.setParameter("text", text);
    }
    @SuppressWarnings("unchecked") List<HashMap<String, Object>> results = (List<HashMap<String, Object>>) ((Object) query.getResults());
    JsonArray array = new JsonArray();
    for (HashMap<String, Object> row : results) {
        ServerGeoObjectType rowType = ServerGeoObjectType.get((MdVertexDAOIF) MdGraphClassDAO.getMdGraphClassByTableName((String) row.get("clazz")));
        if (ServiceFactory.getGeoObjectPermissionService().canRead(rowType.getOrganization().getCode(), rowType)) {
            JsonObject result = new JsonObject();
            result.addProperty("id", (String) row.get("oid"));
            result.addProperty("name", (String) row.get("$filteredLabel"));
            result.addProperty(GeoObject.CODE, (String) row.get("code"));
            result.addProperty(GeoObject.UID, (String) row.get("uuid"));
            result.addProperty("typeCode", rowType.getCode());
            array.add(result);
        }
    }
    return array;
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) VertexObject(com.runwaysdk.business.graph.VertexObject) HashMap(java.util.HashMap) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) JsonArray(com.google.gson.JsonArray) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) JsonObject(com.google.gson.JsonObject) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) JSONObject(org.json.JSONObject) VertexObject(com.runwaysdk.business.graph.VertexObject) GraphQuery(com.runwaysdk.business.graph.GraphQuery) Request(com.runwaysdk.session.Request) OAuthClientRequest(org.apache.oltu.oauth2.client.request.OAuthClientRequest)

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