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