Search in sources :

Example 21 with GeoObjectType

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;
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType)

Example 22 with GeoObjectType

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();
}
Also used : Universal(com.runwaysdk.system.gis.geo.Universal) ServerGeoObjectTypeConverter(net.geoprism.registry.conversion.ServerGeoObjectTypeConverter) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType)

Example 23 with GeoObjectType

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;
}
Also used : NoChildForLeafGeoObjectType(net.geoprism.registry.NoChildForLeafGeoObjectType) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) LinkedList(java.util.LinkedList) HierarchyNode(org.commongeoregistry.adapter.metadata.HierarchyNode)

Example 24 with GeoObjectType

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);
        }
    }
}
Also used : NoChildForLeafGeoObjectType(net.geoprism.registry.NoChildForLeafGeoObjectType) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) GeoObjectTypePermissionServiceIF(net.geoprism.registry.permission.GeoObjectTypePermissionServiceIF) HierarchyNode(org.commongeoregistry.adapter.metadata.HierarchyNode)

Example 25 with GeoObjectType

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;
}
Also used : JsonArray(com.google.gson.JsonArray) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) HierarchyType(org.commongeoregistry.adapter.metadata.HierarchyType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) JsonObject(com.google.gson.JsonObject) CustomSerializer(org.commongeoregistry.adapter.metadata.CustomSerializer) OrganizationDTO(org.commongeoregistry.adapter.metadata.OrganizationDTO) HierarchyNode(org.commongeoregistry.adapter.metadata.HierarchyNode) Request(com.runwaysdk.session.Request) OAuthClientRequest(org.apache.oltu.oauth2.client.request.OAuthClientRequest)

Aggregations

GeoObjectType (org.commongeoregistry.adapter.metadata.GeoObjectType)33 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)23 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)13 JsonArray (com.google.gson.JsonArray)10 JsonObject (com.google.gson.JsonObject)10 Request (com.runwaysdk.session.Request)10 LinkedList (java.util.LinkedList)7 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)6 Test (org.junit.Test)6 ServerGeoObjectTypeConverter (net.geoprism.registry.conversion.ServerGeoObjectTypeConverter)4 HierarchyNode (org.commongeoregistry.adapter.metadata.HierarchyNode)4 HierarchyType (org.commongeoregistry.adapter.metadata.HierarchyType)4 Endpoint (com.runwaysdk.mvc.Endpoint)3 RestBodyResponse (com.runwaysdk.mvc.RestBodyResponse)3 List (java.util.List)3 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)3 MdAttributeDAOIF (com.runwaysdk.dataaccess.MdAttributeDAOIF)2 Universal (com.runwaysdk.system.gis.geo.Universal)2 SimpleDateFormat (java.text.SimpleDateFormat)2 HashMap (java.util.HashMap)2