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);
}
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);
}
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()]);
}
Aggregations