Search in sources :

Example 6 with ParentTreeNode

use of org.commongeoregistry.adapter.dataaccess.ParentTreeNode in project geoprism-registry by terraframe.

the class RegistryController method addChild.

/**
 * Creates a relationship between @parentUid and @childUid.
 *
 * @pre Both the parent and child have already been persisted / applied
 * @post A relationship will exist between @parent and @child
 *
 * @returns ParentTreeNode The new node which was created with the provided
 *          parent.
 * @param startDate TODO
 * @param endDate TODO
 */
@Endpoint(method = ServletMethod.POST, error = ErrorSerialization.JSON, url = RegistryUrls.GEO_OBJECT_ADD_CHILD)
public ResponseIF addChild(ClientRequestIF request, @RequestParamter(name = RegistryUrls.GEO_OBJECT_ADD_CHILD_PARAM_PARENTCODE, required = true) String parentCode, @RequestParamter(name = RegistryUrls.GEO_OBJECT_ADD_CHILD_PARAM_PARENT_TYPE_CODE, required = true) String parentTypeCode, @RequestParamter(name = RegistryUrls.GEO_OBJECT_ADD_CHILD_PARAM_CHILDCODE, required = true) String childCode, @RequestParamter(name = RegistryUrls.GEO_OBJECT_ADD_CHILD_PARAM_CHILD_TYPE_CODE, required = true) String childTypeCode, @RequestParamter(name = RegistryUrls.GEO_OBJECT_ADD_CHILD_PARAM_HIERARCHY_CODE, required = true) String hierarchyRef, @RequestParamter(name = RegistryUrls.GEO_OBJECT_ADD_CHILD_PARAM_START_DATE) String startDateString, @RequestParamter(name = RegistryUrls.GEO_OBJECT_ADD_CHILD_PARAM_END_DATE) String endDateString) {
    Date startDate = (startDateString != null && startDateString.length() > 0) ? GeoRegistryUtil.parseDate(startDateString, true) : null;
    Date endDate = (endDateString != null && endDateString.length() > 0) ? GeoRegistryUtil.parseDate(endDateString, true) : null;
    ParentTreeNode pn = ServiceFactory.getGeoObjectService().addChild(request.getSessionId(), parentCode, parentTypeCode, childCode, childTypeCode, hierarchyRef, startDate, endDate);
    return new RestBodyResponse(pn.toJSON());
}
Also used : ParentTreeNode(org.commongeoregistry.adapter.dataaccess.ParentTreeNode) RestBodyResponse(com.runwaysdk.mvc.RestBodyResponse) Date(java.util.Date) Endpoint(com.runwaysdk.mvc.Endpoint)

Example 7 with ParentTreeNode

use of org.commongeoregistry.adapter.dataaccess.ParentTreeNode in project geoprism-registry by terraframe.

the class AbstractServerGeoObject method getHierarchiesForGeoObject.

public JsonArray getHierarchiesForGeoObject(Date date) {
    ServerGeoObjectType geoObjectType = this.getType();
    List<ServerHierarchyType> hierarchyTypes = ServiceFactory.getMetadataCache().getAllHierarchyTypes();
    JsonArray hierarchies = new JsonArray();
    Universal root = Universal.getRoot();
    for (ServerHierarchyType sType : hierarchyTypes) {
        if (ServiceFactory.getHierarchyPermissionService().canWrite(sType.getOrganization().getCode())) {
            // Note: Ordered ancestors always includes self
            Collection<?> uniParents = GeoEntityUtil.getOrderedAncestors(root, geoObjectType.getUniversal(), sType.getUniversalType());
            ParentTreeNode ptnAncestors = this.getParentGeoObjects(null, true, date).toNode(true);
            if (uniParents.size() > 1) {
                JsonObject object = new JsonObject();
                object.addProperty("code", sType.getCode());
                object.addProperty("label", sType.getDisplayLabel().getValue());
                JsonArray pArray = new JsonArray();
                for (Object parent : uniParents) {
                    ServerGeoObjectType pType = ServerGeoObjectType.get((Universal) parent);
                    if (!pType.getCode().equals(geoObjectType.getCode())) {
                        JsonObject pObject = new JsonObject();
                        pObject.addProperty("code", pType.getCode());
                        pObject.addProperty("label", pType.getLabel().getValue());
                        List<ParentTreeNode> ptns = ptnAncestors.findParentOfType(pType.getCode());
                        for (ParentTreeNode ptn : ptns) {
                            if (ptn.getHierachyType().getCode().equals(sType.getCode())) {
                                pObject.add("ptn", ptn.toJSON());
                                // TODO Sibling ancestors
                                break;
                            }
                        }
                        pArray.add(pObject);
                    }
                }
                object.add("parents", pArray);
                hierarchies.add(object);
            }
        }
    }
    if (hierarchies.size() == 0) {
        for (ServerHierarchyType hierarchyType : hierarchyTypes) {
            if (ServiceFactory.getHierarchyPermissionService().canWrite(hierarchyType.getOrganization().getCode())) {
                JsonObject object = new JsonObject();
                object.addProperty("code", hierarchyType.getCode());
                object.addProperty("label", hierarchyType.getDisplayLabel().getValue());
                object.add("parents", new JsonArray());
                hierarchies.add(object);
            }
        }
    }
    return hierarchies;
}
Also used : JsonArray(com.google.gson.JsonArray) Universal(com.runwaysdk.system.gis.geo.Universal) ParentTreeNode(org.commongeoregistry.adapter.dataaccess.ParentTreeNode) JsonObject(com.google.gson.JsonObject) JsonObject(com.google.gson.JsonObject)

Example 8 with ParentTreeNode

use of org.commongeoregistry.adapter.dataaccess.ParentTreeNode in project geoprism-registry by terraframe.

the class ShapefileServiceTest method testBadParentSynonymAndResume.

@Test
@Request
public void testBadParentSynonymAndResume() throws Throwable {
    InputStream istream = this.getClass().getResourceAsStream("/cb_2017_us_state_500k.zip.test");
    Assert.assertNotNull(istream);
    ShapefileService service = new ShapefileService();
    GeoObjectImportConfiguration config = this.getTestConfiguration(istream, service, null, ImportStrategy.NEW_AND_UPDATE);
    ServerHierarchyType hierarchyType = ServerHierarchyType.get(USATestData.HIER_ADMIN.getCode());
    config.setHierarchy(hierarchyType);
    config.addParent(new Location(USATestData.COUNTRY.getServerObject(), hierarchyType, new BasicColumnFunction("LSAD"), ParentMatchStrategy.ALL));
    // ImportHistory hist = mockImport(config);
    // Assert.assertTrue(hist.getStatus().get(0).equals(AllJobStatus.FEEDBACK));
    ImportHistory hist = importShapefile(testData.clientRequest.getSessionId(), config.toJSON().toString());
    SchedulerTestUtils.waitUntilStatus(hist.getOid(), AllJobStatus.FEEDBACK);
    hist = ImportHistory.get(hist.getOid());
    Assert.assertEquals(new Long(56), hist.getWorkTotal());
    Assert.assertEquals(new Long(56), hist.getWorkProgress());
    Assert.assertEquals(new Long(0), hist.getImportedRecords());
    Assert.assertEquals(ImportStage.VALIDATION_RESOLVE, hist.getStage().get(0));
    JSONObject page = new JSONObject(new ETLService().getValidationProblems(testData.clientRequest.getSessionId(), hist.getOid(), false, 100, 1).toString());
    JSONArray results = page.getJSONArray("resultSet");
    Assert.assertEquals(1, results.length());
    // Ensure the geo objects were not created
    ServerGeoObjectQuery query = new ServerGeoObjectService().createQuery(USATestData.STATE.getServerObject(), config.getStartDate());
    query.setRestriction(new ServerCodeRestriction("01"));
    Assert.assertNull(query.getSingleResult());
    // Resolve the import problem with a synonym
    GeoObject geoObj = ServiceFactory.getRegistryService().newGeoObjectInstance(testData.clientRequest.getSessionId(), USATestData.COUNTRY.getCode());
    geoObj.setCode("99");
    geoObj.setDisplayLabel(LocalizedValue.DEFAULT_LOCALE, "Test Label99");
    geoObj.setUid(ServiceFactory.getIdService().getUids(1)[0]);
    ServerGeoObjectIF serverGo = new ServerGeoObjectService(new AllowAllGeoObjectPermissionService()).apply(geoObj, TestDataSet.DEFAULT_OVER_TIME_DATE, TestDataSet.DEFAULT_END_TIME_DATE, true, false);
    JSONObject valRes = new JSONObject();
    valRes.put("validationProblemId", results.getJSONObject(0).getString("id"));
    valRes.put("resolution", ValidationResolution.SYNONYM);
    valRes.put("code", serverGo.getCode());
    valRes.put("typeCode", serverGo.getType().getCode());
    valRes.put("label", "00");
    new ETLService().submitValidationProblemResolution(testData.clientRequest.getSessionId(), valRes.toString());
    ValidationProblem vp = ValidationProblem.get(results.getJSONObject(0).getString("id"));
    Assert.assertEquals(ValidationResolution.SYNONYM.name(), vp.getResolution());
    Assert.assertEquals(ParentReferenceProblem.DEFAULT_SEVERITY, vp.getSeverity());
    ImportHistory hist2 = importShapefile(testData.clientRequest.getSessionId(), hist.getConfigJson());
    Assert.assertEquals(hist.getOid(), hist2.getOid());
    SchedulerTestUtils.waitUntilStatus(hist.getOid(), AllJobStatus.SUCCESS);
    hist = ImportHistory.get(hist.getOid());
    Assert.assertEquals(ImportStage.COMPLETE, hist.getStage().get(0));
    Assert.assertEquals(new Long(56), hist.getWorkTotal());
    Assert.assertEquals(new Long(56), hist.getWorkProgress());
    Assert.assertEquals(new Long(56), hist.getImportedRecords());
    String sessionId = testData.clientRequest.getSessionId();
    GeoObject go = ServiceFactory.getRegistryService().getGeoObjectByCode(sessionId, "01", USATestData.STATE.getCode(), TestDataSet.DEFAULT_OVER_TIME_DATE);
    Assert.assertEquals("01", go.getCode());
    ParentTreeNode nodes = ServiceFactory.getRegistryService().getParentGeoObjects(sessionId, go.getCode(), config.getType().getCode(), new String[] { USATestData.COUNTRY.getCode() }, false, TestDataSet.DEFAULT_OVER_TIME_DATE);
    List<ParentTreeNode> parents = nodes.getParents();
    Assert.assertEquals(1, parents.size());
    JSONObject page2 = new JSONObject(new ETLService().getValidationProblems(testData.clientRequest.getSessionId(), hist.getOid(), false, 100, 1).toString());
    JSONArray results2 = page2.getJSONArray("resultSet");
    Assert.assertEquals(0, results2.length());
    Assert.assertEquals(0, page2.getInt("count"));
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) InputStream(java.io.InputStream) BasicColumnFunction(net.geoprism.data.importer.BasicColumnFunction) JSONArray(org.json.JSONArray) ShapefileService(net.geoprism.registry.service.ShapefileService) ServerGeoObjectQuery(net.geoprism.registry.query.ServerGeoObjectQuery) JSONObject(org.json.JSONObject) ParentTreeNode(org.commongeoregistry.adapter.dataaccess.ParentTreeNode) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) ServerCodeRestriction(net.geoprism.registry.query.ServerCodeRestriction) Location(net.geoprism.registry.io.Location) AllowAllGeoObjectPermissionService(net.geoprism.registry.permission.AllowAllGeoObjectPermissionService) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 9 with ParentTreeNode

use of org.commongeoregistry.adapter.dataaccess.ParentTreeNode 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 10 with ParentTreeNode

use of org.commongeoregistry.adapter.dataaccess.ParentTreeNode 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

ParentTreeNode (org.commongeoregistry.adapter.dataaccess.ParentTreeNode)11 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)5 Test (org.junit.Test)5 TestGeoObjectInfo (net.geoprism.registry.test.TestGeoObjectInfo)4 Endpoint (com.runwaysdk.mvc.Endpoint)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 ServerGeoObjectService (net.geoprism.registry.geoobject.ServerGeoObjectService)2 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)2 ChildTreeNode (org.commongeoregistry.adapter.dataaccess.ChildTreeNode)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 SmartExceptionDTO (com.runwaysdk.business.SmartExceptionDTO)1 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)1 RestBodyResponse (com.runwaysdk.mvc.RestBodyResponse)1 Request (com.runwaysdk.session.Request)1 Universal (com.runwaysdk.system.gis.geo.Universal)1 InputStream (java.io.InputStream)1 Instant (java.time.Instant)1 LinkedList (java.util.LinkedList)1