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

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


The following commit(s) were added to refs/heads/NLPCRAFT-41 by this push:
     new ec52019  WIP.
ec52019 is described below

commit ec52019d4a94edcde21dd574db9fdaab010c1a10
Author: Sergey Kamov <[email protected]>
AuthorDate: Mon Aug 24 21:14:18 2020 +0300

    WIP.
---
 nlpcraft/src/main/resources/nlpcraft.conf          |   6 +-
 .../nlpcraft/server/model/NCEnhanceManager.scala   |  58 ++++---
 ...nceSuggestion.scala => NCEnhanceResponse.scala} |  16 +-
 ...ion.scala => NCEnhanceSynonymsSuggestion.scala} |   2 +-
 ...EnhanceSuggestion.scala => NCEnhanceType.scala} |  19 +--
 .../nlpcraft/server/rest/NCBasicRestApi.scala      | 169 +++++++++++----------
 .../apache/nlpcraft/server/rest/NCRestApi.scala    |  14 +-
 .../nlpcraft/server/rest/NCRestManager.scala       |   6 -
 8 files changed, 144 insertions(+), 146 deletions(-)

diff --git a/nlpcraft/src/main/resources/nlpcraft.conf 
b/nlpcraft/src/main/resources/nlpcraft.conf
index 9e181a6..1e6b938 100644
--- a/nlpcraft/src/main/resources/nlpcraft.conf
+++ b/nlpcraft/src/main/resources/nlpcraft.conf
@@ -206,7 +206,11 @@ nlpcraft {
         # spacy.proxy.url=http://localhost:5002
 
         # If ContextWord enricher is enabled as a token provider - defines 
ctxword-server URL.
-        ctxword.url="http://localhost:5000";
+        ctxword {
+            url="http://localhost:5000";
+
+            suggestions.minScore = 0
+       }
     }
 
     # +---------------------+
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/model/NCEnhanceManager.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/model/NCEnhanceManager.scala
index 7d0019a..dbdf99a 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/model/NCEnhanceManager.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/model/NCEnhanceManager.scala
@@ -18,8 +18,8 @@
 package org.apache.nlpcraft.server.model
 
 import java.util.concurrent.atomic.AtomicInteger
-import java.util.concurrent.{CopyOnWriteArrayList, CountDownLatch, TimeUnit}
-import java.util.{List ⇒ JList}
+import java.util.concurrent.{ConcurrentHashMap, CopyOnWriteArrayList, 
CountDownLatch, TimeUnit}
+import java.util.{List ⇒ JList, Map ⇒ JMap}
 
 import com.google.gson.Gson
 import com.google.gson.reflect.TypeToken
@@ -35,6 +35,7 @@ import org.apache.nlpcraft.common.makro.NCMacroParser
 import org.apache.nlpcraft.common.nlp.core.NCNlpPorterStemmer
 import org.apache.nlpcraft.common.util.NCUtils
 import org.apache.nlpcraft.common.{NCE, NCService}
+import org.apache.nlpcraft.server.model.NCEnhanceType._
 import org.apache.nlpcraft.server.probe.NCProbeManager
 
 import scala.collection.JavaConverters._
@@ -45,10 +46,8 @@ import scala.collection._
   */
 object NCEnhanceManager extends NCService {
     // For context word server requests.
-    private final val DFLT_LIMIT: Int = 20
-    private final val MAX_LIMIT: Int = 10000
-    private final val DFLT_MIN_SCORE: Double = 0
-    private final val BATCH_SIZE = 20
+    private final val SUGGS_MAX_LIMIT: Int = 10000
+    private final val SUGGS_BATCH_SIZE = 20
 
     // For warnings.
     private final val MIN_CNT_INTENT = 5
@@ -56,8 +55,16 @@ object NCEnhanceManager extends NCService {
 
     private object Config extends NCConfigurable {
         val urlOpt: Option[String] = 
getStringOpt("nlpcraft.server.ctxword.url")
+        val suggestionsMinScore: Int = 
getInt("nlpcraft.server.ctxword.suggestions.minScore")
+
+        @throws[NCE]
+        def check(): Unit =
+            if (suggestionsMinScore < 0 || suggestionsMinScore > 1)
+                 throw new NCE("Invalid 
'nlpcraft.server.ctxword.suggestions.minScore' parameter value. It should be 
double value between 0 and 1, inclusive")
     }
 
+    Config.check()
+
     case class Suggestion(word: String, score: Double)
     case class RequestData(sentence: String, example: String, elementId: 
String, index: Int)
     case class RestRequestSentence(text: String, indexes: JList[Int])
@@ -117,23 +124,25 @@ object NCEnhanceManager extends NCService {
         seq
     }
 
+    @throws[NCE]
+    def enhance(mdlId: String, types: Seq[NCEnhanceType], parent: Span = 
null): Seq[NCEnhanceResponse] =
+        startScopedSpan("enhance", parent, "modelId" → mdlId) { _ ⇒
+            types.map {
+                case typ@ELEMENTS_SYNONYMS ⇒ NCEnhanceResponse(typ, 
suggestions = Some(suggest(mdlId, parent)))
+                case typ@VALIDATION_ELEMENTS ⇒ NCEnhanceResponse(typ, null)
+            }
+    }
+
     /**
       * TODO:
       * @param mdlId Model ID.
-      * @param minScore Context word server minimal suggestion score (default 
DFLT_MIN_SCORE).
       * Increase it for suggestions count increasing, decrease it to be more 
precise. Range 0 ... 1.
       *
       * @param parent Parent.
       */
     @throws[NCE]
-    def enhance(mdlId: String, minScore: Option[Double], parent: Span = null): 
Map[String, Seq[NCEnhanceSuggestion]] =
-        startScopedSpan(
-            "suggest", parent, "modelId" → mdlId, "minScore" → 
minScore.getOrElse(() ⇒ null)
-        ) { _ ⇒
-            val minScoreVal = minScore.getOrElse(DFLT_MIN_SCORE)
-
-            require(minScoreVal >= 0 && minScoreVal <= 1)
-
+    private def suggest(mdlId: String, parent: Span = null): JMap[String, 
JList[NCEnhanceSynonymsSuggestion]] =
+        startScopedSpan("suggest", parent, "modelId" → mdlId) { _ ⇒
             val url = s"${Config.urlOpt.getOrElse(throw new NCE("Context word 
server is not configured"))}/suggestions"
 
             val mdl = NCProbeManager.getModel(mdlId)
@@ -242,14 +251,14 @@ object NCEnhanceManager extends NCService {
 
             logger.info(s"Data prepared [examples=${examples.size}, 
synonyms=$allSynsCnt, requests=$allReqsCnt]")
 
-            val allSuggs = new java.util.concurrent.ConcurrentHashMap[String, 
JList[Suggestion]]()
+            val allSuggs = new ConcurrentHashMap[String, JList[Suggestion]]()
             val cdl = new CountDownLatch(1)
             val debugs = mutable.HashMap.empty[RequestData, Seq[Suggestion]]
             val cnt = new AtomicInteger(0)
 
             val client = HttpClients.createDefault
 
-            for ((elemId, reqs) ← allReqs; batch ← reqs.sliding(BATCH_SIZE, 
BATCH_SIZE).map(_.toSeq)) {
+            for ((elemId, reqs) ← allReqs; batch ← 
reqs.sliding(SUGGS_BATCH_SIZE, SUGGS_BATCH_SIZE).map(_.toSeq)) {
                 NCUtils.asFuture(
                     _ ⇒ {
                         val post = new HttpPost(url)
@@ -262,10 +271,9 @@ object NCEnhanceManager extends NCService {
                                     RestRequest(
                                         sentences = batch.map(p ⇒ 
RestRequestSentence(p.sentence, Seq(p.index).asJava)).asJava,
                                         // ContextWord server range is (0, 2), 
input range is (0, 1)
-                                        min_score = minScoreVal * 2,
-                                        // If minScore defined, we set big 
limit value and in fact only minimal score
-                                        // is taken into account. Otherwise - 
default value.
-                                        limit = if (minScore.isDefined) 
MAX_LIMIT else DFLT_LIMIT
+                                        min_score = Config.suggestionsMinScore 
* 2,
+                                        // We set big limit value and in fact 
only minimal score is taken into account.
+                                        limit = SUGGS_MAX_LIMIT
                                     )
                                 ),
                                 "UTF-8"
@@ -308,7 +316,7 @@ object NCEnhanceManager extends NCService {
 
             val nonEmptySuggs = allSuggs.asScala.map(p ⇒ p._1 → 
p._2.asScala).filter(_._2.nonEmpty)
 
-            val res = mutable.HashMap.empty[String, 
mutable.ArrayBuffer[NCEnhanceSuggestion]]
+            val res = mutable.HashMap.empty[String, 
mutable.ArrayBuffer[NCEnhanceSynonymsSuggestion]]
 
             nonEmptySuggs.
                 foreach { case (elemId, elemSuggs) ⇒
@@ -332,14 +340,14 @@ object NCEnhanceManager extends NCService {
                                 res.get(elemId) match {
                                     case Some(seq) ⇒ seq
                                     case None ⇒
-                                        val buf = 
mutable.ArrayBuffer.empty[NCEnhanceSuggestion]
+                                        val buf = 
mutable.ArrayBuffer.empty[NCEnhanceSynonymsSuggestion]
 
                                         res += elemId → buf
 
                                         buf
                                 }
 
-                            seq += NCEnhanceSuggestion(sugg.word, sugg.score, 
cnt, sumFactor)
+                            seq += NCEnhanceSynonymsSuggestion(sugg.word, 
sugg.score, cnt, sumFactor)
                         }
                 }
 
@@ -365,6 +373,6 @@ object NCEnhanceManager extends NCService {
                 }
             })
 
-            res
+            res.map(p ⇒ p._1 → p._2.asJava).asJava
         }
 }
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/model/NCEnhanceSuggestion.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/model/NCEnhanceResponse.scala
similarity index 77%
copy from 
nlpcraft/src/main/scala/org/apache/nlpcraft/server/model/NCEnhanceSuggestion.scala
copy to 
nlpcraft/src/main/scala/org/apache/nlpcraft/server/model/NCEnhanceResponse.scala
index d9041a9..d77b6cd 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/model/NCEnhanceSuggestion.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/model/NCEnhanceResponse.scala
@@ -17,16 +17,14 @@
 
 package org.apache.nlpcraft.server.model
 
+import org.apache.nlpcraft.server.model.NCEnhanceType.NCEnhanceType
+
 /**
   * TODO:
-  * @param synonym
-  * @param ctxWorldServerScore
-  * @param suggestedCount
-  * @param totalScore
   */
-case class NCEnhanceSuggestion(
-    synonym: String,
-    ctxWorldServerScore: Double,
-    suggestedCount: Int,
-    totalScore: Double
+case class NCEnhanceResponse(
+    enhanceType: NCEnhanceType,
+    errors: Option[Seq[String]] = None,
+    warnings: Option[Seq[String]] = None,
+    suggestions: Option[AnyRef] = None
 )
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/model/NCEnhanceSuggestion.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/model/NCEnhanceSynonymsSuggestion.scala
similarity index 96%
copy from 
nlpcraft/src/main/scala/org/apache/nlpcraft/server/model/NCEnhanceSuggestion.scala
copy to 
nlpcraft/src/main/scala/org/apache/nlpcraft/server/model/NCEnhanceSynonymsSuggestion.scala
index d9041a9..661d423 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/model/NCEnhanceSuggestion.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/model/NCEnhanceSynonymsSuggestion.scala
@@ -24,7 +24,7 @@ package org.apache.nlpcraft.server.model
   * @param suggestedCount
   * @param totalScore
   */
-case class NCEnhanceSuggestion(
+case class NCEnhanceSynonymsSuggestion(
     synonym: String,
     ctxWorldServerScore: Double,
     suggestedCount: Int,
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/model/NCEnhanceSuggestion.scala
 b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/model/NCEnhanceType.scala
similarity index 76%
rename from 
nlpcraft/src/main/scala/org/apache/nlpcraft/server/model/NCEnhanceSuggestion.scala
rename to 
nlpcraft/src/main/scala/org/apache/nlpcraft/server/model/NCEnhanceType.scala
index d9041a9..0aba13d 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/model/NCEnhanceSuggestion.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/model/NCEnhanceType.scala
@@ -17,16 +17,9 @@
 
 package org.apache.nlpcraft.server.model
 
-/**
-  * TODO:
-  * @param synonym
-  * @param ctxWorldServerScore
-  * @param suggestedCount
-  * @param totalScore
-  */
-case class NCEnhanceSuggestion(
-    synonym: String,
-    ctxWorldServerScore: Double,
-    suggestedCount: Int,
-    totalScore: Double
-)
+object NCEnhanceType extends Enumeration {
+    type NCEnhanceType = Value
+
+    val ELEMENTS_SYNONYMS = Value
+    val VALIDATION_ELEMENTS = Value
+}
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala
index 3228bdf..2347807 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala
@@ -17,6 +17,8 @@
 
 package org.apache.nlpcraft.server.rest
 
+import java.util
+
 import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._
 import akka.http.scaladsl.model.HttpMethods._
 import akka.http.scaladsl.model._
@@ -34,10 +36,10 @@ import 
org.apache.nlpcraft.server.apicodes.NCApiStatusCode.{API_OK, _}
 import org.apache.nlpcraft.server.company.NCCompanyManager
 import org.apache.nlpcraft.server.feedback.NCFeedbackManager
 import org.apache.nlpcraft.server.mdo.{NCQueryStateMdo, NCUserMdo}
+import org.apache.nlpcraft.server.model.{NCEnhanceManager, NCEnhanceType}
 import org.apache.nlpcraft.server.opencensus.NCOpenCensusServerStats
 import org.apache.nlpcraft.server.probe.NCProbeManager
 import org.apache.nlpcraft.server.query.NCQueryManager
-import org.apache.nlpcraft.server.model.NCEnhanceManager
 import org.apache.nlpcraft.server.user.NCUserManager
 import spray.json.DefaultJsonProtocol._
 import spray.json.{JsValue, RootJsonFormat}
@@ -45,7 +47,7 @@ import spray.json.{JsValue, RootJsonFormat}
 import scala.collection.JavaConverters._
 import scala.concurrent.ExecutionContext.Implicits.global
 import scala.concurrent.Future
-import akka.http.scaladsl.coding.{Coders, Gzip, NoCoding}
+import akka.http.scaladsl.coding.Coders
 
 /**
   * REST API default implementation.
@@ -629,49 +631,56 @@ class NCBasicRestApi extends NCRestApi with LazyLogging 
with NCOpenCensusTrace w
         case class Req(
             acsTok: String,
             mdlId: String,
-            minScore: Option[Double]
-        )
-
-        case class Suggestion(
-            synonym: String,
-            score: Double,
-            suggestedCount: Int
-        )
-
-        case class Res(
-            status: String,
-            suggestions: Map[String, Seq[Suggestion]]
+            types: Seq[String]
         )
 
         implicit val reqFmt: RootJsonFormat[Req] = jsonFormat3(Req)
-        implicit val fbFmt: RootJsonFormat[Suggestion] = 
jsonFormat3(Suggestion)
-        implicit val resFmt: RootJsonFormat[Res] = jsonFormat2(Res)
 
         entity(as[Req]) { req ⇒
-            startScopedSpan(
-                "modelEnhance$",
-                "mdlId" → req.mdlId,
-                "minScore" → req.minScore.getOrElse(() ⇒ null),
-                "acsTok" → req.acsTok
-            ) { span ⇒
+            startScopedSpan("modelEnhance$", "mdlId" → req.mdlId, "acsTok" → 
req.acsTok) { span ⇒
                 checkLength("acsTok", req.acsTok, 256)
                 checkLength("mdlId", req.mdlId, 32)
-                checkRangeOpt("score", req.minScore, 0, 1)
+
+                val types =
+                    req.types.map(typ ⇒
+                        try
+                            NCEnhanceType.withName(typ)
+                        catch {
+                            case _: Exception ⇒ throw InvalidField("types")
+                        }
+                    )
 
                 val admin = authenticateAsAdmin(req.acsTok)
 
                 if (!NCProbeManager.getAllProbes(admin.companyId, 
span).exists(_.models.exists(_.id == req.mdlId)))
                     throw new NCE(s"Probe not found for model: ${req.mdlId}")
 
-                val res: Map[String, Seq[Suggestion]] =
-                    NCEnhanceManager.enhance(req.mdlId, req.minScore, span).
-                        map { case (elemId, suggs) ⇒
-                            elemId → suggs.map(p ⇒ Suggestion(p.synonym, 
p.ctxWorldServerScore, p.suggestedCount))
-                        }.toMap
+                val res =
+                    NCEnhanceManager.
+                        enhance(req.mdlId, types, span).
+                        map(resp ⇒ {
+                            // We don't use internal case class here because 
GSON can use only public classes.
+                            // So, we use HashMap.
+                            val m = new util.HashMap[String, Object]()
 
-                complete {
-                    Res(API_OK, res)
-                }
+                            m.put("enhanceType", resp.enhanceType.toString)
+
+                            if (resp.errors.isDefined)
+                                m.put("errors", resp.errors.get.asJava)
+                            if (resp.warnings.isDefined)
+                                m.put("warnings", resp.warnings.get.asJava)
+                            if (resp.suggestions.isDefined)
+                                m.put("suggestions", resp.suggestions.get)
+
+                            m
+
+                        }).asJava
+
+                complete(
+                    HttpResponse(
+                        entity = HttpEntity(ContentTypes.`application/json`, 
GSON.toJson(res))
+                    )
+                )
             }
         }
     }
@@ -1657,7 +1666,7 @@ class NCBasicRestApi extends NCRestApi with LazyLogging 
with NCOpenCensusTrace w
       *
       * @return
       */
-    override def getExceptionHandler: ExceptionHandler = ExceptionHandler {
+    def getExceptionHandler: ExceptionHandler = ExceptionHandler {
         case e: AccessTokenFailure ⇒
             val errMsg = e.getLocalizedMessage
             val code = "NC_INVALID_ACCESS_TOKEN"
@@ -1718,7 +1727,7 @@ class NCBasicRestApi extends NCRestApi with LazyLogging 
with NCOpenCensusTrace w
       *
       * @return
       */
-    override def getRejectionHandler: RejectionHandler =
+    def getRejectionHandler: RejectionHandler =
         RejectionHandler.newBuilder().
             handle {
                 // It doesn't try to process all rejections special way.
@@ -1768,52 +1777,56 @@ class NCBasicRestApi extends NCRestApi with LazyLogging 
with NCOpenCensusTrace w
                 entity = "Unable to serve response within time limit, please 
enhance your calm."
             )
 
-        corsHandler (
-            get {
-                withRequestTimeoutResponse(_ ⇒ timeoutResp) {
-                    path(API / "health") { health$() }
-                }
-            } ~
-            post {
-                encodeResponseWith(Coders.NoCoding, Coders.Gzip) {
-                    withRequestTimeoutResponse(_ ⇒ timeoutResp) {
-                        path(API / "signin") { 
withLatency(M_SIGNIN_LATENCY_MS, signin$) } ~
-                        path(API / "signout") { 
withLatency(M_SIGNOUT_LATENCY_MS, signout$) } ~ {
-                        path(API / "cancel") { 
withLatency(M_CANCEL_LATENCY_MS, cancel$) } ~
-                        path(API / "check") { withLatency(M_CHECK_LATENCY_MS, 
check$) } ~
-                        path(API / "model"/ "enhance") { 
withLatency(M_MODEL_ENHANCE_LATENCY_MS, modelEnhance$) } ~
-                        path(API / "clear"/ "conversation") { 
withLatency(M_CLEAR_CONV_LATENCY_MS, clear$Conversation) } ~
-                        path(API / "clear"/ "dialog") { 
withLatency(M_CLEAR_DIALOG_LATENCY_MS, clear$Dialog) } ~
-                        path(API / "company"/ "add") { 
withLatency(M_COMPANY_ADD_LATENCY_MS, company$Add) } ~
-                        path(API / "company"/ "get") { 
withLatency(M_COMPANY_GET_LATENCY_MS, company$Get) } ~
-                        path(API / "company" / "update") { 
withLatency(M_COMPANY_UPDATE_LATENCY_MS, company$Update) } ~
-                        path(API / "company" / "token" / "reset") { 
withLatency(M_COMPANY_TOKEN_LATENCY_MS, company$Token$Reset) } ~
-                        path(API / "company" / "delete") { 
withLatency(M_COMPANY_DELETE_LATENCY_MS, company$Delete) } ~
-                        path(API / "user" / "get") { 
withLatency(M_USER_GET_LATENCY_MS, user$Get) } ~
-                        path(API / "user" / "add") { 
withLatency(M_USER_ADD_LATENCY_MS, user$Add) } ~
-                        path(API / "user" / "update") { 
withLatency(M_USER_UPDATE_LATENCY_MS, user$Update) } ~
-                        path(API / "user" / "delete") { 
withLatency(M_USER_DELETE_LATENCY_MS, user$Delete) } ~
-                        path(API / "user" / "admin") { 
withLatency(M_USER_ADMIN_LATENCY_MS, user$Admin) } ~
-                        path(API / "user" / "passwd" / "reset") { 
withLatency(M_USER_PASSWD_RESET_LATENCY_MS, user$Password$Reset) } ~
-                        path(API / "user" / "all") { 
withLatency(M_USER_ALL_LATENCY_MS, user$All) } ~
-                        path(API / "feedback"/ "add") { 
withLatency(M_FEEDBACK_ADD_LATENCY_MS, feedback$Add) } ~
-                        path(API / "feedback"/ "all") { 
withLatency(M_FEEDBACK_GET_LATENCY_MS, feedback$All) } ~
-                        path(API / "feedback" / "delete") { 
withLatency(M_FEEDBACK_DELETE_LATENCY_MS, feedback$Delete) } ~
-                        path(API / "probe" / "all") { 
withLatency(M_PROBE_ALL_LATENCY_MS, probe$All) } ~
-                        path(API / "ask") { withLatency(M_ASK_LATENCY_MS, 
ask$) } ~
-                        (path(API / "ask" / "sync") &
-                            entity(as[JsValue]) &
-                            optionalHeaderValueByName("User-Agent") &
-                            extractClientIP
-                        ) {
-                            (req, userAgentOpt, rmtAddr) ⇒
-                                onSuccess(withLatency(M_ASK_SYNC_LATENCY_MS, 
ask$Sync(req, userAgentOpt, rmtAddr))) {
-                                    js ⇒ complete(HttpResponse(entity = 
HttpEntity(ContentTypes.`application/json`, js)))
-                                }
-                        }}
+        handleExceptions(getExceptionHandler) {
+            handleRejections(getRejectionHandler) {
+                corsHandler (
+                    get {
+                        withRequestTimeoutResponse(_ ⇒ timeoutResp) {
+                            path(API / "health") { health$() }
+                        }
+                    } ~
+                    post {
+                        encodeResponseWith(Coders.NoCoding, Coders.Gzip) {
+                            withRequestTimeoutResponse(_ ⇒ timeoutResp) {
+                                path(API / "signin") { 
withLatency(M_SIGNIN_LATENCY_MS, signin$) } ~
+                                path(API / "signout") { 
withLatency(M_SIGNOUT_LATENCY_MS, signout$) } ~ {
+                                path(API / "cancel") { 
withLatency(M_CANCEL_LATENCY_MS, cancel$) } ~
+                                path(API / "check") { 
withLatency(M_CHECK_LATENCY_MS, check$) } ~
+                                path(API / "model"/ "enhance") { 
withLatency(M_MODEL_ENHANCE_LATENCY_MS, modelEnhance$) } ~
+                                path(API / "clear"/ "conversation") { 
withLatency(M_CLEAR_CONV_LATENCY_MS, clear$Conversation) } ~
+                                path(API / "clear"/ "dialog") { 
withLatency(M_CLEAR_DIALOG_LATENCY_MS, clear$Dialog) } ~
+                                path(API / "company"/ "add") { 
withLatency(M_COMPANY_ADD_LATENCY_MS, company$Add) } ~
+                                path(API / "company"/ "get") { 
withLatency(M_COMPANY_GET_LATENCY_MS, company$Get) } ~
+                                path(API / "company" / "update") { 
withLatency(M_COMPANY_UPDATE_LATENCY_MS, company$Update) } ~
+                                path(API / "company" / "token" / "reset") { 
withLatency(M_COMPANY_TOKEN_LATENCY_MS, company$Token$Reset) } ~
+                                path(API / "company" / "delete") { 
withLatency(M_COMPANY_DELETE_LATENCY_MS, company$Delete) } ~
+                                path(API / "user" / "get") { 
withLatency(M_USER_GET_LATENCY_MS, user$Get) } ~
+                                path(API / "user" / "add") { 
withLatency(M_USER_ADD_LATENCY_MS, user$Add) } ~
+                                path(API / "user" / "update") { 
withLatency(M_USER_UPDATE_LATENCY_MS, user$Update) } ~
+                                path(API / "user" / "delete") { 
withLatency(M_USER_DELETE_LATENCY_MS, user$Delete) } ~
+                                path(API / "user" / "admin") { 
withLatency(M_USER_ADMIN_LATENCY_MS, user$Admin) } ~
+                                path(API / "user" / "passwd" / "reset") { 
withLatency(M_USER_PASSWD_RESET_LATENCY_MS, user$Password$Reset) } ~
+                                path(API / "user" / "all") { 
withLatency(M_USER_ALL_LATENCY_MS, user$All) } ~
+                                path(API / "feedback"/ "add") { 
withLatency(M_FEEDBACK_ADD_LATENCY_MS, feedback$Add) } ~
+                                path(API / "feedback"/ "all") { 
withLatency(M_FEEDBACK_GET_LATENCY_MS, feedback$All) } ~
+                                path(API / "feedback" / "delete") { 
withLatency(M_FEEDBACK_DELETE_LATENCY_MS, feedback$Delete) } ~
+                                path(API / "probe" / "all") { 
withLatency(M_PROBE_ALL_LATENCY_MS, probe$All) } ~
+                                path(API / "ask") { 
withLatency(M_ASK_LATENCY_MS, ask$) } ~
+                                (path(API / "ask" / "sync") &
+                                    entity(as[JsValue]) &
+                                    optionalHeaderValueByName("User-Agent") &
+                                    extractClientIP
+                                ) {
+                                    (req, userAgentOpt, rmtAddr) ⇒
+                                        
onSuccess(withLatency(M_ASK_SYNC_LATENCY_MS, ask$Sync(req, userAgentOpt, 
rmtAddr))) {
+                                            js ⇒ complete(HttpResponse(entity 
= HttpEntity(ContentTypes.`application/json`, js)))
+                                        }
+                                }}
+                            }
+                        }
                     }
-                }
+                )
             }
-        )
+        }
     }
 }
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCRestApi.scala 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCRestApi.scala
index 9c0cb5b..837b5c7 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCRestApi.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCRestApi.scala
@@ -17,7 +17,7 @@
 
 package org.apache.nlpcraft.server.rest
 
-import akka.http.scaladsl.server.{ExceptionHandler, RejectionHandler, Route}
+import akka.http.scaladsl.server.Route
 import org.apache.nlpcraft.server.opencensus.NCOpenCensusServerStats
 
 /**
@@ -29,16 +29,4 @@ trait NCRestApi extends NCOpenCensusServerStats {
       * @return
       */
     def getRoute: Route
-
-    /**
-      *
-      * @return
-      */
-    def getExceptionHandler: ExceptionHandler
-
-    /**
-      *
-      * @return
-      */
-    def getRejectionHandler: RejectionHandler
 }
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCRestManager.scala 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCRestManager.scala
index 6884109..640fd6f 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCRestManager.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCRestManager.scala
@@ -38,9 +38,6 @@ object NCRestManager extends NCService {
 
     @volatile private var bindFut: Future[Http.ServerBinding] = _
 
-    @volatile private implicit var handleErrors: ExceptionHandler = _
-    @volatile private implicit var handleRejections: RejectionHandler = _
-
     private final object Config extends NCConfigurable {
         final private val pre = "nlpcraft.server.rest"
 
@@ -75,9 +72,6 @@ object NCRestManager extends NCService {
             "api" → Config.apiImpl
         )
 
-        handleErrors = api.getExceptionHandler
-        handleRejections = api.getRejectionHandler
-
         bindFut = Http().newServerAt(Config.host, 
Config.port).bind(Route.toFunction(api.getRoute))
 
         bindFut.onComplete {

Reply via email to