use of org.commongeoregistry.adapter.dataaccess.ChildTreeNode in project geoprism-registry by terraframe.
the class ServerChildTreeNode method toNode.
public ChildTreeNode toNode(boolean enforcePermissions) {
final GeoObjectRelationshipPermissionServiceIF relPermServ = ServiceFactory.getGeoObjectRelationshipPermissionService();
final GeoObjectPermissionServiceIF goPermServ = ServiceFactory.getGeoObjectPermissionService();
GeoObject go = this.getGeoObject().toGeoObject(this.getStartDate());
HierarchyType ht = this.getHierarchyType() != null ? this.getHierarchyType().toHierarchyType() : null;
ChildTreeNode node = new ChildTreeNode(go, ht);
String orgCode = go.getType().getOrganizationCode();
ServerGeoObjectType type = ServerGeoObjectType.get(go.getType());
for (ServerChildTreeNode child : this.children) {
if (!enforcePermissions || (relPermServ.canViewChild(orgCode, type, child.getGeoObject().getType()) && goPermServ.canRead(orgCode, type))) {
node.addChild(child.toNode(enforcePermissions));
}
}
return node;
}
use of org.commongeoregistry.adapter.dataaccess.ChildTreeNode in project geoprism-registry by terraframe.
the class TestGeoObjectInfo method childTreeNodeAssert.
public void childTreeNodeAssert(ChildTreeNode tn, List<TestGeoObjectInfo> expectedChildren) {
this.assertEquals(tn.getGeoObject());
// TODO : HierarchyType?
List<ChildTreeNode> tnChildren = tn.getChildren();
Assert.assertEquals(expectedChildren.size(), tnChildren.size());
for (TestGeoObjectInfo expectedChild : expectedChildren) {
ChildTreeNode tnChild = null;
for (ChildTreeNode compareChild : tnChildren) {
if (expectedChild.getCode().equals(compareChild.getGeoObject().getCode())) {
tnChild = compareChild;
}
}
if (tnChild == null) {
Assert.fail("The ChildTreeNode did not contain a child that we expected to find.");
}
}
}
use of org.commongeoregistry.adapter.dataaccess.ChildTreeNode in project geoprism-registry by terraframe.
the class GeoObjectRelationshipServiceTest method testGetChildGeoObjects.
@Test
public void testGetChildGeoObjects() {
final String parentCode = FastTestDataset.CAMBODIA.getCode();
final String parentTypeCode = FastTestDataset.CAMBODIA.getGeoObjectType().getCode();
final String[] childrenTypes = new String[] { FastTestDataset.PROVINCE.getCode() };
final List<TestGeoObjectInfo> expectedChildren = new ArrayList<TestGeoObjectInfo>();
expectedChildren.add(FastTestDataset.PROV_CENTRAL);
expectedChildren.add(FastTestDataset.PROV_CENTRAL);
expectedChildren.add(FastTestDataset.PROV_WESTERN);
// Recursive
ChildTreeNode tn = testData.adapter.getChildGeoObjects(parentCode, parentTypeCode, TestDataSet.DEFAULT_OVER_TIME_DATE, childrenTypes, true);
FastTestDataset.CAMBODIA.childTreeNodeAssert(tn, expectedChildren);
Assert.assertEquals(tn.toJSON().toString(), ChildTreeNode.fromJSON(tn.toJSON().toString(), testData.adapter).toJSON().toString());
// Not recursive
ChildTreeNode tn2 = testData.adapter.getChildGeoObjects(parentCode, parentTypeCode, TestDataSet.DEFAULT_OVER_TIME_DATE, childrenTypes, false);
FastTestDataset.CAMBODIA.childTreeNodeAssert(tn2, expectedChildren);
Assert.assertEquals(tn2.toJSON().toString(), ChildTreeNode.fromJSON(tn2.toJSON().toString(), testData.adapter).toJSON().toString());
// Null date
ChildTreeNode tn3 = testData.adapter.getChildGeoObjects(parentCode, parentTypeCode, null, childrenTypes, false);
FastTestDataset.CAMBODIA.childTreeNodeAssert(tn3, expectedChildren);
Assert.assertEquals(tn3.toJSON().toString(), ChildTreeNode.fromJSON(tn3.toJSON().toString(), testData.adapter).toJSON().toString());
}
use of org.commongeoregistry.adapter.dataaccess.ChildTreeNode in project geoprism-registry by terraframe.
the class GeoObjectRelationshipServiceTest method testAddChild.
@Test
public void testAddChild() {
String startDate = GeoRegistryUtil.formatDate(FastTestDataset.DEFAULT_OVER_TIME_DATE, false);
String endDate = GeoRegistryUtil.formatDate(FastTestDataset.DEFAULT_END_TIME_DATE, false);
TestGeoObjectInfo testAddChild = testData.newTestGeoObjectInfo("TEST_ADD_CHILD", FastTestDataset.PROVINCE);
testAddChild.apply();
ParentTreeNode ptnTestState = testData.adapter.addChild(FastTestDataset.CAMBODIA.getCode(), FastTestDataset.CAMBODIA.getGeoObjectType().getCode(), testAddChild.getCode(), testAddChild.getGeoObjectType().getCode(), FastTestDataset.HIER_ADMIN.getCode(), startDate, endDate);
boolean found = false;
for (ParentTreeNode ptnCAMBODIA : ptnTestState.getParents()) {
if (ptnCAMBODIA.getGeoObject().getCode().equals(FastTestDataset.CAMBODIA.getCode())) {
found = true;
break;
}
}
Assert.assertTrue("Did not find our test object in the list of returned children", found);
testAddChild.assertEquals(ptnTestState.getGeoObject());
ChildTreeNode ctnCAMBODIA2 = testData.adapter.getChildGeoObjects(FastTestDataset.CAMBODIA.getCode(), FastTestDataset.CAMBODIA.getGeoObjectType().getCode(), TestDataSet.DEFAULT_OVER_TIME_DATE, new String[] { FastTestDataset.PROVINCE.getCode() }, false);
found = false;
for (ChildTreeNode ctnState : ctnCAMBODIA2.getChildren()) {
if (ctnState.getGeoObject().getCode().equals(testAddChild.getCode())) {
found = true;
break;
}
}
Assert.assertTrue("Did not find our test object in the list of returned children", found);
}
use of org.commongeoregistry.adapter.dataaccess.ChildTreeNode in project geoprism-registry by terraframe.
the class GeoObjectRelationshipServiceTest method testInsertChild.
@Test
public void testInsertChild() {
String startDate = GeoRegistryUtil.formatDate(FastTestDataset.DEFAULT_OVER_TIME_DATE, false);
String endDate = GeoRegistryUtil.formatDate(FastTestDataset.DEFAULT_END_TIME_DATE, false);
TestGeoObjectInfo testAddChild = testData.newTestGeoObjectInfo("TEST_ADD_CHILD", FastTestDataset.PROVINCE);
testAddChild.apply();
ParentTreeNode ptnTestState = testData.adapter.addChild(FastTestDataset.CAMBODIA.getCode(), FastTestDataset.CAMBODIA.getGeoObjectType().getCode(), testAddChild.getCode(), testAddChild.getGeoObjectType().getCode(), FastTestDataset.HIER_ADMIN.getCode(), startDate, endDate);
boolean found = false;
for (ParentTreeNode ptnCAMBODIA : ptnTestState.getParents()) {
if (ptnCAMBODIA.getGeoObject().getCode().equals(FastTestDataset.CAMBODIA.getCode())) {
found = true;
break;
}
}
Assert.assertTrue("Did not find our test object in the list of returned children", found);
testAddChild.assertEquals(ptnTestState.getGeoObject());
ChildTreeNode ctnCAMBODIA2 = testData.adapter.getChildGeoObjects(FastTestDataset.CAMBODIA.getCode(), FastTestDataset.CAMBODIA.getGeoObjectType().getCode(), TestDataSet.DEFAULT_OVER_TIME_DATE, new String[] { FastTestDataset.PROVINCE.getCode() }, false);
found = false;
for (ChildTreeNode ctnState : ctnCAMBODIA2.getChildren()) {
if (ctnState.getGeoObject().getCode().equals(testAddChild.getCode())) {
found = true;
break;
}
}
Assert.assertTrue("Did not find our test object in the list of returned children", found);
}
Aggregations