use of org.commongeoregistry.adapter.metadata.HierarchyType in project geoprism-registry by terraframe.
the class RegistryController method createHierarchyType.
/**
* Create the {@link HierarchyType} from the given JSON.
*
* @param sessionId
* @param htJSON
* JSON of the {@link HierarchyType} to be created.
*/
@Endpoint(method = ServletMethod.POST, error = ErrorSerialization.JSON, url = RegistryUrls.HIERARCHY_TYPE_CREATE)
public ResponseIF createHierarchyType(ClientRequestIF request, @RequestParamter(name = "htJSON", required = true) String htJSON) {
HierarchyType hierarchyType = ServiceFactory.getHierarchyService().createHierarchyType(request.getSessionId(), htJSON);
CustomSerializer serializer = this.registryService.serializer(request.getSessionId());
return new RestBodyResponse(hierarchyType.toJSON(serializer));
}
use of org.commongeoregistry.adapter.metadata.HierarchyType in project geoprism-registry by terraframe.
the class RegistryController method removeFromHierarchy.
/**
* Removes the {@link GeoObjectType} with the given child code from the parent
* {@link GeoObjectType} with the given code for the given
* {@link HierarchyType} code.
*
* @param sessionId
* @param hierarchyCode
* code of the {@link HierarchyType} the child is being added to.
* @param parentGeoObjectTypeCode
* parent {@link GeoObjectType}.
* @param childGeoObjectTypeCode
* child {@link GeoObjectType}.
*/
@Endpoint(method = ServletMethod.GET, error = ErrorSerialization.JSON, url = RegistryUrls.HIERARCHY_TYPE_REMOVE)
public ResponseIF removeFromHierarchy(ClientRequestIF request, @RequestParamter(name = "hierarchyCode", required = true) String hierarchyCode, @RequestParamter(name = "parentGeoObjectTypeCode", required = true) String parentGeoObjectTypeCode, @RequestParamter(name = "childGeoObjectTypeCode", required = true) String childGeoObjectTypeCode) {
HierarchyType ht = ServiceFactory.getHierarchyService().removeFromHierarchy(request.getSessionId(), hierarchyCode, parentGeoObjectTypeCode, childGeoObjectTypeCode, true);
CustomSerializer serializer = this.registryService.serializer(request.getSessionId());
return new RestBodyResponse(ht.toJSON(serializer));
}
use of org.commongeoregistry.adapter.metadata.HierarchyType in project geoprism-registry by terraframe.
the class RegistryController method addToHierarchy.
/**
* Adds the {@link GeoObjectType} with the given child code to the parent
* {@link GeoObjectType} with the given code for the given
* {@link HierarchyType} code.
*
* @param sessionId
* @param hierarchyCode
* code of the {@link HierarchyType} the child is being added to.
* @param parentGeoObjectTypeCode
* parent {@link GeoObjectType}.
* @param childGeoObjectTypeCode
* child {@link GeoObjectType}.
*/
@Endpoint(method = ServletMethod.POST, error = ErrorSerialization.JSON, url = RegistryUrls.HIERARCHY_TYPE_ADD)
public ResponseIF addToHierarchy(ClientRequestIF request, @RequestParamter(name = "hierarchyCode", required = true) String hierarchyCode, @RequestParamter(name = "parentGeoObjectTypeCode", required = true) String parentGeoObjectTypeCode, @RequestParamter(name = "childGeoObjectTypeCode", required = true) String childGeoObjectTypeCode) {
HierarchyType ht = ServiceFactory.getHierarchyService().addToHierarchy(request.getSessionId(), hierarchyCode, parentGeoObjectTypeCode, childGeoObjectTypeCode);
CustomSerializer serializer = this.registryService.serializer(request.getSessionId());
return new RestBodyResponse(ht.toJSON(serializer));
}
use of org.commongeoregistry.adapter.metadata.HierarchyType 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 org.commongeoregistry.adapter.metadata.HierarchyType 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