use of net.geoprism.registry.service.ShapefileService in project geoprism-registry by terraframe.
the class ShapefileServiceTest method testGetAttributeInformationPostalCode.
@Test
@Request
public void testGetAttributeInformationPostalCode() {
InputStream istream = this.getClass().getResourceAsStream("/cb_2017_us_state_500k.zip.test");
ServerGeoObjectType type = USATestData.STATE.getServerObject();
PostalCodeFactory.addPostalCode(type, new LocationBuilder() {
@Override
public Location build(ShapefileFunction function) {
return null;
}
});
Assert.assertNotNull(istream);
ShapefileService service = new ShapefileService();
JSONObject result = service.getShapefileConfiguration(testData.clientRequest.getSessionId(), USATestData.STATE.getCode(), null, null, "cb_2017_us_state_500k.zip", istream, ImportStrategy.NEW_AND_UPDATE, false);
Assert.assertTrue(result.getBoolean(GeoObjectImportConfiguration.HAS_POSTAL_CODE));
}
use of net.geoprism.registry.service.ShapefileService in project geoprism-registry by terraframe.
the class ShapefileServiceTest method testImportShapefileWithBadParentCode.
@Test
@Request
public void testImportShapefileWithBadParentCode() throws Throwable {
GeoObject geoObj = ServiceFactory.getRegistryService().newGeoObjectInstance(testData.clientRequest.getSessionId(), USATestData.COUNTRY.getCode());
geoObj.setCode("00");
geoObj.setDisplayLabel(LocalizedValue.DEFAULT_LOCALE, "Test Label");
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);
geoObj = RegistryService.getInstance().getGeoObjectByCode(Session.getCurrentSession().getOid(), serverGO.getCode(), serverGO.getType().getCode(), TestDataSet.DEFAULT_OVER_TIME_DATE);
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("GEOID"), ParentMatchStrategy.CODE));
ImportHistory hist = mockImport(config);
Assert.assertTrue(hist.getStatus().get(0).equals(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));
final GeoObjectImportConfiguration test = new GeoObjectImportConfiguration();
test.fromJSON(hist.getConfigJson(), false);
// TODO
// Assert.assertEquals(config.getParentLookupType(),
// test.getParentLookupType());
// JSONArray errors = new JSONArray(hist.getErrorJson());
//
// Assert.assertEquals(0, errors.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());
}
use of net.geoprism.registry.service.ShapefileService in project geoprism-registry by terraframe.
the class ShapefileServiceTest method testImportShapefileInteger.
@Test
@Request
public void testImportShapefileInteger() 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.setFunction(testInteger.getName(), new BasicColumnFunction("ALAND"));
config.setHierarchy(hierarchyType);
ImportHistory hist = mockImport(config);
Assert.assertTrue(hist.getStatus().get(0).equals(AllJobStatus.SUCCESS));
hist = ImportHistory.get(hist.getOid());
Assert.assertEquals(new Long(56), hist.getWorkTotal());
Assert.assertEquals(new Long(56), hist.getWorkProgress());
Assert.assertEquals(new Long(56), hist.getImportedRecords());
Assert.assertEquals(ImportStage.COMPLETE, hist.getStage().get(0));
GeoObject object = ServiceFactory.getRegistryService().getGeoObjectByCode(testData.clientRequest.getSessionId(), "01", USATestData.STATE.getCode(), TestDataSet.DEFAULT_OVER_TIME_DATE);
Assert.assertNotNull(object);
Assert.assertNotNull(object.getGeometry());
Assert.assertEquals("Alabama", object.getLocalizedDisplayLabel());
Assert.assertEquals(131174431216L, object.getValue(testInteger.getName()));
}
use of net.geoprism.registry.service.ShapefileService 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 net.geoprism.registry.service.ShapefileService in project geoprism-registry by terraframe.
the class ShapefileServiceTest method testGetAttributeInformation.
// @Before
// public void setUp()
// {
// testData = USATestData.newTestData(false);
//
// this.adminCR = testData.adminClientRequest;
//
// AttributeTermType testTerm = (AttributeTermType)
// AttributeType.factory("testTerm", new LocalizedValue("testTermLocalName"),
// new LocalizedValue("testTermLocalDescrip"), AttributeTermType.TYPE, false,
// false, false);
// this.testTerm = (AttributeTermType)
// ServiceFactory.getRegistryService().createAttributeType(this.adminCR.getSessionId(),
// this.USATestData.STATE.getCode(), testTerm.toJSON().toString());
//
// AttributeIntegerType testInteger = (AttributeIntegerType)
// AttributeType.factory("testInteger", new
// LocalizedValue("testIntegerLocalName"), new
// LocalizedValue("testIntegerLocalDescrip"), AttributeIntegerType.TYPE,
// false, false, false);
// this.testInteger = (AttributeIntegerType)
// ServiceFactory.getRegistryService().createAttributeType(this.adminCR.getSessionId(),
// this.USATestData.STATE.getCode(), testInteger.toJSON().toString());
//
// reload();
// }
//
// @After
// public void tearDown() throws IOException
// {
// testData.cleanUp();
//
// FileUtils.deleteDirectory(new
// File(VaultProperties.getPath("vault.default"), "files"));
// }
@Test
@Request
public void testGetAttributeInformation() {
PostalCodeFactory.remove(USATestData.STATE.getServerObject());
InputStream istream = this.getClass().getResourceAsStream("/cb_2017_us_state_500k.zip.test");
Assert.assertNotNull(istream);
ShapefileService service = new ShapefileService();
JSONObject result = service.getShapefileConfiguration(testData.clientRequest.getSessionId(), USATestData.STATE.getCode(), null, null, "cb_2017_us_state_500k.zip", istream, ImportStrategy.NEW_AND_UPDATE, false);
Assert.assertFalse(result.getBoolean(GeoObjectImportConfiguration.HAS_POSTAL_CODE));
JSONObject type = result.getJSONObject(GeoObjectImportConfiguration.TYPE);
Assert.assertNotNull(type);
JSONArray tAttributes = type.getJSONArray(GeoObjectType.JSON_ATTRIBUTES);
Assert.assertEquals(4, tAttributes.length());
boolean hasCode = false;
for (int i = 0; i < tAttributes.length(); i++) {
JSONObject tAttribute = tAttributes.getJSONObject(i);
String code = tAttribute.getString(AttributeType.JSON_CODE);
if (code.equals(GeoObjectType.JSON_CODE)) {
hasCode = true;
Assert.assertTrue(tAttribute.has("required"));
Assert.assertTrue(tAttribute.getBoolean("required"));
}
}
Assert.assertTrue(hasCode);
JSONObject sheet = result.getJSONObject("sheet");
Assert.assertNotNull(sheet);
Assert.assertEquals("cb_2017_us_state_500k", sheet.getString("name"));
JSONObject attributes = sheet.getJSONObject("attributes");
Assert.assertNotNull(attributes);
JSONArray fields = attributes.getJSONArray(GeoObjectImportConfiguration.TEXT);
Assert.assertEquals(9, fields.length());
Assert.assertEquals("STATEFP", fields.getString(0));
Assert.assertEquals(2, attributes.getJSONArray(GeoObjectImportConfiguration.NUMERIC).length());
Assert.assertEquals(0, attributes.getJSONArray(AttributeBooleanType.TYPE).length());
Assert.assertEquals(0, attributes.getJSONArray(AttributeDateType.TYPE).length());
}
Aggregations