This is an automated email from the ASF dual-hosted git repository.

sergeykamov pushed a commit to branch NLPCRAFT-345
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git

commit 7b6667cac5d45ed64807fecd9b11046335e1cde5
Author: Sergey Kamov <[email protected]>
AuthorDate: Thu Jun 24 15:25:19 2021 +0300

    WIP.
---
 .../openweathermap/OpenWeatherMapService.java      | 23 +++++++++++-----------
 .../examples/weather/NCModelValidationSpec.scala   | 13 ++++++++++++
 .../src/test/resources/openweathermap/api_key.txt  |  1 +
 3 files changed, 25 insertions(+), 12 deletions(-)

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 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS;
  */
 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 @@ public class OpenWeatherMapService {
 
     // Can be configured.
     private final ExecutorService pool = NCUtils.mkThreadPool(
-    "openweather",
-    Runtime.getRuntime().availableProcessors() * 8
+        "openweather",
+        Runtime.getRuntime().availableProcessors() * 8
     );
 
     /**
@@ -98,8 +99,8 @@ public class OpenWeatherMapService {
     /**
      * 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 @@ public class OpenWeatherMapService {
     }
 
     /**
-     *
      * @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 @@ public class OpenWeatherMapService {
     }
 
     /**
-     *
      * @param url REST endpoint URL.
      * @return REST call result.
      */
@@ -167,10 +166,10 @@ public class OpenWeatherMapService {
     /**
      * 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 @@ public class OpenWeatherMapService {
      * @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..465120f 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
@@ -17,6 +17,7 @@
 
 package org.apache.nlpcraft.examples.weather
 
+import org.apache.nlpcraft.common.U
 import org.apache.nlpcraft.model.tools.test.NCTestAutoModelValidator
 import org.junit.jupiter.api.{Assertions, Test}
 
@@ -24,8 +25,20 @@ import org.junit.jupiter.api.{Assertions, Test}
   * JUnit model validation.
   */
 class NCModelValidationSpec {
+    private final val PROP_NAME = "OWM_API_KEY"
+
     @Test
     def test(): Unit = {
+        // Set your own API key here.
+        var apiKey: String = System.getProperty(PROP_NAME)
+
+        if (apiKey == null)
+            apiKey = System.getenv(PROP_NAME)
+
+        // Default value, used for tests.
+        if (apiKey == null)
+            System.setProperty(PROP_NAME, 
U.readResource("openweathermap/api_key.txt").mkString.strip)
+
         // Instruct auto-validator what models to test.
         System.setProperty("NLPCRAFT_TEST_MODELS", 
"org.apache.nlpcraft.examples.weather.WeatherModel")
 
diff --git 
a/nlpcraft-examples/weather/src/test/resources/openweathermap/api_key.txt 
b/nlpcraft-examples/weather/src/test/resources/openweathermap/api_key.txt
new file mode 100644
index 0000000..0a4af6e
--- /dev/null
+++ b/nlpcraft-examples/weather/src/test/resources/openweathermap/api_key.txt
@@ -0,0 +1 @@
+20cb4ca5715a699436af8fab11d234e6
\ No newline at end of file

Reply via email to