GeoJcrIndex working
authorMathieu Baudier <mbaudier@argeo.org>
Fri, 11 Mar 2011 15:29:07 +0000 (15:29 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Fri, 11 Mar 2011 15:29:07 +0000 (15:29 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@4286 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

16 files changed:
gis/plugins/org.argeo.gis.ui.rap.openlayers/src/main/java/org/argeo/gis/ui/rap/openlayers/OpenLayersMapViewer.java
gis/plugins/org.argeo.gis.ui/src/main/java/org/argeo/gis/ui/commands/AddFeatureSources.java
gis/plugins/org.argeo.gis.ui/src/main/java/org/argeo/gis/ui/editors/MapFormPage.java
gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/geotools/GeoToolsUtils.java
gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/geotools/jcr/GeoJcrIndex.java
gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/geotools/jcr/GeoJcrMapper.java
gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/geotools/jcr/SimpleGeoJcrMapper.java
gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/jts/jcr/JtsJcrUtils.java
security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/core/KeyBasedSystemExecutionService.java
server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/ArgeoNames.java
server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/ArgeoTypes.java
server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/JcrUtils.java
server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/gis/GisNames.java
server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/gis/GisTypes.java
server/runtime/org.argeo.server.jcr/src/main/resources/org/argeo/jcr/argeo.cnd
server/runtime/org.argeo.server.jcr/src/main/resources/org/argeo/jcr/gis/argeo_gis.cnd

index 1228611fe6dcefdceaf94505fbf5c1940fdd347a..b82259b122f793c461ca94ee6e33a3e31a7bae82 100644 (file)
@@ -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);
 
index 7c83fad8768755b019b85583ee9d90ceb12ddd85..ee12806fed776a08bb472432b1071612b6422265 100644 (file)
@@ -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;
        }
 
index c84816571c4a79c07eab21d91f49e1203ec243cc..5c454d2c9d9531551fe46a96ab3f1eeb6fce0f13 100644 (file)
@@ -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();
+               }
+
+       }
 }
index c154f4b97920d410874d32faa851c0487bf6df14..fb5ad5b76a816844b15f494f3d47228010ef4f5e 100644 (file)
@@ -57,7 +57,7 @@ public class GeoToolsUtils {
                                dataStore.createSchema(featureType);
                        } catch (IOException e1) {
                                throw new ArgeoException("Cannot create schema " + featureType,
-                                               e);
+                                               e1);
                        }
                }
        }
index e1c3db1f151402ff65f2e29d6bb4339f96059f86..a1175abc72a384daec388dc3618623a7eb6c84a7 100644 (file)
@@ -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<String, FeatureStore<SimpleFeatureType, SimpleFeature>> geoJcrIndexes = Collections
+                       .synchronizedMap(new HashMap<String, FeatureStore<SimpleFeatureType, SimpleFeature>>());
+
        // 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<SimpleFeatureType, SimpleFeature> geoJcrIndex = GeoToolsUtils
-                               .getFeatureStore(dataStore, indexType.getName());
+       public void dispose() {
+       }
 
-               FeatureCollection<SimpleFeatureType, SimpleFeature> toAdd = FeatureCollections
+       public void onEvent(final EventIterator events) {
+               final FeatureCollection<SimpleFeatureType, SimpleFeature> toAdd = FeatureCollections
                                .newCollection();
-               Set<FeatureId> toRemove = new HashSet<FeatureId>();
-               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<FeatureId> toRemove = new HashSet<FeatureId>();
+
+               // 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<SimpleFeatureType, SimpleFeature> getGeoJcrIndex() {
+               String workspaceName = session.getWorkspace().getName();
+               if (!geoJcrIndexes.containsKey(workspaceName)) {
+                       SimpleFeatureType indexType = getWorkspaceGeoJcrIndexType(workspaceName);
+                       FeatureStore<SimpleFeatureType, SimpleFeature> 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());
index b5bf0036f5a3e9560b27d5a6badded2c6eed95c6..bb5bab512bad1cece592fda06e609f747a77b358 100644 (file)
@@ -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<SimpleFeatureType, SimpleFeature> featureSource,
-       // SimpleFeature feature);
-
        public Map<String, List<FeatureSource<SimpleFeatureType, SimpleFeature>>> getPossibleFeatureSources();
 
        public Node getFeatureSourceNode(Session session, String dataStoreAlias,
                        FeatureSource<SimpleFeatureType, SimpleFeature> featureSource);
 
-       // public Node getNode(String dataStoreAlias,
-       // FeatureSource<SimpleFeatureType, SimpleFeature> featureSource);
-
        public Node getFeatureNode(Node featureSource, String featureId);
 
        public FeatureSource<SimpleFeatureType, SimpleFeature> getFeatureSource(
index d3661870546011cef32c9434f2afb785f2e6590c..0619e521565917f29e6b8fa7ac818cd82737cc4c 100644 (file)
@@ -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<String, DataStore> registeredDataStores = Collections
                        .synchronizedSortedMap(new TreeMap<String, DataStore>());
 
-       // private Session session;
-
        public Map<String, List<FeatureSource<SimpleFeatureType, SimpleFeature>>> getPossibleFeatureSources() {
                Map<String, List<FeatureSource<SimpleFeatureType, SimpleFeature>>> res = new TreeMap<String, List<FeatureSource<SimpleFeatureType, SimpleFeature>>>();
                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;
-       // }
-
 }
index f649f6687c553104d0b0fcdcb1b7bc20a867ee86..0bfa2e89c4d48e8329516b29e173c3f078d91507 100644 (file)
@@ -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<WKBWriter> wkbWriters = new ThreadLocal<WKBWriter>();
+       private static ThreadLocal<WKBWriter> wkbWriters = new ThreadLocal<WKBWriter>() {
+               protected WKBWriter initialValue() {
+                       return new WKBWriter();
+               }
+       };
        private static ThreadLocal<WKBReader> wkbReaders = new ThreadLocal<WKBReader>() {
                protected WKBReader initialValue() {
                        return new WKBReader(getGeometryFactory());
index d586d1178268af09ed507bea46390eac1c41ef33..2fc4388afbca2de6411e400bc7303ad2248caf38 100644 (file)
@@ -41,6 +41,9 @@ public class KeyBasedSystemExecutionService implements SystemExecutionService {
                                securityContext.setAuthentication(auth);
 
                                runnable.run();
+
+                               // remove the authentication
+                               securityContext.setAuthentication(null);
                        }
                };
        }
index ab6c021234ebdea8b2b77bf63a814c0816451420..fd215279811d2c8928340b7d7f5815158c182f66 100644 (file)
@@ -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";
 }
index 56ef1570abf26e0b3b6db82256fe53a446ee2f9d..c8eaa6691ab8093a9438b01e103c2171969ff259 100644 (file)
@@ -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";
 }
index 6871e60c76a57a1f1479aff03003f246596315b9..d9eeb4998d6c1a648fba54c719661bf65450a62a 100644 (file)
@@ -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 {
index 750c2a594a71a0bca37deb875fcad2f9cf13530d..e8eca58cfce16d9123909820cd8dd4d26e54982b 100644 (file)
@@ -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";
index 3bd1bc6b22570183c4fdc58778b9fff22d5d003e..a943c55cef93b46d36d28504c33bb1c86e557c0e 100644 (file)
@@ -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";
 }
index 532bcdcafafc8fd51d76d717c52f20a58cd3c8ec..979e102713bb73856a4c079b72340738024cb992 100644 (file)
@@ -1,10 +1,10 @@
-<argeo = 'http://www.argeo.org/argeo'>
+<argeo = 'http://www.argeo.org/ns/argeo'>
 
 // 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
index 14c24e7b06843f640b9fa5753ffc2942598ebc79..76f029c2d9d844280e19e158d7faad1b1fe2645f 100644 (file)
@@ -1,4 +1,4 @@
-<gis = 'http://www.argeo.org/gis'>
+<gis = 'http://www.argeo.org/ns/gis'>
 
 // 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