de.deepamehta.plugins.geomaps
Class GeomapsPlugin

Show UML class diagram
java.lang.Object
  extended by de.deepamehta.core.osgi.PluginActivator
      extended by de.deepamehta.plugins.geomaps.GeomapsPlugin
All Implemented Interfaces:
PluginContext, PostCreateTopicListener, PostUpdateTopicListener, PreSendTopicListener, EventListener, PluginService, GeomapsService, BundleActivator

public class GeomapsPlugin
extends PluginActivator
implements GeomapsService, PostCreateTopicListener, PostUpdateTopicListener, PreSendTopicListener


Nested Class Summary
private  class GeomapsPlugin.Address
           
 
Field Summary
private static String COOKIE_NO_GEOCODING
           
private static double EARTH_RADIUS_KM
           
private  FacetsService facetsService
           
private static String GEOCODER_URL
           
private  Logger logger
           
private  TopicmapsService topicmapsService
           
 
Fields inherited from class de.deepamehta.core.osgi.PluginActivator
bundle, dms
 
Constructor Summary
GeomapsPlugin()
           
 
Method Summary
private  boolean abortGeocoding()
           
 void addCoordinateToGeomap(long geomapId, long geoCoordId)
          Adds a Geo Coordinate topic to a geomap.
private  Topic findAddress(Topic topic)
           
private  Topic findChildTopic(Topic topic, String topicTypeUri)
          Searches a topic's composite value for a topic of a given type.
private  void geocodeAndStoreFacet(GeomapsPlugin.Address address, Topic topic)
          Geocodes the given address and stores the resulting coordinate as a facet value of the given Address topic.
 GeoCoordinate geoCoordinate(Topic geoCoordTopic)
          Returns the geo coordinate encoded in a Geo Coordinate topic.
 double getDistance(GeoCoordinate coord1, GeoCoordinate coord2)
          Calculates the distance between 2 geo coordinates in kilometer.
 Topic getDomainTopic(long geoCoordId)
          Finds the domain topic that corresponds to a Geo Coordinate topic.
 GeoCoordinate getGeoCoordinate(Topic geoTopic)
          Returns the geo coordinate of a geo-facetted topic (e.g.
private  Topic getGeoCoordinateTopic(Topic geoTopic)
          Returns the Geo Coordinate topic (including its child topics) of a geo-facetted topic (e.g.
 Geomap getGeomap(long geomapId)
           
 void init()
           
 void postCreateTopic(Topic topic)
           
 void postUpdateTopic(Topic topic, TopicModel newModel, TopicModel oldModel)
           
 void preSendTopic(Topic topic)
          Enriches an Address topic with its geo coordinate.
 void setGeomapState(long geomapId, double lon, double lat, int zoom)
           
private  void storeGeoCoordinate(Topic address, GeoCoordinate geoCoord)
          Stores a geo coordinate for an address topic in the DB.
 
Methods inherited from class de.deepamehta.core.osgi.PluginActivator
getBundleContext, getPluginName, getStaticResource, getUri, postInstall, publishDirectory, serviceArrived, serviceGone, setCoreService, shutdown, start, stop, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

GEOCODER_URL

private static final String GEOCODER_URL
See Also:
Constant Field Values

COOKIE_NO_GEOCODING

private static final String COOKIE_NO_GEOCODING
See Also:
Constant Field Values

EARTH_RADIUS_KM

private static final double EARTH_RADIUS_KM
See Also:
Constant Field Values

topicmapsService

private TopicmapsService topicmapsService

facetsService

private FacetsService facetsService

logger

private Logger logger
Constructor Detail

GeomapsPlugin

public GeomapsPlugin()
Method Detail

getGeomap

public Geomap getGeomap(long geomapId)
Specified by:
getGeomap in interface GeomapsService

getDomainTopic

public Topic getDomainTopic(long geoCoordId)
Description copied from interface: GeomapsService
Finds the domain topic that corresponds to a Geo Coordinate topic.

Specified by:
getDomainTopic in interface GeomapsService

getGeoCoordinate

public GeoCoordinate getGeoCoordinate(Topic geoTopic)
Description copied from interface: GeomapsService
Returns the geo coordinate of a geo-facetted topic (e.g. an Address), or null if no geo coordinate is stored.

Specified by:
getGeoCoordinate in interface GeomapsService
Returns:
the geo coordinate, or null.

geoCoordinate

public GeoCoordinate geoCoordinate(Topic geoCoordTopic)
Description copied from interface: GeomapsService
Returns the geo coordinate encoded in a Geo Coordinate topic.

Specified by:
geoCoordinate in interface GeomapsService

addCoordinateToGeomap

public void addCoordinateToGeomap(long geomapId,
                                  long geoCoordId)
Description copied from interface: GeomapsService
Adds a Geo Coordinate topic to a geomap.

Specified by:
addCoordinateToGeomap in interface GeomapsService

setGeomapState

public void setGeomapState(long geomapId,
                           double lon,
                           double lat,
                           int zoom)
Specified by:
setGeomapState in interface GeomapsService

getDistance

public double getDistance(GeoCoordinate coord1,
                          GeoCoordinate coord2)
Description copied from interface: GeomapsService
Calculates the distance between 2 geo coordinates in kilometer.

Specified by:
getDistance in interface GeomapsService

init

public void init()
Specified by:
init in interface PluginContext
Overrides:
init in class PluginActivator

postCreateTopic

public void postCreateTopic(Topic topic)
Specified by:
postCreateTopic in interface PostCreateTopicListener

postUpdateTopic

public void postUpdateTopic(Topic topic,
                            TopicModel newModel,
                            TopicModel oldModel)
Specified by:
postUpdateTopic in interface PostUpdateTopicListener

preSendTopic

public void preSendTopic(Topic topic)
Enriches an Address topic with its geo coordinate.

Specified by:
preSendTopic in interface PreSendTopicListener

getGeoCoordinateTopic

private Topic getGeoCoordinateTopic(Topic geoTopic)
Returns the Geo Coordinate topic (including its child topics) of a geo-facetted topic (e.g. an Address), or null if no geo coordinate is stored.


geocodeAndStoreFacet

private void geocodeAndStoreFacet(GeomapsPlugin.Address address,
                                  Topic topic)
Geocodes the given address and stores the resulting coordinate as a facet value of the given Address topic. If geocoding (or storing the coordinate) fails a warning is logged; no exception is thrown.

Parameters:
topic - the Address topic to be facetted.

storeGeoCoordinate

private void storeGeoCoordinate(Topic address,
                                GeoCoordinate geoCoord)
Stores a geo coordinate for an address topic in the DB.


findAddress

private Topic findAddress(Topic topic)

findChildTopic

private Topic findChildTopic(Topic topic,
                             String topicTypeUri)
Searches a topic's composite value for a topic of a given type. The search is driven by the topic's type definition. In other words, composite value entries which do not adhere to the topic's type definition are not found. Note: this is an in-memory search; the DB is not accessed.

The first topic found is returned, according to a depth-first search. For multiple-value fields only the first topic is returned.

TODO: make this a generally available method by adding it to the Topic interface?


abortGeocoding

private boolean abortGeocoding()


Copyright © 2014. All Rights Reserved.