use of net.geoprism.registry.io.GeoObjectImportConfiguration in project geoprism-registry by terraframe.
the class PatchOrgIntoImportHistory method doIt.
@Transaction
private void doIt() {
ImportHistoryQuery ihq = new ImportHistoryQuery(new QueryFactory());
OIterator<? extends ImportHistory> it = ihq.getIterator();
try {
for (ImportHistory hist : it) {
try {
ImportConfiguration config = hist.getConfig();
if (config instanceof GeoObjectImportConfiguration) {
GeoObjectImportConfiguration goConfig = (GeoObjectImportConfiguration) config;
Organization org = goConfig.getType().getOrganization();
hist.appLock();
hist.setOrganization(org);
hist.apply();
}
} catch (net.geoprism.registry.DataNotFoundException e) {
logger.error("ImportHistory references object which does not exist", e);
}
}
} finally {
it.close();
}
}
use of net.geoprism.registry.io.GeoObjectImportConfiguration in project geoprism-registry by terraframe.
the class GeoObjectImporterTest method testUpdateErrorCount.
/**
* Tests to make sure that we are recording the correct amount of import errors.
*
* @throws InterruptedException
*/
@Test
@Request
public void testUpdateErrorCount() throws InterruptedException {
InputStream istream = this.getClass().getResourceAsStream("/test-spreadsheet3.xlsx");
Assert.assertNotNull(istream);
ExcelService service = new ExcelService();
ServerHierarchyType hierarchyType = ServerHierarchyType.get(USATestData.HIER_ADMIN.getCode());
GeoObjectImportConfiguration config = this.getTestConfiguration(istream, service, null, ImportStrategy.NEW_ONLY);
config.setHierarchy(hierarchyType);
// First, import the spreadsheet. It should be succesful
ImportHistory hist = importExcelFile(testData.clientRequest.getSessionId(), config.toJSON().toString());
SchedulerTestUtils.waitUntilStatus(hist.getOid(), AllJobStatus.SUCCESS);
hist = ImportHistory.get(hist.getOid());
Assert.assertEquals(new Long(10), hist.getWorkTotal());
Assert.assertEquals(new Long(10), hist.getWorkProgress());
Assert.assertEquals(new Long(10), hist.getImportedRecords());
Assert.assertEquals(ImportStage.COMPLETE, hist.getStage().get(0));
// Import a second spreadsheet, which should have a few duplicate records.
InputStream istream2 = this.getClass().getResourceAsStream("/test-spreadsheet4.xlsx");
GeoObjectImportConfiguration config2 = this.getTestConfiguration(istream2, service, null, ImportStrategy.NEW_ONLY);
config2.setHierarchy(hierarchyType);
ImportHistory hist2 = importExcelFile(testData.clientRequest.getSessionId(), config2.toJSON().toString());
SchedulerTestUtils.waitUntilStatus(hist2.getOid(), AllJobStatus.FEEDBACK);
hist2 = ImportHistory.get(hist2.getOid());
Assert.assertEquals(new Long(17), hist2.getWorkTotal());
Assert.assertEquals(new Long(17), hist2.getWorkProgress());
Assert.assertEquals(new Long(7), hist2.getImportedRecords());
Assert.assertEquals(ImportStage.IMPORT_RESOLVE, hist2.getStage().get(0));
JSONObject json = new JSONObject(new ETLService().getImportErrors(testData.clientRequest.getSessionId(), hist2.getOid(), false, 100, 1).toString());
Assert.assertEquals(10, json.getJSONArray("resultSet").length());
}
use of net.geoprism.registry.io.GeoObjectImportConfiguration 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.io.GeoObjectImportConfiguration in project geoprism-registry by terraframe.
the class PatchGotIntoImportHistory method doIt.
@Transaction
private void doIt() {
ImportHistoryQuery ihq = new ImportHistoryQuery(new QueryFactory());
OIterator<? extends ImportHistory> it = ihq.getIterator();
try {
for (ImportHistory hist : it) {
try {
ImportConfiguration config = hist.getConfig();
if (config instanceof GeoObjectImportConfiguration) {
GeoObjectImportConfiguration goConfig = (GeoObjectImportConfiguration) config;
ServerGeoObjectType type = goConfig.getType();
hist.appLock();
hist.setOrganization(type.getOrganization());
hist.setGeoObjectTypeCode(type.getCode());
hist.apply();
}
} catch (net.geoprism.registry.DataNotFoundException e) {
logger.error("ImportHistory references object which does not exist", e);
}
}
} finally {
it.close();
}
}
use of net.geoprism.registry.io.GeoObjectImportConfiguration in project geoprism-registry by terraframe.
the class ExcelImporter method getGeometry.
@Override
public Geometry getGeometry(FeatureRow row) {
if (this.config.isExternalImport() && this.config.getExternalSystem() instanceof RevealExternalSystem) {
return ((RevealExcelContentHandler) this.excelHandler).getGeometry();
} else {
ShapefileFunction latitudeFunction = this.config.getFunction(GeoObjectImportConfiguration.LATITUDE);
ShapefileFunction longitudeFunction = this.config.getFunction(GeoObjectImportConfiguration.LONGITUDE);
if (latitudeFunction != null && longitudeFunction != null) {
Object latitude = latitudeFunction.getValue(row);
Object longitude = longitudeFunction.getValue(row);
if (latitude != null && longitude != null) {
Double lat = new Double(latitude.toString());
Double lon = new Double(longitude.toString());
if (Math.abs(lat) > 90 || Math.abs(lon) > 180) {
LatLonException ex = new LatLonException();
ex.setLat(lat.toString());
ex.setLon(lon.toString());
throw ex;
}
ImportConfiguration configuration = this.objectImporter.getConfiguration();
if (configuration instanceof GeoObjectImportConfiguration) {
ServerGeoObjectType type = ((GeoObjectImportConfiguration) configuration).getType();
if (type.getGeometryType().equals(GeometryType.POINT) || type.getGeometryType().equals(GeometryType.MIXED)) {
return new Point(new CoordinateSequence2D(lon, lat), factory);
}
}
return new MultiPoint(new Point[] { new Point(new CoordinateSequence2D(lon, lat), factory) }, factory);
}
}
return null;
}
}
Aggregations