Index: lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/service/ChatOutputFactory.java =================================================================== diff -u -rcdf0794ac8a26a5fe88b0db3a941994a41e8de97 -rc4dfe712e2f4adc4d448e5653df6430eb2949002 --- lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/service/ChatOutputFactory.java (.../ChatOutputFactory.java) (revision cdf0794ac8a26a5fe88b0db3a941994a41e8de97) +++ lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/service/ChatOutputFactory.java (.../ChatOutputFactory.java) (revision c4dfe712e2f4adc4d448e5653df6430eb2949002) @@ -59,14 +59,9 @@ Chat chat = (Chat) toolContentObject; // adding all existing conditions chatMessagesDefinition.setDefaultConditions(new ArrayList(chat.getConditions())); - // if no conditions were created in the tool instance, a default condition is added; the condition is - // persisted in ChatService. + // if no conditions were created in the tool instance, a default condition is added; if (chatMessagesDefinition.getDefaultConditions().isEmpty()) { - String name = buildConditionName(ChatConstants.TEXT_SEARCH_DEFINITION_NAME, chat.getToolContentId() - .toString()); - // Default condition checks if messages contain word "LAMS" - ChatCondition defaultCondition = new ChatCondition(null, null, 1, name, getI18NText( - ChatConstants.TEXT_SEARCH_DEFAULT_CONDITION_DISPLAY_NAME_KEY, false), "LAMS", null, null, null); + ChatCondition defaultCondition = createDefaultComplexCondition(chat); chat.getConditions().add(defaultCondition); chatMessagesDefinition.getDefaultConditions().add(defaultCondition); } @@ -159,4 +154,18 @@ private boolean isTextSearchConditionName(String name) { return name != null && name.startsWith(ChatConstants.TEXT_SEARCH_DEFINITION_NAME); } + + /** + * Creates a default condition so teachers know how to use complex conditions for this tool. + * + * @param chat + * content of the tool + * @return default chat condition + */ + protected ChatCondition createDefaultComplexCondition(Chat chat) { + String name = buildConditionName(ChatConstants.TEXT_SEARCH_DEFINITION_NAME, chat.getToolContentId().toString()); + // Default condition checks if messages contain word "LAMS" + return new ChatCondition(null, null, 1, name, getI18NText( + ChatConstants.TEXT_SEARCH_DEFAULT_CONDITION_DISPLAY_NAME_KEY, false), "LAMS", null, null, null); + } } \ No newline at end of file Index: lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/service/ChatService.java =================================================================== diff -u -rcd0d0b28a7c27711a74ce2b41821f3ccf5c80df9 -rc4dfe712e2f4adc4d448e5653df6430eb2949002 --- lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/service/ChatService.java (.../ChatService.java) (revision cd0d0b28a7c27711a74ce2b41821f3ccf5c80df9) +++ lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/service/ChatService.java (.../ChatService.java) (revision c4dfe712e2f4adc4d448e5653df6430eb2949002) @@ -388,14 +388,8 @@ if (chat == null) { chat = getDefaultContent(); } - // If there are no user added conditions, the default condition will be added in the output factory. It also - // needs to be persisted. - boolean defaultConditionToBeAdded = chat.getConditions().isEmpty(); - SortedMap map = getChatOutputFactory().getToolOutputDefinitions(chat); - if (defaultConditionToBeAdded && !chat.getConditions().isEmpty()) { - saveOrUpdateChat(chat); - } - return map; + + return getChatOutputFactory().getToolOutputDefinitions(chat); } /* IChatService Methods */ @@ -418,6 +412,9 @@ ChatService.logger.error(error); throw new ChatException(error); } + if (defaultContent.getConditions().isEmpty()) { + defaultContent.getConditions().add(getChatOutputFactory().createDefaultComplexCondition(defaultContent)); + } return defaultContent; } Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumOutputFactory.java =================================================================== diff -u -rcdf0794ac8a26a5fe88b0db3a941994a41e8de97 -rc4dfe712e2f4adc4d448e5653df6430eb2949002 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumOutputFactory.java (.../ForumOutputFactory.java) (revision cdf0794ac8a26a5fe88b0db3a941994a41e8de97) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumOutputFactory.java (.../ForumOutputFactory.java) (revision c4dfe712e2f4adc4d448e5653df6430eb2949002) @@ -67,23 +67,9 @@ Forum forum = (Forum) toolContentObject; // adding all existing conditions chosenTopicAnswersDefinition.setDefaultConditions(new ArrayList(forum.getConditions())); - // if no conditions were created in the tool instance, a default condition is added; the condition is - // persisted in ForumService. + // if no conditions were created in the tool instance, a default condition is added; if (chosenTopicAnswersDefinition.getDefaultConditions().isEmpty() && !forum.getMessages().isEmpty()) { - Set messages = new HashSet(); - for (Message message : (Set) forum.getMessages()) { - if (message.getIsAuthored()) { - messages.add(message); - break; - } - } - - String name = buildConditionName(ForumConstants.TEXT_SEARCH_DEFINITION_NAME, forum.getContentId() - .toString()); - // Default condition checks if the answers for the first topic contain word "LAMS" - ForumCondition defaultCondition = new ForumCondition(null, null, 1, name, getI18NText( - ForumConstants.TEXT_SEARCH_DEFAULT_CONDITION_DISPLAY_NAME_KEY, false), "LAMS", null, null, - null, messages); + ForumCondition defaultCondition = createDefaultComplexCondition(forum); forum.getConditions().add(defaultCondition); chosenTopicAnswersDefinition.getDefaultConditions().add(defaultCondition); } @@ -202,4 +188,31 @@ private boolean isTextSearchConditionName(String name) { return name != null && name.startsWith(ForumConstants.TEXT_SEARCH_DEFINITION_NAME); } + + /** + * Creates a default condition so teachers know how to use complex conditions for this tool. + * + * @param forum + * content of the tool + * @return default Forum condition + */ + protected ForumCondition createDefaultComplexCondition(Forum forum) { + + if (forum.getMessages().isEmpty()) { + return null; + } + Set messages = new HashSet(); + for (Message message : (Set) forum.getMessages()) { + if (message.getIsAuthored()) { + messages.add(message); + break; + } + } + + String name = buildConditionName(ForumConstants.TEXT_SEARCH_DEFINITION_NAME, forum.getContentId().toString()); + // Default condition checks if the answers for the first topic contain word "LAMS" + return new ForumCondition(null, null, 1, name, getI18NText( + ForumConstants.TEXT_SEARCH_DEFAULT_CONDITION_DISPLAY_NAME_KEY, false), "LAMS", null, null, null, + messages); + } } Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java =================================================================== diff -u -rc081e2b0c9c82fc97d2d39fb7109c9c2f10ff224 -rc4dfe712e2f4adc4d448e5653df6430eb2949002 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java (.../ForumService.java) (revision c081e2b0c9c82fc97d2d39fb7109c9c2f10ff224) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java (.../ForumService.java) (revision c4dfe712e2f4adc4d448e5653df6430eb2949002) @@ -851,15 +851,8 @@ Forum forum = getForumByContentId(toolContentId); if (forum == null) { forum = getDefaultForum(); - } // If there are no user added conditions, the default condition will be added in the output factory. It - // also - // needs to be persisted. - boolean defaultConditionToBeAdded = forum.getConditions().isEmpty(); - SortedMap map = getForumOutputFactory().getToolOutputDefinitions(forum); - if (defaultConditionToBeAdded && !forum.getConditions().isEmpty()) { - updateForum(forum); } - return map; + return getForumOutputFactory().getToolOutputDefinitions(forum); } /** @@ -964,6 +957,9 @@ } Forum defaultContent = getDefaultForum(); + if (defaultContent.getConditions().isEmpty()) { + defaultContent.getConditions().add(getForumOutputFactory().createDefaultComplexCondition(defaultContent)); + } // get default content by given ID. Forum content = new Forum(); content = Forum.newInstance(defaultContent, contentID, forumToolContentHandler); Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/IQaService.java =================================================================== diff -u -r97aceb8f087c5d2613e004dc2be171ac8acae574 -rc4dfe712e2f4adc4d448e5653df6430eb2949002 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/IQaService.java (.../IQaService.java) (revision 97aceb8f087c5d2613e004dc2be171ac8acae574) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/IQaService.java (.../IQaService.java) (revision c4dfe712e2f4adc4d448e5653df6430eb2949002) @@ -294,4 +294,6 @@ public String createConditionName(Collection existingConditions); public void deleteCondition(QaCondition condition); + + public QaCondition createDefaultComplexCondition(QaContent qaContent); } Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaOutputFactory.java =================================================================== diff -u -rcdf0794ac8a26a5fe88b0db3a941994a41e8de97 -rc4dfe712e2f4adc4d448e5653df6430eb2949002 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaOutputFactory.java (.../QaOutputFactory.java) (revision cdf0794ac8a26a5fe88b0db3a941994a41e8de97) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaOutputFactory.java (.../QaOutputFactory.java) (revision c4dfe712e2f4adc4d448e5653df6430eb2949002) @@ -63,17 +63,10 @@ QaContent qaContent = (QaContent) toolContentObject; // adding all existing conditions allAnswersDefinition.setDefaultConditions(new ArrayList(qaContent.getConditions())); - // if no conditions were created in the tool instance, a default condition is added; the condition is - // persisted in QaService. + // if no conditions were created in the tool instance, a default condition is added; if (allAnswersDefinition.getDefaultConditions().isEmpty() && !qaContent.getQaQueContents().isEmpty()) { - Set questions = new HashSet(); - questions.add((QaQueContent) qaContent.getQaQueContents().iterator().next()); - String name = buildConditionName(QaAppConstants.TEXT_SEARCH_DEFINITION_NAME, qaContent.getQaContentId() - .toString()); - // Default condition checks if the first answer contains word "LAMS" - QaCondition defaultCondition = new QaCondition(null, null, 1, name, getI18NText( - QaAppConstants.TEXT_SEARCH_DEFAULT_CONDITION_DISPLAY_NAME_KEY, false), "LAMS", null, null, - null, questions); + + QaCondition defaultCondition = createDefaultComplexCondition(qaContent); qaContent.getConditions().add(defaultCondition); allAnswersDefinition.getDefaultConditions().add(defaultCondition); @@ -169,4 +162,25 @@ private boolean isTextSearchConditionName(String name) { return name != null && name.startsWith(QaAppConstants.TEXT_SEARCH_DEFINITION_NAME); } + + /** + * Creates a default condition so teachers know how to use complex conditions for this tool. + * + * @param qaContent + * content of the tool + * @return default Q&A condition + */ + protected QaCondition createDefaultComplexCondition(QaContent qaContent) { + if (qaContent.getQaQueContents().isEmpty()) { + return null; + } + Set questions = new HashSet(); + questions.add((QaQueContent) qaContent.getQaQueContents().iterator().next()); + String name = buildConditionName(QaAppConstants.TEXT_SEARCH_DEFINITION_NAME, qaContent.getQaContentId() + .toString()); + // Default condition checks if the first answer contains word "LAMS" + return new QaCondition(null, null, 1, name, getI18NText( + QaAppConstants.TEXT_SEARCH_DEFAULT_CONDITION_DISPLAY_NAME_KEY, false), "LAMS", null, null, null, + questions); + } } \ No newline at end of file Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaServicePOJO.java =================================================================== diff -u -r97aceb8f087c5d2613e004dc2be171ac8acae574 -rc4dfe712e2f4adc4d448e5653df6430eb2949002 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaServicePOJO.java (.../QaServicePOJO.java) (revision 97aceb8f087c5d2613e004dc2be171ac8acae574) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaServicePOJO.java (.../QaServicePOJO.java) (revision c4dfe712e2f4adc4d448e5653df6430eb2949002) @@ -740,12 +740,12 @@ { QaServicePOJO.logger.debug("start of copyToolContent with ids: " + fromContentId + " and " + toContentId); - + long defaultContentId = 0; if (fromContentId == null) { QaServicePOJO.logger.debug("fromContentId is null."); QaServicePOJO.logger.debug("attempt retrieving tool's default content id with signatute : " + QaAppConstants.MY_SIGNATURE); - long defaultContentId = 0; + try { defaultContentId = getToolDefaultContentIdBySignature(QaAppConstants.MY_SIGNATURE); fromContentId = new Long(defaultContentId); @@ -770,7 +770,6 @@ QaServicePOJO.logger.debug("fromContent is null."); QaServicePOJO.logger.debug("attempt retrieving tool's default content id with signatute : " + QaAppConstants.MY_SIGNATURE); - long defaultContentId = 0; try { defaultContentId = getToolDefaultContentIdBySignature(QaAppConstants.MY_SIGNATURE); fromContentId = new Long(defaultContentId); @@ -782,9 +781,12 @@ } fromContent = qaDAO.loadQaById(fromContentId.longValue()); + QaServicePOJO.logger.debug("using fromContent: " + fromContent); } - + if (fromContentId.equals(defaultContentId) && fromContent != null && fromContent.getConditions().isEmpty()) { + fromContent.getConditions().add(getQaOutputFactory().createDefaultComplexCondition(fromContent)); + } QaServicePOJO.logger.debug("final - retrieved fromContent: " + fromContent); QaServicePOJO.logger.debug("final - before new instance using " + fromContent + " and " + toContentId); @@ -1059,6 +1061,9 @@ if (toolContentObj == null) { long defaultToolContentId = toolService.getToolDefaultContentIdBySignature(QaAppConstants.MY_SIGNATURE); toolContentObj = retrieveQa(defaultToolContentId); + if (toolContentObj != null && toolContentObj.getConditions().isEmpty()) { + toolContentObj.getConditions().add(getQaOutputFactory().createDefaultComplexCondition(toolContentObj)); + } } if (toolContentObj == null) { throw new DataMissingException("Unable to find default content for the question and answer tool"); @@ -1149,15 +1154,11 @@ if (qaContent == null) { long defaultToolContentId = toolService.getToolDefaultContentIdBySignature(QaAppConstants.MY_SIGNATURE); qaContent = retrieveQa(defaultToolContentId); + if (qaContent != null && qaContent.getConditions().isEmpty()) { + qaContent.getConditions().add(getQaOutputFactory().createDefaultComplexCondition(qaContent)); + } } - // If there are no user added conditions, the default condition will be added in the output factory. It also - // needs to be persisted. - boolean defaultConditionToBeAdded = qaContent.getConditions().isEmpty(); - SortedMap map = getQaOutputFactory().getToolOutputDefinitions(qaContent); - if (defaultConditionToBeAdded && !qaContent.getConditions().isEmpty()) { - updateQa(qaContent); - } - return map; + return getQaOutputFactory().getToolOutputDefinitions(qaContent); } /** @@ -1236,6 +1237,9 @@ } qaContent = qaDAO.loadQaById(toolContentID.longValue()); + if (qaContent.getConditions().isEmpty()) { + qaContent.getConditions().add(getQaOutputFactory().createDefaultComplexCondition(qaContent)); + } } QaServicePOJO.logger.debug("final - retrieved qaContent: " + qaContent); @@ -1851,4 +1855,8 @@ qaDAO.deleteCondition(condition); } } + + public QaCondition createDefaultComplexCondition(QaContent qaContent) { + return getQaOutputFactory().createDefaultComplexCondition(qaContent); + } } \ No newline at end of file Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaStarterAction.java =================================================================== diff -u -r33f9171c071c179459972380a9b732f1aeec87bf -rc4dfe712e2f4adc4d448e5653df6430eb2949002 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaStarterAction.java (.../QaStarterAction.java) (revision 33f9171c071c179459972380a9b732f1aeec87bf) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaStarterAction.java (.../QaStarterAction.java) (revision c4dfe712e2f4adc4d448e5653df6430eb2949002) @@ -409,6 +409,9 @@ QaStarterAction.logger.debug("getting content with id:" + toolContentID); QaContent qaContent = qaService.retrieveQa(toolContentID); + if (isDefaultContent && qaContent.getConditions().isEmpty()) { + qaContent.getConditions().add(qaService.createDefaultComplexCondition(qaContent)); + } QaStarterAction.logger.debug("QaContent: " + qaContent); QaUtils.populateAuthoringDTO(request, qaContent, qaGeneralAuthoringDTO); Index: lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/service/NotebookOutputFactory.java =================================================================== diff -u -ra74ae929e1b5f6e321e7251fb5bf5f93285c5b92 -rc4dfe712e2f4adc4d448e5653df6430eb2949002 --- lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/service/NotebookOutputFactory.java (.../NotebookOutputFactory.java) (revision a74ae929e1b5f6e321e7251fb5bf5f93285c5b92) +++ lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/service/NotebookOutputFactory.java (.../NotebookOutputFactory.java) (revision c4dfe712e2f4adc4d448e5653df6430eb2949002) @@ -59,15 +59,9 @@ Notebook notebook = (Notebook) toolContentObject; // adding all existing conditions notebookEntryDefinition.setDefaultConditions(new ArrayList(notebook.getConditions())); - // if no conditions were created in the tool instance, a default condition is added; the condition is - // persisted in NotebookService. + // if no conditions were created in the tool instance, a default condition is added; if (notebookEntryDefinition.getDefaultConditions().isEmpty()) { - String name = buildConditionName(NotebookConstants.TEXT_SEARCH_DEFINITION_NAME, notebook - .getToolContentId().toString()); - // Default condition checks if the text contains word "LAMS" - NotebookCondition defaultCondition = new NotebookCondition(null, null, 1, name, getI18NText( - NotebookConstants.TEXT_SEARCH_DEFAULT_CONDITION_DISPLAY_NAME_KEY, false), "LAMS", null, null, - null); + NotebookCondition defaultCondition = createDefaultComplexCondition(notebook); notebook.getConditions().add(defaultCondition); notebookEntryDefinition.getDefaultConditions().add(defaultCondition); } @@ -153,4 +147,19 @@ private boolean isTextSearchConditionName(String name) { return name != null && name.startsWith(NotebookConstants.TEXT_SEARCH_DEFINITION_NAME); } + + /** + * Creates a default condition so teachers know how to use complex conditions for this tool. + * + * @param notebook + * content of the tool + * @return default notebook condition + */ + protected NotebookCondition createDefaultComplexCondition(Notebook notebook) { + String name = buildConditionName(NotebookConstants.TEXT_SEARCH_DEFINITION_NAME, notebook.getToolContentId() + .toString()); + // Default condition checks if the text contains word "LAMS" + return new NotebookCondition(null, null, 1, name, getI18NText( + NotebookConstants.TEXT_SEARCH_DEFAULT_CONDITION_DISPLAY_NAME_KEY, false), "LAMS", null, null, null); + } } \ No newline at end of file Index: lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/service/NotebookService.java =================================================================== diff -u -ra74ae929e1b5f6e321e7251fb5bf5f93285c5b92 -rc4dfe712e2f4adc4d448e5653df6430eb2949002 --- lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/service/NotebookService.java (.../NotebookService.java) (revision a74ae929e1b5f6e321e7251fb5bf5f93285c5b92) +++ lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/service/NotebookService.java (.../NotebookService.java) (revision c4dfe712e2f4adc4d448e5653df6430eb2949002) @@ -305,18 +305,10 @@ */ public SortedMap getToolOutputDefinitions(Long toolContentId) throws ToolException { Notebook notebook = getNotebookDAO().getByContentId(toolContentId); - if (notebook == null) { notebook = getDefaultContent(); } - // If there are no user added conditions, the default condition will be added in the output factory. It also - // needs to be persisted. - boolean defaultConditionToBeAdded = notebook.getConditions().isEmpty(); - SortedMap map = getNotebookOutputFactory().getToolOutputDefinitions(notebook); - if (defaultConditionToBeAdded && !notebook.getConditions().isEmpty()) { - saveOrUpdateNotebook(notebook); - } - return map; + return getNotebookOutputFactory().getToolOutputDefinitions(notebook); } /* ********** INotebookService Methods ********************************* */ @@ -352,6 +344,10 @@ NotebookService.logger.error(error); throw new NotebookException(error); } + if (defaultContent.getConditions().isEmpty()) { + defaultContent.getConditions() + .add(getNotebookOutputFactory().createDefaultComplexCondition(defaultContent)); + } return defaultContent; } Index: lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/SurveyOutputFactory.java =================================================================== diff -u -rcdf0794ac8a26a5fe88b0db3a941994a41e8de97 -rc4dfe712e2f4adc4d448e5653df6430eb2949002 --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/SurveyOutputFactory.java (.../SurveyOutputFactory.java) (revision cdf0794ac8a26a5fe88b0db3a941994a41e8de97) +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/SurveyOutputFactory.java (.../SurveyOutputFactory.java) (revision c4dfe712e2f4adc4d448e5653df6430eb2949002) @@ -63,19 +63,10 @@ Survey survey = (Survey) toolContentObject; // adding all existing conditions allAnswersDefinition.setDefaultConditions(new ArrayList(survey.getConditions())); - // if no conditions were created in the tool instance, a default condition is added; the condition is - // persisted in SurveyService. + // if no conditions were created in the tool instance, a default condition is added; if (allAnswersDefinition.getDefaultConditions().isEmpty() && !survey.getQuestions().isEmpty()) { - Set questions = new HashSet(); - questions.add(survey.getQuestions().iterator().next()); - String name = buildConditionName(SurveyConstants.TEXT_SEARCH_DEFINITION_NAME, survey.getContentId() - .toString()); - // Default condition checks if the first answer contains word "LAMS" - SurveyCondition defaultCondition = new SurveyCondition(null, null, 1, name, getI18NText( - SurveyConstants.TEXT_SEARCH_DEFAULT_CONDITION_DISPLAY_NAME_KEY, false), "LAMS", null, null, - null, questions); + SurveyCondition defaultCondition = createDefaultComplexCondition(survey); survey.getConditions().add(defaultCondition); - allAnswersDefinition.getDefaultConditions().add(defaultCondition); } allAnswersDefinition.setShowConditionNameOnly(true); @@ -168,4 +159,29 @@ private boolean isTextSearchConditionName(String name) { return name != null && name.startsWith(SurveyConstants.TEXT_SEARCH_DEFINITION_NAME); } + + /** + * Creates a default condition so teachers know how to use complex conditions for this tool. + * + * @param survey + * content of the tool + * @return default survey condition + */ + protected SurveyCondition createDefaultComplexCondition(Survey survey) { + Set questions = new HashSet(); + for (SurveyQuestion question : survey.getQuestions()) { + if (question.getType() == SurveyConstants.SURVEY_TYPE_TEXT_ENTRY) { + questions.add(question); + break; + } + } + if (questions.isEmpty()) { + return null; + } + String name = buildConditionName(SurveyConstants.TEXT_SEARCH_DEFINITION_NAME, survey.getContentId().toString()); + // Default condition checks if the first answer contains word "LAMS" + return new SurveyCondition(null, null, 1, name, getI18NText( + SurveyConstants.TEXT_SEARCH_DEFAULT_CONDITION_DISPLAY_NAME_KEY, false), "LAMS", null, null, null, + questions); + } } \ No newline at end of file Index: lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/SurveyServiceImpl.java =================================================================== diff -u -r625dccc46218d5cf4648d73a139af38f21c222ce -rc4dfe712e2f4adc4d448e5653df6430eb2949002 --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/SurveyServiceImpl.java (.../SurveyServiceImpl.java) (revision 625dccc46218d5cf4648d73a139af38f21c222ce) +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/SurveyServiceImpl.java (.../SurveyServiceImpl.java) (revision c4dfe712e2f4adc4d448e5653df6430eb2949002) @@ -177,6 +177,9 @@ } Survey defaultContent = getDefaultSurvey(); + if (defaultContent.getConditions().isEmpty()) { + defaultContent.getConditions().add(getSurveyOutputFactory().createDefaultComplexCondition(defaultContent)); + } // save default content by given ID. Survey content = new Survey(); content = Survey.newInstance(defaultContent, contentId, surveyToolContentHandler); @@ -745,14 +748,7 @@ throw new ToolException(e); } } - // If there are no user added conditions, the default condition will be added in the output factory. It also - // needs to be persisted. - boolean defaultConditionToBeAdded = survey.getConditions().isEmpty(); - SortedMap map = getSurveyOutputFactory().getToolOutputDefinitions(survey); - if (defaultConditionToBeAdded && !survey.getConditions().isEmpty()) { - saveOrUpdateSurvey(survey); - } - return map; + return getSurveyOutputFactory().getToolOutputDefinitions(survey); } public void copyToolContent(Long fromContentId, Long toContentId) throws ToolException {