You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by ar...@apache.org on 2021/01/25 02:28:26 UTC

[incubator-nlpcraft] branch NLPCRAFT-228 created (now bff04ca)

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

aradzinski pushed a change to branch NLPCRAFT-228
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git.


      at bff04ca  Update NCExternalConfigManager.scala

This branch includes the following new commits:

     new bff04ca  Update NCExternalConfigManager.scala

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[incubator-nlpcraft] 01/01: Update NCExternalConfigManager.scala

Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit bff04ca83927ffd55c31f51ef6950d9f9926783b
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Sun Jan 24 18:28:13 2021 -0800

    Update NCExternalConfigManager.scala
---
 .../common/extcfg/NCExternalConfigManager.scala    | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/extcfg/NCExternalConfigManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/extcfg/NCExternalConfigManager.scala
index 773bfe7..7b74fa6 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/extcfg/NCExternalConfigManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/extcfg/NCExternalConfigManager.scala
@@ -183,6 +183,24 @@ object NCExternalConfigManager extends NCService {
     }
 
     /**
+     *
+     * @param typ Resource type.
+     * @param res Resource name.
+     * @return
+     */
+    private def mkFile(typ: NCResourceType, res: String): File = {
+        val file = mkExtFile(typ, res)
+
+        if (!file.exists() || !file.canRead)
+            throw new NCE(
+                s"Configuration file '$res' not found or not readable. Delete all files from an external " +
+                s"configuration folder '${Config.dir}' and restart."
+            )
+
+        file
+    }
+
+    /**
       *
       * @param typ
       * @param res
@@ -191,7 +209,7 @@ object NCExternalConfigManager extends NCService {
     @throws[NCE]
     def getContent(typ: NCResourceType, res: String, parent: Span = null): String =
         startScopedSpan("getContent", parent, "res" → res) { _ ⇒
-            mkString(U.readFile(mkExtFile(typ, res), "UTF-8"))
+            mkString(U.readFile(mkFile(typ, res), "UTF-8"))
         }
 
     /**
@@ -203,7 +221,7 @@ object NCExternalConfigManager extends NCService {
     @throws[NCE]
     def getStream(typ: NCResourceType, res: String, parent: Span = null): InputStream =
         startScopedSpan("getStream", parent, "res" → res) { _ ⇒
-            new BufferedInputStream(new FileInputStream(mkExtFile(typ, res)))
+            new BufferedInputStream(new FileInputStream(mkFile(typ, res)))
         }
 
     /**