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