Search in sources :

Example 1 with HierarchyNode

use of org.commongeoregistry.adapter.metadata.HierarchyNode in project geoprism-registry by terraframe.

the class GeoObjectTypeRelationshipServiceTest method addChild.

private void addChild(TestRegistryAdapterClient adapter, TestGeoObjectTypeInfo parent, TestGeoObjectTypeInfo child) {
    String parentCode = (parent == null) ? Universal.ROOT : parent.getCode();
    HierarchyType ht = adapter.addToHierarchy(TEST_HT.getCode(), parentCode, child.getCode());
    List<HierarchyNode> rootGots = ht.getRootGeoObjectTypes();
    for (HierarchyNode node : rootGots) {
        if (node.getGeoObjectType().getCode().equals(child.getCode())) {
            return;
        }
    }
    Assert.fail("We did not find the child we just added.");
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) HierarchyType(org.commongeoregistry.adapter.metadata.HierarchyType) HierarchyNode(org.commongeoregistry.adapter.metadata.HierarchyNode)

Example 2 with HierarchyNode

use of org.commongeoregistry.adapter.metadata.HierarchyNode in project geoprism-registry by terraframe.

the class InheritedHierarchyAnnotationTest method testSetInheritedHierarchy.

@Test
public void testSetInheritedHierarchy() {
    FastTestDataset.runAsUser(FastTestDataset.USER_CGOV_RA, (request, adapter) -> {
        HierarchyService service = new HierarchyService();
        try {
            HierarchyType ht = service.setInheritedHierarchy(request.getSessionId(), TEST_HT.getCode(), FastTestDataset.HIER_ADMIN.getCode(), FastTestDataset.PROVINCE.getCode());
            List<HierarchyNode> nodes = ht.getRootGeoObjectTypes();
            HierarchyNode node = nodes.get(0);
            GeoObjectType root = node.getGeoObjectType();
            Assert.assertEquals(FastTestDataset.COUNTRY.getCode(), root.getCode());
            Assert.assertEquals(FastTestDataset.HIER_ADMIN.getCode(), node.getInheritedHierarchyCode());
        } finally {
            HierarchyType ht = service.removeInheritedHierarchy(request.getSessionId(), TEST_HT.getCode(), FastTestDataset.PROVINCE.getCode());
            List<HierarchyNode> nodes = ht.getRootGeoObjectTypes();
            HierarchyNode node = nodes.get(0);
            GeoObjectType root = node.getGeoObjectType();
            Assert.assertEquals(FastTestDataset.PROVINCE.getCode(), root.getCode());
            Assert.assertNull(node.getInheritedHierarchyCode());
        }
    });
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) HierarchyType(org.commongeoregistry.adapter.metadata.HierarchyType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) HierarchyNode(org.commongeoregistry.adapter.metadata.HierarchyNode) Test(org.junit.Test)

Example 3 with HierarchyNode

use of org.commongeoregistry.adapter.metadata.HierarchyNode in project geoprism-registry by terraframe.

the class GeoObjectTypeMetadata method hasPublicChildren.

public boolean hasPublicChildren() {
    ServerGeoObjectType type = this.getServerType();
    GeoObjectType typeDTO = type.getType();
    List<ServerHierarchyType> hierarchyTypes = ServiceFactory.getMetadataCache().getAllHierarchyTypes();
    for (ServerHierarchyType ht : hierarchyTypes) {
        List<HierarchyNode> roots = ht.getRootGeoObjectTypes();
        for (HierarchyNode root : roots) {
            HierarchyNode node = root.findChild(typeDTO);
            if (node != null) {
                Iterator<HierarchyNode> it = node.getDescendantsIterator();
                while (it.hasNext()) {
                    HierarchyNode child = it.next();
                    if (!child.getGeoObjectType().getIsPrivate()) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) HierarchyNode(org.commongeoregistry.adapter.metadata.HierarchyNode)

Example 4 with HierarchyNode

use of org.commongeoregistry.adapter.metadata.HierarchyNode 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 5 with HierarchyNode

use of org.commongeoregistry.adapter.metadata.HierarchyNode in project geoprism-registry by terraframe.

the class ServerHierarchyType method buildHierarchy.

private HierarchyNode buildHierarchy(HierarchyNode parentNode, ServerGeoObjectType parent) {
    List<ServerGeoObjectType> children = this.getChildren(parent);
    for (ServerGeoObjectType child : children) {
        HierarchyNode node = new HierarchyNode(child.getType());
        node = buildHierarchy(node, child);
        parentNode.addChild(node);
    }
    return parentNode;
}
Also used : HierarchyNode(org.commongeoregistry.adapter.metadata.HierarchyNode)

Aggregations

HierarchyNode (org.commongeoregistry.adapter.metadata.HierarchyNode)9 GeoObjectType (org.commongeoregistry.adapter.metadata.GeoObjectType)5 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)4 HierarchyType (org.commongeoregistry.adapter.metadata.HierarchyType)4 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)3 Request (com.runwaysdk.session.Request)2 NoChildForLeafGeoObjectType (net.geoprism.registry.NoChildForLeafGeoObjectType)2 Test (org.junit.Test)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Organization (net.geoprism.registry.Organization)1 ClassificationTypeTest (net.geoprism.registry.classification.ClassificationTypeTest)1 ServerElement (net.geoprism.registry.model.ServerElement)1 GeoObjectTypePermissionServiceIF (net.geoprism.registry.permission.GeoObjectTypePermissionServiceIF)1 OAuthClientRequest (org.apache.oltu.oauth2.client.request.OAuthClientRequest)1 Term (org.commongeoregistry.adapter.Term)1