use of net.geoprism.registry.permission.AllowAllGeoObjectPermissionService in project geoprism-registry by terraframe.
the class ChangeRequestTestDataGenerator method genChangeRequest.
@Transaction
private static void genChangeRequest(String genKey, Instant when, boolean includeRemove, boolean includeAdd) {
ServerGeoObjectService service = new ServerGeoObjectService(new AllowAllGeoObjectPermissionService());
GeoObject goNewChild = ServiceFactory.getAdapter().newGeoObjectInstance("Cambodia_District");
goNewChild.setCode(genKey + "_CODE");
goNewChild.setDisplayLabel(LocalizedValue.DEFAULT_LOCALE, genKey + "_LABEL");
goNewChild.setWKTGeometry("MULTIPOLYGON (((10000 10000, 12300 40000, 16800 50000, 12354 60000, 13354 60000, 17800 50000, 13300 40000, 11000 10000, 10000 10000)))");
ServerGeoObjectIF testAddChildParent = service.getGeoObjectByCode("855 01", "Cambodia_Province");
ServerGeoObjectIF testAddChild = service.getGeoObjectByCode("855 0109", "Cambodia_District");
List<AbstractActionDTO> actions = new ArrayList<AbstractActionDTO>();
/*
* Remove Child
*/
if (includeRemove) {
RemoveChildActionDTO removeChild = new RemoveChildActionDTO();
removeChild.setChildCode(testAddChild.getUid());
removeChild.setChildTypeCode(testAddChild.getType().getCode());
removeChild.setParentCode(testAddChildParent.getUid());
removeChild.setParentTypeCode(testAddChildParent.getType().getCode());
removeChild.setHierarchyCode(LocatedIn.class.getSimpleName());
removeChild.setCreateActionDate(Date.from(when.minus(9, ChronoUnit.HOURS)));
removeChild.setContributorNotes("Removing the village from the district");
actions.add(removeChild);
}
/*
* Add Child
*/
if (includeAdd) {
AddChildActionDTO addChild = new AddChildActionDTO();
addChild.setChildCode(testAddChild.getUid());
addChild.setChildTypeCode(testAddChild.getType().getCode());
addChild.setParentCode(testAddChildParent.getUid());
addChild.setParentTypeCode(testAddChildParent.getType().getCode());
addChild.setHierarchyCode(LocatedIn.class.getSimpleName());
addChild.setCreateActionDate(Date.from(when.minus(10, ChronoUnit.HOURS)));
addChild.setContributorNotes("Adding the village as a child of the district");
actions.add(addChild);
}
/*
* Create a new GeoObject
*/
CreateGeoObjectActionDTO create = new CreateGeoObjectActionDTO();
create.setGeoObject(goNewChild.toJSON());
create.setCreateActionDate(Date.from(when.minus(8, ChronoUnit.HOURS)));
create.setContributorNotes("Creating a new village");
actions.add(create);
/*
* Update the previously created GeoObject
*/
final String NEW_DISPLAY_LABEL = genKey + "_NEW_DISPLAY_LABEL";
goNewChild.setDisplayLabel(LocalizedValue.DEFAULT_LOCALE, NEW_DISPLAY_LABEL);
UpdateGeoObjectActionDTO update = new UpdateGeoObjectActionDTO();
update.setGeoObject(goNewChild.toJSON());
update.setCreateActionDate(Date.from(when.minus(7, ChronoUnit.HOURS)));
update.setContributorNotes("Updating the village. Adding a better name and stuff");
actions.add(update);
// Serialize the actions
String sActions = AbstractActionDTO.serializeActions(actions).toString();
submitChangeRequest(sActions);
}
use of net.geoprism.registry.permission.AllowAllGeoObjectPermissionService 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"));
}
Aggregations