Search in sources :

Example 1 with GeoObjectImportConfiguration

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();
    }
}
Also used : QueryFactory(com.runwaysdk.query.QueryFactory) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) Organization(net.geoprism.registry.Organization) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) ImportConfiguration(net.geoprism.registry.etl.upload.ImportConfiguration) ImportHistoryQuery(net.geoprism.registry.etl.ImportHistoryQuery) ImportHistory(net.geoprism.registry.etl.ImportHistory) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 2 with GeoObjectImportConfiguration

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());
}
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 3 with GeoObjectImportConfiguration

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());
}
Also used : ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) InputStream(java.io.InputStream) BasicColumnFunction(net.geoprism.data.importer.BasicColumnFunction) ShapefileService(net.geoprism.registry.service.ShapefileService) ServerGeoObjectQuery(net.geoprism.registry.query.ServerGeoObjectQuery) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) ServerCodeRestriction(net.geoprism.registry.query.ServerCodeRestriction) AllowAllGeoObjectPermissionService(net.geoprism.registry.permission.AllowAllGeoObjectPermissionService) Location(net.geoprism.registry.io.Location) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 4 with GeoObjectImportConfiguration

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();
    }
}
Also used : QueryFactory(com.runwaysdk.query.QueryFactory) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) ImportConfiguration(net.geoprism.registry.etl.upload.ImportConfiguration) ImportHistoryQuery(net.geoprism.registry.etl.ImportHistoryQuery) ImportHistory(net.geoprism.registry.etl.ImportHistory) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 5 with GeoObjectImportConfiguration

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;
    }
}
Also used : LatLonException(net.geoprism.registry.io.LatLonException) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) CoordinateSequence2D(org.jaitools.jts.CoordinateSequence2D) RevealExternalSystem(net.geoprism.registry.graph.RevealExternalSystem) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) ShapefileFunction(net.geoprism.data.importer.ShapefileFunction) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint)

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