Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/IQaContentDAO.java =================================================================== diff -u -r0db83894504dc7652d3670a6ce496605b961faa1 -r97aceb8f087c5d2613e004dc2be171ac8acae574 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/IQaContentDAO.java (.../IQaContentDAO.java) (revision 0db83894504dc7652d3670a6ce496605b961faa1) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/IQaContentDAO.java (.../IQaContentDAO.java) (revision 97aceb8f087c5d2613e004dc2be171ac8acae574) @@ -23,38 +23,38 @@ /* $$Id$$ */ package org.lamsfoundation.lams.tool.qa.dao; +import org.lamsfoundation.lams.tool.qa.QaCondition; import org.lamsfoundation.lams.tool.qa.QaContent; - /** * * @author Ozgur Demirtas - * + * */ -public interface IQaContentDAO -{ - public QaContent getQaById(long qaId); - - public QaContent loadQaById(long qaId); - - public QaContent getQaContentByUID(Long uid); - - public QaContent getQaBySession(Long sessionId); - - public void saveOrUpdateQa(QaContent qa); - +public interface IQaContentDAO { + public QaContent getQaById(long qaId); + + public QaContent loadQaById(long qaId); + + public QaContent getQaContentByUID(Long uid); + + public QaContent getQaBySession(Long sessionId); + + public void saveOrUpdateQa(QaContent qa); + public void saveQa(QaContent qa); - + public void updateQa(QaContent qa); - + public void removeQa(Long qaContentId); - + public void deleteQa(QaContent qa); - + public void removeQaById(Long qaId); - + public void removeAllQaSession(QaContent content); - + public int countUserResponsed(QaContent content); - -} + + public void deleteCondition(QaCondition condition); +} \ No newline at end of file Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/hibernate/QaContentDAO.java =================================================================== diff -u -r0db83894504dc7652d3670a6ce496605b961faa1 -r97aceb8f087c5d2613e004dc2be171ac8acae574 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/hibernate/QaContentDAO.java (.../QaContentDAO.java) (revision 0db83894504dc7652d3670a6ce496605b961faa1) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/hibernate/QaContentDAO.java (.../QaContentDAO.java) (revision 97aceb8f087c5d2613e004dc2be171ac8acae574) @@ -29,154 +29,126 @@ import org.hibernate.FlushMode; import org.hibernate.HibernateException; import org.hibernate.Session; +import org.lamsfoundation.lams.tool.qa.QaCondition; import org.lamsfoundation.lams.tool.qa.QaContent; import org.lamsfoundation.lams.tool.qa.dao.IQaContentDAO; import org.springframework.orm.hibernate3.HibernateCallback; import org.springframework.orm.hibernate3.HibernateTemplate; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; - /** * @author Ozgur Demirtas - * - * TODO To change the template for this generated type comment go to - * Window - Preferences - Java - Code Style - Code Templates + * + * TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code + * Templates */ public class QaContentDAO extends HibernateDaoSupport implements IQaContentDAO { - static Logger logger = Logger.getLogger(QaContentDAO.class.getName()); - - private static final String LOAD_QA_BY_SESSION = "select qa from QaContent qa left join fetch " - + "qa.qaSessions session where session.qaSessionId=:sessionId"; + static Logger logger = Logger.getLogger(QaContentDAO.class.getName()); - - private static final String COUNT_USER_RESPONSED = "select distinct u.userId from QaQueUsr u left join fetch" - + " u.qaQueContent as ques where ques.qaContent = :qa group by u.userId"; - - - public QaContentDAO() {} + private static final String LOAD_QA_BY_SESSION = "select qa from QaContent qa left join fetch " + + "qa.qaSessions session where session.qaSessionId=:sessionId"; - - public QaContent getQaById(long qaId) - { - return loadQaById(qaId); - } - + private static final String COUNT_USER_RESPONSED = "select distinct u.userId from QaQueUsr u left join fetch" + + " u.qaQueContent as ques where ques.qaContent = :qa group by u.userId"; - public QaContent loadQaById(long qaId) - { - String query = "from QaContent as qa where qa.qaContentId = ?"; - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(query) - .setLong(0,qaId) - .list(); - - if(list != null && list.size() > 0){ - QaContent qa = (QaContent) list.get(0); - return qa; - } - return null; - } + public QaContentDAO() { + } + public QaContent getQaById(long qaId) { + return loadQaById(qaId); + } - - public QaContent getQaContentByUID(Long uid) - { - return (QaContent) this.getHibernateTemplate().get(QaContent.class, uid); - } - - - public void updateQa(QaContent qa) - { - this.getSession().setFlushMode(FlushMode.AUTO); - logger.debug("before updateQa: " + qa); - this.getHibernateTemplate().update(qa); - } - - public QaContent getQaBySession(final Long sessionId) - { - return (QaContent) getHibernateTemplate().execute(new HibernateCallback() - { + public QaContent loadQaById(long qaId) { + String query = "from QaContent as qa where qa.qaContentId = ?"; + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(query).setLong(0, qaId).list(); - public Object doInHibernate(Session session) throws HibernateException - { - return session.createQuery(LOAD_QA_BY_SESSION) - .setLong("sessionId", - sessionId.longValue()) - .uniqueResult(); - } - }); - } + if (list != null && list.size() > 0) { + QaContent qa = (QaContent) list.get(0); + return qa; + } + return null; + } - - public void saveQa(QaContent qa) - { - this.getSession().setFlushMode(FlushMode.AUTO); - this.getHibernateTemplate().save(qa); - } - - public void saveOrUpdateQa(QaContent qa) - { - this.getSession().setFlushMode(FlushMode.AUTO); - logger.debug("before saveOrUpdateQa: " + qa); - this.getHibernateTemplate().saveOrUpdate(qa); - } + public QaContent getQaContentByUID(Long uid) { + return (QaContent) this.getHibernateTemplate().get(QaContent.class, uid); + } - - public void createQa(QaContent qa) - { - this.getSession().setFlushMode(FlushMode.AUTO); - logger.debug("before createQa: " + qa); - this.getHibernateTemplate().save(qa); - } - - public void UpdateQa(QaContent qa) - { - this.getSession().setFlushMode(FlushMode.AUTO); - this.getHibernateTemplate().update(qa); - } + public void updateQa(QaContent qa) { + this.getSession().setFlushMode(FlushMode.AUTO); + QaContentDAO.logger.debug("before updateQa: " + qa); + this.getHibernateTemplate().update(qa); + } - public int countUserResponsed(QaContent qa) - { - return (getHibernateTemplate().findByNamedParam(COUNT_USER_RESPONSED, - "qa", - qa)).size(); - } - - - public void removeAllQaSession(QaContent qaContent){ - this.getHibernateTemplate().deleteAll(qaContent.getQaSessions()); - } - - public void removeQa(Long qaContentId) - { - if ( qaContentId != null ) { - String query = "from qa in class org.lamsfoundation.lams.tool.qa.QaContent" - + " where qa.qaContentId = ?"; - Object obj = getSession().createQuery(query) - .setLong(0,qaContentId.longValue()) - .uniqueResult(); - this.getSession().setFlushMode(FlushMode.AUTO); - getHibernateTemplate().delete(obj); - } - } - - public void deleteQa(QaContent qaContent) - { - this.getSession().setFlushMode(FlushMode.AUTO); - this.getHibernateTemplate().delete(qaContent); - } + public QaContent getQaBySession(final Long sessionId) { + return (QaContent) getHibernateTemplate().execute(new HibernateCallback() { - public void removeQaById(Long qaId) - { - this.getSession().setFlushMode(FlushMode.AUTO); - removeQa(qaId); + public Object doInHibernate(Session session) throws HibernateException { + return session.createQuery(QaContentDAO.LOAD_QA_BY_SESSION).setLong("sessionId", sessionId.longValue()) + .uniqueResult(); } + }); + } - - public void flush() - { - this.getHibernateTemplate().flush(); - } - -} \ No newline at end of file + public void saveQa(QaContent qa) { + this.getSession().setFlushMode(FlushMode.AUTO); + this.getHibernateTemplate().save(qa); + } + + public void saveOrUpdateQa(QaContent qa) { + this.getSession().setFlushMode(FlushMode.AUTO); + QaContentDAO.logger.debug("before saveOrUpdateQa: " + qa); + this.getHibernateTemplate().saveOrUpdate(qa); + } + + public void createQa(QaContent qa) { + this.getSession().setFlushMode(FlushMode.AUTO); + QaContentDAO.logger.debug("before createQa: " + qa); + this.getHibernateTemplate().save(qa); + } + + public void UpdateQa(QaContent qa) { + this.getSession().setFlushMode(FlushMode.AUTO); + this.getHibernateTemplate().update(qa); + } + + public int countUserResponsed(QaContent qa) { + return getHibernateTemplate().findByNamedParam(QaContentDAO.COUNT_USER_RESPONSED, "qa", qa).size(); + } + + public void removeAllQaSession(QaContent qaContent) { + this.getHibernateTemplate().deleteAll(qaContent.getQaSessions()); + } + + public void removeQa(Long qaContentId) { + if (qaContentId != null) { + String query = "from qa in class org.lamsfoundation.lams.tool.qa.QaContent" + " where qa.qaContentId = ?"; + Object obj = getSession().createQuery(query).setLong(0, qaContentId.longValue()).uniqueResult(); + this.getSession().setFlushMode(FlushMode.AUTO); + getHibernateTemplate().delete(obj); + } + } + + public void deleteQa(QaContent qaContent) { + this.getSession().setFlushMode(FlushMode.AUTO); + this.getHibernateTemplate().delete(qaContent); + } + + public void removeQaById(Long qaId) { + this.getSession().setFlushMode(FlushMode.AUTO); + removeQa(qaId); + } + + public void flush() { + this.getHibernateTemplate().flush(); + } + + public void deleteCondition(QaCondition condition) { + if (condition != null && condition.getConditionId() != null) { + this.getSession().setFlushMode(FlushMode.AUTO); + this.getHibernateTemplate().delete(condition); + } + } + +} \ No newline at end of file Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/IQaService.java =================================================================== diff -u -r0af4ed13b963a588f3499b080801863d57f8ad95 -r97aceb8f087c5d2613e004dc2be171ac8acae574 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/IQaService.java (.../IQaService.java) (revision 0af4ed13b963a588f3499b080801863d57f8ad95) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/IQaService.java (.../IQaService.java) (revision 97aceb8f087c5d2613e004dc2be171ac8acae574) @@ -292,4 +292,6 @@ * @return unique QaCondition name */ public String createConditionName(Collection existingConditions); + + public void deleteCondition(QaCondition condition); } Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaOutputFactory.java =================================================================== diff -u -rfa106090a403c6816960351dd1937a1264d78ded -r97aceb8f087c5d2613e004dc2be171ac8acae574 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaOutputFactory.java (.../QaOutputFactory.java) (revision fa106090a403c6816960351dd1937a1264d78ded) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaOutputFactory.java (.../QaOutputFactory.java) (revision 97aceb8f087c5d2613e004dc2be171ac8acae574) @@ -107,7 +107,7 @@ ToolOutput output = getToolOutput(name, qaService, toolSessionId, learnerId); if (output != null) { outputs.put(name, output); - if (isTextSearchConditionName(QaAppConstants.TEXT_SEARCH_DEFINITION_NAME)) { + if (isTextSearchConditionName(name)) { allAnswersOutput = output; } } @@ -121,7 +121,7 @@ ToolOutput output = getToolOutput(name, qaService, toolSessionId, learnerId); if (output != null) { outputs.put(name, output); - if (isTextSearchConditionName(QaAppConstants.TEXT_SEARCH_DEFINITION_NAME)) { + if (isTextSearchConditionName(name)) { allAnswersOutput = output; } } Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaServicePOJO.java =================================================================== diff -u -r0af4ed13b963a588f3499b080801863d57f8ad95 -r97aceb8f087c5d2613e004dc2be171ac8acae574 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaServicePOJO.java (.../QaServicePOJO.java) (revision 0af4ed13b963a588f3499b080801863d57f8ad95) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaServicePOJO.java (.../QaServicePOJO.java) (revision 97aceb8f087c5d2613e004dc2be171ac8acae574) @@ -1845,4 +1845,10 @@ } while (uniqueNumber == null); return getQaOutputFactory().buildConditionName(uniqueNumber); } + + public void deleteCondition(QaCondition condition) { + if (condition != null && condition.getConditionId() != null) { + qaDAO.deleteCondition(condition); + } + } } \ No newline at end of file Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaAction.java =================================================================== diff -u -r0af4ed13b963a588f3499b080801863d57f8ad95 -r97aceb8f087c5d2613e004dc2be171ac8acae574 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaAction.java (.../QaAction.java) (revision 0af4ed13b963a588f3499b080801863d57f8ad95) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaAction.java (.../QaAction.java) (revision 97aceb8f087c5d2613e004dc2be171ac8acae574) @@ -320,6 +320,7 @@ } QaContent qaContent = qaContentTest; + if (errors.isEmpty()) { QaAction.logger.debug("errors is empty: " + errors); /* @@ -392,6 +393,14 @@ } } + List delConditionList = getDeletedQaConditionList(sessionMap); + Iterator iter = delConditionList.iterator(); + while (iter.hasNext()) { + QaCondition condition = (QaCondition) iter.next(); + iter.remove(); + qaService.deleteCondition(condition); + } + qaGeneralAuthoringDTO.setSbmtSuccess(new Integer(1).toString()); qaAuthoringForm.resetUserAction(); @@ -1093,6 +1102,7 @@ conditionIter.remove(); } } + QaAction.logger.debug("listQuestionContentDTO after remove:" + listQuestionContentDTO); listQuestionContentDTO = AuthoringUtil.reorderListQuestionContentDTO(listQuestionContentDTO, questionIndex); @@ -2129,4 +2139,18 @@ return true; } + /** + * Get the deleted condition list, which could be persisted or non-persisted items. + * + * @param request + * @return + */ + private List getDeletedQaConditionList(SessionMap sessionMap) { + List list = (List) sessionMap.get(QaAppConstants.ATTR_DELETED_CONDITION_LIST); + if (list == null) { + list = new ArrayList(); + sessionMap.put(QaAppConstants.ATTR_DELETED_CONDITION_LIST, list); + } + return list; + } } Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaAuthoringConditionAction.java =================================================================== diff -u -r33f9171c071c179459972380a9b732f1aeec87bf -r97aceb8f087c5d2613e004dc2be171ac8acae574 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaAuthoringConditionAction.java (.../QaAuthoringConditionAction.java) (revision 33f9171c071c179459972380a9b732f1aeec87bf) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaAuthoringConditionAction.java (.../QaAuthoringConditionAction.java) (revision 97aceb8f087c5d2613e004dc2be171ac8acae574) @@ -202,6 +202,11 @@ SortedSet conditionSet = getQaConditionSet(sessionMap); List conditionList = new ArrayList(conditionSet); QaCondition condition = conditionList.remove(orderId); + for (QaCondition otherCondition : conditionSet) { + if (otherCondition.getOrderId() > orderId) { + otherCondition.setOrderId(otherCondition.getOrderId() - 1); + } + } conditionSet.clear(); conditionSet.addAll(conditionList); // add to delList @@ -354,13 +359,6 @@ if (orderId >= 0) { form.setOrderId(orderId + 1); } - - Integer[] selectedItems = new Integer[condition.temporaryQuestionDTOSet.size()]; - int i = 0; - for (QaQuestionContentDTO question : condition.temporaryQuestionDTOSet) { - selectedItems[i++] = new Integer(question.getDisplayOrder()); - } - form.setSelectedItems(selectedItems); } /**