Index: lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dao/SurveyDAO.java =================================================================== diff -u -rf0c3f41d54ef4f390ef3f93f28c0679c46b6730c -r625dccc46218d5cf4648d73a139af38f21c222ce --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dao/SurveyDAO.java (.../SurveyDAO.java) (revision f0c3f41d54ef4f390ef3f93f28c0679c46b6730c) +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dao/SurveyDAO.java (.../SurveyDAO.java) (revision 625dccc46218d5cf4648d73a139af38f21c222ce) @@ -24,13 +24,16 @@ package org.lamsfoundation.lams.tool.survey.dao; import org.lamsfoundation.lams.tool.survey.model.Survey; +import org.lamsfoundation.lams.tool.survey.model.SurveyCondition; -public interface SurveyDAO extends DAO { +public interface SurveyDAO extends DAO { - Survey getByContentId(Long contentId); + Survey getByContentId(Long contentId); - Survey getByUid(Long surveyUid); + Survey getByUid(Long surveyUid); - void delete(Survey survey); + void delete(Survey survey); + void deleteCondition(SurveyCondition condition); + } Index: lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dao/hibernate/SurveyDAOHibernate.java =================================================================== diff -u -rf0c3f41d54ef4f390ef3f93f28c0679c46b6730c -r625dccc46218d5cf4648d73a139af38f21c222ce --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dao/hibernate/SurveyDAOHibernate.java (.../SurveyDAOHibernate.java) (revision f0c3f41d54ef4f390ef3f93f28c0679c46b6730c) +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dao/hibernate/SurveyDAOHibernate.java (.../SurveyDAOHibernate.java) (revision 625dccc46218d5cf4648d73a139af38f21c222ce) @@ -27,30 +27,38 @@ import org.lamsfoundation.lams.tool.survey.dao.SurveyDAO; import org.lamsfoundation.lams.tool.survey.model.Survey; +import org.lamsfoundation.lams.tool.survey.model.SurveyCondition; /** * * @author Steve.Ni * * @version $Revision$ */ -public class SurveyDAOHibernate extends BaseDAOHibernate implements SurveyDAO{ - private static final String GET_RESOURCE_BY_CONTENTID = "from "+Survey.class.getName()+" as r where r.contentId=?"; - - public Survey getByContentId(Long contentId) { - List list = getHibernateTemplate().find(GET_RESOURCE_BY_CONTENTID,contentId); - if(list.size() > 0) - return (Survey) list.get(0); - else - return null; - } +public class SurveyDAOHibernate extends BaseDAOHibernate implements SurveyDAO { + private static final String GET_RESOURCE_BY_CONTENTID = "from " + Survey.class.getName() + + " as r where r.contentId=?"; - public Survey getByUid(Long surveyUid) { - return (Survey) getObject(Survey.class,surveyUid); + public Survey getByContentId(Long contentId) { + List list = getHibernateTemplate().find(SurveyDAOHibernate.GET_RESOURCE_BY_CONTENTID, contentId); + if (list.size() > 0) { + return (Survey) list.get(0); + } else { + return null; } + } - public void delete(Survey survey) { - this.getHibernateTemplate().delete(survey); - } + public Survey getByUid(Long surveyUid) { + return (Survey) getObject(Survey.class, surveyUid); + } + public void delete(Survey survey) { + this.getHibernateTemplate().delete(survey); + } + + public void deleteCondition(SurveyCondition condition) { + if (condition != null && condition.getConditionId() != null) { + this.getHibernateTemplate().delete(condition); + } + } } Index: lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/ISurveyService.java =================================================================== diff -u -r7b79396263b36a933d66390fb9ab12821956d59d -r625dccc46218d5cf4648d73a139af38f21c222ce --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/ISurveyService.java (.../ISurveyService.java) (revision 7b79396263b36a933d66390fb9ab12821956d59d) +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/ISurveyService.java (.../ISurveyService.java) (revision 625dccc46218d5cf4648d73a139af38f21c222ce) @@ -320,4 +320,6 @@ * @return unique SurveyCondition name */ public String createConditionName(Collection existingConditions); + + public void deleteCondition(SurveyCondition condition); } Index: lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/SurveyOutputFactory.java =================================================================== diff -u -r7b79396263b36a933d66390fb9ab12821956d59d -r625dccc46218d5cf4648d73a139af38f21c222ce --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/SurveyOutputFactory.java (.../SurveyOutputFactory.java) (revision 7b79396263b36a933d66390fb9ab12821956d59d) +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/SurveyOutputFactory.java (.../SurveyOutputFactory.java) (revision 625dccc46218d5cf4648d73a139af38f21c222ce) @@ -97,8 +97,8 @@ ToolOutput allAnswersOutput = null; if (names == null) { // output will be set for all the existing conditions - Survey qaContent = surveyService.getSurveyBySessionId(toolSessionId); - Set conditions = qaContent.getConditions(); + Survey survey = surveyService.getSurveyBySessionId(toolSessionId); + Set conditions = survey.getConditions(); for (SurveyCondition condition : conditions) { String name = condition.getName(); if (isTextSearchConditionName(name) && allAnswersOutput != null) { @@ -107,7 +107,7 @@ ToolOutput output = getToolOutput(name, surveyService, toolSessionId, learnerId); if (output != null) { outputs.put(name, output); - if (isTextSearchConditionName(SurveyConstants.TEXT_SEARCH_DEFINITION_NAME)) { + if (isTextSearchConditionName(name)) { allAnswersOutput = output; } } @@ -121,7 +121,7 @@ ToolOutput output = getToolOutput(name, surveyService, toolSessionId, learnerId); if (output != null) { outputs.put(name, output); - if (isTextSearchConditionName(SurveyConstants.TEXT_SEARCH_DEFINITION_NAME)) { + if (isTextSearchConditionName(name)) { allAnswersOutput = output; } } Index: lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/SurveyServiceImpl.java =================================================================== diff -u -r7b79396263b36a933d66390fb9ab12821956d59d -r625dccc46218d5cf4648d73a139af38f21c222ce --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/SurveyServiceImpl.java (.../SurveyServiceImpl.java) (revision 7b79396263b36a933d66390fb9ab12821956d59d) +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/SurveyServiceImpl.java (.../SurveyServiceImpl.java) (revision 625dccc46218d5cf4648d73a139af38f21c222ce) @@ -1159,4 +1159,8 @@ } while (uniqueNumber == null); return getSurveyOutputFactory().buildConditionName(uniqueNumber); } + + public void deleteCondition(SurveyCondition condition) { + surveyDao.deleteCondition(condition); + } } \ No newline at end of file Index: lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/web/action/AuthoringAction.java =================================================================== diff -u -r7b79396263b36a933d66390fb9ab12821956d59d -r625dccc46218d5cf4648d73a139af38f21c222ce --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/web/action/AuthoringAction.java (.../AuthoringAction.java) (revision 7b79396263b36a933d66390fb9ab12821956d59d) +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/web/action/AuthoringAction.java (.../AuthoringAction.java) (revision 625dccc46218d5cf4648d73a139af38f21c222ce) @@ -648,6 +648,14 @@ // finally persist surveyPO again service.saveOrUpdateSurvey(surveyPO); + List delConditionList = getDeletedSurveyConditionList(sessionMap); + iter = delConditionList.iterator(); + while (iter.hasNext()) { + SurveyCondition condition = (SurveyCondition) iter.next(); + iter.remove(); + service.deleteCondition(condition); + } + // initialize attachmentList again attachmentList = getAttachmentList(sessionMap); attachmentList.addAll(survey.getAttachments()); @@ -1165,4 +1173,13 @@ return mapping.findForward(SurveyConstants.SUCCESS); } + /** + * 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); + } } Index: lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/web/action/AuthoringConditionAction.java =================================================================== diff -u -r7b79396263b36a933d66390fb9ab12821956d59d -r625dccc46218d5cf4648d73a139af38f21c222ce --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/web/action/AuthoringConditionAction.java (.../AuthoringConditionAction.java) (revision 7b79396263b36a933d66390fb9ab12821956d59d) +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/web/action/AuthoringConditionAction.java (.../AuthoringConditionAction.java) (revision 625dccc46218d5cf4648d73a139af38f21c222ce) @@ -203,6 +203,11 @@ SortedSet conditionSet = getSurveyConditionSet(sessionMap); List conditionList = new ArrayList(conditionSet); SurveyCondition condition = conditionList.remove(orderId); + for (SurveyCondition otherCondition : conditionSet) { + if (otherCondition.getOrderId() > orderId) { + otherCondition.setOrderId(otherCondition.getOrderId() - 1); + } + } conditionSet.clear(); conditionSet.addAll(conditionList); // add to delList @@ -285,7 +290,7 @@ } /** - * List save current taskList items. + * List containing survey conditions. * * @param request * @return @@ -349,13 +354,6 @@ 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); } /**