Weather example fixes.
diff --git a/nlpcraft-examples/weather/src/main/java/org/apache/nlpcraft/examples/weather/WeatherModel.java b/nlpcraft-examples/weather/src/main/java/org/apache/nlpcraft/examples/weather/WeatherModel.java
index 5b8b8b8..f8380b6 100644
--- a/nlpcraft-examples/weather/src/main/java/org/apache/nlpcraft/examples/weather/WeatherModel.java
+++ b/nlpcraft-examples/weather/src/main/java/org/apache/nlpcraft/examples/weather/WeatherModel.java
@@ -47,13 +47,16 @@
* <p>
* This is a relatively complete weather service with JSON output and a non-trivial
* intent matching logic. It uses OpenWeather API weather provider REST service for the actual
- * weather information (https://openweathermap.org/api/one-call-api)
+ * weather information (https://openweathermap.org/api/one-call-api).
+ * <p>
+ * NOTE: you must provide OpenWorldMap API key in 'OWM_API_KEY' system property.
+ * See https://openweathermap.org/api for more information.
* <p>
* See 'README.md' file in the same folder for running and testing instructions.
*/
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
public class WeatherModel extends NCModelFileAdapter {
- /* System property for OpenWeatherMap API key. */
+ // System property for OpenWeatherMap API key.
public final String OWM_API_KEY = "OWM_API_KEY";
// Please register your own account at https://openweathermap.org/api and
diff --git a/nlpcraft-examples/weather/src/main/java/org/apache/nlpcraft/examples/weather/openweathermap/OpenWeatherMapService.java b/nlpcraft-examples/weather/src/main/java/org/apache/nlpcraft/examples/weather/openweathermap/OpenWeatherMapService.java
index 2faa068..1d43507 100644
--- a/nlpcraft-examples/weather/src/main/java/org/apache/nlpcraft/examples/weather/openweathermap/OpenWeatherMapService.java
+++ b/nlpcraft-examples/weather/src/main/java/org/apache/nlpcraft/examples/weather/openweathermap/OpenWeatherMapService.java
@@ -50,7 +50,8 @@
*/
public class OpenWeatherMapService {
// GSON response type.
- private static final Type TYPE_RESP = new TypeToken<HashMap<String, Object>>() {}.getType();
+ private static final Type TYPE_RESP = new TypeToken<HashMap<String, Object>>() {
+ }.getType();
// Access key.
private final String key;
@@ -69,8 +70,8 @@
// Can be configured.
private final ExecutorService pool = NCUtils.mkThreadPool(
- "openweather",
- Runtime.getRuntime().availableProcessors() * 8
+ "openweather",
+ Runtime.getRuntime().availableProcessors() * 8
);
/**
@@ -98,8 +99,8 @@
/**
* Constructor.
*
- * @param key Service key.
- * @param maxDaysBack Max days (looking back) configuration value.
+ * @param key Service key.
+ * @param maxDaysBack Max days (looking back) configuration value.
* @param maxDaysForward Max days (looking forward) configuration value.
*/
public OpenWeatherMapService(String key, int maxDaysBack, int maxDaysForward) {
@@ -125,10 +126,9 @@
}
/**
- *
* @param lat Latitude.
* @param lon Longitude.
- * @param d Date.
+ * @param d Date.
* @return REST call result.
*/
private Map<String, Object> get(double lat, double lon, long d) {
@@ -141,7 +141,6 @@
}
/**
- *
* @param url REST endpoint URL.
* @return REST call result.
*/
@@ -167,10 +166,10 @@
/**
* See https://openweathermap.org/api/one-call-api#hist_parameter to extract fields.
*
- * @param lat Latitude.
- * @param lon Longitude.
+ * @param lat Latitude.
+ * @param lon Longitude.
* @param from From date.
- * @param to To date.
+ * @param to To date.
* @return List of REST call results.
* @throws OpenWeatherMapException Thrown in case of any provider errors.
*/
@@ -218,6 +217,6 @@
* @throws OpenWeatherMapException Thrown in case of any provider errors.
*/
public Map<String, Object> getCurrent(double lat, double lon) throws OpenWeatherMapException {
- return get("https://api.openweathermap.org/data/2.5/forecast?lat=" + lat + "&lon=" + lon +"&appid="+ key);
+ return get("https://api.openweathermap.org/data/2.5/forecast?lat=" + lat + "&lon=" + lon + "&appid=" + key);
}
}
diff --git a/nlpcraft-examples/weather/src/test/java/org/apache/nlpcraft/examples/weather/NCModelValidationSpec.scala b/nlpcraft-examples/weather/src/test/java/org/apache/nlpcraft/examples/weather/NCModelValidationSpec.scala
index 6258fe6..136d713 100644
--- a/nlpcraft-examples/weather/src/test/java/org/apache/nlpcraft/examples/weather/NCModelValidationSpec.scala
+++ b/nlpcraft-examples/weather/src/test/java/org/apache/nlpcraft/examples/weather/NCModelValidationSpec.scala
@@ -24,8 +24,20 @@
* JUnit model validation.
*/
class NCModelValidationSpec {
+ private final val propName = "OWM_API_KEY"
+
@Test
def test(): Unit = {
+ // Set your own API key here.
+ var apiKey: String = System.getProperty(propName)
+
+ if (apiKey == null)
+ apiKey = System.getenv(propName)
+
+ // Default value, used for tests.
+ if (apiKey == null)
+ System.setProperty(propName, "8a51a2eb343bf87dc55ffd352f5641ea")
+
// Instruct auto-validator what models to test.
System.setProperty("NLPCRAFT_TEST_MODELS", "org.apache.nlpcraft.examples.weather.WeatherModel")