Index: lams_tool_laqa/conf/hibernate/mappings/org/lamsfoundation/lams/tool/qa/QaContent.hbm.xml =================================================================== diff -u -rc5457cc74f3986b393bc2947604b17168ba54dfb -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/conf/hibernate/mappings/org/lamsfoundation/lams/tool/qa/QaContent.hbm.xml (.../QaContent.hbm.xml) (revision c5457cc74f3986b393bc2947604b17168ba54dfb) +++ lams_tool_laqa/conf/hibernate/mappings/org/lamsfoundation/lams/tool/qa/QaContent.hbm.xml (.../QaContent.hbm.xml) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -135,15 +135,6 @@ column="created_by" length="20" /> - - - conditions, - boolean allowRichEditor, boolean useSelectLeaderToolOuput) { + boolean allowRateAnswers, boolean notifyTeachersOnResponseSubmit, boolean lockWhenFinished, + boolean showOtherAnswers, boolean reflect, String reflectionSubject, Date creationDate, Date updateDate, + Set qaQueContents, Set qaSessions, Set conditions, boolean allowRichEditor, + boolean useSelectLeaderToolOuput) { this.qaContentId = qaContentId; this.content = content; this.title = title; @@ -144,7 +134,6 @@ this.usernameVisible = usernameVisible; this.allowRateAnswers = allowRateAnswers; this.notifyTeachersOnResponseSubmit = notifyTeachersOnResponseSubmit; - this.synchInMonitor = synchInMonitor; this.lockWhenFinished = lockWhenFinished; this.showOtherAnswers = showOtherAnswers; this.reflect = reflect; @@ -168,15 +157,13 @@ * the new qa content id. * @return the new qa content object. */ - public static QaContent newInstance(QaContent qa, Long newContentId) throws ItemNotFoundException, - RepositoryCheckedException { + public static QaContent newInstance(QaContent qa, Long newContentId) { QaContent newContent = new QaContent(newContentId, qa.getContent(), qa.getTitle(), qa.getInstructions(), qa.getReportTitle(), qa.getMonitoringReportTitle(), qa.getCreatedBy(), qa.isQuestionsSequenced(), qa.isUsernameVisible(), qa.isAllowRateAnswers(), qa.isNotifyTeachersOnResponseSubmit(), - qa.isSynchInMonitor(), qa.isLockWhenFinished(), qa.isShowOtherAnswers(), qa.isReflect(), - qa.getReflectionSubject(), qa.getCreationDate(), qa.getUpdateDate(), new TreeSet(), new TreeSet(), - new TreeSet(new TextSearchConditionComparator()), qa.isAllowRichEditor(), - qa.isUseSelectLeaderToolOuput()); + qa.isLockWhenFinished(), qa.isShowOtherAnswers(), qa.isReflect(), qa.getReflectionSubject(), + qa.getCreationDate(), qa.getUpdateDate(), new TreeSet(), new TreeSet(), new TreeSet( + new TextSearchConditionComparator()), qa.isAllowRichEditor(), qa.isUseSelectLeaderToolOuput()); newContent.setQaQueContents(qa.deepCopyQaQueContent(newContent)); @@ -268,7 +255,7 @@ .append("username_visible:", isUsernameVisible()) .append("allow to rate answers:", isAllowRateAnswers()).append("defineLater", isDefineLater()) .append("report_title: ", getReportTitle()).append("reflection subject: ", getReflectionSubject()) - .append("synch_in_monitor: ", isSynchInMonitor()).toString(); + .toString(); } @Override @@ -346,21 +333,6 @@ } /** - * @return Returns the synchInMonitor. - */ - public boolean isSynchInMonitor() { - return synchInMonitor; - } - - /** - * @param synchInMonitor - * The synchInMonitor to set. - */ - public void setSynchInMonitor(boolean synchInMonitor) { - this.synchInMonitor = synchInMonitor; - } - - /** * @return Returns the updateDate. */ public Date getUpdateDate() { @@ -419,7 +391,7 @@ public void setAllowRateAnswers(boolean allowRateAnswers) { this.allowRateAnswers = allowRateAnswers; } - + /** * @return */ @@ -558,13 +530,13 @@ public void setAllowRichEditor(boolean allowRichEditor) { this.allowRichEditor = allowRichEditor; } - + public boolean isUseSelectLeaderToolOuput() { - return useSelectLeaderToolOuput; + return useSelectLeaderToolOuput; } public void setUseSelectLeaderToolOuput(boolean useSelectLeaderToolOuput) { - this.useSelectLeaderToolOuput = useSelectLeaderToolOuput; + this.useSelectLeaderToolOuput = useSelectLeaderToolOuput; } /** Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/QaQueContent.java =================================================================== diff -u -r501ddb69e1c739b90388262f41b4927356cb0449 -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/QaQueContent.java (.../QaQueContent.java) (revision 501ddb69e1c739b90388262f41b4927356cb0449) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/QaQueContent.java (.../QaQueContent.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -24,8 +24,6 @@ package org.lamsfoundation.lams.tool.qa; import java.io.Serializable; -import java.util.Set; -import java.util.TreeSet; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; @@ -60,26 +58,22 @@ /** nullable persistent field */ private QaContent qaContent; - /** persistent field */ - private Set qaQueUsers; - /** default constructor */ public QaQueContent() { } public QaQueContent(String question, int displayOrder, String feedback, boolean required, - QaContent qaContent, Set qaQueUsers) { + QaContent qaContent) { this.question = question; this.displayOrder = displayOrder; this.feedback = feedback; this.required = required; this.qaContent = qaContent; - this.qaQueUsers = qaQueUsers; } public static QaQueContent newInstance(QaQueContent queContent, QaContent newQaContent) { QaQueContent newQueContent = new QaQueContent(queContent.getQuestion(), queContent.getDisplayOrder(), - queContent.getFeedback(), queContent.isRequired(), newQaContent, new TreeSet()); + queContent.getFeedback(), queContent.isRequired(), newQaContent); return newQueContent; } @@ -150,24 +144,6 @@ } /** - * @return Returns the qaQueUsers. - */ - public Set getQaQueUsers() { - if (qaQueUsers == null) { - setQaQueUsers(new TreeSet()); - } - return qaQueUsers; - } - - /** - * @param qaQueUsers - * The qaQueUsers to set. - */ - public void setQaQueUsers(Set qaQueUsers) { - this.qaQueUsers = qaQueUsers; - } - - /** * @return Returns the question. */ public String getQuestion() { Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/IQaContentDAO.java =================================================================== diff -u -r567af22fafd6a56534cc071f3650eda4495d05ef -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/IQaContentDAO.java (.../IQaContentDAO.java) (revision 567af22fafd6a56534cc071f3650eda4495d05ef) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/IQaContentDAO.java (.../IQaContentDAO.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -27,32 +27,30 @@ import org.lamsfoundation.lams.tool.qa.QaContent; /** - * * @author Ozgur Demirtas - * */ public interface IQaContentDAO { - public QaContent getQaByContentId(long qaId); + QaContent getQaByContentId(long qaId); - public QaContent getQaBySession(Long sessionId); + void saveOrUpdateQa(QaContent qa); - public void saveOrUpdateQa(QaContent qa); + void saveQa(QaContent qa); - public void saveQa(QaContent qa); + void updateQa(QaContent qa); - public void updateQa(QaContent qa); + void removeQa(Long qaContentId); - public void removeQa(Long qaContentId); + void deleteQa(QaContent qa); - public void deleteQa(QaContent qa); + void removeQaById(Long qaId); - public void removeQaById(Long qaId); + void removeAllQaSession(QaContent content); - public void removeAllQaSession(QaContent content); + void deleteCondition(QaCondition condition); - public void deleteCondition(QaCondition condition); - - public void removeQuestionsFromCache(QaContent qaContent); + void removeQuestionsFromCache(QaContent qaContent); - public void delete(Object object); -} \ No newline at end of file + void removeQaContentFromCache(QaContent qaContent); + + void delete(Object object); +} Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/IQaQueUsrDAO.java =================================================================== diff -u -r91f0740e75daa643981b757e49d1ed2ed7f0a528 -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/IQaQueUsrDAO.java (.../IQaQueUsrDAO.java) (revision 91f0740e75daa643981b757e49d1ed2ed7f0a528) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/IQaQueUsrDAO.java (.../IQaQueUsrDAO.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -30,27 +30,21 @@ import org.lamsfoundation.lams.tool.qa.QaSession; /** - * * @author Ozgur Demirtas - * */ public interface IQaQueUsrDAO { - public QaQueUsr getQaQueUsrById(long qaQueUsrId); + QaQueUsr getQaUserBySession(final Long queUsrId, final Long qaSessionId); - public QaQueUsr loadQaQueUsrById(long qaQueUsrId); + void createUsr(QaQueUsr usr); - public QaQueUsr getQaUserBySession(final Long queUsrId, final Long qaSessionId); + void updateUsr(QaQueUsr usr); - public void createUsr(QaQueUsr usr); + void deleteQaQueUsr(QaQueUsr qaQueUsr); - public void updateUsr(QaQueUsr usr); + int countSessionUser(QaSession qaSession); - public void deleteQaQueUsr(QaQueUsr qaQueUsr); + int getTotalNumberOfUsers(QaContent qa); - public int countSessionUser(QaSession qaSession); - - public int getTotalNumberOfUsers(QaContent qa); - - public List getUserBySessionOnly(final QaSession qaSession); + List getUserBySessionOnly(final QaSession qaSession); } Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/IQaQuestionDAO.java =================================================================== diff -u -r629b2631320321b57015e15be850e7c6b747225f -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/IQaQuestionDAO.java (.../IQaQuestionDAO.java) (revision 629b2631320321b57015e15be850e7c6b747225f) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/IQaQuestionDAO.java (.../IQaQuestionDAO.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -28,25 +28,23 @@ import org.lamsfoundation.lams.tool.qa.QaQueContent; /** - * * @author Ozgur Demirtas - * */ public interface IQaQuestionDAO { - public void createQueContent(QaQueContent queContent); + void createQueContent(QaQueContent queContent); - public void saveOrUpdateQaQueContent(QaQueContent qaQuestion); + void saveOrUpdateQaQueContent(QaQueContent qaQuestion); - public void removeQueContent(long qaQueContentId); + void removeQueContent(long qaQueContentId); - public void removeQaQueContent(QaQueContent qaQuestion); + void removeQaQueContent(QaQueContent qaQuestion); - public List getAllQuestionEntries(final long qaContentId); + List getAllQuestionEntries(final long qaContentId); - public QaQueContent getQuestionContentByQuestionText(final String question, Long qaContentId); + QaQueContent getQuestionByDisplayOrder(Long displayOrder, Long qaContentId); + + QaQueContent getQuestionByUid(Long questionUid); - public QaQueContent getQuestionByDisplayOrder(Long displayOrder, Long qaContentId); - - public List getAllQuestionEntriesSorted(final long qaContentId); + List getAllQuestionEntriesSorted(final long qaContentId); } Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/IQaSessionDAO.java =================================================================== diff -u -r91f0740e75daa643981b757e49d1ed2ed7f0a528 -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/IQaSessionDAO.java (.../IQaSessionDAO.java) (revision 91f0740e75daa643981b757e49d1ed2ed7f0a528) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/IQaSessionDAO.java (.../IQaSessionDAO.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -29,23 +29,19 @@ import org.lamsfoundation.lams.tool.qa.QaSession; /** - * * * @author Ozgur Demirtas - * */ public interface IQaSessionDAO { - public int countSessionComplete(QaContent qa); + int countSessionComplete(QaContent qa); - public QaSession getQaSessionById(long qaSessionId); + QaSession getQaSessionById(long qaSessionId); - public void CreateQaSession(QaSession session); + void createSession(QaSession session); - public void UpdateQaSession(QaSession session); + void UpdateQaSession(QaSession session); - public void deleteQaSession(QaSession session); + void deleteQaSession(QaSession session); - public List getSessionsFromContent(QaContent qaContent); - - public List getSessionNamesFromContent(QaContent qaContent); + List getSessionsFromContent(QaContent qaContent); } Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/hibernate/QaContentDAO.java =================================================================== diff -u -r567af22fafd6a56534cc071f3650eda4495d05ef -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/hibernate/QaContentDAO.java (.../QaContentDAO.java) (revision 567af22fafd6a56534cc071f3650eda4495d05ef) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/hibernate/QaContentDAO.java (.../QaContentDAO.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -27,13 +27,10 @@ import java.util.Set; 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.QaQueContent; 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; @@ -44,9 +41,6 @@ public class QaContentDAO extends HibernateDaoSupport implements IQaContentDAO { - 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 getQaByContentId(long qaId) { String query = "from QaContent as qa where qa.qaContentId = ?"; HibernateTemplate templ = this.getHibernateTemplate(); @@ -64,16 +58,6 @@ this.getHibernateTemplate().update(qa); } - public QaContent getQaBySession(final Long sessionId) { - return (QaContent) getHibernateTemplate().execute(new HibernateCallback() { - - public Object doInHibernate(Session session) throws HibernateException { - return session.createQuery(QaContentDAO.LOAD_QA_BY_SESSION).setLong("sessionId", sessionId.longValue()) - .uniqueResult(); - } - }); - } - public void saveQa(QaContent qa) { this.getSession().setFlushMode(FlushMode.AUTO); this.getHibernateTemplate().save(qa); @@ -127,14 +111,20 @@ this.getHibernateTemplate().delete(condition); } } + + public void removeQaContentFromCache(QaContent qaContent) { + if (qaContent != null) { + getHibernateTemplate().evict(qaContent); + } + } + public void removeQuestionsFromCache(QaContent qaContent) { if (qaContent != null) { for (QaQueContent question : (Set) qaContent.getQaQueContents()) { getHibernateTemplate().evict(question); } - getHibernateTemplate().evict(qaContent); } } Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/hibernate/QaQueUsrDAO.java =================================================================== diff -u -r501ddb69e1c739b90388262f41b4927356cb0449 -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/hibernate/QaQueUsrDAO.java (.../QaQueUsrDAO.java) (revision 501ddb69e1c739b90388262f41b4927356cb0449) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/hibernate/QaQueUsrDAO.java (.../QaQueUsrDAO.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -37,11 +37,9 @@ /** * @author Ozgur Demirtas - * */ - public class QaQueUsrDAO extends HibernateDaoSupport implements IQaQueUsrDAO { - static Logger logger = Logger.getLogger(QaQueUsrDAO.class.getName()); + private static Logger logger = Logger.getLogger(QaQueUsrDAO.class.getName()); private static final String COUNT_SESSION_USER = "select qaQueUsr.queUsrId from QaQueUsr qaQueUsr where qaQueUsr.qaSession.qaSessionId= :qaSession"; private static final String LOAD_USER_FOR_SESSION = "from qaQueUsr in class QaQueUsr where qaQueUsr.qaSession.qaSessionId= :qaSessionId"; @@ -53,19 +51,6 @@ return (getHibernateTemplate().findByNamedParam(COUNT_SESSION_USER, "qaSession", qaSession)).size(); } - public QaQueUsr getQaQueUsrById(long qaQueUsrId) { - String query = "from QaQueUsr user where user.queUsrId=?"; - - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(query).setLong(0, qaQueUsrId).list(); - - if (list != null && list.size() > 0) { - QaQueUsr qu = (QaQueUsr) list.get(0); - return qu; - } - return null; - } - public QaQueUsr getQaUserBySession(final Long queUsrId, final Long qaSessionId) { String strGetUser = "from qaQueUsr in class QaQueUsr where qaQueUsr.queUsrId=:queUsrId and qaQueUsr.qaSession.qaSessionId=:qaSessionId"; @@ -87,10 +72,6 @@ return list; } - public QaQueUsr loadQaQueUsrById(long qaQueUsrId) { - return getQaQueUsrById(qaQueUsrId); - } - public void createUsr(QaQueUsr usr) { this.getSession().setFlushMode(FlushMode.AUTO); this.getHibernateTemplate().save(usr); Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/hibernate/QaQuestionDAO.java =================================================================== diff -u -r629b2631320321b57015e15be850e7c6b747225f -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/hibernate/QaQuestionDAO.java (.../QaQuestionDAO.java) (revision 629b2631320321b57015e15be850e7c6b747225f) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/hibernate/QaQuestionDAO.java (.../QaQuestionDAO.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -29,7 +29,6 @@ import org.hibernate.FlushMode; import org.lamsfoundation.lams.tool.qa.QaQueContent; import org.lamsfoundation.lams.tool.qa.dao.IQaQuestionDAO; -import org.springframework.orm.hibernate3.HibernateTemplate; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; /** @@ -38,44 +37,40 @@ */ public class QaQuestionDAO extends HibernateDaoSupport implements IQaQuestionDAO { private static final String LOAD_QUESTION_BY_CONTENT_UID = "from qaQuestion in class QaQueContent where qaQuestion.qaContent.uid=:uid"; - private static final String LOAD_QUESTION_CONTENT_BY_QUESTION_TEXT = "from qaQuestion in class QaQueContent where qaQuestion.question=:question and qaQuestion.qaContent.uid=:uid"; - private static final String LOAD_QUESTION_CONTENT_BY_DISPLAY_ORDER = "from qaQuestion in class QaQueContent where qaQuestion.displayOrder=:displayOrder and qaQuestion.qaContent.uid=:uid"; - private static final String SORT_QUESTION_CONTENT_BY_DISPLAY_ORDER = "from qaQuestion in class QaQueContent where qaQuestion.qaContent.uid=:uid order by qaQuestion.displayOrder"; + private static final String LOAD_QUESTION_BY_DISPLAY_ORDER = "from qaQuestion in class QaQueContent where qaQuestion.displayOrder=:displayOrder and qaQuestion.qaContent.uid=:uid"; + private static final String LOAD_QUESTION_BY_QUESTION_UID = "from qaQuestion in class QaQueContent where qaQuestion.uid=:uid"; + private static final String SORT_QUESTION_BY_DISPLAY_ORDER = "from qaQuestion in class QaQueContent where qaQuestion.qaContent.uid=:uid order by qaQuestion.displayOrder"; - public QaQueContent getQuestionContentByQuestionText(final String question, Long contentUid) { - HibernateTemplate templ = this.getHibernateTemplate(); + public QaQueContent getQuestionByDisplayOrder(Long displayOrder, Long contentUid) { + List list = getSession().createQuery(QaQuestionDAO.LOAD_QUESTION_BY_DISPLAY_ORDER).setLong( + "displayOrder", displayOrder.longValue()).setLong("uid", contentUid.longValue()).list(); - List list = getSession().createQuery(QaQuestionDAO.LOAD_QUESTION_CONTENT_BY_QUESTION_TEXT).setString( - "question", question).setLong("uid", contentUid.longValue()).list(); - if (list != null && list.size() > 0) { QaQueContent qa = (QaQueContent) list.get(0); return qa; } return null; } + + public QaQueContent getQuestionByUid(Long questionUid) { + List list = getSession().createQuery(QaQuestionDAO.LOAD_QUESTION_BY_QUESTION_UID).setLong( + "uid", questionUid.longValue()).list(); - public QaQueContent getQuestionByDisplayOrder(Long displayOrder, Long contentUid) { - List list = getSession().createQuery(QaQuestionDAO.LOAD_QUESTION_CONTENT_BY_DISPLAY_ORDER).setLong( - "displayOrder", displayOrder.longValue()).setLong("uid", contentUid.longValue()).list(); - if (list != null && list.size() > 0) { QaQueContent qa = (QaQueContent) list.get(0); return qa; } return null; } - public List getAllQuestionEntriesSorted(final long contentUid) { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(QaQuestionDAO.SORT_QUESTION_CONTENT_BY_DISPLAY_ORDER).setLong( + public List getAllQuestionEntriesSorted(final long contentUid) { + List list = getSession().createQuery(QaQuestionDAO.SORT_QUESTION_BY_DISPLAY_ORDER).setLong( "uid", contentUid).list(); return list; } - public List getAllQuestionEntries(final long contentUid) { - HibernateTemplate templ = this.getHibernateTemplate(); + public List getAllQuestionEntries(final long contentUid) { List list = getSession().createQuery(QaQuestionDAO.LOAD_QUESTION_BY_CONTENT_UID).setLong( "uid", contentUid).list(); Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/hibernate/QaSessionDAO.java =================================================================== diff -u -rbe07c35c372d904a65581d98660e73f3b13b69db -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/hibernate/QaSessionDAO.java (.../QaSessionDAO.java) (revision be07c35c372d904a65581d98660e73f3b13b69db) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/hibernate/QaSessionDAO.java (.../QaSessionDAO.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -38,7 +38,6 @@ public class QaSessionDAO extends HibernateDaoSupport implements IQaSessionDAO { private static final String COUNT_SESSION_COMPLETE = "from qaSession in class QaSession where qaSession.session_status='COMPLETE'"; private static final String GET_SESSION_IDS_FROM_CONTENT = "select qas.qaSessionId from QaSession qas where qas.qaContent=:qaContent order by qas.session_name asc"; - private static final String GET_SESSION_NAMES_FROM_CONTENT = "select qas.session_name from QaSession qas where qas.qaContent=:qaContent order by qas.session_name asc"; public int countSessionComplete(QaContent qa) { List list = getSession().createQuery(COUNT_SESSION_COMPLETE).list(); @@ -70,7 +69,7 @@ /** * @see org.lamsfoundation.lams.tool.survey.dao.interfaces.ISurveySessionDAO#CreateSurveySession(com.lamsinternational.tool.survey.domain.SurveySession) */ - public void CreateQaSession(QaSession session) { + public void createSession(QaSession session) { this.getSession().setFlushMode(FlushMode.AUTO); this.getHibernateTemplate().save(session); } @@ -95,8 +94,4 @@ return (getHibernateTemplate().findByNamedParam(GET_SESSION_IDS_FROM_CONTENT, "qaContent", qaContent)); } - public List getSessionNamesFromContent(QaContent qaContent) { - return (getHibernateTemplate().findByNamedParam(GET_SESSION_NAMES_FROM_CONTENT, "qaContent", qaContent)); - } - } Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dbupdates/patch20140527.sql =================================================================== diff -u -rc5457cc74f3986b393bc2947604b17168ba54dfb -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dbupdates/patch20140527.sql (.../patch20140527.sql) (revision c5457cc74f3986b393bc2947604b17168ba54dfb) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dbupdates/patch20140527.sql (.../patch20140527.sql) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -5,6 +5,7 @@ -- LDEV-3236 Ability to change, add, remove Q&A questions even after student have reached it ALTER TABLE tl_laqa11_content DROP COLUMN content_inUse; +ALTER TABLE tl_laqa11_content DROP COLUMN synch_in_monitor; ALTER TABLE tl_laqa11_content ADD COLUMN notify_response_submit TINYINT(1) NOT NULL DEFAULT 0; Fisheye: Tag a7661f206a3f21114f1c05f9a29f56e20f5e35f0 refers to a dead (removed) revision in file `lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dto/GeneralMonitoringDTO.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dto/QaConditionDTO.java =================================================================== diff -u -r501ddb69e1c739b90388262f41b4927356cb0449 -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dto/QaConditionDTO.java (.../QaConditionDTO.java) (revision 501ddb69e1c739b90388262f41b4927356cb0449) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dto/QaConditionDTO.java (.../QaConditionDTO.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -38,7 +38,7 @@ super(condition, toolActivityUIID); for (QaQueContent question : condition.getQuestions()) { QaQueContent questionCopy = new QaQueContent(question.getQuestion(), question.getDisplayOrder(), null, - question.isRequired(), null, null); + question.isRequired(), null); getQuestions().add(questionCopy); } } Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dto/QaGeneralAuthoringDTO.java =================================================================== diff -u -rdfbc0a5728344573bc1bcbf0095e4f2778d3ad8d -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dto/QaGeneralAuthoringDTO.java (.../QaGeneralAuthoringDTO.java) (revision dfbc0a5728344573bc1bcbf0095e4f2778d3ad8d) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dto/QaGeneralAuthoringDTO.java (.../QaGeneralAuthoringDTO.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -24,7 +24,6 @@ /* $$Id$$ */ package org.lamsfoundation.lams.tool.qa.dto; -import org.apache.commons.lang.builder.ToStringBuilder; /** *

@@ -36,21 +35,13 @@ public class QaGeneralAuthoringDTO implements Comparable { protected String toolContentID; protected String currentTab; - protected String activeModule; - protected String defineLaterInEditMode; - protected String showAuthoringTabs; - protected String monitoringOriginatedDefineLater; - protected String targetMode; - protected String defaultQuestionContent; - protected String defaultContentIdStr; protected String activityTitle; protected String activityInstructions; protected String usernameVisible; protected String allowRateAnswers; protected String showOtherAnswers; protected String reflect; - protected String synchInMonitor; protected String questionsSequenced; protected String lockWhenFinished; protected String editActivityEditMode; @@ -59,35 +50,13 @@ protected Boolean useSelectLeaderToolOuput; protected String httpSessionID; - protected String requestedModule; - protected String isDefineLater; - protected String sbmtSuccess; protected String userExceptionQuestionsDuplicate; protected String contentFolderID; protected String editableQuestionText; protected String editableQuestionFeedback; - public String toString() { - return new ToStringBuilder(this).append("toolContentID: ", toolContentID) - .append("contentFolderID: ", contentFolderID).append("httpSessionID: ", httpSessionID) - .append("currentTab: ", currentTab).append("activeModule: ", activeModule) - .append("defineLaterInEditMode: ", defineLaterInEditMode) - .append("showAuthoringTabs: ", showAuthoringTabs) - .append("monitoringOriginatedDefineLater: ", monitoringOriginatedDefineLater) - .append("targetMode: ", targetMode).append("defaultQuestionContent: ", defaultQuestionContent) - .append("defaultContentIdStr: ", defaultContentIdStr).append("activityTitle: ", activityTitle) - .append("activityInstructions: ", activityInstructions).append("reflect: ", reflect) - .append("usernameVisible: ", usernameVisible).append("allowRateAnswers: ", allowRateAnswers) - .append("showOtherAnswers: ", showOtherAnswers).append("synchInMonitor: ", synchInMonitor) - .append("questionsSequenced: ", questionsSequenced).append("lockWhenFinished: ", lockWhenFinished) - .append("editActivityEditMode: ", editActivityEditMode) - .append("reflectionSubject: ", reflectionSubject).append("requestedModule: ", requestedModule) - .append("isDefineLater: ", isDefineLater).append("sbmtSuccess: ", sbmtSuccess) - .append("userExceptionQuestionsDuplicate: ", userExceptionQuestionsDuplicate).toString(); - } - /** * @return Returns the userExceptionQuestionsDuplicate. */ @@ -134,21 +103,6 @@ } /** - * @return Returns the isDefineLater. - */ - public String getIsDefineLater() { - return isDefineLater; - } - - /** - * @param isDefineLater - * The isDefineLater to set. - */ - public void setIsDefineLater(String isDefineLater) { - this.isDefineLater = isDefineLater; - } - - /** * @return Returns the toolContentID. */ public String getToolContentID() { @@ -163,81 +117,6 @@ this.toolContentID = toolContentID; } - /** - * @return Returns the targetMode. - */ - public String getTargetMode() { - return targetMode; - } - - /** - * @param targetMode - * The targetMode to set. - */ - public void setTargetMode(String targetMode) { - this.targetMode = targetMode; - } - - /** - * @return Returns the monitoringOriginatedDefineLater. - */ - public String getMonitoringOriginatedDefineLater() { - return monitoringOriginatedDefineLater; - } - - /** - * @param monitoringOriginatedDefineLater - * The monitoringOriginatedDefineLater to set. - */ - public void setMonitoringOriginatedDefineLater(String monitoringOriginatedDefineLater) { - this.monitoringOriginatedDefineLater = monitoringOriginatedDefineLater; - } - - /** - * @return Returns the activeModule. - */ - public String getActiveModule() { - return activeModule; - } - - /** - * @param activeModule - * The activeModule to set. - */ - public void setActiveModule(String activeModule) { - this.activeModule = activeModule; - } - - /** - * @return Returns the defineLaterInEditMode. - */ - public String getDefineLaterInEditMode() { - return defineLaterInEditMode; - } - - /** - * @param defineLaterInEditMode - * The defineLaterInEditMode to set. - */ - public void setDefineLaterInEditMode(String defineLaterInEditMode) { - this.defineLaterInEditMode = defineLaterInEditMode; - } - - /** - * @return Returns the showAuthoringTabs. - */ - public String getShowAuthoringTabs() { - return showAuthoringTabs; - } - - /** - * @param showAuthoringTabs - * The showAuthoringTabs to set. - */ - public void setShowAuthoringTabs(String showAuthoringTabs) { - this.showAuthoringTabs = showAuthoringTabs; - } - public int compareTo(Object o) { QaGeneralAuthoringDTO qaGeneralAuthoringDTO = (QaGeneralAuthoringDTO) o; @@ -248,51 +127,6 @@ } /** - * @return Returns the defaultContentIdStr. - */ - public String getDefaultContentIdStr() { - return defaultContentIdStr; - } - - /** - * @param defaultContentIdStr - * The defaultContentIdStr to set. - */ - public void setDefaultContentIdStr(String defaultContentIdStr) { - this.defaultContentIdStr = defaultContentIdStr; - } - - /** - * @return Returns the defaultQuestionContent. - */ - public String getDefaultQuestionContent() { - return defaultQuestionContent; - } - - /** - * @param defaultQuestionContent - * The defaultQuestionContent to set. - */ - public void setDefaultQuestionContent(String defaultQuestionContent) { - this.defaultQuestionContent = defaultQuestionContent; - } - - /** - * @return Returns the requestedModule. - */ - public String getRequestedModule() { - return requestedModule; - } - - /** - * @param requestedModule - * The requestedModule to set. - */ - public void setRequestedModule(String requestedModule) { - this.requestedModule = requestedModule; - } - - /** * @return Returns the activityInstructions. */ public String getActivityInstructions() { @@ -338,21 +172,6 @@ } /** - * @return Returns the synchInMonitor. - */ - public String getSynchInMonitor() { - return synchInMonitor; - } - - /** - * @param synchInMonitor - * The synchInMonitor to set. - */ - public void setSynchInMonitor(String synchInMonitor) { - this.synchInMonitor = synchInMonitor; - } - - /** * @return Returns the usernameVisible. */ public String getUsernameVisible() { @@ -398,21 +217,6 @@ } /** - * @return Returns the sbmtSuccess. - */ - public String getSbmtSuccess() { - return sbmtSuccess; - } - - /** - * @param sbmtSuccess - * The sbmtSuccess to set. - */ - public void setSbmtSuccess(String sbmtSuccess) { - this.sbmtSuccess = sbmtSuccess; - } - - /** * @return Returns the contentFolderID. */ public String getContentFolderID() { Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dto/QaQuestionDTO.java =================================================================== diff -u -r501ddb69e1c739b90388262f41b4927356cb0449 -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dto/QaQuestionDTO.java (.../QaQuestionDTO.java) (revision 501ddb69e1c739b90388262f41b4927356cb0449) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dto/QaQuestionDTO.java (.../QaQuestionDTO.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -23,33 +23,26 @@ /* $$Id$$ */ package org.lamsfoundation.lams.tool.qa.dto; -import org.apache.commons.lang.builder.ToStringBuilder; import org.lamsfoundation.lams.tool.qa.QaQueContent; /** - *

* DTO that holds users attempt history data for jsp purposes - *

* * @author Ozgur Demirtas */ public class QaQuestionDTO implements Comparable { + private Long uid; private String question; private String displayOrder; private String feedback; private boolean required; - @Override - public String toString() { - return new ToStringBuilder(this).append("question:", question).append("feedback:", feedback).append( - "displayOrder:", displayOrder).append("required:", Boolean.toString(required)).toString(); - } - public QaQuestionDTO(QaQueContent que) { this.question = que.getQuestion(); this.displayOrder = new Integer(que.getDisplayOrder()).toString(); this.feedback = que.getFeedback() != null ? que.getFeedback() : " "; this.required = que.isRequired(); + this.uid = que.getUid(); } public QaQuestionDTO(String question, String displayOrder, String feedback, boolean required) { @@ -68,8 +61,23 @@ return 0; } } + + /** + * @return Returns the uid. + */ + public Long getUid() { + return uid; + } /** + * @param uid + * The uid to set. + */ + public void setUid(Long uid) { + this.uid = uid; + } + + /** * @return Returns the displayOrder. */ public String getDisplayOrder() { Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/IQaService.java =================================================================== diff -u -rc5457cc74f3986b393bc2947604b17168ba54dfb -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/IQaService.java (.../IQaService.java) (revision c5457cc74f3986b393bc2947604b17168ba54dfb) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/IQaService.java (.../IQaService.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -25,6 +25,7 @@ import java.util.Collection; import java.util.List; +import java.util.Set; import java.util.SortedSet; import org.lamsfoundation.lams.notebook.model.NotebookEntry; @@ -40,8 +41,8 @@ import org.lamsfoundation.lams.tool.qa.QaUsrResp; import org.lamsfoundation.lams.tool.qa.QaWizardCategory; import org.lamsfoundation.lams.tool.qa.dto.AverageRatingDTO; +import org.lamsfoundation.lams.tool.qa.dto.QaQuestionDTO; import org.lamsfoundation.lams.tool.qa.dto.ReflectionDTO; -import org.lamsfoundation.lams.tool.qa.util.QaApplicationException; import org.lamsfoundation.lams.util.audit.IAuditService; /** @@ -50,61 +51,58 @@ * @author Ozgur Demirtas */ public interface IQaService { - + /** * @param user * @param toolSessionId * @return */ boolean isUserGroupLeader(QaQueUsr user, Long toolSessionId); - + /** * Set specified user as a leader. Also the previous leader (if any) is marked as non-leader. * * @param userId * @param toolSessionID */ QaQueUsr checkLeaderSelectToolForSessionLeader(QaQueUsr user, Long toolSessionID); - + /** - * Check user has the same answers logs as group leader. If not - creates missing ones. + * Check user has the same answers logs as group leader. If not - creates missing ones. * * @param user * @param leader */ void copyAnswersFromLeader(QaQueUsr user, QaQueUsr leader); - + /** * Get users by given toolSessionID. * * @param toolSessionID * @return */ - List getUsersBySession(Long toolSessionID); - + List getUsersBySessionId(Long toolSessionID); + /** * Return the qa object according to the requested content id. * * @param toolContentId - * the tool content id + * the tool content id * @return the qa object */ - QaContent getQa(long toolContentId) throws QaApplicationException; + QaContent getQaContent(long toolContentId); - void saveOrUpdateQa(QaContent qa) throws QaApplicationException; + void saveOrUpdateQaContent(QaContent qa); - int getTotalNumberOfUsers(QaContent qa) throws QaApplicationException; + int getTotalNumberOfUsers(QaContent qa); - int countSessionComplete(QaContent qa) throws QaApplicationException; + int countSessionComplete(QaContent qa); - void updateQaQueUsr(QaQueUsr qaQueUsr) throws QaApplicationException; + void updateUser(QaQueUsr qaQueUsr); - QaQueUsr loadQaQueUsr(Long userId) throws QaApplicationException; + QaUsrResp getResponseByUserAndQuestion(final Long queUsrId, final Long qaQueContentId); - QaUsrResp getResponseByUserAndQuestion(final Long queUsrId, final Long qaQueContentId) - throws QaApplicationException; - /** * Creates or updates response with answer submitted by user. * @@ -114,66 +112,59 @@ */ void updateResponseWithNewAnswer(String newAnswer, String toolSessionID, Long questionDisplayOrder); - void createQaQue(QaQueContent qaQuestion) throws QaApplicationException; + void createQuestion(QaQueContent qaQuestion); - void removeQaQueContent(QaQueContent qaQuestion) throws QaApplicationException; + void removeQuestion(QaQueContent qaQuestion); - void createQaUsrResp(QaUsrResp qaUsrResp) throws QaApplicationException; + void createUserResponse(QaUsrResp qaUsrResp); - void updateUserResponse(QaUsrResp resp) throws QaApplicationException; + void updateUserResponse(QaUsrResp resp); - QaUsrResp getResponseById(Long responseId) throws QaApplicationException; + QaUsrResp getResponseById(Long responseId); - QaQueContent getQuestionContentByQuestionText(final String question, Long contentUid) - throws QaApplicationException; + QaQueContent getQuestionByContentAndDisplayOrder(Long displayOrder, Long contentUid); - QaQueContent getQuestionByContentAndDisplayOrder(Long displayOrder, Long contentUid) - throws QaApplicationException; + QaQueContent getQuestionByUid(Long questionUid); - List getAllQuestionEntriesSorted(final long qaContentId) throws QaApplicationException; + List getAllQuestionEntriesSorted(final long qaContentId); - void saveOrUpdateQaQueContent(QaQueContent qaQuestion) throws QaApplicationException; + void saveOrUpdateQuestion(QaQueContent qaQuestion); /** * Return the qa session object according to the requested session id. * * @param qaSessionId - * qa session id + * qa session id * @return the qa session object */ - QaSession retrieveQaSession(long qaSessionId) throws QaApplicationException; + QaSession getSessionById(long qaSessionId); - QaSession getSessionById(long qaSessionId) throws QaApplicationException; + void createSession(QaSession qaSession); - void createQaSession(QaSession qaSession) throws QaApplicationException; - - List getSessionNamesFromContent(QaContent qaContent) throws QaApplicationException; - void removeToolSession(Long toolSessionId) throws DataMissingException, ToolException; - List getSessionsFromContent(QaContent qaContent) throws QaApplicationException; + List getSessionsFromContent(QaContent qaContent); - QaQueUsr createUser(Long toolSessionID) throws QaApplicationException; + QaQueUsr createUser(Long toolSessionID); - void updateQaSession(QaSession qaSession) throws QaApplicationException; + void updateSession(QaSession qaSession); - QaQueUsr getQaQueUsrById(long qaQueUsrId) throws QaApplicationException; + void updateQaContent(QaContent qa); - void updateQa(QaContent qa) throws QaApplicationException; + void createQaContent(QaContent qa); - void createQa(QaContent qa) throws QaApplicationException; - void updateResponseVisibility(Long responseUid, boolean visible); - QaContent retrieveQaBySession(long qaSessionId) throws QaApplicationException; + QaQueUsr getUserByIdAndSession(final Long queUsrId, final Long qaSessionId); - QaQueUsr getUserByIdAndSession(final Long queUsrId, final Long qaSessionId) throws QaApplicationException; + void removeUserResponse(QaUsrResp resp); - void removeUserResponse(QaUsrResp resp) throws QaApplicationException; + List getAllQuestionEntries(final Long uid); - List getAllQuestionEntries(final Long uid) throws QaApplicationException; + List getUserBySessionOnly(final QaSession qaSession); - List getUserBySessionOnly(final QaSession qaSession) throws QaApplicationException; + void recalculateUserAnswers(QaContent content, Set oldQuestions, List questionDTOs, + List deletedQuestions); /** * copyToolContent(Long fromContentId, Long toContentId) return void @@ -183,14 +174,13 @@ */ void copyToolContent(Long fromContentId, Long toContentId) throws ToolException; - boolean isStudentActivityOccurredGlobal(QaContent qaContent) throws QaApplicationException; + boolean isStudentActivityOccurredGlobal(QaContent qaContent); /** - * createToolSession(Long toolSessionId,String toolSessionName, Long - * toolContentId) + * createToolSession(Long toolSessionId,String toolSessionName, Long toolContentId) * - * It is also defined here since in development we want to be able call it - * directly from the web-layer instead of it being called by the container. + * It is also defined here since in development we want to be able call it directly from the web-layer instead of it + * being called by the container. * * @param toolSessionId * @param toolContentId @@ -200,25 +190,25 @@ /** * leaveToolSession(Long toolSessionId, Long learnerId) * - * It is also defined here since in development we want to be able call it - * directly from our web-layer instead of it being called by the container. + * It is also defined here since in development we want to be able call it directly from our web-layer instead of it + * being called by the container. * * @param toolSessionId * @param toolContentId */ String leaveToolSession(Long toolSessionId, Long learnerId) throws DataMissingException, ToolException; - IToolVO getToolBySignature(String toolSignature) throws QaApplicationException; + IToolVO getToolBySignature(String toolSignature); - long getToolDefaultContentIdBySignature(String toolSignature) throws QaApplicationException; + long getToolDefaultContentIdBySignature(String toolSignature); Long createNotebookEntry(Long id, Integer idType, String signature, Integer userID, String entry); NotebookEntry getEntry(Long id, Integer idType, String signature, Integer userID); /** - * Get the LAMS audit service. Needed as the web layer controls the staff - * updating of an answer, so the log entry must be made by the web layer. + * Get the LAMS audit service. Needed as the web layer controls the staff updating of an answer, so the log entry + * must be made by the web layer. */ IAuditService getAuditService(); @@ -227,12 +217,11 @@ QaContent getQaContentBySessionId(Long sessionId); /** - * Creates an unique name for a QaCondition. It consists of the tool output - * definition name and a unique positive integer number. + * Creates an unique name for a QaCondition. It consists of the tool output definition name and a unique positive + * integer number. * * @param existingConditions - * existing conditions; required to check if a condition with - * the same name does not exist. + * existing conditions; required to check if a condition with the same name does not exist. * @return unique QaCondition name */ String createConditionName(Collection existingConditions); @@ -264,8 +253,7 @@ SortedSet getWizardCategories(); /** - * Saves the entire set of QaWizardCategories (including the child cognitive - * skills and questions) + * Saves the entire set of QaWizardCategories (including the child cognitive skills and questions) * * @param categories */ @@ -298,29 +286,31 @@ void deleteAllWizardCategories(); void removeQuestionsFromCache(QaContent qaContent); - + + void removeQaContentFromCache(QaContent qaContent); + /** * Returns whether activity is grouped and therefore it is expected more than one tool session. * * @param toolContentID * @return */ boolean isGroupedActivity(long toolContentID); - + /** - * Return content folder (unique to each learner and lesson) which is used for storing user generated content. - * It's been used by CKEditor. + * Return content folder (unique to each learner and lesson) which is used for storing user generated content. It's + * been used by CKEditor. * * @param toolSessionId * @param userId * @return */ String getLearnerContentFolder(Long toolSessionId, Long userId); - + AverageRatingDTO rateResponse(Long responseId, Long userId, Long toolSessionID, float rating); - + AverageRatingDTO getAverageRatingDTOByResponse(Long responseId); - + /** * Return reflection data for all sessions. * @@ -329,7 +319,7 @@ * @return */ List getReflectList(QaContent content, String userID); - + /** * notifyTeachersOnResponseSubmit * Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaImportContentVersionFilter.java =================================================================== diff -u -rdfbc0a5728344573bc1bcbf0095e4f2778d3ad8d -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaImportContentVersionFilter.java (.../QaImportContentVersionFilter.java) (revision dfbc0a5728344573bc1bcbf0095e4f2778d3ad8d) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaImportContentVersionFilter.java (.../QaImportContentVersionFilter.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -61,5 +61,6 @@ */ public void up20140102To20140102() { this.removeField(QaContent.class, "contentLocked"); + this.removeField(QaContent.class, "synchInMonitor"); } } Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaOutputFactory.java =================================================================== diff -u -r629b2631320321b57015e15be850e7c6b747225f -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaOutputFactory.java (.../QaOutputFactory.java) (revision 629b2631320321b57015e15be850e7c6b747225f) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaOutputFactory.java (.../QaOutputFactory.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -154,7 +154,7 @@ if (QaAppConstants.USER_ANSWERS_DEFINITION_NAME.equals(nameParts[0])) { // user answers are loaded from the DB and array of strings is created - QaSession session = qaService.retrieveQaSession(toolSessionId); + QaSession session = qaService.getSessionById(toolSessionId); QaContent qaContent = session.getQaContent(); Set questions = qaContent.getQaQueContents(); String[] answers = new String[questions.size()]; @@ -169,7 +169,7 @@ } else if (QaAppConstants.GROUP_ANSWERS_DEFINITION_NAME.equals(nameParts[0])) { // all users' answers are loaded from the DB and array of strings is created - QaSession session = qaService.retrieveQaSession(toolSessionId); + QaSession session = qaService.getSessionById(toolSessionId); QaContent qaContent = session.getQaContent(); Set questions = qaContent.getQaQueContents(); Set users = session.getQaQueUsers(); @@ -232,7 +232,7 @@ usersAndAnswers, false); } else if (QaAppConstants.QUESTIONS_DEFINITION_NAME.equals(nameParts[0])) { // Questions asked in this Q&A activity - QaSession session = qaService.retrieveQaSession(toolSessionId); + QaSession session = qaService.getSessionById(toolSessionId); QaContent qaContent = session.getQaContent(); Set questions = qaContent.getQaQueContents(); String[] questionArray = new String[questions.size()]; Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaServicePOJO.java =================================================================== diff -u -rc5457cc74f3986b393bc2947604b17168ba54dfb -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaServicePOJO.java (.../QaServicePOJO.java) (revision c5457cc74f3986b393bc2947604b17168ba54dfb) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaServicePOJO.java (.../QaServicePOJO.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -24,6 +24,7 @@ /* $$Id$$ */ package org.lamsfoundation.lams.tool.qa.service; +import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.Hashtable; @@ -39,8 +40,6 @@ import javax.servlet.http.HttpSession; import org.apache.log4j.Logger; -import org.lamsfoundation.lams.contentrepository.ItemNotFoundException; -import org.lamsfoundation.lams.contentrepository.RepositoryCheckedException; import org.lamsfoundation.lams.contentrepository.client.IToolContentHandler; import org.lamsfoundation.lams.events.IEventNotificationService; import org.lamsfoundation.lams.learning.service.ILearnerService; @@ -79,6 +78,7 @@ import org.lamsfoundation.lams.tool.qa.dao.IQaWizardDAO; import org.lamsfoundation.lams.tool.qa.dao.IResponseRatingDAO; import org.lamsfoundation.lams.tool.qa.dto.AverageRatingDTO; +import org.lamsfoundation.lams.tool.qa.dto.QaQuestionDTO; import org.lamsfoundation.lams.tool.qa.dto.ReflectionDTO; import org.lamsfoundation.lams.tool.qa.util.QaApplicationException; import org.lamsfoundation.lams.tool.qa.util.QaSessionComparator; @@ -96,23 +96,14 @@ import org.springframework.dao.DataAccessException; /** - * The POJO implementation of Survey service. All business logics of survey tool are implemented in this class. It - * translate the request from presentation layer and perform approporiate database operation. + * The POJO implementation of Qa service. All business logics of Qa tool are implemented in this class. It translate the + * request from presentation layer and perform approporiate database operation. * - * Two construtors are provided in this class. The constuctor with Hibernate session object allows survey tool to handle - * long run application transaction. The developer can store Hibernate session in http session and pass across different - * http request. This implementation also make the testing out side JBoss container much easier. - * - * Every method is implemented as a Hibernate session transaction. It open an new persistent session or connect to - * existing persistent session in the begining and it close or disconnect to the persistent session in the end. - * * @author Ozgur Demirtas - * */ - public class QaServicePOJO implements IQaService, ToolContentManager, ToolSessionManager, ToolContentImport102Manager, QaAppConstants { - static Logger logger = Logger.getLogger(QaServicePOJO.class.getName()); + private static Logger logger = Logger.getLogger(QaServicePOJO.class.getName()); private IQaContentDAO qaDAO; private IQaQuestionDAO qaQuestionDAO; @@ -137,17 +128,17 @@ private MessageService messageService; private Random generator = new Random(); - + @Override public boolean isUserGroupLeader(QaQueUsr user, Long toolSessionId) { QaSession session = this.getSessionById(toolSessionId); QaQueUsr groupLeader = session.getGroupLeader(); - + boolean isUserLeader = (groupLeader != null) && user.getUid().equals(groupLeader.getUid()); return isUserLeader; } - + @Override public QaQueUsr checkLeaderSelectToolForSessionLeader(QaQueUsr user, Long toolSessionId) { if (user == null || toolSessionId == null) { @@ -175,30 +166,31 @@ // set group leader qaSession.setGroupLeader(leader); - this.updateQaSession(qaSession); + this.updateSession(qaSession); } } return leader; } - + @Override public void copyAnswersFromLeader(QaQueUsr user, QaQueUsr leader) { if ((user == null) || (leader == null) || user.getUid().equals(leader.getUid())) { return; } - for (QaUsrResp leaderResponse : (Set)leader.getQaUsrResps()) { + for (QaUsrResp leaderResponse : (Set) leader.getQaUsrResps()) { QaQueContent question = leaderResponse.getQaQuestion(); QaUsrResp response = qaUsrRespDAO.getResponseByUserAndQuestion(user.getQueUsrId(), question.getUid()); // if response doesn't exist if (response == null) { - response = new QaUsrResp(leaderResponse.getAnswer(), leaderResponse.getAttemptTime(), "", question, user, true); - createQaUsrResp(response); + response = new QaUsrResp(leaderResponse.getAnswer(), leaderResponse.getAttemptTime(), "", question, + user, true); + createUserResponse(response); - // if it's been changed by the leader + // if it's been changed by the leader } else if (leaderResponse.getAttemptTime().compareTo(response.getAttemptTime()) != 0) { response.setAnswer(leaderResponse.getAnswer()); response.setAttemptTime(leaderResponse.getAttemptTime()); @@ -207,169 +199,79 @@ } } } - + @Override - public List getUsersBySession(Long toolSessionID) { + public List getUsersBySessionId(Long toolSessionID) { QaSession session = qaSessionDAO.getQaSessionById(toolSessionID); return qaQueUsrDAO.getUserBySessionOnly(session); } - public void createQa(QaContent qaContent) throws QaApplicationException { - try { - qaDAO.saveQa(qaContent); - } catch (DataAccessException e) { - throw new QaApplicationException("Exception occured when lams is creating qa content: " + e.getMessage(), e); - } + public void createQaContent(QaContent qaContent) { + qaDAO.saveQa(qaContent); } - public QaContent getQa(long toolContentID) throws QaApplicationException { - try { - return qaDAO.getQaByContentId(toolContentID); - } catch (DataAccessException e) { - throw new QaApplicationException("Exception occured when lams is loading qa content: " + e.getMessage(), e); - } + public QaContent getQaContent(long toolContentID) { + return qaDAO.getQaByContentId(toolContentID); } - public void saveOrUpdateQa(QaContent qa) throws QaApplicationException { - try { - qaDAO.saveOrUpdateQa(qa); - } catch (DataAccessException e) { - throw new QaApplicationException("Exception occured when lams is saveOrUpdating qa content: " - + e.getMessage(), e); - } - + public void saveOrUpdateQaContent(QaContent qa) { + qaDAO.saveOrUpdateQa(qa); } - public QaQueContent getQuestionContentByQuestionText(final String question, Long contentUid) - throws QaApplicationException { - try { - return qaQuestionDAO.getQuestionContentByQuestionText(question, contentUid); - - } catch (DataAccessException e) { - throw new QaApplicationException("Exception occured when lams is getting qa content by question text: " - + e.getMessage(), e); - } + public QaQueContent getQuestionByContentAndDisplayOrder(Long displayOrder, Long contentUid) { + return qaQuestionDAO.getQuestionByDisplayOrder(displayOrder, contentUid); } - - public QaQueContent getQuestionByContentAndDisplayOrder(Long displayOrder, Long contentUid) - throws QaApplicationException { - try { - return qaQuestionDAO.getQuestionByDisplayOrder(displayOrder, contentUid); - - } catch (DataAccessException e) { - throw new QaApplicationException("Exception occured when lams is getting qa content by question text: " - + e.getMessage(), e); + + public QaQueContent getQuestionByUid(Long questionUid) { + if (questionUid == null) { + return null; } + + return qaQuestionDAO.getQuestionByUid(questionUid); } - public void saveOrUpdateQaQueContent(QaQueContent qaQuestion) throws QaApplicationException { - try { - qaQuestionDAO.saveOrUpdateQaQueContent(qaQuestion); - - } catch (DataAccessException e) { - throw new QaApplicationException("Exception occured when lams is updating qa content by question: " - + e.getMessage(), e); - } - + public void saveOrUpdateQuestion(QaQueContent question) { + qaQuestionDAO.saveOrUpdateQaQueContent(question); } - public void createQaQue(QaQueContent qaQuestion) throws QaApplicationException { - try { - qaQuestionDAO.createQueContent(qaQuestion); - } catch (DataAccessException e) { - throw new QaApplicationException("Exception occured when lams is creating qa content: " + e.getMessage(), e); - } + public void createQuestion(QaQueContent question) { + qaQuestionDAO.createQueContent(question); } - public void createQaSession(QaSession qaSession) throws QaApplicationException { - try { - qaSessionDAO.CreateQaSession(qaSession); - } catch (DataAccessException e) { - throw new QaApplicationException("Exception occured when lams is creating qa session: " + e.getMessage(), e); - } + public void createSession(QaSession qaSession) { + qaSessionDAO.createSession(qaSession); } - public List getSessionNamesFromContent(QaContent qaContent) throws QaApplicationException { - try { - return qaSessionDAO.getSessionNamesFromContent(qaContent); - } catch (DataAccessException e) { - throw new QaApplicationException("Exception occured when lams is getting session names from content: " - + e.getMessage(), e); - } + public List getSessionsFromContent(QaContent qaContent) { + return qaSessionDAO.getSessionsFromContent(qaContent); } - public List getSessionsFromContent(QaContent qaContent) throws QaApplicationException { - try { - return qaSessionDAO.getSessionsFromContent(qaContent); - } catch (DataAccessException e) { - throw new QaApplicationException("Exception occured when lams is getting" + " the qa sessions list: " - + e.getMessage(), e); - } - } + public QaQueUsr createUser(Long toolSessionID) { + HttpSession ss = SessionManager.getSession(); + UserDTO toolUser = (UserDTO) ss.getAttribute(AttributeNames.USER); + Long userId = toolUser.getUserID().longValue(); + String userName = toolUser.getLogin(); + String fullName = toolUser.getFirstName() + " " + toolUser.getLastName(); + QaSession qaSession = getSessionById(toolSessionID.longValue()); - public QaQueUsr createUser(Long toolSessionID) throws QaApplicationException { - try { - HttpSession ss = SessionManager.getSession(); - UserDTO toolUser = (UserDTO) ss.getAttribute(AttributeNames.USER); - Long userId = toolUser.getUserID().longValue(); - String userName = toolUser.getLogin(); - String fullName = toolUser.getFirstName() + " " + toolUser.getLastName(); - QaSession qaSession = getSessionById(toolSessionID.longValue()); + QaQueUsr user = new QaQueUsr(userId, userName, fullName, qaSession, new TreeSet()); + qaQueUsrDAO.createUsr(user); - QaQueUsr user = new QaQueUsr(userId, userName, fullName, qaSession, new TreeSet()); - qaQueUsrDAO.createUsr(user); - - return user; - } catch (DataAccessException e) { - throw new QaApplicationException("Exception occured when lams is creating qa QueUsr: " + e.getMessage(), e); - } + return user; } - public QaQueUsr getUserByIdAndSession(final Long queUsrId, final Long qaSessionId) throws QaApplicationException { - try { - return qaQueUsrDAO.getQaUserBySession(queUsrId, qaSessionId); - } catch (DataAccessException e) { - throw new QaApplicationException("Exception occured when lams is getting qa QueUsr: " + e.getMessage(), e); - } + public QaQueUsr getUserByIdAndSession(final Long queUsrId, final Long qaSessionId) { + return qaQueUsrDAO.getQaUserBySession(queUsrId, qaSessionId); } - public QaQueUsr loadQaQueUsr(Long userId) throws QaApplicationException { - try { - QaQueUsr qaQueUsr = qaQueUsrDAO.loadQaQueUsrById(userId.longValue()); - return qaQueUsr; - } catch (DataAccessException e) { - throw new QaApplicationException("Exception occured when lams is loading qa QueUsr: " + e.getMessage(), e); - } + public QaUsrResp getResponseByUserAndQuestion(final Long queUsrId, final Long qaQueContentId) { + return qaUsrRespDAO.getResponseByUserAndQuestion(queUsrId, qaQueContentId); } - public QaQueUsr getQaQueUsrById(long qaQueUsrId) throws QaApplicationException { - try { - QaQueUsr qaQueUsr = qaQueUsrDAO.getQaQueUsrById(qaQueUsrId); - return qaQueUsr; - } catch (DataAccessException e) { - throw new QaApplicationException("Exception occured when lams is getting qa QueUsr: " + e.getMessage(), e); - } + public void updateUserResponse(QaUsrResp resp) { + qaUsrRespDAO.updateUserResponse(resp); } - public QaUsrResp getResponseByUserAndQuestion(final Long queUsrId, final Long qaQueContentId) - throws QaApplicationException { - try { - return qaUsrRespDAO.getResponseByUserAndQuestion(queUsrId, qaQueContentId); - } catch (DataAccessException e) { - throw new QaApplicationException( - "Exception occured when lams is getting qa qaUsrRespDAO by user id and que content id: " - + e.getMessage(), e); - } - } - - public void updateUserResponse(QaUsrResp resp) throws QaApplicationException { - try { - qaUsrRespDAO.updateUserResponse(resp); - } catch (DataAccessException e) { - throw new QaApplicationException("Exception occured when lams is updating response" + e.getMessage(), e); - } - } - public void updateResponseWithNewAnswer(String newAnswer, String toolSessionID, Long questionDisplayOrder) { HttpSession ss = SessionManager.getSession(); UserDTO toolUser = (UserDTO) ss.getAttribute(AttributeNames.USER); @@ -378,17 +280,16 @@ QaSession session = getSessionById(new Long(toolSessionID)); QaContent qaContent = session.getQaContent(); - - QaQueContent question = getQuestionByContentAndDisplayOrder(new Long(questionDisplayOrder), - qaContent.getUid()); + QaQueContent question = getQuestionByContentAndDisplayOrder(new Long(questionDisplayOrder), qaContent.getUid()); + QaUsrResp response = getResponseByUserAndQuestion(user.getQueUsrId(), question.getUid()); // if response doesn't exist if (response == null) { response = new QaUsrResp(newAnswer, new Date(System.currentTimeMillis()), "", question, user, true); - createQaUsrResp(response); + createUserResponse(response); - // if answer has changed + // if answer has changed } else if (!newAnswer.equals(response.getAnswer())) { response.setAnswer(newAnswer); response.setAttemptTime(new Date(System.currentTimeMillis())); @@ -397,105 +298,47 @@ } } - public List getUserBySessionOnly(final QaSession qaSession) throws QaApplicationException { - try { - return qaQueUsrDAO.getUserBySessionOnly(qaSession); - } catch (DataAccessException e) { - throw new QaApplicationException("Exception occured when lams is getting qa QueUsr by qa session " - + e.getMessage(), e); - } + public List getUserBySessionOnly(final QaSession qaSession) { + return qaQueUsrDAO.getUserBySessionOnly(qaSession); } - public void createQaUsrResp(QaUsrResp qaUsrResp) throws QaApplicationException { - try { - qaUsrRespDAO.createUserResponse(qaUsrResp); - } catch (DataAccessException e) { - throw new QaApplicationException("Exception occured when lams is creating qa UsrResp: " + e.getMessage(), e); - } + public void createUserResponse(QaUsrResp qaUsrResp) { + qaUsrRespDAO.createUserResponse(qaUsrResp); } - public void updateQaQueUsr(QaQueUsr qaQueUsr) throws QaApplicationException { - try { - qaQueUsrDAO.updateUsr(qaQueUsr); - } catch (DataAccessException e) { - throw new QaApplicationException("Exception occured when lams is updating qa QueUsr: " + e.getMessage(), e); - } + public void updateUser(QaQueUsr qaQueUsr) { + qaQueUsrDAO.updateUsr(qaQueUsr); } - public QaUsrResp getResponseById(Long responseId) throws QaApplicationException { - try { - return qaUsrRespDAO.getResponseById(responseId); - } catch (DataAccessException e) { - throw new QaApplicationException("Exception occured when lams is loading qa qaUsrResp: " + e.getMessage(), - e); - } + public QaUsrResp getResponseById(Long responseId) { + return qaUsrRespDAO.getResponseById(responseId); } - public int countSessionComplete(QaContent qa) throws QaApplicationException { - try { - return qaSessionDAO.countSessionComplete(qa); - } catch (DataAccessException e) { - throw new QaApplicationException("Exception occured when lams is counting complete sessions" - + e.getMessage(), e); - } + public int countSessionComplete(QaContent qa) { + return qaSessionDAO.countSessionComplete(qa); } - public QaSession retrieveQaSession(long qaSessionId) throws QaApplicationException { - try { - return qaSessionDAO.getQaSessionById(qaSessionId); - } catch (DataAccessException e) { - throw new QaApplicationException("Exception occured when lams is loading qa session : " + e.getMessage(), e); - } + public QaSession getSessionById(long qaSessionId) { + return qaSessionDAO.getQaSessionById(qaSessionId); } - public QaSession getSessionById(long qaSessionId) throws QaApplicationException { - try { - return qaSessionDAO.getQaSessionById(qaSessionId); - } catch (DataAccessException e) { - throw new QaApplicationException("Exception occured when lams is loading qa session : " + e.getMessage(), e); - } + public void updateQaContent(QaContent qa) { + qaDAO.updateQa(qa); } - public QaContent retrieveQaBySession(long qaSessionId) throws QaApplicationException { - try { - return qaDAO.getQaBySession(new Long(qaSessionId)); - } catch (DataAccessException e) { - throw new QaApplicationException("Exception occured when lams is loading qa: " + e.getMessage(), e); - } + public void updateSession(QaSession qaSession) { + qaSessionDAO.UpdateQaSession(qaSession); } - public void updateQa(QaContent qa) throws QaApplicationException { - try { - qaDAO.updateQa(qa); - } catch (DataAccessException e) { - throw new QaApplicationException("Exception occured when lams is updating" + " the qa content: " - + e.getMessage(), e); - } + public void removeUserResponse(QaUsrResp resp) { + auditService.logChange(QaAppConstants.MY_SIGNATURE, resp.getQaQueUser().getQueUsrId(), resp.getQaQueUser() + .getUsername(), resp.getAnswer(), null); + qaUsrRespDAO.removeUserResponse(resp); } - public void updateQaSession(QaSession qaSession) throws QaApplicationException { - try { - qaSessionDAO.UpdateQaSession(qaSession); - } catch (DataAccessException e) { - throw new QaApplicationException("Exception occured when lams is updating qa session : " + e.getMessage(), - e); - } - } - - public void removeUserResponse(QaUsrResp resp) throws QaApplicationException { - try { - auditService.logChange(QaAppConstants.MY_SIGNATURE, resp.getQaQueUser().getQueUsrId(), resp.getQaQueUser() - .getUsername(), resp.getAnswer(), null); - qaUsrRespDAO.removeUserResponse(resp); - } catch (DataAccessException e) { - throw new QaApplicationException( - "Exception occured when lams is deleting" + " the resp: " + e.getMessage(), e); - } - } - @Override public void updateResponseVisibility(Long responseUid, boolean isHideItem) { - + QaUsrResp response = getResponseById(responseUid); if (response != null) { // createBy should be null for system default value. @@ -516,134 +359,145 @@ } public int getTotalNumberOfUsers(QaContent qa) { - try { - return qaQueUsrDAO.getTotalNumberOfUsers(qa); - } catch (DataAccessException e) { - throw new QaApplicationException("Exception occured when lams is retrieving total number of QaQueUsr: " - + e.getMessage(), e); - } + return qaQueUsrDAO.getTotalNumberOfUsers(qa); } - public List getAllQuestionEntries(final Long uid) throws QaApplicationException { - try { - return qaQuestionDAO.getAllQuestionEntries(uid.longValue()); - } catch (DataAccessException e) { - throw new QaApplicationException("Exception occured when lams is getting by uid qa question content: " - + e.getMessage(), e); - } + public List getAllQuestionEntries(final Long uid) { + return qaQuestionDAO.getAllQuestionEntries(uid.longValue()); } - public List getAllQuestionEntriesSorted(final long contentUid) throws QaApplicationException { - try { - return qaQuestionDAO.getAllQuestionEntriesSorted(contentUid); - } catch (DataAccessException e) { - throw new QaApplicationException("Exception occured when lams is getting all question entries: " - + e.getMessage(), e); - } + public List getAllQuestionEntriesSorted(final long contentUid) { + return qaQuestionDAO.getAllQuestionEntriesSorted(contentUid); } - public void removeQaQueContent(QaQueContent qaQuestion) throws QaApplicationException { - try { - qaQuestionDAO.removeQaQueContent(qaQuestion); - } catch (DataAccessException e) { - throw new QaApplicationException("Exception occured when lams is removing question content: " - + e.getMessage(), e); - } + public void removeQuestion(QaQueContent question) { + qaQuestionDAO.removeQaQueContent(question); } /** - * checks the paramter content in the user responses table + * checks the paramter content in the user responses table * * @param qa * @return boolean * @throws QaApplicationException */ - public boolean isStudentActivityOccurredGlobal(QaContent qaContent) throws QaApplicationException { + public boolean isStudentActivityOccurredGlobal(QaContent qaContent) { int countResponses = 0; if (qaContent != null) { countResponses = qaUsrRespDAO.getCountResponsesByQaContent(qaContent.getQaContentId()); } return countResponses > 0; } + + @Override + public void recalculateUserAnswers(QaContent content, Set oldQuestions, + List questionDTOs, List deletedQuestions) { + // create list of modified questions + List modifiedQuestions = new ArrayList(); + for (QaQueContent oldQuestion : oldQuestions) { + for (QaQuestionDTO questionDTO : questionDTOs) { + if (oldQuestion.getUid().equals(questionDTO.getUid())) { + + // question is different + if (!oldQuestion.getQuestion().equals(questionDTO.getQuestion())) { + modifiedQuestions.add(questionDTO); + } + } + } + } + + Set sessionList = content.getQaSessions(); + for (QaSession session : sessionList) { + Long toolSessionId = session.getQaSessionId(); + Set sessionUsers = session.getQaQueUsers(); + + for (QaQueUsr user : sessionUsers) { + + // get all finished user results + List userAttempts = qaUsrRespDAO.getResponsesByUserUid(user.getUid()); + Iterator iter = userAttempts.iterator(); + while (iter.hasNext()) { + QaUsrResp resp = iter.next(); + + QaQueContent question = resp.getQaQuestion(); + + boolean isRemoveQuestionResult = false; + + // [+] if the question is modified + for (QaQuestionDTO modifiedQuestion : modifiedQuestions) { + if (question.getUid().equals(modifiedQuestion.getUid())) { + isRemoveQuestionResult = true; + break; + } + } + + // [+] if the question was removed + for (QaQuestionDTO deletedQuestion : deletedQuestions) { + if (question.getUid().equals(deletedQuestion.getUid())) { + isRemoveQuestionResult = true; + break; + } + } + + if (isRemoveQuestionResult) { + iter.remove(); + qaUsrRespDAO.removeUserResponse(resp); + } + + // [+] doing nothing if the new question was added + + } + + } + } + + } + /** - * gets called ONLY when a lesson is being created in monitoring mode. - * Should create the new content(toContent) based on what the author has - * created her content with. In q/a tool's case that is content + question's - * content but not user responses. The deep copy should go only as far as - * default content (or author created content) already goes. - * ToolContentManager CONTRACT + * gets called ONLY when a lesson is being created in monitoring mode. Should create the new content(toContent) + * based on what the author has created her content with. In q/a tool's case that is content + question's content + * but not user responses. The deep copy should go only as far as default content (or author created content) + * already goes. ToolContentManager CONTRACT * - * similar to public void removeToolContent(Long toolContentID) gets called - * by Container+Flash + * similar to public void removeToolContent(Long toolContentID) gets called by Container+Flash * */ - public void copyToolContent(Long fromContentId, Long toContentId) throws ToolException - - { + public void copyToolContent(Long fromContentId, Long toContentId) { long defaultContentId = 0; if (fromContentId == null) { - - try { - defaultContentId = getToolDefaultContentIdBySignature(QaAppConstants.MY_SIGNATURE); - fromContentId = new Long(defaultContentId); - } catch (Exception e) { - QaServicePOJO.logger.error("default content id has not been setup for signature: " - + QaAppConstants.MY_SIGNATURE); - throw new ToolException("WARNING! default content has not been setup for signature" - + QaAppConstants.MY_SIGNATURE + " Can't continue!"); - } + defaultContentId = getToolDefaultContentIdBySignature(QaAppConstants.MY_SIGNATURE); + fromContentId = new Long(defaultContentId); } if (toContentId == null) { QaServicePOJO.logger.error("throwing ToolException: toContentId is null"); throw new ToolException("toContentId is missing"); } - try { - QaContent fromContent = qaDAO.getQaByContentId(fromContentId.longValue()); + QaContent fromContent = qaDAO.getQaByContentId(fromContentId.longValue()); - if (fromContent == null) { - try { - defaultContentId = getToolDefaultContentIdBySignature(QaAppConstants.MY_SIGNATURE); - fromContentId = new Long(defaultContentId); - } catch (Exception e) { - QaServicePOJO.logger.error("default content id has not been setup for signature: " - + QaAppConstants.MY_SIGNATURE); - throw new ToolException("WARNING! default content has not been setup for signature" - + QaAppConstants.MY_SIGNATURE + " Can't continue!"); - } + if (fromContent == null) { + defaultContentId = getToolDefaultContentIdBySignature(QaAppConstants.MY_SIGNATURE); + fromContentId = new Long(defaultContentId); - fromContent = qaDAO.getQaByContentId(fromContentId.longValue()); - } - if (fromContentId.equals(defaultContentId) && fromContent != null && fromContent.getConditions().isEmpty()) { - fromContent.getConditions().add( - getQaOutputFactory().createDefaultComplexUserAnswersCondition(fromContent)); - } - QaContent toContent = QaContent.newInstance(fromContent, toContentId); - if (toContent == null) { - QaServicePOJO.logger.error("throwing ToolException: WARNING!, retrieved toContent is null."); - throw new ToolException("WARNING! Fail to create toContent. Can't continue!"); - } else { - qaDAO.saveQa(toContent); - } - } catch (DataAccessException e) { - QaServicePOJO.logger - .error("throwing ToolException: Exception occured when lams is copying content between content ids."); - throw new ToolException("Exception occured when lams is copying content between content ids."); - } catch (ItemNotFoundException e) { - throw new ToolException("Exception occured when lams is copying content between content ids."); - } catch (RepositoryCheckedException e) { - throw new ToolException("Exception occured when lams is copying content between content ids."); + fromContent = qaDAO.getQaByContentId(fromContentId.longValue()); } + if (fromContentId.equals(defaultContentId) && fromContent != null && fromContent.getConditions().isEmpty()) { + fromContent.getConditions().add(getQaOutputFactory().createDefaultComplexUserAnswersCondition(fromContent)); + } + QaContent toContent = QaContent.newInstance(fromContent, toContentId); + if (toContent == null) { + QaServicePOJO.logger.error("throwing ToolException: WARNING!, retrieved toContent is null."); + throw new ToolException("WARNING! Fail to create toContent. Can't continue!"); + } else { + qaDAO.saveQa(toContent); + } } /** - * removeToolContent(Long toolContentID, boolean removeSessionData) throws - * SessionDataExistsException, ToolException Will need an update on the core - * tool signature: reason : when qaContent is null throw an exception - * + * Will need an update on the core tool signature: reason : when qaContent is null throw an exception */ public void removeToolContent(Long toolContentID, boolean removeSessionData) throws SessionDataExistsException, ToolException { @@ -675,14 +529,14 @@ } } - //removed all existing responses of toolContent with toolContentID + // removed all existing responses of toolContent with toolContentID qaDAO.removeQa(toolContentID); } else { QaServicePOJO.logger.error("Warning!!!, We should have not come here. qaContent is null."); throw new ToolException("toolContentID is missing"); } } - + @SuppressWarnings("unchecked") public void removeLearnerContent(Long toolContentId, Integer userId) throws ToolException { if (logger.isDebugEnabled()) { @@ -704,7 +558,7 @@ } qaQueUsrDAO.deleteQaQueUsr(user); - + NotebookEntry entry = getEntry(session.getQaSessionId(), CoreNotebookConstants.NOTEBOOK_TOOL, QaAppConstants.MY_SIGNATURE, userId); if (entry != null) { @@ -718,28 +572,28 @@ public AverageRatingDTO rateResponse(Long responseId, Long userId, Long toolSessionID, float rating) { QaQueUsr imageGalleryUser = this.getUserByIdAndSession(userId, toolSessionID); ResponseRating responseRating = qaResponseRatingDAO.getRatingByResponseAndUser(responseId, userId); - QaUsrResp response = qaUsrRespDAO.getResponseById(responseId); + QaUsrResp response = qaUsrRespDAO.getResponseById(responseId); - //persist ResponseRating changes in DB + // persist ResponseRating changes in DB if (responseRating == null) { // add responseRating = new ResponseRating(); responseRating.setUser(imageGalleryUser); responseRating.setResponse(response); } responseRating.setRating(rating); qaResponseRatingDAO.saveObject(responseRating); - - //to make available new changes be visible in jsp page + + // to make available new changes be visible in jsp page return qaResponseRatingDAO.getAverageRatingDTOByResponse(responseId); } - + public AverageRatingDTO getAverageRatingDTOByResponse(Long responseId) { return qaResponseRatingDAO.getAverageRatingDTOByResponse(responseId); } - + public List getReflectList(QaContent content, String userID) { - //reflection data for all sessions + // reflection data for all sessions List reflectionDTOs = new LinkedList(); Set sessions = new TreeSet(new QaSessionComparator()); sessions.addAll(content.getQaSessions()); @@ -797,50 +651,51 @@ } } } - + return reflectionDTOs; } - + @Override public void notifyTeachersOnResponseSubmit(Long sessionId) { final String NEW_LINE_CHARACTER = "
"; - + HttpSession ss = SessionManager.getSession(); UserDTO toolUser = (UserDTO) ss.getAttribute(AttributeNames.USER); Long userId = new Long(toolUser.getUserID().longValue()); QaQueUsr user = getUserByIdAndSession(userId, new Long(sessionId)); - + String fullName = user.getFullname(); - String message = NEW_LINE_CHARACTER + NEW_LINE_CHARACTER + messageService.getMessage("label.user.has.answered.questions", new Object[] { fullName }); - + String message = NEW_LINE_CHARACTER + NEW_LINE_CHARACTER + + messageService.getMessage("label.user.has.answered.questions", new Object[] { fullName }); + List responses = qaUsrRespDAO.getResponsesByUserUid(user.getUid()); for (QaUsrResp response : responses) { String question = response.getQaQuestion().getQuestion(); String answer = response.getAnswer(); - + message += NEW_LINE_CHARACTER + NEW_LINE_CHARACTER + question + answer; } - + message += NEW_LINE_CHARACTER + NEW_LINE_CHARACTER; - + eventNotificationService.notifyLessonMonitors(sessionId, message, true); } /** * Export the XML fragment for the tool's content, along with any files needed for the content. * * @throws DataMissingException - * if no tool content matches the toolSessionId + * if no tool content matches the toolSessionId * @throws ToolException - * if any other error occurs + * if any other error occurs */ - public void exportToolContent(Long toolContentID, String rootPath) throws DataMissingException, ToolException { + public void exportToolContent(Long toolContentID, String rootPath) { QaContent toolContentObj = qaDAO.getQaByContentId(toolContentID); if (toolContentObj == null) { long defaultToolContentId = toolService.getToolDefaultContentIdBySignature(QaAppConstants.MY_SIGNATURE); - toolContentObj = getQa(defaultToolContentId); + toolContentObj = getQaContent(defaultToolContentId); if (toolContentObj != null && toolContentObj.getConditions().isEmpty()) { toolContentObj.getConditions().add( getQaOutputFactory().createDefaultComplexUserAnswersCondition(toolContentObj)); @@ -859,25 +714,20 @@ toolContentObj.setQaSessions(null); Set questions = toolContentObj.getQaQueContents(); for (QaQueContent question : questions) { - question.setQaQueUsers(null); question.setQaContent(null); } exportContentService.exportToolContent(toolContentID, toolContentObj, qaToolContentHandler, rootPath); } catch (ExportToolContentException e) { throw new ToolException(e); - } catch (ItemNotFoundException e) { - throw new ToolException(e); - } catch (RepositoryCheckedException e) { - throw new ToolException(e); } } /** * Import the XML fragment for the tool's content, along with any files needed for the content. * * @throws ToolException - * if any other error occurs + * if any other error occurs */ public void importToolContent(Long toolContentID, Integer newUserUid, String toolContentPath, String fromVersion, String toVersion) throws ToolException { @@ -921,7 +771,7 @@ QaContent qaContent = qaDAO.getQaByContentId(toolContentId); if (qaContent == null) { long defaultToolContentId = toolService.getToolDefaultContentIdBySignature(QaAppConstants.MY_SIGNATURE); - qaContent = getQa(defaultToolContentId); + qaContent = getQaContent(defaultToolContentId); if (qaContent != null && qaContent.getConditions().isEmpty()) { qaContent.getConditions().add(getQaOutputFactory().createDefaultComplexUserAnswersCondition(qaContent)); } @@ -932,33 +782,11 @@ public String getToolContentTitle(Long toolContentId) { return qaDAO.getQaByContentId(toolContentId).getTitle(); } - - public boolean isContentEdited(Long toolContentId) { - return qaDAO.getQaByContentId(toolContentId).isDefineLater(); - } - - /** - * it is possible that the tool session id already exists in the tool sessions table as the users from the same - * session are involved. existsSession(long toolSessionId) - * - * @param toolSessionId - * @return boolean - */ - protected boolean existsSession(long toolSessionId) { - QaSession qaSession = getSessionById(toolSessionId); - if (qaSession == null) { - return false; - } - return true; - } - /** - * createToolSession(Long toolSessionId,String toolSessionName, Long toolContentID) throws ToolException * ToolSessionManager CONTRACT : creates a tool session with the incoming toolSessionId in the tool session table * * gets called only in the Learner mode. All the learners in the same group have the same toolSessionId. - * */ public void createToolSession(Long toolSessionId, String toolSessionName, Long toolContentID) throws ToolException { @@ -967,48 +795,17 @@ throw new ToolException("toolSessionId is missing"); } - long defaultContentId = 0; - if (toolContentID == null) { - - try { - defaultContentId = getToolDefaultContentIdBySignature(QaAppConstants.MY_SIGNATURE); - toolContentID = new Long(defaultContentId); - } catch (Exception e) { - QaServicePOJO.logger.error("default content id has not been setup for signature: " - + QaAppConstants.MY_SIGNATURE); - throw new ToolException("WARNING! default content has not been setup for signature" - + QaAppConstants.MY_SIGNATURE + " Can't continue!"); - } - } - QaContent qaContent = qaDAO.getQaByContentId(toolContentID.longValue()); - if (qaContent == null) { - - try { - defaultContentId = getToolDefaultContentIdBySignature(QaAppConstants.MY_SIGNATURE); - toolContentID = new Long(defaultContentId); - } catch (Exception e) { - QaServicePOJO.logger.error("default content id has not been setup for signature: " - + QaAppConstants.MY_SIGNATURE); - throw new ToolException("WARNING! default content has not been setup for signature" - + QaAppConstants.MY_SIGNATURE + " Can't continue!"); - } - - qaContent = qaDAO.getQaByContentId(toolContentID.longValue()); - if (qaContent.getConditions().isEmpty()) { - qaContent.getConditions().add(getQaOutputFactory().createDefaultComplexUserAnswersCondition(qaContent)); - } - } - /* * create a new a new tool session if it does not already exist in the tool session table */ - if (!existsSession(toolSessionId.longValue())) { + QaSession qaSession = getSessionById(toolSessionId); + if (qaSession == null) { try { - QaSession qaSession = new QaSession(toolSessionId, new Date(System.currentTimeMillis()), - QaSession.INCOMPLETE, toolSessionName, qaContent, new TreeSet()); - qaSessionDAO.CreateQaSession(qaSession); + qaSession = new QaSession(toolSessionId, new Date(System.currentTimeMillis()), QaSession.INCOMPLETE, + toolSessionName, qaContent, new TreeSet()); + qaSessionDAO.createSession(qaSession); } catch (Exception e) { QaServicePOJO.logger.error("Error creating new toolsession in the db"); throw new ToolException("Error creating new toolsession in the db: " + e); @@ -1065,7 +862,7 @@ QaSession qaSession = getSessionById(toolSessionId.longValue()); qaSession.setSession_end_date(new Date(System.currentTimeMillis())); qaSession.setSession_status(QaAppConstants.COMPLETED); - updateQaSession(qaSession); + updateSession(qaSession); try { String nextUrl = learnerService.completeToolSession(toolSessionId, learnerId); @@ -1114,12 +911,12 @@ return getQaOutputFactory().getToolOutput(name, this, toolSessionId, learnerId); } - public IToolVO getToolBySignature(String toolSignature) throws QaApplicationException { + public IToolVO getToolBySignature(String toolSignature) { IToolVO tool = toolService.getToolBySignature(toolSignature); return tool; } - public long getToolDefaultContentIdBySignature(String toolSignature) throws QaApplicationException { + public long getToolDefaultContentIdBySignature(String toolSignature) { long contentId = 0; contentId = toolService.getToolDefaultContentIdBySignature(toolSignature); return contentId; @@ -1140,12 +937,12 @@ return list.get(0); } } - + @Override public boolean isGroupedActivity(long toolContentID) { return toolService.isGroupedActivity(toolContentID); } - + @Override public String getLearnerContentFolder(Long toolSessionId, Long userId) { return toolService.getLearnerContentFolder(toolSessionId, userId); @@ -1205,8 +1002,8 @@ public void setQaUsrRespDAO(IQaUsrRespDAO qaUsrRespDAO) { this.qaUsrRespDAO = qaUsrRespDAO; - } - + } + public void setQaResponseRatingDAO(IResponseRatingDAO responseRatingDAO) { this.qaResponseRatingDAO = responseRatingDAO; } @@ -1231,7 +1028,7 @@ public IQaUsrRespDAO getQaUsrRespDAO() { return qaUsrRespDAO; } - + /** * @return Returns the IResponseRatingDAO. */ @@ -1256,7 +1053,7 @@ /** * @param qaToolContentHandler - * The qaToolContentHandler to set. + * The qaToolContentHandler to set. */ public void setQaToolContentHandler(IToolContentHandler qaToolContentHandler) { this.qaToolContentHandler = qaToolContentHandler; @@ -1302,7 +1099,6 @@ toolContentObj.setContent(null); toolContentObj.setReportTitle(null); toolContentObj.setMonitoringReportTitle(null); - toolContentObj.setSynchInMonitor(false); // doesn't appear to be used // in LAMS 2.0 toolContentObj.setLockWhenFinished(true); toolContentObj.setShowOtherAnswers(true); @@ -1345,7 +1141,7 @@ QaContent qaContent = null; if (toolContentId != null) { - qaContent = getQa(toolContentId.longValue()); + qaContent = getQaContent(toolContentId.longValue()); } if (qaContent == null) { throw new DataMissingException("Unable to set reflective data titled " + title @@ -1366,16 +1162,16 @@ /** * @param coreNotebookService - * The coreNotebookService to set. + * The coreNotebookService to set. */ public void setCoreNotebookService(ICoreNotebookService coreNotebookService) { this.coreNotebookService = coreNotebookService; } - + public void setEventNotificationService(IEventNotificationService eventNotificationService) { this.eventNotificationService = eventNotificationService; } - + public void setMessageService(MessageService messageService) { this.messageService = messageService; } @@ -1517,6 +1313,10 @@ public void removeQuestionsFromCache(QaContent qaContent) { qaDAO.removeQuestionsFromCache(qaContent); } + + public void removeQaContentFromCache(QaContent qaContent) { + qaDAO.removeQaContentFromCache(qaContent); + } public Class[] getSupportedToolOutputDefinitionClasses(int definitionType) { return getQaOutputFactory().getSupportedDefinitionClasses(definitionType); Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/util/QaComparator.java =================================================================== diff -u -r629b2631320321b57015e15be850e7c6b747225f -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/util/QaComparator.java (.../QaComparator.java) (revision 629b2631320321b57015e15be850e7c6b747225f) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/util/QaComparator.java (.../QaComparator.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -28,11 +28,10 @@ import java.util.Comparator; /** - * @author Ozgur Demirtas - * * A comparator implementation that can be used as a constructor to collections. * The TreeMap in the web layer makes use of it. * + * @author Ozgur Demirtas */ public class QaComparator implements Comparator, Serializable { Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/util/QaUtils.java =================================================================== diff -u -rc5457cc74f3986b393bc2947604b17168ba54dfb -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/util/QaUtils.java (.../QaUtils.java) (revision c5457cc74f3986b393bc2947604b17168ba54dfb) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/util/QaUtils.java (.../QaUtils.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -23,80 +23,40 @@ /* $$Id$$ */ package org.lamsfoundation.lams.tool.qa.util; -import java.text.DateFormat; -import java.util.Date; - import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpSession; +import org.apache.commons.lang.StringUtils; +import org.lamsfoundation.lams.tool.ToolAccessMode; import org.lamsfoundation.lams.tool.qa.QaAppConstants; import org.lamsfoundation.lams.tool.qa.QaContent; -import org.lamsfoundation.lams.tool.qa.QaSession; import org.lamsfoundation.lams.tool.qa.dto.QaGeneralAuthoringDTO; import org.lamsfoundation.lams.tool.qa.service.IQaService; import org.lamsfoundation.lams.tool.qa.web.form.QaAuthoringForm; -import org.lamsfoundation.lams.usermanagement.dto.UserDTO; -import org.lamsfoundation.lams.web.session.SessionManager; import org.lamsfoundation.lams.web.util.AttributeNames; -import org.lamsfoundation.lams.web.util.SessionMap; /** - * @author Ozgur Demirtas - * * Common utility functions live here. + * + * @author Ozgur Demirtas */ public abstract class QaUtils implements QaAppConstants { - /** - * - * @param request - * @param defaultQaContent - * @param qaAuthoringForm - */ - public static void populateAuthoringDTO(HttpServletRequest request, QaContent defaultQaContent, - QaGeneralAuthoringDTO qaGeneralAuthoringDTO) { - qaGeneralAuthoringDTO.setActivityTitle(defaultQaContent.getTitle()); - qaGeneralAuthoringDTO.setActivityInstructions(defaultQaContent.getInstructions()); - } + public static void setFormProperties(HttpServletRequest request, QaAuthoringForm qaAuthoringForm, + QaGeneralAuthoringDTO qaGeneralAuthoringDTO, String strToolContentID, String httpSessionID) { - public static String replaceNewLines(String text) { - - String newText = ""; - if (text != null) { - newText = text.replaceAll("\n", "
"); - - } - - return newText; - } - - public static void setFormProperties(HttpServletRequest request, IQaService qaService, - QaAuthoringForm qaAuthoringForm, QaGeneralAuthoringDTO qaGeneralAuthoringDTO, String strToolContentID, - String defaultContentIdStr, String activeModule, SessionMap sessionMap, String httpSessionID) { - qaAuthoringForm.setHttpSessionID(httpSessionID); qaGeneralAuthoringDTO.setHttpSessionID(httpSessionID); qaAuthoringForm.setToolContentID(strToolContentID); - if ((defaultContentIdStr != null) && (defaultContentIdStr.length() > 0)) - qaAuthoringForm.setDefaultContentIdStr(new Long(defaultContentIdStr).toString()); - - qaAuthoringForm.setActiveModule(activeModule); - qaGeneralAuthoringDTO.setActiveModule(activeModule); - - String synchInMonitor = request.getParameter(SYNC_IN_MONITOR); - qaAuthoringForm.setSynchInMonitor(synchInMonitor); - qaGeneralAuthoringDTO.setSynchInMonitor(synchInMonitor); - String usernameVisible = request.getParameter(USERNAME_VISIBLE); qaAuthoringForm.setUsernameVisible(usernameVisible); qaGeneralAuthoringDTO.setUsernameVisible(usernameVisible); - + String allowRateAnswers = request.getParameter(ALLOW_RATE_ANSWERS); qaAuthoringForm.setAllowRateAnswers(allowRateAnswers); qaGeneralAuthoringDTO.setAllowRateAnswers(allowRateAnswers); - + String notifyTeachersOnResponseSubmit = request.getParameter(NOTIFY_TEACHERS_ON_RESPONSE_SUBMIT); qaAuthoringForm.setNotifyTeachersOnResponseSubmit(notifyTeachersOnResponseSubmit); @@ -113,96 +73,47 @@ qaGeneralAuthoringDTO.setLockWhenFinished(lockWhenFinished); String reflect = request.getParameter(REFLECT); - + qaAuthoringForm.setReflect(reflect); qaGeneralAuthoringDTO.setReflect(reflect); String reflectionSubject = request.getParameter(REFLECTION_SUBJECT); - + qaAuthoringForm.setReflectionSubject(reflectionSubject); qaGeneralAuthoringDTO.setReflectionSubject(reflectionSubject); - - + ToolAccessMode mode; + String modeStr = request.getParameter(AttributeNames.ATTR_MODE); + if (StringUtils.equalsIgnoreCase(modeStr, ToolAccessMode.TEACHER.toString())) { + mode = ToolAccessMode.TEACHER; + } else { + mode = ToolAccessMode.AUTHOR; + } + request.setAttribute(AttributeNames.ATTR_MODE, mode.toString()); } - public static int getCurrentUserId(HttpServletRequest request) throws QaApplicationException { - HttpSession ss = SessionManager.getSession(); - /* get back login user DTO */ - UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); - return user.getUserID().intValue(); - } - /** - * - * @param long - * toolContentID - * @return boolean determine whether a specific toolContentID exists in the - * db - */ - public static boolean existsContent(long toolContentID, IQaService qaService) { - QaContent qaContent = qaService.getQa(toolContentID); - if (qaContent == null) - return false; - - return true; - } - - /** - * it is expected that the tool session id already exists in the tool - * sessions table existsSession(long toolSessionId) - * - * @param toolSessionId - * @return boolean - */ - public static boolean existsSession(long toolContentID, IQaService qaService) { - QaSession qaSession = qaService.getSessionById(toolContentID); - - - if (qaSession == null) - return false; - - return true; - } - - public static String getFormattedDateString(Date date) { - return (DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(date)); - } - - /** - * the only attributes kept are TOOL_SESSION and TOOL_CONTENT_ID and - * ACTIVITY_TITLE ACTIVITY_INSTRUCTIONS + * the only attributes kept are TOOL_SESSION and TOOL_CONTENT_ID and ACTIVITY_TITLE ACTIVITY_INSTRUCTIONS * cleanUpSessionAbsolute(HttpServletRequest request) * * @param request */ public static void cleanUpSessionAbsolute(HttpServletRequest request) { request.getSession().removeAttribute(MY_SIGNATURE); - request.getSession().removeAttribute(ERROR_QAAPPLICATION); - request.getSession().removeAttribute(TARGET_MODE); - request.getSession().removeAttribute(TARGET_MODE_AUTHORING); - request.getSession().removeAttribute(TARGET_MODE_LEARNING); - request.getSession().removeAttribute(TARGET_MODE_MONITORING); - request.getSession().removeAttribute(TARGET_MODE_EXPORT_PORTFOLIO); request.getSession().removeAttribute(AUTHORING_STARTER); request.getSession().removeAttribute(LOAD_LEARNER); request.getSession().removeAttribute(LEARNING_STARTER); request.getSession().removeAttribute(MONITORING_STARTER); - request.getSession().removeAttribute(LOAD_MONITORING); request.getSession().removeAttribute(EDITABLE_RESPONSE_ID); request.getSession().removeAttribute(COPY_TOOL_CONTENT); - request.getSession().removeAttribute(DEFAULT_CONTENT_ID_STR); request.getSession().removeAttribute(TOOL_SESSION_ID); - request.getSession().removeAttribute(LOAD); request.getSession().removeAttribute(LOAD_QUESTIONS); request.getSession().removeAttribute(LOAD_STARTER); - request.getSession().removeAttribute(IS_DEFINE_LATER); request.getSession().removeAttribute(LEARNING_MODE); request.getSession().removeAttribute(IS_ADD_QUESTION); request.getSession().removeAttribute(IS_REMOVE_QUESTION); request.getSession().removeAttribute(IS_REMOVE_CONTENT); request.getSession().removeAttribute(MAP_QUESTION_CONTENT); - request.getSession().removeAttribute(DEFAULT_QUESTION_CONTENT); request.getSession().removeAttribute(END_LEARNING_MESSSAGE); request.getSession().removeAttribute(ON); request.getSession().removeAttribute(OFF); @@ -259,14 +170,8 @@ request.getSession().removeAttribute(SUBMIT_SUCCESS); request.getSession().removeAttribute(IS_USERNAME_VISIBLE); request.getSession().removeAttribute(CURRENT_ANSWER); - request.getSession().removeAttribute(ACTIVE_MODULE); - request.getSession().removeAttribute(AUTHORING); - request.getSession().removeAttribute(DEFINE_LATER_IN_EDIT_MODE); - request.getSession().removeAttribute(SHOW_AUTHORING_TABS); request.getSession().removeAttribute(DEFINE_LATER); request.getSession().removeAttribute(SOURCE_MC_STARTER); - request.getSession().removeAttribute(LOAD_MONITORING_CONTENT_EDITACTIVITY); - request.getSession().removeAttribute(MONITORING_ORIGINATED_DEFINELATER); request.getSession().removeAttribute(REQUEST_LEARNING_REPORT); request.getSession().removeAttribute(REQUEST_LEARNING_REPORT_VIEWONLY); request.getSession().removeAttribute(REQUEST_PREVIEW); @@ -276,18 +181,14 @@ request.getSession().removeAttribute(USER_EXCEPTION_UNCOMPATIBLE_IDS); request.getSession().removeAttribute(USER_EXCEPTION_NUMBERFORMAT); request.getSession().removeAttribute(USER_EXCEPTION_USER_DOESNOTEXIST); - //request.getSession().removeAttribute(USER_EXCEPTION_CONTENT_DOESNOTEXIST); request.getSession().removeAttribute(USER_EXCEPTION_TOOLSESSION_DOESNOTEXIST); request.getSession().removeAttribute(USER_EXCEPTION_CONTENTID_REQUIRED); request.getSession().removeAttribute(USER_EXCEPTION_TOOLSESSIONID_REQUIRED); - request.getSession().removeAttribute(USER_EXCEPTION_DEFAULTCONTENT_NOT_AVAILABLE); - request.getSession().removeAttribute(USER_EXCEPTION_DEFAULTQUESTIONCONTENT_NOT_AVAILABLE); request.getSession().removeAttribute(USER_EXCEPTION_USERID_NOTAVAILABLE); request.getSession().removeAttribute(USER_EXCEPTION_USERID_NOTNUMERIC); request.getSession().removeAttribute(USER_EXCEPTION_ONLYCONTENT_ANDNOSESSIONS); request.getSession().removeAttribute(USER_EXCEPTION_USERID_EXISTING); request.getSession().removeAttribute(USER_EXCEPTION_MONITORINGTAB_CONTENTID_REQUIRED); - request.getSession().removeAttribute(USER_EXCEPTION_DEFAULTCONTENT_NOTSETUP); request.getSession().removeAttribute(USER_EXCEPTION_NO_TOOL_SESSIONS); request.getSession().removeAttribute(USER_EXCEPTION_NO_STUDENT_ACTIVITY); request.getSession().removeAttribute(USER_EXCEPTION_CONTENT_IN_USE); @@ -305,46 +206,12 @@ public static void setDefineLater(HttpServletRequest request, boolean value, String strToolContentID, IQaService qaService) { - QaContent qaContent = qaService.getQa(new Long(strToolContentID).longValue()); - + QaContent qaContent = qaService.getQaContent(new Long(strToolContentID).longValue()); + if (qaContent != null) { qaContent.setDefineLater(value); - qaService.updateQa(qaContent); + qaService.updateQaContent(qaContent); } } - /** - * determines the struts level location to return - * - * @param sourceMcStarter - * @param requestedModule - * @return - */ - public static String getDestination(String sourceMcStarter, String requestedModule) { - if (requestedModule.equals(DEFINE_LATER)) { - //request is from define Later url. return to LOAD_VIEW_ONLY - return LOAD_VIEW_ONLY; - } else if (requestedModule.equals(AUTHORING)) { - //request is from authoring url. return to LOAD_QUESTIONS - return LOAD_QUESTIONS; - } else { - //request is from an unknown source. return null - return null; - } - } - - public static String getCurrentLearnerID() { - String userID = ""; - HttpSession ss = SessionManager.getSession(); - - - if (ss != null) { - UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); - if ((user != null) && (user.getUserID() != null)) { - userID = user.getUserID().toString(); - } - } - return userID; - } - } Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/AuthoringUtil.java =================================================================== diff -u -rc5457cc74f3986b393bc2947604b17168ba54dfb -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/AuthoringUtil.java (.../AuthoringUtil.java) (revision c5457cc74f3986b393bc2947604b17168ba54dfb) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/AuthoringUtil.java (.../AuthoringUtil.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -28,24 +28,20 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; -import java.util.Map; import java.util.Set; import java.util.SortedSet; -import java.util.TreeMap; import java.util.TreeSet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; -import org.apache.commons.lang.StringUtils; import org.lamsfoundation.lams.learningdesign.TextSearchConditionComparator; import org.lamsfoundation.lams.tool.qa.QaAppConstants; import org.lamsfoundation.lams.tool.qa.QaCondition; import org.lamsfoundation.lams.tool.qa.QaContent; import org.lamsfoundation.lams.tool.qa.QaQueContent; import org.lamsfoundation.lams.tool.qa.dto.QaQuestionDTO; import org.lamsfoundation.lams.tool.qa.service.IQaService; -import org.lamsfoundation.lams.tool.qa.util.QaComparator; import org.lamsfoundation.lams.tool.qa.util.QaQueContentComparator; import org.lamsfoundation.lams.tool.qa.util.QaQuestionContentDTOComparator; import org.lamsfoundation.lams.tool.qa.web.form.QaAuthoringForm; @@ -54,269 +50,167 @@ import org.lamsfoundation.lams.web.util.AttributeNames; /** - * * Keeps all operations needed for Authoring mode. * * @author Ozgur Demirtas - * */ public class AuthoringUtil implements QaAppConstants { - protected static List swapNodes(List listQuestionContentDTO, String questionIndex, String direction, - Set conditions) { + protected static List swapQuestions(List questionDTOs, String questionIndex, + String direction, Set conditions) { int intQuestionIndex = new Integer(questionIndex).intValue(); int intOriginalQuestionIndex = intQuestionIndex; - int replacedNodeIndex = 0; + int replacedQuestionIndex = 0; if (direction.equals("down")) { - //direction down - replacedNodeIndex = ++intQuestionIndex; + // direction down + replacedQuestionIndex = ++intQuestionIndex; } else { - //direction up - replacedNodeIndex = --intQuestionIndex; - + // direction up + replacedQuestionIndex = --intQuestionIndex; } - QaQuestionDTO mainNode = extractNodeAtDisplayOrder(listQuestionContentDTO, intOriginalQuestionIndex); + QaQuestionDTO mainQuestion = getQuestionAtDisplayOrder(questionDTOs, intOriginalQuestionIndex); - QaQuestionDTO replacedNode = extractNodeAtDisplayOrder(listQuestionContentDTO, replacedNodeIndex); + QaQuestionDTO replacedQuestion = getQuestionAtDisplayOrder(questionDTOs, replacedQuestionIndex); - List listFinalQuestionContentDTO = new LinkedList(); + List newQuestionDtos = new LinkedList(); - listFinalQuestionContentDTO = reorderSwappedListQuestionContentDTO(listQuestionContentDTO, - intOriginalQuestionIndex, replacedNodeIndex, mainNode, replacedNode, conditions); + Iterator iter = questionDTOs.iterator(); + while (iter.hasNext()) { + QaQuestionDTO questionDTO = iter.next(); + QaQuestionDTO tempQuestion = null; - return listFinalQuestionContentDTO; - } + if (!questionDTO.getDisplayOrder().equals(new Integer(intOriginalQuestionIndex).toString()) + && !questionDTO.getDisplayOrder().equals(new Integer(replacedQuestionIndex).toString())) { + // normal copy + tempQuestion = questionDTO; - protected static List reorderSwappedListQuestionContentDTO(List listQuestionContentDTO, - int intOriginalQuestionIndex, int replacedNodeIndex, QaQuestionDTO mainNode, - QaQuestionDTO replacedNode, Set conditions) { + } else if (questionDTO.getDisplayOrder().equals(new Integer(intOriginalQuestionIndex).toString())) { + // move type 1 + tempQuestion = replacedQuestion; - List listFinalQuestionContentDTO = new LinkedList(); - - int queIndex = 0; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - QaQuestionDTO qaQuestionDTO = (QaQuestionDTO) listIterator.next(); - queIndex++; - QaQuestionDTO tempNode = null; - - if (!qaQuestionDTO.getDisplayOrder().equals(new Integer(intOriginalQuestionIndex).toString()) - && !qaQuestionDTO.getDisplayOrder().equals(new Integer(replacedNodeIndex).toString())) { - //normal copy - tempNode = new QaQuestionDTO(qaQuestionDTO.getQuestion(), - qaQuestionDTO.getDisplayOrder(), qaQuestionDTO.getFeedback(), qaQuestionDTO.isRequired()); - } else if (qaQuestionDTO.getDisplayOrder().equals(new Integer(intOriginalQuestionIndex).toString())) { - //move type 1 - tempNode = new QaQuestionDTO(replacedNode.getQuestion(), - replacedNode.getDisplayOrder(),replacedNode.getFeedback(), replacedNode.isRequired()); - } else if (qaQuestionDTO.getDisplayOrder().equals(new Integer(replacedNodeIndex).toString())) { - //move type 1 - tempNode = new QaQuestionDTO(mainNode.getQuestion(), - mainNode.getDisplayOrder(), mainNode.getFeedback(), mainNode.isRequired()); + } else if (questionDTO.getDisplayOrder().equals(new Integer(replacedQuestionIndex).toString())) { + // move type 1 + tempQuestion = mainQuestion; } - listFinalQuestionContentDTO.add(tempNode); + newQuestionDtos.add(tempQuestion); } + // references in conditions also need to be changed if (conditions != null) { for (QaCondition condition : conditions) { SortedSet newQuestionDTOSet = new TreeSet( new QaQuestionContentDTOComparator()); - for (QaQuestionDTO dto : (List) listFinalQuestionContentDTO) { + for (QaQuestionDTO dto : (List) newQuestionDtos) { if (condition.temporaryQuestionDTOSet.contains(dto)) { newQuestionDTOSet.add(dto); } } condition.temporaryQuestionDTOSet = newQuestionDTOSet; } } - return listFinalQuestionContentDTO; + + return newQuestionDtos; } - protected static QaQuestionDTO extractNodeAtDisplayOrder(List listQuestionContentDTO, + private static QaQuestionDTO getQuestionAtDisplayOrder(List questionDTOs, int intOriginalQuestionIndex) { - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - QaQuestionDTO qaQuestionDTO = (QaQuestionDTO) listIterator.next(); + Iterator iter = questionDTOs.iterator(); + while (iter.hasNext()) { + QaQuestionDTO qaQuestionDTO = iter.next(); if (new Integer(intOriginalQuestionIndex).toString().equals(qaQuestionDTO.getDisplayOrder())) { return qaQuestionDTO; } } return null; } - - protected static Map reorderQuestionContentMap(Map mapQuestionContent) { - Map mapFinalQuestionContent = new TreeMap(new QaComparator()); - int queIndex = 0; - Iterator itMap = mapQuestionContent.entrySet().iterator(); - while (itMap.hasNext()) { - Map.Entry pairs = (Map.Entry) itMap.next(); - if (pairs.getValue() != null && !pairs.getValue().equals("")) { - ++queIndex; - mapFinalQuestionContent.put(new Integer(queIndex).toString(), pairs.getValue()); + protected static List reorderQuestionDTOs(List questionDTOs) { + List listFinalQuestionDTO = new LinkedList(); - } - } - return mapFinalQuestionContent; - } - - protected static List reorderListQuestionContentDTO(List listQuestionContentDTO, String excludeQuestionIndex) { - - List listFinalQuestionContentDTO = new LinkedList(); - int queIndex = 0; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - QaQuestionDTO qaQuestionDTO = (QaQuestionDTO) listIterator.next(); - - String question = qaQuestionDTO.getQuestion(); + Iterator iter = questionDTOs.iterator(); + while (iter.hasNext()) { + QaQuestionDTO qaQuestionDTO = iter.next(); - String displayOrder = qaQuestionDTO.getDisplayOrder(); - + String question = qaQuestionDTO.getQuestion(); String feedback = qaQuestionDTO.getFeedback(); boolean required = qaQuestionDTO.isRequired(); if (question != null && !question.equals("")) { - if (!displayOrder.equals(excludeQuestionIndex)) { - ++queIndex; - - qaQuestionDTO.setQuestion(question); - qaQuestionDTO.setDisplayOrder(new Integer(queIndex).toString()); - qaQuestionDTO.setFeedback(feedback); - qaQuestionDTO.setRequired(required); - - listFinalQuestionContentDTO.add(qaQuestionDTO); - } - } - } - return listFinalQuestionContentDTO; - } - - protected static List reorderSimpleListQuestionContentDTO(List listQuestionContentDTO) { - List listFinalQuestionContentDTO = new LinkedList(); - - int queIndex = 0; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - QaQuestionDTO qaQuestionDTO = (QaQuestionDTO) listIterator.next(); - - String question = qaQuestionDTO.getQuestion(); - String displayOrder = qaQuestionDTO.getDisplayOrder(); - String feedback = qaQuestionDTO.getFeedback(); - boolean required = qaQuestionDTO.isRequired(); - - if (question != null && !question.equals("")) { ++queIndex; qaQuestionDTO.setQuestion(question); qaQuestionDTO.setDisplayOrder(new Integer(queIndex).toString()); qaQuestionDTO.setFeedback(feedback); qaQuestionDTO.setRequired(required); - listFinalQuestionContentDTO.add(qaQuestionDTO); + listFinalQuestionDTO.add(qaQuestionDTO); } } - return listFinalQuestionContentDTO; + return listFinalQuestionDTO; } - protected static List reorderUpdateListQuestionContentDTO(List listQuestionContentDTO, + protected static List reorderUpdateQuestionDTOs(List questionDTOs, QaQuestionDTO qaQuestionContentDTONew, String editableQuestionIndex) { - List listFinalQuestionContentDTO = new LinkedList(); + List listFinalQuestionDTO = new LinkedList(); int queIndex = 0; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - QaQuestionDTO qaQuestionDTO = (QaQuestionDTO) listIterator.next(); - + Iterator iter = questionDTOs.iterator(); + while (iter.hasNext()) { + QaQuestionDTO qaQuestionDTO = (QaQuestionDTO) iter.next(); + ++queIndex; String question = qaQuestionDTO.getQuestion(); String displayOrder = qaQuestionDTO.getDisplayOrder(); String feedback = qaQuestionDTO.getFeedback(); - boolean required = qaQuestionDTO.isRequired(); - + boolean required = qaQuestionDTO.isRequired(); + if (displayOrder.equals(editableQuestionIndex)) { qaQuestionDTO.setQuestion(qaQuestionContentDTONew.getQuestion()); qaQuestionDTO.setDisplayOrder(qaQuestionContentDTONew.getDisplayOrder()); qaQuestionDTO.setFeedback(qaQuestionContentDTONew.getFeedback()); qaQuestionDTO.setRequired(required); - listFinalQuestionContentDTO.add(qaQuestionDTO); + listFinalQuestionDTO.add(qaQuestionDTO); } else { qaQuestionDTO.setQuestion(question); qaQuestionDTO.setDisplayOrder(displayOrder); qaQuestionDTO.setFeedback(feedback); qaQuestionDTO.setRequired(required); - listFinalQuestionContentDTO.add(qaQuestionDTO); + listFinalQuestionDTO.add(qaQuestionDTO); } } - return listFinalQuestionContentDTO; + return listFinalQuestionDTO; } - /** - * repopulateMap(TreeMap mapQuestionContent, HttpServletRequest request) - * return void repopulates the user entries into the Map - */ - protected void repopulateMap(Map mapQuestionContent, HttpServletRequest request) { - int intQuestionIndex = mapQuestionContent.size(); - - /* - * if there is data in the Map remaining from previous session remove those - */ - mapQuestionContent.clear(); - - for (long i = 0; i < intQuestionIndex; i++) { - String candidateQuestionEntry = request.getParameter("questionContent" + i); - if (i == 0) { - } - if (candidateQuestionEntry != null && candidateQuestionEntry.length() > 0) { - mapQuestionContent.put(new Long(i + 1).toString(), candidateQuestionEntry); - } - } - } - - public QaContent saveOrUpdateQaContent(List listQuestionContentDTO, IQaService qaService, - QaAuthoringForm qaAuthoringForm, HttpServletRequest request, QaContent qaContent, String strToolContentID, + public static QaContent saveOrUpdateQaContent(List questionDTOs, IQaService qaService, + HttpServletRequest request, QaContent qaContent, String strToolContentID, Set conditions) { UserDTO toolUser = (UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER); String richTextTitle = request.getParameter(QaAppConstants.TITLE); String richTextInstructions = request.getParameter(QaAppConstants.INSTRUCTIONS); - - String synchInMonitor = request.getParameter(QaAppConstants.SYNC_IN_MONITOR); - String usernameVisible = request.getParameter(QaAppConstants.USERNAME_VISIBLE); - String allowRateQuestions = request.getParameter(QaAppConstants.ALLOW_RATE_ANSWERS); - String notifyTeachersOnResponseSubmit = request.getParameter(QaAppConstants.NOTIFY_TEACHERS_ON_RESPONSE_SUBMIT); - String showOtherAnswers = request.getParameter("showOtherAnswers"); - String questionsSequenced = request.getParameter(QaAppConstants.QUESTIONS_SEQUENCED); - String lockWhenFinished = request.getParameter("lockWhenFinished"); - String allowRichEditor = request.getParameter("allowRichEditor"); - String useSelectLeaderToolOuput = request.getParameter("useSelectLeaderToolOuput"); - String reflect = request.getParameter(QaAppConstants.REFLECT); - String reflectionSubject = request.getParameter(QaAppConstants.REFLECTION_SUBJECT); - String activeModule = request.getParameter(QaAppConstants.ACTIVE_MODULE); - boolean questionsSequencedBoolean = false; - boolean synchInMonitorBoolean = false; boolean lockWhenFinishedBoolean = false; boolean usernameVisibleBoolean = false; boolean allowRateQuestionsBoolean = false; @@ -330,34 +224,30 @@ questionsSequencedBoolean = true; } - if (synchInMonitor != null && synchInMonitor.equalsIgnoreCase("1")) { - synchInMonitorBoolean = true; - } - if (lockWhenFinished != null && lockWhenFinished.equalsIgnoreCase("1")) { lockWhenFinishedBoolean = true; } if (usernameVisible != null && usernameVisible.equalsIgnoreCase("1")) { usernameVisibleBoolean = true; } - + if (allowRateQuestions != null && allowRateQuestions.equalsIgnoreCase("1")) { allowRateQuestionsBoolean = true; } - + if (notifyTeachersOnResponseSubmit != null && notifyTeachersOnResponseSubmit.equalsIgnoreCase("1")) { notifyTeachersOnResponseSubmitBoolean = true; } if (showOtherAnswers != null && showOtherAnswers.equalsIgnoreCase("1")) { showOtherAnswersBoolean = true; } - + if (allowRichEditor != null && allowRichEditor.equalsIgnoreCase("1")) { allowRichEditorBoolean = true; } - + if (useSelectLeaderToolOuput != null && useSelectLeaderToolOuput.equalsIgnoreCase("1")) { useSelectLeaderToolOuputBoolean = true; } @@ -392,33 +282,26 @@ qaContent.setCreatedBy(userId); /** make sure we are setting the userId from the User object above */ - if (activeModule.equals(QaAppConstants.AUTHORING)) { - qaContent.setUsernameVisible(usernameVisibleBoolean); - qaContent.setAllowRateAnswers(allowRateQuestionsBoolean); - qaContent.setNotifyTeachersOnResponseSubmit(notifyTeachersOnResponseSubmitBoolean); - qaContent.setShowOtherAnswers(showOtherAnswersBoolean); - qaContent.setQuestionsSequenced(questionsSequencedBoolean); - qaContent.setLockWhenFinished(lockWhenFinishedBoolean); - qaContent.setSynchInMonitor(synchInMonitorBoolean); - qaContent.setReflect(reflectBoolean); - qaContent.setReflectionSubject(reflectionSubject); - qaContent.setAllowRichEditor(allowRichEditorBoolean); - qaContent.setUseSelectLeaderToolOuput(useSelectLeaderToolOuputBoolean); + qaContent.setUsernameVisible(usernameVisibleBoolean); + qaContent.setAllowRateAnswers(allowRateQuestionsBoolean); + qaContent.setNotifyTeachersOnResponseSubmit(notifyTeachersOnResponseSubmitBoolean); + qaContent.setShowOtherAnswers(showOtherAnswersBoolean); + qaContent.setQuestionsSequenced(questionsSequencedBoolean); + qaContent.setLockWhenFinished(lockWhenFinishedBoolean); + qaContent.setReflect(reflectBoolean); + qaContent.setReflectionSubject(reflectionSubject); + qaContent.setAllowRichEditor(allowRichEditorBoolean); + qaContent.setUseSelectLeaderToolOuput(useSelectLeaderToolOuputBoolean); - } - qaContent.setConditions(new TreeSet(new TextSearchConditionComparator())); if (newContent) { - qaService.createQa(qaContent); + qaService.createQaContent(qaContent); } else { - qaService.updateQa(qaContent); + qaService.updateQaContent(qaContent); } - qaContent = qaService.getQa(new Long(strToolContentID).longValue()); - qaContent = createQuestionContent(listQuestionContentDTO, qaService, qaContent); + qaContent = qaService.getQaContent(new Long(strToolContentID).longValue()); - qaContent = qaService.getQa(new Long(strToolContentID).longValue()); - for (QaCondition condition : conditions) { condition.setQuestions(new TreeSet(new QaQueContentComparator())); for (QaQuestionDTO dto : condition.temporaryQuestionDTOSet) { @@ -430,163 +313,51 @@ } } qaContent.setConditions(conditions); - qaService.updateQa(qaContent); - return qaContent; - } + qaService.updateQaContent(qaContent); + + //persist questions + int displayOrder = 0; + for (QaQuestionDTO questionDTO : questionDTOs) { - /** - * removes unused question entries from db - * - * @param mapQuestionContent - * @param qaService - * @param qaAuthoringForm - */ - public void removeRedundantQuestions(ListlistQuestionContentDTO, IQaService qaService, QaAuthoringForm qaAuthoringForm, - HttpServletRequest request, String toolContentID) { + String questionText = questionDTO.getQuestion(); - QaContent qaContent = qaService.getQa(new Long(toolContentID).longValue()); - if (qaContent != null) { - List allQuestions = qaService.getAllQuestionEntries(qaContent.getUid()); - - Iterator listIterator = allQuestions.iterator(); - boolean entryUsed = false; - while (listIterator.hasNext()) { - - QaQueContent queContent = (QaQueContent) listIterator.next(); - - //Checking whether to remove question with id queContent.getUid() - entryUsed = false; - for ( QaQuestionDTO questionDTO : listQuestionContentDTO ) { - if (StringUtils.equals(queContent.getQuestion(), questionDTO.getQuestion())) { - entryUsed = true; - break; - } - } - - if (entryUsed == false) { - - QaQueContent removeableQaQueContent = qaService.getQuestionContentByQuestionText(queContent - .getQuestion(), qaContent.getUid()); - if (removeableQaQueContent != null) { - //Removing question with id removeableQaQueContent.getUid() - qaService.removeQaQueContent(removeableQaQueContent); - } - - } + // skip empty questions + if (questionText.isEmpty()) { + continue; } - } - } + ++displayOrder; - /** - * persist the questions in the Map the user has submitted - * - * LDEV-2526 note that questions have already been removed before this method is called, but - * their displayOrder fields haven't been updated yet. Note also that the given - * mapQuestionContent maps question numbers to question strings. - */ - protected QaContent createQuestionContent(List listQuestionContentDTO, IQaService qaService, - QaContent qaContent) { - int displayOrder = 0; - for ( QaQuestionDTO questionContentDTO : listQuestionContentDTO ) { - - // LDEV-2526 Assuming here that removed questions exist in mapQuestionContent, but that the value is empty - // (this whole thing needs a rewrite). If empty, do not attempt to persist it. - // LDEV-2524 Partial rewrite - removed the old question and feedback maps and just use the original list. - // Overriding the displayOrder with a new displayOrder. - String questionText = questionContentDTO.getQuestion(); - if (StringUtils.isNotBlank(questionText)) { - - ++displayOrder; + QaQueContent question = qaService.getQuestionByUid(questionDTO.getUid()); + + // in case question doesn't exist + if (question == null) { + question = new QaQueContent(questionText, displayOrder, questionDTO.getFeedback(), + questionDTO.isRequired(), qaContent); + qaContent.getQaQueContents().add(question); + question.setQaContent(qaContent); - QaQueContent existingQaQueContent = qaService.getQuestionContentByQuestionText(questionText, qaContent.getUid()); - if (existingQaQueContent == null) { - QaQueContent queContent = new QaQueContent(questionText, displayOrder, questionContentDTO.getFeedback(), - questionContentDTO.isRequired(), qaContent, null); - qaContent.getQaQueContents().add(queContent); - queContent.setQaContent(qaContent); + // in case question exists already + } else { - qaService.createQaQue(queContent); - } else { - - existingQaQueContent.setQuestion(questionText); - existingQaQueContent.setFeedback(questionContentDTO.getFeedback()); - existingQaQueContent.setDisplayOrder(displayOrder); - existingQaQueContent.setRequired(questionContentDTO.isRequired()); - qaService.saveOrUpdateQaQueContent(existingQaQueContent); - } + question.setQuestion(questionText); + question.setFeedback(questionDTO.getFeedback()); + question.setDisplayOrder(displayOrder); + question.setRequired(questionDTO.isRequired()); } + + qaService.saveOrUpdateQuestion(question); } - + return qaContent; } - public static boolean checkDuplicateQuestions(List listQuestionContentDTO, String newQuestion) { - for (QaQuestionDTO questionDTO : listQuestionContentDTO ) { - if ( questionDTO.getQuestion() != null && questionDTO.getQuestion().equals(newQuestion) ) { + public static boolean checkDuplicateQuestions(List questionDTOs, String newQuestion) { + for (QaQuestionDTO questionDTO : questionDTOs) { + if (questionDTO.getQuestion() != null && questionDTO.getQuestion().equals(newQuestion)) { return true; } } return false; } - - /** - * sorts the questions by the display order - * - * @param mapQuestionContent - * @param qaService - * @param qaAuthoringForm - * @param qaContent - */ - public void reOrganizeDisplayOrder(IQaService qaService, QaAuthoringForm qaAuthoringForm, - QaContent qaContent) { - if (qaContent != null) { - List sortedQuestions = qaService.getAllQuestionEntriesSorted(qaContent.getUid().longValue()); - - Iterator listIterator = sortedQuestions.iterator(); - int displayOrder = 1; - while (listIterator.hasNext()) { - QaQueContent queContent = (QaQueContent) listIterator.next(); - - QaQueContent existingQaQueContent = qaService.getQuestionContentByQuestionText( - queContent.getQuestion(), qaContent.getUid()); - existingQaQueContent.setDisplayOrder(displayOrder); - qaService.saveOrUpdateQaQueContent(existingQaQueContent); - displayOrder++; - } - } - } - - /** - * checks if any entry is duplicate verifyDuplicatesOptionsMap(Map - * mapQuestions) - * - * @param mapQuestions - * @return - */ - public static boolean verifyDuplicatesOptionsMap(Map mapQuestions) { - Map originalMap = mapQuestions; - Map backupMap = mapQuestions; - - int optionCount = 0; - for (long i = 1; i <= QaAppConstants.MAX_QUESTION_COUNT.longValue(); i++) { - String currentOption = (String) originalMap.get(new Long(i).toString()); - - optionCount = 0; - for (long j = 1; j <= QaAppConstants.MAX_QUESTION_COUNT.longValue(); j++) { - String backedOption = (String) backupMap.get(new Long(j).toString()); - - if (currentOption != null && backedOption != null) { - if (currentOption.equals(backedOption)) { - optionCount++; - } - - if (optionCount > 1) { - return false; - } - } - } - } - return true; - } } \ No newline at end of file Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/ExportServlet.java =================================================================== diff -u -raf2294a9411ee67e92a614ee7e60df3c1c764b6e -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/ExportServlet.java (.../ExportServlet.java) (revision af2294a9411ee67e92a614ee7e60df3c1c764b6e) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/ExportServlet.java (.../ExportServlet.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -136,7 +136,7 @@ throw new QaApplicationException(error); } - QaContent content = qaService.getQa(toolContentID.longValue()); + QaContent content = qaService.getQaContent(toolContentID.longValue()); if (content == null) { String error = "Data is missing from the database. Unable to Continue"; Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/LearningUtil.java =================================================================== diff -u -r7cefcae725bb4e568ae1d61624a75bd6b3f3a8c3 -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/LearningUtil.java (.../LearningUtil.java) (revision 7cefcae725bb4e568ae1d61624a75bd6b3f3a8c3) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/LearningUtil.java (.../LearningUtil.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -96,31 +96,6 @@ return generalLearnerFlowDTO; } - - public static String getRemainingQuestionCount(int currentQuestionIndex, String totalQuestionCount) { - int remainingQuestionCount = new Long(totalQuestionCount).intValue() - currentQuestionIndex + 1; - return new Integer(remainingQuestionCount).toString(); - } - - /** - * feedBackAnswersProgress(HttpServletRequest request, int - * currentQuestionIndex) give user feedback on the remaining questions - * - * @param qaLearningForm - * return void - */ - public static String feedBackAnswersProgress(HttpServletRequest request, int currentQuestionIndex, - String totalQuestionCount) { - int remainingQuestionCount = new Long(totalQuestionCount).intValue() - currentQuestionIndex + 1; - String userFeedback = ""; - if (remainingQuestionCount != 0) { - userFeedback = "Remaining question count: " + remainingQuestionCount; - } else { - userFeedback = "End of the questions."; - } - - return userFeedback; - } /** */ Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/MonitoringUtil.java =================================================================== diff -u -r6ac8c3a8a953aab157cb5075fba73b09da5e4cf8 -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/MonitoringUtil.java (.../MonitoringUtil.java) (revision 6ac8c3a8a953aab157cb5075fba73b09da5e4cf8) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/MonitoringUtil.java (.../MonitoringUtil.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -52,7 +52,6 @@ import org.lamsfoundation.lams.tool.qa.service.IQaService; import org.lamsfoundation.lams.tool.qa.util.QaSessionComparator; import org.lamsfoundation.lams.tool.qa.util.QaStringComparator; -import org.lamsfoundation.lams.tool.qa.util.QaUtils; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.util.DateUtil; import org.lamsfoundation.lams.web.session.SessionManager; @@ -66,16 +65,14 @@ public class MonitoringUtil implements QaAppConstants { /** - * User id is needed if learnerRequest = true, as it is required to work out - * if the data being analysed is the current user (for not show other names) - * or to work out which is the user's answers (for not show all answers). + * User id is needed if learnerRequest = true, as it is required to work out if the data being analysed is the + * current user (for not show other names) or to work out which is the user's answers (for not show all answers). */ public static Map buildGroupsAttemptData(HttpServletRequest request, QaContent qaContent, IQaService qaService, - String questionUid, boolean isUserNamesVisible, boolean isLearnerRequest, String sessionId, - String userId) { + String questionUid, boolean isUserNamesVisible, boolean isLearnerRequest, String sessionId, String userId) { List> listMonitoredAttemptsContainerDTO = new LinkedList>(); - QaSession session = qaService.retrieveQaSession(new Long(sessionId).longValue()); + QaSession session = qaService.getSessionById(new Long(sessionId).longValue()); List listUsers = new LinkedList(); if (!isLearnerRequest) { @@ -97,31 +94,18 @@ listUsers = new ArrayList(); QaQueUsr currentUser = qaService.getUserByIdAndSession(new Long(userId).longValue(), session.getQaSessionId()); - if (currentUser != null){ + if (currentUser != null) { listUsers.add(currentUser); } } } - Map sessionUsersAttempts = populateSessionUsersAttempts(qaService, new Long(sessionId), listUsers, - questionUid, isUserNamesVisible, isLearnerRequest, userId); - listMonitoredAttemptsContainerDTO.add(sessionUsersAttempts); - - return convertToMap(listMonitoredAttemptsContainerDTO); - } - - /** - * Populates all the user's attempt data of a particular tool session. - * User id is needed if isUserNamesVisible is false && is learnerRequest = - * true, as it is required to work out if the data being analysed is the - * current user. - */ - private static Map populateSessionUsersAttempts(IQaService qaService, Long sessionId, - List listUsers, String questionUid, boolean isUserNamesVisible, boolean isLearnerRequest, String userId) { - + /** + * Populates all the user's attempt data of a particular tool session. User id is needed if isUserNamesVisible + * is false && is learnerRequest = true, as it is required to work out if the data being analysed is the current + * user. + */ List qaMonitoredUserDTOs = new LinkedList(); - QaContent qaContent = qaService.getQaContentBySessionId(sessionId); - for (QaQueUsr user : (List) listUsers) { QaUsrResp response = qaService.getResponseByUserAndQuestion(user.getQueUsrId(), new Long(questionUid)); if (response != null) { @@ -142,7 +126,7 @@ qaMonitoredUserDTO.setSessionId(sessionId.toString()); qaMonitoredUserDTO.setResponse(response.getAnswer()); - //String responsePresentable = QaUtils.replaceNewLines(response.getAnswer()); + // String responsePresentable = QaUtils.replaceNewLines(response.getAnswer()); qaMonitoredUserDTO.setResponsePresentable(response.getAnswer()); qaMonitoredUserDTO.setQuestionUid(questionUid); @@ -158,45 +142,39 @@ qaMonitoredUserDTOs.add(qaMonitoredUserDTO); } } - - //convert To McMonitoredUserDTOMap - Map map = new TreeMap(new QaStringComparator()); + + // convert To McMonitoredUserDTOMap + Map sessionUsersAttempts = new TreeMap( + new QaStringComparator()); Long mapIndex = new Long(1); for (QaMonitoredUserDTO data : qaMonitoredUserDTOs) { - map.put(mapIndex.toString(), data); + sessionUsersAttempts.put(mapIndex.toString(), data); mapIndex = mapIndex + 1; } - return map; - } + listMonitoredAttemptsContainerDTO.add(sessionUsersAttempts); - public static Map removeNewLinesMap(Map map) { - Map newMap = new TreeMap(new QaStringComparator()); - - Iterator itMap = map.entrySet().iterator(); - while (itMap.hasNext()) { - Map.Entry pairs = (Map.Entry) itMap.next(); - newMap.put(pairs.getKey(), QaUtils.replaceNewLines(pairs.getValue().toString())); - } - return newMap; - } - - private static Map convertToMap(List list) { + //convertToMap Map map = new TreeMap(new QaStringComparator()); - - Iterator listIterator = list.iterator(); - Long mapIndex = new Long(1); - + Iterator listIterator = listMonitoredAttemptsContainerDTO.iterator(); + Long mapIndex2 = new Long(1); while (listIterator.hasNext()) { Map data = (Map) listIterator.next(); - map.put(mapIndex.toString(), data); - mapIndex = new Long(mapIndex.longValue() + 1); + map.put(mapIndex2.toString(), data); + mapIndex2 = new Long(mapIndex2.longValue() + 1); } return map; } - private static void buildQaStatsDTO(HttpServletRequest request, IQaService qaService, QaContent qaContent) { - QaStatsDTO qaStatsDTO = new QaStatsDTO(); + public static void setUpMonitoring(HttpServletRequest request, IQaService qaService, QaContent qaContent) { + // setting up the advanced summary for LDEV-1662 + request.setAttribute(QaAppConstants.ATTR_CONTENT, qaContent); + + boolean isGroupedActivity = qaService.isGroupedActivity(qaContent.getQaContentId()); + request.setAttribute("isGroupedActivity", isGroupedActivity); + + //buildQaStatsDTO + QaStatsDTO qaStatsDTO = new QaStatsDTO(); int countSessionComplete = 0; int countAllUsers = 0; Iterator iteratorSession = qaContent.getQaSessions().iterator(); @@ -219,27 +197,14 @@ } } } - qaStatsDTO.setCountAllUsers(new Integer(countAllUsers).toString()); qaStatsDTO.setCountSessionComplete(new Integer(countSessionComplete).toString()); - request.setAttribute(QA_STATS_DTO, qaStatsDTO); - } - public static void setUpMonitoring(HttpServletRequest request, IQaService qaService, QaContent qaContent) { - - // setting up the advanced summary for LDEV-1662 - request.setAttribute(QaAppConstants.ATTR_CONTENT, qaContent); - - boolean isGroupedActivity = qaService.isGroupedActivity(qaContent.getQaContentId()); - request.setAttribute("isGroupedActivity", isGroupedActivity); - - buildQaStatsDTO(request, qaService, qaContent); - - //generateGroupsSessionData + // generateGroupsSessionData List listAllGroupsDTO = buildGroupBasedSessionData(request, qaContent, qaService); request.setAttribute(LIST_ALL_GROUPS_DTO, listAllGroupsDTO); - + List reflectionDTOs = qaService.getReflectList(qaContent, null); request.setAttribute(QaAppConstants.REFLECTIONS_CONTAINER_DTO, reflectionDTOs); @@ -253,12 +218,11 @@ request.setAttribute(QaAppConstants.ATTR_SUBMISSION_DEADLINE, tzSubmissionDeadline.getTime()); } } - - public static List buildGroupBasedSessionData(HttpServletRequest request, QaContent qaContent, IQaService qaService) { - List questions = qaService.getAllQuestionEntries(qaContent.getUid()); + public static List buildGroupBasedSessionData(HttpServletRequest request, QaContent qaContent, + IQaService qaService) { + List questions = qaService.getAllQuestionEntries(qaContent.getUid()); List groupDTOs = new LinkedList(); - Set sessions = new TreeSet(new QaSessionComparator()); sessions.addAll(qaContent.getQaSessions()); for (QaSession session : sessions) { @@ -291,7 +255,6 @@ groupDTO.setSessionName(sessionName); groupDTO.setSessionId(sessionId); groupDTOs.add(groupDTO); - } return groupDTOs; } Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaAction.java =================================================================== diff -u -rdfbc0a5728344573bc1bcbf0095e4f2778d3ad8d -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaAction.java (.../QaAction.java) (revision dfbc0a5728344573bc1bcbf0095e4f2778d3ad8d) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaAction.java (.../QaAction.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -30,21 +30,22 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.Set; import java.util.SortedSet; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; -import org.apache.struts.Globals; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; import org.apache.struts.action.ActionMessages; import org.lamsfoundation.lams.authoring.web.AuthoringConstants; -import org.lamsfoundation.lams.tool.exception.ToolException; +import org.lamsfoundation.lams.tool.ToolAccessMode; import org.lamsfoundation.lams.tool.qa.QaAppConstants; import org.lamsfoundation.lams.tool.qa.QaCondition; import org.lamsfoundation.lams.tool.qa.QaConfigItem; @@ -54,7 +55,6 @@ import org.lamsfoundation.lams.tool.qa.dto.QaQuestionDTO; import org.lamsfoundation.lams.tool.qa.service.IQaService; import org.lamsfoundation.lams.tool.qa.service.QaServiceProxy; -import org.lamsfoundation.lams.tool.qa.util.QaToolContentHandler; import org.lamsfoundation.lams.tool.qa.util.QaUtils; import org.lamsfoundation.lams.tool.qa.web.form.QaAuthoringForm; import org.lamsfoundation.lams.util.WebUtil; @@ -66,209 +66,160 @@ * @author Ozgur Demirtas */ public class QaAction extends LamsDispatchAction implements QaAppConstants { - static Logger logger = Logger.getLogger(QaAction.class.getName()); + private static Logger logger = Logger.getLogger(QaAction.class.getName()); - private QaToolContentHandler toolContentHandler; - public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { return mapping.findForward(QaAppConstants.LOAD_QUESTIONS); } /** * submits content into the tool database - * - * @param mapping - * @param form - * @param request - * @param response - * @return - * @throws IOException - * @throws ServletException */ public ActionForward submitAllContent(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - QaAuthoringForm qaAuthoringForm = (QaAuthoringForm) form; - IQaService qaService = QaServiceProxy.getQaService(getServlet().getServletContext()); - String httpSessionID = qaAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - SortedSet conditionSet = (SortedSet) sessionMap - .get(QaAppConstants.ATTR_CONDITION_SET); - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); qaAuthoringForm.setContentFolderID(contentFolderID); - String activeModule = request.getParameter(QaAppConstants.ACTIVE_MODULE); - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = request.getParameter(QaAppConstants.DEFAULT_CONTENT_ID_STR); + List questionDTOs = (List) sessionMap.get(QaAppConstants.LIST_QUESTION_DTOS); - List listQuestionContentDTO = (List) sessionMap.get(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); - ActionMessages errors = new ActionMessages(); - - if (listQuestionContentDTO.size() == 0) { + if (questionDTOs.size() == 0) { ActionMessage error = new ActionMessage("questions.none.submitted"); errors.add(ActionMessages.GLOBAL_MESSAGE, error); } - AuthoringUtil authoringUtil = new AuthoringUtil(); - - QaGeneralAuthoringDTO qaGeneralAuthoringDTO = new QaGeneralAuthoringDTO(); - - qaGeneralAuthoringDTO.setContentFolderID(contentFolderID); - String richTextTitle = request.getParameter(QaAppConstants.TITLE); String richTextInstructions = request.getParameter(QaAppConstants.INSTRUCTIONS); - + QaGeneralAuthoringDTO qaGeneralAuthoringDTO = new QaGeneralAuthoringDTO(); + qaGeneralAuthoringDTO.setContentFolderID(contentFolderID); + qaGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); qaGeneralAuthoringDTO.setActivityTitle(richTextTitle); + qaGeneralAuthoringDTO.setToolContentID(strToolContentID); + qaGeneralAuthoringDTO.setHttpSessionID(httpSessionID); + request.setAttribute(QaAppConstants.QA_GENERAL_AUTHORING_DTO, qaGeneralAuthoringDTO); + qaAuthoringForm.setTitle(richTextTitle); - qaGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - sessionMap.put(QaAppConstants.ACTIVITY_TITLE_KEY, richTextTitle); sessionMap.put(QaAppConstants.ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); - request.setAttribute(QaAppConstants.QA_GENERAL_AUTHORING_DTO, qaGeneralAuthoringDTO); - - - QaContent qaContentTest = qaService.getQa(new Long(strToolContentID).longValue()); - if (!errors.isEmpty()) { saveErrors(request, errors); QaAction.logger.debug("errors saved: " + errors); } - QaContent qaContent = qaContentTest; - + QaContent qaContent = qaService.getQaContent(new Long(strToolContentID).longValue()); if (errors.isEmpty()) { - /* - * to remove deleted entries in the questions table based on mapQuestionContent - */ - authoringUtil.removeRedundantQuestions(listQuestionContentDTO, qaService, qaAuthoringForm, request, - strToolContentID); + ToolAccessMode mode = getAccessMode(request); + request.setAttribute(AttributeNames.ATTR_MODE, mode.toString()); + + List deletedQuestionDTOs = (List) sessionMap.get(LIST_DELETED_QUESTION_DTOS); + + // in case request is from monitoring module - recalculate User Answers + if (mode.isTeacher()) { + Set oldQuestions = qaContent.getQaQueContents(); + qaService.removeQuestionsFromCache(qaContent); + QaUtils.setDefineLater(request, false, strToolContentID, qaService); + + // recalculate User Answers + qaService.recalculateUserAnswers(qaContent, oldQuestions, questionDTOs, deletedQuestionDTOs); + } + + // remove deleted questions + for (QaQuestionDTO deletedQuestionDTO : deletedQuestionDTOs) { + QaQueContent removeableQuestion = qaService.getQuestionByUid(deletedQuestionDTO.getUid()); + if (removeableQuestion != null) { + qaContent.getQaQueContents().remove(removeableQuestion); + qaService.removeQuestion(removeableQuestion); + } + } - qaContent = authoringUtil.saveOrUpdateQaContent(listQuestionContentDTO, qaService, - qaAuthoringForm, request, qaContentTest, strToolContentID, conditionSet); + SortedSet conditionSet = (SortedSet) sessionMap + .get(QaAppConstants.ATTR_CONDITION_SET); - long defaultContentID = 0; - defaultContentID = qaService.getToolDefaultContentIdBySignature(QaAppConstants.MY_SIGNATURE); + // store content + qaContent = AuthoringUtil.saveOrUpdateQaContent(questionDTOs, qaService, request, qaContent, + strToolContentID, conditionSet); - if (qaContent != null) { - qaGeneralAuthoringDTO.setDefaultContentIdStr(new Long(defaultContentID).toString()); + //reOrganizeDisplayOrder + List sortedQuestions = qaService.getAllQuestionEntriesSorted(qaContent.getUid().longValue()); + Iterator iter = sortedQuestions.iterator(); + int displayOrder = 1; + while (iter.hasNext()) { + QaQueContent question = iter.next(); + + QaQueContent existingQaQueContent = qaService.getQuestionByUid(question.getUid()); + existingQaQueContent.setDisplayOrder(displayOrder); + qaService.saveOrUpdateQuestion(existingQaQueContent); + displayOrder++; } - authoringUtil.reOrganizeDisplayOrder(qaService, qaAuthoringForm, qaContent); + QaUtils.setFormProperties(request, qaAuthoringForm, qaGeneralAuthoringDTO, strToolContentID, httpSessionID); - QaUtils.setDefineLater(request, false, strToolContentID, qaService); - QaUtils.setFormProperties(request, qaService, qaAuthoringForm, qaGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); + request.setAttribute(AuthoringConstants.LAMS_AUTHORING_SUCCESS_FLAG, Boolean.TRUE); - if (activeModule.equals(QaAppConstants.AUTHORING)) { - request.setAttribute(AuthoringConstants.LAMS_AUTHORING_SUCCESS_FLAG, Boolean.TRUE); - qaGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - } else { - qaGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(false).toString()); - } - } else { if (qaContent != null) { - long defaultContentID = 0; - defaultContentID = qaService.getToolDefaultContentIdBySignature(QaAppConstants.MY_SIGNATURE); - - if (qaContent != null) { - qaGeneralAuthoringDTO.setDefaultContentIdStr(new Long(defaultContentID).toString()); - } - - QaUtils.setFormProperties(request, qaService, qaAuthoringForm, qaGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - + QaUtils.setFormProperties(request, qaAuthoringForm, qaGeneralAuthoringDTO, strToolContentID, httpSessionID); } } - List delConditionList = getDeletedQaConditionList(sessionMap); - Iterator iter = delConditionList.iterator(); + List delConditionList = getDeletedQaConditionList(sessionMap); + Iterator iter = delConditionList.iterator(); while (iter.hasNext()) { - QaCondition condition = (QaCondition) iter.next(); + QaCondition condition = iter.next(); iter.remove(); qaService.deleteCondition(condition); } - qaGeneralAuthoringDTO.setSbmtSuccess(new Integer(1).toString()); - qaAuthoringForm.resetUserAction(); - - request.setAttribute(QaAppConstants.QA_GENERAL_AUTHORING_DTO, qaGeneralAuthoringDTO); - - request.setAttribute(QaAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - sessionMap.put(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - request.getSession().setAttribute(httpSessionID, sessionMap); - - request.setAttribute(QaAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - - qaGeneralAuthoringDTO.setToolContentID(strToolContentID); - qaGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - qaGeneralAuthoringDTO.setActiveModule(activeModule); - qaGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - qaAuthoringForm.setToolContentID(strToolContentID); qaAuthoringForm.setHttpSessionID(httpSessionID); - qaAuthoringForm.setActiveModule(activeModule); - qaAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); qaAuthoringForm.setCurrentTab("1"); + request.setAttribute(QaAppConstants.LIST_QUESTION_DTOS, questionDTOs); + request.getSession().setAttribute(httpSessionID, sessionMap); + request.setAttribute(QaAppConstants.TOTAL_QUESTION_COUNT, new Integer(questionDTOs.size())); + sessionMap.put(QaAppConstants.LIST_QUESTION_DTOS, questionDTOs); + return mapping.findForward(QaAppConstants.LOAD_QUESTIONS); } /** * saveSingleQuestion - * - * @param mapping - * @param form - * @param request - * @param response - * @return - * @throws IOException - * @throws ServletException */ public ActionForward saveSingleQuestion(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { QaAuthoringForm qaAuthoringForm = (QaAuthoringForm) form; - IQaService qaService = QaServiceProxy.getQaService(getServlet().getServletContext()); - String httpSessionID = qaAuthoringForm.getHttpSessionID(); SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); qaAuthoringForm.setContentFolderID(contentFolderID); - String activeModule = request.getParameter(QaAppConstants.ACTIVE_MODULE); - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = request.getParameter(QaAppConstants.DEFAULT_CONTENT_ID_STR); - String editQuestionBoxRequest = request.getParameter("editQuestionBoxRequest"); QaGeneralAuthoringDTO qaGeneralAuthoringDTO = new QaGeneralAuthoringDTO(); qaGeneralAuthoringDTO.setContentFolderID(contentFolderID); - qaGeneralAuthoringDTO.setSbmtSuccess(new Integer(0).toString()); + List questionDTOs = (List) sessionMap.get(QaAppConstants.LIST_QUESTION_DTOS); - List listQuestionContentDTO = (List) sessionMap.get(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); - String newQuestion = request.getParameter("newQuestion"); String feedback = request.getParameter("feedback"); @@ -284,17 +235,15 @@ if (newQuestion != null && newQuestion.length() > 0) { if (editQuestionBoxRequest != null && editQuestionBoxRequest.equals("false")) { //request for add and save - boolean duplicates = AuthoringUtil.checkDuplicateQuestions(listQuestionContentDTO, newQuestion); + boolean duplicates = AuthoringUtil.checkDuplicateQuestions(questionDTOs, newQuestion); if (!duplicates) { QaQuestionDTO qaQuestionDTO = null; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - qaQuestionDTO = (QaQuestionDTO) listIterator.next(); + Iterator iter = questionDTOs.iterator(); + while (iter.hasNext()) { + qaQuestionDTO = iter.next(); String displayOrder = qaQuestionDTO.getDisplayOrder(); - - if (displayOrder != null && !displayOrder.equals("")) { if (displayOrder.equals(editableQuestionIndex)) { break; @@ -308,17 +257,17 @@ qaQuestionDTO.setDisplayOrder(editableQuestionIndex); qaQuestionDTO.setRequired(requiredBoolean); - listQuestionContentDTO = AuthoringUtil.reorderUpdateListQuestionContentDTO(listQuestionContentDTO, + questionDTOs = AuthoringUtil.reorderUpdateQuestionDTOs(questionDTOs, qaQuestionDTO, editableQuestionIndex); } else { //duplicate question entry, not adding } } else { //request for edit and save QaQuestionDTO qaQuestionDTO = null; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - qaQuestionDTO = (QaQuestionDTO) listIterator.next(); + Iterator iter = questionDTOs.iterator(); + while (iter.hasNext()) { + qaQuestionDTO = iter.next(); String displayOrder = qaQuestionDTO.getDisplayOrder(); @@ -335,15 +284,15 @@ qaQuestionDTO.setDisplayOrder(editableQuestionIndex); qaQuestionDTO.setRequired(requiredBoolean); - listQuestionContentDTO = AuthoringUtil.reorderUpdateListQuestionContentDTO(listQuestionContentDTO, + questionDTOs = AuthoringUtil.reorderUpdateQuestionDTOs(questionDTOs, qaQuestionDTO, editableQuestionIndex); } } else { //entry blank, not adding } - request.setAttribute(QaAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - sessionMap.put(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); + request.setAttribute(QaAppConstants.LIST_QUESTION_DTOS, questionDTOs); + sessionMap.put(QaAppConstants.LIST_QUESTION_DTOS, questionDTOs); String richTextTitle = request.getParameter(QaAppConstants.TITLE); String richTextInstructions = request.getParameter(QaAppConstants.INSTRUCTIONS); @@ -360,67 +309,44 @@ request.getSession().setAttribute(httpSessionID, sessionMap); - QaUtils.setFormProperties(request, qaService, qaAuthoringForm, qaGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); + QaUtils.setFormProperties(request, qaAuthoringForm, qaGeneralAuthoringDTO, strToolContentID, httpSessionID); qaGeneralAuthoringDTO.setToolContentID(strToolContentID); qaGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - qaGeneralAuthoringDTO.setActiveModule(activeModule); - qaGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); qaAuthoringForm.setToolContentID(strToolContentID); qaAuthoringForm.setHttpSessionID(httpSessionID); - qaAuthoringForm.setActiveModule(activeModule); - qaAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); qaAuthoringForm.setCurrentTab("1"); - qaGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - request.setAttribute(QaAppConstants.QA_GENERAL_AUTHORING_DTO, qaGeneralAuthoringDTO); request.getSession().setAttribute(httpSessionID, sessionMap); - request.setAttribute(QaAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); + request.setAttribute(QaAppConstants.TOTAL_QUESTION_COUNT, new Integer(questionDTOs.size())); return mapping.findForward(QaAppConstants.LOAD_QUESTIONS); } /** * addSingleQuestion - * - * @param mapping - * @param form - * @param request - * @param response - * @return - * @throws IOException - * @throws ServletException */ public ActionForward addSingleQuestion(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { QaAuthoringForm qaAuthoringForm = (QaAuthoringForm) form; - IQaService qaService = QaServiceProxy.getQaService(getServlet().getServletContext()); - String httpSessionID = qaAuthoringForm.getHttpSessionID(); SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); qaAuthoringForm.setContentFolderID(contentFolderID); - String activeModule = request.getParameter(QaAppConstants.ACTIVE_MODULE); - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = request.getParameter(QaAppConstants.DEFAULT_CONTENT_ID_STR); - QaGeneralAuthoringDTO qaGeneralAuthoringDTO = new QaGeneralAuthoringDTO(); qaGeneralAuthoringDTO.setContentFolderID(contentFolderID); - qaGeneralAuthoringDTO.setSbmtSuccess(new Integer(0).toString()); + List questionDTOs = (List) sessionMap.get(QaAppConstants.LIST_QUESTION_DTOS); - List listQuestionContentDTO = (List) sessionMap.get(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); - String newQuestion = request.getParameter("newQuestion"); String feedback = request.getParameter("feedback"); String required = request.getParameter("required"); @@ -429,24 +355,24 @@ requiredBoolean = true; } - int listSize = listQuestionContentDTO.size(); + int listSize = questionDTOs.size(); if (newQuestion != null && newQuestion.length() > 0) { - boolean duplicates = AuthoringUtil.checkDuplicateQuestions(listQuestionContentDTO, newQuestion); + boolean duplicates = AuthoringUtil.checkDuplicateQuestions(questionDTOs, newQuestion); if (!duplicates) { QaQuestionDTO qaQuestionDTO = new QaQuestionDTO(newQuestion, new Long(listSize + 1).toString(), feedback, requiredBoolean); - listQuestionContentDTO.add(qaQuestionDTO); + questionDTOs.add(qaQuestionDTO); } else { //entry duplicate, not adding } } else { //entry blank, not adding } - request.setAttribute(QaAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - sessionMap.put(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); + request.setAttribute(QaAppConstants.LIST_QUESTION_DTOS, questionDTOs); + sessionMap.put(QaAppConstants.LIST_QUESTION_DTOS, questionDTOs); String richTextTitle = request.getParameter(QaAppConstants.TITLE); String richTextInstructions = request.getParameter(QaAppConstants.INSTRUCTIONS); @@ -462,39 +388,23 @@ qaGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); request.getSession().setAttribute(httpSessionID, sessionMap); - QaUtils.setFormProperties(request, qaService, qaAuthoringForm, qaGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); + QaUtils.setFormProperties(request, qaAuthoringForm, qaGeneralAuthoringDTO, strToolContentID, httpSessionID); qaGeneralAuthoringDTO.setToolContentID(strToolContentID); qaGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - qaGeneralAuthoringDTO.setActiveModule(activeModule); - qaGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); qaAuthoringForm.setToolContentID(strToolContentID); qaAuthoringForm.setHttpSessionID(httpSessionID); - qaAuthoringForm.setActiveModule(activeModule); - qaAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); qaAuthoringForm.setCurrentTab("1"); - qaGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - request.setAttribute(QaAppConstants.QA_GENERAL_AUTHORING_DTO, qaGeneralAuthoringDTO); request.getSession().setAttribute(httpSessionID, sessionMap); - request.setAttribute(QaAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); + request.setAttribute(QaAppConstants.TOTAL_QUESTION_COUNT, new Integer(questionDTOs.size())); return mapping.findForward(QaAppConstants.LOAD_QUESTIONS); } /** * opens up an new screen within the current page for adding a new question - * newQuestionBox - * - * @param mapping - * @param form - * @param request - * @param response - * @return - * @throws IOException - * @throws ServletException */ public ActionForward newQuestionBox(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { @@ -510,12 +420,8 @@ qaAuthoringForm.setContentFolderID(contentFolderID); - String activeModule = request.getParameter(QaAppConstants.ACTIVE_MODULE); - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = request.getParameter(QaAppConstants.DEFAULT_CONTENT_ID_STR); - QaGeneralAuthoringDTO qaGeneralAuthoringDTO = new QaGeneralAuthoringDTO(); qaGeneralAuthoringDTO.setContentFolderID(contentFolderID); @@ -530,16 +436,13 @@ qaGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - QaUtils.setFormProperties(request, qaService, qaAuthoringForm, qaGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); + QaUtils.setFormProperties(request, qaAuthoringForm, qaGeneralAuthoringDTO, strToolContentID, httpSessionID); - qaGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - request.setAttribute(QaAppConstants.QA_GENERAL_AUTHORING_DTO, qaGeneralAuthoringDTO); - Collection listQuestionContentDTO = (Collection) sessionMap.get(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); + Collection questionDTOs = (Collection) sessionMap.get(QaAppConstants.LIST_QUESTION_DTOS); - request.setAttribute(QaAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); + request.setAttribute(QaAppConstants.TOTAL_QUESTION_COUNT, new Integer(questionDTOs.size())); // Adding in the qa wizard data if it is turned on if (qaService.getConfigItem(QaConfigItem.KEY_ENABLE_QAWIZARD) != null @@ -553,21 +456,11 @@ /** * opens up an new screen within the current page for editing a question - * newEditableQuestionBox - * - * @param mapping - * @param form - * @param request - * @param response - * @return - * @throws ServletException */ public ActionForward newEditableQuestionBox(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { QaAuthoringForm qaAuthoringForm = (QaAuthoringForm) form; - IQaService qaService = QaServiceProxy.getQaService(getServlet().getServletContext()); - String httpSessionID = qaAuthoringForm.getHttpSessionID(); SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); @@ -576,15 +469,14 @@ qaAuthoringForm.setEditableQuestionIndex(questionIndex); - List listQuestionContentDTO = (List) sessionMap.get(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); + List questionDTOs = (List) sessionMap.get(QaAppConstants.LIST_QUESTION_DTOS); String editableQuestion = ""; String editableFeedback = ""; boolean requiredBoolean = false; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - QaQuestionDTO qaQuestionDTO = (QaQuestionDTO) listIterator.next(); - String question = qaQuestionDTO.getQuestion(); + Iterator iter = questionDTOs.iterator(); + while (iter.hasNext()) { + QaQuestionDTO qaQuestionDTO = (QaQuestionDTO) iter.next(); String displayOrder = qaQuestionDTO.getDisplayOrder(); if (displayOrder != null && !displayOrder.equals("")) { @@ -601,14 +493,8 @@ String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); qaAuthoringForm.setContentFolderID(contentFolderID); - String activeModule = request.getParameter(QaAppConstants.ACTIVE_MODULE); - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = request.getParameter(QaAppConstants.DEFAULT_CONTENT_ID_STR); - - QaContent qaContent = qaService.getQa(new Long(strToolContentID).longValue()); - QaGeneralAuthoringDTO qaGeneralAuthoringDTO = new QaGeneralAuthoringDTO(); qaGeneralAuthoringDTO.setContentFolderID(contentFolderID); @@ -621,76 +507,65 @@ qaGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - QaUtils.setFormProperties(request, qaService, qaAuthoringForm, qaGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); + QaUtils.setFormProperties(request, qaAuthoringForm, qaGeneralAuthoringDTO, strToolContentID, httpSessionID); qaGeneralAuthoringDTO.setEditableQuestionText(editableQuestion); qaGeneralAuthoringDTO.setEditableQuestionFeedback(editableFeedback); qaAuthoringForm.setRequired(requiredBoolean); qaAuthoringForm.setFeedback(editableFeedback); - qaGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - request.setAttribute(QaAppConstants.QA_GENERAL_AUTHORING_DTO, qaGeneralAuthoringDTO); - request.setAttribute(QaAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); + request.setAttribute(QaAppConstants.TOTAL_QUESTION_COUNT, new Integer(questionDTOs.size())); return mapping.findForward("editQuestionBox"); } /** - * removes a question from the questions map ActionForward - * removeQuestion(ActionMapping mapping, ActionForm form, HttpServletRequest - * request, HttpServletResponse response) throws IOException, - * ServletException - * - * @param mapping - * @param form - * @param request - * @param response - * @return - * @throws IOException - * @throws ServletException + * removes a question from the questions map */ public ActionForward removeQuestion(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { QaAuthoringForm qaAuthoringForm = (QaAuthoringForm) form; - IQaService qaService = QaServiceProxy.getQaService(getServlet().getServletContext()); - String httpSessionID = qaAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - String questionIndex = request.getParameter("questionIndex"); + String questionIndexToDelete = request.getParameter("questionIndex"); + QaQuestionDTO questionToDelete = null; + List questionDTOs = (List) sessionMap.get(QaAppConstants.LIST_QUESTION_DTOS); + + List listFinalQuestionDTO = new LinkedList(); + int queIndex = 0; + for (QaQuestionDTO questionDTO : questionDTOs) { - List listQuestionContentDTO = (List) sessionMap.get(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); + String questionText = questionDTO.getQuestion(); + String displayOrder = questionDTO.getDisplayOrder(); - QaQuestionDTO qaQuestionDTO = null; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - qaQuestionDTO = (QaQuestionDTO) listIterator.next(); - - String displayOrder = qaQuestionDTO.getDisplayOrder(); - - if (displayOrder != null && !displayOrder.equals("")) { - if (displayOrder.equals(questionIndex)) { - break; - } - + if (questionText != null && !questionText.equals("") && (!displayOrder.equals(questionIndexToDelete))) { + + ++queIndex; + questionDTO.setDisplayOrder(new Integer(queIndex).toString()); + listFinalQuestionDTO.add(questionDTO); } + if ((questionText != null) && (!questionText.isEmpty()) && displayOrder.equals(questionIndexToDelete)) { + List deletedQuestionDTOs = (List) sessionMap.get(LIST_DELETED_QUESTION_DTOS);; + deletedQuestionDTOs.add(questionDTO); + sessionMap.put(LIST_DELETED_QUESTION_DTOS, deletedQuestionDTOs); + questionToDelete = questionDTO; + } } + request.setAttribute(QaAppConstants.LIST_QUESTION_DTOS, listFinalQuestionDTO); + sessionMap.put(QaAppConstants.LIST_QUESTION_DTOS, listFinalQuestionDTO); + request.setAttribute(QaAppConstants.TOTAL_QUESTION_COUNT, new Integer(listFinalQuestionDTO.size())); - qaQuestionDTO.setQuestion(""); - - SortedSet list = (SortedSet) sessionMap.get(QaAppConstants.ATTR_CONDITION_SET); - Iterator conditionIter = list.iterator(); - + SortedSet conditions = (SortedSet) sessionMap.get(QaAppConstants.ATTR_CONDITION_SET); + Iterator conditionIter = conditions.iterator(); while (conditionIter.hasNext()) { QaCondition condition = conditionIter.next(); Iterator dtoIter = condition.temporaryQuestionDTOSet.iterator(); while (dtoIter.hasNext()) { - if (dtoIter.next() == qaQuestionDTO) { + if (dtoIter.next() == questionToDelete) { dtoIter.remove(); } } @@ -699,106 +574,57 @@ } } - - listQuestionContentDTO = AuthoringUtil.reorderListQuestionContentDTO(listQuestionContentDTO, questionIndex); - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - qaAuthoringForm.setContentFolderID(contentFolderID); - - String activeModule = request.getParameter(QaAppConstants.ACTIVE_MODULE); - String richTextTitle = request.getParameter(QaAppConstants.TITLE); - String richTextInstructions = request.getParameter(QaAppConstants.INSTRUCTIONS); - sessionMap.put(QaAppConstants.ACTIVITY_TITLE_KEY, richTextTitle); sessionMap.put(QaAppConstants.ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - - String defaultContentIdStr = request.getParameter(QaAppConstants.DEFAULT_CONTENT_ID_STR); - - QaContent qaContent = qaService.getQa(new Long(strToolContentID).longValue()); - - if (qaContent == null) { - qaContent = qaService.getQa(new Long(defaultContentIdStr).longValue()); - } - QaGeneralAuthoringDTO qaGeneralAuthoringDTO = new QaGeneralAuthoringDTO(); qaGeneralAuthoringDTO.setContentFolderID(contentFolderID); - qaGeneralAuthoringDTO.setActivityTitle(richTextTitle); qaAuthoringForm.setTitle(richTextTitle); - qaGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - qaGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - request.getSession().setAttribute(httpSessionID, sessionMap); - - QaUtils.setFormProperties(request, qaService, qaAuthoringForm, qaGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - + QaUtils.setFormProperties(request, qaAuthoringForm, qaGeneralAuthoringDTO, strToolContentID, httpSessionID); qaGeneralAuthoringDTO.setToolContentID(strToolContentID); qaGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - qaGeneralAuthoringDTO.setActiveModule(activeModule); - qaGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); qaAuthoringForm.setToolContentID(strToolContentID); qaAuthoringForm.setHttpSessionID(httpSessionID); - qaAuthoringForm.setActiveModule(activeModule); - qaAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); qaAuthoringForm.setCurrentTab("1"); - - request.setAttribute(QaAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - sessionMap.put(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - - qaGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - request.setAttribute(QaAppConstants.QA_GENERAL_AUTHORING_DTO, qaGeneralAuthoringDTO); - request.setAttribute(QaAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); + return mapping.findForward(QaAppConstants.LOAD_QUESTIONS); } /** - * moves a question down in the list moveQuestionDown - * - * @param mapping - * @param form - * @param request - * @param response - * @return - * @throws IOException - * @throws ServletException + * moves a question down in the list */ public ActionForward moveQuestionDown(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { QaAuthoringForm qaAuthoringForm = (QaAuthoringForm) form; - IQaService qaService = QaServiceProxy.getQaService(getServlet().getServletContext()); - String httpSessionID = qaAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); String questionIndex = request.getParameter("questionIndex"); - List listQuestionContentDTO = (List) sessionMap.get(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); + List questionDTOs = (List) sessionMap.get(QaAppConstants.LIST_QUESTION_DTOS); SortedSet conditionSet = (SortedSet) sessionMap .get(QaAppConstants.ATTR_CONDITION_SET); - listQuestionContentDTO = AuthoringUtil.swapNodes(listQuestionContentDTO, questionIndex, "down", conditionSet); + questionDTOs = AuthoringUtil.swapQuestions(questionDTOs, questionIndex, "down", conditionSet); - listQuestionContentDTO = AuthoringUtil.reorderSimpleListQuestionContentDTO(listQuestionContentDTO); + questionDTOs = AuthoringUtil.reorderQuestionDTOs(questionDTOs); - sessionMap.put(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); + sessionMap.put(QaAppConstants.LIST_QUESTION_DTOS, questionDTOs); String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); qaAuthoringForm.setContentFolderID(contentFolderID); - String activeModule = request.getParameter(QaAppConstants.ACTIVE_MODULE); - String richTextTitle = request.getParameter(QaAppConstants.TITLE); String richTextInstructions = request.getParameter(QaAppConstants.INSTRUCTIONS); @@ -808,8 +634,6 @@ String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = request.getParameter(QaAppConstants.DEFAULT_CONTENT_ID_STR); - QaGeneralAuthoringDTO qaGeneralAuthoringDTO = new QaGeneralAuthoringDTO(); qaGeneralAuthoringDTO.setContentFolderID(contentFolderID); @@ -822,67 +646,48 @@ request.getSession().setAttribute(httpSessionID, sessionMap); - QaUtils.setFormProperties(request, qaService, qaAuthoringForm, qaGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); + QaUtils.setFormProperties(request, qaAuthoringForm, qaGeneralAuthoringDTO, strToolContentID, httpSessionID); qaGeneralAuthoringDTO.setToolContentID(strToolContentID); qaGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - qaGeneralAuthoringDTO.setActiveModule(activeModule); - qaGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); qaAuthoringForm.setToolContentID(strToolContentID); qaAuthoringForm.setHttpSessionID(httpSessionID); - qaAuthoringForm.setActiveModule(activeModule); - qaAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); qaAuthoringForm.setCurrentTab("1"); - request.setAttribute(QaAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); + request.setAttribute(QaAppConstants.LIST_QUESTION_DTOS, questionDTOs); - qaGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - request.setAttribute(QaAppConstants.QA_GENERAL_AUTHORING_DTO, qaGeneralAuthoringDTO); - request.setAttribute(QaAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); + request.setAttribute(QaAppConstants.TOTAL_QUESTION_COUNT, new Integer(questionDTOs.size())); return mapping.findForward(QaAppConstants.LOAD_QUESTIONS); } /** - * moves a question up in the list moveQuestionUp - * - * @param mapping - * @param form - * @param request - * @param response - * @return - * @throws IOException - * @throws ServletException + * moves a question up in the list */ public ActionForward moveQuestionUp(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { QaAuthoringForm qaAuthoringForm = (QaAuthoringForm) form; - IQaService qaService = QaServiceProxy.getQaService(getServlet().getServletContext()); - String httpSessionID = qaAuthoringForm.getHttpSessionID(); SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); String questionIndex = request.getParameter("questionIndex"); - List listQuestionContentDTO = (List) sessionMap.get(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); + List questionDTOs = (List) sessionMap.get(QaAppConstants.LIST_QUESTION_DTOS); SortedSet conditionSet = (SortedSet) sessionMap .get(QaAppConstants.ATTR_CONDITION_SET); - listQuestionContentDTO = AuthoringUtil.swapNodes(listQuestionContentDTO, questionIndex, "up", conditionSet); + questionDTOs = AuthoringUtil.swapQuestions(questionDTOs, questionIndex, "up", conditionSet); - listQuestionContentDTO = AuthoringUtil.reorderSimpleListQuestionContentDTO(listQuestionContentDTO); + questionDTOs = AuthoringUtil.reorderQuestionDTOs(questionDTOs); - sessionMap.put(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); + sessionMap.put(QaAppConstants.LIST_QUESTION_DTOS, questionDTOs); String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); qaAuthoringForm.setContentFolderID(contentFolderID); - String activeModule = request.getParameter(QaAppConstants.ACTIVE_MODULE); - String richTextTitle = request.getParameter(QaAppConstants.TITLE); String richTextInstructions = request.getParameter(QaAppConstants.INSTRUCTIONS); @@ -892,8 +697,6 @@ String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = request.getParameter(QaAppConstants.DEFAULT_CONTENT_ID_STR); - QaGeneralAuthoringDTO qaGeneralAuthoringDTO = new QaGeneralAuthoringDTO(); qaGeneralAuthoringDTO.setContentFolderID(contentFolderID); @@ -907,163 +710,51 @@ request.getSession().setAttribute(httpSessionID, sessionMap); - QaUtils.setFormProperties(request, qaService, qaAuthoringForm, qaGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); + QaUtils.setFormProperties(request, qaAuthoringForm, qaGeneralAuthoringDTO, strToolContentID, httpSessionID); qaGeneralAuthoringDTO.setToolContentID(strToolContentID); qaGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - qaGeneralAuthoringDTO.setActiveModule(activeModule); - qaGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); qaAuthoringForm.setToolContentID(strToolContentID); qaAuthoringForm.setHttpSessionID(httpSessionID); - qaAuthoringForm.setActiveModule(activeModule); - qaAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); qaAuthoringForm.setCurrentTab("1"); - request.setAttribute(QaAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); + request.setAttribute(QaAppConstants.LIST_QUESTION_DTOS, questionDTOs); - qaGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - request.setAttribute(QaAppConstants.QA_GENERAL_AUTHORING_DTO, qaGeneralAuthoringDTO); - request.setAttribute(QaAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); + request.setAttribute(QaAppConstants.TOTAL_QUESTION_COUNT, new Integer(questionDTOs.size())); return mapping.findForward(QaAppConstants.LOAD_QUESTIONS); } - /** - * persists error messages to request scope + * Get the deleted condition list, which could be persisted or non-persisted + * items. * - * * @param request - * @param message - */ - public void persistError(HttpServletRequest request, String message) { - ActionMessages errors = new ActionMessages(); - errors.add(Globals.ERROR_KEY, new ActionMessage(message)); - saveErrors(request, errors); - } - - public ActionForward editActivity(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - return null; - } - - /** - * generates Edit Activity screen - * - * @param mapping - * @param form - * @param request - * @param response * @return - * @throws IOException - * @throws ServletException - * @throws ToolException */ - public ActionForward editActivityQuestions(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException, ToolException { - - QaAuthoringForm qaAuthoringForm = (QaAuthoringForm) form; - - IQaService qaService = QaServiceProxy.getQaService(getServlet().getServletContext()); - - String httpSessionID = qaAuthoringForm.getHttpSessionID(); - - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - qaAuthoringForm.setContentFolderID(contentFolderID); - - String activeModule = request.getParameter(QaAppConstants.ACTIVE_MODULE); - - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - - String defaultContentIdStr = request.getParameter(QaAppConstants.DEFAULT_CONTENT_ID_STR); - - QaContent qaContent = qaService.getQa(new Long(strToolContentID).longValue()); - - QaGeneralAuthoringDTO qaGeneralAuthoringDTO = new QaGeneralAuthoringDTO(); - qaGeneralAuthoringDTO.setContentFolderID(contentFolderID); - - - qaGeneralAuthoringDTO.setActivityTitle(qaContent.getTitle()); - qaAuthoringForm.setTitle(qaContent.getTitle()); - - qaGeneralAuthoringDTO.setActivityInstructions(qaContent.getInstructions()); - - sessionMap.put(QaAppConstants.ACTIVITY_TITLE_KEY, qaContent.getTitle()); - sessionMap.put(QaAppConstants.ACTIVITY_INSTRUCTIONS_KEY, qaContent.getInstructions()); - - /* determine whether the request is from Monitoring url Edit Activity */ - - qaAuthoringForm.setDefineLaterInEditMode(new Boolean(true).toString()); - qaGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - QaUtils.setDefineLater(request, true, strToolContentID, qaService); - - QaUtils.setFormProperties(request, qaService, qaAuthoringForm, qaGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - - qaGeneralAuthoringDTO.setToolContentID(strToolContentID); - qaGeneralAuthoringDTO.setActiveModule(activeModule); - qaGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - qaAuthoringForm.setToolContentID(strToolContentID); - qaAuthoringForm.setActiveModule(activeModule); - qaAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); - qaAuthoringForm.setCurrentTab("1"); - - List listQuestionContentDTO = new LinkedList(); - - Iterator queIterator = qaContent.getQaQueContents().iterator(); - while (queIterator.hasNext()) { - QaQueContent qaQuestion = (QaQueContent) queIterator.next(); - - if (qaQuestion != null) { - QaQuestionDTO qaQuestionDTO = new QaQuestionDTO(qaQuestion); - qaQuestionDTO.setDisplayOrder(new Integer(qaQuestion.getDisplayOrder()).toString()); - listQuestionContentDTO.add(qaQuestionDTO); - } + 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); } - request.setAttribute(QaAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - sessionMap.put(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - - request.setAttribute(QaAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - request.getSession().setAttribute(httpSessionID, sessionMap); - - request.setAttribute(QaAppConstants.QA_GENERAL_AUTHORING_DTO, qaGeneralAuthoringDTO); - - return mapping.findForward(QaAppConstants.LOAD_QUESTIONS); + return list; } - + /** - * existsContent + * Get ToolAccessMode from HttpRequest parameters. Default value is AUTHOR mode. * - * @param toolContentID - * @param qaService - * @return - */ - protected boolean existsContent(long toolContentID, IQaService qaService) { - QaContent qaContent = qaService.getQa(toolContentID); - if (qaContent == null) { - return false; - } - - 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); + 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 list; + return mode; } } Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaAuthoringConditionAction.java =================================================================== diff -u -r91f0740e75daa643981b757e49d1ed2ed7f0a528 -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaAuthoringConditionAction.java (.../QaAuthoringConditionAction.java) (revision 91f0740e75daa643981b757e49d1ed2ed7f0a528) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaAuthoringConditionAction.java (.../QaAuthoringConditionAction.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -314,10 +314,10 @@ */ private List getQuestionList(SessionMap sessionMap) { List list = (List) sessionMap - .get(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); + .get(QaAppConstants.LIST_QUESTION_DTOS); if (list == null) { list = new LinkedList(); - sessionMap.put(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, list); + sessionMap.put(QaAppConstants.LIST_QUESTION_DTOS, list); } return list; } Fisheye: Tag a7661f206a3f21114f1c05f9a29f56e20f5e35f0 refers to a dead (removed) revision in file `lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaDLStarterAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaLearningAction.java =================================================================== diff -u -r7cefcae725bb4e568ae1d61624a75bd6b3f3a8c3 -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaLearningAction.java (.../QaLearningAction.java) (revision 7cefcae725bb4e568ae1d61624a75bd6b3f3a8c3) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaLearningAction.java (.../QaLearningAction.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -25,6 +25,7 @@ import java.io.IOException; import java.util.Date; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -58,7 +59,7 @@ import org.lamsfoundation.lams.tool.qa.service.IQaService; import org.lamsfoundation.lams.tool.qa.service.QaServiceProxy; import org.lamsfoundation.lams.tool.qa.util.QaComparator; -import org.lamsfoundation.lams.tool.qa.util.QaUtils; +import org.lamsfoundation.lams.tool.qa.util.QaStringComparator; import org.lamsfoundation.lams.tool.qa.web.form.QaLearningForm; import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; @@ -119,7 +120,7 @@ ActionMessages errors = new ActionMessages(); String httpSessionID = qaLearningForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); /* if the listing mode is QUESTION_LISTING_MODE_COMBINED populate the answers here*/ if (questionListingMode.equalsIgnoreCase(QaAppConstants.QUESTION_LISTING_MODE_COMBINED)) { @@ -131,14 +132,14 @@ String answer = request.getParameter(answerParamName); // String answerPresentable = QaUtils.replaceNewLines(answer); - String questionIndexString = new Integer(questionIndex).toString(); - mapAnswers.put(questionIndexString, answer); - mapAnswersPresentable.put(questionIndexString, answer); + Integer questionIndexInteger = new Integer(questionIndex); + mapAnswers.put(questionIndexInteger.toString(), answer); + mapAnswersPresentable.put(questionIndexInteger.toString(), answer); Map questionContentMap = generalLearnerFlowDTO.getMapQuestionContentLearner(); - QaQuestionDTO dto = questionContentMap.get(questionIndexString); + QaQuestionDTO dto = questionContentMap.get(questionIndexInteger); if (dto.isRequired() && isEmpty(answer)) { - errors.add(Globals.ERROR_KEY, new ActionMessage("error.required", questionIndexString)); + errors.add(Globals.ERROR_KEY, new ActionMessage("error.required", questionIndexInteger)); forwardName = QaAppConstants.LOAD_LEARNER; } @@ -151,14 +152,14 @@ mapAnswers = storeSequentialAnswer(qaLearningForm, request, generalLearnerFlowDTO, true); mapAnswersPresentable = (Map) sessionMap.get(QaAppConstants.MAP_ALL_RESULTS_KEY); - mapAnswersPresentable = MonitoringUtil.removeNewLinesMap(mapAnswersPresentable); + mapAnswersPresentable = QaLearningAction.removeNewLinesMap(mapAnswersPresentable); // only need to check the final question as the others will have been checked when the user clicked next. Map questionMap = generalLearnerFlowDTO.getMapQuestionContentLearner(); int numQuestions = questionMap.size(); - String finalQuestionIndex = new Integer(numQuestions).toString(); + Integer finalQuestionIndex = new Integer(numQuestions); QaQuestionDTO dto = questionMap.get(finalQuestionIndex); - if (dto.isRequired() && isEmpty(mapAnswersPresentable.get(finalQuestionIndex))) { + if (dto.isRequired() && isEmpty(mapAnswersPresentable.get(finalQuestionIndex).toString())) { errors.add(Globals.ERROR_KEY, new ActionMessage("error.required", finalQuestionIndex)); forwardName = QaAppConstants.LOAD_LEARNER; } @@ -169,7 +170,7 @@ /*mapAnswers will be used in the viewAllAnswers screen*/ if (sessionMap == null) { - sessionMap = new SessionMap(); + sessionMap = new SessionMap(); } sessionMap.put(QaAppConstants.MAP_ALL_RESULTS_KEY, mapAnswers); @@ -282,7 +283,7 @@ String httpSessionID = qaLearningForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); request.getSession().setAttribute(sessionMap.getSessionID(), sessionMap); qaLearningForm.setHttpSessionID(sessionMap.getSessionID()); generalLearnerFlowDTO.setHttpSessionID(sessionMap.getSessionID()); @@ -327,14 +328,14 @@ QaContent qaContent = qaSession.getQaContent(); String httpSessionID = qaLearningForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); Map mapAnswers = (Map) sessionMap.get(QaAppConstants.MAP_ALL_RESULTS_KEY); // LearningUtil.storeResponses(mapAnswers, qaService, toolContentID, new Long(toolSessionID)); // mark response as finalised QaQueUsr qaQueUsr = getCurrentUser(toolSessionID); qaQueUsr.setResponseFinalized(true); - QaLearningAction.qaService.updateQaQueUsr(qaQueUsr); + QaLearningAction.qaService.updateUser(qaQueUsr); qaLearningForm.resetUserActions(); qaLearningForm.setSubmitAnswersContent(null); @@ -541,7 +542,7 @@ GeneralLearnerFlowDTO generalLearnerFlowDTO, boolean getNextQuestion) { QaLearningForm qaLearningForm = (QaLearningForm) form; String httpSessionID = qaLearningForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); String currentQuestionIndex = qaLearningForm.getCurrentQuestionIndex(); @@ -563,7 +564,7 @@ // is this question required and are they trying to go to the next question? // if so, check if the answer is blank and generate an error if it is blank. Map questionContentMap = generalLearnerFlowDTO.getMapQuestionContentLearner(); - QaQuestionDTO dto = questionContentMap.get(currentQuestionIndex); + QaQuestionDTO dto = questionContentMap.get(new Integer(currentQuestionIndex)); boolean isRequiredQuestionMissed = dto.isRequired() && isEmpty(newAnswer); if (getNextQuestion && isRequiredQuestionMissed) { ActionMessages errors = new ActionMessages(); @@ -596,13 +597,17 @@ String totalQuestionCount = qaLearningForm.getTotalQuestionCount(); - String userFeedback = LearningUtil - .feedBackAnswersProgress(request, intCurrentQuestionIndex, totalQuestionCount); + int remainingQuestionCount = new Long(totalQuestionCount).intValue() - new Integer(currentQuestionIndex).intValue() + 1; + String userFeedback = ""; + if (remainingQuestionCount != 0) { + userFeedback = "Remaining question count: " + remainingQuestionCount; + } else { + userFeedback = "End of the questions."; + } generalLearnerFlowDTO.setUserFeedback(userFeedback); + + generalLearnerFlowDTO.setRemainingQuestionCount("" + remainingQuestionCount); - String remQCount = LearningUtil.getRemainingQuestionCount(intCurrentQuestionIndex, totalQuestionCount); - generalLearnerFlowDTO.setRemainingQuestionCount(remQCount); - qaLearningForm.resetUserActions(); /*resets all except submitAnswersContent */ sessionMap.put(QaAppConstants.MAP_SEQUENTIAL_ANSWERS_KEY, mapSequentialAnswers); @@ -722,7 +727,7 @@ QaQueUsr qaQueUsr = QaLearningAction.qaService.getUserByIdAndSession(new Long(userID), qaSession.getQaSessionId()); qaQueUsr.setLearnerFinished(true); - QaLearningAction.qaService.updateQaQueUsr(qaQueUsr); + QaLearningAction.qaService.updateUser(qaQueUsr); /* * The learner is done with the tool session. The tool needs to clean-up. @@ -733,7 +738,7 @@ qaSession.setSession_end_date(new Date(System.currentTimeMillis())); qaSession.setSession_status(QaAppConstants.COMPLETED); - QaLearningAction.qaService.updateQaSession(qaSession); + QaLearningAction.qaService.updateSession(qaSession); String httpSessionID = qaLearningForm.getHttpSessionID(); // request.getSession().removeAttribute(httpSessionID); @@ -958,7 +963,20 @@ MonitoringUtil.setUpMonitoring(request, qaService, qaContent); } + private static Map removeNewLinesMap(Map map) { + Map newMap = new TreeMap(new QaStringComparator()); + Iterator itMap = map.entrySet().iterator(); + while (itMap.hasNext()) { + Map.Entry pairs = (Map.Entry) itMap.next(); + String newText = ""; + if (pairs.getValue().toString() != null) { + newText = pairs.getValue().toString().replaceAll("\n", "
"); + } + newMap.put(pairs.getKey(), newText); + } + return newMap; + } private void initializeQAService() { if (QaLearningAction.qaService == null) { Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaLearningStarterAction.java =================================================================== diff -u -r7cefcae725bb4e568ae1d61624a75bd6b3f3a8c3 -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaLearningStarterAction.java (.../QaLearningStarterAction.java) (revision 7cefcae725bb4e568ae1d61624a75bd6b3f3a8c3) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaLearningStarterAction.java (.../QaLearningStarterAction.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -109,13 +109,12 @@ * * make sure this session exists in tool's session table by now. */ - - if (!QaUtils.existsSession(new Long(toolSessionID).longValue(), qaService)) { + QaSession qaSession = qaService.getSessionById(new Long(toolSessionID).longValue()); + if (qaSession == null) { QaUtils.cleanUpSessionAbsolute(request); throw new ServletException("No session found"); } - QaSession qaSession = qaService.getSessionById(new Long(toolSessionID).longValue()); QaContent qaContent = qaSession.getQaContent(); if (qaContent == null) { QaUtils.cleanUpSessionAbsolute(request); @@ -141,7 +140,7 @@ // forwards to the leaderSelection page if (groupLeader == null && !mode.equals(ToolAccessMode.TEACHER.toString())) { - List groupUsers = qaService.getUsersBySession(new Long(toolSessionID).longValue()); + List groupUsers = qaService.getUsersBySessionId(new Long(toolSessionID).longValue()); request.setAttribute(ATTR_GROUP_USERS, groupUsers); request.setAttribute(TOOL_SESSION_ID, toolSessionID); request.setAttribute(ATTR_CONTENT, qaContent); @@ -157,7 +156,7 @@ qaService.copyAnswersFromLeader(qaUser, groupLeader); qaUser.setResponseFinalized(true); - qaService.updateQaQueUsr(qaUser); + qaService.updateUser(qaUser); } } Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaMonitoringAction.java =================================================================== diff -u -rdfbc0a5728344573bc1bcbf0095e4f2778d3ad8d -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaMonitoringAction.java (.../QaMonitoringAction.java) (revision dfbc0a5728344573bc1bcbf0095e4f2778d3ad8d) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaMonitoringAction.java (.../QaMonitoringAction.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -25,10 +25,6 @@ import java.io.IOException; import java.util.Date; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; import java.util.TimeZone; import javax.servlet.ServletException; @@ -37,182 +33,34 @@ import javax.servlet.http.HttpSession; import org.apache.log4j.Logger; -import org.apache.struts.Globals; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; -import org.apache.struts.action.ActionMessage; -import org.apache.struts.action.ActionMessages; import org.lamsfoundation.lams.tool.exception.ToolException; import org.lamsfoundation.lams.tool.qa.QaAppConstants; -import org.lamsfoundation.lams.tool.qa.QaCondition; import org.lamsfoundation.lams.tool.qa.QaContent; -import org.lamsfoundation.lams.tool.qa.QaQueContent; import org.lamsfoundation.lams.tool.qa.QaUsrResp; -import org.lamsfoundation.lams.tool.qa.dto.GeneralMonitoringDTO; -import org.lamsfoundation.lams.tool.qa.dto.QaGeneralAuthoringDTO; -import org.lamsfoundation.lams.tool.qa.dto.QaQuestionDTO; import org.lamsfoundation.lams.tool.qa.service.IQaService; import org.lamsfoundation.lams.tool.qa.service.QaServiceProxy; -import org.lamsfoundation.lams.tool.qa.util.QaUtils; -import org.lamsfoundation.lams.tool.qa.web.form.QaAuthoringForm; -import org.lamsfoundation.lams.tool.qa.web.form.QaMonitoringForm; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.util.DateUtil; import org.lamsfoundation.lams.util.WebUtil; import org.lamsfoundation.lams.web.action.LamsDispatchAction; import org.lamsfoundation.lams.web.session.SessionManager; import org.lamsfoundation.lams.web.util.AttributeNames; -import org.lamsfoundation.lams.web.util.SessionMap; /** * @author Ozgur Demirtas */ public class QaMonitoringAction extends LamsDispatchAction implements QaAppConstants { private static Logger logger = Logger.getLogger(QaMonitoringAction.class.getName()); - public static String SELECTBOX_SELECTED_TOOL_SESSION = "selectBoxSelectedToolSession"; - public static Integer READABLE_TOOL_SESSION_COUNT = new Integer(1); - @Override public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException, ToolException { return null; } - /** - * activates editActivity screen - * - * @param mapping - * @param form - * @param request - * @param response - * @return - * @throws IOException - * @throws ServletException - */ - public ActionForward editActivity(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - - QaMonitoringForm qaMonitoringForm = (QaMonitoringForm) form; - IQaService qaService = QaServiceProxy.getQaService(getServlet().getServletContext()); - if (qaService == null) { - qaService = qaMonitoringForm.getQaService(); - } - - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - - qaMonitoringForm.setToolContentID(strToolContentID); - - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - - qaMonitoringForm.setContentFolderID(contentFolderID); - - request.setAttribute(QaAppConstants.SOURCE_MC_STARTER, "monitoring"); - - - /* - * it is possible that the content is being used by some learners. In this situation, the content is marked as - * "in use" and content in use is not modifiable - */ - QaContent qaContent = qaService.getQa(new Long(strToolContentID).longValue()); - - GeneralMonitoringDTO generalMonitoringDTO = new GeneralMonitoringDTO(); - if (qaService.isStudentActivityOccurredGlobal(qaContent)) { - generalMonitoringDTO.setUserExceptionContentInUse(new Boolean(true).toString()); - return mapping.findForward(QaAppConstants.LOAD_MONITORING); - } - - if (qaContent.getTitle() == null) { - generalMonitoringDTO.setActivityTitle("Questions and Answers"); - generalMonitoringDTO.setActivityInstructions("Please answer the questions."); - } else { - generalMonitoringDTO.setActivityTitle(qaContent.getTitle()); - generalMonitoringDTO.setActivityInstructions(qaContent.getInstructions()); - } - - - request.setAttribute(QaAppConstants.QA_GENERAL_MONITORING_DTO, generalMonitoringDTO); - - - request.setAttribute(QaAppConstants.QA_GENERAL_MONITORING_DTO, generalMonitoringDTO); - - QaGeneralAuthoringDTO qaGeneralAuthoringDTO = new QaGeneralAuthoringDTO(); - qaGeneralAuthoringDTO.setActivityTitle(qaContent.getTitle()); - qaGeneralAuthoringDTO.setActivityInstructions(qaContent.getInstructions()); - request.setAttribute(QaAppConstants.QA_GENERAL_AUTHORING_DTO, qaGeneralAuthoringDTO); - - MonitoringUtil.setUpMonitoring(request, qaService, qaContent); - - /* note that we are casting monitoring form subclass into Authoring form */ - QaStarterAction qaStarterAction = new QaStarterAction(); - return qaStarterAction.executeDefineLater(mapping, qaMonitoringForm, request, response, qaService); - } - - public ActionForward editActivityQuestions(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException, ToolException { - QaMonitoringForm qaMonitoringForm = (QaMonitoringForm) form; - - - IQaService qaService = QaServiceProxy.getQaService(getServlet().getServletContext()); - - - GeneralMonitoringDTO generalMonitoringDTO = new GeneralMonitoringDTO(); - - generalMonitoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - - request.setAttribute(QaAppConstants.QA_GENERAL_MONITORING_DTO, generalMonitoringDTO); - - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - qaMonitoringForm.setToolContentID(strToolContentID); - - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - - qaMonitoringForm.setContentFolderID(contentFolderID); - - String httpSessionID = request.getParameter("httpSessionID"); - - qaMonitoringForm.setHttpSessionID(httpSessionID); - - QaContent qaContent = qaService.getQa(new Long(strToolContentID).longValue()); - - - qaMonitoringForm.setTitle(qaContent.getTitle()); - - QaUtils.setDefineLater(request, true, strToolContentID, qaService); - - - request.setAttribute(QaAppConstants.QA_GENERAL_MONITORING_DTO, generalMonitoringDTO); - - List listQuestionContentDTO = new LinkedList(); - - Iterator queIterator = qaContent.getQaQueContents().iterator(); - while (queIterator.hasNext()) { - QaQueContent qaQuestion = (QaQueContent) queIterator.next(); - if (qaQuestion != null) { - QaQuestionDTO qaQuestionDTO = new QaQuestionDTO(qaQuestion); - listQuestionContentDTO.add(qaQuestionDTO); - } - } - - request.setAttribute(QaAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - request.setAttribute(QaAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - - QaGeneralAuthoringDTO qaGeneralAuthoringDTO = new QaGeneralAuthoringDTO(); - qaGeneralAuthoringDTO.setActivityTitle(qaContent.getTitle()); - qaGeneralAuthoringDTO.setActivityInstructions(qaContent.getInstructions()); - qaGeneralAuthoringDTO.setActiveModule(QaAppConstants.MONITORING); - qaGeneralAuthoringDTO.setToolContentID(strToolContentID); - qaGeneralAuthoringDTO.setContentFolderID(contentFolderID); - qaGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - request.setAttribute(QaAppConstants.QA_GENERAL_AUTHORING_DTO, qaGeneralAuthoringDTO); - - MonitoringUtil.setUpMonitoring(request, qaService, qaContent); - - return mapping.findForward(QaAppConstants.LOAD_MONITORING); - } - public ActionForward updateResponse(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { @@ -235,18 +83,6 @@ return null; } - /** - * persists error messages to request scope - * - * @param request - * @param message - */ - public void persistError(HttpServletRequest request, String message) { - ActionMessages errors = new ActionMessages(); - errors.add(Globals.ERROR_KEY, new ActionMessage(message)); - saveErrors(request, errors); - } - public ActionForward updateResponseVisibility(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException, ToolException { IQaService qaService = QaServiceProxy.getQaService(getServlet().getServletContext()); @@ -257,885 +93,6 @@ return null; } - - public ActionForward submitAllContent(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - - /* start authoring code */ - QaAuthoringForm qaAuthoringForm = (QaMonitoringForm) form; - - - IQaService qaService = QaServiceProxy.getQaService(getServlet().getServletContext()); - - - String httpSessionID = request.getParameter("httpSessionID"); - - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - - - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - qaAuthoringForm.setContentFolderID(contentFolderID); - - String activeModule = request.getParameter(QaAppConstants.ACTIVE_MODULE); - - - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - - String defaultContentIdStr = request.getParameter(QaAppConstants.DEFAULT_CONTENT_ID_STR); - - List listQuestionContentDTO = (List) sessionMap.get(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); - - ActionMessages errors = new ActionMessages(); - - if (listQuestionContentDTO.size() == 0) { - ActionMessage error = new ActionMessage("questions.none.submitted"); - errors.add(ActionMessages.GLOBAL_MESSAGE, error); - } - - AuthoringUtil authoringUtil = new AuthoringUtil(); - - QaGeneralAuthoringDTO qaGeneralAuthoringDTO = new QaGeneralAuthoringDTO(); - qaGeneralAuthoringDTO.setContentFolderID(contentFolderID); - - String richTextTitle = request.getParameter(QaAppConstants.TITLE); - String richTextInstructions = request.getParameter(QaAppConstants.INSTRUCTIONS); - - qaGeneralAuthoringDTO.setActivityTitle(richTextTitle); - qaAuthoringForm.setTitle(richTextTitle); - - qaGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - - sessionMap.put(QaAppConstants.ACTIVITY_TITLE_KEY, richTextTitle); - sessionMap.put(QaAppConstants.ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); - request.setAttribute(QaAppConstants.QA_GENERAL_AUTHORING_DTO, qaGeneralAuthoringDTO); - - QaContent qaContentTest = qaService.getQa(new Long(strToolContentID).longValue()); - - if (!errors.isEmpty()) { - saveErrors(request, errors); - QaMonitoringAction.logger.debug("errors saved: " + errors); - } - - GeneralMonitoringDTO qaGeneralMonitoringDTO = new GeneralMonitoringDTO(); - - QaContent qaContent = qaContentTest; - if (errors.isEmpty()) { - /* - * removes deleted entries in the questions table based on mapQuestionContent - */ - authoringUtil.removeRedundantQuestions(listQuestionContentDTO, qaService, qaAuthoringForm, request, - strToolContentID); - - Set conditionSet = (Set) sessionMap.get(QaAppConstants.ATTR_CONDITION_SET); - - qaContent = authoringUtil.saveOrUpdateQaContent(listQuestionContentDTO, qaService, - qaAuthoringForm, request, qaContentTest, strToolContentID, conditionSet); - - - long defaultContentID = 0; - defaultContentID = qaService.getToolDefaultContentIdBySignature(QaAppConstants.MY_SIGNATURE); - - if (qaContent != null) { - qaGeneralAuthoringDTO.setDefaultContentIdStr(new Long(defaultContentID).toString()); - } - - authoringUtil.reOrganizeDisplayOrder(qaService, qaAuthoringForm, qaContent); - - QaUtils.setDefineLater(request, false, strToolContentID, qaService); - - QaUtils.setFormProperties(request, qaService, qaAuthoringForm, qaGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - - qaGeneralMonitoringDTO.setDefineLaterInEditMode(new Boolean(false).toString()); - } else { - //errors is not empty - - if (qaContent != null) { - long defaultContentID = 0; - defaultContentID = qaService.getToolDefaultContentIdBySignature(QaAppConstants.MY_SIGNATURE); - if (qaContent != null) { - qaGeneralAuthoringDTO.setDefaultContentIdStr(new Long(defaultContentID).toString()); - } - - QaUtils.setFormProperties(request, qaService, qaAuthoringForm, qaGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - } - qaGeneralMonitoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - } - - qaGeneralAuthoringDTO.setSbmtSuccess(new Integer(1).toString()); - - qaAuthoringForm.resetUserAction(); - - request.setAttribute(QaAppConstants.QA_GENERAL_AUTHORING_DTO, qaGeneralAuthoringDTO); - - request.setAttribute(QaAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - sessionMap.put(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - request.getSession().setAttribute(httpSessionID, sessionMap); - - request.setAttribute(QaAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - - qaGeneralAuthoringDTO.setToolContentID(strToolContentID); - qaGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - qaGeneralAuthoringDTO.setActiveModule(activeModule); - qaGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - - qaAuthoringForm.setToolContentID(strToolContentID); - qaAuthoringForm.setHttpSessionID(httpSessionID); - qaAuthoringForm.setActiveModule(activeModule); - qaAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); - qaAuthoringForm.setCurrentTab("2"); - - request.setAttribute(QaAppConstants.QA_GENERAL_MONITORING_DTO, qaGeneralMonitoringDTO); - - MonitoringUtil.setUpMonitoring(request, qaService, qaContent); - - return mapping.findForward(QaAppConstants.LOAD_MONITORING); - } - - public ActionForward saveSingleQuestion(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - /* start authoring code */ - QaAuthoringForm qaAuthoringForm = (QaMonitoringForm) form; - - IQaService qaService = QaServiceProxy.getQaService(getServlet().getServletContext()); - - - String httpSessionID = request.getParameter("httpSessionID"); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - - - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - qaAuthoringForm.setContentFolderID(contentFolderID); - - String editQuestionBoxRequest = request.getParameter("editQuestionBoxRequest"); - - - String activeModule = request.getParameter(QaAppConstants.ACTIVE_MODULE); - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = request.getParameter(QaAppConstants.DEFAULT_CONTENT_ID_STR); - QaContent qaContent = qaService.getQa(new Long(strToolContentID).longValue()); - if (qaContent == null) { - qaContent = qaService.getQa(new Long(defaultContentIdStr).longValue()); - } - - - QaGeneralAuthoringDTO qaGeneralAuthoringDTO = new QaGeneralAuthoringDTO(); - - - qaGeneralAuthoringDTO.setContentFolderID(contentFolderID); - - qaGeneralAuthoringDTO.setSbmtSuccess(new Integer(0).toString()); - - AuthoringUtil authoringUtil = new AuthoringUtil(); - - List listQuestionContentDTO = (List) sessionMap.get(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); - - - String newQuestion = request.getParameter("newQuestion"); - String feedback = request.getParameter("feedback"); - String required = request.getParameter("required"); - boolean requiredBoolean = false; - if (required != null && required.equalsIgnoreCase("1")) { - requiredBoolean = true; - } - - String editableQuestionIndex = request.getParameter("editableQuestionIndex"); - - if (newQuestion != null && newQuestion.length() > 0) { - if (editQuestionBoxRequest != null && editQuestionBoxRequest.equals("false")) { - boolean duplicates = AuthoringUtil.checkDuplicateQuestions(listQuestionContentDTO, newQuestion); - - if (!duplicates) { - QaQuestionDTO qaQuestionDTO = null; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - qaQuestionDTO = (QaQuestionDTO) listIterator.next(); - - String question = qaQuestionDTO.getQuestion(); - String displayOrder = qaQuestionDTO.getDisplayOrder(); - - if (displayOrder != null && !displayOrder.equals("")) { - if (displayOrder.equals(editableQuestionIndex)) { - break; - } - - } - } - - - qaQuestionDTO.setQuestion(newQuestion); - qaQuestionDTO.setFeedback(feedback); - qaQuestionDTO.setDisplayOrder(editableQuestionIndex); - qaQuestionDTO.setRequired(requiredBoolean); - - listQuestionContentDTO = AuthoringUtil.reorderUpdateListQuestionContentDTO(listQuestionContentDTO, - qaQuestionDTO, editableQuestionIndex); - } else { - //duplicate question entry, not adding - } - } else { - //request for edit and save - QaQuestionDTO qaQuestionDTO = null; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - qaQuestionDTO = (QaQuestionDTO) listIterator.next(); - - String question = qaQuestionDTO.getQuestion(); - String displayOrder = qaQuestionDTO.getDisplayOrder(); - - - if (displayOrder != null && !displayOrder.equals("")) { - if (displayOrder.equals(editableQuestionIndex)) { - break; - } - - } - } - - - qaQuestionDTO.setQuestion(newQuestion); - qaQuestionDTO.setFeedback(feedback); - qaQuestionDTO.setDisplayOrder(editableQuestionIndex); - qaQuestionDTO.setRequired(requiredBoolean); - - listQuestionContentDTO = AuthoringUtil.reorderUpdateListQuestionContentDTO(listQuestionContentDTO, - qaQuestionDTO, editableQuestionIndex); - } - } else { - //entry blank, not adding - } - - request.setAttribute(QaAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - sessionMap.put(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - - - String richTextTitle = request.getParameter(QaAppConstants.TITLE); - String richTextInstructions = request.getParameter(QaAppConstants.INSTRUCTIONS); - - - - qaGeneralAuthoringDTO.setActivityTitle(richTextTitle); - qaAuthoringForm.setTitle(richTextTitle); - - qaGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - - sessionMap.put(QaAppConstants.ACTIVITY_TITLE_KEY, richTextTitle); - sessionMap.put(QaAppConstants.ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); - - qaGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - - request.getSession().setAttribute(httpSessionID, sessionMap); - sessionMap.put(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - - QaUtils.setFormProperties(request, qaService, qaAuthoringForm, qaGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - - qaGeneralAuthoringDTO.setToolContentID(strToolContentID); - qaGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - qaGeneralAuthoringDTO.setActiveModule(activeModule); - qaGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - - qaAuthoringForm.setToolContentID(strToolContentID); - qaAuthoringForm.setHttpSessionID(httpSessionID); - qaAuthoringForm.setActiveModule(activeModule); - qaAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); - qaAuthoringForm.setCurrentTab("2"); - - - request.setAttribute(QaAppConstants.QA_GENERAL_AUTHORING_DTO, qaGeneralAuthoringDTO); - - request.getSession().setAttribute(httpSessionID, sessionMap); - - request.setAttribute(QaAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - - /* start monitoring code */ - GeneralMonitoringDTO qaGeneralMonitoringDTO = new GeneralMonitoringDTO(); - qaGeneralMonitoringDTO.setDefineLaterInEditMode(new Boolean(false).toString()); - qaGeneralMonitoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - - - request.setAttribute(QaAppConstants.QA_GENERAL_MONITORING_DTO, qaGeneralMonitoringDTO); - - MonitoringUtil.setUpMonitoring(request, qaService, qaContent); - - return mapping.findForward(QaAppConstants.LOAD_MONITORING); - } - - public ActionForward addSingleQuestion(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - - /* start authoring code */ - QaAuthoringForm qaAuthoringForm = (QaMonitoringForm) form; - - IQaService qaService = QaServiceProxy.getQaService(getServlet().getServletContext()); - - - String httpSessionID = request.getParameter("httpSessionID"); - - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - - - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - qaAuthoringForm.setContentFolderID(contentFolderID); - - String activeModule = request.getParameter(QaAppConstants.ACTIVE_MODULE); - - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - - String defaultContentIdStr = request.getParameter(QaAppConstants.DEFAULT_CONTENT_ID_STR); - - QaContent qaContent = qaService.getQa(new Long(strToolContentID).longValue()); - - - if (qaContent == null) { - qaContent = qaService.getQa(new Long(defaultContentIdStr).longValue()); - } - - - QaGeneralAuthoringDTO qaGeneralAuthoringDTO = new QaGeneralAuthoringDTO(); - - qaGeneralAuthoringDTO.setContentFolderID(contentFolderID); - - qaGeneralAuthoringDTO.setSbmtSuccess(new Integer(0).toString()); - - List listQuestionContentDTO = (List) sessionMap.get(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); - - - String newQuestion = request.getParameter("newQuestion"); - String feedback = request.getParameter("feedback"); - String required = request.getParameter("required"); - boolean requiredBoolean = false; - if (required != null && required.equalsIgnoreCase("1")) { - requiredBoolean = true; - } - - int listSize = listQuestionContentDTO.size(); - - - if (newQuestion != null && newQuestion.length() > 0) { - boolean duplicates = AuthoringUtil.checkDuplicateQuestions(listQuestionContentDTO, newQuestion); - - if (!duplicates) { - QaQuestionDTO qaQuestionDTO = new QaQuestionDTO(newQuestion, - new Long(listSize + 1).toString(), feedback, requiredBoolean); - listQuestionContentDTO.add(qaQuestionDTO); - - } else { - //entry duplicate, not adding - } - } else { - //entry blank, not adding - } - - request.setAttribute(QaAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - sessionMap.put(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - - String richTextTitle = request.getParameter(QaAppConstants.TITLE); - String richTextInstructions = request.getParameter(QaAppConstants.INSTRUCTIONS); - - - - qaGeneralAuthoringDTO.setActivityTitle(richTextTitle); - qaAuthoringForm.setTitle(richTextTitle); - - qaGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - - sessionMap.put(QaAppConstants.ACTIVITY_TITLE_KEY, richTextTitle); - sessionMap.put(QaAppConstants.ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); - - qaGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - request.getSession().setAttribute(httpSessionID, sessionMap); - - QaUtils.setFormProperties(request, qaService, qaAuthoringForm, qaGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - - qaGeneralAuthoringDTO.setToolContentID(strToolContentID); - qaGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - qaGeneralAuthoringDTO.setActiveModule(activeModule); - qaGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - - qaAuthoringForm.setToolContentID(strToolContentID); - qaAuthoringForm.setHttpSessionID(httpSessionID); - qaAuthoringForm.setActiveModule(activeModule); - qaAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); - qaAuthoringForm.setCurrentTab("2"); - - - request.setAttribute(QaAppConstants.QA_GENERAL_AUTHORING_DTO, qaGeneralAuthoringDTO); - - request.getSession().setAttribute(httpSessionID, sessionMap); - - request.setAttribute(QaAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - - /* start monitoring code */ - GeneralMonitoringDTO qaGeneralMonitoringDTO = new GeneralMonitoringDTO(); - qaGeneralMonitoringDTO.setDefineLaterInEditMode(new Boolean(false).toString()); - - - qaGeneralMonitoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - request.setAttribute(QaAppConstants.QA_GENERAL_MONITORING_DTO, qaGeneralMonitoringDTO); - - MonitoringUtil.setUpMonitoring(request, qaService, qaContent); - - return mapping.findForward(QaAppConstants.LOAD_MONITORING); - } - - public ActionForward newQuestionBox(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - - /* start authoring code */ - QaAuthoringForm qaAuthoringForm = (QaMonitoringForm) form; - - IQaService qaService = QaServiceProxy.getQaService(getServlet().getServletContext()); - - - String httpSessionID = request.getParameter("httpSessionID"); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - - - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - qaAuthoringForm.setContentFolderID(contentFolderID); - - String activeModule = request.getParameter(QaAppConstants.ACTIVE_MODULE); - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = request.getParameter(QaAppConstants.DEFAULT_CONTENT_ID_STR); - QaContent qaContent = qaService.getQa(new Long(strToolContentID).longValue()); - - if (qaContent == null) { - qaContent = qaService.getQa(new Long(defaultContentIdStr).longValue()); - } - - - QaGeneralAuthoringDTO qaGeneralAuthoringDTO = new QaGeneralAuthoringDTO(); - - qaGeneralAuthoringDTO.setContentFolderID(contentFolderID); - - String richTextTitle = request.getParameter(QaAppConstants.TITLE); - String richTextInstructions = request.getParameter(QaAppConstants.INSTRUCTIONS); - - - - qaGeneralAuthoringDTO.setActivityTitle(richTextTitle); - qaAuthoringForm.setTitle(richTextTitle); - - qaGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - - QaUtils.setFormProperties(request, qaService, qaAuthoringForm, qaGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - - List listQuestionContentDTO = (List) sessionMap.get(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); - - - request.setAttribute(QaAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - - /* start monitoring code */ - GeneralMonitoringDTO qaGeneralMonitoringDTO = new GeneralMonitoringDTO(); - qaGeneralMonitoringDTO.setDefineLaterInEditMode(new Boolean(false).toString()); - qaGeneralMonitoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - request.setAttribute(QaAppConstants.QA_GENERAL_MONITORING_DTO, qaGeneralMonitoringDTO); - - MonitoringUtil.setUpMonitoring(request, qaService, qaContent); - - return mapping.findForward("newQuestionBox"); - } - - public ActionForward newEditableQuestionBox(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - /* start authoring code */ - QaAuthoringForm qaAuthoringForm = (QaMonitoringForm) form; - - IQaService qaService = QaServiceProxy.getQaService(getServlet().getServletContext()); - - - String httpSessionID = request.getParameter("httpSessionID"); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - - - String questionIndex = request.getParameter("questionIndex"); - qaAuthoringForm.setEditableQuestionIndex(questionIndex); - - List listQuestionContentDTO = (List) sessionMap.get(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); - - - String editableQuestion = ""; - String editableFeedback = ""; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - QaQuestionDTO qaQuestionDTO = (QaQuestionDTO) listIterator.next(); - - - String displayOrder = qaQuestionDTO.getDisplayOrder(); - - if (displayOrder != null && !displayOrder.equals("")) { - if (displayOrder.equals(questionIndex)) { - editableFeedback = qaQuestionDTO.getFeedback(); - editableQuestion = qaQuestionDTO.getQuestion(); - - break; - } - - } - } - - - - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - qaAuthoringForm.setContentFolderID(contentFolderID); - - String activeModule = request.getParameter(QaAppConstants.ACTIVE_MODULE); - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - String defaultContentIdStr = request.getParameter(QaAppConstants.DEFAULT_CONTENT_ID_STR); - QaContent qaContent = qaService.getQa(new Long(strToolContentID).longValue()); - if (qaContent == null) { - qaContent = qaService.getQa(new Long(defaultContentIdStr).longValue()); - } - - - QaGeneralAuthoringDTO qaGeneralAuthoringDTO = new QaGeneralAuthoringDTO(); - - qaGeneralAuthoringDTO.setContentFolderID(contentFolderID); - - String richTextTitle = request.getParameter(QaAppConstants.TITLE); - String richTextInstructions = request.getParameter(QaAppConstants.INSTRUCTIONS); - - - - qaGeneralAuthoringDTO.setActivityTitle(richTextTitle); - qaAuthoringForm.setTitle(richTextTitle); - - qaGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - - QaUtils.setFormProperties(request, qaService, qaAuthoringForm, qaGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - - qaGeneralAuthoringDTO.setEditableQuestionText(editableQuestion); - qaGeneralAuthoringDTO.setEditableQuestionFeedback(editableFeedback); - qaAuthoringForm.setFeedback(editableFeedback); - - - request.setAttribute(QaAppConstants.QA_GENERAL_AUTHORING_DTO, qaGeneralAuthoringDTO); - - request.setAttribute(QaAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - - /* start monitoring code */ - GeneralMonitoringDTO qaGeneralMonitoringDTO = new GeneralMonitoringDTO(); - qaGeneralMonitoringDTO.setDefineLaterInEditMode(new Boolean(false).toString()); - qaGeneralMonitoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - request.setAttribute(QaAppConstants.QA_GENERAL_MONITORING_DTO, qaGeneralMonitoringDTO); - - MonitoringUtil.setUpMonitoring(request, qaService, qaContent); - - return mapping.findForward("editQuestionBox"); - } - - public ActionForward removeQuestion(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - - /* start authoring code */ - QaAuthoringForm qaAuthoringForm = (QaMonitoringForm) form; - IQaService qaService = QaServiceProxy.getQaService(getServlet().getServletContext()); - - - String httpSessionID = request.getParameter("httpSessionID"); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - - - String questionIndex = request.getParameter("questionIndex"); - List listQuestionContentDTO = (List) sessionMap.get(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); - - - QaQuestionDTO qaQuestionDTO = null; - Iterator listIterator = listQuestionContentDTO.iterator(); - while (listIterator.hasNext()) { - qaQuestionDTO = (QaQuestionDTO) listIterator.next(); - - String displayOrder = qaQuestionDTO.getDisplayOrder(); - if (displayOrder != null && !displayOrder.equals("")) { - if (displayOrder.equals(questionIndex)) { - break; - } - - } - } - - qaQuestionDTO.setQuestion(""); - - listQuestionContentDTO = AuthoringUtil.reorderListQuestionContentDTO(listQuestionContentDTO, questionIndex); - - sessionMap.put(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - qaAuthoringForm.setContentFolderID(contentFolderID); - - String activeModule = request.getParameter(QaAppConstants.ACTIVE_MODULE); - - String richTextTitle = request.getParameter(QaAppConstants.TITLE); - - - String richTextInstructions = request.getParameter(QaAppConstants.INSTRUCTIONS); - - - sessionMap.put(QaAppConstants.ACTIVITY_TITLE_KEY, richTextTitle); - sessionMap.put(QaAppConstants.ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); - - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - - String defaultContentIdStr = request.getParameter(QaAppConstants.DEFAULT_CONTENT_ID_STR); - - QaContent qaContent = qaService.getQa(new Long(strToolContentID).longValue()); - - - if (qaContent == null) { - qaContent = qaService.getQa(new Long(defaultContentIdStr).longValue()); - } - - - QaGeneralAuthoringDTO qaGeneralAuthoringDTO = new QaGeneralAuthoringDTO(); - - qaGeneralAuthoringDTO.setContentFolderID(contentFolderID); - - qaGeneralAuthoringDTO.setActivityTitle(richTextTitle); - qaAuthoringForm.setTitle(richTextTitle); - - qaGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - - qaGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - - request.getSession().setAttribute(httpSessionID, sessionMap); - - QaUtils.setFormProperties(request, qaService, qaAuthoringForm, qaGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - - qaGeneralAuthoringDTO.setToolContentID(strToolContentID); - qaGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - qaGeneralAuthoringDTO.setActiveModule(activeModule); - qaGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - qaAuthoringForm.setToolContentID(strToolContentID); - qaAuthoringForm.setHttpSessionID(httpSessionID); - qaAuthoringForm.setActiveModule(activeModule); - qaAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); - qaAuthoringForm.setCurrentTab("2"); - - request.setAttribute(QaAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - - - - - request.setAttribute(QaAppConstants.QA_GENERAL_AUTHORING_DTO, qaGeneralAuthoringDTO); - - request.setAttribute(QaAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - - /* start monitoring code */ - GeneralMonitoringDTO qaGeneralMonitoringDTO = new GeneralMonitoringDTO(); - qaGeneralMonitoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - request.setAttribute(QaAppConstants.QA_GENERAL_MONITORING_DTO, qaGeneralMonitoringDTO); - - MonitoringUtil.setUpMonitoring(request, qaService, qaContent); - - return mapping.findForward(QaAppConstants.LOAD_MONITORING); - } - - public ActionForward moveQuestionDown(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - - /* start authoring code */ - QaAuthoringForm qaAuthoringForm = (QaMonitoringForm) form; - - IQaService qaService = QaServiceProxy.getQaService(getServlet().getServletContext()); - - - String httpSessionID = request.getParameter("httpSessionID"); - - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - - - String questionIndex = request.getParameter("questionIndex"); - - List listQuestionContentDTO = (List) sessionMap.get(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); - - - listQuestionContentDTO = AuthoringUtil.swapNodes(listQuestionContentDTO, questionIndex, "down", null); - - - listQuestionContentDTO = AuthoringUtil.reorderSimpleListQuestionContentDTO(listQuestionContentDTO); - - - sessionMap.put(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - qaAuthoringForm.setContentFolderID(contentFolderID); - - String activeModule = request.getParameter(QaAppConstants.ACTIVE_MODULE); - - String richTextTitle = request.getParameter(QaAppConstants.TITLE); - - - String richTextInstructions = request.getParameter(QaAppConstants.INSTRUCTIONS); - - - sessionMap.put(QaAppConstants.ACTIVITY_TITLE_KEY, richTextTitle); - sessionMap.put(QaAppConstants.ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); - - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - - String defaultContentIdStr = request.getParameter(QaAppConstants.DEFAULT_CONTENT_ID_STR); - - QaContent qaContent = qaService.getQa(new Long(strToolContentID).longValue()); - - - if (qaContent == null) { - qaContent = qaService.getQa(new Long(defaultContentIdStr).longValue()); - } - - - QaGeneralAuthoringDTO qaGeneralAuthoringDTO = new QaGeneralAuthoringDTO(); - - qaGeneralAuthoringDTO.setContentFolderID(contentFolderID); - - qaGeneralAuthoringDTO.setActivityTitle(richTextTitle); - qaAuthoringForm.setTitle(richTextTitle); - - qaGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - - qaGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - request.getSession().setAttribute(httpSessionID, sessionMap); - - QaUtils.setFormProperties(request, qaService, qaAuthoringForm, qaGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - - qaGeneralAuthoringDTO.setToolContentID(strToolContentID); - qaGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - qaGeneralAuthoringDTO.setActiveModule(activeModule); - qaGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - qaAuthoringForm.setToolContentID(strToolContentID); - qaAuthoringForm.setHttpSessionID(httpSessionID); - qaAuthoringForm.setActiveModule(activeModule); - qaAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); - qaAuthoringForm.setCurrentTab("2"); - - request.setAttribute(QaAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - - - - request.setAttribute(QaAppConstants.QA_GENERAL_AUTHORING_DTO, qaGeneralAuthoringDTO); - - request.setAttribute(QaAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - - /* start monitoring code */ - GeneralMonitoringDTO qaGeneralMonitoringDTO = new GeneralMonitoringDTO(); - qaGeneralMonitoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - request.setAttribute(QaAppConstants.QA_GENERAL_MONITORING_DTO, qaGeneralMonitoringDTO); - - MonitoringUtil.setUpMonitoring(request, qaService, qaContent); - - return mapping.findForward(QaAppConstants.LOAD_MONITORING); - - } - - public ActionForward moveQuestionUp(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - - /* start authoring code */ - QaAuthoringForm qaAuthoringForm = (QaMonitoringForm) form; - - IQaService qaService = QaServiceProxy.getQaService(getServlet().getServletContext()); - - - String httpSessionID = request.getParameter("httpSessionID"); - - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - - - String questionIndex = request.getParameter("questionIndex"); - - List listQuestionContentDTO = (List) sessionMap.get(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY); - - - listQuestionContentDTO = AuthoringUtil.swapNodes(listQuestionContentDTO, questionIndex, "up", null); - - - listQuestionContentDTO = AuthoringUtil.reorderSimpleListQuestionContentDTO(listQuestionContentDTO); - - - sessionMap.put(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - qaAuthoringForm.setContentFolderID(contentFolderID); - - String activeModule = request.getParameter(QaAppConstants.ACTIVE_MODULE); - - String richTextTitle = request.getParameter(QaAppConstants.TITLE); - - - String richTextInstructions = request.getParameter(QaAppConstants.INSTRUCTIONS); - - - sessionMap.put(QaAppConstants.ACTIVITY_TITLE_KEY, richTextTitle); - sessionMap.put(QaAppConstants.ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); - - String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); - - String defaultContentIdStr = request.getParameter(QaAppConstants.DEFAULT_CONTENT_ID_STR); - - QaContent qaContent = qaService.getQa(new Long(strToolContentID).longValue()); - - - if (qaContent == null) { - qaContent = qaService.getQa(new Long(defaultContentIdStr).longValue()); - } - - - QaGeneralAuthoringDTO qaGeneralAuthoringDTO = new QaGeneralAuthoringDTO(); - - qaGeneralAuthoringDTO.setContentFolderID(contentFolderID); - - qaGeneralAuthoringDTO.setActivityTitle(richTextTitle); - qaAuthoringForm.setTitle(richTextTitle); - - qaGeneralAuthoringDTO.setActivityInstructions(richTextInstructions); - - qaGeneralAuthoringDTO.setEditActivityEditMode(new Boolean(true).toString()); - - request.getSession().setAttribute(httpSessionID, sessionMap); - - QaUtils.setFormProperties(request, qaService, qaAuthoringForm, qaGeneralAuthoringDTO, strToolContentID, - defaultContentIdStr, activeModule, sessionMap, httpSessionID); - - qaGeneralAuthoringDTO.setToolContentID(strToolContentID); - qaGeneralAuthoringDTO.setHttpSessionID(httpSessionID); - qaGeneralAuthoringDTO.setActiveModule(activeModule); - qaGeneralAuthoringDTO.setDefaultContentIdStr(defaultContentIdStr); - qaAuthoringForm.setToolContentID(strToolContentID); - qaAuthoringForm.setHttpSessionID(httpSessionID); - qaAuthoringForm.setActiveModule(activeModule); - qaAuthoringForm.setDefaultContentIdStr(defaultContentIdStr); - qaAuthoringForm.setCurrentTab("2"); - - request.setAttribute(QaAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - - - - request.setAttribute(QaAppConstants.QA_GENERAL_AUTHORING_DTO, qaGeneralAuthoringDTO); - - request.setAttribute(QaAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - - /* start monitoring code */ - GeneralMonitoringDTO qaGeneralMonitoringDTO = new GeneralMonitoringDTO(); - qaGeneralMonitoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - - request.setAttribute(QaAppConstants.QA_GENERAL_MONITORING_DTO, qaGeneralMonitoringDTO); - - MonitoringUtil.setUpMonitoring(request, qaService, qaContent); - - return mapping.findForward(QaAppConstants.LOAD_MONITORING); - } /** * Set Submission Deadline @@ -1151,7 +108,7 @@ IQaService qaService = getQAService(); Long contentID = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID); - QaContent content = qaService.getQa(contentID); + QaContent content = qaService.getQaContent(contentID); Long dateParameter = WebUtil.readLongParam(request, QaAppConstants.ATTR_SUBMISSION_DEADLINE, true); Date tzSubmissionDeadline = null; @@ -1163,7 +120,7 @@ tzSubmissionDeadline = DateUtil.convertFromTimeZoneToDefault(teacherTimeZone, submissionDeadline); } content.setSubmissionDeadline(tzSubmissionDeadline); - qaService.saveOrUpdateQa(content); + qaService.saveOrUpdateQaContent(content); return null; } Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaMonitoringStarterAction.java =================================================================== diff -u -rdfbc0a5728344573bc1bcbf0095e4f2778d3ad8d -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaMonitoringStarterAction.java (.../QaMonitoringStarterAction.java) (revision dfbc0a5728344573bc1bcbf0095e4f2778d3ad8d) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaMonitoringStarterAction.java (.../QaMonitoringStarterAction.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -48,8 +48,6 @@ import org.lamsfoundation.lams.tool.qa.QaCondition; import org.lamsfoundation.lams.tool.qa.QaContent; import org.lamsfoundation.lams.tool.qa.QaQueContent; -import org.lamsfoundation.lams.tool.qa.dto.GeneralMonitoringDTO; -import org.lamsfoundation.lams.tool.qa.dto.QaGeneralAuthoringDTO; import org.lamsfoundation.lams.tool.qa.dto.QaQuestionDTO; import org.lamsfoundation.lams.tool.qa.service.IQaService; import org.lamsfoundation.lams.tool.qa.service.QaServiceProxy; @@ -73,7 +71,6 @@ QaUtils.cleanUpSessionAbsolute(request); QaMonitoringForm qaMonitoringForm = (QaMonitoringForm) form; - IQaService qaService = QaServiceProxy.getQaService(getServlet().getServletContext()); @@ -89,32 +86,12 @@ } String toolContentID = qaMonitoringForm.getToolContentID(); - QaContent qaContent = qaService.getQa(new Long(toolContentID).longValue()); + QaContent qaContent = qaService.getQaContent(new Long(toolContentID).longValue()); if (qaContent == null) { QaUtils.cleanUpSessionAbsolute(request); throw new ServletException("Data not initialised in Monitoring"); } - GeneralMonitoringDTO generalMonitoringDTO = new GeneralMonitoringDTO(); - if (qaContent.getTitle() == null) { - generalMonitoringDTO.setActivityTitle("Questions and Answers"); - generalMonitoringDTO.setActivityInstructions("Please answer the questions."); - } else { - generalMonitoringDTO.setActivityTitle(qaContent.getTitle()); - generalMonitoringDTO.setActivityInstructions(qaContent.getInstructions()); - } - - /* getting stats screen content from here... */ - int countAllUsers = qaService.getTotalNumberOfUsers(qaContent); - if (countAllUsers == 0) { - //error: countAllUsers is 0 - generalMonitoringDTO.setUserExceptionNoStudentActivity(new Boolean(true).toString()); - } - - generalMonitoringDTO.setCountAllUsers(new Integer(countAllUsers).toString()); - - request.setAttribute(QaAppConstants.QA_GENERAL_MONITORING_DTO, generalMonitoringDTO); - MonitoringUtil.setUpMonitoring(request, qaService, qaContent); qaMonitoringForm.setCurrentTab("1"); @@ -125,38 +102,25 @@ /* this section is related to summary tab. Starts here. */ - generalMonitoringDTO.setContentFolderID(contentFolderID); - int countSessionComplete = qaService.countSessionComplete(qaContent); - generalMonitoringDTO.setCountSessionComplete(new Integer(countSessionComplete).toString()); - request.setAttribute(QaAppConstants.QA_GENERAL_MONITORING_DTO, generalMonitoringDTO); - - qaMonitoringForm.setActiveModule(MONITORING); - - /*for Edit Activity screen, BasicTab-ViewOnly*/ - QaGeneralAuthoringDTO qaGeneralAuthoringDTO = new QaGeneralAuthoringDTO(); - qaGeneralAuthoringDTO.setActivityTitle(qaContent.getTitle()); - qaGeneralAuthoringDTO.setActivityInstructions(qaContent.getInstructions()); - request.setAttribute(QaAppConstants.QA_GENERAL_AUTHORING_DTO, qaGeneralAuthoringDTO); - SessionMap sessionMap = new SessionMap(); sessionMap.put(ACTIVITY_TITLE_KEY, qaContent.getTitle()); sessionMap.put(ACTIVITY_INSTRUCTIONS_KEY, qaContent.getInstructions()); qaMonitoringForm.setHttpSessionID(sessionMap.getSessionID()); request.getSession().setAttribute(sessionMap.getSessionID(), sessionMap); - List listQuestionContentDTO = new LinkedList(); + List questionDTOs = new LinkedList(); Iterator queIterator = qaContent.getQaQueContents().iterator(); while (queIterator.hasNext()) { QaQueContent qaQuestion = (QaQueContent) queIterator.next(); if (qaQuestion != null) { QaQuestionDTO qaQuestionDTO = new QaQuestionDTO(qaQuestion); - listQuestionContentDTO.add(qaQuestionDTO); + questionDTOs.add(qaQuestionDTO); } } - request.setAttribute(LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - sessionMap.put(LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); - request.setAttribute(TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); + request.setAttribute(LIST_QUESTION_DTOS, questionDTOs); + sessionMap.put(LIST_QUESTION_DTOS, questionDTOs); + request.setAttribute(TOTAL_QUESTION_COUNT, new Integer(questionDTOs.size())); // preserve conditions into sessionMap SortedSet conditionSet = new TreeSet(new TextSearchConditionComparator()); Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaPedagogicalPlannerAction.java =================================================================== diff -u -rbe07c35c372d904a65581d98660e73f3b13b69db -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaPedagogicalPlannerAction.java (.../QaPedagogicalPlannerAction.java) (revision be07c35c372d904a65581d98660e73f3b13b69db) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaPedagogicalPlannerAction.java (.../QaPedagogicalPlannerAction.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -58,7 +58,7 @@ HttpServletResponse response) { QaPedagogicalPlannerForm plannerForm = (QaPedagogicalPlannerForm) form; Long toolContentID = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID); - QaContent qaContent = getQaService().getQa(toolContentID); + QaContent qaContent = getQaService().getQaContent(toolContentID); plannerForm.fillForm(qaContent); String contentFolderId = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); plannerForm.setContentFolderID(contentFolderId); @@ -71,7 +71,7 @@ ActionMessages errors = plannerForm.validate(); if (errors.isEmpty()) { - QaContent qaContent = getQaService().getQa(plannerForm.getToolContentID()); + QaContent qaContent = getQaService().getQaContent(plannerForm.getToolContentID()); int questionIndex = 0; String question = null; @@ -85,25 +85,26 @@ QaQueContent qaQuestion = getQaService().getQuestionByContentAndDisplayOrder( (long) questionIndex + 1, qaContent.getUid()); qaQuestion.setQuestion(question); - getQaService().saveOrUpdateQaQueContent(qaQuestion); + getQaService().saveOrUpdateQuestion(qaQuestion); } else { QaQueContent qaQuestion = new QaQueContent(); qaQuestion.setDisplayOrder(questionIndex + 1); qaQuestion.setRequired(false); qaQuestion.setQaContent(qaContent); qaQuestion.setQuestion(question); - getQaService().saveOrUpdateQaQueContent(qaQuestion); + getQaService().saveOrUpdateQuestion(qaQuestion); } questionIndex++; } } while (question != null); if (questionIndex < qaContent.getQaQueContents().size()) { getQaService().removeQuestionsFromCache(qaContent); + getQaService().removeQaContentFromCache(qaContent); for (; questionIndex < qaContent.getQaQueContents().size(); questionIndex++) { QaQueContent qaQuestion = getQaService().getQuestionByContentAndDisplayOrder( (long) questionIndex + 1, qaContent.getUid()); - getQaService().removeQaQueContent(qaQuestion); + getQaService().removeQuestion(qaQuestion); } } } else { Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaStarterAction.java =================================================================== diff -u -rc5457cc74f3986b393bc2947604b17168ba54dfb -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaStarterAction.java (.../QaStarterAction.java) (revision c5457cc74f3986b393bc2947604b17168ba54dfb) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaStarterAction.java (.../QaStarterAction.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -21,109 +21,11 @@ * **************************************************************** */ -/** - * @author Ozgur Demirtas - * - * Created on 8/03/2005 - * - * initializes the tool's authoring mode - */ - -/** - * Tool path The URL path for the tool should be /tool/$TOOL_SIG. - * - * CONTENT_LOCKED ->CONTENT_IN_USE - * - * QaStarterAction loads the default content and initializes the presentation Map - * Requests can come either from authoring envuironment or from the monitoring environment for Edit Activity screen - * - * Check QaUtils.createAuthoringUser again User Management Service is ready - * - * */ - -/** - * - * Tool Content: - * - * While tool's manage their own content, the LAMS core and the tools work together to create and use the content. - * The tool content id (toolContentID) is the key by which the tool and the LAMS core discuss data - - * it is generated by the LAMS core and supplied to the tool whenever content needs to be stored. - * The LAMS core will refer to the tool content id whenever the content needs to be used. - * Tool content will be covered in more detail in following sections. - * - * Each tool will have one piece of content that is the default content. - * The tool content id for this content is created as part of the installation process. - * Whenever a tool is asked for some tool content that does not exist, it should supply the default tool content. - * This will allow the system to render the normal screen, albeit with useless information, rather than crashing. - */ - -/** - * - * Authoring URL: - * - * The tool must supply an authoring module, which will be called to create new content or edit existing content. It will be called by an authoring URL using the following format: ????? - * The initial data displayed on the authoring screen for a new tool content id may be the default tool content. - * - * Authoring UI data consists of general Activity data fields and the Tool specific data fields. - * The authoring interface will have three tabs. The mandatory (and suggested) fields are given. Each tool will have its own fields which it will add on any of the three tabs, as appropriate to the tabs' function. - * - * Basic: Displays the basic set of fields that are needed for the tool, and it could be expected that a new LAMS user would use. Mandatory fields: Title, Instructions. - * Advanced: Displays the extra fields that would be used by experienced LAMS users. Optional fields: Lock On Finish, Make Responses Anonymous - * Instructions: Displays the "instructions" fields for teachers. Mandatory fields: Online instructions, Offline instructions, Document upload. - * The "Define Later" and "Run Offline" options are set on the Flash authoring part, and not on the tool's authoring screens. - * - * Preview The tool must be able to show the specified content as if it was running in a lesson. It will be the learner url with tool access mode set to ToolAccessMode.AUTHOR. - * Export The tool must be able to export its tool content for part of the overall learning design export. - * - * The format of the serialization for export is XML. Tool will define extra namespace inside the element to add a new data element (type). Inside the data element, it can further define more structures and types as it seems fit. - * The data elements must be "version" aware. The data elements must be "type" aware if they are to be shared between Tools. - * - * - - - - - - - - - - - - - - - - * - */ - /* $$Id$$ */ package org.lamsfoundation.lams.tool.qa.web; import java.io.IOException; +import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -134,6 +36,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.apache.struts.Globals; import org.apache.struts.action.Action; @@ -143,6 +46,7 @@ import org.apache.struts.action.ActionMessage; import org.apache.struts.action.ActionMessages; import org.lamsfoundation.lams.learningdesign.TextSearchConditionComparator; +import org.lamsfoundation.lams.tool.ToolAccessMode; import org.lamsfoundation.lams.tool.qa.QaAppConstants; import org.lamsfoundation.lams.tool.qa.QaCondition; import org.lamsfoundation.lams.tool.qa.QaContent; @@ -159,6 +63,8 @@ import org.lamsfoundation.lams.web.util.SessionMap; /** + * Initializes the tool's authoring mode + * * @author Ozgur Demirtas */ public class QaStarterAction extends Action implements QaAppConstants { @@ -188,113 +94,48 @@ qaGeneralAuthoringDTO.setCurrentTab("1"); - qaGeneralAuthoringDTO.setMonitoringOriginatedDefineLater(new Boolean(false).toString()); - String servletPath = request.getServletPath(); - String requestedModule = null; - if (servletPath.indexOf("authoringStarter") > 0) { - qaGeneralAuthoringDTO.setActiveModule(QaAppConstants.AUTHORING); - qaGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - qaGeneralAuthoringDTO.setShowAuthoringTabs(new Boolean(true).toString()); - qaAuthoringForm.setActiveModule(QaAppConstants.AUTHORING); - requestedModule = QaAppConstants.AUTHORING; - } else { - //request is for define later module either direcly from define later url or monitoring url - qaGeneralAuthoringDTO.setActiveModule(QaAppConstants.DEFINE_LATER); - qaGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); - qaGeneralAuthoringDTO.setShowAuthoringTabs(new Boolean(false).toString()); - qaAuthoringForm.setActiveModule(QaAppConstants.DEFINE_LATER); - requestedModule = QaAppConstants.DEFINE_LATER; + validateDefaultContent(request, mapping, qaService, qaGeneralAuthoringDTO, qaAuthoringForm); - if (servletPath.indexOf("monitoring") > 0) { - //request is from monitoring url - qaGeneralAuthoringDTO.setMonitoringOriginatedDefineLater(new Boolean(true).toString()); - } - } - qaGeneralAuthoringDTO.setRequestedModule(requestedModule); - - /* in development this needs to be called only once. */ - /* QaUtils.configureContentRepository(request); */ - - String sourceMcStarter = (String) request.getAttribute(QaAppConstants.SOURCE_MC_STARTER); - - boolean validateSignature = readSignature(request, mapping, qaService, qaGeneralAuthoringDTO, qaAuthoringForm); - - /* mark the http session as an authoring activity */ - qaGeneralAuthoringDTO.setTargetMode(QaAppConstants.TARGET_MODE_AUTHORING); - - /* - * find out whether the request is coming from monitoring module for EditActivity tab or from authoring - * environment url - */ //no problems getting the default content, will render authoring screen String strToolContentID = ""; /* the authoring url must be passed a tool content id */ strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); qaGeneralAuthoringDTO.setToolContentID(strToolContentID); + qaAuthoringForm.setToolContentID(strToolContentID); - SessionMap sessionMap = new SessionMap(); - List sequentialCheckedCa = new LinkedList(); + SessionMap sessionMap = new SessionMap(); sessionMap.put(QaAppConstants.ACTIVITY_TITLE_KEY, ""); sessionMap.put(QaAppConstants.ACTIVITY_INSTRUCTIONS_KEY, ""); + sessionMap.put(AttributeNames.PARAM_CONTENT_FOLDER_ID, contentFolderID); qaAuthoringForm.setHttpSessionID(sessionMap.getSessionID()); qaGeneralAuthoringDTO.setHttpSessionID(sessionMap.getSessionID()); - String defaultContentId = null; - // pay attention here: remove - // request.getSession().getAttribute(TOOL_CONTENT_ID); - if (strToolContentID == null) { - /* - * it is possible that the original request for authoring module is coming from monitoring url which keeps - * the TOOL_CONTENT_ID in the session - */ - //strToolContentID is null, handle this - - Long toolContentID = (Long) request.getSession().getAttribute(QaAppConstants.TOOL_CONTENT_ID); - if (toolContentID != null) { - strToolContentID = toolContentID.toString(); - } else { - //we should IDEALLY not arrive here. The TOOL_CONTENT_ID is NOT available from the url or the session - /* use default content instead of giving a warning */ - defaultContentId = qaAuthoringForm.getDefaultContentIdStr(); - strToolContentID = defaultContentId; - } - } - if (strToolContentID == null || strToolContentID.equals("")) { QaUtils.cleanUpSessionAbsolute(request); throw new ServletException("No Tool Content ID found"); } - qaAuthoringForm.setToolContentID(strToolContentID); - - /* - * find out if the passed tool content id exists in the db present user either a first timer screen with default - * content data or fetch the existing content. - * - * if the toolcontentid does not exist in the db, create the default Map, there is no need to check if the - * content is locked in this case. It is always unlocked since it is the default content. - */ - - String defaultContentIdStr = null; - QaContent qaContent = null; - if (!existsContent(new Long(strToolContentID).longValue(), qaService)) { + QaContent qaContent = qaService.getQaContent(new Long(strToolContentID).longValue()); + if (qaContent == null) { /* fetch default content */ - defaultContentIdStr = qaAuthoringForm.getDefaultContentIdStr(); - qaContent = retrieveContent(request, mapping, qaAuthoringForm, new Long( - defaultContentIdStr).longValue(), true, qaService, qaGeneralAuthoringDTO, sessionMap); + long defaultContentID = qaService.getToolDefaultContentIdBySignature(QaAppConstants.MY_SIGNATURE); + qaContent = qaService.getQaContent(defaultContentID); + qaContent = QaContent.newInstance(qaContent, new Long(strToolContentID)); - } else { - /* it is possible that the content is in use by learners. */ - qaContent = qaService.getQa(new Long(strToolContentID).longValue()); - - if (qaService.isStudentActivityOccurredGlobal(qaContent)) { - QaUtils.cleanUpSessionAbsolute(request); - throw new ServletException("Content in use"); + if (qaContent.getConditions().isEmpty()) { + qaContent.getConditions().add(qaService.createDefaultComplexCondition(qaContent)); } - qaContent = retrieveContent(request, mapping, qaAuthoringForm, new Long( - strToolContentID).longValue(), false, qaService, qaGeneralAuthoringDTO, sessionMap); } + prepareDTOandForm(request, qaAuthoringForm, qaContent, qaService, qaGeneralAuthoringDTO, sessionMap); + + ToolAccessMode mode = getAccessMode(request); + // request is from monitoring module + if (mode.isTeacher()) { + QaUtils.setDefineLater(request, true, strToolContentID, qaService); + } + request.setAttribute(AttributeNames.ATTR_MODE, mode.toString()); + SortedSet conditionList = getQaConditionList(sessionMap); conditionList.clear(); conditionList.addAll(qaContent.getConditions()); @@ -306,18 +147,15 @@ qaAuthoringForm.setUseSelectLeaderToolOuput(qaContent.isUseSelectLeaderToolOuput()); sessionMap.put(QaAppConstants.ATTR_QA_AUTHORING_FORM, qaAuthoringForm); - - String destination = QaUtils.getDestination(sourceMcStarter, requestedModule); request.getSession().setAttribute(sessionMap.getSessionID(), sessionMap); request.setAttribute(QaAppConstants.QA_GENERAL_AUTHORING_DTO, qaGeneralAuthoringDTO); - return mapping.findForward(destination); + return mapping.findForward(LOAD_QUESTIONS); } /** - * retrives the existing content information from the db and prepares the - * data for presentation purposes. + * retrives the existing content information from the db and prepares the data for presentation purposes. * * @param request * @param mapping @@ -326,23 +164,14 @@ * @param toolContentID * @return ActionForward */ - protected QaContent retrieveContent(HttpServletRequest request, ActionMapping mapping, - QaAuthoringForm qaAuthoringForm, long toolContentID, boolean isDefaultContent, - IQaService qaService, QaGeneralAuthoringDTO qaGeneralAuthoringDTO, SessionMap sessionMap) { - - QaContent qaContent = qaService.getQa(toolContentID); - if (isDefaultContent && qaContent.getConditions().isEmpty()) { - qaContent.getConditions().add(qaService.createDefaultComplexCondition(qaContent)); - } - + protected QaContent prepareDTOandForm(HttpServletRequest request, QaAuthoringForm qaAuthoringForm, + QaContent qaContent, IQaService qaService, QaGeneralAuthoringDTO qaGeneralAuthoringDTO, + SessionMap sessionMap) { - QaUtils.populateAuthoringDTO(request, qaContent, qaGeneralAuthoringDTO); - qaAuthoringForm.setUsernameVisible(qaContent.isUsernameVisible() ? "1" : "0"); qaAuthoringForm.setAllowRateAnswers(qaContent.isAllowRateAnswers() ? "1" : "0"); qaAuthoringForm.setNotifyTeachersOnResponseSubmit(qaContent.isNotifyTeachersOnResponseSubmit() ? "1" : "0"); qaAuthoringForm.setShowOtherAnswers(qaContent.isShowOtherAnswers() ? "1" : "0"); - qaAuthoringForm.setSynchInMonitor(qaContent.isSynchInMonitor() ? "1" : "0"); qaAuthoringForm.setQuestionsSequenced(qaContent.isQuestionsSequenced() ? "1" : "0"); qaAuthoringForm.setLockWhenFinished(qaContent.isLockWhenFinished() ? "1" : "0"); @@ -353,8 +182,6 @@ qaAuthoringForm.setReflectionSubject(qaContent.getReflectionSubject()); qaGeneralAuthoringDTO.setReflectionSubject(qaContent.getReflectionSubject()); - qaGeneralAuthoringDTO.setIsDefineLater(new Boolean(qaContent.isDefineLater()).toString()); - qaGeneralAuthoringDTO.setActivityTitle(qaContent.getTitle()); qaAuthoringForm.setTitle(qaContent.getTitle()); @@ -364,38 +191,29 @@ sessionMap.put(QaAppConstants.ACTIVITY_TITLE_KEY, qaGeneralAuthoringDTO.getActivityTitle()); sessionMap.put(QaAppConstants.ACTIVITY_INSTRUCTIONS_KEY, qaGeneralAuthoringDTO.getActivityInstructions()); - List listQuestionContentDTO = new LinkedList(); + List questionDTOs = new LinkedList(); /* * get the existing question content */ - boolean isFirst = false; Iterator queIterator = qaContent.getQaQueContents().iterator(); while (queIterator.hasNext()) { QaQueContent qaQuestion = (QaQueContent) queIterator.next(); if (qaQuestion != null) { QaQuestionDTO qaQuestionDTO = new QaQuestionDTO(qaQuestion); - listQuestionContentDTO.add(qaQuestionDTO); - /** - * make the first entry the default(first) one for jsp - */ - if (isFirst) { - qaGeneralAuthoringDTO.setDefaultQuestionContent(qaQuestion.getQuestion()); - isFirst = false; - } + questionDTOs.add(qaQuestionDTO); } } - - request.setAttribute(QaAppConstants.TOTAL_QUESTION_COUNT, new Integer(listQuestionContentDTO.size())); - request.setAttribute(QaAppConstants.LIST_QUESTION_CONTENT_DTO, listQuestionContentDTO); - sessionMap.put(QaAppConstants.LIST_QUESTION_CONTENT_DTO_KEY, listQuestionContentDTO); + request.setAttribute(QaAppConstants.TOTAL_QUESTION_COUNT, new Integer(questionDTOs.size())); + request.setAttribute(QaAppConstants.LIST_QUESTION_DTOS, questionDTOs); + sessionMap.put(QaAppConstants.LIST_QUESTION_DTOS, questionDTOs); SortedSet conditionSet = new TreeSet(new TextSearchConditionComparator()); for (QaCondition condition : qaContent.getConditions()) { conditionSet.add(condition); - for (QaQuestionDTO dto : listQuestionContentDTO) { + for (QaQuestionDTO dto : questionDTOs) { for (QaQueContent question : condition.getQuestions()) { if (dto.getDisplayOrder().equals(String.valueOf(question.getDisplayOrder()))) { condition.temporaryQuestionDTOSet.add(dto); @@ -404,12 +222,10 @@ } } sessionMap.put(QaAppConstants.ATTR_CONDITION_SET, conditionSet); + + List listDeletedQuestionDTOs = new ArrayList(); + sessionMap.put(QaAppConstants.LIST_DELETED_QUESTION_DTOS, listDeletedQuestionDTOs); - if (isDefaultContent) { - qaGeneralAuthoringDTO.setDefaultQuestionContent("Sample Question 1?"); - - } - qaAuthoringForm.resetUserAction(); return qaContent; @@ -425,7 +241,7 @@ * @param mapping * @return ActionForward */ - public boolean readSignature(HttpServletRequest request, ActionMapping mapping, IQaService qaService, + public boolean validateDefaultContent(HttpServletRequest request, ActionMapping mapping, IQaService qaService, QaGeneralAuthoringDTO qaGeneralAuthoringDTO, QaAuthoringForm qaAuthoringForm) { /* @@ -449,7 +265,7 @@ */ try { //retrieve uid of the content based on default content id determined above - QaContent qaContent = qaService.getQa(defaultContentID); + QaContent qaContent = qaService.getQaContent(defaultContentID); if (qaContent == null) { QaStarterAction.logger.error("Exception occured: No default content"); persistError(request, "error.defaultContent.notSetup"); @@ -462,49 +278,10 @@ return false; } - qaGeneralAuthoringDTO.setDefaultContentIdStr(new Long(defaultContentID).toString()); - qaAuthoringForm.setDefaultContentIdStr(new Long(defaultContentID).toString()); - return true; } /** - * existsContent(long toolContentID) - * - * @param long - * toolContentID - * @return boolean determine whether a specific toolContentID exists in the - * db - */ - protected boolean existsContent(long toolContentID, IQaService qaService) { - QaContent qaContent = qaService.getQa(toolContentID); - if (qaContent == null) { - return false; - } - - return true; - } - - /** - * bridges define later url request to authoring functionality - * - * @param mapping - * @param form - * @param request - * @param response - * @param qaService - * @return - * @throws IOException - * @throws ServletException - * @throws QaApplicationException - */ - public ActionForward executeDefineLater(ActionMapping mapping, QaAuthoringForm qaAuthoringForm, - HttpServletRequest request, HttpServletResponse response, IQaService qaService) throws IOException, - ServletException, QaApplicationException { - return execute(mapping, qaAuthoringForm, request, response); - } - - /** * persists error messages to request scope * * @param request @@ -516,12 +293,29 @@ saveErrors(request, errors); } - private SortedSet getQaConditionList(SessionMap sessionMap) { + private SortedSet getQaConditionList(SessionMap sessionMap) { SortedSet list = (SortedSet) sessionMap.get(QaAppConstants.ATTR_CONDITION_SET); if (list == null) { list = new TreeSet(new TextSearchConditionComparator()); sessionMap.put(QaAppConstants.ATTR_CONDITION_SET, list); } return list; } + + /** + * 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; + } } Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/form/QaAuthoringForm.java =================================================================== diff -u -rc5457cc74f3986b393bc2947604b17168ba54dfb -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/form/QaAuthoringForm.java (.../QaAuthoringForm.java) (revision c5457cc74f3986b393bc2947604b17168ba54dfb) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/form/QaAuthoringForm.java (.../QaAuthoringForm.java) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -24,15 +24,11 @@ package org.lamsfoundation.lams.tool.qa.web.form; /* ActionForm for the Authoring environment*/ -import org.apache.commons.lang.builder.ToStringBuilder; import org.lamsfoundation.lams.tool.qa.QaAppConstants; import org.lamsfoundation.lams.tool.qa.service.IQaService; /** * @author Ozgur Demirtas - * - * TODO To change the template for this generated type comment go to Window - - * Preferences - Java - Code Style - Code Templates */ public class QaAuthoringForm extends QaLearningForm implements QaAppConstants { protected String addContent; @@ -48,8 +44,6 @@ protected String choiceAdvanced; protected String choiceInstructions; - protected String activeModule; - /* basic content */ protected String title; protected String instructions; @@ -58,7 +52,6 @@ protected String toolContentID; /* advanced content */ - protected String synchInMonitor; protected String reportTitle; protected String monitoringReportTitle; protected String endLearningMessage; @@ -85,8 +78,6 @@ private boolean required; private String editQuestionBoxRequest; - protected String defineLaterInEditMode; - protected String defaultContentIdStr; protected IQaService qaService; protected boolean allowRichEditor; @@ -126,7 +117,6 @@ this.isRemoveContent = null; this.endLearningMessage = null; - this.synchInMonitor = null; this.reportTitle = null; this.monitoringReportTitle = null; this.questionsSequenced = null; @@ -145,7 +135,6 @@ } public void resetRadioBoxes() { - this.synchInMonitor = OPTION_OFF; this.usernameVisible = OPTION_OFF; this.allowRateAnswers = OPTION_OFF; this.notifyTeachersOnResponseSubmit = OPTION_OFF; @@ -278,21 +267,6 @@ } /** - * @return Returns the syncInMonitor. - */ - public String getSynchInMonitor() { - return synchInMonitor; - } - - /** - * @param syncInMonitor - * The syncInMonitor to set. - */ - public void setSynchInMonitor(String synchInMonitor) { - this.synchInMonitor = synchInMonitor; - } - - /** * @return Returns the choiceAdvanced. */ public String getChoiceAdvanced() { @@ -593,36 +567,6 @@ } /** - * @return Returns the activeModule. - */ - public String getActiveModule() { - return activeModule; - } - - /** - * @param activeModule - * The activeModule to set. - */ - public void setActiveModule(String activeModule) { - this.activeModule = activeModule; - } - - /** - * @return Returns the defaultContentIdStr. - */ - public String getDefaultContentIdStr() { - return defaultContentIdStr; - } - - /** - * @param defaultContentIdStr - * The defaultContentIdStr to set. - */ - public void setDefaultContentIdStr(String defaultContentIdStr) { - this.defaultContentIdStr = defaultContentIdStr; - } - - /** * @return Returns the qaService. */ public IQaService getQaService() { @@ -638,21 +582,6 @@ } /** - * @return Returns the defineLaterInEditMode. - */ - public String getDefineLaterInEditMode() { - return defineLaterInEditMode; - } - - /** - * @param defineLaterInEditMode - * The defineLaterInEditMode to set. - */ - public void setDefineLaterInEditMode(String defineLaterInEditMode) { - this.defineLaterInEditMode = defineLaterInEditMode; - } - - /** * @return Returns the reflect. */ public String getReflect() { Fisheye: Tag a7661f206a3f21114f1c05f9a29f56e20f5e35f0 refers to a dead (removed) revision in file `lams_tool_laqa/web/AuthoringMaincontent.jsp'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_tool_laqa/web/WEB-INF/struts-config.xml =================================================================== diff -u -r9fbb7ff85ea238ebc8699e9ec116eb0cd782ff90 -ra7661f206a3f21114f1c05f9a29f56e20f5e35f0 --- lams_tool_laqa/web/WEB-INF/struts-config.xml (.../struts-config.xml) (revision 9fbb7ff85ea238ebc8699e9ec116eb0cd782ff90) +++ lams_tool_laqa/web/WEB-INF/struts-config.xml (.../struts-config.xml) (revision a7661f206a3f21114f1c05f9a29f56e20f5e35f0) @@ -54,35 +54,17 @@ - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - @@ -397,47 +303,10 @@ parameter="dispatch" unknown="false" validate="true"> - - - - - - - - - - - - - + - <%@ include file="/common/taglibs.jsp"%>