Repository: incubator-unomi Updated Branches: refs/heads/master 76433205c -> d43e3644d
Add module deleted by mistake in pull request 35 Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/96e5ca6c Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/96e5ca6c Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/96e5ca6c Branch: refs/heads/master Commit: 96e5ca6c0b6de74800d83cf942c24d7c9e2dd597 Parents: 845eeb5 Author: Dinesh <[email protected]> Authored: Wed Nov 29 16:19:14 2017 +0100 Committer: Dinesh <[email protected]> Committed: Wed Nov 29 16:19:14 2017 +0100 ---------------------------------------------------------------------- extensions/pom.xml | 1 + extensions/weather-update/README.md | 42 +++ extensions/weather-update/core/pom.xml | 99 +++++++ .../actions/WeatherUpdateAction.java | 288 +++++++++++++++++++ .../cxs/actions/UpdateWeatherAction.json | 15 + .../sessions/weather/weatherLike.json | 14 + .../sessions/weather/weatherTemp.json | 14 + .../sessions/weather/weatherWindDirection.json | 14 + .../sessions/weather/weatherWindSpeed.json | 14 + .../sessions/weatherSessionProperties.json | 5 + .../resources/OSGI-INF/blueprint/blueprint.xml | 44 +++ .../src/main/resources/messages_en.properties | 18 ++ .../org.apache.unomi.weatherUpdate.cfg | 19 ++ extensions/weather-update/karaf-kar/pom.xml | 81 ++++++ .../karaf-kar/src/main/feature/feature.xml | 28 ++ extensions/weather-update/pom.xml | 36 +++ 16 files changed, 732 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/96e5ca6c/extensions/pom.xml ---------------------------------------------------------------------- diff --git a/extensions/pom.xml b/extensions/pom.xml index abac863..e834413 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -37,6 +37,7 @@ <module>router</module> <module>salesforce-connector</module> <module>unomi-mailchimp</module> + <module>weather-update</module> </modules> </project> http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/96e5ca6c/extensions/weather-update/README.md ---------------------------------------------------------------------- diff --git a/extensions/weather-update/README.md b/extensions/weather-update/README.md new file mode 100644 index 0000000..0bf6e0b --- /dev/null +++ b/extensions/weather-update/README.md @@ -0,0 +1,42 @@ +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one or more + ~ contributor license agreements. See the NOTICE file distributed with + ~ this work for additional information regarding copyright ownership. + ~ The ASF licenses this file to You under the Apache License, Version 2.0 + ~ (the "License"); you may not use this file except in compliance with + ~ the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + + +Apache Unomi Weather Update +================================= + +This extension will retrieve the weather associated with the resolved location of the user (from his IP address) + +## Getting started + +1. Create an new account : + + https://home.openweathermap.org/users/sign_up + +2. Generate a new API Key, or get the default + + https://home.openweathermap.org/api_keys + +3. Configure the Apache Unomi Weather Update. In the etc/org.apache.unomi.weatherUpdate.cfg file +change the following settings: + + weatherUpdate.apiKey=YOUR_WEATHER_APIKEY + +4. 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/${project.version}/xml/features + feature:install unomi-weather-update-karaf-kar http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/96e5ca6c/extensions/weather-update/core/pom.xml ---------------------------------------------------------------------- diff --git a/extensions/weather-update/core/pom.xml b/extensions/weather-update/core/pom.xml new file mode 100755 index 0000000..ede8e15 --- /dev/null +++ b/extensions/weather-update/core/pom.xml @@ -0,0 +1,99 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one or more + ~ contributor license agreements. See the NOTICE file distributed with + ~ this work for additional information regarding copyright ownership. + ~ The ASF licenses this file to You under the Apache License, Version 2.0 + ~ (the "License"); you may not use this file except in compliance with + ~ the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.unomi</groupId> + <artifactId>unomi-weather-update</artifactId> + <version>1.3.0-incubating-SNAPSHOT</version> + </parent> + + <artifactId>unomi-weather-update-core</artifactId> + <name>Apache Unomi :: Extension :: Weather Update :: Core</name> + <description>This is a simple Apache Unomi plugin.</description> + <packaging>bundle</packaging> + + <dependencies> + <dependency> + <groupId>org.apache.unomi</groupId> + <artifactId>unomi-api</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient-osgi</artifactId> + <version>4.5.1</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpcore-osgi</artifactId> + <version>4.4.6</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-databind</artifactId> + <scope>provided</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency> + <Import-Package> + * + </Import-Package> + </instructions> + </configuration> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <executions> + <execution> + <id>attach-artifacts</id> + <phase>package</phase> + <goals> + <goal>attach-artifact</goal> + </goals> + <configuration> + <artifacts> + <artifact> + <file> + src/main/resources/org.apache.unomi.weatherUpdate.cfg + </file> + <type>cfg</type> + <classifier>weatherupdatecfg</classifier> + </artifact> + </artifacts> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/96e5ca6c/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 new file mode 100644 index 0000000..0f9e756 --- /dev/null +++ b/extensions/weather-update/core/src/main/java/org/apache/unomi/weatherupdate/actions/WeatherUpdateAction.java @@ -0,0 +1,288 @@ +/* + + ~ Licensed to the Apache Software Foundation (ASF) under one or more + ~ contributor license agreements. See the NOTICE file distributed with + ~ this work for additional information regarding copyright ownership. + ~ The ASF licenses this file to You under the Apache License, Version 2.0 + ~ (the "License"); you may not use this file except in compliance with + ~ the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. +*/ + +package org.apache.unomi.weatherupdate.actions; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.apache.unomi.api.Event; +import org.apache.unomi.api.Session; +import org.apache.unomi.api.actions.Action; +import org.apache.unomi.api.actions.ActionExecutor; +import org.apache.unomi.api.services.EventService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.Map; + +/** + * Get the weather location of the users by an API + * + * @author dsalhotra + */ +public class WeatherUpdateAction implements ActionExecutor { + + private static final double KELVIN = 273.15; + private static final double ROUND_TO_THE_TENTH = 0.5; + private static final double SECOND_TO_HOUR = 3.6; + private static final String MAIN_INFO_WEATHER = "main"; + private static final String SPEED = "speed"; + private static final String STATUS_CODE = "cod"; + private static final String TEMPERATURE_VALUE = "temp"; + private static final String WEATHER_LIKE_INFO = "weather"; + private static final String WIND = "wind"; + private static final String WIND_DIRECTION_INFO = "deg"; + private static final String WEATHER_TEMPERATURE = "weatherTemperature"; + private static final String WEATHER_LIKE = "weatherLike"; + private static final String WEATHER_WIND_DIRECTION = "weatherWindDirection"; + private static final String WEATHER_WIND_SPEED = "weatherWindSpeed"; + private static final String LOCATION = "location"; + private static final String MESSAGE = "message"; + private static Logger logger = LoggerFactory.getLogger(WeatherUpdateAction.class); + private CloseableHttpClient httpClient; + private String weatherApiKey; + private String weatherUrlBase; + private String weatherUrlAttributes; + + @Override + public int execute(Action action, Event event) { + if (httpClient == null) { + httpClient = HttpClients.createDefault(); + } + + Session session = event.getSession(); + if (weatherApiKey == null || weatherUrlBase == null || weatherUrlAttributes == null) { + logger.warn("Configuration incomplete."); + return EventService.NO_CHANGE; + } + + Map<String, Object> sessionProperties = session.getProperties(); + if (!sessionProperties.containsKey(LOCATION)) { + logger.warn("No location info found in the session."); + return EventService.NO_CHANGE; + } + + Map<String, Double> location = (Map<String, Double>) session.getProperty(LOCATION); + JsonNode currentWeatherData = getWeather(location); + if (currentWeatherData == null) { + logger.error("No response from the request"); + return EventService.NO_CHANGE; + } + + if (currentWeatherData.has(STATUS_CODE) && currentWeatherData.get(STATUS_CODE).asText().equals("200")) { + updateSessionWithWeatherData(currentWeatherData, session); + return EventService.SESSION_UPDATED; + } else { + if (currentWeatherData.has(MESSAGE) && currentWeatherData.has(STATUS_CODE)) { + logger.error("Something went wrong, the status code was {} and the message response was {}", + currentWeatherData.get(STATUS_CODE), + currentWeatherData.get(MESSAGE)); + } else { + logger.error("Something went wrong, the response was {}", currentWeatherData); + } + } + + logger.info("No update made"); + return EventService.NO_CHANGE; + } + + /** + * Do the API call + * + * @param location + * @return the response + */ + private JsonNode getWeather(Map<String, Double> location) { + //Call to OpenWeatherMap + HttpGet httpGet = new HttpGet(weatherUrlBase + "/" + weatherUrlAttributes + + "?lat=" + location.get("lat") + "&lon=" + location.get("lon") + "&appid=" + weatherApiKey); + JsonNode currentWeatherData = null; + CloseableHttpResponse response = null; + try { + response = httpClient.execute(httpGet); + if (response != null) { + HttpEntity entity = response.getEntity(); + String responseString; + if (entity != null) { + try { + responseString = EntityUtils.toString(entity); + ObjectMapper objectMapper = new ObjectMapper(); + currentWeatherData = objectMapper.readTree(responseString); + } catch (IOException e) { + logger.error("Error with the API json response.", e); + } + } + } + } catch (IOException e) { + logger.error("Error with the Http Request execution. Wrong parameters given", e); + } finally { + if (response != null) { + EntityUtils.consumeQuietly(response.getEntity()); + } + } + return currentWeatherData; + } + + /** + * Update the session info with the weather infos + * + * @param currentWeatherData the response from the API + * @param session + */ + private void updateSessionWithWeatherData(JsonNode currentWeatherData, Session session) { + String temperature = extractTemperature(currentWeatherData); + String weatherLike = extractWeatherLike(currentWeatherData); + String windDirection = extractWindDirection(currentWeatherData); + String windSpeed = extractWindSpeed(currentWeatherData); + if (temperature != null) { + session.setProperty(WEATHER_TEMPERATURE, temperature); + } + if (weatherLike != null) { + session.setProperty(WEATHER_LIKE, weatherLike); + } + if (windDirection != null) { + session.setProperty(WEATHER_WIND_DIRECTION, windDirection); + } + if (windSpeed != null) { + session.setProperty(WEATHER_WIND_SPEED, windSpeed); + } + } + + /** + * Extract the temperature property from the response + * + * @param currentWeatherData the response from the API + * @return String temperature in celsius + */ + private String extractTemperature(JsonNode currentWeatherData) { + float temperature; + if (currentWeatherData.has(MAIN_INFO_WEATHER) && currentWeatherData.get(MAIN_INFO_WEATHER).has(TEMPERATURE_VALUE)) { + String responseString = currentWeatherData.get(MAIN_INFO_WEATHER).get(TEMPERATURE_VALUE).asText(); + temperature = Float.parseFloat(responseString); + temperature -= KELVIN; + int temperatureTreated = (int) temperature; + if (temperature - temperatureTreated > ROUND_TO_THE_TENTH) { + temperatureTreated++; + } + logger.debug("Temperature: {}", temperatureTreated); + return String.valueOf(temperatureTreated); + } + logger.info("API Response doesn't contains the temperature"); + return null; + } + + /** + * Extract the wind speed property from the response + * + * @param currentWeatherData the response from the API + * @return String wind speed in km/h + */ + private String extractWindSpeed(JsonNode currentWeatherData) { + JsonNode WindInfoSpeed; + if (currentWeatherData.has(WIND) && currentWeatherData.get(WIND).has(SPEED)) { + WindInfoSpeed = currentWeatherData.get(WIND).get(SPEED); + float speed = Float.parseFloat(WindInfoSpeed.toString()); + speed *= SECOND_TO_HOUR; + int speedTreated = (int) speed; + logger.debug("Wind speed: {}", speedTreated); + return String.valueOf(speedTreated); + } + logger.info("API Response doesn't contains the wind speed"); + return null; + } + + /** + * Extract the wind direction property from the response + * + * @param currentWeatherData the response from the API + * @return String wind direction in cardinal points format + */ + private String extractWindDirection(JsonNode currentWeatherData) { + JsonNode windInfoDirection; + String direction = ""; + if (currentWeatherData.has(WIND)) { + if (currentWeatherData.get(WIND).has(WIND_DIRECTION_INFO)) { + windInfoDirection = currentWeatherData.get(WIND).get(WIND_DIRECTION_INFO); + 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.warn("API Response doesn't contains the wind direction"); + return null; + } + + /** + * Extract the weather like property from the response + * + * @param currentWeatherData the response from the API + * @return String weather like + */ + private String extractWeatherLike(JsonNode currentWeatherData) { + JsonNode weatherLike; + if (currentWeatherData.has(WEATHER_LIKE_INFO)) { + weatherLike = currentWeatherData.get(WEATHER_LIKE_INFO); + if (weatherLike.size() > 0) { + weatherLike = weatherLike.get(0).get(MAIN_INFO_WEATHER); + logger.debug("Weather like: {}", weatherLike); + return weatherLike.asText(); + } + } + logger.warn("API Response doesn't contains the weather description"); + return null; + } + + public void setWeatherApiKey(String weatherApiKey) { + this.weatherApiKey = weatherApiKey; + } + + public void setWeatherUrlBase(String weatherUrlBase) { + this.weatherUrlBase = weatherUrlBase; + } + + public void setWeatherUrlAttributes(String weatherUrlAttributes) { + this.weatherUrlAttributes = weatherUrlAttributes; + } +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/96e5ca6c/extensions/weather-update/core/src/main/resources/META-INF/cxs/actions/UpdateWeatherAction.json ---------------------------------------------------------------------- diff --git a/extensions/weather-update/core/src/main/resources/META-INF/cxs/actions/UpdateWeatherAction.json b/extensions/weather-update/core/src/main/resources/META-INF/cxs/actions/UpdateWeatherAction.json new file mode 100755 index 0000000..5ab40df --- /dev/null +++ b/extensions/weather-update/core/src/main/resources/META-INF/cxs/actions/UpdateWeatherAction.json @@ -0,0 +1,15 @@ +{ + "metadata": { + "id": "weatherUpdateAction", + "name": "Update session with local weather information", + "description": "This action will retrieve the weather associated with the resolved location of the user (from his IP address)", + "systemTags": [ + "event", + "availableToEndUser", + "hasNoTemplate" + ], + "readOnly": true + }, + "actionExecutor": "weatherUpdate", + "parameters": [] +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/96e5ca6c/extensions/weather-update/core/src/main/resources/META-INF/cxs/properties/sessions/weather/weatherLike.json ---------------------------------------------------------------------- diff --git a/extensions/weather-update/core/src/main/resources/META-INF/cxs/properties/sessions/weather/weatherLike.json b/extensions/weather-update/core/src/main/resources/META-INF/cxs/properties/sessions/weather/weatherLike.json new file mode 100755 index 0000000..ad23875 --- /dev/null +++ b/extensions/weather-update/core/src/main/resources/META-INF/cxs/properties/sessions/weather/weatherLike.json @@ -0,0 +1,14 @@ +{ + "metadata": { + "id": "weatherLike", + "name": "Weather Description", + "systemTags": [ + "properties", + "sessionProperties" + ] + }, + "type": "string", + "defaultValue": "", + "automaticMappingsFrom": [], + "rank": "302.0" +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/96e5ca6c/extensions/weather-update/core/src/main/resources/META-INF/cxs/properties/sessions/weather/weatherTemp.json ---------------------------------------------------------------------- diff --git a/extensions/weather-update/core/src/main/resources/META-INF/cxs/properties/sessions/weather/weatherTemp.json b/extensions/weather-update/core/src/main/resources/META-INF/cxs/properties/sessions/weather/weatherTemp.json new file mode 100755 index 0000000..bae8ceb --- /dev/null +++ b/extensions/weather-update/core/src/main/resources/META-INF/cxs/properties/sessions/weather/weatherTemp.json @@ -0,0 +1,14 @@ +{ + "metadata": { + "id": "weatherTemperature", + "name": "Weather Temperature", + "systemTags": [ + "properties", + "sessionProperties" + ] + }, + "type": "integer", + "defaultValue": "", + "automaticMappingsFrom": [], + "rank": "302.0" +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/96e5ca6c/extensions/weather-update/core/src/main/resources/META-INF/cxs/properties/sessions/weather/weatherWindDirection.json ---------------------------------------------------------------------- diff --git a/extensions/weather-update/core/src/main/resources/META-INF/cxs/properties/sessions/weather/weatherWindDirection.json b/extensions/weather-update/core/src/main/resources/META-INF/cxs/properties/sessions/weather/weatherWindDirection.json new file mode 100755 index 0000000..f0629dc --- /dev/null +++ b/extensions/weather-update/core/src/main/resources/META-INF/cxs/properties/sessions/weather/weatherWindDirection.json @@ -0,0 +1,14 @@ +{ + "metadata": { + "id": "weatherWindDirection", + "name": "Weather Wind Direction", + "systemTags": [ + "properties", + "sessionProperties" + ] + }, + "type": "string", + "defaultValue": "", + "automaticMappingsFrom": [], + "rank": "302.0" +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/96e5ca6c/extensions/weather-update/core/src/main/resources/META-INF/cxs/properties/sessions/weather/weatherWindSpeed.json ---------------------------------------------------------------------- diff --git a/extensions/weather-update/core/src/main/resources/META-INF/cxs/properties/sessions/weather/weatherWindSpeed.json b/extensions/weather-update/core/src/main/resources/META-INF/cxs/properties/sessions/weather/weatherWindSpeed.json new file mode 100755 index 0000000..4b668f5 --- /dev/null +++ b/extensions/weather-update/core/src/main/resources/META-INF/cxs/properties/sessions/weather/weatherWindSpeed.json @@ -0,0 +1,14 @@ +{ + "metadata": { + "id": "weatherWindSpeed", + "name": "Weather Wind Speed", + "systemTags": [ + "properties", + "sessionProperties" + ] + }, + "type": "integer", + "defaultValue": "", + "automaticMappingsFrom": [], + "rank": "302.0" +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/96e5ca6c/extensions/weather-update/core/src/main/resources/META-INF/cxs/tags/properties/sessions/weatherSessionProperties.json ---------------------------------------------------------------------- diff --git a/extensions/weather-update/core/src/main/resources/META-INF/cxs/tags/properties/sessions/weatherSessionProperties.json b/extensions/weather-update/core/src/main/resources/META-INF/cxs/tags/properties/sessions/weatherSessionProperties.json new file mode 100755 index 0000000..d634f69 --- /dev/null +++ b/extensions/weather-update/core/src/main/resources/META-INF/cxs/tags/properties/sessions/weatherSessionProperties.json @@ -0,0 +1,5 @@ +{ + "id": "weatherSessionProperties", + "parent": "sessionProperties", + "rank": "1.0" +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/96e5ca6c/extensions/weather-update/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml ---------------------------------------------------------------------- diff --git a/extensions/weather-update/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/extensions/weather-update/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml new file mode 100755 index 0000000..0339ce8 --- /dev/null +++ b/extensions/weather-update/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -0,0 +1,44 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one or more + ~ contributor license agreements. See the NOTICE file distributed with + ~ this work for additional information regarding copyright ownership. + ~ The ASF licenses this file to You under the Apache License, Version 2.0 + ~ (the "License"); you may not use this file except in compliance with + ~ the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> +<blueprint xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0" + xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" + xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> + + <!-- cfg configuration --> + <cm:property-placeholder persistent-id="org.apache.unomi.weatherupdate" + update-strategy="reload"> + <cm:default-properties> + <cm:property name="weatherUpdate.apiKey" value=""/> + <cm:property name="weatherUpdate.url.base" value=""/> + <cm:property name="weatherUpdate.url.attributes" value=""/> + </cm:default-properties> + </cm:property-placeholder> + + <!-- Action executor --> + <service auto-export="interfaces"> + <service-properties> + <entry key="actionExecutorId" value="weatherUpdate"/> + </service-properties> + <bean class="org.apache.unomi.weatherupdate.actions.WeatherUpdateAction"> + <property name="weatherApiKey" value="${weatherUpdate.apiKey}"/> + <property name="weatherUrlBase" value="${weatherUpdate.url.base}"/> + <property name="weatherUrlAttributes" value="${weatherUpdate.url.attributes}"/> + </bean> + </service> +</blueprint> http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/96e5ca6c/extensions/weather-update/core/src/main/resources/messages_en.properties ---------------------------------------------------------------------- diff --git a/extensions/weather-update/core/src/main/resources/messages_en.properties b/extensions/weather-update/core/src/main/resources/messages_en.properties new file mode 100755 index 0000000..3f2dbac --- /dev/null +++ b/extensions/weather-update/core/src/main/resources/messages_en.properties @@ -0,0 +1,18 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +action.weatherUpdateAction.name=Update session with local weather information +action.weatherUpdateAction.description=This action will retrieve the weather associated with the resolved location of the user (from his IP address) http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/96e5ca6c/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 new file mode 100644 index 0000000..aa85dc0 --- /dev/null +++ b/extensions/weather-update/core/src/main/resources/org.apache.unomi.weatherUpdate.cfg @@ -0,0 +1,19 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +weatherUpdate.apiKey=YOUR_WEATHER_APIKEY +weatherUpdate.url.base=http://api.openweathermap.org +weatherUpdate.url.attributes=data/2.5/weather http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/96e5ca6c/extensions/weather-update/karaf-kar/pom.xml ---------------------------------------------------------------------- diff --git a/extensions/weather-update/karaf-kar/pom.xml b/extensions/weather-update/karaf-kar/pom.xml new file mode 100644 index 0000000..ab324b3 --- /dev/null +++ b/extensions/weather-update/karaf-kar/pom.xml @@ -0,0 +1,81 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one or more + ~ contributor license agreements. See the NOTICE file distributed with + ~ this work for additional information regarding copyright ownership. + ~ The ASF licenses this file to You under the Apache License, Version 2.0 + ~ (the "License"); you may not use this file except in compliance with + ~ the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <groupId>org.apache.unomi</groupId> + <artifactId>unomi-weather-update</artifactId> + <version>1.3.0-incubating-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>unomi-weather-update-karaf-kar</artifactId> + <name>Apache Unomi :: Extension :: Weather Update :: Apache Karaf Feature and KAR archive</name> + <description>This is a simple Apache Unomi plugin.</description> + <packaging>kar</packaging> + + <dependencies> + <dependency> + <groupId>org.apache.unomi</groupId> + <artifactId>unomi-api</artifactId> + <version>1.3.0-incubating-SNAPSHOT</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpcore-osgi</artifactId> + <version>4.4.6</version> + </dependency> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient-osgi</artifactId> + <version>4.5.1</version> + </dependency> + + <dependency> + <groupId>org.apache.unomi</groupId> + <artifactId>unomi-weather-update-core</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + + <build> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.apache.karaf.tooling</groupId> + <artifactId>karaf-maven-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <includeTransitiveDependency>false</includeTransitiveDependency> + </configuration> + </plugin> + </plugins> + </pluginManagement> + + <plugins> + <plugin> + <groupId>org.apache.karaf.tooling</groupId> + <artifactId>karaf-maven-plugin</artifactId> + <configuration> + <startLevel>85</startLevel> + </configuration> + </plugin> + </plugins> + </build> +</project> http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/96e5ca6c/extensions/weather-update/karaf-kar/src/main/feature/feature.xml ---------------------------------------------------------------------- diff --git a/extensions/weather-update/karaf-kar/src/main/feature/feature.xml b/extensions/weather-update/karaf-kar/src/main/feature/feature.xml new file mode 100644 index 0000000..2f005a6 --- /dev/null +++ b/extensions/weather-update/karaf-kar/src/main/feature/feature.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one or more + ~ contributor license agreements. See the NOTICE file distributed with + ~ this work for additional information regarding copyright ownership. + ~ The ASF licenses this file to You under the Apache License, Version 2.0 + ~ (the "License"); you may not use this file except in compliance with + ~ the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> +<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.1" name="unomi-weather-update-karaf-feature"> + <feature name="unomi-weather-update-karaf-kar" version="${project.version}" + description="Apache Unomi :: Extensions :: Weather update :: Apache Karaf Feature"> + <details>Apache Karaf feature for the Apache Unomi Context Server extension that integrates Weather + update</details> + <configfile finalname="/etc/org.apache.unomi.weatherUpdate.cfg">mvn:org.apache.unomi/unomi-weather-update-core/${project.version}/cfg/weatherupdatecfg</configfile> + <bundle start-level="85">mvn:org.apache.httpcomponents/httpcore-osgi/4.4.6</bundle> + <bundle start-level="85">mvn:org.apache.httpcomponents/httpclient-osgi/4.5.1</bundle> + <bundle start-level="85">mvn:org.apache.unomi/unomi-weather-update-core/${project.version}</bundle> + </feature> +</features> http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/96e5ca6c/extensions/weather-update/pom.xml ---------------------------------------------------------------------- diff --git a/extensions/weather-update/pom.xml b/extensions/weather-update/pom.xml new file mode 100644 index 0000000..5928c9d --- /dev/null +++ b/extensions/weather-update/pom.xml @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one or more + ~ contributor license agreements. See the NOTICE file distributed with + ~ this work for additional information regarding copyright ownership. + ~ The ASF licenses this file to You under the Apache License, Version 2.0 + ~ (the "License"); you may not use this file except in compliance with + ~ the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.unomi</groupId> + <artifactId>unomi-extensions</artifactId> + <version>1.3.0-incubating-SNAPSHOT</version> + </parent> + + <artifactId>unomi-weather-update</artifactId> + <name>Apache Unomi :: Extension :: Weather Update</name> + <description>Apache Unomi Context Server that get the visitor weather based on his location</description> + <packaging>pom</packaging> + + <modules> + <module>core</module> + <module>karaf-kar</module> + </modules> +</project>
