Add Java Doc and update the README.

Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/acfe90d9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/acfe90d9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/acfe90d9

Branch: refs/heads/master
Commit: acfe90d96db14a4a0b65ae892b6ebb8c480acec3
Parents: 774e801
Author: dinesh1996 <Dragonball21>
Authored: Wed Jul 26 15:56:49 2017 +0200
Committer: dinesh1996 <Dragonball21>
Committed: Thu Aug 3 14:27:18 2017 +0200

----------------------------------------------------------------------
 extensions/weather-update/README.md             |  21 ++--
 .../actions/WeatherUpdateAction.java            | 106 ++++++++++---------
 .../org.apache.unomi.weatherUpdate.cfg          |   2 +-
 3 files changed, 72 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/acfe90d9/extensions/weather-update/README.md
----------------------------------------------------------------------
diff --git a/extensions/weather-update/README.md 
b/extensions/weather-update/README.md
index 0763929..dcc486f 100644
--- a/extensions/weather-update/README.md
+++ b/extensions/weather-update/README.md
@@ -16,15 +16,20 @@
   -->
 
 
-# UnomiWeatherUpdate
-A simple plugin to send Unomi events when a member is logged
+Apache Unomi Unomi Weather Update
+=================================
 
+This sample plugin will retrieve the weather associated with the resolved 
location of the user (from his IP address)
 
-In the etc/org.apache.unomi.weatherupdate.cfg file change the following 
settings:
+## Getting started
 
-        weatherUpdate.apiKey=YOUR_WEATHER_APIKEY
-        
-        
-                <configfile 
finalname="/etc/org.apache.unomi.weatherupdate.cfg">mvn:org.apache.unomi
-                
.samples/weather-update-karaf-kar/${project.version}/cfg/weatherupdatecfg</configfile>
+1.  Configure the Apache Unomi Weather Update. In the 
etc/org.apache.unomi.weatherUpdate.cfg file 
+change the following settings:
 
+         weatherUpdate.apiKey=YOUR_WEATHER_APIKEY
+  
+           
+2. Deploy into Apache Unomi using the following commands from the Apache Karaf 
shell:
+
+        feature:repo-add 
mvn:org.apache.unomi/unomi-weather-update-karaf-kar/1.2.0-incubating-SNAPSHOT/xml/features
+        feature:install unomi-weather-update-karaf-kar

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/acfe90d9/extensions/weather-update/core/src/main/java/org/apache/unomi/weatherupdate/actions/WeatherUpdateAction.java
----------------------------------------------------------------------
diff --git 
a/extensions/weather-update/core/src/main/java/org/apache/unomi/weatherupdate/actions/WeatherUpdateAction.java
 
b/extensions/weather-update/core/src/main/java/org/apache/unomi/weatherupdate/actions/WeatherUpdateAction.java
index e37895e..c3a345e 100644
--- 
a/extensions/weather-update/core/src/main/java/org/apache/unomi/weatherupdate/actions/WeatherUpdateAction.java
+++ 
b/extensions/weather-update/core/src/main/java/org/apache/unomi/weatherupdate/actions/WeatherUpdateAction.java
@@ -57,15 +57,12 @@ public class WeatherUpdateAction implements ActionExecutor {
         }
 
         Session session = event.getSession();
-
         if (!(weatherApiKey == null || weatherUrlBase == null || 
weatherUrlAttributes == null)) {
             Map<String, Object> sessionProperties = session.getProperties();
             if (sessionProperties.containsKey("location")) {
                 Map<String, Double> location = (Map<String, Double>) 
session.getProperty("location");
-                HttpGet httpGet = new HttpGet(weatherUrlBase + "/" + 
weatherUrlAttributes + "?lat=" +
-                        location.get("lat") + "&lon=" + location.get("lon") + 
"&appid=" + weatherApiKey
-                );
-
+                HttpGet httpGet = new HttpGet(weatherUrlBase + "/" + 
weatherUrlAttributes +
+                        "?lat=" + location.get("lat") + "&lon=" + 
location.get("lon") + "&appid=" + weatherApiKey);
                 JsonNode jsonNode = null;
                 CloseableHttpResponse response = null;
                 try {
@@ -114,9 +111,16 @@ public class WeatherUpdateAction implements ActionExecutor 
{
                 }
             }
         }
+        logger.info("No update made.");
         return EventService.NO_CHANGE;
     }
 
+    /**
+     * Extract the temperature property from the response
+     *
+     * @param jsonNode
+     * @return String temperature in celsius
+     */
     private String extractTemperature(JsonNode jsonNode) {
         float temperature;
         if (jsonNode.has("main") && jsonNode.get("main").has("temp")) {
@@ -134,6 +138,12 @@ public class WeatherUpdateAction implements ActionExecutor 
{
         return null;
     }
 
+    /**
+     * Extract the wind speed property from the response
+     *
+     * @param jsonNode
+     * @return String wind speed in km/h
+     */
     private String extractWindSpeed(JsonNode jsonNode) {
         JsonNode WindInfoSpeed;
         if (jsonNode.has("wind") && jsonNode.get("wind").has("speed")) {
@@ -149,56 +159,50 @@ public class WeatherUpdateAction implements 
ActionExecutor {
 
     }
 
+    /**
+     * Extract the wind direction property from the response
+     *
+     * @param jsonNode
+     * @return String wind direction in cardinal points format
+     */
     private String extractWindDirection(JsonNode jsonNode) {
-        JsonNode WindInfoDirection;
+        JsonNode windInfoDirection;
+        String direction = "";
         if (jsonNode.has("wind")) {
-            WindInfoDirection = jsonNode.get("wind").get("deg");
-            String direction = "";
-            float deg = Float.parseFloat(WindInfoDirection.toString());
-            if (11.25 < deg && deg < 348.75) {
-                direction = ("N");
-            } else if (11.25 < deg && deg < 33.75) {
-                direction = ("NNE");
-            } else if (33.75 < deg && deg < 56.25) {
-                direction = ("NE");
-            } else if (56.25 < deg && deg < 78.75) {
-                direction = ("ENE");
-            } else if (78.75 < deg && deg < 101.25) {
-                direction = ("E");
-            } else if (101.25 < deg && deg < 123.75) {
-                direction = ("ESE");
-            } else if (123.75 < deg && deg < 146.25) {
-                direction = ("SE");
-            } else if (146.25 < deg && deg < 168.75) {
-                direction = ("SSE");
-            } else if (168.75 < deg && deg < 191.25) {
-                direction = ("S");
-            } else if (191.25 < deg && deg < 213.75) {
-                direction = ("SSW");
-            } else if (213.75 < deg && deg < 236.25) {
-                direction = ("SW");
-            } else if (236.25 < deg && deg < 258.75) {
-                direction = ("WSW");
-            } else if (258.75 < deg && deg < 281.25) {
-                direction = ("W");
-            } else if (281.25 < deg && deg < 303.75) {
-                direction = ("WNW");
-            } else if (303.75 < deg && deg < 326.25) {
-                direction = ("NW");
-            } else if (326.25 < deg && deg < 348.75) {
-                direction = ("NNW");
+            windInfoDirection = jsonNode.get("wind").get("deg");
+            if (windInfoDirection != null) {
+
+                float deg = Float.parseFloat(windInfoDirection.toString());
+                if (340 < deg && deg < 360 || 0 < deg && deg < 20) {
+                    direction = ("N");
+                } else if (20 < deg && deg < 70) {
+                    direction = ("NE");
+                } else if (70 < deg && deg < 110) {
+                    direction = ("E");
+                } else if (110 < deg && deg < 160) {
+                    direction = ("SE");
+                } else if (160 < deg && deg < 200) {
+                    direction = ("S");
+                } else if (200 < deg && deg < 245) {
+                    direction = ("SW");
+                } else if (245 < deg && deg < 290) {
+                    direction = ("W");
+                } else if (290 < deg && deg < 340) {
+                    direction = ("NW");
+                }
+                logger.debug("Wind direction: " + direction);
+                return direction;
             }
-            logger.debug("Wind direction: " + direction);
-            return direction;
         }
         logger.info("API Response doesn't contains the wind direction");
         return null;
     }
 
     /**
+     * Extract the weather like property from the response
      *
      * @param jsonNode
-     * @return
+     * @return String weather like
      */
     private String extractWeatherLike(JsonNode jsonNode) {
         JsonNode weatherLike;
@@ -215,10 +219,9 @@ public class WeatherUpdateAction implements ActionExecutor 
{
     }
 
     /**
-     *
-     * @param session
-     * @param property
-     * @param value
+     * @param session  the current session
+     * @param property session property to fill
+     * @param value    of property
      */
     private void fillPropreties(Session session, String property, String 
value) {
         session.setProperty(property, value);
@@ -227,6 +230,9 @@ public class WeatherUpdateAction implements ActionExecutor {
     //Setters
 
     /**
+     * +
+     * Set the weatherApiKey
+     *
      * @param weatherApiKey
      */
     public void setWeatherApiKey(String weatherApiKey) {
@@ -234,6 +240,8 @@ public class WeatherUpdateAction implements ActionExecutor {
     }
 
     /**
+     * Set the weatherUrlBase
+     *
      * @param weatherUrlBase
      */
     public void setWeatherUrlBase(String weatherUrlBase) {
@@ -241,6 +249,8 @@ public class WeatherUpdateAction implements ActionExecutor {
     }
 
     /**
+     * Set the weatherUrlAttributes
+     *
      * @param weatherUrlAttributes
      */
     public void setWeatherUrlAttributes(String weatherUrlAttributes) {

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/acfe90d9/extensions/weather-update/core/src/main/resources/org.apache.unomi.weatherUpdate.cfg
----------------------------------------------------------------------
diff --git 
a/extensions/weather-update/core/src/main/resources/org.apache.unomi.weatherUpdate.cfg
 
b/extensions/weather-update/core/src/main/resources/org.apache.unomi.weatherUpdate.cfg
index 475b631..6b8afd1 100644
--- 
a/extensions/weather-update/core/src/main/resources/org.apache.unomi.weatherUpdate.cfg
+++ 
b/extensions/weather-update/core/src/main/resources/org.apache.unomi.weatherUpdate.cfg
@@ -15,6 +15,6 @@
 # limitations under the License.
 #
 
-weatherUpdate.apiKey=3e66ec6001684dad10724dbddaf547e6
+weatherUpdate.apiKey=
 weatherUpdate.url.base=http://api.openweathermap.org
 weatherUpdate.url.attributes=data/2.5/weather

Reply via email to