Search in sources :

Example 51 with GraphQuery

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

the class VertexServerGeoObject method buildAncestorQueryFast.

/**
 * @param hierarchy
 * @param parents
 *          The parent types, sorted from the top to the bottom
 * @return
 */
private GraphQuery<Map<String, Object>> buildAncestorQueryFast(ServerHierarchyType hierarchy, List<ServerGeoObjectType> parents) {
    LinkedList<ServerHierarchyType> inheritancePath = new LinkedList<ServerHierarchyType>();
    inheritancePath.add(hierarchy);
    for (int i = parents.size() - 1; i >= 0; --i) {
        ServerGeoObjectType parent = parents.get(i);
        if (parent.isRoot(hierarchy)) {
            ServerHierarchyType inheritedHierarchy = parent.getInheritedHierarchy(hierarchy);
            if (inheritedHierarchy != null) {
                inheritancePath.addFirst(inheritedHierarchy);
            }
        }
    }
    String dbClassName = this.getMdClass().getDBClassName();
    // select code, displayLabel_cot from (
    // TRAVERSE inE('adh0')[DATE('2021-06-10','yyyy-MM-dd') between startDate
    // AND endDate].outV() FROM (
    // TRAVERSE inE('hfgh0')[DATE('2021-06-10','yyyy-MM-dd') between startDate
    // AND endDate].outV() FROM (
    // SELECT FROM ch0 WHERE @rid=#65:0
    // )
    // )
    // )
    // WHERE
    // exists_cot CONTAINS (value CONTAINS
    // 'ea48a4be-aa38-4b92-9d5b-dfd10e0005ba' AND
    // DATE('2021-06-10','yyyy-MM-dd') BETWEEN startDate AND endDate)
    StringBuilder statement = new StringBuilder();
    statement.append("SELECT @class AS cl, " + DefaultAttribute.CODE.getName() + " AS code, " + DefaultAttribute.DISPLAY_LABEL.getName() + "_cot AS label FROM (");
    for (ServerHierarchyType hier : inheritancePath) {
        if (this.date != null) {
            statement.append("TRAVERSE inE('" + hier.getMdEdge().getDBClassName() + "')[:date between startDate AND endDate].outV() FROM (");
        } else {
            statement.append("TRAVERSE inE('" + hier.getMdEdge().getDBClassName() + "').outV() FROM (");
        }
    }
    statement.append("SELECT FROM " + dbClassName + " WHERE @rid=:rid");
    for (ServerHierarchyType hier : inheritancePath) {
        statement.append(")");
    }
    if (this.date != null) {
        statement.append(") WHERE exists_cot CONTAINS (value=true AND :date BETWEEN startDate AND endDate)");
    } else {
        statement.append(") WHERE exists_cot CONTAINS (value=true)");
    }
    GraphQuery<Map<String, Object>> query = new GraphQuery<Map<String, Object>>(statement.toString());
    query.setParameter("rid", this.vertex.getRID());
    if (this.date != null) {
        query.setParameter("date", this.date);
    }
    return query;
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) 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) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) LineString(com.vividsolutions.jts.geom.LineString) Map(java.util.Map) HashedMap(org.apache.commons.collections4.map.HashedMap) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) GraphQuery(com.runwaysdk.business.graph.GraphQuery) LinkedList(java.util.LinkedList) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) Point(com.vividsolutions.jts.geom.Point)

Example 52 with GraphQuery

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

the class SearchService method search.

public List<ServerGeoObjectIF> search(String text, Date date, Long limit) {
    String suffix = this.getSuffix();
    RolePermissionService service = new RolePermissionService();
    MdVertexDAOIF mdVertex = MdVertexDAO.getMdVertexDAO(PACKAGE + "." + VERTEX_PREFIX + suffix);
    MdAttributeDAOIF code = mdVertex.definesAttribute(CODE);
    MdAttributeDAOIF startDate = mdVertex.definesAttribute(START_DATE);
    MdAttributeDAOIF endDate = mdVertex.definesAttribute(END_DATE);
    MdAttributeDAOIF label = mdVertex.definesAttribute(LABEL);
    MdAttributeDAOIF vertexType = mdVertex.definesAttribute(VERTEX_TYPE);
    MdEdgeDAOIF mdEdge = MdEdgeDAO.getMdEdgeDAO(PACKAGE + "." + EDGE_PREFIX + suffix);
    String attributeName = label.getValue(MdAttributeTextInfo.NAME);
    String className = mdVertex.getDBClassName();
    String indexName = className + "." + attributeName;
    StringBuilder statement = new StringBuilder();
    statement.append("SELECT EXPAND(out('" + mdEdge.getDBClassName() + "'))");
    statement.append(" FROM " + mdVertex.getDBClassName());
    if (text != null) {
        String regex = "([+\\-!\\(\\){}\\[\\]^\"~*?:\\\\]|[&\\|]{2})";
        String escapedText = text.replaceAll(regex, "\\\\\\\\$1").trim();
        statement.append(" WHERE (SEARCH_INDEX(\"" + indexName + "\", \"+" + label.getColumnName() + ":" + escapedText + "*\") = true");
        statement.append(" OR :code = " + code.getColumnName() + ")");
    } else {
        statement.append(" WHERE " + code.getColumnName() + " IS NOT NULL");
    }
    if (date != null) {
        statement.append(" AND :date BETWEEN " + startDate.getColumnName() + " AND " + endDate.getColumnName());
    }
    if (!service.isSRA() && service.hasSessionUser()) {
        statement.append(" AND " + vertexType.getColumnName() + " IN ( :vertexTypes )");
    }
    statement.append(" ORDER BY " + label.getColumnName() + " DESC");
    if (limit != null) {
        statement.append(" LIMIT " + limit);
    }
    List<ServerGeoObjectIF> list = new LinkedList<ServerGeoObjectIF>();
    GraphQuery<VertexObject> query = new GraphQuery<VertexObject>(statement.toString());
    if (text != null) {
        query.setParameter("code", text);
    }
    if (date != null) {
        query.setParameter("date", date);
    }
    if (!service.isSRA() && service.hasSessionUser()) {
        List<String> vertexTypes = new GeoObjectPermissionService().getMandateTypes(service.getOrganization());
        query.setParameter("vertexTypes", vertexTypes);
    }
    List<VertexObject> results = query.getResults();
    for (VertexObject result : results) {
        MdVertexDAOIF mdVertexType = (MdVertexDAOIF) result.getMdClass();
        ServerGeoObjectType type = ServerGeoObjectType.get(mdVertexType);
        list.add(new VertexServerGeoObject(type, result, date));
    }
    return list;
}
Also used : RolePermissionService(net.geoprism.registry.permission.RolePermissionService) MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) MdEdgeDAOIF(com.runwaysdk.dataaccess.MdEdgeDAOIF) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) VertexObject(com.runwaysdk.business.graph.VertexObject) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) LinkedList(java.util.LinkedList) GeoObjectPermissionService(net.geoprism.registry.permission.GeoObjectPermissionService) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Example 53 with GraphQuery

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

the class HistoricalRow method getCount.

public static Long getCount(ServerGeoObjectType type, Date startDate, Date endDate) {
    MdVertexDAOIF transitionVertex = MdVertexDAO.getMdVertexDAO(Transition.CLASS);
    MdAttributeDAOIF eventAttribute = transitionVertex.definesAttribute(Transition.EVENT);
    MdVertexDAOIF eventVertex = MdVertexDAO.getMdVertexDAO(TransitionEvent.CLASS);
    MdAttributeDAOIF beforeTypeCode = eventVertex.definesAttribute(TransitionEvent.BEFORETYPECODE);
    MdAttributeDAOIF afterTypeCode = eventVertex.definesAttribute(TransitionEvent.AFTERTYPECODE);
    MdAttributeDAOIF eventDate = eventVertex.definesAttribute(TransitionEvent.EVENTDATE);
    List<ServerGeoObjectType> types = new LinkedList<ServerGeoObjectType>();
    types.add(type);
    types.addAll(type.getSubtypes());
    List<String> codes = types.stream().map(t -> t.getCode()).distinct().collect(Collectors.toList());
    StringBuilder statement = new StringBuilder();
    statement.append("SELECT COUNT(*)");
    statement.append(" FROM " + transitionVertex.getDBClassName());
    statement.append(" WHERE ( " + eventAttribute.getColumnName() + "." + beforeTypeCode.getColumnName() + " IN :typeCode");
    statement.append(" OR " + eventAttribute.getColumnName() + "." + afterTypeCode.getColumnName() + " IN :typeCode )");
    statement.append(" AND " + eventAttribute.getColumnName() + "." + eventDate.getColumnName() + " BETWEEN :startDate AND :endDate");
    GraphQuery<Long> query = new GraphQuery<Long>(statement.toString());
    query.setParameter("typeCode", codes);
    query.setParameter("startDate", startDate);
    query.setParameter("endDate", endDate);
    return query.getSingleResult();
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GraphQuery(com.runwaysdk.business.graph.GraphQuery) LinkedList(java.util.LinkedList)

Example 54 with GraphQuery

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

the class HistoricalRow method getHistoricalReport.

public static Page<HistoricalRow> getHistoricalReport(ServerGeoObjectType type, Date startDate, Date endDate, Integer pageSize, Integer pageNumber) {
    MdVertexDAOIF transitionVertex = MdVertexDAO.getMdVertexDAO(Transition.CLASS);
    MdAttributeDAOIF eventAttribute = transitionVertex.definesAttribute(Transition.EVENT);
    MdAttributeDAOIF sourceAttribute = transitionVertex.definesAttribute(Transition.SOURCE);
    MdAttributeDAOIF targetAttribute = transitionVertex.definesAttribute(Transition.TARGET);
    MdAttributeDAOIF transitionAttribute = transitionVertex.definesAttribute(Transition.TRANSITIONTYPE);
    MdVertexDAOIF eventVertex = MdVertexDAO.getMdVertexDAO(TransitionEvent.CLASS);
    MdAttributeDAOIF eventId = eventVertex.definesAttribute(TransitionEvent.EVENTID);
    MdAttributeDAOIF beforeTypeCode = eventVertex.definesAttribute(TransitionEvent.BEFORETYPECODE);
    MdAttributeDAOIF afterTypeCode = eventVertex.definesAttribute(TransitionEvent.AFTERTYPECODE);
    MdAttributeDAOIF eventDate = eventVertex.definesAttribute(TransitionEvent.EVENTDATE);
    MdAttributeDAOIF description = eventVertex.definesAttribute(TransitionEvent.DESCRIPTION);
    List<ServerGeoObjectType> types = new LinkedList<ServerGeoObjectType>();
    types.add(type);
    types.addAll(type.getSubtypes());
    List<String> codes = types.stream().map(t -> t.getCode()).distinct().collect(Collectors.toList());
    StringBuilder statement = new StringBuilder();
    statement.append("SELECT " + eventAttribute.getColumnName() + "." + eventId.getColumnName() + " AS " + HistoricalRow.EVENT_ID);
    statement.append(", " + eventAttribute.getColumnName() + "." + eventDate.getColumnName() + " AS " + HistoricalRow.EVENT_DATE);
    statement.append(", " + transitionAttribute.getColumnName() + " AS " + HistoricalRow.EVENT_TYPE);
    statement.append(", " + eventAttribute.getColumnName() + "." + description.getColumnName() + " AS " + HistoricalRow.DESCRIPTION);
    statement.append(", " + eventAttribute.getColumnName() + "." + beforeTypeCode.getColumnName() + " AS " + HistoricalRow.BEFORE_TYPE);
    statement.append(", " + sourceAttribute.getColumnName() + ".code AS " + HistoricalRow.BEFORE_CODE);
    statement.append(", " + sourceAttribute.getColumnName() + ".displayLabel_cot AS " + HistoricalRow.BEFORE_LABEL);
    statement.append(", " + eventAttribute.getColumnName() + "." + afterTypeCode.getColumnName() + " AS " + HistoricalRow.AFTER_TYPE);
    statement.append(", " + targetAttribute.getColumnName() + ".code AS " + HistoricalRow.AFTER_CODE);
    statement.append(", " + targetAttribute.getColumnName() + ".displayLabel_cot AS " + HistoricalRow.AFTER_LABEL);
    statement.append(" FROM " + transitionVertex.getDBClassName());
    statement.append(" WHERE ( " + eventAttribute.getColumnName() + "." + beforeTypeCode.getColumnName() + " IN :typeCode");
    statement.append(" OR " + eventAttribute.getColumnName() + "." + afterTypeCode.getColumnName() + " IN :typeCode )");
    statement.append(" AND " + eventAttribute.getColumnName() + "." + eventDate.getColumnName() + " BETWEEN :startDate AND :endDate");
    statement.append(" ORDER BY " + eventAttribute.getColumnName() + "." + eventDate.getColumnName() + " DESC");
    statement.append(", " + eventAttribute.getColumnName() + "." + eventId.getColumnName());
    statement.append(", " + sourceAttribute.getColumnName() + ".code");
    statement.append(", " + targetAttribute.getColumnName() + ".code");
    if (pageNumber != null && pageSize != null) {
        statement.append(" SKIP " + ((pageNumber - 1) * pageSize) + " LIMIT " + pageSize);
    }
    GraphQuery<Map<String, Object>> query = new GraphQuery<Map<String, Object>>(statement.toString());
    query.setParameter("typeCode", codes);
    query.setParameter("startDate", startDate);
    query.setParameter("endDate", endDate);
    Long count = getCount(type, startDate, endDate);
    List<HistoricalRow> results = query.getRawResults().stream().map(list -> HistoricalRow.parse(list)).collect(Collectors.toList());
    return new Page<HistoricalRow>(count, pageNumber, pageSize, results);
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) Transition(net.geoprism.registry.graph.transition.Transition) JsonObject(com.google.gson.JsonObject) TransitionEvent(net.geoprism.registry.graph.transition.TransitionEvent) Date(java.util.Date) GraphQuery(com.runwaysdk.business.graph.GraphQuery) LocalizationFacade(net.geoprism.localization.LocalizationFacade) IOException(java.io.IOException) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) Collectors(java.util.stream.Collectors) GsonBuilder(com.google.gson.GsonBuilder) MdVertexDAO(com.runwaysdk.dataaccess.metadata.graph.MdVertexDAO) JsonElement(com.google.gson.JsonElement) MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) List(java.util.List) HistoricalReportExcelExporter(net.geoprism.registry.excel.HistoricalReportExcelExporter) LocalizedValueConverter(net.geoprism.registry.conversion.LocalizedValueConverter) Map(java.util.Map) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) SeverGeoObjectJsonAdapters(net.geoprism.registry.etl.export.SeverGeoObjectJsonAdapters) LinkedList(java.util.LinkedList) InputStream(java.io.InputStream) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) LinkedList(java.util.LinkedList) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) JsonObject(com.google.gson.JsonObject) Map(java.util.Map) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Example 55 with GraphQuery

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

the class DHIS2ServiceTest method deleteExternalIds.

@Request
private void deleteExternalIds() {
    final MdEdgeDAOIF mdEdge = MdEdgeDAO.getMdEdgeDAO(GeoVertex.EXTERNAL_ID);
    StringBuilder builder = new StringBuilder();
    builder.append("SELECT FROM " + mdEdge.getDBClassName());
    builder.append(" WHERE out = :system");
    final GraphQuery<EdgeObject> query = new GraphQuery<EdgeObject>(builder.toString());
    query.setParameter("system", this.system.getRID());
    List<EdgeObject> edges = query.getResults();
    for (EdgeObject edge : edges) {
        edge.delete();
    }
}
Also used : MdEdgeDAOIF(com.runwaysdk.dataaccess.MdEdgeDAOIF) EdgeObject(com.runwaysdk.business.graph.EdgeObject) GraphQuery(com.runwaysdk.business.graph.GraphQuery) Request(com.runwaysdk.session.Request)

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