From: Mathieu Baudier Date: Fri, 11 Mar 2011 15:29:07 +0000 (+0000) Subject: GeoJcrIndex working X-Git-Tag: argeo-commons-2.1.30~1372 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=3cd76e9fb547b4e839931c96264f0edc3ec315b6;p=lgpl%2Fargeo-commons.git GeoJcrIndex working git-svn-id: https://svn.argeo.org/commons/trunk@4286 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/gis/plugins/org.argeo.gis.ui.rap.openlayers/src/main/java/org/argeo/gis/ui/rap/openlayers/OpenLayersMapViewer.java b/gis/plugins/org.argeo.gis.ui.rap.openlayers/src/main/java/org/argeo/gis/ui/rap/openlayers/OpenLayersMapViewer.java index 1228611fe..b82259b12 100644 --- a/gis/plugins/org.argeo.gis.ui.rap.openlayers/src/main/java/org/argeo/gis/ui/rap/openlayers/OpenLayersMapViewer.java +++ b/gis/plugins/org.argeo.gis.ui.rap.openlayers/src/main/java/org/argeo/gis/ui/rap/openlayers/OpenLayersMapViewer.java @@ -64,6 +64,8 @@ public class OpenLayersMapViewer extends AbstractMapViewer implements createControl(parent); this.map = ((OpenLayersWidget) getControl()).getMap(); + // TODO: make dependent of the base layer + map.setNumZoomLevels(2); // mapContextProvider.getMapContext().addMapLayerListListener(this); diff --git a/gis/plugins/org.argeo.gis.ui/src/main/java/org/argeo/gis/ui/commands/AddFeatureSources.java b/gis/plugins/org.argeo.gis.ui/src/main/java/org/argeo/gis/ui/commands/AddFeatureSources.java index 7c83fad87..ee12806fe 100644 --- a/gis/plugins/org.argeo.gis.ui/src/main/java/org/argeo/gis/ui/commands/AddFeatureSources.java +++ b/gis/plugins/org.argeo.gis.ui/src/main/java/org/argeo/gis/ui/commands/AddFeatureSources.java @@ -13,6 +13,7 @@ import javax.jcr.Session; import org.argeo.ArgeoException; import org.argeo.eclipse.ui.AbstractTreeContentProvider; import org.argeo.eclipse.ui.TreeParent; +import org.argeo.eclipse.ui.dialogs.Error; import org.argeo.geotools.jcr.GeoJcrMapper; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -58,19 +59,17 @@ public class AddFeatureSources extends AbstractHandler { } } } - return null; } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - return null; + Error.show("Cannot add new feature source", e); } + return null; } public void setGeoJcrMapper(GeoJcrMapper geoJcrMapper) { this.geoJcrMapper = geoJcrMapper; } - protected void setSession(Session session) { + public void setSession(Session session) { this.session = session; } diff --git a/gis/plugins/org.argeo.gis.ui/src/main/java/org/argeo/gis/ui/editors/MapFormPage.java b/gis/plugins/org.argeo.gis.ui/src/main/java/org/argeo/gis/ui/editors/MapFormPage.java index c84816571..5c454d2c9 100644 --- a/gis/plugins/org.argeo.gis.ui/src/main/java/org/argeo/gis/ui/editors/MapFormPage.java +++ b/gis/plugins/org.argeo.gis.ui/src/main/java/org/argeo/gis/ui/editors/MapFormPage.java @@ -6,10 +6,12 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.argeo.gis.ui.MapControlCreator; import org.argeo.gis.ui.MapViewer; +import org.argeo.gis.ui.MapViewerListener; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.forms.AbstractFormPart; import org.eclipse.ui.forms.IManagedForm; import org.eclipse.ui.forms.editor.FormEditor; import org.eclipse.ui.forms.editor.FormPage; @@ -43,21 +45,13 @@ public class MapFormPage extends FormPage { layout.marginWidth = 0; mapArea.setLayout(layout); mapViewer = mapControlCreator.createMapControl(context, mapArea); - tk.adapt(mapViewer.getControl()); - } - - public void featureSelected(String layerId, String featureId) { - if (log.isDebugEnabled()) - log.debug("Selected feature '" + featureId + "' of layer '" - + layerId + "'"); - } - - public void featureUnselected(String layerId, String featureId) { - if (log.isDebugEnabled()) - log.debug("Unselected feature '" + featureId + "' of layer '" - + layerId + "'"); + // form part + MapFormPart mapFormPart = new MapFormPart(); + getManagedForm().addPart(mapFormPart); + mapViewer.addMapViewerListener(mapFormPart); + tk.adapt(mapViewer.getControl()); } public void setFocus() { @@ -69,4 +63,23 @@ public class MapFormPage extends FormPage { return mapViewer; } + private static class MapFormPart extends AbstractFormPart implements + MapViewerListener { + + public void featureSelected(String layerId, String featureId) { + if (log.isDebugEnabled()) + log.debug("Selected feature '" + featureId + "' of layer '" + + layerId + "'"); + markDirty(); + } + + public void featureUnselected(String layerId, String featureId) { + if (log.isDebugEnabled()) + log.debug("Unselected feature '" + featureId + "' of layer '" + + layerId + "'"); + + markDirty(); + } + + } } diff --git a/gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/geotools/GeoToolsUtils.java b/gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/geotools/GeoToolsUtils.java index c154f4b97..fb5ad5b76 100644 --- a/gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/geotools/GeoToolsUtils.java +++ b/gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/geotools/GeoToolsUtils.java @@ -57,7 +57,7 @@ public class GeoToolsUtils { dataStore.createSchema(featureType); } catch (IOException e1) { throw new ArgeoException("Cannot create schema " + featureType, - e); + e1); } } } diff --git a/gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/geotools/jcr/GeoJcrIndex.java b/gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/geotools/jcr/GeoJcrIndex.java index e1c3db1f1..a1175abc7 100644 --- a/gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/geotools/jcr/GeoJcrIndex.java +++ b/gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/geotools/jcr/GeoJcrIndex.java @@ -1,8 +1,11 @@ package org.argeo.geotools.jcr; import java.io.IOException; +import java.util.Collections; import java.util.Date; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; import javax.jcr.Node; @@ -12,6 +15,7 @@ import javax.jcr.Session; import javax.jcr.observation.Event; import javax.jcr.observation.EventIterator; import javax.jcr.observation.EventListener; +import javax.jcr.observation.ObservationManager; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -41,106 +45,109 @@ import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.Point; import com.vividsolutions.jts.geom.Polygon; -public class GeoJcrIndex implements EventListener { - final static String GEOJCR_INDEX = "GEOJCR_INDEX"; +public class GeoJcrIndex implements EventListener, GisNames, GisTypes { // PostGIS convention final static String DEFAULT_GEOM_NAME = "the_geom"; private final static Log log = LogFactory.getLog(GeoJcrIndex.class); - public static SimpleFeatureType getWorkspaceGeoIndex(String workspaceName) { - SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); - builder.setNamespaceURI(GisNames.GIS_NAMESPACE); - builder.setName(workspaceName.toUpperCase() + "_" + GEOJCR_INDEX); - - builder.setDefaultGeometry(JcrUtils.normalize(GisNames.GIS_BBOX)); - builder.add(JcrUtils.normalize(GisNames.GIS_BBOX), Polygon.class); - builder.add(JcrUtils.normalize(GisNames.GIS_CENTROID), Point.class); - - builder.add(JcrUtils.normalize(Property.JCR_UUID), String.class); - builder.add(JcrUtils.normalize(Property.JCR_PATH), String.class); - builder.add(JcrUtils.normalize(Property.JCR_PRIMARY_TYPE), String.class); - // mix:lastModified - builder.add(JcrUtils.normalize(Property.JCR_LAST_MODIFIED), Date.class); - builder.add(JcrUtils.normalize(Property.JCR_LAST_MODIFIED_BY), - String.class); - - return builder.buildFeatureType(); - } - private DataStore dataStore; private Session session; private SystemExecutionService systemExecutionService; + /** The key is the workspace */ + private Map> geoJcrIndexes = Collections + .synchronizedMap(new HashMap>()); + // TODO: use common factory finder? private FilterFactory2 ff = new FilterFactoryImpl(); public void init() { - systemExecutionService.executeAsSystem(new Runnable() { public void run() { - try { - session.getWorkspace() - .getObservationManager() - .addEventListener(GeoJcrIndex.this, - Event.NODE_ADDED | Event.NODE_REMOVED, "/", - true, null, - new String[] { GisTypes.GIS_INDEXED }, - false); - } catch (RepositoryException e) { - throw new ArgeoException("Cannot initialize GeoJcr index", - e); - } - + initGeoJcrIndex(); } }); } - public void dispose() { + protected void initGeoJcrIndex() { + try { + // create GIS schema + SimpleFeatureType indexType = getWorkspaceGeoJcrIndexType(session + .getWorkspace().getName()); + GeoToolsUtils.createSchemaIfNeeded(dataStore, indexType); + + // register JCR listeners + ObservationManager om = session.getWorkspace() + .getObservationManager(); + om.addEventListener(this, Event.NODE_ADDED | Event.NODE_REMOVED, + "/", true, null, null, false); + + // FIXME: use a different listener for properties since it resets + // the filter + // om.addEventListener(this, Event.PROPERTY_CHANGED, "/", + // true, null, new String[] { GIS_LOCATED }, false); + + } catch (RepositoryException e) { + throw new ArgeoException("Cannot initialize GeoJcr index", e); + } } - public void onEvent(EventIterator events) { - SimpleFeatureType indexType = getWorkspaceGeoIndex(session - .getWorkspace().getName()); - GeoToolsUtils.createSchemaIfNeeded(dataStore, indexType); - FeatureStore geoJcrIndex = GeoToolsUtils - .getFeatureStore(dataStore, indexType.getName()); + public void dispose() { + } - FeatureCollection toAdd = FeatureCollections + public void onEvent(final EventIterator events) { + final FeatureCollection toAdd = FeatureCollections .newCollection(); - Set toRemove = new HashSet(); - while (events.hasNext()) { - Event event = events.nextEvent(); - try { - Integer eventType = event.getType(); - if (Event.NODE_ADDED == eventType) { - Node node = session.getNodeByIdentifier(event - .getIdentifier()); - if (node.isNodeType(GisTypes.GIS_LOCATED)) { - SimpleFeature feature = mapNodeToFeature(node, - indexType); - toAdd.add(feature); + final Set toRemove = new HashSet(); + + // execute with system authentication so that JCR can be read + systemExecutionService.executeAsSystem(new Runnable() { + public void run() { + while (events.hasNext()) { + Event event = events.nextEvent(); + try { + Integer eventType = event.getType(); + if (Event.NODE_ADDED == eventType) { + Node node = session.getNodeByIdentifier(event + .getIdentifier()); + if (node.isNodeType(GIS_INDEXED)) { + SimpleFeature feature = mapNodeToFeature(node, + getGeoJcrIndex().getSchema()); + toAdd.add(feature); + } + } else if (Event.NODE_REMOVED == eventType) { + // we have no way to check whether the node was + // actually + // geoindexed without querying the index, this is + // therefore + // more optimal to create a filter with all ideas + // and apply + // a remove later on + String id = event.getIdentifier(); + toRemove.add(ff.featureId(id)); + } else if (Event.PROPERTY_CHANGED == eventType) { + // TODO: monitor changes to SRS, BBOX AND CENTROID + } + } catch (Exception e) { + log.error("Cannot process event " + event, e); } - } else if (Event.NODE_REMOVED == eventType) { - String id = event.getIdentifier(); - toRemove.add(ff.featureId(id)); } - } catch (Exception e) { - log.error("Cannot process event " + event, e); } - } + }); - // persist - // TODO: this may be more optimal to persist in one single transaction, - // but we will loose modifications on all nodes if one fails + // TODO: this may be more optimal to persist in one single + // transaction, + // but we will loose modifications on all nodes if a single one + // fails try { Transaction transaction = new DefaultTransaction(); - geoJcrIndex.setTransaction(transaction); + getGeoJcrIndex().setTransaction(transaction); try { // points - geoJcrIndex.addFeatures(toAdd); + getGeoJcrIndex().addFeatures(toAdd); if (toRemove.size() != 0) - geoJcrIndex.removeFeatures(ff.id(toRemove)); + getGeoJcrIndex().removeFeatures(ff.id(toRemove)); transaction.commit(); } catch (Exception e) { transaction.rollback(); @@ -155,14 +162,44 @@ public class GeoJcrIndex implements EventListener { } } + protected FeatureStore getGeoJcrIndex() { + String workspaceName = session.getWorkspace().getName(); + if (!geoJcrIndexes.containsKey(workspaceName)) { + SimpleFeatureType indexType = getWorkspaceGeoJcrIndexType(workspaceName); + FeatureStore geoIndex = GeoToolsUtils + .getFeatureStore(dataStore, indexType.getName()); + geoJcrIndexes.put(workspaceName, geoIndex); + } + return geoJcrIndexes.get(workspaceName); + } + + protected SimpleFeatureType getWorkspaceGeoJcrIndexType(String workspaceName) { + SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); + builder.setNamespaceURI(GIS_NAMESPACE); + builder.setName(workspaceName + "_geojcr_index"); + + builder.setDefaultGeometry(JcrUtils.normalize(GIS_BBOX)); + builder.add(JcrUtils.normalize(GIS_BBOX), Polygon.class); + builder.add(JcrUtils.normalize(GIS_CENTROID), Point.class); + + builder.add(JcrUtils.normalize("jcr:uuid"), String.class); + builder.add(JcrUtils.normalize("jcr:path"), String.class); + builder.add(JcrUtils.normalize("jcr:primaryType"), String.class); + // mix:lastModified + builder.add(JcrUtils.normalize("jcr:lastModified"), Date.class); + builder.add(JcrUtils.normalize("jcr:lastModifiedBy"), String.class); + + return builder.buildFeatureType(); + } + protected SimpleFeature mapNodeToFeature(Node node, SimpleFeatureType type) { try { SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); Node locatedNode; - if (node.isNodeType(GisTypes.GIS_LOCATED)) { + if (node.isNodeType(GIS_LOCATED)) { locatedNode = node; - } else if (node.isNodeType(GisTypes.GIS_INDEXED)) { + } else if (node.isNodeType(GIS_INDEXED)) { locatedNode = findLocatedparent(node); } else { throw new ArgeoException("Unsupported node " + node); @@ -170,25 +207,23 @@ public class GeoJcrIndex implements EventListener { // TODO: reproject to the feature store SRS Polygon bbox = (Polygon) JtsJcrUtils.readWkb(locatedNode - .getProperty(GisNames.GIS_BBOX)); - builder.set(JcrUtils.normalize(GisNames.GIS_BBOX), bbox); - Polygon centroid = (Polygon) JtsJcrUtils.readWkb(locatedNode - .getProperty(GisNames.GIS_CENTROID)); - builder.set(JcrUtils.normalize(GisNames.GIS_CENTROID), centroid); - - builder.set(JcrUtils.normalize(Property.JCR_UUID), - node.getIdentifier()); - builder.set(JcrUtils.normalize(Property.JCR_PATH), node.getPath()); - builder.set(JcrUtils.normalize(Property.JCR_PRIMARY_TYPE), node + .getProperty(GIS_BBOX)); + builder.set(JcrUtils.normalize(GIS_BBOX), bbox); + Point centroid = (Point) JtsJcrUtils.readWkb(locatedNode + .getProperty(GIS_CENTROID)); + builder.set(JcrUtils.normalize(GIS_CENTROID), centroid); + + builder.set(JcrUtils.normalize("jcr:uuid"), node.getIdentifier()); + builder.set(JcrUtils.normalize("jcr:path"), node.getPath()); + builder.set(JcrUtils.normalize("jcr:primaryType"), node .getPrimaryNodeType().getName()); if (node.hasProperty(Property.JCR_LAST_MODIFIED)) - builder.set(JcrUtils.normalize(Property.JCR_LAST_MODIFIED), - node.getProperty(Property.JCR_LAST_MODIFIED).getDate() - .getTime()); + builder.set(JcrUtils.normalize("jcr:lastModified"), node + .getProperty(Property.JCR_LAST_MODIFIED).getDate() + .getTime()); if (node.hasProperty(Property.JCR_LAST_MODIFIED_BY)) - builder.set(JcrUtils.normalize(Property.JCR_LAST_MODIFIED_BY), - node.getProperty(Property.JCR_LAST_MODIFIED_BY) - .getString()); + builder.set(JcrUtils.normalize("jcr:lastModifiedBy"), node + .getProperty(Property.JCR_LAST_MODIFIED_BY).getString()); return builder.buildFeature(node.getIdentifier()); } catch (RepositoryException e) { throw new ArgeoException("Cannot map " + node + " to " + type, e); @@ -197,7 +232,7 @@ public class GeoJcrIndex implements EventListener { protected Node findLocatedparent(Node child) { try { - if (child.getParent().isNodeType(GisTypes.GIS_LOCATED)) + if (child.getParent().isNodeType(GIS_LOCATED)) return child.getParent(); else return findLocatedparent(child.getParent()); diff --git a/gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/geotools/jcr/GeoJcrMapper.java b/gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/geotools/jcr/GeoJcrMapper.java index b5bf0036f..bb5bab512 100644 --- a/gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/geotools/jcr/GeoJcrMapper.java +++ b/gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/geotools/jcr/GeoJcrMapper.java @@ -10,19 +10,16 @@ import org.geotools.data.FeatureSource; import org.opengis.feature.simple.SimpleFeature; import org.opengis.feature.simple.SimpleFeatureType; +/** + * Maps datastore and feature sources with JCR nodes. It is meant to be + * repository independent. + */ public interface GeoJcrMapper { - // public Node getNode(String dataStoreAlias, - // FeatureSource featureSource, - // SimpleFeature feature); - public Map>> getPossibleFeatureSources(); public Node getFeatureSourceNode(Session session, String dataStoreAlias, FeatureSource featureSource); - // public Node getNode(String dataStoreAlias, - // FeatureSource featureSource); - public Node getFeatureNode(Node featureSource, String featureId); public FeatureSource getFeatureSource( diff --git a/gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/geotools/jcr/SimpleGeoJcrMapper.java b/gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/geotools/jcr/SimpleGeoJcrMapper.java index d36618705..0619e5215 100644 --- a/gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/geotools/jcr/SimpleGeoJcrMapper.java +++ b/gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/geotools/jcr/SimpleGeoJcrMapper.java @@ -23,11 +23,17 @@ import org.argeo.jcr.gis.GisTypes; import org.argeo.jts.jcr.JtsJcrUtils; import org.geotools.data.DataStore; import org.geotools.data.FeatureSource; +import org.geotools.referencing.CRS; import org.opengis.feature.simple.SimpleFeature; import org.opengis.feature.simple.SimpleFeatureType; import org.opengis.feature.type.Name; +import org.opengis.referencing.FactoryException; +import org.opengis.referencing.crs.CoordinateReferenceSystem; +import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Geometry; +import com.vividsolutions.jts.geom.Point; +import com.vividsolutions.jts.geom.Polygon; public class SimpleGeoJcrMapper implements GeoJcrMapper { private final static Log log = LogFactory.getLog(SimpleGeoJcrMapper.class); @@ -37,8 +43,6 @@ public class SimpleGeoJcrMapper implements GeoJcrMapper { private Map registeredDataStores = Collections .synchronizedSortedMap(new TreeMap()); - // private Session session; - public Map>> getPossibleFeatureSources() { Map>> res = new TreeMap>>(); dataStores: for (String alias : registeredDataStores.keySet()) { @@ -102,12 +106,42 @@ public class SimpleGeoJcrMapper implements GeoJcrMapper { Node featureNode = featureSourceNode.addNode(featureId); featureNode.addMixin(GisTypes.GIS_FEATURE); Geometry geometry = (Geometry) feature.getDefaultGeometry(); - featureNode.setProperty(GisNames.GIS_SRS, featureSource - .getSchema().getCoordinateReferenceSystem().getName() - .toString()); + // SRS + String srs; + CoordinateReferenceSystem crs = featureSource.getSchema() + .getCoordinateReferenceSystem(); + try { + Integer epsgCode = CRS.lookupEpsgCode(crs, false); + if (epsgCode != null) + srs = "EPSG:" + epsgCode; + else + srs = crs.toWKT(); + } catch (FactoryException e) { + log.warn("Cannot lookup EPSG code", e); + srs = crs.toWKT(); + } + featureNode.setProperty(GisNames.GIS_SRS, srs); + + Polygon bboxPolygon; + Geometry envelope = geometry.getEnvelope(); + if (envelope instanceof Point) { + Point pt = (Point) envelope; + Coordinate[] coords = new Coordinate[4]; + for (int i = 0; i < coords.length; i++) + coords[i] = pt.getCoordinate(); + bboxPolygon = JtsJcrUtils.getGeometryFactory() + .createPolygon( + JtsJcrUtils.getGeometryFactory() + .createLinearRing(coords), null); + } else if (envelope instanceof Polygon) { + bboxPolygon = (Polygon) envelope; + } else { + throw new ArgeoException("Unsupported envelope format " + + envelope.getClass()); + } bbox = JtsJcrUtils.writeWkb(featureNode.getSession(), - geometry.getEnvelope()); + bboxPolygon); featureNode.setProperty(GisNames.GIS_BBOX, bbox); centroid = JtsJcrUtils.writeWkb(featureNode.getSession(), geometry.getCentroid()); @@ -213,9 +247,4 @@ public class SimpleGeoJcrMapper implements GeoJcrMapper { registeredDataStores .remove(properties.get(GeoToolsConstants.ALIAS_KEY)); } - - // public void setSession(Session session) { - // this.session = session; - // } - } diff --git a/gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/jts/jcr/JtsJcrUtils.java b/gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/jts/jcr/JtsJcrUtils.java index f649f6687..0bfa2e89c 100644 --- a/gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/jts/jcr/JtsJcrUtils.java +++ b/gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/jts/jcr/JtsJcrUtils.java @@ -20,7 +20,11 @@ import com.vividsolutions.jts.io.WKBWriter; /** Utilities depending only from the JTS library. */ public class JtsJcrUtils { private static GeometryFactory geometryFactory = new GeometryFactory(); - private static ThreadLocal wkbWriters = new ThreadLocal(); + private static ThreadLocal wkbWriters = new ThreadLocal() { + protected WKBWriter initialValue() { + return new WKBWriter(); + } + }; private static ThreadLocal wkbReaders = new ThreadLocal() { protected WKBReader initialValue() { return new WKBReader(getGeometryFactory()); diff --git a/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/core/KeyBasedSystemExecutionService.java b/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/core/KeyBasedSystemExecutionService.java index d586d1178..2fc4388af 100644 --- a/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/core/KeyBasedSystemExecutionService.java +++ b/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/core/KeyBasedSystemExecutionService.java @@ -41,6 +41,9 @@ public class KeyBasedSystemExecutionService implements SystemExecutionService { securityContext.setAuthentication(auth); runnable.run(); + + // remove the authentication + securityContext.setAuthentication(null); } }; } diff --git a/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/ArgeoNames.java b/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/ArgeoNames.java index ab6c02123..fd2152798 100644 --- a/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/ArgeoNames.java +++ b/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/ArgeoNames.java @@ -3,8 +3,7 @@ package org.argeo.jcr; /** JCR names in the http://www.argeo.org/argeo namespace */ public interface ArgeoNames { public final static String ARGEO_ = "argeo:"; - + public final static String ARGEO_URI = "argeo:uri"; - public final static String ARGEO_LINK = "argeo:link"; public final static String ARGEO_USER_ID = "argeo:userID"; } diff --git a/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/ArgeoTypes.java b/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/ArgeoTypes.java index 56ef1570a..c8eaa6691 100644 --- a/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/ArgeoTypes.java +++ b/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/ArgeoTypes.java @@ -2,7 +2,7 @@ package org.argeo.jcr; /** JCR types in the http://www.argeo.org/argeo namespace */ public interface ArgeoTypes { - public final static String ARGEO_LINKS = "argeo:links"; + public final static String ARGEO_LINK = "argeo:link"; public final static String ARGEO_HOME = "argeo:home"; public final static String ARGEO_USER_HOME = "argeo:userHome"; } diff --git a/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/JcrUtils.java b/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/JcrUtils.java index 6871e60c7..d9eeb4998 100644 --- a/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/JcrUtils.java +++ b/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/JcrUtils.java @@ -112,9 +112,7 @@ public class JcrUtils { URL u = new URL(url); StringBuffer path = new StringBuffer(url.length()); // invert host - String[] hostTokens = u.getHost().split("\\."); - for (int i = hostTokens.length - 1; i >= 0; i--) - path.append(hostTokens[i]).append('/'); + path.append(hostAsPath(u.getHost())); // we don't put port since it may not always be there and may change path.append(u.getPath()); return path.toString(); @@ -123,6 +121,21 @@ public class JcrUtils { } } + /** + * Creates a path from a FQDN, inverting the order of the component: + * www.argeo.org => org.argeo.www + */ + public static String hostAsPath(String host) { + StringBuffer path = new StringBuffer(host.length()); + String[] hostTokens = host.split("\\."); + for (int i = hostTokens.length - 1; i >= 0; i--) { + path.append(hostTokens[i]); + if (i != 0) + path.append('/'); + } + return path.toString(); + } + /** * The provided data as a path ('/' at the end, not the beginning) * @@ -171,13 +184,6 @@ public class JcrUtils { } - /** Converts the FQDN of an host into a path (converts '.' into '/'). */ - public static String hostAsPath(String host) { - // TODO : inverse order of the elements (to have org/argeo/test IO - // test/argeo/org - return host.replace('.', '/'); - } - /** The last element of a path. */ public static String lastPathElement(String path) { if (path.charAt(path.length() - 1) == '/') @@ -212,7 +218,9 @@ public class JcrUtils { return mkdirs(session, path, type, null, false); } - /** Creates the nodes making path, if they don't exist. */ + /** + * Creates the nodes making path, if they don't exist. + */ public static Node mkdirs(Session session, String path, String type, String intermediaryNodeType, Boolean versioning) { try { diff --git a/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/gis/GisNames.java b/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/gis/GisNames.java index 750c2a594..e8eca58cf 100644 --- a/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/gis/GisNames.java +++ b/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/gis/GisNames.java @@ -2,7 +2,7 @@ package org.argeo.jcr.gis; /** JCR names in the http://www.argeo.org/gis namespace */ public interface GisNames { - public final static String GIS_NAMESPACE = "http://www.argeo.org/gis"; + public final static String GIS_NAMESPACE = "http://www.argeo.org/ns/gis"; public final static String GIS_ = "gis:"; public final static String GIS_SRS = "gis:srs"; diff --git a/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/gis/GisTypes.java b/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/gis/GisTypes.java index 3bd1bc6b2..a943c55ce 100644 --- a/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/gis/GisTypes.java +++ b/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/gis/GisTypes.java @@ -12,5 +12,5 @@ public interface GisTypes { public final static String GIS_DATA_STORE = "gis:dataStore"; public final static String GIS_FEATURE_SOURCE = "gis:featureSource"; public final static String GIS_FEATURE = "gis:feature"; - public final static String GIS_RELATED_FEATURE = "gis:feature"; + public final static String GIS_RELATED_FEATURE = "gis:relatedFeature"; } diff --git a/server/runtime/org.argeo.server.jcr/src/main/resources/org/argeo/jcr/argeo.cnd b/server/runtime/org.argeo.server.jcr/src/main/resources/org/argeo/jcr/argeo.cnd index 532bcdcaf..979e10271 100644 --- a/server/runtime/org.argeo.server.jcr/src/main/resources/org/argeo/jcr/argeo.cnd +++ b/server/runtime/org.argeo.server.jcr/src/main/resources/org/argeo/jcr/argeo.cnd @@ -1,10 +1,10 @@ - + // GENERIC TYPES NOT AVAILABLE IN JCR -[argeo:links] > mix:created, mix:lastModified +[argeo:link] > mix:created, mix:lastModified mixin // URI(s) -- argeo:link (STRING) m * +- argeo:uri (STRING) m // HOME DIRECTORIES [argeo:home] > nt:unstructured, mix:created, mix:lastModified diff --git a/server/runtime/org.argeo.server.jcr/src/main/resources/org/argeo/jcr/gis/argeo_gis.cnd b/server/runtime/org.argeo.server.jcr/src/main/resources/org/argeo/jcr/gis/argeo_gis.cnd index 14c24e7b0..76f029c2d 100644 --- a/server/runtime/org.argeo.server.jcr/src/main/resources/org/argeo/jcr/gis/argeo_gis.cnd +++ b/server/runtime/org.argeo.server.jcr/src/main/resources/org/argeo/jcr/gis/argeo_gis.cnd @@ -1,4 +1,4 @@ - + // GEOMETRIES (based on JTS http://www.vividsolutions.com/jts/JTSHome.htm) [gis:coordinate] > nt:base @@ -27,6 +27,11 @@ abstract mixin // GEOTOOLS [gis:feature] > nt:base mixin +- gis:srs (STRING) m +// WKB +- gis:bbox (BINARY) m +// WKB +- gis:centroid (BINARY) m //- gis:relatedNode (REFERENCE) * [gis:featureSource] > nt:unstructured, mix:title