Search in sources :

Example 6 with GraphType

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

the class RelationshipVisualizationService method tree.

@Request(RequestType.SESSION)
public JsonElement tree(String sessionId, Date date, String relationshipType, String graphTypeCode, String geoObjectCode, String geoObjectTypeCode) {
    final GeoObjectTypePermissionServiceIF typePermissions = ServiceFactory.getGeoObjectTypePermissionService();
    final ServerGeoObjectType type = ServiceFactory.getMetadataCache().getGeoObjectType(geoObjectTypeCode).get();
    JsonObject view = new JsonObject();
    JsonArray jaEdges = new JsonArray();
    view.add("edges", jaEdges);
    JsonArray jaVerticies = new JsonArray();
    view.add("verticies", jaVerticies);
    if (typePermissions.canRead(type.getOrganization().getCode(), type, type.getIsPrivate())) {
        VertexServerGeoObject rootGo = (VertexServerGeoObject) ServiceFactory.getGeoObjectService().getGeoObjectByCode(geoObjectCode, type);
        final GraphType graphType = GraphType.getByCode(relationshipType, graphTypeCode);
        jaVerticies.add(serializeVertex(rootGo, (graphType instanceof UndirectedGraphType) ? "PARENT" : "SELECTED"));
        Set<String> setEdges = new HashSet<String>();
        Set<String> setVerticies = new HashSet<String>();
        if (graphType instanceof UndirectedGraphType) {
            // get parent and get children return the same thing for an undirected
            // graph
            fetchChildrenData(false, rootGo, graphType, date, jaEdges, jaVerticies, setEdges, setVerticies);
        } else if (graphType instanceof DirectedAcyclicGraphType) {
            // Out is children
            fetchParentsData(false, rootGo, graphType, date, jaEdges, jaVerticies, setEdges, setVerticies);
            // In is parents
            fetchChildrenData(false, rootGo, graphType, date, jaEdges, jaVerticies, setEdges, setVerticies);
        } else {
            // Out is children
            fetchParentsData(true, rootGo, graphType, date, jaEdges, jaVerticies, setEdges, setVerticies);
            // In is parents
            fetchChildrenData(false, rootGo, graphType, date, jaEdges, jaVerticies, setEdges, setVerticies);
        }
    }
    return view;
}
Also used : JsonArray(com.google.gson.JsonArray) DirectedAcyclicGraphType(net.geoprism.registry.DirectedAcyclicGraphType) GraphType(net.geoprism.registry.model.GraphType) UndirectedGraphType(net.geoprism.registry.UndirectedGraphType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) DirectedAcyclicGraphType(net.geoprism.registry.DirectedAcyclicGraphType) JsonObject(com.google.gson.JsonObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) GeoObjectTypePermissionServiceIF(net.geoprism.registry.permission.GeoObjectTypePermissionServiceIF) UndirectedGraphType(net.geoprism.registry.UndirectedGraphType) HashSet(java.util.HashSet) Request(com.runwaysdk.session.Request)

Example 7 with GraphType

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

the class RelationshipVisualizationService method getRelationshipTypes.

@Request(RequestType.SESSION)
public JsonElement getRelationshipTypes(String sessionId, String geoObjectTypeCode) {
    JsonArray view = new JsonArray();
    // Hierarchy relationships
    final HierarchyTypePermissionServiceIF htpService = ServiceFactory.getHierarchyPermissionService();
    ServerGeoObjectType type = ServerGeoObjectType.get(geoObjectTypeCode);
    type.getHierarchies().stream().filter(htp -> {
        return htpService.canRead(htp.getOrganizationCode());
    }).forEach(graphType -> {
        JsonObject jo = new JsonObject();
        jo.addProperty("oid", graphType.getCode());
        jo.addProperty("code", graphType.getCode());
        jo.add("label", graphType.getLabel().toJSON());
        jo.addProperty("isHierarchy", true);
        view.add(jo);
    });
    // Non-hierarchy relationships
    UndirectedGraphType.getAll().forEach(graphType -> {
        JsonObject jo = graphType.toJSON();
        jo.addProperty("isHierarchy", false);
        view.add(jo);
    });
    DirectedAcyclicGraphType.getAll().forEach(graphType -> {
        JsonObject jo = graphType.toJSON();
        jo.addProperty("isHierarchy", false);
        view.add(jo);
    });
    return view;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) HierarchyTypePermissionServiceIF(net.geoprism.registry.permission.HierarchyTypePermissionServiceIF) ServerGraphNode(net.geoprism.registry.model.ServerGraphNode) Date(java.util.Date) RequestType(com.runwaysdk.session.RequestType) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) Set(java.util.Set) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) Request(com.runwaysdk.session.Request) DirectedAcyclicGraphType(net.geoprism.registry.DirectedAcyclicGraphType) ServerParentGraphNode(net.geoprism.registry.model.ServerParentGraphNode) ServiceFactory(net.geoprism.registry.service.ServiceFactory) HashSet(java.util.HashSet) JsonElement(com.google.gson.JsonElement) ServerChildGraphNode(net.geoprism.registry.model.ServerChildGraphNode) JsonArray(com.google.gson.JsonArray) GraphType(net.geoprism.registry.model.GraphType) UndirectedGraphType(net.geoprism.registry.UndirectedGraphType) GeoObjectTypePermissionServiceIF(net.geoprism.registry.permission.GeoObjectTypePermissionServiceIF) HierarchyTypePermissionServiceIF(net.geoprism.registry.permission.HierarchyTypePermissionServiceIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) JsonObject(com.google.gson.JsonObject) Request(com.runwaysdk.session.Request)

Aggregations

Request (com.runwaysdk.session.Request)7 GraphType (net.geoprism.registry.model.GraphType)7 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)5 ServerGeoObjectService (net.geoprism.registry.geoobject.ServerGeoObjectService)4 ServerGraphNode (net.geoprism.registry.model.ServerGraphNode)4 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 HashSet (java.util.HashSet)2 DirectedAcyclicGraphType (net.geoprism.registry.DirectedAcyclicGraphType)2 UndirectedGraphType (net.geoprism.registry.UndirectedGraphType)2 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)2 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)2 GeoObjectTypePermissionServiceIF (net.geoprism.registry.permission.GeoObjectTypePermissionServiceIF)2 JsonElement (com.google.gson.JsonElement)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)1 RequestType (com.runwaysdk.session.RequestType)1 IOException (java.io.IOException)1 Date (java.util.Date)1 Set (java.util.Set)1