Search in sources :

Example 66 with ServerHierarchyType

use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.

the class VertexServerGeoObject method internalGetParentGeoObjects.

protected static ServerParentTreeNode internalGetParentGeoObjects(VertexServerGeoObject child, String[] parentTypes, boolean recursive, ServerHierarchyType htIn, Date date) {
    ServerParentTreeNode tnRoot = new ServerParentTreeNode(child, htIn, date, null, null);
    Map<String, Object> parameters = new HashedMap<String, Object>();
    parameters.put("rid", child.getVertex().getRID());
    StringBuilder statement = new StringBuilder();
    statement.append("SELECT EXPAND( inE(");
    if (htIn != null) {
        statement.append("'" + htIn.getMdEdge().getDBClassName() + "'");
    }
    statement.append(")");
    if (date != null || (parentTypes != null && parentTypes.length > 0)) {
        statement.append("[");
        if (date != null) {
            statement.append(" :date BETWEEN startDate AND endDate");
            parameters.put("date", date);
        }
        if (parentTypes != null && parentTypes.length > 0) {
            if (date != null) {
                statement.append(" AND");
            }
            statement.append("(");
            for (int i = 0; i < parentTypes.length; i++) {
                ServerGeoObjectType type = ServerGeoObjectType.get(parentTypes[i]);
                final String paramName = "p" + Integer.toString(i);
                if (i > 0) {
                    statement.append(" OR ");
                }
                statement.append("out.@class = :" + paramName);
                parameters.put(paramName, type.getMdVertex().getDBClassName());
            }
            statement.append(")");
        }
        statement.append("]");
    }
    statement.append(") FROM :rid");
    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)) {
            final VertexObject parentVertex = edge.getParent();
            MdVertexDAOIF mdVertex = (MdVertexDAOIF) parentVertex.getMdClass();
            ServerHierarchyType ht = ServerHierarchyType.get(mdEdge);
            ServerGeoObjectType parentType = ServerGeoObjectType.get(mdVertex);
            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, edge.getOid());
            }
            tnRoot.addParent(tnParent);
        }
    }
    return tnRoot;
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) MdEdgeDAOIF(com.runwaysdk.dataaccess.MdEdgeDAOIF) ServerParentTreeNode(net.geoprism.registry.model.ServerParentTreeNode) VertexObject(com.runwaysdk.business.graph.VertexObject) 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) 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) HashedMap(org.apache.commons.collections4.map.HashedMap) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Example 67 with ServerHierarchyType

use of net.geoprism.registry.model.ServerHierarchyType 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 68 with ServerHierarchyType

use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.

the class VertexSynonymRestriction method restrict.

@Override
public void restrict(StringBuilder statement, Map<String, Object> parameters) {
    statement.append(",where: (code = :label");
    statement.append(" OR displayLabel_cot CONTAINS (:date BETWEEN startDate AND endDate AND " + localize("value") + " = :label)");
    statement.append(" OR out('geo_vertex_has_synonym').label CONTAINS :label)");
    parameters.put("label", this.label);
    parameters.put("date", this.date);
    if (this.parent != null && this.hierarchyType != null) {
        Set<String> edges = new TreeSet<String>();
        edges.add(this.hierarchyType.getMdEdge().getDBClassName());
        ServerHierarchyType inheritedHierarchy = type.findHierarchy(this.hierarchyType, this.parent.getType());
        if (inheritedHierarchy != null) {
            edges.add(inheritedHierarchy.getMdEdge().getDBClassName());
        }
        statement.append("}.in(");
        int i = 0;
        for (String edge : edges) {
            if (i > 0) {
                statement.append(",");
            }
            statement.append("'" + edge + "'");
            i++;
        }
        statement.append("){where: (uuid=:uuid), while: (true)");
        parameters.put("uuid", this.parent.getUid());
    }
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) TreeSet(java.util.TreeSet)

Example 69 with ServerHierarchyType

use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.

the class LocationService method getLocationInformation.

@Request(RequestType.SESSION)
public LocationInformation getLocationInformation(String sessionId, Date date, String typeCode, String hierarchyCode) {
    LocationInformation information = new LocationInformation();
    HierarchyService hService = ServiceFactory.getHierarchyService();
    HierarchyType[] hierarchies = hService.getHierarchyTypes(sessionId, null, PermissionContext.READ);
    ServerHierarchyType hierarchy = null;
    if (hierarchyCode == null || hierarchyCode.length() == 0) {
        hierarchy = ServerHierarchyType.get(hierarchies[0]);
    } else {
        hierarchy = ServerHierarchyType.get(hierarchyCode);
    }
    List<ServerGeoObjectType> nodes = hierarchy.getDirectRootNodes();
    if (nodes.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
       */
        ServerGeoObjectType type = nodes.get(0);
        if (typeCode != null && typeCode.length() > 0) {
            for (ServerGeoObjectType node : nodes) {
                if (node.getCode().equals(typeCode)) {
                    type = ServerGeoObjectType.get(typeCode);
                }
            }
        }
        if (type != null) {
            ServiceFactory.getGeoObjectPermissionService().enforceCanRead(type.getOrganization().getCode(), type);
            information.setChildType(type.getType());
            List<VertexServerGeoObject> children = this.getGeoObjects(type.getCode(), date);
            for (VertexServerGeoObject child : children) {
                information.addChild(child.toGeoObject(date));
            }
        }
    }
    information.setHierarchies(hierarchies);
    information.setHierarchy(hierarchy.getCode());
    information.setChildTypes(nodes);
    return information;
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) LocationInformation(net.geoprism.registry.view.LocationInformation) HierarchyService(net.geoprism.registry.hierarchy.HierarchyService) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) HierarchyType(org.commongeoregistry.adapter.metadata.HierarchyType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) Request(com.runwaysdk.session.Request)

Example 70 with ServerHierarchyType

use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.

the class ServerParentTreeNodeOverTime method toJSON.

public JsonArray toJSON() {
    SimpleDateFormat format = getDateFormat();
    final JsonArray response = new JsonArray();
    final Set<Entry<String, Hierarchy>> entrySet = this.hierarchies.entrySet();
    for (Entry<String, Hierarchy> entry : entrySet) {
        final Hierarchy hierarchy = entry.getValue();
        final ServerHierarchyType ht = hierarchy.getType();
        List<GeoObjectType> parentTypes = this.type.getTypeAncestors(ht, false);
        // Populate a "types" array with all ancestors of the GOT they passed us
        JsonArray types = new JsonArray();
        for (GeoObjectType parent : parentTypes) {
            ServerGeoObjectType pType = ServerGeoObjectType.get(parent);
            if (!pType.getCode().equals(this.type.getCode())) {
                JsonObject pObject = new JsonObject();
                pObject.addProperty(JSON_TYPE_CODE, pType.getCode());
                pObject.addProperty(JSON_TYPE_LABEL, pType.getLabel().getValue());
                types.add(pObject);
            }
        }
        // Populate an "entries" array with all the parents per time period
        final JsonArray entries = new JsonArray();
        final List<ServerParentTreeNode> nodes = hierarchy.getNodes();
        for (ServerParentTreeNode node : nodes) {
            JsonObject pArray = new JsonObject();
            for (GeoObjectType parent : parentTypes) {
                ServerGeoObjectType pType = ServerGeoObjectType.get(parent);
                if (!pType.getCode().equals(this.type.getCode())) {
                    final List<ServerParentTreeNode> ptns = node.findParentOfType(pType.getCode());
                    if (ptns.size() > 0) {
                        ServerParentTreeNode sptn = ptns.get(0);
                        final VertexServerGeoObject sGeoObject = (VertexServerGeoObject) sptn.getGeoObject();
                        final GeoObject geoObject = sGeoObject.toGeoObject(node.getStartDate());
                        geoObject.setGeometry(null);
                        JsonObject pObject = new JsonObject();
                        pObject.add(JSON_ENTRY_PARENT_GEOOBJECT, geoObject.toJSON());
                        LocalizedValue label = sGeoObject.getDisplayLabel();
                        if (label != null) {
                            pObject.addProperty(JSON_ENTRY_PARENT_TEXT, label.getValue() + " : " + sGeoObject.getCode());
                        } else {
                            pObject.addProperty(JSON_ENTRY_PARENT_TEXT, "null" + " : " + sGeoObject.getCode());
                        }
                        pArray.add(pType.getCode(), pObject);
                    }
                }
            }
            JsonObject object = new JsonObject();
            object.addProperty(JSON_ENTRY_STARTDATE, format.format(node.getStartDate()));
            if (node.getEndDate() != null) {
                object.addProperty(JSON_ENTRY_ENDDATE, format.format(node.getEndDate()));
            }
            object.add(JSON_ENTRY_PARENTS, pArray);
            object.addProperty("oid", node.getOid());
            entries.add(object);
        }
        JsonObject object = new JsonObject();
        object.addProperty(JSON_HIERARCHY_CODE, ht.getCode());
        object.addProperty(JSON_HIERARCHY_LABEL, ht.getDisplayLabel().getValue());
        object.add(JSON_HIERARCHY_TYPES, types);
        object.add(JSON_HIERARCHY_ENTRIES, entries);
        response.add(object);
    }
    return response;
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ServerParentTreeNode(net.geoprism.registry.model.ServerParentTreeNode) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) JsonObject(com.google.gson.JsonObject) JsonArray(com.google.gson.JsonArray) Entry(java.util.Map.Entry) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)86 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)55 Request (com.runwaysdk.session.Request)38 JsonObject (com.google.gson.JsonObject)20 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)18 Test (org.junit.Test)17 JsonArray (com.google.gson.JsonArray)16 LinkedList (java.util.LinkedList)14 List (java.util.List)14 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)12 GeoObjectType (org.commongeoregistry.adapter.metadata.GeoObjectType)12 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)11 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)11 Locale (java.util.Locale)10 Point (com.vividsolutions.jts.geom.Point)9 ServerParentTreeNode (net.geoprism.registry.model.ServerParentTreeNode)9 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)8 MdBusiness (com.runwaysdk.system.metadata.MdBusiness)8 InheritedHierarchyAnnotation (net.geoprism.registry.InheritedHierarchyAnnotation)8 Organization (net.geoprism.registry.Organization)8