Search in sources :

Example 1 with HierarchyTypePermissionServiceIF

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

the class HierarchyService method getHierarchyGroupedTypes.

@Request(RequestType.SESSION)
public JsonArray getHierarchyGroupedTypes(String sessionId) {
    final HierarchyTypePermissionServiceIF hierarchyPermissions = ServiceFactory.getHierarchyPermissionService();
    final GeoObjectTypePermissionServiceIF typePermissions = ServiceFactory.getGeoObjectTypePermissionService();
    final RolePermissionService rps = ServiceFactory.getRolePermissionService();
    final boolean isSRA = rps.isSRA();
    JsonArray allHiers = new JsonArray();
    List<ServerHierarchyType> shts = ServiceFactory.getMetadataCache().getAllHierarchyTypes();
    for (ServerHierarchyType sht : shts) {
        final String htOrgCode = sht.getOrganizationCode();
        if (hierarchyPermissions.canRead(htOrgCode) && (isSRA || rps.isRA(htOrgCode) || rps.isRM(htOrgCode))) {
            JsonObject hierView = new JsonObject();
            hierView.addProperty("code", sht.getCode());
            hierView.addProperty("label", sht.getDisplayLabel().getValue());
            hierView.addProperty("orgCode", sht.getOrganizationCode());
            JsonArray allHierTypes = new JsonArray();
            List<ServerGeoObjectType> types = sht.getAllTypes();
            for (ServerGeoObjectType type : types) {
                final String gotOrgCode = type.getOrganizationCode();
                if (typePermissions.canRead(gotOrgCode, type, type.getIsPrivate()) && (isSRA || rps.isRA(gotOrgCode) || rps.isRM(gotOrgCode, type))) {
                    if (type.getIsAbstract()) {
                        JsonObject superView = new JsonObject();
                        superView.addProperty("code", type.getCode());
                        superView.addProperty("label", type.getLabel().getValue());
                        superView.addProperty("orgCode", type.getOrganizationCode());
                        superView.addProperty("isAbstract", true);
                        List<ServerGeoObjectType> subtypes = type.getSubtypes();
                        for (ServerGeoObjectType subtype : subtypes) {
                            JsonObject typeView = new JsonObject();
                            typeView.addProperty("code", subtype.getCode());
                            typeView.addProperty("label", subtype.getLabel().getValue());
                            typeView.addProperty("orgCode", subtype.getOrganization().getCode());
                            typeView.add("super", superView);
                            allHierTypes.add(typeView);
                        }
                    } else {
                        JsonObject typeView = new JsonObject();
                        typeView.addProperty("code", type.getCode());
                        typeView.addProperty("label", type.getLabel().getValue());
                        typeView.addProperty("orgCode", type.getOrganizationCode());
                        allHierTypes.add(typeView);
                    }
                }
            }
            hierView.add("types", allHierTypes);
            allHiers.add(hierView);
        }
    }
    return allHiers;
}
Also used : RolePermissionService(net.geoprism.registry.permission.RolePermissionService) JsonArray(com.google.gson.JsonArray) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) HierarchyTypePermissionServiceIF(net.geoprism.registry.permission.HierarchyTypePermissionServiceIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) JsonObject(com.google.gson.JsonObject) GeoObjectTypePermissionServiceIF(net.geoprism.registry.permission.GeoObjectTypePermissionServiceIF) Request(com.runwaysdk.session.Request)

Example 2 with HierarchyTypePermissionServiceIF

use of net.geoprism.registry.permission.HierarchyTypePermissionServiceIF 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 3 with HierarchyTypePermissionServiceIF

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

the class HierarchyService method getHierarchiesForSubtypes.

@Request(RequestType.SESSION)
public JsonArray getHierarchiesForSubtypes(String sessionId, String code) {
    ServerGeoObjectType geoObjectType = ServerGeoObjectType.get(code);
    Set<ServerHierarchyType> hierarchyTypes = geoObjectType.getHierarchiesOfSubTypes();
    JsonArray hierarchies = new JsonArray();
    HierarchyTypePermissionServiceIF pService = ServiceFactory.getHierarchyPermissionService();
    for (ServerHierarchyType sHT : hierarchyTypes) {
        if (pService.canWrite(sHT.getOrganizationCode())) {
            JsonObject object = new JsonObject();
            object.addProperty("code", sHT.getCode());
            object.addProperty("label", sHT.getDisplayLabel().getValue());
            hierarchies.add(object);
        }
    }
    return hierarchies;
}
Also used : JsonArray(com.google.gson.JsonArray) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) HierarchyTypePermissionServiceIF(net.geoprism.registry.permission.HierarchyTypePermissionServiceIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) JsonObject(com.google.gson.JsonObject) Request(com.runwaysdk.session.Request)

Example 4 with HierarchyTypePermissionServiceIF

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

the class HierarchyService method getHierarchyTypes.

/**
 * Returns the {@link HierarchyType}s with the given codes or all
 * {@link HierarchyType}s if no codes are provided.
 *
 * @param sessionId
 * @param codes
 *          codes of the {@link HierarchyType}s.
 * @param context
 * @return the {@link HierarchyType}s with the given codes or all
 *         {@link HierarchyType}s if no codes are provided.
 */
@Request(RequestType.SESSION)
public HierarchyType[] getHierarchyTypes(String sessionId, String[] codes, PermissionContext context) {
    final HierarchyTypePermissionServiceIF hierPermServ = ServiceFactory.getHierarchyPermissionService();
    List<ServerHierarchyType> types = ServerHierarchyType.getAll();
    if (codes != null && codes.length > 0) {
        final List<String> list = Arrays.asList(codes);
        types = types.stream().filter(type -> list.contains(type.getCode())).collect(Collectors.toList());
    }
    // Filter out what they're not allowed to see
    List<HierarchyType> hierarchies = types.stream().filter(type -> {
        Organization org = Organization.getByCode(type.getOrganizationCode());
        return !((context.equals(PermissionContext.READ) && !hierPermServ.canRead(org.getCode())) || (context.equals(PermissionContext.WRITE) && !hierPermServ.canWrite(org.getCode())));
    }).filter(type -> type.hasVisibleRoot()).map(type -> type.toHierarchyType(false)).collect(Collectors.toList());
    return hierarchies.toArray(new HierarchyType[hierarchies.size()]);
}
Also used : JsonObject(com.google.gson.JsonObject) Arrays(java.util.Arrays) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) HierarchyTypePermissionServiceIF(net.geoprism.registry.permission.HierarchyTypePermissionServiceIF) ServerParentTreeNodeOverTime(net.geoprism.registry.view.ServerParentTreeNodeOverTime) Collection(java.util.Collection) RequestType(com.runwaysdk.session.RequestType) GeoRegistryUtil(net.geoprism.registry.GeoRegistryUtil) Set(java.util.Set) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) Collectors(java.util.stream.Collectors) Request(com.runwaysdk.session.Request) ServiceFactory(net.geoprism.registry.service.ServiceFactory) PermissionContext(net.geoprism.registry.permission.PermissionContext) HierarchyType(org.commongeoregistry.adapter.metadata.HierarchyType) GeoObjectRelationshipPermissionServiceIF(net.geoprism.registry.permission.GeoObjectRelationshipPermissionServiceIF) List(java.util.List) JsonArray(com.google.gson.JsonArray) Organization(net.geoprism.registry.Organization) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) Session(com.runwaysdk.session.Session) GeoObjectTypePermissionServiceIF(net.geoprism.registry.permission.GeoObjectTypePermissionServiceIF) RolePermissionService(net.geoprism.registry.permission.RolePermissionService) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) Organization(net.geoprism.registry.Organization) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) HierarchyType(org.commongeoregistry.adapter.metadata.HierarchyType) HierarchyTypePermissionServiceIF(net.geoprism.registry.permission.HierarchyTypePermissionServiceIF) Request(com.runwaysdk.session.Request)

Example 5 with HierarchyTypePermissionServiceIF

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

the class ServerHierarchyType method getForOrganization.

public static List<ServerHierarchyType> getForOrganization(Organization organization) {
    final HierarchyTypePermissionServiceIF service = ServiceFactory.getHierarchyPermissionService();
    final List<ServerHierarchyType> list = new LinkedList<ServerHierarchyType>();
    List<ServerHierarchyType> lHt = ServiceFactory.getMetadataCache().getAllHierarchyTypes();
    // Filter out what they're not allowed to see
    lHt.forEach(ht -> {
        if (service.canWrite(organization.getCode())) {
            list.add(ht);
        }
    });
    return list;
}
Also used : HierarchyTypePermissionServiceIF(net.geoprism.registry.permission.HierarchyTypePermissionServiceIF) LinkedList(java.util.LinkedList)

Aggregations

HierarchyTypePermissionServiceIF (net.geoprism.registry.permission.HierarchyTypePermissionServiceIF)6 JsonArray (com.google.gson.JsonArray)5 JsonObject (com.google.gson.JsonObject)5 Request (com.runwaysdk.session.Request)5 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)5 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)4 GeoObjectTypePermissionServiceIF (net.geoprism.registry.permission.GeoObjectTypePermissionServiceIF)3 RequestType (com.runwaysdk.session.RequestType)2 Set (java.util.Set)2 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)2 GeoObjectRelationshipPermissionServiceIF (net.geoprism.registry.permission.GeoObjectRelationshipPermissionServiceIF)2 RolePermissionService (net.geoprism.registry.permission.RolePermissionService)2 ServiceFactory (net.geoprism.registry.service.ServiceFactory)2 GeoObjectType (org.commongeoregistry.adapter.metadata.GeoObjectType)2 JsonElement (com.google.gson.JsonElement)1 Session (com.runwaysdk.session.Session)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1