use of org.commongeoregistry.adapter.metadata.GeoObjectType in project geoprism-registry by terraframe.
the class GeoObjectTypeService method getGeoObjectTypes.
/**
* Returns the {@link GeoObjectType}s with the given codes or all
* {@link GeoObjectType}s if no codes are provided.
*
* @param codes
* codes of the {@link GeoObjectType}s.
* @param hierarchies
* @param context
* @return the {@link GeoObjectType}s with the given codes or all
* {@link GeoObjectType}s if no codes are provided.
*/
public List<GeoObjectType> getGeoObjectTypes(String[] codes, String[] hierarchies, PermissionContext context) {
List<GeoObjectType> gots;
if (codes == null || codes.length == 0) {
gots = adapter.getMetadataCache().getAllGeoObjectTypes();
} else {
gots = new ArrayList<GeoObjectType>(codes.length);
for (int i = 0; i < codes.length; ++i) {
Optional<GeoObjectType> optional = adapter.getMetadataCache().getGeoObjectType(codes[i]);
if (optional.isPresent()) {
gots.add(optional.get());
} else {
net.geoprism.registry.DataNotFoundException ex = new net.geoprism.registry.DataNotFoundException();
ex.setTypeLabel(GeoObjectTypeMetadata.sGetClassDisplayLabel());
ex.setDataIdentifier(codes[i]);
ex.setAttributeLabel(GeoObjectTypeMetadata.getAttributeDisplayLabel(DefaultAttribute.CODE.getName()));
throw ex;
}
}
}
Iterator<GeoObjectType> it = gots.iterator();
while (it.hasNext()) {
GeoObjectType got = it.next();
ServerGeoObjectType serverGot = ServerGeoObjectType.get(got);
// Filter ones that they can't see due to permissions
if (context.equals(PermissionContext.READ)) {
if (!ServiceFactory.getGeoObjectTypePermissionService().canRead(serverGot.getOrganization().getCode(), serverGot, serverGot.getIsPrivate())) {
it.remove();
// If we don't have continue here, then it could invoke it.remove twice which throws an error.
continue;
}
} else {
if (!ServiceFactory.getGeoObjectTypePermissionService().canWrite(serverGot.getOrganization().getCode(), serverGot, serverGot.getIsPrivate())) {
it.remove();
// If we don't have continue here, then it could invoke it.remove twice which throws an error.
continue;
}
}
if (hierarchies != null && hierarchies.length > 0) {
List<ServerHierarchyType> hts = serverGot.getHierarchies();
boolean contains = false;
OuterLoop: for (ServerHierarchyType ht : hts) {
for (String hierarchy : hierarchies) {
if (ht.getCode().equals(hierarchy)) {
contains = true;
break OuterLoop;
}
}
}
if (!contains) {
it.remove();
continue;
}
}
}
return gots;
}
use of org.commongeoregistry.adapter.metadata.GeoObjectType in project geoprism-registry by terraframe.
the class ServerGeoObjectType method update.
public void update(GeoObjectType geoObjectTypeNew) {
GeoObjectType geoObjectTypeModified = this.type.copy(geoObjectTypeNew);
Universal universal = updateGeoObjectType(geoObjectTypeModified);
ServerGeoObjectType geoObjectTypeModifiedApplied = new ServerGeoObjectTypeConverter().build(universal);
// If this did not error out then add to the cache
ServiceFactory.getMetadataCache().refreshGeoObjectType(geoObjectTypeModifiedApplied);
// isPrivate). We should refresh them as well.
if (geoObjectTypeModifiedApplied.getIsAbstract()) {
List<ServerGeoObjectType> subtypes = geoObjectTypeModifiedApplied.getSubtypes();
for (ServerGeoObjectType subtype : subtypes) {
ServerGeoObjectType refreshedSubtype = new ServerGeoObjectTypeConverter().build(subtype.getUniversal());
ServiceFactory.getMetadataCache().refreshGeoObjectType(refreshedSubtype);
}
}
this.type = geoObjectTypeModifiedApplied.getType();
this.universal = geoObjectTypeModifiedApplied.getUniversal();
this.mdBusiness = geoObjectTypeModifiedApplied.getMdBusiness();
}
use of org.commongeoregistry.adapter.metadata.GeoObjectType in project geoprism-registry by terraframe.
the class ServerHierarchyType method getRootGeoObjectTypes.
public List<HierarchyNode> getRootGeoObjectTypes(boolean includePrivateTypes) {
List<HierarchyNode> rootGeoObjectTypes = new LinkedList<HierarchyNode>();
List<ServerGeoObjectType> types = this.getDirectRootNodes();
for (ServerGeoObjectType geoObjectType : types) {
ServerHierarchyType inheritedHierarchy = geoObjectType.getInheritedHierarchy(this.hierarchicalRelationship);
if (inheritedHierarchy != null) {
List<GeoObjectType> ancestors = geoObjectType.getTypeAncestors(inheritedHierarchy, true);
Collections.reverse(ancestors);
HierarchyNode child = new HierarchyNode(geoObjectType.getType(), null);
HierarchyNode root = child;
for (GeoObjectType ancestor : ancestors) {
HierarchyNode cNode = new HierarchyNode(ancestor, inheritedHierarchy.getCode());
cNode.addChild(root);
root = cNode;
}
buildHierarchy(child, geoObjectType);
rootGeoObjectTypes.add(root);
} else {
HierarchyNode node = new HierarchyNode(geoObjectType.getType());
node = buildHierarchy(node, geoObjectType);
rootGeoObjectTypes.add(node);
}
}
if (!includePrivateTypes) {
Iterator<HierarchyNode> rootIt = rootGeoObjectTypes.iterator();
while (rootIt.hasNext()) {
HierarchyNode hn = rootIt.next();
if (isRootPrivate(hn)) {
rootIt.remove();
} else {
this.filterOutPrivateNodes(hn);
}
}
}
return rootGeoObjectTypes;
}
use of org.commongeoregistry.adapter.metadata.GeoObjectType in project geoprism-registry by terraframe.
the class ServerHierarchyType method filterOutPrivateNodes.
private void filterOutPrivateNodes(HierarchyNode parent) {
final GeoObjectTypePermissionServiceIF typePermServ = ServiceFactory.getGeoObjectTypePermissionService();
List<HierarchyNode> list = parent.getChildren();
Iterator<HierarchyNode> it = list.iterator();
while (it.hasNext()) {
HierarchyNode child = it.next();
GeoObjectType got = child.getGeoObjectType();
if (!typePermServ.canRead(got.getOrganizationCode(), ServerGeoObjectType.get(got), got.getIsPrivate())) {
it.remove();
} else {
this.filterOutPrivateNodes(child);
}
}
}
use of org.commongeoregistry.adapter.metadata.GeoObjectType in project geoprism-registry by terraframe.
the class RegistryService method initHierarchyManager.
@Request(RequestType.SESSION)
public JsonObject initHierarchyManager(String sessionId) {
GeoObjectType[] gots = this.getGeoObjectTypes(sessionId, null, null, PermissionContext.READ);
HierarchyType[] hts = ServiceFactory.getHierarchyService().getHierarchyTypes(sessionId, null, PermissionContext.READ);
OrganizationDTO[] orgDtos = RegistryService.getInstance().getOrganizations(sessionId, null);
CustomSerializer serializer = this.serializer(sessionId);
JsonArray types = new JsonArray();
for (GeoObjectType got : gots) {
JsonObject joGot = got.toJSON(serializer);
JsonArray relatedHiers = new JsonArray();
for (HierarchyType ht : hts) {
List<HierarchyNode> hns = ht.getRootGeoObjectTypes();
for (HierarchyNode hn : hns) {
if (hn.hierarchyHasGeoObjectType(got.getCode(), true)) {
relatedHiers.add(ht.getCode());
}
}
}
joGot.add("relatedHierarchies", relatedHiers);
types.add(joGot);
}
JsonArray hierarchies = new JsonArray();
for (HierarchyType ht : hts) {
hierarchies.add(ht.toJSON(serializer));
}
JsonArray organizations = new JsonArray();
for (OrganizationDTO dto : orgDtos) {
organizations.add(dto.toJSON(serializer));
}
JsonObject response = new JsonObject();
response.add("types", types);
response.add("hierarchies", hierarchies);
response.add("organizations", organizations);
response.add("locales", this.getLocales(sessionId));
return response;
}
Aggregations