Search in sources :

Example 1 with GeoObjectRelationshipPermissionServiceIF

use of net.geoprism.registry.permission.GeoObjectRelationshipPermissionServiceIF in project geoprism-registry by terraframe.

the class HierarchyService method getHierarchiesForType.

@Request(RequestType.SESSION)
public JsonArray getHierarchiesForType(String sessionId, String code, Boolean includeTypes) {
    ServerGeoObjectType geoObjectType = ServerGeoObjectType.get(code);
    List<ServerHierarchyType> hierarchyTypes = ServerHierarchyType.getAll();
    JsonArray hierarchies = new JsonArray();
    HierarchyTypePermissionServiceIF htpService = ServiceFactory.getHierarchyPermissionService();
    GeoObjectRelationshipPermissionServiceIF grpService = ServiceFactory.getGeoObjectRelationshipPermissionService();
    for (ServerHierarchyType sHT : hierarchyTypes) {
        if (htpService.canRead(sHT.getOrganizationCode())) {
            List<GeoObjectType> parents = geoObjectType.getTypeAncestors(sHT, true);
            if (parents.size() > 0 || geoObjectType.isRoot(sHT)) {
                JsonObject object = new JsonObject();
                object.addProperty("code", sHT.getCode());
                object.addProperty("label", sHT.getDisplayLabel().getValue());
                if (includeTypes) {
                    JsonArray pArray = new JsonArray();
                    for (GeoObjectType parent : parents) {
                        ServerGeoObjectType pType = ServerGeoObjectType.get(parent);
                        if (!pType.getCode().equals(geoObjectType.getCode()) && grpService.canViewChild(sHT.getOrganizationCode(), null, pType)) {
                            JsonObject pObject = new JsonObject();
                            pObject.addProperty("code", pType.getCode());
                            pObject.addProperty("label", pType.getLabel().getValue());
                            pArray.add(pObject);
                        }
                    }
                    object.add("parents", pArray);
                }
                hierarchies.add(object);
            }
        }
    }
    if (hierarchies.size() == 0) {
        for (ServerHierarchyType sHT : hierarchyTypes) {
            if (htpService.canWrite(sHT.getOrganizationCode())) {
                if (geoObjectType.isRoot(sHT)) {
                    JsonObject object = new JsonObject();
                    object.addProperty("code", sHT.getCode());
                    object.addProperty("label", sHT.getDisplayLabel().getValue());
                    object.add("parents", new JsonArray());
                    hierarchies.add(object);
                }
            }
        }
    }
    return hierarchies;
}
Also used : JsonArray(com.google.gson.JsonArray) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) GeoObjectRelationshipPermissionServiceIF(net.geoprism.registry.permission.GeoObjectRelationshipPermissionServiceIF) HierarchyTypePermissionServiceIF(net.geoprism.registry.permission.HierarchyTypePermissionServiceIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) JsonObject(com.google.gson.JsonObject) Request(com.runwaysdk.session.Request)

Example 2 with GeoObjectRelationshipPermissionServiceIF

use of net.geoprism.registry.permission.GeoObjectRelationshipPermissionServiceIF in project geoprism-registry by terraframe.

the class ServerChildTreeNode method toNode.

public ChildTreeNode toNode(boolean enforcePermissions) {
    final GeoObjectRelationshipPermissionServiceIF relPermServ = ServiceFactory.getGeoObjectRelationshipPermissionService();
    final GeoObjectPermissionServiceIF goPermServ = ServiceFactory.getGeoObjectPermissionService();
    GeoObject go = this.getGeoObject().toGeoObject(this.getStartDate());
    HierarchyType ht = this.getHierarchyType() != null ? this.getHierarchyType().toHierarchyType() : null;
    ChildTreeNode node = new ChildTreeNode(go, ht);
    String orgCode = go.getType().getOrganizationCode();
    ServerGeoObjectType type = ServerGeoObjectType.get(go.getType());
    for (ServerChildTreeNode child : this.children) {
        if (!enforcePermissions || (relPermServ.canViewChild(orgCode, type, child.getGeoObject().getType()) && goPermServ.canRead(orgCode, type))) {
            node.addChild(child.toNode(enforcePermissions));
        }
    }
    return node;
}
Also used : GeoObjectRelationshipPermissionServiceIF(net.geoprism.registry.permission.GeoObjectRelationshipPermissionServiceIF) HierarchyType(org.commongeoregistry.adapter.metadata.HierarchyType) GeoObjectPermissionServiceIF(net.geoprism.registry.permission.GeoObjectPermissionServiceIF) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) ChildTreeNode(org.commongeoregistry.adapter.dataaccess.ChildTreeNode)

Example 3 with GeoObjectRelationshipPermissionServiceIF

use of net.geoprism.registry.permission.GeoObjectRelationshipPermissionServiceIF in project geoprism-registry by terraframe.

the class HierarchyService method filterHierarchiesFromPermissions.

public static void filterHierarchiesFromPermissions(ServerGeoObjectType type, ServerParentTreeNodeOverTime pot) {
    GeoObjectRelationshipPermissionServiceIF service = ServiceFactory.getGeoObjectRelationshipPermissionService();
    Collection<ServerHierarchyType> hierarchies = pot.getHierarchies();
    for (ServerHierarchyType hierarchy : hierarchies) {
        Organization organization = hierarchy.getOrganization();
        // null, type) ))
        if (!service.canViewChild(organization.getCode(), null, type)) {
            pot.remove(hierarchy);
        }
    }
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) GeoObjectRelationshipPermissionServiceIF(net.geoprism.registry.permission.GeoObjectRelationshipPermissionServiceIF) Organization(net.geoprism.registry.Organization)

Aggregations

GeoObjectRelationshipPermissionServiceIF (net.geoprism.registry.permission.GeoObjectRelationshipPermissionServiceIF)3 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 Request (com.runwaysdk.session.Request)1 Organization (net.geoprism.registry.Organization)1 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)1 GeoObjectPermissionServiceIF (net.geoprism.registry.permission.GeoObjectPermissionServiceIF)1 HierarchyTypePermissionServiceIF (net.geoprism.registry.permission.HierarchyTypePermissionServiceIF)1 ChildTreeNode (org.commongeoregistry.adapter.dataaccess.ChildTreeNode)1 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)1 GeoObjectType (org.commongeoregistry.adapter.metadata.GeoObjectType)1 HierarchyType (org.commongeoregistry.adapter.metadata.HierarchyType)1