Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chatbot 625 creating q&a parameters and pages #243

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
################################################################################");
# Attention ce fichier est généré automatiquement !");
# Resources du module io.vertigo.chatbot.commons.domain.questionanswer;
################################################################################");

fldQuestionAnswer$qaId = Question-Answer id
fldQuestionAnswer$question = Question
fldQuestionAnswer$answer = Answer
fldQuestionAnswer$isEnabled = Enabled
fldQuestionAnswer$botId = Chatbot
fldQuestionAnswer$qaCatId = Category

################################################################################");

fldQuestionAnswerCategory$qaCatId = Category id
fldQuestionAnswerCategory$label = Category label
fldQuestionAnswerCategory$isEnabled = Enabled
fldQuestionAnswerCategory$botId = Chatbot

################################################################################");

fldQuestionAnswerIhm$qaId = Question-Answer id
fldQuestionAnswerIhm$question = Question
fldQuestionAnswerIhm$answer = Answer
fldQuestionAnswerIhm$isEnabled = Enabled
fldQuestionAnswerIhm$catId = Category id
fldQuestionAnswerIhm$catLabel = Category

################################################################################");

fldQuestionAnswerCategoryExport$label = Question-Answer category label
fldQuestionAnswerCategoryExport$isEnabled = Enabled

################################################################################");

fldQuestionAnswerExport$question = Question
fldQuestionAnswerExport$answer = Answer
fldQuestionAnswerExport$isEnabled = Enabled

################################################################################");

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
################################################################################");
# Attention ce fichier est généré automatiquement !");
# Resources du module io.vertigo.chatbot.commons.domain.questionanswer;
################################################################################");

fldQuestionAnswer$qaId = id des question/r�ponse
fldQuestionAnswer$question = Question
fldQuestionAnswer$answer = R�ponse
fldQuestionAnswer$isEnabled = Actif
fldQuestionAnswer$botId = Chatbot
fldQuestionAnswer$qaCatId = Cat�gorie

################################################################################");

fldQuestionAnswerCategory$qaCatId = id de la cat�gorie
fldQuestionAnswerCategory$label = Libell� de la cat�gorie
fldQuestionAnswerCategory$isEnabled = Actif
fldQuestionAnswerCategory$botId = Chatbot

################################################################################");

fldQuestionAnswerIhm$qaId = id des question/r�ponse
fldQuestionAnswerIhm$question = Question
fldQuestionAnswerIhm$answer = R�ponse
fldQuestionAnswerIhm$isEnabled = Actif
fldQuestionAnswerIhm$catId = id de la cat�gorie
fldQuestionAnswerIhm$catLabel = Cat�gorie

################################################################################");

fldQuestionAnswerCategoryExport$label = Libell� de la cat�gorie
fldQuestionAnswerCategoryExport$isEnabled = Actif

################################################################################");

fldQuestionAnswerExport$question = Question
fldQuestionAnswerExport$answer = R�ponse
fldQuestionAnswerExport$isEnabled = Actif

################################################################################");
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public enum BotMultilingualResources implements MessageKey {

EXPORT_ZIP_FILENAME,

MULTILINGUAL_RESSOURCES_KO
MULTILINGUAL_RESSOURCES_KO,

QUESTIONANSWER_LIST,

QUESTIONANSWERCATEGORY_LIST,
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ TRAINING_LIST = Models
PERSON_LIST = Persons
TOPICCATEGORY_LIST = Categories
TOPIC_LIST = Topics
QUESTIONANSWER_LIST = Questions / Answers
QUESTIONANSWERCATEGORY_LIST = Categories
CONTEXTVALUE_LIST = Context values
NODE_NOT_UP_TO_DATE = Model was not trained since last modifications. These will not be taken into account by the bot.
UNKNOWNSENTENCEDETAIL_LIST = Unknown sentences
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ TRAINING_LIST = Mod\u00E8les
PERSON_LIST = Droits
TOPICCATEGORY_LIST = Cat\u00E9gories
TOPIC_LIST = Intentions
QUESTIONANSWER_LIST = Questions / R\u00E9ponses
QUESTIONANSWERCATEGORY_LIST = Cat\u00E9gories
CONTEXTVALUE_LIST = Valeurs de contexte
NODE_NOT_UP_TO_DATE = Le mod\u00E8le n'a pas \u00E9t\u00E9 entrain\u00E9 depuis les derni\u00E8res modifications. Celles-ci ne sont donc pas prises en compte par le bot.
UNKNOWNSENTENCEDETAIL_LIST = Messages non reconnus
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.vertigo.chatbot.commons.multilingual.queAnsCategory;

import io.vertigo.core.locale.MessageKey;

public enum QueAnsCategoryMultilingualResources implements MessageKey {

EXPORT_QUEANS_CATEGORIES_FILENAME,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EXPORT_QUEANS_CATEGORIES_FILENAME = export_qa_categories_{0}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EXPORT_QUEANS_CATEGORIES_FILENAME = export_qa_categories_{0}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.vertigo.chatbot.commons.multilingual.questionAnswer;

import io.vertigo.core.locale.MessageKey;

public enum QuestionAnswerMultilingualResources implements MessageKey {

EXPORT_QUESTIONS_ANSWERS_FILENAME,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EXPORT_QUESTIONS_ANSWERS_FILENAME = export_questions_answers_{0}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EXPORT_QUESTIONS_ANSWERS_FILENAME = export_questions_answers_{0}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import io.vertigo.chatbot.commons.multilingual.kindTopic.KindTopicMultilingualResources;
import io.vertigo.chatbot.commons.multilingual.model.ModelMultilingualResources;
import io.vertigo.chatbot.commons.multilingual.person.PersonMultilingualResources;
import io.vertigo.chatbot.commons.multilingual.queAnsCategory.QueAnsCategoryMultilingualResources;
import io.vertigo.chatbot.commons.multilingual.questionAnswer.QuestionAnswerMultilingualResources;
import io.vertigo.chatbot.commons.multilingual.topicFileExport.TopicFileExportMultilingualResources;
import io.vertigo.chatbot.commons.multilingual.topics.TopicsMultilingualResources;
import io.vertigo.chatbot.commons.multilingual.utils.UtilsMultilingualResources;
Expand Down Expand Up @@ -43,6 +45,7 @@ public void init() {
localeManager.add("io.vertigo.chatbot.designer.domain.admin.DtResources", io.vertigo.chatbot.designer.domain.admin.DtResources.values());
localeManager.add("io.vertigo.chatbot.designer.domain.commons.DtResources", io.vertigo.chatbot.designer.domain.commons.DtResources.values());
localeManager.add("io.vertigo.chatbot.commons.domain.topic.DtResources", io.vertigo.chatbot.commons.domain.topic.DtResources.values());
localeManager.add("io.vertigo.chatbot.commons.domain.questionanswer.DtResources", io.vertigo.chatbot.commons.domain.questionanswer.DtResources.values());
localeManager.add("io.vertigo.chatbot.designer.domain.commons.EnumResources", EnumResource.values());
localeManager.add("io.vertigo.chatbot.commons.multilingual.topics.TopicsMultilingualResources", TopicsMultilingualResources.values());
localeManager.add("io.vertigo.chatbot.commons.multilingual.topicFileExport.TopicFileExportMultilingualResources", TopicFileExportMultilingualResources.values());
Expand All @@ -57,7 +60,7 @@ public void init() {
localeManager.add("io.vertigo.chatbot.commons.multilingual.dictionaryEntities.DictionaryEntityMultilingualResources", DictionaryEntityMultilingualResources.values());
localeManager.add("io.vertigo.chatbot.commons.multilingual.extensions.ExtensionsMultilingualResources", ExtensionsMultilingualResources.values());
localeManager.add("io.vertigo.chatbot.commons.multilingual.attachment.AttachmentMultilingualResources", AttachmentMultilingualResources.values());

localeManager.add("io.vertigo.chatbot.commons.multilingual.queAnsCategory.QueAnsCategoryMultilingualResources", QueAnsCategoryMultilingualResources.values());
localeManager.add("io.vertigo.chatbot.commons.multilingual.questionAnswer.QuestionAnswerMultilingualResources", QuestionAnswerMultilingualResources.values());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
package io.vertigo.chatbot.designer.builder.controllers.bot;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.inject.Inject;

import io.vertigo.account.authorization.annotations.Secured;
import io.vertigo.chatbot.commons.domain.Chatbot;
import io.vertigo.chatbot.commons.domain.questionanswer.QuestionAnswerCategory;
import io.vertigo.chatbot.commons.domain.questionanswer.QuestionAnswerIhm;
import io.vertigo.chatbot.designer.builder.services.questionanswer.QuestionAnswerCategoryServices;
import io.vertigo.chatbot.designer.builder.services.questionanswer.QuestionAnswerServices;
import io.vertigo.datamodel.structure.model.DtList;
import io.vertigo.ui.core.ViewContext;
import io.vertigo.ui.core.ViewContextKey;
import io.vertigo.ui.impl.springmvc.argumentresolvers.ViewAttribute;
import io.vertigo.vega.webservice.validation.UiMessageStack;

import static io.vertigo.chatbot.designer.utils.ListUtils.listLimitReached;
import static java.lang.Long.parseLong;

@Controller
@RequestMapping("/bot/{botId}/qacategory")
@Secured("BotUser")
public class QuestionAnswerCategoryDetailController extends AbstractBotCreationController<QuestionAnswerCategory> {

private static final ViewContextKey<QuestionAnswerCategory> categoryListKey = ViewContextKey.of("categoryList");
private static final ViewContextKey<QuestionAnswerCategory> categoryKey = ViewContextKey.of("category");
private static final ViewContextKey<QuestionAnswerIhm> queAnsIhmFromCategoryListKey = ViewContextKey.of("queAnsIhmFromCategoryList");
private static final ViewContextKey<QuestionAnswerIhm> queAnsIhmExceptCategoryListKey = ViewContextKey.of("queAnsIhmExceptCategoryList");
private static final ViewContextKey<String> queAnsIdKey = ViewContextKey.of("queAnsId");
private static final ViewContextKey<String> newQueAnsCatIdKey = ViewContextKey.of("newQueAnsCatId");
private static final ViewContextKey<String> queAnsListToUpdateKey = ViewContextKey.of("queAnsListToUpdate");
private static final ViewContextKey<QuestionAnswerIhm> selectedQueAnsIhmListKey = ViewContextKey.of("selectedQueAnsIhmList");


@Inject
private QuestionAnswerCategoryServices questionAnswerCategoryServices;

@Inject
private QuestionAnswerServices questionAnswerServices;

@GetMapping("/{qaCatId}")
public void initContext(final ViewContext viewContext, final UiMessageStack uiMessageStack, @PathVariable("botId") final Long botId,
@PathVariable("qaCatId") final Long qaCatId) {
final Chatbot bot = initCommonContext(viewContext, uiMessageStack, botId);
final QuestionAnswerCategory queAnsCategory = questionAnswerCategoryServices.getQueAnsCategoryById(bot, qaCatId);
final DtList<QuestionAnswerCategory> queAnsCategoryAllList = questionAnswerCategoryServices.getAllQueAnsCatByBot(bot);
final DtList<QuestionAnswerIhm> questionAnswerIhmFromCategoryList = questionAnswerServices.getQueAnsIhmByCatId(bot, qaCatId);
final DtList<QuestionAnswerIhm> questionAnswerIhmExceptCatList = questionAnswerServices.getAllQueAnsIhmByBotIdExceptACategory(bot, qaCatId);


viewContext.publishDtList(categoryListKey, queAnsCategoryAllList);
viewContext.publishDto(categoryKey, queAnsCategory);
viewContext.publishDtList(queAnsIhmFromCategoryListKey, questionAnswerIhmFromCategoryList);
viewContext.publishDtList(queAnsIhmExceptCategoryListKey, questionAnswerIhmExceptCatList);
viewContext.publishRef(queAnsIdKey, "");
viewContext.publishRef(newQueAnsCatIdKey, "");
viewContext.publishRef(queAnsListToUpdateKey, "");
viewContext.publishDtList(selectedQueAnsIhmListKey, new DtList<>(QuestionAnswerIhm.class));

super.initBreadCrums(viewContext, queAnsCategory);
listLimitReached(viewContext, uiMessageStack);
toModeReadOnly();
}

@GetMapping("/new")
public void getNewCategory(final ViewContext viewContext, final UiMessageStack uiMessageStack, @PathVariable("botId") final Long botId) {
final Chatbot bot = initCommonContext(viewContext, uiMessageStack, botId);
final QuestionAnswerCategory queAnsCategory = questionAnswerCategoryServices.getNewQueAnsCategory(bot);
final DtList<QuestionAnswerCategory> queAnsCategoryAllList = questionAnswerCategoryServices.getAllQueAnsCatByBot(bot);
final DtList<QuestionAnswerIhm> questionAnswerIhmExceptCatList = questionAnswerServices.getAllQueAnsIhmByBot(bot);

viewContext.publishDtList(categoryListKey, queAnsCategoryAllList);
viewContext.publishDto(categoryKey, queAnsCategory);
viewContext.publishDtList(queAnsIhmFromCategoryListKey, new DtList<>(QuestionAnswerIhm.class));
viewContext.publishDtList(queAnsIhmExceptCategoryListKey, questionAnswerIhmExceptCatList);
viewContext.publishRef(queAnsIdKey, "");
viewContext.publishRef(newQueAnsCatIdKey, "");
viewContext.publishRef(queAnsListToUpdateKey, "");
viewContext.publishDtList(selectedQueAnsIhmListKey, new DtList<>(QuestionAnswerIhm.class));

super.initEmptyBreadcrums(viewContext);
listLimitReached(viewContext, uiMessageStack);
toModeCreate();
}

@PostMapping("/_saveQueAnsCategoryChange")
public ViewContext saveQueAnsCategoryChange(final ViewContext viewContext,
final UiMessageStack uiMessageStack,
@ViewAttribute("bot") final Chatbot bot,
@ViewAttribute("category") final QuestionAnswerCategory category,
@ViewAttribute("queAnsId") final String queAnsId,
@ViewAttribute("newQueAnsCatId") final String newQueAnsCatId) {


questionAnswerServices.saveCategoryChange(bot, parseLong(queAnsId), parseLong(newQueAnsCatId));

final DtList<QuestionAnswerIhm> questionAnswerIhmFromCategoryList = questionAnswerServices.getQueAnsIhmByCatId(bot, category.getQaCatId());
final DtList<QuestionAnswerIhm> questionAnswerIhmExceptCatList = questionAnswerServices.getAllQueAnsIhmByBotIdExceptACategory(bot, category.getQaCatId());

viewContext.publishDtList(queAnsIhmFromCategoryListKey, questionAnswerIhmFromCategoryList);
viewContext.publishDtList(queAnsIhmExceptCategoryListKey, questionAnswerIhmExceptCatList);
viewContext.publishRef(queAnsIdKey, "");
viewContext.publishRef(newQueAnsCatIdKey, "");

return viewContext;
}

@PostMapping("/_saveAddingQuestionsAnswers")
public ViewContext saveAddingQuestionsAnswers(final ViewContext viewContext,
final UiMessageStack uiMessageStack,
@ViewAttribute("bot") final Chatbot bot,
@ViewAttribute("category") final QuestionAnswerCategory category,
@ViewAttribute("queAnsListToUpdate") final String queAnsListToUpdate) {


questionAnswerServices.saveQueAnsCategoryChangesFromTopIdsString(bot, queAnsListToUpdate, category.getQaCatId());

final DtList<QuestionAnswerIhm> questionAnswerIhmFromCategoryList = questionAnswerServices.getQueAnsIhmByCatId(bot, category.getQaCatId());
final DtList<QuestionAnswerIhm> questionAnswerIhmExceptCatList = questionAnswerServices.getAllQueAnsIhmByBotIdExceptACategory(bot, category.getQaCatId());


viewContext.publishDtList(queAnsIhmFromCategoryListKey, questionAnswerIhmFromCategoryList);
viewContext.publishDtList(queAnsIhmExceptCategoryListKey, questionAnswerIhmExceptCatList);

return viewContext;
}

@PostMapping("/_save")
public String doSave(final ViewContext viewContext, @ViewAttribute("bot") final Chatbot bot, @ViewAttribute("category") final QuestionAnswerCategory category) {
questionAnswerCategoryServices.saveCategory(bot, category);
return "redirect:/bot/" + category.getBotId() + "/qacategory/" + category.getQaCatId();
}

@PostMapping("/_delete")
public String doDelete(final ViewContext viewContext, @ViewAttribute("bot") final Chatbot bot, @ViewAttribute("category") final QuestionAnswerCategory category) {
questionAnswerCategoryServices.deleteCategory(bot, category.getQaCatId());
return "redirect:/bot/" + bot.getBotId() + "/qacategories/";
}

@PostMapping("/_edit")
public void doEdit() {
toModeEdit();
}

@Override
protected String getBreadCrums(QuestionAnswerCategory object) {
return object.getLabel();
}
}
Loading