Search in sources :

Example 6 with GeoObjectImportConfiguration

use of net.geoprism.registry.io.GeoObjectImportConfiguration in project geoprism-registry by terraframe.

the class ExcelImporter method process.

@Request
private void process(ImportStage stage, File file) throws InvocationTargetException, IOException {
    try {
        /*
       * Check permissions
       */
        ImportConfiguration config = this.getObjectImporter().getConfiguration();
        config.enforceCreatePermissions();
        // TODO Determine permissions for
        this.progressListener.setWorkTotal(this.getWorkTotal(file));
        if (this.config.isExternalImport() && this.config.getExternalSystem() instanceof RevealExternalSystem && this.config instanceof GeoObjectImportConfiguration) {
            this.excelHandler = new RevealExcelContentHandler(this.objectImporter, stage, this.getStartIndex(), ((GeoObjectImportConfiguration) this.config).getRevealGeometryColumn());
        } else {
            this.excelHandler = new ExcelContentHandler(this.objectImporter, stage, this.getStartIndex());
        }
        ExcelDataFormatter formatter = new ExcelDataFormatter();
        ExcelSheetReader reader = new ExcelSheetReader(excelHandler, formatter);
        reader.process(new FileInputStream(file));
    } catch (Exception e) {
        throw new ProgrammingErrorException(e);
    }
}
Also used : GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) ExcelDataFormatter(net.geoprism.data.etl.excel.ExcelDataFormatter) RevealExternalSystem(net.geoprism.registry.graph.RevealExternalSystem) ExcelSheetReader(net.geoprism.data.etl.excel.ExcelSheetReader) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) FileInputStream(java.io.FileInputStream) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) ImportFileFormatException(net.geoprism.registry.etl.ImportFileFormatException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) LatLonException(net.geoprism.registry.io.LatLonException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) Request(com.runwaysdk.session.Request)

Example 7 with GeoObjectImportConfiguration

use of net.geoprism.registry.io.GeoObjectImportConfiguration in project geoprism-registry by terraframe.

the class ImportConfiguration method build.

public static ImportConfiguration build(String json, boolean includeCoordinates) {
    JSONObject jo = new JSONObject(json);
    String objectType = jo.getString(OBJECT_TYPE);
    if (objectType.equals(ObjectImporterFactory.ObjectImportType.GEO_OBJECT.name())) {
        GeoObjectImportConfiguration config = new GeoObjectImportConfiguration();
        config.fromJSON(json, includeCoordinates);
        return config;
    } else if (objectType.equals(ObjectImporterFactory.ObjectImportType.BUSINESS_OBJECT.name())) {
        BusinessObjectImportConfiguration config = new BusinessObjectImportConfiguration();
        config.fromJSON(json, false);
        return config;
    } else {
        throw new UnsupportedOperationException();
    }
}
Also used : GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) JSONObject(org.json.JSONObject)

Example 8 with GeoObjectImportConfiguration

use of net.geoprism.registry.io.GeoObjectImportConfiguration in project geoprism-registry by terraframe.

the class GeoObjectImporterTest method getTestConfiguration.

private GeoObjectImportConfiguration getTestConfiguration(InputStream istream, ExcelService service, AttributeTermType attributeTerm, ImportStrategy strategy) {
    JSONObject result = service.getExcelConfiguration(testData.clientRequest.getSessionId(), USATestData.DISTRICT.getCode(), TestDataSet.DEFAULT_OVER_TIME_DATE, TestDataSet.DEFAULT_END_TIME_DATE, "test-spreadsheet.xlsx", istream, strategy, false);
    JSONObject type = result.getJSONObject(GeoObjectImportConfiguration.TYPE);
    JSONArray attributes = type.getJSONArray(GeoObjectType.JSON_ATTRIBUTES);
    for (int i = 0; i < attributes.length(); i++) {
        JSONObject attribute = attributes.getJSONObject(i);
        String attributeName = attribute.getString(AttributeType.JSON_CODE);
        if (attributeName.equals(GeoObject.DISPLAY_LABEL)) {
            attribute.put(GeoObjectImportConfiguration.TARGET, "Name");
        } else if (attributeName.equals(GeoObject.CODE)) {
            attribute.put(GeoObjectImportConfiguration.TARGET, "Code");
        } else if (attributeName.equals(GeoObjectImportConfiguration.LATITUDE)) {
            attribute.put(GeoObjectImportConfiguration.TARGET, "Latitude");
        } else if (attributeName.equals(GeoObjectImportConfiguration.LONGITUDE)) {
            attribute.put(GeoObjectImportConfiguration.TARGET, "Longitude");
        } else if (attributeTerm != null && attributeName.equals(attributeTerm.getName())) {
            attribute.put(GeoObjectImportConfiguration.TARGET, "Term");
        }
    }
    result.put(ImportConfiguration.FORMAT_TYPE, FormatImporterType.EXCEL);
    result.put(ImportConfiguration.OBJECT_TYPE, ObjectImportType.GEO_OBJECT);
    GeoObjectImportConfiguration configuration = (GeoObjectImportConfiguration) ImportConfiguration.build(result.toString(), true);
    return configuration;
}
Also used : GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Point(com.vividsolutions.jts.geom.Point)

Example 9 with GeoObjectImportConfiguration

use of net.geoprism.registry.io.GeoObjectImportConfiguration in project geoprism-registry by terraframe.

the class GeoObjectImporterTest method testNewAndUpdate.

/*
   * I simply could not get this test to work on the build machine :(. It works locally for me but not on the build machine and I don't know why.
   */
// @Test
// public void testSessionExpire() throws InterruptedException
// {
// CommonsConfigurationResolver.getInMemoryConfigurator().setProperty("import.refreshSessionRecordCount", "1");
// Assert.assertEquals(1, GeoregistryProperties.getRefreshSessionRecordCount());
// 
// Date benchmarkStartTime = new Date();
// testUpdateOnly();
// Date benchmarkEndTime = new Date();
// long benchmarkRuntime = benchmarkEndTime.getTime() - benchmarkStartTime.getTime();
// System.out.println("Benchmark time is " + benchmarkRuntime); // Find out how long it takes on this computer to import one record
// 
// GeoObjectImportConfiguration config = testSessionSetup();
// 
// Date startTime = new Date();
// 
// long oldSessionTime = Session.getSessionTime();
// 
// // This value must be very finely tuned. It has to be short enough such that it is less than the time a fast computer
// // will take to import the entire spreadsheet, but small enough so that a slow computer can import a single record
// // before the session expires.
// final long sessionTimeMs = benchmarkRuntime + 1500;
// Session.setSessionTime(sessionTimeMs / (1000));
// 
// ImportHistory hist;
// try
// {
// hist = testSessionExpireInReq(config);
// }
// finally
// {
// Session.setSessionTime(oldSessionTime);
// }
// 
// sessionTestValidateInRequest(hist, startTime, sessionTimeMs);
// }
// 
// @Request
// private void sessionTestValidateInRequest(ImportHistory hist, Date startTime, long sessionTimeMs) throws InterruptedException
// {
// SchedulerTestUtils.waitUntilStatus(hist.getOid(), AllJobStatus.SUCCESS);
// 
// Date endTime = new Date();
// 
// System.out.println("Session expiration test took " + (endTime.getTime() - startTime.getTime()) + " miliseconds to complete.");
// 
// if ((endTime.getTime() - startTime.getTime()) < sessionTimeMs)
// {
// Assert.fail("The test completed before the session had a chance to expire. Try setting the 'sessionTimeMs' lower.");
// }
// }
// 
// @Request
// private GeoObjectImportConfiguration testSessionSetup()
// {
// InputStream istream = this.getClass().getResourceAsStream("/test-spreadsheet-500records.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_AND_UPDATE);
// config.setHierarchy(hierarchyType);
// return config;
// }
// 
// @Request
// public ImportHistory testSessionExpireInReq(GeoObjectImportConfiguration config) throws InterruptedException
// {
// ImportHistory hist = importExcelFile(testData.clientRequest.getSessionId(), config.toJSON().toString());
// 
// // We have to wait until the job is running so that it will run with the session time.
// SchedulerTestUtils.waitUntilStatus(hist.getOid(), AllJobStatus.RUNNING);
// 
// return hist;
// }
@Test
@Request
public void testNewAndUpdate() throws InterruptedException {
    InputStream istream = this.getClass().getResourceAsStream("/test-spreadsheet2.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_AND_UPDATE);
    config.setHierarchy(hierarchyType);
    ImportHistory hist = importExcelFile(testData.clientRequest.getSessionId(), config.toJSON().toString());
    SchedulerTestUtils.waitUntilStatus(hist.getOid(), AllJobStatus.SUCCESS);
    hist = ImportHistory.get(hist.getOid());
    Assert.assertEquals(new Long(ROW_COUNT), hist.getWorkTotal());
    Assert.assertEquals(new Long(ROW_COUNT), hist.getWorkProgress());
    Assert.assertEquals(new Long(3), hist.getImportedRecords());
    Assert.assertEquals(ImportStage.COMPLETE, hist.getStage().get(0));
    GeoObject object = ServiceFactory.getRegistryService().getGeoObjectByCode(testData.clientRequest.getSessionId(), "0001", USATestData.DISTRICT.getCode(), TestDataSet.DEFAULT_OVER_TIME_DATE);
    Assert.assertNotNull(object);
    Assert.assertEquals("Test", object.getLocalizedDisplayLabel());
    Geometry geometry = object.getGeometry();
    Assert.assertNotNull(geometry);
    Double lat = new Double(2.232343);
    Double lon = new Double(1.134232);
    GeometryFactory factory = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING), 4326);
    Point expected = new Point(new CoordinateSequence2D(lon, lat), factory);
    Assert.assertEquals(expected, geometry);
    GeoObjectOverTime coloradoDistOne = ServiceFactory.getRegistryService().getGeoObjectOverTimeByCode(testData.clientRequest.getSessionId(), USATestData.CO_D_ONE.getCode(), USATestData.DISTRICT.getCode());
    Double cd1_lat = new Double(4.3333);
    Double cd1_lon = new Double(1.222);
    GeometryFactory cd1_factory = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING), 4326);
    Point cd1_expected = new Point(new CoordinateSequence2D(cd1_lon, cd1_lat), cd1_factory);
    Geometry cd1_geometry = coloradoDistOne.getGeometry(TestDataSet.DEFAULT_OVER_TIME_DATE);
    Assert.assertEquals(cd1_expected, cd1_geometry);
    JSONObject json = new JSONObject(new ETLService().getImportErrors(testData.clientRequest.getSessionId(), hist.getOid(), false, 100, 1).toString());
    Assert.assertEquals(0, json.getJSONArray("resultSet").length());
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) CoordinateSequence2D(org.jaitools.jts.CoordinateSequence2D) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) InputStream(java.io.InputStream) ExcelService(net.geoprism.registry.service.ExcelService) PrecisionModel(com.vividsolutions.jts.geom.PrecisionModel) GeoObjectOverTime(org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime) Point(com.vividsolutions.jts.geom.Point) Geometry(com.vividsolutions.jts.geom.Geometry) JSONObject(org.json.JSONObject) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 10 with GeoObjectImportConfiguration

use of net.geoprism.registry.io.GeoObjectImportConfiguration 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()));
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) InputStream(java.io.InputStream) BasicColumnFunction(net.geoprism.data.importer.BasicColumnFunction) ShapefileService(net.geoprism.registry.service.ShapefileService) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Aggregations

GeoObjectImportConfiguration (net.geoprism.registry.io.GeoObjectImportConfiguration)12 Request (com.runwaysdk.session.Request)7 InputStream (java.io.InputStream)6 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)6 JSONObject (org.json.JSONObject)6 Test (org.junit.Test)6 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)5 Point (com.vividsolutions.jts.geom.Point)4 BasicColumnFunction (net.geoprism.data.importer.BasicColumnFunction)3 ExcelService (net.geoprism.registry.service.ExcelService)3 ShapefileService (net.geoprism.registry.service.ShapefileService)3 CoordinateSequence2D (org.jaitools.jts.CoordinateSequence2D)3 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)2 QueryFactory (com.runwaysdk.query.QueryFactory)2 Geometry (com.vividsolutions.jts.geom.Geometry)2 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)2 PrecisionModel (com.vividsolutions.jts.geom.PrecisionModel)2 ImportHistory (net.geoprism.registry.etl.ImportHistory)2 ImportHistoryQuery (net.geoprism.registry.etl.ImportHistoryQuery)2 ImportConfiguration (net.geoprism.registry.etl.upload.ImportConfiguration)2