Search in sources :

Example 26 with ServerHierarchyType

use of net.geoprism.registry.model.ServerHierarchyType 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;
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) MdEdgeDAOIF(com.runwaysdk.dataaccess.MdEdgeDAOIF) VertexObject(com.runwaysdk.business.graph.VertexObject) ServerParentTreeNode(net.geoprism.registry.model.ServerParentTreeNode) 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) Date(java.util.Date) LocalDate(java.time.LocalDate) 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) ServerParentTreeNodeOverTime(net.geoprism.registry.view.ServerParentTreeNodeOverTime) HashedMap(org.apache.commons.collections4.map.HashedMap) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Example 27 with ServerHierarchyType

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

Example 28 with ServerHierarchyType

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

the class RegistryService method refreshMetadataCache.

public void refreshMetadataCache() {
    ServiceFactory.getMetadataCache().rebuild();
    QueryFactory qf = new QueryFactory();
    UniversalQuery uq = new UniversalQuery(qf);
    OIterator<? extends Universal> it = uq.getIterator();
    try {
        while (it.hasNext()) {
            Universal uni = it.next();
            if (uni.getKey().equals(Universal.ROOT_KEY)) {
                continue;
            }
            ServerGeoObjectType type = new ServerGeoObjectTypeConverter().build(uni);
            ServiceFactory.getMetadataCache().addGeoObjectType(type);
        }
    } finally {
        it.close();
    }
    // We must build the hierarchy types which are inherited first
    // Otherwise you will end up with a NPE when building the hierarchies
    // which inherit the inherited hierarchy if it hasn't been built
    HierarchicalRelationshipType.getInheritedTypes().forEach(relationship -> {
        ServerHierarchyType ht = new ServerHierarchyTypeBuilder().get(relationship, false);
        ServiceFactory.getMetadataCache().addHierarchyType(ht);
    });
    HierarchicalRelationshipType.getAll().forEach(relationship -> {
        ServerHierarchyType ht = new ServerHierarchyTypeBuilder().get(relationship, false);
        if (!ServiceFactory.getMetadataCache().getHierachyType(ht.getCode()).isPresent()) {
            ServiceFactory.getMetadataCache().addHierarchyType(ht);
        }
    });
    try {
        // This is, unfortunately, a big hack. Some patch items need to occur
        // before the organizaiton class is defined
        MdClassDAO.getMdClassDAO(Organization.CLASS);
        OrganizationQuery oQ = new OrganizationQuery(qf);
        OIterator<? extends Organization> it3 = oQ.getIterator();
        try {
            while (it3.hasNext()) {
                Organization organization = it3.next();
                ServiceFactory.getMetadataCache().addOrganization(organization);
            }
        } finally {
            it3.close();
        }
    } catch (com.runwaysdk.dataaccess.cache.DataNotFoundException e) {
    // skip for now
    }
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) QueryFactory(com.runwaysdk.query.QueryFactory) Universal(com.runwaysdk.system.gis.geo.Universal) ServerGeoObjectTypeConverter(net.geoprism.registry.conversion.ServerGeoObjectTypeConverter) Organization(net.geoprism.registry.Organization) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) OrganizationQuery(net.geoprism.registry.OrganizationQuery) ServerHierarchyTypeBuilder(net.geoprism.registry.conversion.ServerHierarchyTypeBuilder) UniversalQuery(com.runwaysdk.system.gis.geo.UniversalQuery)

Example 29 with ServerHierarchyType

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

the class RegistryService method getAncestors.

@Request(RequestType.SESSION)
public List<GeoObjectType> getAncestors(String sessionId, String code, String hierarchyCode, Boolean includeInheritedTypes, Boolean includeChild) {
    ServerGeoObjectType child = ServerGeoObjectType.get(code);
    ServerHierarchyType hierarchyType = ServerHierarchyType.get(hierarchyCode);
    List<GeoObjectType> ancestors = child.getTypeAncestors(hierarchyType, includeInheritedTypes);
    if (includeChild) {
        ancestors.add(child.getType());
    }
    return ancestors;
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) Request(com.runwaysdk.session.Request) OAuthClientRequest(org.apache.oltu.oauth2.client.request.OAuthClientRequest)

Example 30 with ServerHierarchyType

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

the class SynchronizationConfigService method edit.

@Request(RequestType.SESSION)
public JsonObject edit(String sessionId, String oid) {
    JsonObject response = new JsonObject();
    if (oid != null && oid.length() > 0) {
        SynchronizationConfig config = SynchronizationConfig.lock(oid);
        response.add("config", config.toJSON());
    }
    JsonArray orgs = new JsonArray();
    List<Organization> organizations = Organization.getUserAdminOrganizations();
    for (Organization organization : organizations) {
        JsonArray hierarchies = new JsonArray();
        List<ServerHierarchyType> sHierachies = ServerHierarchyType.getForOrganization(organization);
        for (ServerHierarchyType hierarchy : sHierachies) {
            JsonObject object = new JsonObject();
            object.addProperty("label", hierarchy.getDisplayLabel().getValue());
            object.addProperty("code", hierarchy.getCode());
            hierarchies.add(object);
        }
        JsonArray systems = new JsonArray();
        List<ExternalSystem> esystems = ExternalSystem.getForOrganization(organization);
        for (ExternalSystem system : esystems) {
            if (system.isExportSupported()) {
                LocalizedValue label = LocalizedValueConverter.convert(system.getEmbeddedComponent(ExternalSystem.LABEL));
                JsonObject object = new JsonObject();
                object.addProperty("label", label.getValue());
                object.addProperty("oid", system.getOid());
                object.addProperty("type", system.getMdClass().getTypeName());
                systems.add(object);
            }
        }
        JsonObject object = new JsonObject();
        object.addProperty("label", organization.getDisplayLabel().getValue());
        object.addProperty("code", organization.getCode());
        object.add("hierarchies", hierarchies);
        object.add("systems", systems);
        orgs.add(object);
    }
    response.add("orgs", orgs);
    return response;
}
Also used : JsonArray(com.google.gson.JsonArray) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) Organization(net.geoprism.registry.Organization) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) DHIS2ExternalSystem(net.geoprism.registry.graph.DHIS2ExternalSystem) ExternalSystem(net.geoprism.registry.graph.ExternalSystem) JsonObject(com.google.gson.JsonObject) SynchronizationConfig(net.geoprism.registry.SynchronizationConfig) Request(com.runwaysdk.session.Request)

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