Search in sources :

Example 1 with ChildTreeNode

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;
}
Also used : GeoObjectRelationshipPermissionServiceIF(net.geoprism.registry.permission.GeoObjectRelationshipPermissionServiceIF) HierarchyType(org.commongeoregistry.adapter.metadata.HierarchyType) GeoObjectPermissionServiceIF(net.geoprism.registry.permission.GeoObjectPermissionServiceIF) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) ChildTreeNode(org.commongeoregistry.adapter.dataaccess.ChildTreeNode)

Example 2 with ChildTreeNode

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.");
        }
    }
}
Also used : ChildTreeNode(org.commongeoregistry.adapter.dataaccess.ChildTreeNode)

Example 3 with ChildTreeNode

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());
}
Also used : ArrayList(java.util.ArrayList) ChildTreeNode(org.commongeoregistry.adapter.dataaccess.ChildTreeNode) TestGeoObjectInfo(net.geoprism.registry.test.TestGeoObjectInfo) Test(org.junit.Test)

Example 4 with ChildTreeNode

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);
}
Also used : ParentTreeNode(org.commongeoregistry.adapter.dataaccess.ParentTreeNode) ChildTreeNode(org.commongeoregistry.adapter.dataaccess.ChildTreeNode) TestGeoObjectInfo(net.geoprism.registry.test.TestGeoObjectInfo) Test(org.junit.Test)

Example 5 with ChildTreeNode

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);
}
Also used : ParentTreeNode(org.commongeoregistry.adapter.dataaccess.ParentTreeNode) ChildTreeNode(org.commongeoregistry.adapter.dataaccess.ChildTreeNode) TestGeoObjectInfo(net.geoprism.registry.test.TestGeoObjectInfo) Test(org.junit.Test)

Aggregations

ChildTreeNode (org.commongeoregistry.adapter.dataaccess.ChildTreeNode)7 Test (org.junit.Test)5 TestGeoObjectInfo (net.geoprism.registry.test.TestGeoObjectInfo)4 ArrayList (java.util.ArrayList)2 ParentTreeNode (org.commongeoregistry.adapter.dataaccess.ParentTreeNode)2 GeoObjectPermissionServiceIF (net.geoprism.registry.permission.GeoObjectPermissionServiceIF)1 GeoObjectRelationshipPermissionServiceIF (net.geoprism.registry.permission.GeoObjectRelationshipPermissionServiceIF)1 TestUserInfo (net.geoprism.registry.test.TestUserInfo)1 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)1 HierarchyType (org.commongeoregistry.adapter.metadata.HierarchyType)1