Search in sources :

Example 1 with ExcelService

use of net.geoprism.registry.service.ExcelService 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());
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) JSONObject(org.json.JSONObject) InputStream(java.io.InputStream) ExcelService(net.geoprism.registry.service.ExcelService) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 2 with ExcelService

use of net.geoprism.registry.service.ExcelService 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 3 with ExcelService

use of net.geoprism.registry.service.ExcelService in project geoprism-registry by terraframe.

the class GeoObjectImporterTest method testCreateOnly.

@Test
@Request
public void testCreateOnly() throws InterruptedException {
    // USATestData.CO_D_ONE.delete();
    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_ONLY);
    config.setHierarchy(hierarchyType);
    ImportHistory hist = importExcelFile(testData.clientRequest.getSessionId(), config.toJSON().toString());
    SchedulerTestUtils.waitUntilStatus(hist.getOid(), AllJobStatus.FEEDBACK);
    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(2), hist.getImportedRecords());
    Assert.assertEquals(ImportStage.IMPORT_RESOLVE, 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);
    GeoObject coloradoDistOne = ServiceFactory.getRegistryService().getGeoObjectByCode(testData.clientRequest.getSessionId(), USATestData.CO_D_ONE.getCode(), USATestData.DISTRICT.getCode(), TestDataSet.DEFAULT_OVER_TIME_DATE);
    Double cd1_lat = new Double(80);
    Double cd1_lon = new Double(110);
    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();
    Assert.assertEquals(cd1_expected, cd1_geometry);
    JSONObject json = new JSONObject(new ETLService().getImportErrors(testData.clientRequest.getSessionId(), hist.getOid(), false, 100, 1).toString());
    Assert.assertEquals(1, 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) 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 4 with ExcelService

use of net.geoprism.registry.service.ExcelService in project geoprism-registry by terraframe.

the class ExcelServiceTest method testGetAttributeInformation.

@Test
@Request
public void testGetAttributeInformation() {
    PostalCodeFactory.remove(USATestData.DISTRICT.getServerObject());
    InputStream istream = this.getClass().getResourceAsStream("/test-spreadsheet.xlsx");
    Assert.assertNotNull(istream);
    ExcelService service = new ExcelService();
    JSONObject result = service.getExcelConfiguration(testData.clientRequest.getSessionId(), USATestData.DISTRICT.getCode(), null, null, "test-spreadsheet.xlsx", istream, ImportStrategy.NEW_AND_UPDATE, false);
    Assert.assertFalse(result.getBoolean(GeoObjectImportConfiguration.HAS_POSTAL_CODE));
    Assert.assertNotNull(result.getJSONObject(GeoObjectImportConfiguration.TYPE));
    JSONObject sheet = result.getJSONObject(GeoObjectImportConfiguration.SHEET);
    Assert.assertNotNull(sheet);
    Assert.assertEquals("Objects", sheet.getString("name"));
    JSONObject attributes = sheet.getJSONObject(GeoObjectType.JSON_ATTRIBUTES);
    Assert.assertNotNull(attributes);
    JSONArray fields = attributes.getJSONArray(GeoObjectImportConfiguration.TEXT);
    Assert.assertEquals(8, fields.length());
    Assert.assertEquals("Longitude", fields.getString(0));
    Assert.assertEquals(4, attributes.getJSONArray(GeoObjectImportConfiguration.NUMERIC).length());
    Assert.assertEquals(1, attributes.getJSONArray(AttributeBooleanType.TYPE).length());
    Assert.assertEquals(1, attributes.getJSONArray(AttributeDateType.TYPE).length());
}
Also used : JSONObject(org.json.JSONObject) InputStream(java.io.InputStream) JSONArray(org.json.JSONArray) ExcelService(net.geoprism.registry.service.ExcelService) ClassificationTypeTest(net.geoprism.registry.classification.ClassificationTypeTest) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Aggregations

Request (com.runwaysdk.session.Request)4 InputStream (java.io.InputStream)4 ExcelService (net.geoprism.registry.service.ExcelService)4 JSONObject (org.json.JSONObject)4 Test (org.junit.Test)4 GeoObjectImportConfiguration (net.geoprism.registry.io.GeoObjectImportConfiguration)3 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)3 Geometry (com.vividsolutions.jts.geom.Geometry)2 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)2 Point (com.vividsolutions.jts.geom.Point)2 PrecisionModel (com.vividsolutions.jts.geom.PrecisionModel)2 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)2 CoordinateSequence2D (org.jaitools.jts.CoordinateSequence2D)2 ClassificationTypeTest (net.geoprism.registry.classification.ClassificationTypeTest)1 GeoObjectOverTime (org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime)1 JSONArray (org.json.JSONArray)1