diff --git a/bot/admin/server/src/main/kotlin/BotAdminVerticle.kt b/bot/admin/server/src/main/kotlin/BotAdminVerticle.kt index ca27b061d2..8c48726c0d 100644 --- a/bot/admin/server/src/main/kotlin/BotAdminVerticle.kt +++ b/bot/admin/server/src/main/kotlin/BotAdminVerticle.kt @@ -1023,7 +1023,7 @@ open class BotAdminVerticle : AdminVerticle() { val applicationDefinition = front.getApplicationById(applicationId.toId()) if (context.organization == applicationDefinition?.namespace) { try { - FaqAdminService.searchTags(applicationDefinition._id.toString()) + FaqAdminService.searchTags(applicationDefinition.name, context.organization) } catch (t: Exception) { logger.error(t) badRequest("Error searching faq tags: ${t.message}") diff --git a/bot/admin/server/src/main/kotlin/FaqAdminService.kt b/bot/admin/server/src/main/kotlin/FaqAdminService.kt index 9d00f2e3ef..21d261e97d 100644 --- a/bot/admin/server/src/main/kotlin/FaqAdminService.kt +++ b/bot/admin/server/src/main/kotlin/FaqAdminService.kt @@ -104,7 +104,7 @@ object FaqAdminService { createOrUpdateUtterances(query, application, intent._id, userLogin) val existingFaqInCurrentApplication = - faqDefinitionDAO.getFaqDefinitionByIntentIdAndBotId(intent._id, query.applicationName) + faqDefinitionDAO.getFaqDefinitionByIntentIdAndBotIdAndNamespace(intent._id, application.name, application.namespace) val i18nLabel: I18nLabel = manageI18nLabelUpdate(query, application.namespace, existingFaqInCurrentApplication) @@ -242,7 +242,10 @@ object FaqAdminService { applicationDefinition: ApplicationDefinition, faqSettings: FaqSettings ) { - val listFaq = faqDefinitionDAO.getFaqDefinitionByBotId(applicationDefinition.name) + val listFaq = faqDefinitionDAO.getFaqDefinitionByBotIdAndNamespace( + applicationDefinition.name, + applicationDefinition.namespace + ) listFaq.forEach { val currentIntent = it.intentId.let { @@ -438,8 +441,8 @@ object FaqAdminService { return Pair(notYetPresentSentences.toList(), noMorePresentSentences.toList()) } - fun searchTags(applicationId: String): List { - return faqDefinitionDAO.getTags(applicationId) + fun searchTags(botId: String, namespace: String): List { + return faqDefinitionDAO.getTags(botId, namespace) } /** diff --git a/nlp/front/service/src/main/kotlin/ApplicationConfigurationService.kt b/nlp/front/service/src/main/kotlin/ApplicationConfigurationService.kt index 5040532f6e..8cb47e1587 100644 --- a/nlp/front/service/src/main/kotlin/ApplicationConfigurationService.kt +++ b/nlp/front/service/src/main/kotlin/ApplicationConfigurationService.kt @@ -327,7 +327,7 @@ object ApplicationConfigurationService : ConfigurationRepository.entityTypeByName(name)?.obfuscated ?: true override fun getFaqsDefinitionByApplicationId(id: Id): List = - getApplicationById(id)?.let { faqDefinitionDAO.getFaqDefinitionByBotId(it.name) } ?: arrayListOf() + getApplicationById(id)?.let { faqDefinitionDAO.getFaqDefinitionByBotIdAndNamespace(it.name, it.namespace) } ?: arrayListOf() override fun getFaqDefinitionByIntentId(id: Id): FaqDefinition? = faqDefinitionDAO.getFaqDefinitionByIntentId(id) diff --git a/nlp/front/service/src/main/kotlin/storage/FaqDefinitionDAO.kt b/nlp/front/service/src/main/kotlin/storage/FaqDefinitionDAO.kt index ddeec8eca4..8295d7c903 100644 --- a/nlp/front/service/src/main/kotlin/storage/FaqDefinitionDAO.kt +++ b/nlp/front/service/src/main/kotlin/storage/FaqDefinitionDAO.kt @@ -40,9 +40,10 @@ interface FaqDefinitionDAO { /** * Retrieve faqDefinition by filtering on the application name [id][ApplicationDefinition] - * @param id the application name + * @param botId the application name + * @param namespace the namespace */ - fun getFaqDefinitionByBotId(id: String): List + fun getFaqDefinitionByBotIdAndNamespace(botId: String, namespace: String): List fun listenFaqDefinitionChanges(listener: () -> Unit) @@ -60,8 +61,9 @@ interface FaqDefinitionDAO { * Retrieve faqDefinition by filtering on intent id [intentId][IntentDefinition] and the application name[botId][ApplicationDefinition] * @param intentId intent id * @param botId the application name + * @param namespace the namespace */ - fun getFaqDefinitionByIntentIdAndBotId(intentId: Id, botId: String): FaqDefinition? + fun getFaqDefinitionByIntentIdAndBotIdAndNamespace(intentId: Id, botId: String, namespace: String): FaqDefinition? /** * Retrieve faq details with total count numbers according to the filter present un [FaqQuery] @@ -75,7 +77,7 @@ interface FaqDefinitionDAO { i18nIds: List>? = null ): Pair, Long> - fun getTags(botId: String): List + fun getTags(botId: String, namespace: String): List /** * Make migration diff --git a/nlp/front/storage-mongo/src/main/kotlin/FaqDefinitionMongoDAO.kt b/nlp/front/storage-mongo/src/main/kotlin/FaqDefinitionMongoDAO.kt index 3629867f09..3216baa605 100644 --- a/nlp/front/storage-mongo/src/main/kotlin/FaqDefinitionMongoDAO.kt +++ b/nlp/front/storage-mongo/src/main/kotlin/FaqDefinitionMongoDAO.kt @@ -116,8 +116,13 @@ object FaqDefinitionMongoDAO : FaqDefinitionDAO { return col.findOneById(id) } - override fun getFaqDefinitionByBotId(id: String): List { - return col.find(FaqDefinition::botId eq id).into(ArrayList()) + override fun getFaqDefinitionByBotIdAndNamespace(botId: String, namespace: String): List { + return col.find( + and( + FaqDefinition::botId eq botId, + FaqDefinition::namespace eq namespace + ) + ).into(ArrayList()) } override fun getFaqDefinitionByIntentId(id: Id): FaqDefinition? { @@ -140,8 +145,12 @@ object FaqDefinitionMongoDAO : FaqDefinitionDAO { return col.find(FaqDefinition::i18nId `in` ids).into(ArrayList()) } - override fun getFaqDefinitionByIntentIdAndBotId(intentId: Id, botId: String): FaqDefinition? { - return col.findOne(FaqDefinition::intentId eq intentId, FaqDefinition::botId eq botId) + override fun getFaqDefinitionByIntentIdAndBotIdAndNamespace(intentId: Id, botId: String, namespace: String): FaqDefinition? { + return col.findOne( + FaqDefinition::intentId eq intentId, + FaqDefinition::namespace eq namespace, + FaqDefinition::botId eq botId + ) } override fun save(faqDefinition: FaqDefinition) { @@ -194,14 +203,15 @@ object FaqDefinitionMongoDAO : FaqDefinitionDAO { /** * Retrieve tags according to the applicationId present in IntentDefinition with aggregation * @param botId : the botId + * @param namespace: the namespace * @return a string list of tags */ - override fun getTags(botId: String): List { + override fun getTags(botId: String, namespace: String): List { return col.aggregate( joinOnIntentDefinition(), match( andNotNull( - filterOnBotId(botId) + filterOnNamespaceAndBotId(botId, namespace) ) ), // unwind : to flat tags array into an object @@ -300,7 +310,7 @@ object FaqDefinitionMongoDAO : FaqDefinitionDAO { filterI18nIds(i18nIds) ), andNotNull( - filterOnBotId(applicationDefinition.name), + filterOnNamespaceAndBotId(applicationDefinition.name, applicationDefinition.namespace), filterTags(), filterEnabled(), ) @@ -336,7 +346,7 @@ object FaqDefinitionMongoDAO : FaqDefinitionDAO { match( andNotNull( andNotNull( - filterOnBotId(applicationDefinition.name), + filterOnNamespaceAndBotId(applicationDefinition.name, applicationDefinition.namespace), filterTags(), filterEnabled(), filterCurrentApplicationClassifiedSentence(applicationDefinition._id), @@ -402,10 +412,10 @@ object FaqDefinitionMongoDAO : FaqDefinitionDAO { private fun FaqQuery.filterEnabled(): Bson? = if (enabled == null) null else FaqQueryResult::enabled eq enabled /** - * Filter on the botId + * Filter on the botId and the namespace */ - private fun filterOnBotId(botId: String): Bson = - FaqDefinition::botId eq botId + private fun filterOnNamespaceAndBotId(botId: String, namespace: String): Bson = + and(FaqDefinition::botId eq botId, FaqDefinition::namespace eq namespace) /** * Group aggregation pipeline to recompose and group data after multiple unwind especially due to utterances unwind