Search in sources :

Example 1 with PermissionContext

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

the class RegistryController method getGeoObjectTypes.

/**
 * Returns an array of {@link GeoOjectType} objects that define the given list
 * of types.
 *
 * @pre @post
 *
 * @param types
 *          A serialized json array of GeoObjectType codes. If blank then all
 *          GeoObjectType objects are returned.
 * @param hierarchies
 *          A serialized json array of HierarchyType codes. If blank then
 *          GeoObjectTypes belonging to all hierarchies are returned.
 *
 * @returns @throws
 */
@Endpoint(method = ServletMethod.GET, error = ErrorSerialization.JSON, url = RegistryUrls.GEO_OBJECT_TYPE_GET_ALL)
public ResponseIF getGeoObjectTypes(ClientRequestIF request, @RequestParamter(name = RegistryUrls.GEO_OBJECT_TYPE_GET_ALL_PARAM_TYPES) String types, @RequestParamter(name = RegistryUrls.GEO_OBJECT_TYPE_GET_ALL_PARAM_HIERARCHIES) String hierarchies, @RequestParamter(name = "context") String context) {
    String[] aTypes = null;
    if (types != null) {
        JSONArray jaTypes = new JSONArray(types);
        aTypes = new String[jaTypes.length()];
        for (int i = 0; i < jaTypes.length(); i++) {
            aTypes[i] = jaTypes.getString(i);
        }
    }
    String[] aHierarchies = null;
    if (hierarchies != null) {
        JSONArray jaHierarchies = new JSONArray(hierarchies);
        aHierarchies = new String[jaHierarchies.length()];
        for (int i = 0; i < jaHierarchies.length(); i++) {
            aHierarchies[i] = jaHierarchies.getString(i);
        }
    }
    PermissionContext pContext = PermissionContext.get(context);
    GeoObjectType[] gots = this.registryService.getGeoObjectTypes(request.getSessionId(), aTypes, aHierarchies, pContext);
    JsonArray jarray = new JsonArray();
    for (int i = 0; i < gots.length; ++i) {
        JsonObject jo = this.registryService.serialize(request.getSessionId(), gots[i]);
        jarray.add(jo);
    }
    return new RestBodyResponse(jarray);
}
Also used : JsonArray(com.google.gson.JsonArray) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) JSONArray(org.json.JSONArray) PermissionContext(net.geoprism.registry.permission.PermissionContext) JsonObject(com.google.gson.JsonObject) RestBodyResponse(com.runwaysdk.mvc.RestBodyResponse) Endpoint(com.runwaysdk.mvc.Endpoint) Endpoint(com.runwaysdk.mvc.Endpoint)

Example 2 with PermissionContext

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

the class RegistryController method getHierarchyTypes.

/**
 * Returns an array of {@link HierarchyType} that define the given list of
 * types. If no types are provided then all will be returned.
 *
 * @param types
 *          A serialized json array of HierarchyType codes that will be
 *          retrieved.
 */
@Endpoint(method = ServletMethod.GET, error = ErrorSerialization.JSON, url = RegistryUrls.HIERARCHY_TYPE_GET_ALL)
public ResponseIF getHierarchyTypes(ClientRequestIF request, @RequestParamter(name = "types") String types, @RequestParamter(name = "context") String context) {
    String[] aTypes = null;
    if (types != null) {
        JSONArray jaTypes = new JSONArray(types);
        aTypes = new String[jaTypes.length()];
        for (int i = 0; i < jaTypes.length(); i++) {
            aTypes[i] = jaTypes.getString(i);
        }
    }
    PermissionContext pContext = PermissionContext.get(context);
    HierarchyType[] hts = ServiceFactory.getHierarchyService().getHierarchyTypes(request.getSessionId(), aTypes, pContext);
    CustomSerializer serializer = this.registryService.serializer(request.getSessionId());
    JsonArray jarray = new JsonArray();
    for (int i = 0; i < hts.length; ++i) {
        jarray.add(hts[i].toJSON(serializer));
    }
    return new RestBodyResponse(jarray);
}
Also used : JsonArray(com.google.gson.JsonArray) HierarchyType(org.commongeoregistry.adapter.metadata.HierarchyType) JSONArray(org.json.JSONArray) PermissionContext(net.geoprism.registry.permission.PermissionContext) CustomSerializer(org.commongeoregistry.adapter.metadata.CustomSerializer) RestBodyResponse(com.runwaysdk.mvc.RestBodyResponse) Endpoint(com.runwaysdk.mvc.Endpoint) Endpoint(com.runwaysdk.mvc.Endpoint)

Example 3 with PermissionContext

use of net.geoprism.registry.permission.PermissionContext 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)

Aggregations

JsonArray (com.google.gson.JsonArray)3 PermissionContext (net.geoprism.registry.permission.PermissionContext)3 JsonObject (com.google.gson.JsonObject)2 Endpoint (com.runwaysdk.mvc.Endpoint)2 RestBodyResponse (com.runwaysdk.mvc.RestBodyResponse)2 GeoObjectType (org.commongeoregistry.adapter.metadata.GeoObjectType)2 HierarchyType (org.commongeoregistry.adapter.metadata.HierarchyType)2 JSONArray (org.json.JSONArray)2 Request (com.runwaysdk.session.Request)1 RequestType (com.runwaysdk.session.RequestType)1 Session (com.runwaysdk.session.Session)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 GeoRegistryUtil (net.geoprism.registry.GeoRegistryUtil)1 Organization (net.geoprism.registry.Organization)1 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)1 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)1