import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.Executor;
import javax.jcr.Node;
import javax.jcr.Property;
import org.argeo.jcr.gis.GisNames;
import org.argeo.jcr.gis.GisTypes;
import org.argeo.jts.jcr.JtsJcrUtils;
-import org.argeo.security.SystemExecutionService;
import org.geotools.data.DataStore;
import org.geotools.data.DefaultTransaction;
import org.geotools.data.FeatureStore;
import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
import org.geotools.filter.FilterFactoryImpl;
+import org.geotools.referencing.CRS;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.filter.FilterFactory2;
import org.opengis.filter.identity.FeatureId;
+import org.opengis.referencing.FactoryException;
+import org.opengis.referencing.NoSuchAuthorityCodeException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.geom.Polygon;
+/** Index JCR nodes containing or referencing GIS data. */
public class GeoJcrIndex implements EventListener, GisNames, GisTypes {
// PostGIS convention
final static String DEFAULT_GEOM_NAME = "the_geom";
private DataStore dataStore;
private Session session;
- private SystemExecutionService systemExecutionService;
+ private Executor systemExecutionService;
+
+ private String crs = "EPSG:4326";
/** The key is the workspace */
private Map<String, FeatureStore<SimpleFeatureType, SimpleFeature>> geoJcrIndexes = Collections
// TODO: use common factory finder?
private FilterFactory2 ff = new FilterFactoryImpl();
+ /** Expects to execute with system authentication */
public void init() {
- systemExecutionService.executeAsSystem(new Runnable() {
- public void run() {
- initGeoJcrIndex();
- }
- });
+ if (systemExecutionService != null)// legacy
+ systemExecutionService.execute(new Runnable() {
+ public void run() {
+ initGeoJcrIndex();
+ }
+ });
+ else
+ initGeoJcrIndex();
}
protected void initGeoJcrIndex() {
final Set<FeatureId> toRemove = new HashSet<FeatureId>();
// execute with system authentication so that JCR can be read
- systemExecutionService.executeAsSystem(new Runnable() {
+ systemExecutionService.execute(new Runnable() {
public void run() {
while (events.hasNext()) {
Event event = events.nextEvent();
}
protected SimpleFeatureType getWorkspaceGeoJcrIndexType(String workspaceName) {
+
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.setNamespaceURI(GIS_NAMESPACE);
builder.setName(workspaceName + "_geojcr_index");
+ try {
+ builder.setCRS(CRS.decode(crs));
+ } catch (Exception e) {
+ throw new ArgeoException("Cannot set CRS " + crs, e);
+ }
builder.setDefaultGeometry(JcrUtils.normalize(GIS_BBOX));
builder.add(JcrUtils.normalize(GIS_BBOX), Polygon.class);
if (node.isNodeType(GIS_LOCATED)) {
locatedNode = node;
} else if (node.isNodeType(GIS_INDEXED)) {
- locatedNode = findLocatedparent(node);
+ locatedNode = findLocatedParent(node);
} else {
throw new ArgeoException("Unsupported node " + node);
}
}
}
- protected Node findLocatedparent(Node child) {
+ protected Node findLocatedParent(Node child) {
try {
if (child.getParent().isNodeType(GIS_LOCATED))
return child.getParent();
else
- return findLocatedparent(child.getParent());
+ return findLocatedParent(child.getParent());
} catch (Exception e) {
// also if child is root node
throw new ArgeoException("Cannot find located parent", e);
this.session = session;
}
- public void setSystemExecutionService(
- SystemExecutionService systemExecutionService) {
+ public void setSystemExecutionService(Executor systemExecutionService) {
this.systemExecutionService = systemExecutionService;
}