Skip to content

Commit

Permalink
Remove entries from geospatial index (#633).
Browse files Browse the repository at this point in the history
Once a Geo Coordinate topic is deleted (e.g. when an Address is deleted) the corresponding entry is removed from the geospatial index.

NOTE: this module is still experimental. Only use it with a testing DB.

See #633.

-----------------------------------------------------------------------

CORRECT COMMIT MESSAGE FOR PREVIOUS COMMIT:

Update geospatial index (#633).

Once a Geo Coordinate topic changes (e.g. when an Address is changed) the geospatial index is updated accordingly.

See #633.
  • Loading branch information
jri committed Aug 9, 2014
1 parent 36fc1fe commit af280fd
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import de.deepamehta.core.service.annotation.ConsumesService;
import de.deepamehta.core.service.event.PostCreateTopicListener;
import de.deepamehta.core.service.event.PostUpdateTopicListener;
import de.deepamehta.core.service.event.PreDeleteTopicListener;

import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.GraphDatabaseService;
Expand Down Expand Up @@ -48,7 +49,8 @@
@Produces("application/json")
public class GeospatialPlugin extends PluginActivator implements GeospatialService, PointFactory,
PostCreateTopicListener,
PostUpdateTopicListener {
PostUpdateTopicListener,
PreDeleteTopicListener {

// ------------------------------------------------------------------------------------------------------- Constants

Expand Down Expand Up @@ -123,6 +125,9 @@ public void init() {
GraphDatabaseService neo4j = (GraphDatabaseService) dms.getDatabaseVendorObject();
SpatialDatabaseService spatialDB = new SpatialDatabaseService(neo4j);
//
// IMPORTANT: deleting a Neo4j Spatial layer includes deleting the geometry nodes which are at the same time
// our Geo Coordinate topics. This results in a corrupted DM database as associations with only 1 player remain.
// --> Never delete a layer!!!
// spatialDB.deleteLayer(DEFAULT_LAYER_NAME, new NullListener());
//
if (spatialDB.containsLayer(DEFAULT_LAYER_NAME)) {
Expand Down Expand Up @@ -178,6 +183,17 @@ public void postUpdateTopic(Topic topic, TopicModel newModel, TopicModel oldMode
}
}

// ---

@Override
public void preDeleteTopic(Topic topic, Directives directives) {
if (topic.getTypeUri().equals("dm4.geomaps.geo_coordinate")) {
logger.info("########## A Geo Coordinate topic was deleted: " + topic);
layer.removeFromIndex(topic.getId());
logger.info("########## Geo Coordinate " + topic.getId() + " removed from geospatial index");
}
}



// ------------------------------------------------------------------------------------------------- Private Methods
Expand Down

0 comments on commit af280fd

Please sign in to comment.