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