Index: lams_build/lib/lams/lams.jar =================================================================== diff -u -r134b8c6ce9847926aab1420c5adfe0a15b2c78cd -r7b79396263b36a933d66390fb9ab12821956d59d Binary files differ Index: lams_common/db/model/lams_11.clay =================================================================== diff -u -r542b83631b403e37429fce3bb928f2800c5cd9b8 -r7b79396263b36a933d66390fb9ab12821956d59d --- lams_common/db/model/lams_11.clay (.../lams_11.clay) (revision 542b83631b403e37429fce3bb928f2800c5cd9b8) +++ lams_common/db/model/lams_11.clay (.../lams_11.clay) (revision 7b79396263b36a933d66390fb9ab12821956d59d) @@ -5881,9 +5881,9 @@ - + - + @@ -6122,8 +6122,8 @@ - + Index: lams_common/src/java/org/lamsfoundation/lams/commonContext.xml =================================================================== diff -u -r542b83631b403e37429fce3bb928f2800c5cd9b8 -r7b79396263b36a933d66390fb9ab12821956d59d --- lams_common/src/java/org/lamsfoundation/lams/commonContext.xml (.../commonContext.xml) (revision 542b83631b403e37429fce3bb928f2800c5cd9b8) +++ lams_common/src/java/org/lamsfoundation/lams/commonContext.xml (.../commonContext.xml) (revision 7b79396263b36a933d66390fb9ab12821956d59d) @@ -91,7 +91,16 @@ classpath:org/lamsfoundation/lams/tool/notebook/model/NotebookSession.hbm.xml classpath:org/lamsfoundation/lams/tool/notebook/model/NotebookUser.hbm.xml classpath:org/lamsfoundation/lams/tool/notebook/model/NotebookAttachment.hbm.xml - classpath:org/lamsfoundation/lams/tool/notebook/model/NotebookCondition.hbm.xml + classpath:org/lamsfoundation/lams/tool/notebook/model/NotebookCondition.hbm.xml + + classpath:org/lamsfoundation/lams/tool/survey/model/SurveyUser.hbm.xml + classpath:org/lamsfoundation/lams/tool/survey/model/Survey.hbm.xml + classpath:org/lamsfoundation/lams/tool/survey/model/SurveyQuestion.hbm.xml + classpath:org/lamsfoundation/lams/tool/survey/model/SurveyOption.hbm.xml + classpath:org/lamsfoundation/lams/tool/survey/model/SurveyAnswer.hbm.xml + classpath:org/lamsfoundation/lams/tool/survey/model/SurveyAttachment.hbm.xml + classpath:org/lamsfoundation/lams/tool/survey/model/SurveySession.hbm.xml + classpath:org/lamsfoundation/lams/tool/survey/model/SurveyCondition.hbm.xml Index: lams_tool_survey/build.properties =================================================================== diff -u -rf7c130109254ea187c148bdd7270455130c2f8a1 -r7b79396263b36a933d66390fb9ab12821956d59d --- lams_tool_survey/build.properties (.../build.properties) (revision f7c130109254ea187c148bdd7270455130c2f8a1) +++ lams_tool_survey/build.properties (.../build.properties) (revision 7b79396263b36a933d66390fb9ab12821956d59d) @@ -12,7 +12,7 @@ project.displayname = lams survey tool # project version -tool.version=20080229 +tool.version=20081021 # hide tool option hideTool=false Index: lams_tool_survey/conf/language/lams/ApplicationResources.properties =================================================================== diff -u -r7e3ed7aa6da2aaca0745a19e148b8b6013e340db -r7b79396263b36a933d66390fb9ab12821956d59d --- lams_tool_survey/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 7e3ed7aa6da2aaca0745a19e148b8b6013e340db) +++ lams_tool_survey/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 7b79396263b36a933d66390fb9ab12821956d59d) @@ -164,4 +164,27 @@ event.answer.submit.body =The learner {0} submitted a survey answer in a Survey tool.\n\nThis message was send automatically, following tool''s advanced settings. label.specifyOther=Other - please specify +label.authoring.heading.conditions.desc =Please enter conditions for Survey +label.authoring.heading.conditions =Conditions +label.authoring.conditions.add.condition =Add condition +label.authoring.conditions.list.title =Conditions +label.authoring.conditions.order =Order +label.authoring.conditions.empty.condition.list =There are no conditions +label.authoring.conditions.condition.name =Name + +error.condition.name.blank =Condition name can not be blank. +error.condition.duplicated.name =Duplicated name. Please choose unique one. +error.condition.no.questions.selected =There are no questions selected. Please select at least one. +error.condition =Error creating condition. + +output.desc.text.search.output.definition.survey =Answers contain certain words +text.search.output.definition.survey.default.condition =First answer contains word "LAMS" + +textsearch.heading =Answers that... +textsearch.all.words =have all these words: +textsearch.phrase =have this exact wording or phrase: +textsearch.any.words =have one or more of these words: +textsearch.excluded.words =have none of these unwanted words: +textsearch.questions =Search in these questions: + #======= End labels: Exported 157 labels for en AU ===== Index: lams_tool_survey/conf/language/lams/ApplicationResources_en_AU.properties =================================================================== diff -u -r52c8b6bd3127acb3d63263925f12797ba1e0789e -r7b79396263b36a933d66390fb9ab12821956d59d --- lams_tool_survey/conf/language/lams/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision 52c8b6bd3127acb3d63263925f12797ba1e0789e) +++ lams_tool_survey/conf/language/lams/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision 7b79396263b36a933d66390fb9ab12821956d59d) @@ -164,5 +164,26 @@ event.answer.submit.subject =LAMS: A learner submitted a survey answer in a Survey tool event.answer.submit.body =The learner {0} submitted a survey answer in a Survey tool.\n\nThis message was send automatically, following tool''s advanced settings. +label.authoring.heading.conditions.desc =Please enter conditions for Survey +label.authoring.heading.conditions =Conditions +label.authoring.conditions.add.condition =Add condition +label.authoring.conditions.list.title =Conditions +label.authoring.conditions.order =Order +label.authoring.conditions.empty.condition.list =There are no conditions +label.authoring.conditions.condition.name =Name +error.condition.name.blank =Condition name can not be blank. +error.condition.duplicated.name =Duplicated name. Please choose unique one. +error.condition.no.questions.selected =There are no questions selected. Please select at least one. +error.condition =Error creating condition. + +output.desc.text.search.output.definition.survey =Answers contain certain words +text.search.output.definition.survey.default.condition =First answer contains word "LAMS" + +textsearch.heading =Answers that... +textsearch.all.words =have all these words: +textsearch.phrase =have this exact wording or phrase: +textsearch.any.words =have one or more of these words: +textsearch.excluded.words =have none of these unwanted words: +textsearch.questions =Search in these questions: #======= End labels: Exported 157 labels for en AU ===== Index: lams_tool_survey/conf/xdoclet/struts-actions.xml =================================================================== diff -u -r22a3b9201e28162af32878adf81d41d2595eceed -r7b79396263b36a933d66390fb9ab12821956d59d --- lams_tool_survey/conf/xdoclet/struts-actions.xml (.../struts-actions.xml) (revision 22a3b9201e28162af32878adf81d41d2595eceed) +++ lams_tool_survey/conf/xdoclet/struts-actions.xml (.../struts-actions.xml) (revision 7b79396263b36a933d66390fb9ab12821956d59d) @@ -128,7 +128,47 @@ parameter="removeInstruction"> - + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
- + @@ -228,7 +331,7 @@
- + @@ -304,7 +407,7 @@
- + @@ -689,7 +792,7 @@
- + Index: lams_tool_survey/db/sql/create_lams_tool_survey.sql =================================================================== diff -u -r05ab55ef4acdc0c374af7405c58fb0e0fe8eb6b7 -r7b79396263b36a933d66390fb9ab12821956d59d --- lams_tool_survey/db/sql/create_lams_tool_survey.sql (.../create_lams_tool_survey.sql) (revision 05ab55ef4acdc0c374af7405c58fb0e0fe8eb6b7) +++ lams_tool_survey/db/sql/create_lams_tool_survey.sql (.../create_lams_tool_survey.sql) (revision 7b79396263b36a933d66390fb9ab12821956d59d) @@ -95,6 +95,26 @@ primary key (uid) )type=innodb; +CREATE TABLE tl_lasurv11_conditions ( + condition_id BIGINT(20) NOT NULL + , content_uid BIGINT(20) + , PRIMARY KEY (condition_id) + , CONSTRAINT SurveyConditionInheritance FOREIGN KEY (condition_id) + REFERENCES lams_branch_condition(condition_id) ON DELETE CASCADE ON UPDATE CASCADE + , CONSTRAINT SurveyConditionToSurvey FOREIGN KEY (content_uid) + REFERENCES tl_lasurv11_survey(uid) ON DELETE CASCADE ON UPDATE CASCADE +)TYPE=InnoDB; + +CREATE TABLE tl_lasurv11_condition_questions ( + condition_id BIGINT(20) + , question_uid BIGINT(20) + , PRIMARY KEY (condition_id,question_uid) + , CONSTRAINT SurveyConditionQuestionToSurveyCondition FOREIGN KEY (condition_id) + REFERENCES tl_lasurv11_conditions(condition_id) ON DELETE CASCADE ON UPDATE CASCADE + , CONSTRAINT SurveyConditionQuestionToSurveyQuestion FOREIGN KEY (question_uid) + REFERENCES tl_lasurv11_question(uid) ON DELETE CASCADE ON UPDATE CASCADE +)TYPE=InnoDB; + alter table tl_lasurv11_answer add index FK6DAAFE3BB1423DC1 (user_uid), add constraint FK6DAAFE3BB1423DC1 foreign key (user_uid) references tl_lasurv11_user (uid); alter table tl_lasurv11_answer add index FK6DAAFE3B25F3BB77 (question_uid), add constraint FK6DAAFE3B25F3BB77 foreign key (question_uid) references tl_lasurv11_question (uid); alter table tl_lasurv11_attachment add index FKD92A9120D14146E5 (survey_uid), add constraint FKD92A9120D14146E5 foreign key (survey_uid) references tl_lasurv11_survey (uid); Index: lams_tool_survey/db/sql/drop_lams_tool_survey.sql =================================================================== diff -u -r0020cbe23ed34775811ceab0779d065243444dcb -r7b79396263b36a933d66390fb9ab12821956d59d --- lams_tool_survey/db/sql/drop_lams_tool_survey.sql (.../drop_lams_tool_survey.sql) (revision 0020cbe23ed34775811ceab0779d065243444dcb) +++ lams_tool_survey/db/sql/drop_lams_tool_survey.sql (.../drop_lams_tool_survey.sql) (revision 7b79396263b36a933d66390fb9ab12821956d59d) @@ -6,6 +6,8 @@ drop table if exists tl_lasurv11_item_log; drop table if exists tl_lasurv11_session; drop table if exists tl_lasurv11_user; +drop table if exists tl_lasurv11_condition_questions; +drop table if exists tl_lasurv11_conditions; SET FOREIGN_KEY_CHECKS=1; Index: lams_tool_survey/db/sql/tool_insert.sql =================================================================== diff -u -r691d0f5085a52d31d37cb556b134714e944d5c27 -r7b79396263b36a933d66390fb9ab12821956d59d --- lams_tool_survey/db/sql/tool_insert.sql (.../tool_insert.sql) (revision 691d0f5085a52d31d37cb556b134714e944d5c27) +++ lams_tool_survey/db/sql/tool_insert.sql (.../tool_insert.sql) (revision 7b79396263b36a933d66390fb9ab12821956d59d) @@ -30,7 +30,8 @@ classpath_addition, context_file, create_date_time, -modified_date_time +modified_date_time, +supports_outputs ) VALUES ( @@ -60,5 +61,6 @@ 'lams-tool-lasurv11.jar', '/org/lamsfoundation/lams/tool/survey/surveyApplicationContext.xml', NOW(), -NOW() +NOW(), +1 ) Index: lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/SurveyConstants.java =================================================================== diff -u -r05ab55ef4acdc0c374af7405c58fb0e0fe8eb6b7 -r7b79396263b36a933d66390fb9ab12821956d59d --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/SurveyConstants.java (.../SurveyConstants.java) (revision 05ab55ef4acdc0c374af7405c58fb0e0fe8eb6b7) +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/SurveyConstants.java (.../SurveyConstants.java) (revision 7b79396263b36a933d66390fb9ab12821956d59d) @@ -24,158 +24,167 @@ package org.lamsfoundation.lams.tool.survey; public class SurveyConstants { - public static final String TOOL_SIGNATURE = "lasurv11"; + public static final String TOOL_SIGNATURE = "lasurv11"; - public static final String SURVEY_SERVICE = "lasurvSurveyService"; + public static final String SURVEY_SERVICE = "lasurvSurveyService"; - public static final int COMPLETED = 1; + public static final int COMPLETED = 1; - //survey type; - public static final short QUESTION_TYPE_SINGLE_CHOICE = 1; + // survey type; + public static final short QUESTION_TYPE_SINGLE_CHOICE = 1; - public static final short QUESTION_TYPE_MUTLIPLE_CHOICE = 2; + public static final short QUESTION_TYPE_MUTLIPLE_CHOICE = 2; - public static final short QUESTION_TYPE_TEXT_ENTRY = 3; + public static final short QUESTION_TYPE_TEXT_ENTRY = 3; - //for action forward name - public static final String SUCCESS = "success"; + // for action forward name + public static final String SUCCESS = "success"; - public static final String ERROR = "error"; + public static final String ERROR = "error"; - public static final String DEFINE_LATER = "definelater"; + public static final String DEFINE_LATER = "definelater"; - public static final String RUN_OFFLINE = "runOffline"; + public static final String RUN_OFFLINE = "runOffline"; - public static final String FORWARD_RESULT = "result"; + public static final String FORWARD_RESULT = "result"; - //for parameters' name - public static final String PARAM_FILE_VERSION_ID = "fileVersionId"; + // for parameters' name + public static final String PARAM_FILE_VERSION_ID = "fileVersionId"; - public static final String PARAM_FILE_UUID = "fileUuid"; + public static final String PARAM_FILE_UUID = "fileUuid"; - public static final String PARAM_ITEM_INDEX = "itemIndex"; + public static final String PARAM_ITEM_INDEX = "itemIndex"; - public static final String PARAM_RUN_OFFLINE = "runOffline"; + public static final String PARAM_RUN_OFFLINE = "runOffline"; - public static final String PARAM_TITLE = "title"; + public static final String PARAM_TITLE = "title"; - public static final String ATTR_USER_UID = "userUid"; + public static final String ATTR_USER_UID = "userUid"; - //error message keys - public static final String ERROR_MSG_TITLE_BLANK = "error.survey.item.title.blank"; + // error message keys + public static final String ERROR_MSG_TITLE_BLANK = "error.survey.item.title.blank"; - public static final String ERROR_MSG_URL_BLANK = "error.survey.item.url.blank"; + public static final String ERROR_MSG_URL_BLANK = "error.survey.item.url.blank"; - public static final String ERROR_MSG_DESC_BLANK = "error.survey.item.question.blank"; + public static final String ERROR_MSG_DESC_BLANK = "error.survey.item.question.blank"; - public static final String ERROR_MSG_LESS_OPTIONS = "error.survey.item.question.less.option"; + public static final String ERROR_MSG_LESS_OPTIONS = "error.survey.item.question.less.option"; - public static final String ERROR_MSG_FILE_BLANK = "error.survey.item.file.blank"; + public static final String ERROR_MSG_FILE_BLANK = "error.survey.item.file.blank"; - public static final String ERROR_MSG_INVALID_URL = "error.survey.item.invalid.url"; + public static final String ERROR_MSG_INVALID_URL = "error.survey.item.invalid.url"; - public static final String ERROR_MSG_UPLOAD_FAILED = "error.upload.failed"; + public static final String ERROR_MSG_UPLOAD_FAILED = "error.upload.failed"; - public static final String ERROR_MSG_MANDATORY_QUESTION = "error.mandatory.question"; + public static final String ERROR_MSG_MANDATORY_QUESTION = "error.mandatory.question"; - public static final String ERROR_MSG_CHART_ERROR = "error.chart.gen"; + public static final String ERROR_MSG_CHART_ERROR = "error.chart.gen"; - public static final String ERROR_MSG_SINGLE_CHOICE = "error.single.choice.over"; + public static final String ERROR_MSG_SINGLE_CHOICE = "error.single.choice.over"; - public static final String MSG_OPEN_RESPONSE = "label.open.response"; + public static final String MSG_OPEN_RESPONSE = "label.open.response"; - public static final String MSG_PIECHART_TITLE = "piechart.title"; + public static final String MSG_PIECHART_TITLE = "piechart.title"; - public static final String MSG_BARCHART_TITLE = "barchart.title"; + public static final String MSG_BARCHART_TITLE = "barchart.title"; - public static final String MSG_BARCHART_CATEGORY_AXIS_LABEL = "barchart.category.axis.label"; + public static final String MSG_BARCHART_CATEGORY_AXIS_LABEL = "barchart.category.axis.label"; - public static final String MSG_BARCHART_VALUE_AXIS_LABEL = "barchart.value.axis.label"; + public static final String MSG_BARCHART_VALUE_AXIS_LABEL = "barchart.value.axis.label"; - public static final String ATTR_REFLECTION_ON = "reflectOn"; + public static final String ATTR_REFLECTION_ON = "reflectOn"; - public static final String ATTR_REFLECTION_INSTRUCTION = "reflectInstructions"; + public static final String ATTR_REFLECTION_INSTRUCTION = "reflectInstructions"; - public static final String ATTR_REFLECT_LIST = "reflectList"; + public static final String ATTR_REFLECT_LIST = "reflectList"; - public static final String ATTR_REFLECTION_ENTRY = "reflectEntry"; + public static final String ATTR_REFLECTION_ENTRY = "reflectEntry"; - public static final String ATTR_SESSION_MAP_ID = "sessionMapID"; + public static final String ATTR_SESSION_MAP_ID = "sessionMapID"; - public static final String PAGE_EDITABLE = "isPageEditable"; + public static final String PAGE_EDITABLE = "isPageEditable"; - public static final String ATTR_FILE_TYPE_FLAG = "fileTypeFlag"; + public static final String ATTR_FILE_TYPE_FLAG = "fileTypeFlag"; - public static final String ATTR_SURVEY_FORM = "surveyForm"; + public static final String ATTR_SURVEY_FORM = "surveyForm"; - public static final String ATTR_STATISTIC_LIST = "statistic"; + public static final String ATTR_STATISTIC_LIST = "statistic"; - public static final String ATTR_INSTRUCTION_LIST = "instructionList"; + public static final String ATTR_INSTRUCTION_LIST = "instructionList"; - public static final String ATT_ATTACHMENT_LIST = "instructionAttachmentList"; + public static final String ATT_ATTACHMENT_LIST = "instructionAttachmentList"; - public static final String ATTR_DELETED_ATTACHMENT_LIST = "deletedAttachmmentList"; + public static final String ATTR_DELETED_ATTACHMENT_LIST = "deletedAttachmmentList"; - public static final String ATTR_QUESTION_LIST = "questionList"; + public static final String ATTR_QUESTION_LIST = "questionList"; - public static final String ATTR_ANSWER_LIST = "answerList"; + public static final String ATTR_ANSWER_LIST = "answerList"; - public static final String ATTR_QUESTION = "question"; + public static final String ATTR_QUESTION = "question"; - public static final String ATTR_DELETED_QUESTION_LIST = "deletedQuestionList"; + public static final String ATTR_DELETED_QUESTION_LIST = "deletedQuestionList"; - public static final String ATTR_TITLE = "title"; + public static final String ATTR_TITLE = "title"; - public static final String ATTR_SURVEY_INSTRUCTION = "instructions"; + public static final String ATTR_SURVEY_INSTRUCTION = "instructions"; - public static final String ATTR_FINISH_LOCK = "finishedLock"; + public static final String ATTR_FINISH_LOCK = "finishedLock"; - public static final String ATTR_LOCK_ON_FINISH = "lockOnFinish"; + public static final String ATTR_LOCK_ON_FINISH = "lockOnFinish"; - public static final String ATTR_NEXT_ACTIVITY_URL = "nextActivityUrl"; + public static final String ATTR_NEXT_ACTIVITY_URL = "nextActivityUrl"; - public static final short SURVEY_TYPE_TEXT_ENTRY = 3; + public static final short SURVEY_TYPE_TEXT_ENTRY = 3; - public static final short SURVEY_TYPE_MULTIPLE_CHOICES = 2; + public static final short SURVEY_TYPE_MULTIPLE_CHOICES = 2; - public static final short SURVEY_TYPE_SINGLE_CHOICE = 1; + public static final short SURVEY_TYPE_SINGLE_CHOICE = 1; - public static final String FORWARD_OPEN_QUESTION = "opentext"; + public static final String FORWARD_OPEN_QUESTION = "opentext"; - public static final String FORWARD_CHOICE_QUESTION = "question"; + public static final String FORWARD_CHOICE_QUESTION = "question"; - public static final String ATTR_SHOW_ON_ONE_PAGE = "showOnOnePage"; + public static final String ATTR_SHOW_ON_ONE_PAGE = "showOnOnePage"; - public static final String PREFIX_QUESTION_CHOICE = "optionChoice"; + public static final String PREFIX_QUESTION_CHOICE = "optionChoice"; - public static final String PREFIX_QUESTION_TEXT = "optionText"; + public static final String PREFIX_QUESTION_TEXT = "optionText"; - public static final String ERROR_MSG_KEY = "questionError"; + public static final String ERROR_MSG_KEY = "questionError"; - public static final String ATTR_TOTAL_QUESTIONS = "totalQuestions"; + public static final String ATTR_TOTAL_QUESTIONS = "totalQuestions"; - public static final String ATTR_CURRENT_QUESTIONS_IDX = "currentIdx"; + public static final String ATTR_CURRENT_QUESTIONS_IDX = "currentIdx"; - public static final String CHART_TYPE = "chartType"; + public static final String CHART_TYPE = "chartType"; - public static final String ATTR_QUESTION_UID = "questionUid"; + public static final String ATTR_QUESTION_UID = "questionUid"; - public static final String ATTR_SUMMARY_LIST = "summaryList"; + public static final String ATTR_SUMMARY_LIST = "summaryList"; - public static final String ATTR_SURVEY = "survey"; + public static final String ATTR_SURVEY = "survey"; - public static final String ATTR_USER_FINISHED = "userFinished"; + public static final String ATTR_USER_FINISHED = "userFinished"; - //POSITION - public static int POSITION_INSIDE = 0; + // POSITION + public static int POSITION_INSIDE = 0; - public static int POSITION_FIRST = 1; + public static int POSITION_FIRST = 1; - public static int POSITION_LAST = 2; + public static int POSITION_LAST = 2; - public static int POSITION_ONLY_ONE = 3; + public static int POSITION_ONLY_ONE = 3; - public static final String OPTION_SHORT_HEADER = "a"; + public static final String OPTION_SHORT_HEADER = "a"; - public static final String EVENT_NAME_NOTIFY_TEACHERS_ON_SURVERY_ANSWER_SUBMIT = "notify_teachers_on_survey_answer_submit"; -} + public static final String EVENT_NAME_NOTIFY_TEACHERS_ON_SURVERY_ANSWER_SUBMIT = "notify_teachers_on_survey_answer_submit"; + + // for condition management use + + public static final Object ATTR_CONDITION_SET = "conditionList"; + public static final String PARAM_ORDER_ID = "orderId"; + public static final String ATTR_DELETED_CONDITION_LIST = "deletedConditionList"; + + public static final String TEXT_SEARCH_DEFINITION_NAME = "text.search.output.definition.survey"; + public static final String TEXT_SEARCH_DEFAULT_CONDITION_DISPLAY_NAME_KEY = "text.search.output.definition.survey.default.condition"; +} \ No newline at end of file Index: lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dbupdates/patch20081021_updateFrom21.sql =================================================================== diff -u --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dbupdates/patch20081021_updateFrom21.sql (revision 0) +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dbupdates/patch20081021_updateFrom21.sql (revision 7b79396263b36a933d66390fb9ab12821956d59d) @@ -0,0 +1,23 @@ +-- SQL statements to update from LAMS 2.1/2.1.1 + +CREATE TABLE tl_lasurv11_conditions ( + condition_id BIGINT(20) NOT NULL + , content_uid BIGINT(20) + , PRIMARY KEY (condition_id) + , CONSTRAINT SurveyConditionInheritance FOREIGN KEY (condition_id) + REFERENCES lams_branch_condition(condition_id) ON DELETE CASCADE ON UPDATE CASCADE + , CONSTRAINT SurveyConditionToSurvey FOREIGN KEY (content_uid) + REFERENCES tl_lasurv11_survey(uid) ON DELETE CASCADE ON UPDATE CASCADE +)TYPE=InnoDB; + +CREATE TABLE tl_lasurv11_condition_questions ( + condition_id BIGINT(20) + , question_uid BIGINT(20) + , PRIMARY KEY (condition_id,question_uid) + , CONSTRAINT SurveyConditionQuestionToSurveyCondition FOREIGN KEY (condition_id) + REFERENCES tl_lasurv11_conditions(condition_id) ON DELETE CASCADE ON UPDATE CASCADE + , CONSTRAINT SurveyConditionQuestionToSurveyQuestion FOREIGN KEY (question_uid) + REFERENCES tl_lasurv11_question(uid) ON DELETE CASCADE ON UPDATE CASCADE +)TYPE=InnoDB; + +UPDATE lams_tool SET supports_outputs=1 WHERE tool_signature='lasurv11'; \ No newline at end of file Index: lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/model/Survey.hbm.xml =================================================================== diff -u -r05ab55ef4acdc0c374af7405c58fb0e0fe8eb6b7 -r7b79396263b36a933d66390fb9ab12821956d59d --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/model/Survey.hbm.xml (.../Survey.hbm.xml) (revision 05ab55ef4acdc0c374af7405c58fb0e0fe8eb6b7) +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/model/Survey.hbm.xml (.../Survey.hbm.xml) (revision 7b79396263b36a933d66390fb9ab12821956d59d) @@ -196,6 +196,24 @@ column="answer_submit_notify" /> + + + + + + + + + + org/lamsfoundation/lams/learningdesign/BranchCondition.hbm.xml org/lamsfoundation/lams/tool/survey/model/SurveyUser.hbm.xml org/lamsfoundation/lams/tool/survey/model/Survey.hbm.xml org/lamsfoundation/lams/tool/survey/model/SurveyQuestion.hbm.xml org/lamsfoundation/lams/tool/survey/model/SurveyOption.hbm.xml org/lamsfoundation/lams/tool/survey/model/SurveyAnswer.hbm.xml org/lamsfoundation/lams/tool/survey/model/SurveyAttachment.hbm.xml org/lamsfoundation/lams/tool/survey/model/SurveySession.hbm.xml + org/lamsfoundation/lams/tool/survey/model/SurveyCondition.hbm.xml - + + + + @@ -118,6 +123,7 @@ + Index: lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/web/action/AuthoringAction.java =================================================================== diff -u -r7dd15ff5149a5f87efd7cef5304819bf1bd0b78f -r7b79396263b36a933d66390fb9ab12821956d59d --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/web/action/AuthoringAction.java (.../AuthoringAction.java) (revision 7dd15ff5149a5f87efd7cef5304819bf1bd0b78f) +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/web/action/AuthoringAction.java (.../AuthoringAction.java) (revision 7b79396263b36a933d66390fb9ab12821956d59d) @@ -57,10 +57,12 @@ import org.apache.struts.upload.FormFile; import org.lamsfoundation.lams.authoring.web.AuthoringConstants; import org.lamsfoundation.lams.contentrepository.client.IToolContentHandler; +import org.lamsfoundation.lams.learningdesign.TextSearchConditionComparator; import org.lamsfoundation.lams.tool.ToolAccessMode; import org.lamsfoundation.lams.tool.survey.SurveyConstants; import org.lamsfoundation.lams.tool.survey.model.Survey; import org.lamsfoundation.lams.tool.survey.model.SurveyAttachment; +import org.lamsfoundation.lams.tool.survey.model.SurveyCondition; import org.lamsfoundation.lams.tool.survey.model.SurveyOption; import org.lamsfoundation.lams.tool.survey.model.SurveyQuestion; import org.lamsfoundation.lams.tool.survey.model.SurveyUser; @@ -80,980 +82,1087 @@ import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; - /** * @author Steve.Ni * @version $Revision$ */ public class AuthoringAction extends Action { - private static final int INIT_INSTRUCTION_COUNT = 2; - private static final String INSTRUCTION_ITEM_DESC_PREFIX = "instructionItemDesc"; - private static final String INSTRUCTION_ITEM_COUNT = "instructionCount"; - private static final int SHORT_TITLE_LENGTH = 60; - - private static Logger log = Logger.getLogger(AuthoringAction.class); - - public ActionForward execute(ActionMapping mapping, ActionForm form, - HttpServletRequest request, HttpServletResponse response) throws Exception{ - - String param = mapping.getParameter(); - //-----------------------Survey Author function --------------------------- - if(param.equals("start")){ - ToolAccessMode mode = getAccessMode(request); - //teacher mode "check for new" button enter. - if(mode != null) - request.setAttribute(AttributeNames.ATTR_MODE,mode.toString()); - else - request.setAttribute(AttributeNames.ATTR_MODE,ToolAccessMode.AUTHOR.toString()); - return start(mapping, form, request, response); + private static final int INIT_INSTRUCTION_COUNT = 2; + private static final String INSTRUCTION_ITEM_DESC_PREFIX = "instructionItemDesc"; + private static final String INSTRUCTION_ITEM_COUNT = "instructionCount"; + private static final int SHORT_TITLE_LENGTH = 60; + + private static Logger log = Logger.getLogger(AuthoringAction.class); + + @Override + public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + String param = mapping.getParameter(); + // -----------------------Survey Author function --------------------------- + if (param.equals("start")) { + ToolAccessMode mode = getAccessMode(request); + // teacher mode "check for new" button enter. + if (mode != null) { + request.setAttribute(AttributeNames.ATTR_MODE, mode.toString()); + } else { + request.setAttribute(AttributeNames.ATTR_MODE, ToolAccessMode.AUTHOR.toString()); + } + return start(mapping, form, request, response); + } + if (param.equals("definelater")) { + // update define later flag to true + Long contentId = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID)); + ISurveyService service = getSurveyService(); + Survey survey = service.getSurveyByContentId(contentId); + + boolean isEditable = SurveyWebUtils.isSurveyEditable(survey); + if (!isEditable) { + request.setAttribute(SurveyConstants.PAGE_EDITABLE, new Boolean(isEditable)); + return mapping.findForward("forbidden"); + } + + if (!survey.isContentInUse()) { + survey.setDefineLater(true); + service.saveOrUpdateSurvey(survey); + } + + request.setAttribute(AttributeNames.ATTR_MODE, ToolAccessMode.TEACHER.toString()); + return start(mapping, form, request, response); + } + if (param.equals("initPage")) { + return initPage(mapping, form, request, response); + } + + if (param.equals("updateContent")) { + return updateContent(mapping, form, request, response); + } + if (param.equals("uploadOnlineFile")) { + return uploadOnline(mapping, form, request, response); + } + if (param.equals("uploadOfflineFile")) { + return uploadOffline(mapping, form, request, response); + } + if (param.equals("deleteOnlineFile")) { + return deleteOnlineFile(mapping, form, request, response); + } + if (param.equals("deleteOfflineFile")) { + return deleteOfflineFile(mapping, form, request, response); + } + // ----------------------- Add survey item function --------------------------- + if (param.equals("newItemInit")) { + return newItemlInit(mapping, form, request, response); + } + if (param.equals("editItemInit")) { + return editItemInit(mapping, form, request, response); + } + if (param.equals("saveOrUpdateItem")) { + return saveOrUpdateItem(mapping, form, request, response); + } + if (param.equals("removeItem")) { + return removeItem(mapping, form, request, response); + } + if (param.equals("upItem")) { + return upItem(mapping, form, request, response); + } + if (param.equals("downItem")) { + return downItem(mapping, form, request, response); + } + // -----------------------Survey Item Instruction function --------------------------- + if (param.equals("newInstruction")) { + return newInstruction(mapping, form, request, response); + } + if (param.equals("removeInstruction")) { + return removeInstruction(mapping, form, request, response); + } + return mapping.findForward(SurveyConstants.ERROR); + } + + /** + * Remove survey item from HttpSession list and update page display. As authoring rule, all persist only happen when + * user submit whole page. So this remove is just impact HttpSession values. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward removeItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + + // get back sessionMAP + String sessionMapID = WebUtil.readStrParam(request, SurveyConstants.ATTR_SESSION_MAP_ID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + + int itemIdx = NumberUtils.stringToInt(request.getParameter(SurveyConstants.PARAM_ITEM_INDEX), -1); + if (itemIdx != -1) { + SortedSet surveyList = getSurveyItemList(sessionMap); + List rList = new ArrayList(surveyList); + SurveyQuestion item = rList.remove(itemIdx); + surveyList.clear(); + surveyList.addAll(rList); + // add to delList + List delList = getDeletedSurveyItemList(sessionMap); + delList.add(item); + + SortedSet list = getSurveyConditionSet(sessionMap); + Iterator conditionIter = list.iterator(); + + while (conditionIter.hasNext()) { + SurveyCondition condition = conditionIter.next(); + Iterator questionIter = condition.getQuestions().iterator(); + while (questionIter.hasNext()) { + if (questionIter.next() == item) { + questionIter.remove(); + } } - if (param.equals("definelater")) { - //update define later flag to true - Long contentId = new Long(WebUtil.readLongParam(request,AttributeNames.PARAM_TOOL_CONTENT_ID)); - ISurveyService service = getSurveyService(); - Survey survey = service.getSurveyByContentId(contentId); - - boolean isEditable = SurveyWebUtils.isSurveyEditable(survey); - if(!isEditable){ - request.setAttribute(SurveyConstants.PAGE_EDITABLE, new Boolean(isEditable)); - return mapping.findForward("forbidden"); - } - - if(!survey.isContentInUse()){ - survey.setDefineLater(true); - service.saveOrUpdateSurvey(survey); - } - - request.setAttribute(AttributeNames.ATTR_MODE,ToolAccessMode.TEACHER.toString()); - return start(mapping, form, request, response); - } - if (param.equals("initPage")) { - return initPage(mapping, form, request, response); - } + if (condition.getQuestions().isEmpty()) { + conditionIter.remove(); + } + } + } - if (param.equals("updateContent")) { - return updateContent(mapping, form, request, response); - } - if (param.equals("uploadOnlineFile")) { - return uploadOnline(mapping, form, request, response); - } - if (param.equals("uploadOfflineFile")) { - return uploadOffline(mapping, form, request, response); - } - if (param.equals("deleteOnlineFile")) { - return deleteOnlineFile(mapping, form, request, response); - } - if (param.equals("deleteOfflineFile")) { - return deleteOfflineFile(mapping, form, request, response); - } - //----------------------- Add survey item function --------------------------- - if (param.equals("newItemInit")) { - return newItemlInit(mapping, form, request, response); - } - if (param.equals("editItemInit")) { - return editItemInit(mapping, form, request, response); - } - if (param.equals("saveOrUpdateItem")) { - return saveOrUpdateItem(mapping, form, request, response); - } - if (param.equals("removeItem")) { - return removeItem(mapping, form, request, response); - } - if (param.equals("upItem")) { - return upItem(mapping, form, request, response); - } - if (param.equals("downItem")) { - return downItem(mapping, form, request, response); - } - //-----------------------Survey Item Instruction function --------------------------- - if (param.equals("newInstruction")) { - return newInstruction(mapping, form, request, response); - } - if (param.equals("removeInstruction")) { - return removeInstruction(mapping, form, request, response); - } - return mapping.findForward(SurveyConstants.ERROR); + request.setAttribute(SurveyConstants.ATTR_SESSION_MAP_ID, sessionMapID); + return mapping.findForward(SurveyConstants.SUCCESS); + } + + /** + * Move up current item. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward upItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + + return switchItem(mapping, request, true); + } + + /** + * Move down current item. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward downItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + + return switchItem(mapping, request, false); + } + + private ActionForward switchItem(ActionMapping mapping, HttpServletRequest request, boolean up) { + // get back sessionMAP + String sessionMapID = WebUtil.readStrParam(request, SurveyConstants.ATTR_SESSION_MAP_ID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + + int itemIdx = NumberUtils.stringToInt(request.getParameter(SurveyConstants.PARAM_ITEM_INDEX), -1); + if (itemIdx != -1) { + SortedSet surveyList = getSurveyItemList(sessionMap); + List rList = new ArrayList(surveyList); + // get current and the target item, and switch their sequnece + SurveyQuestion item = rList.get(itemIdx); + SurveyQuestion repItem; + if (up) { + repItem = rList.get(--itemIdx); + } else { + repItem = rList.get(++itemIdx); + } + int upSeqId = repItem.getSequenceId(); + repItem.setSequenceId(item.getSequenceId()); + item.setSequenceId(upSeqId); + + // put back list, it will be sorted again + surveyList.clear(); + surveyList.addAll(rList); } + request.setAttribute(SurveyConstants.ATTR_SESSION_MAP_ID, sessionMapID); + return mapping.findForward(SurveyConstants.SUCCESS); + } - /** - * Remove survey item from HttpSession list and update page display. As authoring rule, all persist only happen when - * user submit whole page. So this remove is just impact HttpSession values. - * @param mapping - * @param form - * @param request - * @param response - * @return - */ - private ActionForward removeItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { - -// get back sessionMAP - String sessionMapID = WebUtil.readStrParam(request, SurveyConstants.ATTR_SESSION_MAP_ID); - SessionMap sessionMap = (SessionMap)request.getSession().getAttribute(sessionMapID); - - int itemIdx = NumberUtils.stringToInt(request.getParameter(SurveyConstants.PARAM_ITEM_INDEX),-1); - if(itemIdx != -1){ - SortedSet surveyList = getSurveyItemList(sessionMap); - List rList = new ArrayList(surveyList); - SurveyQuestion item = rList.remove(itemIdx); - surveyList.clear(); - surveyList.addAll(rList); - //add to delList - List delList = getDeletedSurveyItemList(sessionMap); - delList.add(item); - } - - request.setAttribute(SurveyConstants.ATTR_SESSION_MAP_ID, sessionMapID); - return mapping.findForward(SurveyConstants.SUCCESS); + /** + * Display edit page for existed survey item. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward editItemInit(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + + QuestionForm itemForm = (QuestionForm) form; + // get back sessionMAP + String sessionMapID = WebUtil.readStrParam(request, SurveyConstants.ATTR_SESSION_MAP_ID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + + int itemIdx = NumberUtils.stringToInt(request.getParameter(SurveyConstants.PARAM_ITEM_INDEX), -1); + SurveyQuestion item = null; + if (itemIdx != -1) { + SortedSet surveyList = getSurveyItemList(sessionMap); + List rList = new ArrayList(surveyList); + item = rList.get(itemIdx); + if (item != null) { + populateItemToForm(itemIdx, item, itemForm, request); + } } - /** - * Move up current item. - * @param mapping - * @param form - * @param request - * @param response - * @return - */ - private ActionForward upItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { - - return switchItem(mapping, request, true); + if (itemForm.getItemType() == SurveyConstants.QUESTION_TYPE_TEXT_ENTRY) { + return mapping.findForward(SurveyConstants.FORWARD_OPEN_QUESTION); + } else { + return mapping.findForward(SurveyConstants.FORWARD_CHOICE_QUESTION); } - /** - * Move down current item. - * @param mapping - * @param form - * @param request - * @param response - * @return - */ - private ActionForward downItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { - - return switchItem(mapping, request, false); + } + + /** + * Display empty page for new survey item. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward newItemlInit(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + QuestionForm questionForm = (QuestionForm) form; + + List instructionList = new ArrayList(AuthoringAction.INIT_INSTRUCTION_COUNT); + for (int idx = 0; idx < AuthoringAction.INIT_INSTRUCTION_COUNT; idx++) { + instructionList.add(""); } + request.setAttribute("instructionList", instructionList); + if (questionForm.getItemType() == SurveyConstants.QUESTION_TYPE_TEXT_ENTRY) { + return mapping.findForward(SurveyConstants.FORWARD_OPEN_QUESTION); + } else { + return mapping.findForward(SurveyConstants.FORWARD_CHOICE_QUESTION); + } + } + /** + * This method will get necessary information from survey item form and save or update into HttpSession + * SurveyItemList. Notice, this save is not persist them into database, just save HttpSession + * temporarily. Only they will be persist when the entire authoring page is being persisted. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + * @throws ServletException + */ + private ActionForward saveOrUpdateItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws Exception { + // get instructions: + List instructionList = getInstructionsFromRequest(request); - private ActionForward switchItem(ActionMapping mapping, HttpServletRequest request, boolean up) { -// get back sessionMAP - String sessionMapID = WebUtil.readStrParam(request, SurveyConstants.ATTR_SESSION_MAP_ID); - SessionMap sessionMap = (SessionMap)request.getSession().getAttribute(sessionMapID); - - int itemIdx = NumberUtils.stringToInt(request.getParameter(SurveyConstants.PARAM_ITEM_INDEX),-1); - if(itemIdx != -1){ - SortedSet surveyList = getSurveyItemList(sessionMap); - List rList = new ArrayList(surveyList); - //get current and the target item, and switch their sequnece - SurveyQuestion item = rList.get(itemIdx); - SurveyQuestion repItem; - if(up) - repItem = rList.get(--itemIdx); - else - repItem = rList.get(++itemIdx); - int upSeqId = repItem.getSequenceId(); - repItem.setSequenceId(item.getSequenceId()); - item.setSequenceId(upSeqId); - - //put back list, it will be sorted again - surveyList.clear(); - surveyList.addAll(rList); - } - - request.setAttribute(SurveyConstants.ATTR_SESSION_MAP_ID, sessionMapID); - return mapping.findForward(SurveyConstants.SUCCESS); + QuestionForm itemForm = (QuestionForm) form; + ActionErrors errors = validateSurveyItem(itemForm, instructionList); + + if (!errors.isEmpty()) { + this.addErrors(request, errors); + // add at least 2 instruction list + for (int idx = instructionList.size(); idx < 2; idx++) { + instructionList.add(""); + } + request.setAttribute(SurveyConstants.ATTR_INSTRUCTION_LIST, instructionList); + if (itemForm.getItemType() == SurveyConstants.QUESTION_TYPE_TEXT_ENTRY) { + return mapping.findForward(SurveyConstants.FORWARD_OPEN_QUESTION); + } else { + return mapping.findForward(SurveyConstants.FORWARD_CHOICE_QUESTION); + } } - - /** - * Display edit page for existed survey item. - * @param mapping - * @param form - * @param request - * @param response - * @return - */ - private ActionForward editItemInit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { - - QuestionForm itemForm = (QuestionForm) form; -// get back sessionMAP - String sessionMapID = WebUtil.readStrParam(request, SurveyConstants.ATTR_SESSION_MAP_ID); - SessionMap sessionMap = (SessionMap)request.getSession().getAttribute(sessionMapID); - - int itemIdx = NumberUtils.stringToInt(request.getParameter(SurveyConstants.PARAM_ITEM_INDEX),-1); - SurveyQuestion item = null; - if(itemIdx != -1){ - SortedSet surveyList = getSurveyItemList(sessionMap); - List rList = new ArrayList(surveyList); - item = rList.get(itemIdx); - if(item != null){ - populateItemToForm(itemIdx, item,itemForm,request); - } - } - if(itemForm.getItemType() == SurveyConstants.QUESTION_TYPE_TEXT_ENTRY) - return mapping.findForward(SurveyConstants.FORWARD_OPEN_QUESTION); - else - return mapping.findForward(SurveyConstants.FORWARD_CHOICE_QUESTION); + + try { + extractFormToSurveyItem(request, instructionList, itemForm); + } catch (Exception e) { + AuthoringAction.log.error("Uploading failed. The exception is " + e.toString()); + throw e; } - /** - * Display empty page for new survey item. - * @param mapping - * @param form - * @param request - * @param response - * @return - */ - private ActionForward newItemlInit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { - QuestionForm questionForm = (QuestionForm)form; - - List instructionList = new ArrayList(INIT_INSTRUCTION_COUNT); - for(int idx=0;idx questions = null; + Survey survey = null; + SurveyForm surveyForm = (SurveyForm) form; + + // Get contentFolderID and save to form. + String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); + surveyForm.setContentFolderID(contentFolderID); + + // initial Session Map + SessionMap sessionMap = new SessionMap(); + request.getSession().setAttribute(sessionMap.getSessionID(), sessionMap); + surveyForm.setSessionMapID(sessionMap.getSessionID()); + + survey = service.getSurveyByContentId(contentId); + // if survey does not exist, try to use default content instead. + if (survey == null) { + survey = service.getDefaultContent(contentId); + if (survey.getQuestions() != null) { + questions = new ArrayList(survey.getQuestions()); + } else { + questions = null; + } + } else { + questions = new ArrayList(survey.getQuestions()); } - /** - * This method will get necessary information from survey item form and save or update into - * HttpSession SurveyItemList. Notice, this save is not persist them into database, - * just save HttpSession temporarily. Only they will be persist when the entire authoring - * page is being persisted. - * - * @param mapping - * @param form - * @param request - * @param response - * @return - * @throws ServletException - */ - private ActionForward saveOrUpdateItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) - throws Exception { - //get instructions: - List instructionList = getInstructionsFromRequest(request); - - QuestionForm itemForm = (QuestionForm)form; - ActionErrors errors = validateSurveyItem(itemForm,instructionList); - - if(!errors.isEmpty()){ - this.addErrors(request,errors); - //add at least 2 instruction list - for(int idx=instructionList.size();idx < 2;idx++) - instructionList.add(""); - request.setAttribute(SurveyConstants.ATTR_INSTRUCTION_LIST,instructionList); - if(itemForm.getItemType() == SurveyConstants.QUESTION_TYPE_TEXT_ENTRY) - return mapping.findForward(SurveyConstants.FORWARD_OPEN_QUESTION); - else - return mapping.findForward(SurveyConstants.FORWARD_CHOICE_QUESTION); + + surveyForm.setSurvey(survey); + + // initialize instruction attachment list + List attachmentList = getAttachmentList(sessionMap); + attachmentList.clear(); + attachmentList.addAll(survey.getAttachments()); + + // init it to avoid null exception in following handling + if (questions == null) { + questions = new ArrayList(); + } else { + SurveyUser surveyUser = null; + // handle system default question: createBy is null, now set it to current user + for (SurveyQuestion question : questions) { + if (question.getCreateBy() == null) { + if (surveyUser == null) { + // get back login user DTO + HttpSession ss = SessionManager.getSession(); + UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); + surveyUser = new SurveyUser(user, survey); + } + question.setCreateBy(surveyUser); } - - try { - extractFormToSurveyItem(request, instructionList, itemForm); - } catch (Exception e) { - log.error("Uploading failed. The exception is " + e.toString()); - throw e; - } - //set session map ID so that itemlist.jsp can get sessionMAP - request.setAttribute(SurveyConstants.ATTR_SESSION_MAP_ID, itemForm.getSessionMapID()); - request.setAttribute(AttributeNames.PARAM_CONTENT_FOLDER_ID, itemForm.getContentFolderID()); - //return null to close this window - return mapping.findForward(SurveyConstants.SUCCESS); + } } + // init survey item list + SortedSet surveyItemList = getSurveyItemList(sessionMap); + surveyItemList.clear(); + retriveQuestionListForDisplay(questions); + surveyItemList.addAll(questions); + // init condition set + SortedSet conditionSet = getSurveyConditionSet(sessionMap); + conditionSet.clear(); + conditionSet.addAll(survey.getConditions()); - /** - * Read survey data from database and put them into HttpSession. It will redirect to init.do directly after this - * method run successfully. - * - * This method will avoid read database again and lost un-saved resouce item lost when user "refresh page", - * @throws ServletException - * - */ - private ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { - - //save toolContentID into HTTPSession - Long contentId = new Long(WebUtil.readLongParam(request,AttributeNames.PARAM_TOOL_CONTENT_ID)); - -// get back the survey and item list and display them on page - ISurveyService service = getSurveyService(); + sessionMap.put(SurveyConstants.ATTR_SURVEY_FORM, surveyForm); + return mapping.findForward(SurveyConstants.SUCCESS); + } - List questions = null; - Survey survey = null; - SurveyForm surveyForm = (SurveyForm)form; - - // Get contentFolderID and save to form. - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - surveyForm.setContentFolderID(contentFolderID); - - //initial Session Map - SessionMap sessionMap = new SessionMap(); - request.getSession().setAttribute(sessionMap.getSessionID(), sessionMap); - surveyForm.setSessionMapID(sessionMap.getSessionID()); - - survey = service.getSurveyByContentId(contentId); - //if survey does not exist, try to use default content instead. - if(survey == null){ - survey = service.getDefaultContent(contentId); - if(survey.getQuestions() != null){ - questions = new ArrayList(survey.getQuestions()); - }else - questions = null; - }else - questions = new ArrayList(survey.getQuestions()); - - surveyForm.setSurvey(survey); + /** + * Display same entire authoring page content from HttpSession variable. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + * @throws ServletException + */ + private ActionForward initPage(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws ServletException { + String sessionMapID = WebUtil.readStrParam(request, SurveyConstants.ATTR_SESSION_MAP_ID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + SurveyForm existForm = (SurveyForm) sessionMap.get(SurveyConstants.ATTR_SURVEY_FORM); - //initialize instruction attachment list - List attachmentList = getAttachmentList(sessionMap); - attachmentList.clear(); - attachmentList.addAll(survey.getAttachments()); - - //init it to avoid null exception in following handling - if(questions == null) - questions = new ArrayList(); - else{ - SurveyUser surveyUser = null; - //handle system default question: createBy is null, now set it to current user - for (SurveyQuestion question : questions) { - if(question.getCreateBy() == null){ - if(surveyUser == null){ - //get back login user DTO - HttpSession ss = SessionManager.getSession(); - UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); - surveyUser = new SurveyUser(user,survey); - } - question.setCreateBy(surveyUser); - } - } - } - //init survey item list - SortedSet surveyItemList = getSurveyItemList(sessionMap); - surveyItemList.clear(); - retriveQuestionListForDisplay(questions); - surveyItemList.addAll(questions); - - sessionMap.put(SurveyConstants.ATTR_SURVEY_FORM, surveyForm); - return mapping.findForward(SurveyConstants.SUCCESS); + SurveyForm surveyForm = (SurveyForm) form; + try { + PropertyUtils.copyProperties(surveyForm, existForm); + } catch (Exception e) { + throw new ServletException(e); } + ToolAccessMode mode = getAccessMode(request); + if (mode.isAuthor()) { + return mapping.findForward(SurveyConstants.SUCCESS); + } else { + return mapping.findForward(SurveyConstants.DEFINE_LATER); + } + } - /** - * Display same entire authoring page content from HttpSession variable. - * @param mapping - * @param form - * @param request - * @param response - * @return - * @throws ServletException - */ - private ActionForward initPage(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws ServletException { - String sessionMapID = WebUtil.readStrParam(request, SurveyConstants.ATTR_SESSION_MAP_ID); - SessionMap sessionMap = (SessionMap)request.getSession().getAttribute(sessionMapID); - SurveyForm existForm = (SurveyForm) sessionMap.get(SurveyConstants.ATTR_SURVEY_FORM); - - SurveyForm surveyForm = (SurveyForm )form; - try { - PropertyUtils.copyProperties(surveyForm, existForm); - } catch (Exception e) { - throw new ServletException(e); - } - - ToolAccessMode mode = getAccessMode(request); - if(mode.isAuthor()) - return mapping.findForward(SurveyConstants.SUCCESS); - else - return mapping.findForward(SurveyConstants.DEFINE_LATER); + /** + * This method will persist all inforamtion in this authoring page, include all survey item, information etc. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + * @throws ServletException + */ + private ActionForward updateContent(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws Exception { + SurveyForm surveyForm = (SurveyForm) form; + + // get back sessionMAP + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(surveyForm.getSessionMapID()); + + ToolAccessMode mode = getAccessMode(request); + + ActionMessages errors = validate(surveyForm, mapping, request); + if (!errors.isEmpty()) { + saveErrors(request, errors); + if (mode.isAuthor()) { + return mapping.findForward("author"); + } else { + return mapping.findForward("monitor"); + } } - /** - * This method will persist all inforamtion in this authoring page, include all survey item, information etc. - * - * @param mapping - * @param form - * @param request - * @param response - * @return - * @throws ServletException - */ - private ActionForward updateContent(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws Exception { - SurveyForm surveyForm = (SurveyForm)(form); - - //get back sessionMAP - SessionMap sessionMap = (SessionMap)request.getSession().getAttribute(surveyForm.getSessionMapID()); - - ToolAccessMode mode = getAccessMode(request); - - ActionMessages errors = validate(surveyForm, mapping, request); - if(!errors.isEmpty()){ - saveErrors(request, errors); - if(mode.isAuthor()) - return mapping.findForward("author"); - else - return mapping.findForward("monitor"); - } - - - Survey survey = surveyForm.getSurvey(); - ISurveyService service = getSurveyService(); - - //**********************************Get Survey PO********************* - Survey surveyPO = service.getSurveyByContentId(surveyForm.getSurvey().getContentId()); - if(surveyPO == null){ - //new Survey, create it. - surveyPO = survey; - surveyPO.setCreated(new Timestamp(new Date().getTime())); - surveyPO.setUpdated(new Timestamp(new Date().getTime())); - }else{ - if(mode.isAuthor()){ - Long uid = surveyPO.getUid(); - PropertyUtils.copyProperties(surveyPO,survey); - //get back UID - surveyPO.setUid(uid); - }else{ //if it is Teacher, then just update basic tab content (definelater) - surveyPO.setInstructions(survey.getInstructions()); - surveyPO.setTitle(survey.getTitle()); -// change define later status - surveyPO.setDefineLater(false); - } - surveyPO.setUpdated(new Timestamp(new Date().getTime())); - } - - //*******************************Handle user******************* - //try to get form system session - HttpSession ss = SessionManager.getSession(); - //get back login user DTO - UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); - SurveyUser surveyUser = service.getUserByIDAndContent(new Long(user.getUserID().intValue()) - ,surveyForm.getSurvey().getContentId()); - if(surveyUser == null){ - surveyUser = new SurveyUser(user,surveyPO); - } - - surveyPO.setCreatedBy(surveyUser); - - //**********************************Handle Authoring Instruction Attachement ********************* - //merge attachment info - //so far, attPOSet will be empty if content is existed. because PropertyUtils.copyProperties() is executed - Set attPOSet = surveyPO.getAttachments(); - if(attPOSet == null) - attPOSet = new HashSet(); - List attachmentList = getAttachmentList(sessionMap); - List deleteAttachmentList = getDeletedAttachmentList(sessionMap); - - //current attachemnt in authoring instruction tab. - Iterator iter = attachmentList.iterator(); - while(iter.hasNext()){ - SurveyAttachment newAtt = (SurveyAttachment) iter.next(); - attPOSet.add(newAtt); - } - attachmentList.clear(); - - //deleted attachment. 2 possible types: one is persist another is non-persist before. - iter = deleteAttachmentList.iterator(); - while(iter.hasNext()){ - SurveyAttachment delAtt = (SurveyAttachment) iter.next(); - iter.remove(); - //it is an existed att, then delete it from current attachmentPO - if(delAtt.getUid() != null){ - Iterator attIter = attPOSet.iterator(); - while(attIter.hasNext()){ - SurveyAttachment att = (SurveyAttachment) attIter.next(); - if(delAtt.getUid().equals(att.getUid())){ - attIter.remove(); - break; - } - } - service.deleteSurveyAttachment(delAtt.getUid()); - }//end remove from persist value - } - - //copy back - surveyPO.setAttachments(attPOSet); - //************************* Handle survey questions ******************* - //Handle survey items - Set questionList = new LinkedHashSet(); - SortedSet topics = getSurveyItemList(sessionMap); - iter = topics.iterator(); - while(iter.hasNext()){ - SurveyQuestion item = (SurveyQuestion) iter.next(); - if(item != null){ - //This flushs user UID info to message if this user is a new user. - item.setCreateBy(surveyUser); - questionList.add(item); - } - } - surveyPO.setQuestions(questionList); - //delete instructino file from database. - List delSurveyItemList = getDeletedSurveyItemList(sessionMap); - iter = delSurveyItemList.iterator(); - while(iter.hasNext()){ - SurveyQuestion item = (SurveyQuestion) iter.next(); - iter.remove(); - if(item.getUid() != null) - service.deleteQuestion(item.getUid()); - } - - //********************************************** - //finally persist surveyPO again - service.saveOrUpdateSurvey(surveyPO); - - //initialize attachmentList again - attachmentList = getAttachmentList(sessionMap); - attachmentList.addAll(survey.getAttachments()); - surveyForm.setSurvey(surveyPO); - - request.setAttribute(AuthoringConstants.LAMS_AUTHORING_SUCCESS_FLAG,Boolean.TRUE); - if(mode.isAuthor()) - return mapping.findForward("author"); - else - return mapping.findForward("monitor"); + + Survey survey = surveyForm.getSurvey(); + ISurveyService service = getSurveyService(); + + // **********************************Get Survey PO********************* + Survey surveyPO = service.getSurveyByContentId(surveyForm.getSurvey().getContentId()); + if (surveyPO == null) { + // new Survey, create it. + surveyPO = survey; + surveyPO.setCreated(new Timestamp(new Date().getTime())); + surveyPO.setUpdated(new Timestamp(new Date().getTime())); + } else { + if (mode.isAuthor()) { + Long uid = surveyPO.getUid(); + PropertyUtils.copyProperties(surveyPO, survey); + // get back UID + surveyPO.setUid(uid); + } else { // if it is Teacher, then just update basic tab content (definelater) + surveyPO.setInstructions(survey.getInstructions()); + surveyPO.setTitle(survey.getTitle()); + // change define later status + surveyPO.setDefineLater(false); + } + surveyPO.setUpdated(new Timestamp(new Date().getTime())); } - /** - * Handle upload online instruction files request. - * @param mapping - * @param form - * @param request - * @param response - * @return - * @throws UploadSurveyFileException - */ - public ActionForward uploadOnline(ActionMapping mapping, ActionForm form, - HttpServletRequest request, HttpServletResponse response) throws UploadSurveyFileException { - return uploadFile(mapping, form, IToolContentHandler.TYPE_ONLINE,request); + // *******************************Handle user******************* + // try to get form system session + HttpSession ss = SessionManager.getSession(); + // get back login user DTO + UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); + SurveyUser surveyUser = service.getUserByIDAndContent(new Long(user.getUserID().intValue()), surveyForm + .getSurvey().getContentId()); + if (surveyUser == null) { + surveyUser = new SurveyUser(user, surveyPO); } - /** - * Handle upload offline instruction files request. - * @param mapping - * @param form - * @param request - * @param response - * @return - * @throws UploadSurveyFileException - */ - public ActionForward uploadOffline(ActionMapping mapping, ActionForm form, - HttpServletRequest request, HttpServletResponse response) throws UploadSurveyFileException { - return uploadFile(mapping, form, IToolContentHandler.TYPE_OFFLINE,request); + + surveyPO.setCreatedBy(surveyUser); + + // **********************************Handle Authoring Instruction Attachement ********************* + // merge attachment info + // so far, attPOSet will be empty if content is existed. because PropertyUtils.copyProperties() is executed + Set attPOSet = surveyPO.getAttachments(); + if (attPOSet == null) { + attPOSet = new HashSet(); } - /** - * Common method to upload online or offline instruction files request. - * @param mapping - * @param form - * @param type - * @param request - * @return - * @throws UploadSurveyFileException - */ - private ActionForward uploadFile(ActionMapping mapping, ActionForm form, - String type,HttpServletRequest request) throws UploadSurveyFileException { + List attachmentList = getAttachmentList(sessionMap); + List deleteAttachmentList = getDeletedAttachmentList(sessionMap); - SurveyForm surveyForm = (SurveyForm) form; - //get back sessionMAP - SessionMap sessionMap = (SessionMap)request.getSession().getAttribute(surveyForm.getSessionMapID()); + // current attachemnt in authoring instruction tab. + Iterator iter = attachmentList.iterator(); + while (iter.hasNext()) { + SurveyAttachment newAtt = (SurveyAttachment) iter.next(); + attPOSet.add(newAtt); + } + attachmentList.clear(); - FormFile file; - if(StringUtils.equals(IToolContentHandler.TYPE_OFFLINE,type)) - file = (FormFile) surveyForm.getOfflineFile(); - else - file = (FormFile) surveyForm.getOnlineFile(); - - if(file == null || StringUtils.isBlank(file.getFileName())) - return mapping.findForward(SurveyConstants.SUCCESS); - - ActionMessages errors = new ActionMessages(); - FileValidatorUtil.validateFileSize(file, true, errors ); - if(!errors.isEmpty()){ - this.saveErrors(request, errors); - return mapping.findForward("success"); + // deleted attachment. 2 possible types: one is persist another is non-persist before. + iter = deleteAttachmentList.iterator(); + while (iter.hasNext()) { + SurveyAttachment delAtt = (SurveyAttachment) iter.next(); + iter.remove(); + // it is an existed att, then delete it from current attachmentPO + if (delAtt.getUid() != null) { + Iterator attIter = attPOSet.iterator(); + while (attIter.hasNext()) { + SurveyAttachment att = (SurveyAttachment) attIter.next(); + if (delAtt.getUid().equals(att.getUid())) { + attIter.remove(); + break; + } } + service.deleteSurveyAttachment(delAtt.getUid()); + }// end remove from persist value + } - ISurveyService service = getSurveyService(); - //upload to repository - SurveyAttachment att = service.uploadInstructionFile(file, type); - //handle session value - List attachmentList = getAttachmentList(sessionMap); - List deleteAttachmentList = getDeletedAttachmentList(sessionMap); - //first check exist attachment and delete old one (if exist) to deletedAttachmentList - Iterator iter = attachmentList.iterator(); - SurveyAttachment existAtt; - while(iter.hasNext()){ - existAtt = (SurveyAttachment) iter.next(); - if(StringUtils.equals(existAtt.getFileName(),att.getFileName()) - && StringUtils.equals(existAtt.getFileType(),att.getFileType())){ - //if there is same name attachment, delete old one - deleteAttachmentList.add(existAtt); - iter.remove(); - break; - } - } - //add to attachmentList - attachmentList.add(att); + // copy back + surveyPO.setAttachments(attPOSet); + // ************************* Handle survey questions ******************* + // Handle survey items + Set questionList = new LinkedHashSet(); + SortedSet topics = getSurveyItemList(sessionMap); + iter = topics.iterator(); + while (iter.hasNext()) { + SurveyQuestion item = (SurveyQuestion) iter.next(); + if (item != null) { + // This flushs user UID info to message if this user is a new user. + item.setCreateBy(surveyUser); + questionList.add(item); + } + } + surveyPO.setQuestions(questionList); + // delete instructino file from database. + List delSurveyItemList = getDeletedSurveyItemList(sessionMap); + iter = delSurveyItemList.iterator(); + while (iter.hasNext()) { + SurveyQuestion item = (SurveyQuestion) iter.next(); + iter.remove(); + if (item.getUid() != null) { + service.deleteQuestion(item.getUid()); + } + } - return mapping.findForward(SurveyConstants.SUCCESS); + Set conditionSet = new TreeSet(new TextSearchConditionComparator()); + Set existingConditionSet = getSurveyConditionSet(sessionMap); + conditionSet.addAll(existingConditionSet); + surveyPO.setConditions(conditionSet); + // ********************************************** + // finally persist surveyPO again + service.saveOrUpdateSurvey(surveyPO); + + // initialize attachmentList again + attachmentList = getAttachmentList(sessionMap); + attachmentList.addAll(survey.getAttachments()); + surveyForm.setSurvey(surveyPO); + + request.setAttribute(AuthoringConstants.LAMS_AUTHORING_SUCCESS_FLAG, Boolean.TRUE); + if (mode.isAuthor()) { + return mapping.findForward("author"); + } else { + return mapping.findForward("monitor"); } - /** - * Delete offline instruction file from current Survey authoring page. - * @param mapping - * @param form - * @param request - * @param response - * @return - */ - public ActionForward deleteOfflineFile(ActionMapping mapping, ActionForm form, - HttpServletRequest request, HttpServletResponse response) { - return deleteFile(mapping,request, response,form, IToolContentHandler.TYPE_OFFLINE); + } + + /** + * Handle upload online instruction files request. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + * @throws UploadSurveyFileException + */ + public ActionForward uploadOnline(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws UploadSurveyFileException { + return uploadFile(mapping, form, IToolContentHandler.TYPE_ONLINE, request); + } + + /** + * Handle upload offline instruction files request. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + * @throws UploadSurveyFileException + */ + public ActionForward uploadOffline(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws UploadSurveyFileException { + return uploadFile(mapping, form, IToolContentHandler.TYPE_OFFLINE, request); + } + + /** + * Common method to upload online or offline instruction files request. + * + * @param mapping + * @param form + * @param type + * @param request + * @return + * @throws UploadSurveyFileException + */ + private ActionForward uploadFile(ActionMapping mapping, ActionForm form, String type, HttpServletRequest request) + throws UploadSurveyFileException { + + SurveyForm surveyForm = (SurveyForm) form; + // get back sessionMAP + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(surveyForm.getSessionMapID()); + + FormFile file; + if (StringUtils.equals(IToolContentHandler.TYPE_OFFLINE, type)) { + file = surveyForm.getOfflineFile(); + } else { + file = surveyForm.getOnlineFile(); } - /** - * Delete online instruction file from current Survey authoring page. - * @param mapping - * @param form - * @param request - * @param response - * @return - */ - public ActionForward deleteOnlineFile(ActionMapping mapping, ActionForm form, - HttpServletRequest request, HttpServletResponse response) { - return deleteFile(mapping, request, response,form, IToolContentHandler.TYPE_ONLINE); + + if (file == null || StringUtils.isBlank(file.getFileName())) { + return mapping.findForward(SurveyConstants.SUCCESS); } - /** - * General method to delete file (online or offline) - * @param mapping - * @param request - * @param response - * @param form - * @param type - * @return - */ - private ActionForward deleteFile(ActionMapping mapping, HttpServletRequest request, HttpServletResponse response, ActionForm form, String type) { - Long versionID = new Long(WebUtil.readLongParam(request,SurveyConstants.PARAM_FILE_VERSION_ID)); - Long uuID = new Long(WebUtil.readLongParam(request,SurveyConstants.PARAM_FILE_UUID)); - - //get back sessionMAP - String sessionMapID = WebUtil.readStrParam(request, SurveyConstants.ATTR_SESSION_MAP_ID); - SessionMap sessionMap = (SessionMap)request.getSession().getAttribute(sessionMapID); - - //handle session value - List attachmentList = getAttachmentList(sessionMap); - List deleteAttachmentList = getDeletedAttachmentList(sessionMap); - //first check exist attachment and delete old one (if exist) to deletedAttachmentList - Iterator iter = attachmentList.iterator(); - SurveyAttachment existAtt; - while(iter.hasNext()){ - existAtt = (SurveyAttachment) iter.next(); - if(existAtt.getFileUuid().equals(uuID) && existAtt.getFileVersionId().equals(versionID)){ - //if there is same name attachment, delete old one - deleteAttachmentList.add(existAtt); - iter.remove(); - } - } + ActionMessages errors = new ActionMessages(); + FileValidatorUtil.validateFileSize(file, true, errors); + if (!errors.isEmpty()) { + this.saveErrors(request, errors); + return mapping.findForward("success"); + } - request.setAttribute(SurveyConstants.ATTR_FILE_TYPE_FLAG, type); - request.setAttribute(SurveyConstants.ATTR_SESSION_MAP_ID, sessionMapID); - return mapping.findForward(SurveyConstants.SUCCESS); + ISurveyService service = getSurveyService(); + // upload to repository + SurveyAttachment att = service.uploadInstructionFile(file, type); + // handle session value + List attachmentList = getAttachmentList(sessionMap); + List deleteAttachmentList = getDeletedAttachmentList(sessionMap); + // first check exist attachment and delete old one (if exist) to deletedAttachmentList + Iterator iter = attachmentList.iterator(); + SurveyAttachment existAtt; + while (iter.hasNext()) { + existAtt = (SurveyAttachment) iter.next(); + if (StringUtils.equals(existAtt.getFileName(), att.getFileName()) + && StringUtils.equals(existAtt.getFileType(), att.getFileType())) { + // if there is same name attachment, delete old one + deleteAttachmentList.add(existAtt); + iter.remove(); + break; + } + } + // add to attachmentList + attachmentList.add(att); + return mapping.findForward(SurveyConstants.SUCCESS); + + } + + /** + * Delete offline instruction file from current Survey authoring page. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + public ActionForward deleteOfflineFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + return deleteFile(mapping, request, response, form, IToolContentHandler.TYPE_OFFLINE); + } + + /** + * Delete online instruction file from current Survey authoring page. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + public ActionForward deleteOnlineFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + return deleteFile(mapping, request, response, form, IToolContentHandler.TYPE_ONLINE); + } + + /** + * General method to delete file (online or offline) + * + * @param mapping + * @param request + * @param response + * @param form + * @param type + * @return + */ + private ActionForward deleteFile(ActionMapping mapping, HttpServletRequest request, HttpServletResponse response, + ActionForm form, String type) { + Long versionID = new Long(WebUtil.readLongParam(request, SurveyConstants.PARAM_FILE_VERSION_ID)); + Long uuID = new Long(WebUtil.readLongParam(request, SurveyConstants.PARAM_FILE_UUID)); + + // get back sessionMAP + String sessionMapID = WebUtil.readStrParam(request, SurveyConstants.ATTR_SESSION_MAP_ID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + + // handle session value + List attachmentList = getAttachmentList(sessionMap); + List deleteAttachmentList = getDeletedAttachmentList(sessionMap); + // first check exist attachment and delete old one (if exist) to deletedAttachmentList + Iterator iter = attachmentList.iterator(); + SurveyAttachment existAtt; + while (iter.hasNext()) { + existAtt = (SurveyAttachment) iter.next(); + if (existAtt.getFileUuid().equals(uuID) && existAtt.getFileVersionId().equals(versionID)) { + // if there is same name attachment, delete old one + deleteAttachmentList.add(existAtt); + iter.remove(); + } } - //************************************************************************************* - // Private method - //************************************************************************************* - /** - * Return SurveyService bean. - */ - private ISurveyService getSurveyService() { - WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet().getServletContext()); - return (ISurveyService) wac.getBean(SurveyConstants.SURVEY_SERVICE); + + request.setAttribute(SurveyConstants.ATTR_FILE_TYPE_FLAG, type); + request.setAttribute(SurveyConstants.ATTR_SESSION_MAP_ID, sessionMapID); + return mapping.findForward(SurveyConstants.SUCCESS); + + } + + // ************************************************************************************* + // Private method + // ************************************************************************************* + /** + * Return SurveyService bean. + */ + private ISurveyService getSurveyService() { + WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet() + .getServletContext()); + return (ISurveyService) wac.getBean(SurveyConstants.SURVEY_SERVICE); + } + + /** + * @param request + * @return + */ + private List getAttachmentList(SessionMap sessionMap) { + return getListFromSession(sessionMap, SurveyConstants.ATT_ATTACHMENT_LIST); + } + + /** + * @param request + * @return + */ + private List getDeletedAttachmentList(SessionMap sessionMap) { + return getListFromSession(sessionMap, SurveyConstants.ATTR_DELETED_ATTACHMENT_LIST); + } + + /** + * List save current survey items. + * + * @param request + * @return + */ + private SortedSet getSurveyItemList(SessionMap sessionMap) { + SortedSet list = (SortedSet) sessionMap.get(SurveyConstants.ATTR_QUESTION_LIST); + if (list == null) { + list = new TreeSet(new QuestionsComparator()); + sessionMap.put(SurveyConstants.ATTR_QUESTION_LIST, list); } - /** - * @param request - * @return - */ - private List getAttachmentList(SessionMap sessionMap) { - return getListFromSession(sessionMap,SurveyConstants.ATT_ATTACHMENT_LIST); + return list; + } + + /** + * Set of conditions. + * + * @param request + * @return + */ + private SortedSet getSurveyConditionSet(SessionMap sessionMap) { + SortedSet set = (SortedSet) sessionMap + .get(SurveyConstants.ATTR_CONDITION_SET); + if (set == null) { + set = new TreeSet(new TextSearchConditionComparator()); + sessionMap.put(SurveyConstants.ATTR_CONDITION_SET, set); } - /** - * @param request - * @return - */ - private List getDeletedAttachmentList(SessionMap sessionMap) { - return getListFromSession(sessionMap,SurveyConstants.ATTR_DELETED_ATTACHMENT_LIST); + return set; + } + + /** + * List save deleted survey items, which could be persisted or non-persisted items. + * + * @param request + * @return + */ + private List getDeletedSurveyItemList(SessionMap sessionMap) { + return getListFromSession(sessionMap, SurveyConstants.ATTR_DELETED_QUESTION_LIST); + } + + /** + * Get java.util.List from HttpSession by given name. + * + * @param request + * @param name + * @return + */ + private List getListFromSession(SessionMap sessionMap, String name) { + List list = (List) sessionMap.get(name); + if (list == null) { + list = new ArrayList(); + sessionMap.put(name, list); } - /** - * List save current survey items. - * @param request - * @return - */ - private SortedSet getSurveyItemList(SessionMap sessionMap) { - SortedSet list = (SortedSet) sessionMap.get(SurveyConstants.ATTR_QUESTION_LIST); - if(list == null){ - list = new TreeSet(new QuestionsComparator()); - sessionMap.put(SurveyConstants.ATTR_QUESTION_LIST,list); - } - return list; - } - /** - * List save deleted survey items, which could be persisted or non-persisted items. - * @param request - * @return - */ - private List getDeletedSurveyItemList(SessionMap sessionMap) { - return getListFromSession(sessionMap,SurveyConstants.ATTR_DELETED_QUESTION_LIST); + return list; + } + + /** + * Get survey items instruction from HttpRequest + * + * @param request + */ + private List getInstructionsFromRequest(HttpServletRequest request) { + String list = request.getParameter("instructionList"); + List instructionList = new ArrayList(); + // for open text entry question + if (list == null) { + return instructionList; } - /** - * Get java.util.List from HttpSession by given name. - * - * @param request - * @param name - * @return - */ - private List getListFromSession(SessionMap sessionMap,String name) { - List list = (List) sessionMap.get(name); - if(list == null){ - list = new ArrayList(); - sessionMap.put(name,list); - } - return list; + String[] params = list.split("&"); + Map paramMap = new HashMap(); + String[] pair; + for (String item : params) { + pair = item.split("="); + if (pair == null || pair.length != 2) { + continue; + } + try { + paramMap.put(pair[0], URLDecoder.decode(pair[1], "UTF-8")); + } catch (UnsupportedEncodingException e) { + AuthoringAction.log.error("Error occurs when decode instruction string:" + e.toString()); + } } - - - /** - * Get survey items instruction from HttpRequest - * @param request - */ - private List getInstructionsFromRequest(HttpServletRequest request) { - String list = request.getParameter("instructionList"); - List instructionList = new ArrayList(); - //for open text entry question - if(list == null) - return instructionList; - - String[] params = list.split("&"); - Map paramMap = new HashMap(); - String[] pair; - for (String item: params) { - pair = item.split("="); - if(pair == null || pair.length != 2) - continue; - try { - paramMap.put(pair[0],URLDecoder.decode(pair[1],"UTF-8")); - } catch (UnsupportedEncodingException e) { - log.error("Error occurs when decode instruction string:" + e.toString()); - } - } - - int count = NumberUtils.stringToInt(paramMap.get(INSTRUCTION_ITEM_COUNT)); - for(int idx=0;idx= 0) { + form.setItemIndex(new Integer(itemIdx).toString()); + } - /** - * This method will populate survey item information to its form for edit use. - * @param itemIdx - * @param item - * @param form - * @param request - */ - private void populateItemToForm(int itemIdx, SurveyQuestion item, QuestionForm form, HttpServletRequest request) { - if(itemIdx >=0) - form.setItemIndex(new Integer(itemIdx).toString()); - - //set questions - form.setQuestion(item); - - //set options - Set instructionList = item.getOptions(); - List instructions = new ArrayList(); - for(SurveyOption in : instructionList){ - instructions.add(in.getDescription()); - } - - request.setAttribute(SurveyConstants.ATTR_INSTRUCTION_LIST,instructions); - + // set questions + form.setQuestion(item); + + // set options + Set instructionList = item.getOptions(); + List instructions = new ArrayList(); + for (SurveyOption in : instructionList) { + instructions.add(in.getDescription()); } - /** - * Extract web from content to survey item. - * @param request - * @param instructionList - * @param itemForm - * @throws SurveyApplicationException + + request.setAttribute(SurveyConstants.ATTR_INSTRUCTION_LIST, instructions); + + } + + /** + * Extract web from content to survey item. + * + * @param request + * @param instructionList + * @param itemForm + * @throws SurveyApplicationException + */ + private void extractFormToSurveyItem(HttpServletRequest request, List instructionList, QuestionForm itemForm) + throws Exception { + /* + * BE CAREFUL: This method will copy nessary info from request form to a old or new SurveyItem instance. It gets + * all info EXCEPT SurveyItem.createDate and SurveyItem.createBy, which need be set when persisting this survey + * item. */ - private void extractFormToSurveyItem(HttpServletRequest request, List instructionList, QuestionForm itemForm) - throws Exception { - /* BE CAREFUL: This method will copy nessary info from request form to a old or new SurveyItem instance. - * It gets all info EXCEPT SurveyItem.createDate and SurveyItem.createBy, which need be set when persisting - * this survey item. - */ - - SessionMap sessionMap = (SessionMap)request.getSession().getAttribute(itemForm.getSessionMapID()); - //check whether it is "edit(old item)" or "add(new item)" - SortedSet surveyList = getSurveyItemList(sessionMap); - int itemIdx = NumberUtils.stringToInt(itemForm.getItemIndex(),-1); - SurveyQuestion item = itemForm.getQuestion(); - - if(itemIdx == -1){ //add - item.setCreateDate(new Timestamp(new Date().getTime())); - int maxSeq = 1; - if(surveyList != null && surveyList.size() > 0){ - SurveyQuestion last = surveyList.last(); - maxSeq = last.getSequenceId()+1; - } - item.setSequenceId(maxSeq); - surveyList.add(item); - }else{ //edit - List rList = new ArrayList(surveyList); - item = rList.get(itemIdx); - item.setDescription(itemForm.getQuestion().getDescription()); - item.setOptional(itemForm.getQuestion().isOptional()); - item.setAppendText(itemForm.getQuestion().isAppendText()); - item.setAllowMultipleAnswer(itemForm.getQuestion().isAllowMultipleAnswer()); - - } - retriveQuestionForDisplay(item); - short type = getQuestionType(itemForm); - item.setType(type); - //set instrcutions - Set instructions = new LinkedHashSet(); - int idx=0; - for (String ins : instructionList) { - SurveyOption rii = new SurveyOption(); - rii.setDescription(ins); - rii.setSequenceId(idx++); - instructions.add(rii); - } - item.setOptions(instructions); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(itemForm.getSessionMapID()); + // check whether it is "edit(old item)" or "add(new item)" + SortedSet surveyList = getSurveyItemList(sessionMap); + int itemIdx = NumberUtils.stringToInt(itemForm.getItemIndex(), -1); + SurveyQuestion item = itemForm.getQuestion(); - - + if (itemIdx == -1) { // add + item.setCreateDate(new Timestamp(new Date().getTime())); + int maxSeq = 1; + if (surveyList != null && surveyList.size() > 0) { + SurveyQuestion last = surveyList.last(); + maxSeq = last.getSequenceId() + 1; + } + item.setSequenceId(maxSeq); + surveyList.add(item); + } else { // edit + List rList = new ArrayList(surveyList); + item = rList.get(itemIdx); + item.setDescription(itemForm.getQuestion().getDescription()); + item.setOptional(itemForm.getQuestion().isOptional()); + item.setAppendText(itemForm.getQuestion().isAppendText()); + item.setAllowMultipleAnswer(itemForm.getQuestion().isAllowMultipleAnswer()); + } + retriveQuestionForDisplay(item); + short type = getQuestionType(itemForm); + item.setType(type); + // set instrcutions + Set instructions = new LinkedHashSet(); + int idx = 0; + for (String ins : instructionList) { + SurveyOption rii = new SurveyOption(); + rii.setDescription(ins); + rii.setSequenceId(idx++); + instructions.add(rii); + } + item.setOptions(instructions); - private short getQuestionType(QuestionForm itemForm) { - //set question type - short type; - if(itemForm.getItemType() == SurveyConstants.SURVEY_TYPE_TEXT_ENTRY) - type = SurveyConstants.SURVEY_TYPE_TEXT_ENTRY; - else if( itemForm.getQuestion().isAllowMultipleAnswer()) - type = SurveyConstants.SURVEY_TYPE_MULTIPLE_CHOICES; - else - type = SurveyConstants.SURVEY_TYPE_SINGLE_CHOICE; - return type; + } + + private short getQuestionType(QuestionForm itemForm) { + // set question type + short type; + if (itemForm.getItemType() == SurveyConstants.SURVEY_TYPE_TEXT_ENTRY) { + type = SurveyConstants.SURVEY_TYPE_TEXT_ENTRY; + } else if (itemForm.getQuestion().isAllowMultipleAnswer()) { + type = SurveyConstants.SURVEY_TYPE_MULTIPLE_CHOICES; + } else { + type = SurveyConstants.SURVEY_TYPE_SINGLE_CHOICE; } - - private void retriveQuestionListForDisplay(List list) { - for(SurveyQuestion item: list){ - retriveQuestionForDisplay(item); - } + return type; + } + + private void retriveQuestionListForDisplay(List list) { + for (SurveyQuestion item : list) { + retriveQuestionForDisplay(item); } - public static void retriveQuestionForDisplay(SurveyQuestion item) { - String desc = item.getDescription(); - desc = desc.replaceAll("<(.|\n)*?>", ""); - item.setShortTitle(StringUtils.abbreviate(desc,SHORT_TITLE_LENGTH)); + } + + public static void retriveQuestionForDisplay(SurveyQuestion item) { + String desc = item.getDescription(); + desc = desc.replaceAll("<(.|\n)*?>", ""); + item.setShortTitle(StringUtils.abbreviate(desc, AuthoringAction.SHORT_TITLE_LENGTH)); + } + + /** + * Vaidate survey item regards to their type (url/file/learning object/website zip file) + * + * @param itemForm + * @param instructionList + * @return + */ + private ActionErrors validateSurveyItem(QuestionForm itemForm, List instructionList) { + ActionErrors errors = new ActionErrors(); + if (StringUtils.isBlank(itemForm.getQuestion().getDescription())) { + errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(SurveyConstants.ERROR_MSG_DESC_BLANK)); } - /** - * Vaidate survey item regards to their type (url/file/learning object/website zip file) - * @param itemForm - * @param instructionList - * @return - */ - private ActionErrors validateSurveyItem(QuestionForm itemForm, List instructionList) { - ActionErrors errors = new ActionErrors(); - if(StringUtils.isBlank(itemForm.getQuestion().getDescription())) - errors.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage(SurveyConstants.ERROR_MSG_DESC_BLANK)); - - short type = getQuestionType(itemForm); - if(type != SurveyConstants.QUESTION_TYPE_TEXT_ENTRY){ - if(instructionList == null || instructionList.size() < 2) - errors.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage(SurveyConstants.ERROR_MSG_LESS_OPTIONS)); - } - - return errors; + short type = getQuestionType(itemForm); + if (type != SurveyConstants.QUESTION_TYPE_TEXT_ENTRY) { + if (instructionList == null || instructionList.size() < 2) { + errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(SurveyConstants.ERROR_MSG_LESS_OPTIONS)); + } } - /** - * Get ToolAccessMode from HttpRequest parameters. Default value is AUTHOR mode. - * @param request - * @return - */ - private ToolAccessMode getAccessMode(HttpServletRequest request) { - ToolAccessMode mode; - String modeStr = request.getParameter(AttributeNames.ATTR_MODE); - if(StringUtils.equalsIgnoreCase(modeStr,ToolAccessMode.TEACHER.toString())) - mode = ToolAccessMode.TEACHER; - else - mode = ToolAccessMode.AUTHOR; - return mode; + return errors; + } + + /** + * Get ToolAccessMode from HttpRequest parameters. Default value is AUTHOR mode. + * + * @param request + * @return + */ + private ToolAccessMode getAccessMode(HttpServletRequest request) { + ToolAccessMode mode; + String modeStr = request.getParameter(AttributeNames.ATTR_MODE); + if (StringUtils.equalsIgnoreCase(modeStr, ToolAccessMode.TEACHER.toString())) { + mode = ToolAccessMode.TEACHER; + } else { + mode = ToolAccessMode.AUTHOR; } - - - private ActionMessages validate(SurveyForm surveyForm, ActionMapping mapping, HttpServletRequest request) { - ActionMessages errors = new ActionMessages(); -// if (StringUtils.isBlank(surveyForm.getSurvey().getTitle())) { -// ActionMessage error = new ActionMessage("error.title.empty"); -// errors.add(ActionMessages.GLOBAL_MESSAGE, error); -// } - - //define it later mode(TEACHER) skip below validation. - String modeStr = request.getParameter(AttributeNames.ATTR_MODE); - if(StringUtils.equals(modeStr, ToolAccessMode.TEACHER.toString())){ - return errors; - } + return mode; + } - //Some other validation outside basic Tab. - - return errors; + private ActionMessages validate(SurveyForm surveyForm, ActionMapping mapping, HttpServletRequest request) { + ActionMessages errors = new ActionMessages(); + // if (StringUtils.isBlank(surveyForm.getSurvey().getTitle())) { + // ActionMessage error = new ActionMessage("error.title.empty"); + // errors.add(ActionMessages.GLOBAL_MESSAGE, error); + // } + + // define it later mode(TEACHER) skip below validation. + String modeStr = request.getParameter(AttributeNames.ATTR_MODE); + if (StringUtils.equals(modeStr, ToolAccessMode.TEACHER.toString())) { + return errors; } - /** - * Ajax call, will add one more input line for new survey item instruction. - * @param mapping - * @param form - * @param request - * @param response - * @return - */ - private ActionForward newInstruction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { - int count = NumberUtils.stringToInt(request.getParameter(INSTRUCTION_ITEM_COUNT),0); - List instructionList = new ArrayList(++count); - for(int idx=0;idxAuthoringAction action. + * + * @author Marcin Cieslak + * @see org.lamsfoundation.lams.tool.survey.web.action.AuthoringAction + */ +public class AuthoringConditionAction extends Action { + + @Override + public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + String param = mapping.getParameter(); + + if (param.equals("newConditionInit")) { + return newConditionInit(mapping, form, request, response); + } + if (param.equals("editCondition")) { + return editCondition(mapping, form, request, response); + } + if (param.equals("saveOrUpdateCondition")) { + return saveOrUpdateCondition(mapping, form, request, response); + } + if (param.equals("removeCondition")) { + return removeCondition(mapping, form, request, response); + } + if (param.equals("upCondition")) { + return upCondition(mapping, form, request, response); + } + if (param.equals("downCondition")) { + return downCondition(mapping, form, request, response); + } + return null; + } + + /** + * Display empty page for a new condition. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward newConditionInit(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + + populateFormWithPossibleItems(form, request); + ((SurveyConditionForm) form).setOrderId(-1); + return mapping.findForward("addcondition"); + } + + /** + * Display edit page for an existing condition. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward editCondition(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + + SurveyConditionForm SurveyConditionForm = (SurveyConditionForm) form; + String sessionMapID = SurveyConditionForm.getSessionMapID(); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + + int orderId = NumberUtils.stringToInt(request.getParameter(SurveyConstants.PARAM_ORDER_ID), -1); + SurveyCondition condition = null; + if (orderId != -1) { + SortedSet conditionSet = getSurveyConditionSet(sessionMap); + List conditionList = new ArrayList(conditionSet); + condition = conditionList.get(orderId); + if (condition != null) { + populateConditionToForm(orderId, condition, SurveyConditionForm, request); + } + } + + populateFormWithPossibleItems(form, request); + return condition == null ? null : mapping.findForward("addcondition"); + } + + /** + * This method will get necessary information from condition form and save or update into HttpSession + * condition list. Notice, this save is not persist them into database, just save HttpSession + * temporarily. Only they will be persist when the entire authoring page is being persisted. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + * @throws ServletException + */ + private ActionForward saveOrUpdateCondition(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + + SurveyConditionForm conditionForm = (SurveyConditionForm) form; + ActionErrors errors = validateSurveyCondition(conditionForm, request); + + if (!errors.isEmpty()) { + populateFormWithPossibleItems(form, request); + this.addErrors(request, errors); + return mapping.findForward("addcondition"); + } + + try { + extractFormToSurveyCondition(request, conditionForm); + } catch (Exception e) { + + errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.condition", e.getMessage())); + if (!errors.isEmpty()) { + populateFormWithPossibleItems(form, request); + this.addErrors(request, errors); + return mapping.findForward("addcondition"); + } + } + + request.setAttribute(SurveyConstants.ATTR_SESSION_MAP_ID, conditionForm.getSessionMapID()); + + return mapping.findForward(SurveyConstants.SUCCESS); + } + + /** + * Remove condition from HttpSession list and update page display. As authoring rule, all persist only happen when + * user submit whole page. So this remove is just impact HttpSession values. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward removeCondition(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + + // get back sessionMAP + String sessionMapID = WebUtil.readStrParam(request, SurveyConstants.ATTR_SESSION_MAP_ID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + + int orderId = NumberUtils.stringToInt(request.getParameter(SurveyConstants.PARAM_ORDER_ID), -1); + if (orderId != -1) { + SortedSet conditionSet = getSurveyConditionSet(sessionMap); + List conditionList = new ArrayList(conditionSet); + SurveyCondition condition = conditionList.remove(orderId); + conditionSet.clear(); + conditionSet.addAll(conditionList); + // add to delList + List deletedList = getDeletedSurveyConditionList(sessionMap); + deletedList.add(condition); + } + + request.setAttribute(SurveyConstants.ATTR_SESSION_MAP_ID, sessionMapID); + return mapping.findForward(SurveyConstants.SUCCESS); + } + + /** + * Move up current item. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward upCondition(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + return switchItem(mapping, request, true); + } + + /** + * Move down current item. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward downCondition(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + return switchItem(mapping, request, false); + } + + private ActionForward switchItem(ActionMapping mapping, HttpServletRequest request, boolean up) { + // get back sessionMAP + String sessionMapID = WebUtil.readStrParam(request, SurveyConstants.ATTR_SESSION_MAP_ID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + + int orderId = NumberUtils.stringToInt(request.getParameter(SurveyConstants.PARAM_ORDER_ID), -1); + if (orderId != -1) { + SortedSet conditionSet = getSurveyConditionSet(sessionMap); + List conditionList = new ArrayList(conditionSet); + // get current and the target item, and switch their sequnece + SurveyCondition condition = conditionList.get(orderId); + SurveyCondition repCondition; + if (up) { + repCondition = conditionList.get(--orderId); + } else { + repCondition = conditionList.get(++orderId); + } + int upSeqId = repCondition.getOrderId(); + repCondition.setOrderId(condition.getOrderId()); + condition.setOrderId(upSeqId); + + // put back list, it will be sorted again + conditionSet.clear(); + conditionSet.addAll(conditionList); + } + + request.setAttribute(SurveyConstants.ATTR_SESSION_MAP_ID, sessionMapID); + return mapping.findForward(SurveyConstants.SUCCESS); + } + + // ************************************************************************************* + // Private methods for internal needs + // ************************************************************************************* + /** + * Return SurveyService bean. + */ + private ISurveyService getSurveyService() { + WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet() + .getServletContext()); + return (ISurveyService) wac.getBean(SurveyConstants.SURVEY_SERVICE); + } + + /** + * List save current taskList items. + * + * @param request + * @return + */ + private SortedSet getSurveyConditionSet(SessionMap sessionMap) { + SortedSet list = (SortedSet) sessionMap + .get(SurveyConstants.ATTR_CONDITION_SET); + if (list == null) { + list = new TreeSet(new TextSearchConditionComparator()); + sessionMap.put(SurveyConstants.ATTR_CONDITION_SET, list); + } + return list; + } + + private SortedSet getSurveyQuestionSet(SessionMap sessionMap) { + SortedSet list = (SortedSet) sessionMap.get(SurveyConstants.ATTR_QUESTION_LIST); + if (list == null) { + list = new TreeSet(new QuestionsComparator()); + sessionMap.put(SurveyConstants.ATTR_QUESTION_LIST, list); + } + return list; + } + + /** + * Get the deleted condition list, which could be persisted or non-persisted items. + * + * @param request + * @return + */ + private List getDeletedSurveyConditionList(SessionMap sessionMap) { + return getListFromSession(sessionMap, SurveyConstants.ATTR_DELETED_CONDITION_LIST); + } + + /** + * Get java.util.List from HttpSession by given name. + * + * @param request + * @param name + * @return + */ + private List getListFromSession(SessionMap sessionMap, String name) { + List list = (List) sessionMap.get(name); + if (list == null) { + list = new ArrayList(); + sessionMap.put(name, list); + } + return list; + } + + /** + * This method will populate condition information to its form for edit use. + * + * @param orderId + * @param condition + * @param form + * @param request + */ + private void populateConditionToForm(int orderId, SurveyCondition condition, SurveyConditionForm form, + HttpServletRequest request) { + form.populateForm(condition); + if (orderId >= 0) { + form.setOrderId(orderId + 1); + } + + Integer[] selectedItems = new Integer[condition.getQuestions().size()]; + int i = 0; + for (SurveyQuestion question : condition.getQuestions()) { + selectedItems[i++] = new Integer(question.getSequenceId()); + } + form.setSelectedItems(selectedItems); + } + + /** + * This method will populate questions to choose to the form for edit use. + * + * @param sequenceId + * @param condition + * @param form + * @param request + */ + private void populateFormWithPossibleItems(ActionForm form, HttpServletRequest request) { + SurveyConditionForm conditionForm = (SurveyConditionForm) form; + // get back sessionMAP + String sessionMapID = conditionForm.getSessionMapID(); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + + Set questions = getSurveyQuestionSet(sessionMap); + + // Initialise the LabelValueBeans in the possibleOptions array. + + List lvBeans = new LinkedList(); + int i = 0; + for (SurveyQuestion question : questions) { + if (question.getType() == SurveyConstants.QUESTION_TYPE_TEXT_ENTRY) { + lvBeans.add(new LabelValueBean(question.getShortTitle(), new Integer(question.getSequenceId()) + .toString())); + } + } + conditionForm.setPossibleItems(lvBeans.toArray(new LabelValueBean[] {})); + } + + /** + * Extract form content to SurveyCondition. + * + * @param request + * @param form + * @throws QaException + */ + private void extractFormToSurveyCondition(HttpServletRequest request, SurveyConditionForm form) throws Exception { + + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(form.getSessionMapID()); + // check whether it is "edit(old item)" or "add(new item)" + SortedSet conditionSet = getSurveyConditionSet(sessionMap); + int orderId = form.getOrderId(); + SurveyCondition condition = null; + + if (orderId == -1) { // add + String properConditionName = getSurveyService().createConditionName(conditionSet); + condition = form.extractCondition(); + condition.setName(properConditionName); + int maxOrderId = 1; + if (conditionSet != null && conditionSet.size() > 0) { + SurveyCondition last = conditionSet.last(); + maxOrderId = last.getOrderId() + 1; + } + condition.setOrderId(maxOrderId); + conditionSet.add(condition); + } else { // edit + List conditionList = new ArrayList(conditionSet); + condition = conditionList.get(orderId - 1); + form.extractCondition(condition); + } + + Integer[] selectedItems = form.getSelectedItems(); + Set conditionQuestions = new TreeSet(new QuestionsComparator()); + Set questions = getSurveyQuestionSet(sessionMap); + + for (Integer selectedItem : selectedItems) { + for (SurveyQuestion question : questions) { + if (selectedItem.equals(new Integer(question.getSequenceId()))) { + conditionQuestions.add(question); + } + } + } + condition.setQuestions(conditionQuestions); + } + + /** + * Validate SurveyCondition + * + * @param conditionForm + * @return + */ + private ActionErrors validateSurveyCondition(SurveyConditionForm conditionForm, HttpServletRequest request) { + ActionErrors errors = new ActionErrors(); + + String formConditionName = conditionForm.getDisplayName(); + if (StringUtils.isBlank(formConditionName)) { + + errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.condition.name.blank")); + } else { + + Integer formConditionOrderId = conditionForm.getOrderId(); + + String sessionMapID = conditionForm.getSessionMapID(); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + SortedSet conditionSet = getSurveyConditionSet(sessionMap); + for (SurveyCondition condition : conditionSet) { + if (formConditionName.equals(condition.getDisplayName()) + && !formConditionOrderId.equals(condition.getOrderId())) { + + errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.condition.duplicated.name")); + break; + } + } + } + + // should be selected at least one question + Integer[] selectedItems = conditionForm.getSelectedItems(); + if (selectedItems == null || selectedItems.length == 0) { + errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.condition.no.questions.selected")); + } + + return errors; + } + + private ActionMessages validate(SurveyConditionForm form, ActionMapping mapping, HttpServletRequest request) { + return new ActionMessages(); + } +} \ No newline at end of file Index: lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/web/form/SurveyConditionForm.java =================================================================== diff -u --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/web/form/SurveyConditionForm.java (revision 0) +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/web/form/SurveyConditionForm.java (revision 7b79396263b36a933d66390fb9ab12821956d59d) @@ -0,0 +1,117 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +/* $$Id$$ */ +package org.lamsfoundation.lams.tool.survey.web.form; + +import org.apache.struts.util.LabelValueBean; +import org.lamsfoundation.lams.tool.survey.model.SurveyCondition; +import org.lamsfoundation.lams.tool.survey.model.SurveyQuestion; +import org.lamsfoundation.lams.web.TextSearchActionForm; + +/** + * A text search form with additional parameters for Survey needs. + * + * @struts.form name="surveyConditionForm" + * @author Marcin Cieslak + * + */ +public class SurveyConditionForm extends TextSearchActionForm { + /** + * Names of the questions that could be selected by a user. + */ + private LabelValueBean[] possibleItems; + /** + * Numbers of questions that were selected by a user. + */ + private Integer[] selectedItems; + private Integer orderId; + private String displayName; + + public String getDisplayName() { + return displayName; + } + + public void setDisplayName(String name) { + displayName = name; + } + + public SurveyConditionForm() { + } + + public void populateForm(SurveyCondition condition) { + super.populateForm(condition); + setOrderId(condition.getOrderId()); + setDisplayName(condition.getDisplayName()); + Integer[] selectedItems = new Integer[condition.getQuestions().size()]; + int questionIndex = 0; + for (SurveyQuestion question : condition.getQuestions()) { + selectedItems[questionIndex] = new Integer(question.getSequenceId()); + questionIndex++; + } + setSelectedItems(selectedItems); + } + + public LabelValueBean[] getPossibleItems() { + return possibleItems; + } + + public void setPossibleItems(LabelValueBean[] possibleItems) { + this.possibleItems = possibleItems; + } + + public Integer[] getSelectedItems() { + return selectedItems; + } + + public void setSelectedItems(Integer[] selectedItems) { + this.selectedItems = selectedItems; + } + + public Integer getOrderId() { + return orderId; + } + + public void setOrderId(Integer orderId) { + this.orderId = orderId; + } + + /** + * Fills a new SurveyCondition with data contained in this form. Note that some cruicial data is missing, so the + * condition is NOT complete. + * + * @return created condition + */ + public SurveyCondition extractCondition() { + return new SurveyCondition(null, null, getOrderId(), null, getDisplayName(), getAllWords(), getPhrase(), + getAnyWords(), getExcludedWords(), null); + } + + public void extractCondition(SurveyCondition condition) { + condition.setOrderId(getOrderId()); + condition.setDisplayName(getDisplayName()); + condition.setAllWords(getAllWords()); + condition.setPhrase(getPhrase()); + condition.setAnyWords(getAnyWords()); + condition.setExcludedWords(getExcludedWords()); + } +} \ No newline at end of file Index: lams_tool_survey/web/WEB-INF/tags/TextSearch.tag =================================================================== diff -u --- lams_tool_survey/web/WEB-INF/tags/TextSearch.tag (revision 0) +++ lams_tool_survey/web/WEB-INF/tags/TextSearch.tag (revision 7b79396263b36a933d66390fb9ab12821956d59d) @@ -0,0 +1,136 @@ +<% +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + + /** + * TextSearch.tag + * Author: Marcin Cieslak + * Description: Displays form for creating text search conditions. + */ + + %> +<%@ tag body-content="scriptless" %> +<%@ taglib uri="tags-core" prefix="c" %> +<%@ taglib uri="tags-fmt" prefix="fmt" %> +<%@ taglib uri="tags-html" prefix="html" %> +<%@ taglib uri="tags-lams" prefix="lams" %> + +<%-- Required attributes --%> +<%@ attribute name="sessionMapID" required="true" rtexprvalue="true" %> +<%@ attribute name="wrapInFormTag" required="true" rtexprvalue="true" %> + +<%-- Optional attributes --%> +<%@ attribute name="action" required="false" rtexprvalue="true" %> +<%@ attribute name="formID" required="false" rtexprvalue="true" %> +<%@ attribute name="headingLabelKey" required="false" rtexprvalue="true" %> +<%@ attribute name="allWordsLabelKey" required="false" rtexprvalue="true" %> +<%@ attribute name="phraseLabelKey" required="false" rtexprvalue="true" %> +<%@ attribute name="anyWordsLabelKey" required="false" rtexprvalue="true" %> +<%@ attribute name="excludedWordsLabelKey" required="false" rtexprvalue="true" %> +<%@ attribute name="saveButtonLabelKey" required="false" rtexprvalue="true" %> +<%@ attribute name="cancelButtonLabelKey" required="false" rtexprvalue="true" %> +<%@ attribute name="cancelAction" required="false" rtexprvalue="true" %> + +<%-- Default value for message key --%> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

+
+ + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + + + + + + + + \ No newline at end of file Index: lams_tool_survey/web/WEB-INF/tlds/lams/lams.tld =================================================================== diff -u -rc5b655c3c11fa9d9b1d76e0ef602acf6363e45f9 -r7b79396263b36a933d66390fb9ab12821956d59d --- lams_tool_survey/web/WEB-INF/tlds/lams/lams.tld (.../lams.tld) (revision c5b655c3c11fa9d9b1d76e0ef602acf6363e45f9) +++ lams_tool_survey/web/WEB-INF/tlds/lams/lams.tld (.../lams.tld) (revision 7b79396263b36a933d66390fb9ab12821956d59d) @@ -466,6 +466,10 @@ ImgButtonWrapper /WEB-INF/tags/ImgButtonWrapper.tag + + + TextSearch + /WEB-INF/tags/TextSearch.tag textarea Index: lams_tool_survey/web/pages/authoring/addCondition.jsp =================================================================== diff -u --- lams_tool_survey/web/pages/authoring/addCondition.jsp (revision 0) +++ lams_tool_survey/web/pages/authoring/addCondition.jsp (revision 7b79396263b36a933d66390fb9ab12821956d59d) @@ -0,0 +1,47 @@ + +<%@ include file="/common/taglibs.jsp"%> + + + + <%@ include file="/common/header.jsp"%> + + + + + + <%@ include file="/common/messages.jsp"%> + + +

+ +

+ +
+ +
+ +
+ +
+ <%-- Text search form fields are being included --%> + +

+ + + + + +
+
+ +
+ + + + + + +
Index: lams_tool_survey/web/pages/authoring/authoring.jsp =================================================================== diff -u -r8e034b984697716860a840db8d1f0fd48f54b96f -r7b79396263b36a933d66390fb9ab12821956d59d --- lams_tool_survey/web/pages/authoring/authoring.jsp (.../authoring.jsp) (revision 8e034b984697716860a840db8d1f0fd48f54b96f) +++ lams_tool_survey/web/pages/authoring/authoring.jsp (.../authoring.jsp) (revision 7b79396263b36a933d66390fb9ab12821956d59d) @@ -57,6 +57,7 @@ + @@ -83,8 +84,11 @@ + + + + - <%-- Default value cancelButtonLabelKey="label.authoring.cancel.button" Index: lams_tool_survey/web/pages/authoring/conditionList.jsp =================================================================== diff -u --- lams_tool_survey/web/pages/authoring/conditionList.jsp (revision 0) +++ lams_tool_survey/web/pages/authoring/conditionList.jsp (revision 7b79396263b36a933d66390fb9ab12821956d59d) @@ -0,0 +1,92 @@ +<%@ include file="/common/taglibs.jsp"%> + + + + + + + +
+

+ + +

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ +
+ ${status.index + 1} + + ${condition.displayName} + + + " + onclick="upCondition(${status.index},'${sessionMapID}')"> + + "> + + + + + + "> + + + " + onclick="downCondition(${status.index},'${sessionMapID}')"> + + + " + onclick="editCondition(${status.index},'${sessionMapID}')" /> + + " + onclick="deleteCondition(${status.index},'${sessionMapID}')" /> +
+
+ +<%-- This script will works when a new resoruce Condition submit in order to refresh "TaskList List" panel. --%> + Index: lams_tool_survey/web/pages/authoring/conditions.jsp =================================================================== diff -u --- lams_tool_survey/web/pages/authoring/conditions.jsp (revision 0) +++ lams_tool_survey/web/pages/authoring/conditions.jsp (revision 7b79396263b36a933d66390fb9ab12821956d59d) @@ -0,0 +1,110 @@ +<%@ include file="/common/taglibs.jsp"%> + + + + + +
+ + <%@ include file="/pages/authoring/conditionList.jsp"%> +
+ +

+ ');" class="button-add-item"> + +

+ + +

+ +