Search in sources :

Example 1 with LocationBuilder

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

the class GeoObjectImporter method parsePostalCode.

private ServerGeoObjectIF parsePostalCode(FeatureRow feature) {
    LocationBuilder builder = PostalCodeFactory.get(this.configuration.getType());
    Location location = builder.build(this.configuration.getFunction(GeoObject.CODE));
    ShapefileFunction function = location.getFunction();
    String code = (String) function.getValue(feature);
    if (code != null) {
        // Search
        ServerGeoObjectQuery query = new ServerGeoObjectService().createQuery(location.getType(), this.configuration.getStartDate());
        query.setRestriction(new ServerCodeRestriction(code));
        // Assert.assertNull(query.getSingleResult());
        ServerGeoObjectIF result = query.getSingleResult();
        if (result != null) {
            return result;
        } else {
            PostalCodeLocationException e = new PostalCodeLocationException();
            e.setCode(code);
            e.setTypeLabel(location.getType().getLabel().getValue());
            throw e;
        }
    }
    return null;
}
Also used : ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService) LocationBuilder(net.geoprism.registry.io.LocationBuilder) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) PostalCodeLocationException(net.geoprism.registry.io.PostalCodeLocationException) ShapefileFunction(net.geoprism.data.importer.ShapefileFunction) ServerGeoObjectQuery(net.geoprism.registry.query.ServerGeoObjectQuery) ServerCodeRestriction(net.geoprism.registry.query.ServerCodeRestriction) Location(net.geoprism.registry.io.Location)

Example 2 with LocationBuilder

use of net.geoprism.registry.io.LocationBuilder 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));
}
Also used : JSONObject(org.json.JSONObject) LocationBuilder(net.geoprism.registry.io.LocationBuilder) InputStream(java.io.InputStream) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) ShapefileFunction(net.geoprism.data.importer.ShapefileFunction) ConstantShapefileFunction(net.geoprism.registry.io.ConstantShapefileFunction) ShapefileService(net.geoprism.registry.service.ShapefileService) Location(net.geoprism.registry.io.Location) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Aggregations

ShapefileFunction (net.geoprism.data.importer.ShapefileFunction)2 Location (net.geoprism.registry.io.Location)2 LocationBuilder (net.geoprism.registry.io.LocationBuilder)2 Request (com.runwaysdk.session.Request)1 InputStream (java.io.InputStream)1 ServerGeoObjectService (net.geoprism.registry.geoobject.ServerGeoObjectService)1 ConstantShapefileFunction (net.geoprism.registry.io.ConstantShapefileFunction)1 PostalCodeLocationException (net.geoprism.registry.io.PostalCodeLocationException)1 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)1 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)1 ServerCodeRestriction (net.geoprism.registry.query.ServerCodeRestriction)1 ServerGeoObjectQuery (net.geoprism.registry.query.ServerGeoObjectQuery)1 ShapefileService (net.geoprism.registry.service.ShapefileService)1 JSONObject (org.json.JSONObject)1 Test (org.junit.Test)1