Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/dao/IVoteUsrAttemptDAO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/dao/IVoteUsrAttemptDAO.java,v diff -u -r1.25 -r1.26 --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/dao/IVoteUsrAttemptDAO.java 26 Sep 2006 02:26:48 -0000 1.25 +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/dao/IVoteUsrAttemptDAO.java 18 Feb 2009 23:06:58 -0000 1.26 @@ -44,12 +44,8 @@ public List getUserRecords(final String userEntry); - public List getContentEntries(final Long voteContentUid); - public Set getUserEntries(); - public int getAllEntriesCount(); - public int getUserEnteredVotesCountForContent(final Long voteContentUid); public boolean isVoteVisibleForSession(final String userEntry, final Long voteSessionUid); Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/dao/hibernate/VoteContentDAO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/dao/hibernate/VoteContentDAO.java,v diff -u -r1.6 -r1.7 --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/dao/hibernate/VoteContentDAO.java 9 Dec 2008 05:38:13 -0000 1.6 +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/dao/hibernate/VoteContentDAO.java 18 Feb 2009 23:06:58 -0000 1.7 @@ -40,7 +40,8 @@ /** * @author Ozgur Demirtas *

- * Hibernate implementation for database access to VoteContent for the voting tool. + * Hibernate implementation for database access to VoteContent for the + * voting tool. *

*/ Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/dao/hibernate/VoteQueContentDAO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/dao/hibernate/VoteQueContentDAO.java,v diff -u -r1.7 -r1.8 --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/dao/hibernate/VoteQueContentDAO.java 26 Sep 2006 02:26:51 -0000 1.7 +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/dao/hibernate/VoteQueContentDAO.java 18 Feb 2009 23:06:58 -0000 1.8 @@ -31,217 +31,175 @@ import org.springframework.orm.hibernate3.HibernateTemplate; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; - /** * @author Ozgur Demirtas * - *

Hibernate implementation for database access to VoteQueContent for the vote tool.

+ *

+ * Hibernate implementation for database access to VoteQueContent for the vote + * tool. + *

*/ public class VoteQueContentDAO extends HibernateDaoSupport implements IVoteQueContentDAO { - static Logger logger = Logger.getLogger(VoteQueContentDAO.class.getName()); - - private static final String CLEAN_QUESTION_CONTENT_BY_CONTENT_ID_SIMPLE = "from voteQueContent in class VoteQueContent where voteQueContent.voteContentId=:voteContentId"; - - private static final String LOAD_QUESTION_CONTENT_BY_CONTENT_ID = "from voteQueContent in class VoteQueContent where voteQueContent.voteContentId=:voteContentId"; - - private static final String LOAD_QUESTION_CONTENT_BY_QUESTION_TEXT = "from voteQueContent in class VoteQueContent where voteQueContent.question=:question and voteQueContent.voteContentId=:voteContentUid"; - - private static final String LOAD_QUESTION_CONTENT_BY_DISPLAY_ORDER = "from voteQueContent in class VoteQueContent where voteQueContent.displayOrder=:displayOrder and voteQueContent.voteContentId=:voteContentUid"; - - private static final String SORT_QUESTION_CONTENT_BY_DISPLAY_ORDER = "from voteQueContent in class VoteQueContent where voteQueContent.voteContentId=:voteContentId order by voteQueContent.displayOrder"; - - - public VoteQueContent getVoteQueContentByUID(Long uid) - { - return (VoteQueContent) this.getHibernateTemplate() - .get(VoteQueContent.class, uid); - } - - - public VoteQueContent getToolDefaultQuestionContent(final long voteContentId) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_QUESTION_CONTENT_BY_CONTENT_ID) - .setLong("voteContentId", voteContentId) - .list(); - - if(list != null && list.size() > 0){ - VoteQueContent voteq = (VoteQueContent) list.get(0); - return voteq; - } - return null; - } - - - public List getVoteQueContentsByContentId(long voteContentId){ - return getHibernateTemplate().findByNamedParam(LOAD_QUESTION_CONTENT_BY_CONTENT_ID, "voteContentId", new Long(voteContentId)); - } - - public List getAllQuestionEntries(final long voteContentId) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_QUESTION_CONTENT_BY_CONTENT_ID) - .setLong("voteContentId", voteContentId) - .list(); + static Logger logger = Logger.getLogger(VoteQueContentDAO.class.getName()); - return list; - } - - - public VoteQueContent getQuestionContentByQuestionText(final String question, final Long voteContentUid) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_QUESTION_CONTENT_BY_QUESTION_TEXT) - .setString("question", question) - .setLong("voteContentUid", voteContentUid.longValue()) - .list(); - - if(list != null && list.size() > 0){ - VoteQueContent voteq = (VoteQueContent) list.get(0); - return voteq; - } - return null; - } - - - public VoteQueContent getQuestionContentByDisplayOrder(final Long displayOrder, final Long voteContentUid) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_QUESTION_CONTENT_BY_DISPLAY_ORDER) - .setLong("displayOrder", displayOrder.longValue()) - .setLong("voteContentUid", voteContentUid.longValue()) - .list(); - - if(list != null && list.size() > 0){ - VoteQueContent voteq = (VoteQueContent) list.get(0); - return voteq; - } - return null; - } + private static final String CLEAN_QUESTION_CONTENT_BY_CONTENT_ID_SIMPLE = "from voteQueContent in class VoteQueContent where voteQueContent.voteContentId=:voteContentId"; - - public void removeQuestionContentByVoteUid(final Long voteContentUid) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_QUESTION_CONTENT_BY_CONTENT_ID) - .setLong("voteContentId", voteContentUid.longValue()) - .list(); + private static final String LOAD_QUESTION_CONTENT_BY_CONTENT_ID = "from voteQueContent in class VoteQueContent where voteQueContent.voteContentId=:voteContentId"; - if(list != null && list.size() > 0){ - Iterator listIterator=list.iterator(); - while (listIterator.hasNext()) - { - VoteQueContent voteQueContent=(VoteQueContent)listIterator.next(); - this.getSession().setFlushMode(FlushMode.AUTO); - templ.delete(voteQueContent); - templ.flush(); - } - } - } - + private static final String LOAD_QUESTION_CONTENT_BY_QUESTION_TEXT = "from voteQueContent in class VoteQueContent where voteQueContent.question=:question and voteQueContent.voteContentId=:voteContentUid"; - public void resetAllQuestions(final Long voteContentUid) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_QUESTION_CONTENT_BY_CONTENT_ID) - .setLong("voteContentId", voteContentUid.longValue()) - .list(); + private static final String LOAD_QUESTION_CONTENT_BY_DISPLAY_ORDER = "from voteQueContent in class VoteQueContent where voteQueContent.displayOrder=:displayOrder and voteQueContent.voteContentId=:voteContentUid"; - if(list != null && list.size() > 0){ - Iterator listIterator=list.iterator(); - while (listIterator.hasNext()) - { - VoteQueContent voteQueContent=(VoteQueContent)listIterator.next(); - this.getSession().setFlushMode(FlushMode.AUTO); - templ.update(voteQueContent); - } - } - } - + private static final String SORT_QUESTION_CONTENT_BY_DISPLAY_ORDER = "from voteQueContent in class VoteQueContent where voteQueContent.voteContentId=:voteContentId order by voteQueContent.displayOrder"; - public void cleanAllQuestions(final Long voteContentUid) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_QUESTION_CONTENT_BY_CONTENT_ID) - .setLong("voteContentId", voteContentUid.longValue()) - .list(); + public VoteQueContent getVoteQueContentByUID(Long uid) { + return (VoteQueContent) this.getHibernateTemplate().get(VoteQueContent.class, uid); + } - if(list != null && list.size() > 0){ - Iterator listIterator=list.iterator(); - while (listIterator.hasNext()) - { - VoteQueContent voteQueContent=(VoteQueContent)listIterator.next(); - this.getSession().setFlushMode(FlushMode.AUTO); - logger.debug("deleting voteQueContent: " + voteQueContent); - templ.delete(voteQueContent); - } - } + public VoteQueContent getToolDefaultQuestionContent(final long voteContentId) { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(LOAD_QUESTION_CONTENT_BY_CONTENT_ID).setLong("voteContentId", + voteContentId).list(); + + if (list != null && list.size() > 0) { + VoteQueContent voteq = (VoteQueContent) list.get(0); + return voteq; + } + return null; + } + + public List getVoteQueContentsByContentId(long voteContentId) { + return getHibernateTemplate().findByNamedParam(LOAD_QUESTION_CONTENT_BY_CONTENT_ID, "voteContentId", + new Long(voteContentId)); + } + + public List getAllQuestionEntries(final long voteContentId) { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(LOAD_QUESTION_CONTENT_BY_CONTENT_ID).setLong("voteContentId", + voteContentId).list(); + + return list; + } + + public VoteQueContent getQuestionContentByQuestionText(final String question, final Long voteContentUid) { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(LOAD_QUESTION_CONTENT_BY_QUESTION_TEXT).setString("question", question) + .setLong("voteContentUid", voteContentUid.longValue()).list(); + + if (list != null && list.size() > 0) { + VoteQueContent voteq = (VoteQueContent) list.get(0); + return voteq; + } + return null; + } + + public VoteQueContent getQuestionContentByDisplayOrder(final Long displayOrder, final Long voteContentUid) { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(LOAD_QUESTION_CONTENT_BY_DISPLAY_ORDER).setLong("displayOrder", + displayOrder.longValue()).setLong("voteContentUid", voteContentUid.longValue()).list(); + + if (list != null && list.size() > 0) { + VoteQueContent voteq = (VoteQueContent) list.get(0); + return voteq; + } + return null; + } + + public void removeQuestionContentByVoteUid(final Long voteContentUid) { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(LOAD_QUESTION_CONTENT_BY_CONTENT_ID).setLong("voteContentId", + voteContentUid.longValue()).list(); + + if (list != null && list.size() > 0) { + Iterator listIterator = list.iterator(); + while (listIterator.hasNext()) { + VoteQueContent voteQueContent = (VoteQueContent) listIterator.next(); + this.getSession().setFlushMode(FlushMode.AUTO); + templ.delete(voteQueContent); + templ.flush(); } + } + } - - public void cleanAllQuestionsSimple(final Long voteContentUid) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(CLEAN_QUESTION_CONTENT_BY_CONTENT_ID_SIMPLE) - .setLong("voteContentId", voteContentUid.longValue()) - .list(); + public void resetAllQuestions(final Long voteContentUid) { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(LOAD_QUESTION_CONTENT_BY_CONTENT_ID).setLong("voteContentId", + voteContentUid.longValue()).list(); - if(list != null && list.size() > 0){ - Iterator listIterator=list.iterator(); - while (listIterator.hasNext()) - { - VoteQueContent voteQueContent=(VoteQueContent)listIterator.next(); - this.getSession().setFlushMode(FlushMode.AUTO); - logger.debug("deleting voteQueContent: " + voteQueContent); - templ.delete(voteQueContent); - } - } + if (list != null && list.size() > 0) { + Iterator listIterator = list.iterator(); + while (listIterator.hasNext()) { + VoteQueContent voteQueContent = (VoteQueContent) listIterator.next(); + this.getSession().setFlushMode(FlushMode.AUTO); + templ.update(voteQueContent); } + } + } - - public List getAllQuestionEntriesSorted(final long voteContentId) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(SORT_QUESTION_CONTENT_BY_DISPLAY_ORDER) - .setLong("voteContentId", voteContentId) - .list(); + public void cleanAllQuestions(final Long voteContentUid) { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(LOAD_QUESTION_CONTENT_BY_CONTENT_ID).setLong("voteContentId", + voteContentUid.longValue()).list(); - return list; + if (list != null && list.size() > 0) { + Iterator listIterator = list.iterator(); + while (listIterator.hasNext()) { + VoteQueContent voteQueContent = (VoteQueContent) listIterator.next(); + this.getSession().setFlushMode(FlushMode.AUTO); + logger.debug("deleting voteQueContent: " + voteQueContent); + templ.delete(voteQueContent); } + } + } + public void cleanAllQuestionsSimple(final Long voteContentUid) { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(CLEAN_QUESTION_CONTENT_BY_CONTENT_ID_SIMPLE).setLong("voteContentId", + voteContentUid.longValue()).list(); - - public void saveVoteQueContent(VoteQueContent voteQueContent) - { - this.getHibernateTemplate().save(voteQueContent); + if (list != null && list.size() > 0) { + Iterator listIterator = list.iterator(); + while (listIterator.hasNext()) { + VoteQueContent voteQueContent = (VoteQueContent) listIterator.next(); + this.getSession().setFlushMode(FlushMode.AUTO); + logger.debug("deleting voteQueContent: " + voteQueContent); + templ.delete(voteQueContent); } - - public void updateVoteQueContent(VoteQueContent voteQueContent) - { - this.getHibernateTemplate().update(voteQueContent); - } - - public void saveOrUpdateVoteQueContent(VoteQueContent voteQueContent) - { - this.getHibernateTemplate().saveOrUpdate(voteQueContent); - } - - public void removeVoteQueContentByUID(Long uid) - { - VoteQueContent voteq = (VoteQueContent)getHibernateTemplate().get(VoteQueContent.class, uid); - this.getSession().setFlushMode(FlushMode.AUTO); - this.getHibernateTemplate().delete(voteq); - } - - - public void removeVoteQueContent(VoteQueContent voteQueContent) - { - this.getSession().setFlushMode(FlushMode.AUTO); - this.getHibernateTemplate().delete(voteQueContent); - } - - public void flush() - { - this.getHibernateTemplate().flush(); - } - } \ No newline at end of file + } + } + + public List getAllQuestionEntriesSorted(final long voteContentId) { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(SORT_QUESTION_CONTENT_BY_DISPLAY_ORDER).setLong("voteContentId", + voteContentId).list(); + + return list; + } + + public void saveVoteQueContent(VoteQueContent voteQueContent) { + this.getHibernateTemplate().save(voteQueContent); + } + + public void updateVoteQueContent(VoteQueContent voteQueContent) { + this.getHibernateTemplate().update(voteQueContent); + } + + public void saveOrUpdateVoteQueContent(VoteQueContent voteQueContent) { + this.getHibernateTemplate().saveOrUpdate(voteQueContent); + } + + public void removeVoteQueContentByUID(Long uid) { + VoteQueContent voteq = (VoteQueContent) getHibernateTemplate().get(VoteQueContent.class, uid); + this.getSession().setFlushMode(FlushMode.AUTO); + this.getHibernateTemplate().delete(voteq); + } + + public void removeVoteQueContent(VoteQueContent voteQueContent) { + this.getSession().setFlushMode(FlushMode.AUTO); + this.getHibernateTemplate().delete(voteQueContent); + } + + public void flush() { + this.getHibernateTemplate().flush(); + } +} \ No newline at end of file Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/dao/hibernate/VoteUsrAttemptDAO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/dao/hibernate/VoteUsrAttemptDAO.java,v diff -u -r1.31 -r1.32 --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/dao/hibernate/VoteUsrAttemptDAO.java 26 Sep 2006 02:26:51 -0000 1.31 +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/dao/hibernate/VoteUsrAttemptDAO.java 18 Feb 2009 23:06:58 -0000 1.32 @@ -39,671 +39,455 @@ import org.springframework.orm.hibernate3.support.HibernateDaoSupport; /** - * @author Ozgur Demirtas - *

Hibernate implementation for database access to VoteUsrAttemptDAO for the voting tool.

+ * @author Ozgur Demirtas repaired by lfoxton + *

+ * Hibernate implementation for database access to VoteUsrAttemptDAO for + * the voting tool. + *

*/ public class VoteUsrAttemptDAO extends HibernateDaoSupport implements IVoteUsrAttemptDAO { - static Logger logger = Logger.getLogger(VoteUsrAttemptDAO.class.getName()); - - private IVoteUserDAO voteUserDAO; - - private static final String LOAD_ATTEMPT_FOR_QUE_CONTENT = "from voteUsrAttempt in class VoteUsrAttempt where voteUsrAttempt.queUsrId=:queUsrId and voteUsrAttempt.voteQueContentId=:voteQueContentId"; - - private static final String LOAD_ATTEMPT_FOR_USER = "from voteUsrAttempt in class VoteUsrAttempt where voteUsrAttempt.queUsrId=:queUsrId"; + static Logger logger = Logger.getLogger(VoteUsrAttemptDAO.class.getName()); - private static final String LOAD_ATTEMPT_FOR_QUESTION_CONTENT = "from voteUsrAttempt in class VoteUsrAttempt where voteUsrAttempt.voteQueContentId=:voteQueContentId"; - - private static final String LOAD_ATTEMPT_FOR_USER_AND_QUESTION_CONTENT = "from voteUsrAttempt in class VoteUsrAttempt where voteUsrAttempt.queUsrId=:queUsrId and voteUsrAttempt.voteQueContentId=:voteQueContentId"; - - private static final String LOAD_ATTEMPT_FOR_USER_AND_QUESTION_CONTENT_AND_SESSION = "from voteUsrAttempt in class VoteUsrAttempt where voteUsrAttempt.queUsrId=:queUsrId and voteUsrAttempt.voteQueContentId=:voteQueContentId"; - - private static final String LOAD_ATTEMPT_FOR_USER_AND_SESSION = "from voteUsrAttempt in class VoteUsrAttempt where voteUsrAttempt.queUsrId=:queUsrId"; - - private static final String LOAD_USER_ENTRIES = "select distinct voteUsrAttempt.userEntry from VoteUsrAttempt voteUsrAttempt"; - - private static final String LOAD_USER_ENTRY_RECORDS = "from voteUsrAttempt in class VoteUsrAttempt where voteUsrAttempt.userEntry=:userEntry and voteUsrAttempt.voteQueContentId=1 "; - - private static final String LOAD_DISTINCT_USER_ENTRY_RECORDS = "select distinct voteUsrAttempt.queUsrId from VoteUsrAttempt voteUsrAttempt where voteUsrAttempt.userEntry=:userEntry"; - - private static final String LOAD_ALL_ENTRIES = "from voteUsrAttempt in class VoteUsrAttempt"; - - private static final String LOAD_DISTINCT_USER_ENTRIES = "select distinct voteUsrAttempt.queUsrId from VoteUsrAttempt voteUsrAttempt"; - - - public VoteUsrAttempt getVoteUserAttemptByUID(Long uid) - { - return (VoteUsrAttempt) this.getHibernateTemplate() - .get(VoteUsrAttempt.class, uid); - } - - - public VoteUsrAttempt getAttemptByUID(Long uid) - { - String query = "from VoteUsrAttempt attempt where attempt.uid=?"; - - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(query) - .setLong(0,uid.longValue()) - .list(); - - if(list != null && list.size() > 0){ - VoteUsrAttempt attempt = (VoteUsrAttempt) list.get(0); - return attempt; - } - return null; - } + private IVoteUserDAO voteUserDAO; - - - public void saveVoteUsrAttempt(VoteUsrAttempt voteUsrAttempt) - { - this.getHibernateTemplate().save(voteUsrAttempt); - } - - - public List getAttemptsForUser(final Long queUsrId) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_ATTEMPT_FOR_USER) - .setLong("queUsrId", queUsrId.longValue()) - .list(); - return list; - } + private static final String LOAD_ATTEMPT_FOR_QUE_CONTENT = "from voteUsrAttempt in class VoteUsrAttempt where voteUsrAttempt.queUsrId=:queUsrId and voteUsrAttempt.voteQueContentId=:voteQueContentId"; - public List getContentEntries(final Long voteContentUid) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_ALL_ENTRIES) - .list(); + private static final String LOAD_ATTEMPT_FOR_USER = "from voteUsrAttempt in class VoteUsrAttempt where voteUsrAttempt.queUsrId=:queUsrId"; - List contentEntries= new ArrayList(); - Iterator listIterator=list.iterator(); - logger.debug("looking for voteContentUid: " + voteContentUid); - while (listIterator.hasNext()) - { - VoteUsrAttempt attempt=(VoteUsrAttempt)listIterator.next(); - logger.debug("attempt: " + attempt); - if (attempt.getVoteQueUsr().getVoteSession().getVoteContent().getUid().toString().equals(voteContentUid.toString())) - { - logger.debug("found content: " + voteContentUid); - if (attempt.getVoteQueContentId().toString().equals("1")) - { - logger.debug("user entered nomination: " + attempt.getUserEntry()); - if ((attempt.getUserEntry() != null) && (attempt.getUserEntry().length() > 0)) - contentEntries.add(attempt.getUserEntry()); - } - else - { - logger.debug("standard content nomination: " + attempt.getVoteQueContent().getQuestion()); - contentEntries.add(attempt.getVoteQueContent().getQuestion()); - } - } - } - - return contentEntries; - } + private static final String LOAD_ATTEMPT_FOR_QUESTION_CONTENT = "from voteUsrAttempt in class VoteUsrAttempt where voteUsrAttempt.voteQueContentId=:voteQueContentId"; - - public int getUserEnteredVotesCountForContent(final Long voteContentUid) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_ALL_ENTRIES) - .list(); + private static final String LOAD_ATTEMPT_FOR_USER_AND_QUESTION_CONTENT = "from voteUsrAttempt in class VoteUsrAttempt where voteUsrAttempt.queUsrId=:queUsrId and voteUsrAttempt.voteQueContentId=:voteQueContentId"; - int count=0; - Iterator listIterator=list.iterator(); - logger.debug("looking for voteContentUid: " + voteContentUid); - while (listIterator.hasNext()) - { - VoteUsrAttempt attempt=(VoteUsrAttempt)listIterator.next(); - logger.debug("attempt: " + attempt); - - if (attempt.getVoteQueUsr().getVoteSession().getVoteContent().getUid().toString().equals(voteContentUid.toString())) - { - ++count; - } - } - - return count; - } + private static final String LOAD_ATTEMPT_FOR_USER_AND_QUESTION_CONTENT_AND_SESSION = "from voteUsrAttempt in class VoteUsrAttempt where voteUsrAttempt.queUsrId=:queUsrId and voteUsrAttempt.voteQueContentId=:voteQueContentId"; - - - public Set getUserEntries() - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_USER_ENTRIES) - .list(); - - Set set= new HashSet(); - - Set userEntries= new HashSet(); - if(list != null && list.size() > 0){ - Iterator listIterator=list.iterator(); - while (listIterator.hasNext()) - { - String entry=(String)listIterator.next(); - logger.debug("entry: " + entry); - if ((entry != null) && (entry.length() > 0)) - userEntries.add(entry); - } - } - return userEntries; - } - + private static final String LOAD_ATTEMPT_FOR_USER_AND_SESSION = "from voteUsrAttempt in class VoteUsrAttempt where voteUsrAttempt.queUsrId=:queUsrId"; - public List getSessionUserEntries(final Long voteSessionUid) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_ALL_ENTRIES) - .list(); + private static final String LOAD_USER_ENTRIES = "select distinct voteUsrAttempt.userEntry from VoteUsrAttempt voteUsrAttempt"; - List sessionUserEntries= new ArrayList(); - if(list != null && list.size() > 0){ - Iterator listIterator=list.iterator(); - while (listIterator.hasNext()) - { - VoteUsrAttempt attempt=(VoteUsrAttempt)listIterator.next(); - logger.debug("attempt: " + attempt); - if (attempt.getVoteQueUsr().getVoteSession().getUid().toString().equals(voteSessionUid.toString())) - { - if ((attempt.getUserEntry() != null) && (attempt.getUserEntry().length() > 0)) - sessionUserEntries.add(attempt.getUserEntry()); - } - } - } - return sessionUserEntries; - } + private static final String LOAD_USER_ENTRY_RECORDS = "from voteUsrAttempt in class VoteUsrAttempt where voteUsrAttempt.userEntry=:userEntry and voteUsrAttempt.voteQueContentId=1 "; - public Set getSessionUserEntriesSet(final Long voteSessionUid) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_ALL_ENTRIES) - .list(); + private static final String LOAD_DISTINCT_USER_ENTRY_RECORDS = "select distinct voteUsrAttempt.queUsrId from VoteUsrAttempt voteUsrAttempt where voteUsrAttempt.userEntry=:userEntry"; - Set sessionUserEntries= new HashSet(); - if(list != null && list.size() > 0){ - Iterator listIterator=list.iterator(); - while (listIterator.hasNext()) - { - VoteUsrAttempt attempt=(VoteUsrAttempt)listIterator.next(); - logger.debug("attempt: " + attempt); - if (attempt.getVoteQueUsr().getVoteSession().getUid().toString().equals(voteSessionUid.toString())) - { - if ((attempt.getUserEntry() != null) && (attempt.getUserEntry().length() > 0)) - sessionUserEntries.add(attempt.getUserEntry()); - } - } - } - return sessionUserEntries; - } - - public int getUserRecordsEntryCount(final String userEntry) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_DISTINCT_USER_ENTRY_RECORDS) - .setString("userEntry", userEntry) - .list(); + // lfoxton about below: + // No! Very Bad programmer!!! Go to your room and think about what you did! + //private static final String LOAD_ALL_ENTRIES = "from voteUsrAttempt in class VoteUsrAttempt"; - if(list != null && list.size() > 0){ - return list.size(); - } - - return 0; - } - + private static final String LOAD_DISTINCT_USER_ENTRIES = "select distinct voteUsrAttempt.queUsrId from VoteUsrAttempt voteUsrAttempt"; - public int getSessionUserRecordsEntryCount(final String userEntry, final Long voteSessionUid, IVoteService voteService) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_DISTINCT_USER_ENTRY_RECORDS) - .setString("userEntry", userEntry) - .list(); - - int entryCount=0; + private static final String COUNT_ATTEMPTS_BY_CONTENT_ID = "select count(*) from VoteUsrAttempt att, VoteQueUsr user, VoteSession ses where " + + "att.voteQueUsr=user and user.voteSession=ses and " + "ses.voteContentId=:voteContentId"; + + private static final String LOAD_ENTRIES_BY_SESSION_ID = "select att from VoteUsrAttempt att, VoteQueUsr user, VoteSession ses where " + + "att.voteQueUsr=user and user.voteSession=ses and ses.uid=:voteSessionUid"; + + private static final String COUNT_ENTRIES_BY_SESSION_ID = "select count(*) from VoteUsrAttempt att, VoteQueUsr user, VoteSession ses where " + + "att.voteQueUsr=user and user.voteSession=ses and ses.uid=:voteSessionUid"; - if(list != null && list.size() > 0){ - Iterator listIterator=list.iterator(); - while (listIterator.hasNext()) - { - Long userId=(Long)listIterator.next(); - logger.debug("userId: " + userId); - logger.debug("voteService: " + voteService); - VoteQueUsr voteQueUsr=voteService.getVoteUserByUID(userId); - logger.debug("voteQueUsr: " + voteQueUsr); - - if (voteQueUsr.getVoteSession().getUid().toString().equals(voteSessionUid.toString())) - { - ++entryCount; - } - } - } - return entryCount; - } - - - public void removeAttemptsForUser(final Long queUsrId) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_ATTEMPT_FOR_USER) - .setLong("queUsrId", queUsrId.longValue()) - .list(); - - if(list != null && list.size() > 0){ - Iterator listIterator=list.iterator(); - while (listIterator.hasNext()) - { - VoteUsrAttempt attempt=(VoteUsrAttempt)listIterator.next(); - this.getSession().setFlushMode(FlushMode.AUTO); - templ.delete(attempt); - templ.flush(); - } - } - } + public VoteUsrAttempt getVoteUserAttemptByUID(Long uid) { + return (VoteUsrAttempt) this.getHibernateTemplate().get(VoteUsrAttempt.class, uid); + } - public void removeAttemptsForUserandSession(final Long queUsrId, final Long voteSessionId) - { - String strGetUser = "from voteUsrAttempt in class VoteUsrAttempt where voteUsrAttempt.queUsrId=:queUsrId"; - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(strGetUser) - .setLong("queUsrId", queUsrId.longValue()) - .list(); - - if(list != null && list.size() > 0){ - Iterator listIterator=list.iterator(); - while (listIterator.hasNext()) - { - VoteUsrAttempt attempt=(VoteUsrAttempt)listIterator.next(); - if (attempt.getVoteQueUsr().getVoteSession().getUid().toString().equals(voteSessionId.toString())) - { - this.getSession().setFlushMode(FlushMode.AUTO); - templ.delete(attempt); - templ.flush(); - - } - } - } - } + public VoteUsrAttempt getAttemptByUID(Long uid) { + String query = "from VoteUsrAttempt attempt where attempt.uid=?"; + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(query).setLong(0, uid.longValue()).list(); - public int getAttemptsForQuestionContent(final Long voteQueContentId) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_ATTEMPT_FOR_QUESTION_CONTENT) - .setLong("voteQueContentId", voteQueContentId.longValue()) - .list(); - - if(list != null && list.size() > 0){ - return list.size(); - } - - return 0; - } + if (list != null && list.size() > 0) { + VoteUsrAttempt attempt = (VoteUsrAttempt) list.get(0); + return attempt; + } + return null; + } - - public int getStandardAttemptsForQuestionContentAndSessionUid(final Long voteQueContentId, final Long voteSessionUid) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_ATTEMPT_FOR_QUESTION_CONTENT) - .setLong("voteQueContentId", voteQueContentId.longValue()) - .list(); - - List userEntries= new ArrayList(); - if(list != null && list.size() > 0){ - Iterator listIterator=list.iterator(); - while (listIterator.hasNext()) - { - VoteUsrAttempt attempt=(VoteUsrAttempt)listIterator.next(); - if (attempt.getVoteQueUsr().getVoteSession().getUid().toString().equals(voteSessionUid.toString())) - { - userEntries.add(attempt); - } - } - } - return userEntries.size(); + public void saveVoteUsrAttempt(VoteUsrAttempt voteUsrAttempt) { + this.getHibernateTemplate().save(voteUsrAttempt); + } - } - - public List getStandardAttemptUsersForQuestionContentAndSessionUid(final Long voteQueContentId, final Long voteSessionUid) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_ATTEMPT_FOR_QUESTION_CONTENT) - .setLong("voteQueContentId", voteQueContentId.longValue()) - .list(); - - List userEntries= new ArrayList(); - if(list != null && list.size() > 0){ - Iterator listIterator=list.iterator(); - while (listIterator.hasNext()) - { - VoteUsrAttempt attempt=(VoteUsrAttempt)listIterator.next(); - if (attempt.getVoteQueUsr().getVoteSession().getUid().toString().equals(voteSessionUid.toString())) - { - userEntries.add(attempt); - } - } - } - return userEntries; + public List getAttemptsForUser(final Long queUsrId) { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(LOAD_ATTEMPT_FOR_USER).setLong("queUsrId", queUsrId.longValue()).list(); + return list; + } + public int getUserEnteredVotesCountForContent(final Long voteContentUid) { + List result = getSession().createQuery(COUNT_ATTEMPTS_BY_CONTENT_ID).setLong("voteContentId", voteContentUid) + .list(); + Integer resultInt = (result.get(0) != null) ? (Integer) result.get(0) : new Integer(0); + return resultInt.intValue(); + } + + public Set getUserEntries() { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(LOAD_USER_ENTRIES).list(); + + Set set = new HashSet(); + + Set userEntries = new HashSet(); + if (list != null && list.size() > 0) { + Iterator listIterator = list.iterator(); + while (listIterator.hasNext()) { + String entry = (String) listIterator.next(); + logger.debug("entry: " + entry); + if ((entry != null) && (entry.length() > 0)) + userEntries.add(entry); } + } + return userEntries; + } - - - public boolean isVoteVisibleForSession(final String userEntry, final Long voteSessionUid) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_USER_ENTRY_RECORDS) - .setString("userEntry", userEntry) - .list(); - - - List sessionUserEntries= new ArrayList(); - if(list != null && list.size() > 0){ - Iterator listIterator=list.iterator(); - while (listIterator.hasNext()) - { - VoteUsrAttempt attempt=(VoteUsrAttempt)listIterator.next(); - logger.debug("attempt: " + attempt); - if (attempt.getVoteQueUsr().getVoteSession().getUid().toString().equals(voteSessionUid.toString())) - { - boolean isVoteVisible= attempt.isVisible(); - logger.debug("isVoteVisible: " + isVoteVisible); - if (isVoteVisible == false) - return false; - } - } - } - - return true; - } + public List getSessionUserEntries(final Long voteSessionUid) { + + return getSession().createQuery(LOAD_ENTRIES_BY_SESSION_ID).setLong("voteSessionUid", voteSessionUid).list(); + } - public int getStandardAttemptsForQuestionContentAndContentUid(final Long voteQueContentId, final Long voteContentUid) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_ATTEMPT_FOR_QUESTION_CONTENT) - .setLong("voteQueContentId", voteQueContentId.longValue()) - .list(); - - List userEntries= new ArrayList(); - if(list != null && list.size() > 0){ - Iterator listIterator=list.iterator(); - while (listIterator.hasNext()) - { - VoteUsrAttempt attempt=(VoteUsrAttempt)listIterator.next(); - - if (attempt.getVoteQueUsr().getVoteSession().getVoteContent().getUid().toString().equals(voteContentUid.toString())) - { - userEntries.add(attempt); - } - } - } - return userEntries.size(); + public Set getSessionUserEntriesSet(final Long voteSessionUid) { + List list = (List)getSessionUserEntries(voteSessionUid); + Set sessionUserEntries = new HashSet(); + for (VoteUsrAttempt att : list) + { + sessionUserEntries.add(att); + } + return sessionUserEntries; + } + public int getUserRecordsEntryCount(final String userEntry) { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(LOAD_DISTINCT_USER_ENTRY_RECORDS).setString("userEntry", userEntry).list(); + + if (list != null && list.size() > 0) { + return list.size(); + } + + return 0; + } + + public int getSessionUserRecordsEntryCount(final String userEntry, final Long voteSessionUid, + IVoteService voteService) { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(LOAD_DISTINCT_USER_ENTRY_RECORDS).setString("userEntry", userEntry).list(); + + int entryCount = 0; + + if (list != null && list.size() > 0) { + Iterator listIterator = list.iterator(); + while (listIterator.hasNext()) { + Long userId = (Long) listIterator.next(); + logger.debug("userId: " + userId); + logger.debug("voteService: " + voteService); + VoteQueUsr voteQueUsr = voteService.getVoteUserByUID(userId); + logger.debug("voteQueUsr: " + voteQueUsr); + + if (voteQueUsr.getVoteSession().getUid().toString().equals(voteSessionUid.toString())) { + ++entryCount; + } } - - - public List getAttemptsForUserAndQuestionContent(final Long queUsrId, final Long voteQueContentId) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_ATTEMPT_FOR_USER_AND_QUESTION_CONTENT) - .setLong("queUsrId", queUsrId.longValue()) - .setLong("voteQueContentId", voteQueContentId.longValue()) - .list(); - - return list; - } + } + return entryCount; + } - - public VoteUsrAttempt getAttemptsForUserAndQuestionContentAndSession(final Long queUsrId, final Long voteQueContentId, final Long voteSessionId) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_ATTEMPT_FOR_USER_AND_QUESTION_CONTENT_AND_SESSION) - .setLong("queUsrId", queUsrId.longValue()) - .setLong("voteQueContentId", voteQueContentId.longValue()) - .list(); - - if(list != null && list.size() > 0){ - Iterator listIterator=list.iterator(); - while (listIterator.hasNext()) - { - VoteUsrAttempt attempt=(VoteUsrAttempt)listIterator.next(); - logger.debug("attempt: " + attempt); - if (attempt.getVoteQueUsr().getVoteSession().getUid().toString().equals(voteSessionId.toString())) - { - return attempt; - } - } - } - return null; + public void removeAttemptsForUser(final Long queUsrId) { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(LOAD_ATTEMPT_FOR_USER).setLong("queUsrId", queUsrId.longValue()).list(); + + if (list != null && list.size() > 0) { + Iterator listIterator = list.iterator(); + while (listIterator.hasNext()) { + VoteUsrAttempt attempt = (VoteUsrAttempt) listIterator.next(); + this.getSession().setFlushMode(FlushMode.AUTO); + templ.delete(attempt); + templ.flush(); } + } + } - public Set getAttemptsForUserAndSession(final Long queUsrId, final Long voteSessionId) - { - logger.debug("starting getAttemptsForUserAndSession"); - logger.debug("queUsrId: " + queUsrId); - logger.debug("voteSessionId: " + voteSessionId); - - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_ATTEMPT_FOR_USER_AND_SESSION) - .setLong("queUsrId", queUsrId.longValue()) - .list(); - logger.debug("list: " + list); - - Set userEntries= new HashSet(); - if(list != null && list.size() > 0){ - Iterator listIterator=list.iterator(); - while (listIterator.hasNext()) - { - VoteUsrAttempt attempt=(VoteUsrAttempt)listIterator.next(); - logger.debug("attempt: " + attempt); - - if (attempt.getVoteQueUsr().getVoteSession().getUid().toString().equals(voteSessionId.toString())) - { - if (!attempt.getVoteQueContentId().toString().equals("1")) - { - logger.debug("adding attempt question : " + attempt.getVoteQueContent().getQuestion()); - userEntries.add(attempt.getVoteQueContent().getQuestion()); - } - } - } - } - logger.debug("returning userEntries: " + userEntries); - return userEntries; + public void removeAttemptsForUserandSession(final Long queUsrId, final Long voteSessionId) { + String strGetUser = "from voteUsrAttempt in class VoteUsrAttempt where voteUsrAttempt.queUsrId=:queUsrId"; + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(strGetUser).setLong("queUsrId", queUsrId.longValue()).list(); + + if (list != null && list.size() > 0) { + Iterator listIterator = list.iterator(); + while (listIterator.hasNext()) { + VoteUsrAttempt attempt = (VoteUsrAttempt) listIterator.next(); + if (attempt.getVoteQueUsr().getVoteSession().getUid().toString().equals(voteSessionId.toString())) { + this.getSession().setFlushMode(FlushMode.AUTO); + templ.delete(attempt); + templ.flush(); + + } } - + } + } - public Set getAttemptsForUserAndSessionUseOpenAnswer(final Long queUsrId, final Long voteSessionId) - { - logger.debug("starting getAttemptsForUserAndSession"); - logger.debug("queUsrId: " + queUsrId); - logger.debug("voteSessionId: " + voteSessionId); - - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_ATTEMPT_FOR_USER_AND_SESSION) - .setLong("queUsrId", queUsrId.longValue()) - .list(); - logger.debug("list: " + list); - - String openAnswer=""; - Set userEntries= new HashSet(); - if(list != null && list.size() > 0){ - Iterator listIterator=list.iterator(); - while (listIterator.hasNext()) - { - VoteUsrAttempt attempt=(VoteUsrAttempt)listIterator.next(); - logger.debug("attempt: " + attempt); - - if (attempt.getVoteQueUsr().getVoteSession().getUid().toString().equals(voteSessionId.toString())) - { - if (!attempt.getVoteQueContentId().toString().equals("1")) - { - logger.debug("adding attempt question : " + attempt.getVoteQueContent().getQuestion()); - userEntries.add(attempt.getVoteQueContent().getQuestion()); - } - else - { - logger.debug("this is a user entered vote: " + attempt.getUserEntry()); - if (attempt.getUserEntry().length() > 0) - { - openAnswer=attempt.getUserEntry(); - logger.debug("adding openAnswer to userEntries: "); - userEntries.add(openAnswer); - } - - } + public int getAttemptsForQuestionContent(final Long voteQueContentId) { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(LOAD_ATTEMPT_FOR_QUESTION_CONTENT).setLong("voteQueContentId", + voteQueContentId.longValue()).list(); - } - } - } - - logger.debug("final userEntries : " + userEntries); - return userEntries; + if (list != null && list.size() > 0) { + return list.size(); + } + + return 0; + } + + public int getStandardAttemptsForQuestionContentAndSessionUid(final Long voteQueContentId, final Long voteSessionUid) { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(LOAD_ATTEMPT_FOR_QUESTION_CONTENT).setLong("voteQueContentId", + voteQueContentId.longValue()).list(); + + List userEntries = new ArrayList(); + if (list != null && list.size() > 0) { + Iterator listIterator = list.iterator(); + while (listIterator.hasNext()) { + VoteUsrAttempt attempt = (VoteUsrAttempt) listIterator.next(); + if (attempt.getVoteQueUsr().getVoteSession().getUid().toString().equals(voteSessionUid.toString())) { + userEntries.add(attempt); + } } - - - - - - public List getAttemptsListForUserAndQuestionContent(final Long queUsrId, final Long voteQueContentId) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_ATTEMPT_FOR_USER_AND_QUESTION_CONTENT) - .setLong("queUsrId", queUsrId.longValue()) - .setLong("voteQueContentId", voteQueContentId.longValue()) - .list(); - return list; - } + } + return userEntries.size(); - - public int getLastNominationCount(Long userId) - { - return 0; + } + + public List getStandardAttemptUsersForQuestionContentAndSessionUid(final Long voteQueContentId, + final Long voteSessionUid) { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(LOAD_ATTEMPT_FOR_QUESTION_CONTENT).setLong("voteQueContentId", + voteQueContentId.longValue()).list(); + + List userEntries = new ArrayList(); + if (list != null && list.size() > 0) { + Iterator listIterator = list.iterator(); + while (listIterator.hasNext()) { + VoteUsrAttempt attempt = (VoteUsrAttempt) listIterator.next(); + if (attempt.getVoteQueUsr().getVoteSession().getUid().toString().equals(voteSessionUid.toString())) { + userEntries.add(attempt); } - - - public List getAttemptForQueContent(final Long queUsrId, final Long voteQueContentId) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_ATTEMPT_FOR_QUE_CONTENT) - .setLong("queUsrId", queUsrId.longValue()) - .setLong("voteQueContentId", voteQueContentId.longValue()) - .list(); - return list; } - + } + return userEntries; - public List getUserRecords(final String userEntry) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_USER_ENTRY_RECORDS) - .setString("userEntry", userEntry) - .list(); - return list; + } + + public boolean isVoteVisibleForSession(final String userEntry, final Long voteSessionUid) { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(LOAD_USER_ENTRY_RECORDS).setString("userEntry", userEntry).list(); + + List sessionUserEntries = new ArrayList(); + if (list != null && list.size() > 0) { + Iterator listIterator = list.iterator(); + while (listIterator.hasNext()) { + VoteUsrAttempt attempt = (VoteUsrAttempt) listIterator.next(); + logger.debug("attempt: " + attempt); + if (attempt.getVoteQueUsr().getVoteSession().getUid().toString().equals(voteSessionUid.toString())) { + boolean isVoteVisible = attempt.isVisible(); + logger.debug("isVoteVisible: " + isVoteVisible); + if (isVoteVisible == false) + return false; + } } + } - public List getUserEnteredVotesForSession(final String userEntry, final Long voteSessionUid) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_USER_ENTRY_RECORDS) - .setString("userEntry", userEntry) - .list(); - - - List sessionUserEntries= new ArrayList(); - if(list != null && list.size() > 0){ - Iterator listIterator=list.iterator(); - while (listIterator.hasNext()) - { - VoteUsrAttempt attempt=(VoteUsrAttempt)listIterator.next(); - logger.debug("attempt: " + attempt); - if (attempt.getVoteQueUsr().getVoteSession().getUid().toString().equals(voteSessionUid.toString())) - { - sessionUserEntries.add(attempt.getUserEntry()); - } - } - } - return sessionUserEntries; + return true; + } + + public int getStandardAttemptsForQuestionContentAndContentUid(final Long voteQueContentId, final Long voteContentUid) { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(LOAD_ATTEMPT_FOR_QUESTION_CONTENT).setLong("voteQueContentId", + voteQueContentId.longValue()).list(); + + List userEntries = new ArrayList(); + if (list != null && list.size() > 0) { + Iterator listIterator = list.iterator(); + while (listIterator.hasNext()) { + VoteUsrAttempt attempt = (VoteUsrAttempt) listIterator.next(); + + if (attempt.getVoteQueUsr().getVoteSession().getVoteContent().getUid().toString().equals( + voteContentUid.toString())) { + userEntries.add(attempt); + } } + } + return userEntries.size(); - public int getAllEntriesCount() - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_ALL_ENTRIES) - .list(); - return list.size(); + } + + public List getAttemptsForUserAndQuestionContent(final Long queUsrId, final Long voteQueContentId) { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(LOAD_ATTEMPT_FOR_USER_AND_QUESTION_CONTENT).setLong("queUsrId", + queUsrId.longValue()).setLong("voteQueContentId", voteQueContentId.longValue()).list(); + + return list; + } + + public VoteUsrAttempt getAttemptsForUserAndQuestionContentAndSession(final Long queUsrId, + final Long voteQueContentId, final Long voteSessionId) { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(LOAD_ATTEMPT_FOR_USER_AND_QUESTION_CONTENT_AND_SESSION).setLong( + "queUsrId", queUsrId.longValue()).setLong("voteQueContentId", voteQueContentId.longValue()).list(); + + if (list != null && list.size() > 0) { + Iterator listIterator = list.iterator(); + while (listIterator.hasNext()) { + VoteUsrAttempt attempt = (VoteUsrAttempt) listIterator.next(); + logger.debug("attempt: " + attempt); + if (attempt.getVoteQueUsr().getVoteSession().getUid().toString().equals(voteSessionId.toString())) { + return attempt; + } } - + } + return null; + } - public int getSessionEntriesCount(final Long voteSessionUid) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_ALL_ENTRIES) - .list(); - - int totalSessionAttemptsCount=0; - if(list != null && list.size() > 0){ - Iterator listIterator=list.iterator(); - while (listIterator.hasNext()) - { - VoteUsrAttempt attempt=(VoteUsrAttempt)listIterator.next(); - logger.debug("attempt: " + attempt); - if (attempt.getVoteQueUsr().getVoteSession().getUid().toString().equals(voteSessionUid.toString())) - { - ++totalSessionAttemptsCount; - } - } - } - return totalSessionAttemptsCount; + public Set getAttemptsForUserAndSession(final Long queUsrId, final Long voteSessionId) { + logger.debug("starting getAttemptsForUserAndSession"); + logger.debug("queUsrId: " + queUsrId); + logger.debug("voteSessionId: " + voteSessionId); + + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(LOAD_ATTEMPT_FOR_USER_AND_SESSION).setLong("queUsrId", + queUsrId.longValue()).list(); + logger.debug("list: " + list); + + Set userEntries = new HashSet(); + if (list != null && list.size() > 0) { + Iterator listIterator = list.iterator(); + while (listIterator.hasNext()) { + VoteUsrAttempt attempt = (VoteUsrAttempt) listIterator.next(); + logger.debug("attempt: " + attempt); + + if (attempt.getVoteQueUsr().getVoteSession().getUid().toString().equals(voteSessionId.toString())) { + if (!attempt.getVoteQueContentId().toString().equals("1")) { + logger.debug("adding attempt question : " + attempt.getVoteQueContent().getQuestion()); + userEntries.add(attempt.getVoteQueContent().getQuestion()); + } + } } + } + logger.debug("returning userEntries: " + userEntries); + return userEntries; + } - - public int getCompletedSessionEntriesCount(final Long voteSessionUid) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_ALL_ENTRIES) - .list(); - - int completedSessionCount=0; - if(list != null && list.size() > 0){ - Iterator listIterator=list.iterator(); - while (listIterator.hasNext()) - { - VoteUsrAttempt attempt=(VoteUsrAttempt)listIterator.next(); - logger.debug("attempt: " + attempt); - if (attempt.getVoteQueUsr().getVoteSession().getUid().toString().equals(voteSessionUid.toString())) - { - String sessionStatus=attempt.getVoteQueUsr().getVoteSession().getSessionStatus(); - logger.debug("sessionStatus: " + sessionStatus); - if (sessionStatus.equals("COMPLETED")) - { - logger.debug("this is a completed session: " + sessionStatus); - ++completedSessionCount; - } - } - } + public Set getAttemptsForUserAndSessionUseOpenAnswer(final Long queUsrId, final Long voteSessionId) { + logger.debug("starting getAttemptsForUserAndSession"); + logger.debug("queUsrId: " + queUsrId); + logger.debug("voteSessionId: " + voteSessionId); + + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(LOAD_ATTEMPT_FOR_USER_AND_SESSION).setLong("queUsrId", + queUsrId.longValue()).list(); + logger.debug("list: " + list); + + String openAnswer = ""; + Set userEntries = new HashSet(); + if (list != null && list.size() > 0) { + Iterator listIterator = list.iterator(); + while (listIterator.hasNext()) { + VoteUsrAttempt attempt = (VoteUsrAttempt) listIterator.next(); + logger.debug("attempt: " + attempt); + + if (attempt.getVoteQueUsr().getVoteSession().getUid().toString().equals(voteSessionId.toString())) { + if (!attempt.getVoteQueContentId().toString().equals("1")) { + logger.debug("adding attempt question : " + attempt.getVoteQueContent().getQuestion()); + userEntries.add(attempt.getVoteQueContent().getQuestion()); + } else { + logger.debug("this is a user entered vote: " + attempt.getUserEntry()); + if (attempt.getUserEntry().length() > 0) { + openAnswer = attempt.getUserEntry(); + logger.debug("adding openAnswer to userEntries: "); + userEntries.add(openAnswer); } - return completedSessionCount; + + } + + } } + } - - public void updateVoteUsrAttempt(VoteUsrAttempt voteUsrAttempt) - { - this.getSession().setFlushMode(FlushMode.AUTO); - this.getHibernateTemplate().update(voteUsrAttempt); + logger.debug("final userEntries : " + userEntries); + return userEntries; + } + + public List getAttemptsListForUserAndQuestionContent(final Long queUsrId, final Long voteQueContentId) { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(LOAD_ATTEMPT_FOR_USER_AND_QUESTION_CONTENT).setLong("queUsrId", + queUsrId.longValue()).setLong("voteQueContentId", voteQueContentId.longValue()).list(); + return list; + } + + public int getLastNominationCount(Long userId) { + return 0; + } + + public List getAttemptForQueContent(final Long queUsrId, final Long voteQueContentId) { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(LOAD_ATTEMPT_FOR_QUE_CONTENT).setLong("queUsrId", queUsrId.longValue()) + .setLong("voteQueContentId", voteQueContentId.longValue()).list(); + return list; + } + + public List getUserRecords(final String userEntry) { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(LOAD_USER_ENTRY_RECORDS).setString("userEntry", userEntry).list(); + return list; + } + + public List getUserEnteredVotesForSession(final String userEntry, final Long voteSessionUid) { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(LOAD_USER_ENTRY_RECORDS).setString("userEntry", userEntry).list(); + + List sessionUserEntries = new ArrayList(); + if (list != null && list.size() > 0) { + Iterator listIterator = list.iterator(); + while (listIterator.hasNext()) { + VoteUsrAttempt attempt = (VoteUsrAttempt) listIterator.next(); + logger.debug("attempt: " + attempt); + if (attempt.getVoteQueUsr().getVoteSession().getUid().toString().equals(voteSessionUid.toString())) { + sessionUserEntries.add(attempt.getUserEntry()); + } } - - public void removeVoteUsrAttemptByUID(Long uid) - { - VoteUsrAttempt votea = (VoteUsrAttempt)getHibernateTemplate().get(VoteUsrAttempt.class, uid); - this.getSession().setFlushMode(FlushMode.AUTO); - this.getHibernateTemplate().delete(votea); - } - - - public void removeVoteUsrAttempt(VoteUsrAttempt voteUsrAttempt) - { - this.getSession().setFlushMode(FlushMode.AUTO); - this.getHibernateTemplate().delete(voteUsrAttempt); - } -} \ No newline at end of file + } + return sessionUserEntries; + } + + + public int getSessionEntriesCount(final Long voteSessionUid) { + List result = getSession().createQuery(COUNT_ENTRIES_BY_SESSION_ID).setLong("voteSessionUid", voteSessionUid) + .list(); + logger.debug("getSessionEntriesCount: " + result); + Integer resultInt = (result.get(0) != null) ? (Integer) result.get(0) : new Integer(0); + return resultInt.intValue(); + } + + public int getCompletedSessionEntriesCount(final Long voteSessionUid) { + List list = (List)getSessionUserEntries(voteSessionUid); + int completedSessionCount = 0; + for(VoteUsrAttempt att : list) + { + String sessionStatus = att.getVoteQueUsr().getVoteSession().getSessionStatus(); + logger.debug("this is a completed session: " + sessionStatus); + ++completedSessionCount; + } + logger.debug("getCompletedSessionEntriesCount" + completedSessionCount); + return completedSessionCount; + } + + public void updateVoteUsrAttempt(VoteUsrAttempt voteUsrAttempt) { + this.getSession().setFlushMode(FlushMode.AUTO); + this.getHibernateTemplate().update(voteUsrAttempt); + } + + public void removeVoteUsrAttemptByUID(Long uid) { + VoteUsrAttempt votea = (VoteUsrAttempt) getHibernateTemplate().get(VoteUsrAttempt.class, uid); + this.getSession().setFlushMode(FlushMode.AUTO); + this.getHibernateTemplate().delete(votea); + } + + public void removeVoteUsrAttempt(VoteUsrAttempt voteUsrAttempt) { + this.getSession().setFlushMode(FlushMode.AUTO); + this.getHibernateTemplate().delete(voteUsrAttempt); + } +} \ No newline at end of file Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/IVoteService.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/IVoteService.java,v diff -u -r1.39 -r1.40 --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/IVoteService.java 9 Dec 2008 05:38:13 -0000 1.39 +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/IVoteService.java 18 Feb 2009 23:06:57 -0000 1.40 @@ -116,8 +116,6 @@ public int getStandardAttemptsForQuestionContentAndSessionUid(final Long voteQueContentId, final Long voteSessionId) throws VoteApplicationException; - public int getAllEntriesCount() throws VoteApplicationException; - public int getSessionEntriesCount(final Long voteSessionId) throws VoteApplicationException; public int getCompletedSessionEntriesCount(final Long voteSessionUid) throws VoteApplicationException; @@ -153,8 +151,6 @@ public Set getUserEntries() throws VoteApplicationException; - public List getContentEntries(final Long voteContentUid) throws VoteApplicationException; - public int getStandardAttemptsForQuestionContentAndContentUid(final Long voteQueContentId, final Long voteContentUid); public int getSessionUserRecordsEntryCount(final String userEntry, final Long voteSessionUid, @@ -192,9 +188,10 @@ public VoteSession getVoteSessionByUID(Long uid) throws VoteApplicationException; /** - * Get the count of all the potential learners for the vote session. This will include the people that have never - * logged into the lesson. Not great, but it is a better estimate of how many users there will be eventually than - * the number of people already known to the tool. + * Get the count of all the potential learners for the vote session. This + * will include the people that have never logged into the lesson. Not + * great, but it is a better estimate of how many users there will be + * eventually than the number of people already known to the tool. * * @param voteSessionId * The tool session id Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/VoteServicePOJO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/VoteServicePOJO.java,v diff -u -r1.63 -r1.64 --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/VoteServicePOJO.java 9 Dec 2008 05:38:13 -0000 1.63 +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/VoteServicePOJO.java 18 Feb 2009 23:06:58 -0000 1.64 @@ -95,8 +95,9 @@ * * @author Ozgur Demirtas * - * The POJO implementation of Voting service. All business logic of Voting tool is implemented in this class. It - * translates the request from presentation layer and performs appropriate database operation. + * The POJO implementation of Voting service. All business logic of Voting tool + * is implemented in this class. It translates the request from presentation + * layer and performs appropriate database operation. * */ public class VoteServicePOJO implements IVoteService, ToolContentManager, ToolSessionManager, @@ -135,28 +136,28 @@ } public void configureContentRepository() throws VoteApplicationException { - VoteServicePOJO.logger.debug("retrieved repService: " + repositoryService); + logger.debug("retrieved repService: " + repositoryService); cred = new SimpleCredentials(repositoryUser, repositoryId); - VoteServicePOJO.logger.debug("retrieved cred: " + cred); + logger.debug("retrieved cred: " + cred); try { repositoryService.createCredentials(cred); - VoteServicePOJO.logger.debug("created credentails."); - repositoryService.addWorkspace(cred, VoteServicePOJO.repositoryWorkspaceName); - VoteServicePOJO.logger.debug("created workspace."); + logger.debug("created credentails."); + repositoryService.addWorkspace(cred, repositoryWorkspaceName); + logger.debug("created workspace."); } catch (ItemExistsException ie) { - VoteServicePOJO.logger.warn("Tried to configure repository but it " + logger.warn("Tried to configure repository but it " + " appears to be already configured. Exception thrown by repository being ignored. ", ie); } catch (RepositoryCheckedException e) { String error = "Error occured while trying to configure repository." + " Unable to recover from error: " + e.getMessage(); - VoteServicePOJO.logger.error(error, e); + logger.error(error, e); throw new VoteApplicationException(error, e); } } public void createVote(VoteContent voteContent) throws VoteApplicationException { try { - VoteServicePOJO.logger.debug("using voteContent defineLater:" + voteContent.isDefineLater()); + logger.debug("using voteContent defineLater:" + voteContent.isDefineLater()); voteContentDAO.saveVoteContent(voteContent); } catch (DataAccessException e) { throw new VoteApplicationException("Exception occured when lams is creating vote content: " @@ -231,15 +232,6 @@ } } - public List getContentEntries(final Long voteContentUid) throws VoteApplicationException { - try { - return voteUsrAttemptDAO.getContentEntries(voteContentUid); - } catch (DataAccessException e) { - throw new VoteApplicationException("Exception occured when lams is getting content entries: " - + e.getMessage(), e); - } - } - public Set getUserEntries() throws VoteApplicationException { try { return voteUsrAttemptDAO.getUserEntries(); @@ -387,8 +379,7 @@ Set potentialLearners = toolService.getAllPotentialLearners(session.getVoteSessionId().longValue()); return potentialLearners != null ? potentialLearners.size() : 0; } else { - VoteServicePOJO.logger.error("Unable to find vote session record id=" + voteSessionId - + ". Returning 0 users."); + logger.error("Unable to find vote session record id=" + voteSessionId + ". Returning 0 users."); return 0; } } catch (LamsToolServiceException e) { @@ -463,15 +454,6 @@ } } - public int getAllEntriesCount() throws VoteApplicationException { - try { - return voteUsrAttemptDAO.getAllEntriesCount(); - } catch (DataAccessException e) { - throw new VoteApplicationException("Exception occured when lams is getting all attempts entries count: " - + e.getMessage(), e); - } - } - public int getStandardAttemptsForQuestionContentAndContentUid(final Long voteQueContentId, final Long voteContentUid) { try { return voteUsrAttemptDAO.getStandardAttemptsForQuestionContentAndContentUid(voteQueContentId, @@ -852,7 +834,7 @@ * logs hiding of a user entered vote */ public void hideOpenVote(VoteUsrAttempt voteUsrAttempt) throws VoteApplicationException { - VoteServicePOJO.logger.debug("hiding user entry: " + voteUsrAttempt.getUserEntry()); + logger.debug("hiding user entry: " + voteUsrAttempt.getUserEntry()); auditService.logHideEntry(VoteAppConstants.MY_SIGNATURE, voteUsrAttempt.getQueUsrId(), voteUsrAttempt .getVoteQueUsr().getUsername(), voteUsrAttempt.getUserEntry()); } @@ -861,7 +843,7 @@ * logs showing of a user entered vote */ public void showOpenVote(VoteUsrAttempt voteUsrAttempt) throws VoteApplicationException { - VoteServicePOJO.logger.debug("showing user entry: " + voteUsrAttempt.getUserEntry()); + logger.debug("showing user entry: " + voteUsrAttempt.getUserEntry()); auditService.logShowEntry(VoteAppConstants.MY_SIGNATURE, voteUsrAttempt.getQueUsrId(), voteUsrAttempt .getVoteQueUsr().getUsername(), voteUsrAttempt.getUserEntry()); } @@ -904,13 +886,13 @@ public User getCurrentUserData(String username) throws VoteApplicationException { try { - VoteServicePOJO.logger.debug("getCurrentUserData: " + username); + logger.debug("getCurrentUserData: " + username); /** * this will return null if the username not found */ User user = userManagementService.getUserByLogin(username); if (user == null) { - VoteServicePOJO.logger.error("No user with the username: " + username + " exists."); + logger.error("No user with the username: " + username + " exists."); throw new VoteApplicationException("No user with that username exists."); } return user; @@ -961,14 +943,14 @@ * @throws VoteApplicationException */ public boolean studentActivityOccurredGlobal(VoteContent voteContent) throws VoteApplicationException { - VoteServicePOJO.logger.debug("voteContent uid: " + voteContent.getUid()); + logger.debug("voteContent uid: " + voteContent.getUid()); Iterator questionIterator = voteContent.getVoteQueContents().iterator(); while (questionIterator.hasNext()) { VoteQueContent voteQueContent = (VoteQueContent) questionIterator.next(); Iterator attemptsIterator = voteQueContent.getVoteUsrAttempts().iterator(); while (attemptsIterator.hasNext()) { - VoteServicePOJO.logger.debug("there is at least one attempt for the standard nominamtions"); + logger.debug("there is at least one attempt for the standard nominamtions"); /** * proved the fact that there is at least one attempt for this content. */ @@ -979,18 +961,18 @@ } public boolean studentActivityOccurredStandardAndOpen(VoteContent voteContent) throws VoteApplicationException { - VoteServicePOJO.logger.debug("voteContent uid: " + voteContent.getUid()); + logger.debug("voteContent uid: " + voteContent.getUid()); boolean studentActivityOccurredGlobal = studentActivityOccurredGlobal(voteContent); - VoteServicePOJO.logger.debug("studentActivityOccurredGlobal: " + studentActivityOccurredGlobal); + logger.debug("studentActivityOccurredGlobal: " + studentActivityOccurredGlobal); int userEnteredVotesCount = getUserEnteredVotesCountForContent(voteContent.getUid()); - VoteServicePOJO.logger.debug("userEnteredVotesCount: " + userEnteredVotesCount); + logger.debug("userEnteredVotesCount: " + userEnteredVotesCount); if (studentActivityOccurredGlobal == true || userEnteredVotesCount > 0) { return true; } - VoteServicePOJO.logger.debug("there is no votes/nominations for this content"); + logger.debug("there is no votes/nominations for this content"); return false; } @@ -1030,77 +1012,77 @@ * */ public void copyToolContent(Long fromContentId, Long toContentId) throws ToolException { - VoteServicePOJO.logger.debug("start of copyToolContent with ids: " + fromContentId + " and " + toContentId); + logger.debug("start of copyToolContent with ids: " + fromContentId + " and " + toContentId); if (fromContentId == null) { - VoteServicePOJO.logger.error("fromContentId is null."); - VoteServicePOJO.logger.debug("attempt retrieving tool's default content id with signatute : " + logger.error("fromContentId is null."); + logger.debug("attempt retrieving tool's default content id with signatute : " + VoteAppConstants.MY_SIGNATURE); long defaultContentId = 0; try { defaultContentId = getToolDefaultContentIdBySignature(VoteAppConstants.MY_SIGNATURE); fromContentId = new Long(defaultContentId); } catch (Exception e) { - VoteServicePOJO.logger.error("default content id has not been setup for signature: " + logger.error("default content id has not been setup for signature: " + VoteAppConstants.MY_SIGNATURE); throw new ToolException("WARNING! default content has not been setup for signature" + VoteAppConstants.MY_SIGNATURE + " Can't continue!"); } } if (toContentId == null) { - VoteServicePOJO.logger.error("throwing ToolException: toContentId is null"); + logger.error("throwing ToolException: toContentId is null"); throw new ToolException("toContentId is missing"); } - VoteServicePOJO.logger.debug("final - copyToolContent using ids: " + fromContentId + " and " + toContentId); + logger.debug("final - copyToolContent using ids: " + fromContentId + " and " + toContentId); try { VoteContent fromContent = voteContentDAO.findVoteContentById(fromContentId); if (fromContent == null) { - VoteServicePOJO.logger.error("fromContent is null."); - VoteServicePOJO.logger.error("attempt retrieving tool's default content id with signatute : " + logger.error("fromContent is null."); + logger.error("attempt retrieving tool's default content id with signatute : " + VoteAppConstants.MY_SIGNATURE); long defaultContentId = 0; try { defaultContentId = getToolDefaultContentIdBySignature(VoteAppConstants.MY_SIGNATURE); fromContentId = new Long(defaultContentId); } catch (Exception e) { - VoteServicePOJO.logger.error("default content id has not been setup for signature: " + logger.error("default content id has not been setup for signature: " + VoteAppConstants.MY_SIGNATURE); throw new ToolException("WARNING! default content has not been setup for signature" + VoteAppConstants.MY_SIGNATURE + " Can't continue!"); } fromContent = voteContentDAO.findVoteContentById(fromContentId); - VoteServicePOJO.logger.debug("using fromContent: " + fromContent); + logger.debug("using fromContent: " + fromContent); } - VoteServicePOJO.logger.debug("final - retrieved fromContent: " + fromContent); - VoteServicePOJO.logger.debug("final - before new instance using " + fromContent + " and " + toContentId); - VoteServicePOJO.logger.debug("final - before new instance using voteToolContentHandler: " + logger.debug("final - retrieved fromContent: " + fromContent); + logger.debug("final - before new instance using " + fromContent + " and " + toContentId); + logger.debug("final - before new instance using voteToolContentHandler: " + voteToolContentHandler); try { VoteContent toContent = VoteContent.newInstance(voteToolContentHandler, fromContent, toContentId); if (toContent == null) { - VoteServicePOJO.logger.debug("throwing ToolException: WARNING!, retrieved toContent is null."); + logger.debug("throwing ToolException: WARNING!, retrieved toContent is null."); throw new ToolException("WARNING! Fail to create toContent. Can't continue!"); } else { - VoteServicePOJO.logger.debug("retrieved toContent: " + toContent); + logger.debug("retrieved toContent: " + toContent); voteContentDAO.saveVoteContent(toContent); - VoteServicePOJO.logger.debug("toContent has been saved successfully: " + toContent); + logger.debug("toContent has been saved successfully: " + toContent); } - VoteServicePOJO.logger.debug("end of copyToolContent with ids: " + fromContentId + " and " + logger.debug("end of copyToolContent with ids: " + fromContentId + " and " + toContentId); } catch (ItemNotFoundException e) { - VoteServicePOJO.logger.error("exception occurred: " + e); + logger.error("exception occurred: " + e); } catch (RepositoryCheckedException e) { - VoteServicePOJO.logger.error("exception occurred: " + e); + logger.error("exception occurred: " + e); } } catch (DataAccessException e) { - VoteServicePOJO.logger + 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."); } @@ -1117,66 +1099,66 @@ */ public void removeToolContent(Long toolContentID, boolean removeSessionData) throws SessionDataExistsException, ToolException { - VoteServicePOJO.logger.debug("start of removeToolContent with toolContentID: " + toolContentID + logger.debug("start of removeToolContent with toolContentID: " + toolContentID + "removeSessionData: " + removeSessionData); if (toolContentID == null) { - VoteServicePOJO.logger.error("toolContentID is null"); + logger.error("toolContentID is null"); throw new ToolException("toolContentID is missing"); } VoteContent voteContent = voteContentDAO.findVoteContentById(toolContentID); - VoteServicePOJO.logger.debug("retrieving voteContent: " + voteContent); + logger.debug("retrieving voteContent: " + voteContent); if (voteContent != null) { - VoteServicePOJO.logger + logger .error("start deleting any uploaded file for this content from the content repository"); Iterator filesIterator = voteContent.getVoteAttachments().iterator(); while (filesIterator.hasNext()) { VoteUploadedFile voteUploadedFile = (VoteUploadedFile) filesIterator.next(); - VoteServicePOJO.logger.debug("iterated voteUploadedFile : " + voteUploadedFile); + logger.debug("iterated voteUploadedFile : " + voteUploadedFile); String filesUuid = voteUploadedFile.getUuid(); if (filesUuid != null && filesUuid.length() > 0) { try { voteToolContentHandler.deleteFile(new Long(filesUuid)); } catch (RepositoryCheckedException e) { - VoteServicePOJO.logger.error("exception occured deleting files from content repository : " + e); + logger.error("exception occured deleting files from content repository : " + e); throw new ToolException("undeletable file in the content repository"); } } } - VoteServicePOJO.logger.debug("end deleting any uploaded files for this content."); + logger.debug("end deleting any uploaded files for this content."); Iterator sessionIterator = voteContent.getVoteSessions().iterator(); while (sessionIterator.hasNext()) { if (removeSessionData == false) { - VoteServicePOJO.logger.debug("removeSessionData is false, throwing SessionDataExistsException."); + logger.debug("removeSessionData is false, throwing SessionDataExistsException."); throw new SessionDataExistsException(); } VoteSession voteSession = (VoteSession) sessionIterator.next(); - VoteServicePOJO.logger.debug("iterated voteSession : " + voteSession); + logger.debug("iterated voteSession : " + voteSession); Iterator sessionUsersIterator = voteSession.getVoteQueUsers().iterator(); while (sessionUsersIterator.hasNext()) { VoteQueUsr voteQueUsr = (VoteQueUsr) sessionUsersIterator.next(); - VoteServicePOJO.logger.debug("iterated voteQueUsr : " + voteQueUsr); + logger.debug("iterated voteQueUsr : " + voteQueUsr); Iterator sessionUsersAttemptsIterator = voteQueUsr.getVoteUsrAttempts().iterator(); while (sessionUsersAttemptsIterator.hasNext()) { VoteUsrAttempt voteUsrAttempt = (VoteUsrAttempt) sessionUsersAttemptsIterator.next(); - VoteServicePOJO.logger.debug("iterated voteUsrAttempt : " + voteUsrAttempt); + logger.debug("iterated voteUsrAttempt : " + voteUsrAttempt); removeAttempt(voteUsrAttempt); - VoteServicePOJO.logger.debug("removed voteUsrAttempt : " + voteUsrAttempt); + logger.debug("removed voteUsrAttempt : " + voteUsrAttempt); } } } - VoteServicePOJO.logger.debug("removed all existing responses of toolContent with toolContentID:" + logger.debug("removed all existing responses of toolContent with toolContentID:" + toolContentID); voteContentDAO.removeVoteById(toolContentID); - VoteServicePOJO.logger.debug("removed voteContent:" + voteContent); + logger.debug("removed voteContent:" + voteContent); } else { - VoteServicePOJO.logger.error("Warning!!!, We should have not come here. voteContent is null."); + logger.error("Warning!!!, We should have not come here. voteContent is null."); throw new ToolException("toolContentID is missing"); } } @@ -1265,13 +1247,13 @@ */ public void setAsDefineLater(Long toolContentID, boolean value) throws DataMissingException, ToolException { if (toolContentID == null) { - VoteServicePOJO.logger.error("throwing DataMissingException: WARNING!: retrieved toolContentID is null."); + logger.error("throwing DataMissingException: WARNING!: retrieved toolContentID is null."); throw new DataMissingException("toolContentID is missing"); } VoteContent voteContent = retrieveVote(toolContentID); if (voteContent == null) { - VoteServicePOJO.logger.error("throwing DataMissingException: WARNING!: retrieved voteContent is null."); + logger.error("throwing DataMissingException: WARNING!: retrieved voteContent is null."); throw new DataMissingException("voteContent is missing"); } voteContent.setDefineLater(value); @@ -1288,12 +1270,12 @@ */ public void setAsRunOffline(Long toolContentID, boolean value) throws DataMissingException, ToolException { if (toolContentID == null) { - VoteServicePOJO.logger.error("throwing DataMissingException: WARNING!: retrieved toolContentID is null."); + logger.error("throwing DataMissingException: WARNING!: retrieved toolContentID is null."); throw new DataMissingException("toolContentID is missing"); } VoteContent voteContent = voteContentDAO.findVoteContentById(toolContentID); if (voteContent == null) { - VoteServicePOJO.logger.error("throwing DataMissingException: WARNING!: retrieved voteContent is null."); + logger.error("throwing DataMissingException: WARNING!: retrieved voteContent is null."); throw new DataMissingException("voteContent is missing"); } voteContent.setRunOffline(value); @@ -1311,10 +1293,10 @@ VoteSession voteSession = retrieveVoteSession(toolSessionID); if (voteSession == null) { - VoteServicePOJO.logger.error("voteSession does not exist yet: " + toolSessionID); + logger.error("voteSession does not exist yet: " + toolSessionID); return false; } else { - VoteServicePOJO.logger.debug("retrieving an existing voteSession: " + voteSession + " " + toolSessionID); + logger.debug("retrieving an existing voteSession: " + voteSession + " " + toolSessionID); } return true; } @@ -1334,55 +1316,55 @@ * */ public void createToolSession(Long toolSessionID, String toolSessionName, Long toolContentID) throws ToolException { - VoteServicePOJO.logger.debug("start of createToolSession with ids: " + toolSessionID + " and " + toolContentID); - VoteServicePOJO.logger.debug("toolSessionName: " + toolSessionName); + logger.debug("start of createToolSession with ids: " + toolSessionID + " and " + toolContentID); + logger.debug("toolSessionName: " + toolSessionName); if (toolSessionID == null) { - VoteServicePOJO.logger.error("toolSessionID is null"); + logger.error("toolSessionID is null"); throw new ToolException("toolSessionID is missing"); } long defaultContentId = 0; if (toolContentID == null) { - VoteServicePOJO.logger.error("toolContentID is null."); - VoteServicePOJO.logger.error("attempt retrieving tool's default content id with signatute : " + logger.error("toolContentID is null."); + logger.error("attempt retrieving tool's default content id with signatute : " + VoteAppConstants.MY_SIGNATURE); try { defaultContentId = getToolDefaultContentIdBySignature(VoteAppConstants.MY_SIGNATURE); toolContentID = new Long(defaultContentId); - VoteServicePOJO.logger.debug("updated toolContentID to: " + toolContentID); + logger.debug("updated toolContentID to: " + toolContentID); } catch (Exception e) { - VoteServicePOJO.logger.error("default content id has not been setup for signature: " + logger.error("default content id has not been setup for signature: " + VoteAppConstants.MY_SIGNATURE); throw new ToolException("WARNING! default content has not been setup for signature" + VoteAppConstants.MY_SIGNATURE + " Can't continue!"); } } - VoteServicePOJO.logger.debug("final toolSessionID and toolContentID: " + toolSessionID + " " + toolContentID); + logger.debug("final toolSessionID and toolContentID: " + toolSessionID + " " + toolContentID); VoteContent voteContent = voteContentDAO.findVoteContentById(toolContentID); - VoteServicePOJO.logger.debug("retrieved voteContent: " + voteContent); + logger.debug("retrieved voteContent: " + voteContent); if (voteContent == null) { - VoteServicePOJO.logger.error("voteContent is null."); - VoteServicePOJO.logger.error("attempt retrieving tool's default content id with signatute : " + logger.error("voteContent is null."); + logger.error("attempt retrieving tool's default content id with signatute : " + VoteAppConstants.MY_SIGNATURE); try { defaultContentId = getToolDefaultContentIdBySignature(VoteAppConstants.MY_SIGNATURE); toolContentID = new Long(defaultContentId); - VoteServicePOJO.logger.debug("updated toolContentID to: " + toolContentID); + logger.debug("updated toolContentID to: " + toolContentID); } catch (Exception e) { - VoteServicePOJO.logger.error("default content id has not been setup for signature: " + logger.error("default content id has not been setup for signature: " + VoteAppConstants.MY_SIGNATURE); throw new ToolException("WARNING! default content has not been setup for signature" + VoteAppConstants.MY_SIGNATURE + " Can't continue!"); } voteContent = voteContentDAO.findVoteContentById(toolContentID); } - VoteServicePOJO.logger.debug("final - retrieved voteContent: " + voteContent); + logger.debug("final - retrieved voteContent: " + voteContent); /* * create a new a new tool session if it does not already exist in the tool session table @@ -1392,12 +1374,12 @@ VoteSession voteSession = new VoteSession(toolSessionID, new Date(System.currentTimeMillis()), VoteSession.INCOMPLETE, toolSessionName, voteContent, new TreeSet()); - VoteServicePOJO.logger.debug("created voteSession: " + voteSession); + logger.debug("created voteSession: " + voteSession); voteSessionDAO.saveVoteSession(voteSession); - VoteServicePOJO.logger.debug("created voteSession in the db: " + voteSession); + logger.debug("created voteSession in the db: " + voteSession); } catch (Exception e) { - VoteServicePOJO.logger.error("Error creating new toolsession in the db"); + logger.error("Error creating new toolsession in the db"); throw new ToolException("Error creating new toolsession in the db: " + e); } } @@ -1413,30 +1395,30 @@ * @throws ToolException */ public void removeToolSession(Long toolSessionID) throws DataMissingException, ToolException { - VoteServicePOJO.logger.debug("start of removeToolSession with id: " + toolSessionID); + logger.debug("start of removeToolSession with id: " + toolSessionID); if (toolSessionID == null) { - VoteServicePOJO.logger.error("toolSessionID is null"); + logger.error("toolSessionID is null"); throw new DataMissingException("toolSessionID is missing"); } VoteSession voteSession = null; try { voteSession = retrieveVoteSession(toolSessionID); - VoteServicePOJO.logger.debug("retrieved voteSession: " + voteSession); + logger.debug("retrieved voteSession: " + voteSession); } catch (VoteApplicationException e) { throw new DataMissingException("error retrieving voteSession: " + e); } catch (Exception e) { throw new ToolException("error retrieving voteSession: " + e); } if (voteSession == null) { - VoteServicePOJO.logger.error("voteSession is null"); + logger.error("voteSession is null"); throw new DataMissingException("voteSession is missing"); } try { voteSessionDAO.removeVoteSession(voteSession); - VoteServicePOJO.logger.debug("voteSession " + voteSession + " has been deleted successfully."); + logger.debug("voteSession " + voteSession + " has been deleted successfully."); } catch (VoteApplicationException e) { throw new ToolException("error deleting voteSession:" + e); } @@ -1453,41 +1435,41 @@ * */ public String leaveToolSession(Long toolSessionID, Long learnerId) throws DataMissingException, ToolException { - VoteServicePOJO.logger.debug("start of leaveToolSession with toolSessionID:" + toolSessionID + logger.debug("start of leaveToolSession with toolSessionID:" + toolSessionID + " and learnerId:" + learnerId); - VoteServicePOJO.logger.debug("make sure learnerService is available. Is it?" + learnerService); + logger.debug("make sure learnerService is available. Is it?" + learnerService); if (learnerService == null) { return "dummyNextUrl"; } if (learnerId == null) { - VoteServicePOJO.logger.error("learnerId is null"); + logger.error("learnerId is null"); throw new DataMissingException("learnerId is missing"); } if (toolSessionID == null) { - VoteServicePOJO.logger.error("toolSessionID is null"); + logger.error("toolSessionID is null"); throw new DataMissingException("toolSessionID is missing"); } VoteSession voteSession = null; try { voteSession = retrieveVoteSession(toolSessionID); - VoteServicePOJO.logger.debug("retrieved voteSession: " + voteSession); + logger.debug("retrieved voteSession: " + voteSession); } catch (VoteApplicationException e) { throw new DataMissingException("error retrieving voteSession: " + e); } catch (Exception e) { throw new ToolException("error retrieving voteSession: " + e); } voteSession.setSessionStatus(VoteAppConstants.COMPLETED); voteSessionDAO.updateVoteSession(voteSession); - VoteServicePOJO.logger.debug("updated voteSession to COMPLETED" + voteSession); + logger.debug("updated voteSession to COMPLETED" + voteSession); String nextUrl = learnerService.completeToolSession(toolSessionID, learnerId); - VoteServicePOJO.logger.debug("nextUrl: " + nextUrl); + logger.debug("nextUrl: " + nextUrl); if (nextUrl == null) { - VoteServicePOJO.logger.error("nextUrl is null"); + logger.error("nextUrl is null"); throw new ToolException("nextUrl is null"); } return nextUrl; @@ -1518,27 +1500,27 @@ } public IToolVO getToolBySignature(String toolSignature) throws VoteApplicationException { - VoteServicePOJO.logger.debug("attempt retrieving tool with signature : " + toolSignature); + logger.debug("attempt retrieving tool with signature : " + toolSignature); IToolVO tool = toolService.getToolBySignature(toolSignature); - VoteServicePOJO.logger.debug("retrieved tool: " + tool); + logger.debug("retrieved tool: " + tool); return tool; } public long getToolDefaultContentIdBySignature(String toolSignature) throws VoteApplicationException { long contentId = 0; contentId = toolService.getToolDefaultContentIdBySignature(toolSignature); - VoteServicePOJO.logger.debug("tool default contentId : " + contentId); + logger.debug("tool default contentId : " + contentId); return contentId; } public VoteQueContent getToolDefaultQuestionContent(long contentId) throws VoteApplicationException { VoteQueContent voteQueContent = voteQueContentDAO.getToolDefaultQuestionContent(contentId); - VoteServicePOJO.logger.debug("retrieved voteQueContent : " + voteQueContent); + logger.debug("retrieved voteQueContent : " + voteQueContent); return voteQueContent; } public List getToolSessionsForContent(VoteContent vote) { - VoteServicePOJO.logger.debug("attempt retrieving listToolSessionIds for : " + vote); + logger.debug("attempt retrieving listToolSessionIds for : " + vote); List listToolSessionIds = voteSessionDAO.getSessionsFromContent(vote); return listToolSessionIds; } @@ -1576,12 +1558,12 @@ */ public ITicket getRepositoryLoginTicket() throws VoteApplicationException { repositoryService = RepositoryProxy.getRepositoryService(); - VoteServicePOJO.logger.debug("retrieved repositoryService : " + repositoryService); + logger.debug("retrieved repositoryService : " + repositoryService); ICredentials credentials = new SimpleCredentials(repositoryUser, repositoryId); try { ITicket ticket = repositoryService.login(credentials, VoteServicePOJO.repositoryWorkspaceName); - VoteServicePOJO.logger.debug("retrieved ticket: " + ticket); + logger.debug("retrieved ticket: " + ticket); return ticket; } catch (AccessDeniedException e) { throw new VoteApplicationException("Access Denied to repository." + e.getMessage()); @@ -1604,10 +1586,10 @@ */ public void deleteFromRepository(Long uuid, Long versionID) throws VoteApplicationException { ITicket ticket = getRepositoryLoginTicket(); - VoteServicePOJO.logger.debug("retrieved ticket: " + ticket); + logger.debug("retrieved ticket: " + ticket); try { String files[] = repositoryService.deleteVersion(ticket, uuid, versionID); - VoteServicePOJO.logger.debug("retrieved files: " + files); + logger.debug("retrieved files: " + files); } catch (Exception e) { throw new VoteApplicationException("Exception occured while deleting files from" + " the repository " + e.getMessage()); @@ -1629,13 +1611,13 @@ * @throws SubmitFilesException */ public NodeKey uploadFileToRepository(InputStream stream, String fileName) throws VoteApplicationException { - VoteServicePOJO.logger.debug("attempt getting the ticket"); + logger.debug("attempt getting the ticket"); ITicket ticket = getRepositoryLoginTicket(); - VoteServicePOJO.logger.debug("retrieved ticket: " + ticket); + logger.debug("retrieved ticket: " + ticket); try { NodeKey nodeKey = repositoryService.addFileItem(ticket, stream, fileName, null, null); - VoteServicePOJO.logger.debug("retrieved nodeKey from repository service: " + nodeKey); + logger.debug("retrieved nodeKey from repository service: " + nodeKey); return nodeKey; } catch (Exception e) { throw new VoteApplicationException("Exception occured while trying to" + " upload file into the repository" @@ -1647,7 +1629,7 @@ ITicket ticket = getRepositoryLoginTicket(); try { IVersionedNode node = repositoryService.getFileItem(ticket, uuid, null); - VoteServicePOJO.logger.debug("retrieved node: " + node); + logger.debug("retrieved node: " + node); return node.getFile(); } catch (AccessDeniedException e) { throw new VoteApplicationException("AccessDeniedException occured while trying to download file " @@ -1666,22 +1648,22 @@ public void persistFile(String uuid, boolean isOnlineFile, String fileName, VoteContent voteContent) throws VoteApplicationException { - VoteServicePOJO.logger.debug("attempt persisting file to the db: " + uuid + " " + isOnlineFile + " " + fileName + logger.debug("attempt persisting file to the db: " + uuid + " " + isOnlineFile + " " + fileName + " " + voteContent); VoteUploadedFile voteUploadedFile = new VoteUploadedFile(uuid, isOnlineFile, fileName, voteContent); - VoteServicePOJO.logger.debug("created voteUploadedFile: " + voteUploadedFile); + logger.debug("created voteUploadedFile: " + voteUploadedFile); voteUploadedFileDAO.saveUploadFile(voteUploadedFile); - VoteServicePOJO.logger.debug("persisted voteUploadedFile: " + voteUploadedFile); + logger.debug("persisted voteUploadedFile: " + voteUploadedFile); } /** * * removes all the entries in the uploaded files table */ public void cleanUploadedFilesMetaData() throws VoteApplicationException { - VoteServicePOJO.logger.debug("attempt cleaning up uploaded file meta data table from the db"); + logger.debug("attempt cleaning up uploaded file meta data table from the db"); voteUploadedFileDAO.cleanUploadedFilesMetaData(); - VoteServicePOJO.logger.debug("files meta data has been cleaned up"); + logger.debug("files meta data has been cleaned up"); } /** @@ -1757,7 +1739,7 @@ toolContentObj.setMaxNominationCount(maxCount != null ? maxCount.toString() : "1"); } catch (WDDXProcessorConversionException e) { - VoteServicePOJO.logger.error("Unable to content for activity " + toolContentObj.getTitle() + logger.error("Unable to content for activity " + toolContentObj.getTitle() + "properly due to a WDDXProcessorConversionException.", e); throw new ToolException( "Invalid import data format for activity " @@ -1785,7 +1767,10 @@ voteContentDAO.saveVoteContent(toolContentObj); } - /** Set the description, throws away the title value as this is not supported in 2.0 */ + /** + * Set the description, throws away the title value as this is not supported + * in 2.0 + */ public void setReflectiveData(Long toolContentId, String title, String description) throws ToolException, DataMissingException { @@ -1803,7 +1788,7 @@ } public Long createNotebookEntry(Long id, Integer idType, String signature, Integer userID, String entry) { - VoteServicePOJO.logger.debug("coreNotebookService: " + coreNotebookService); + logger.debug("coreNotebookService: " + coreNotebookService); return coreNotebookService.createNotebookEntry(id, idType, signature, userID, "", entry); } @@ -1828,15 +1813,15 @@ public void removeFile(Long submissionId) throws VoteApplicationException { voteUploadedFileDAO.removeUploadFile(submissionId); - VoteServicePOJO.logger.debug("removed voteUploadedFile: " + submissionId); + logger.debug("removed voteUploadedFile: " + submissionId); } public void persistFile(VoteContent content, VoteUploadedFile file) throws VoteApplicationException { - VoteServicePOJO.logger.debug("in persistFile: " + file); + logger.debug("in persistFile: " + file); content.getVoteAttachments().add(file); file.setVoteContent(content); voteContentDAO.saveOrUpdateVote(content); - VoteServicePOJO.logger.debug("persisted voteUploadedFile: " + file); + logger.debug("persisted voteUploadedFile: " + file); } @@ -1853,7 +1838,7 @@ * @return Returns the logger. */ public static Logger getLogger() { - return VoteServicePOJO.logger; + return logger; } /** Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/MonitoringUtil.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/MonitoringUtil.java,v diff -u -r1.47 -r1.48 --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/MonitoringUtil.java 23 May 2008 06:05:24 -0000 1.47 +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/MonitoringUtil.java 18 Feb 2009 23:06:58 -0000 1.48 @@ -53,1741 +53,1617 @@ import org.lamsfoundation.lams.tool.vote.pojos.VoteSession; import org.lamsfoundation.lams.tool.vote.pojos.VoteUsrAttempt; import org.lamsfoundation.lams.tool.vote.service.IVoteService; -import org.lamsfoundation.lams.tool.vote.service.VoteServicePOJO; -import org.lamsfoundation.lams.tool.vote.service.VoteServiceProxy; import org.lamsfoundation.lams.util.MessageService; /** * - *

More generic monitoring mode functions live here

- * + *

+ * More generic monitoring mode functions live here + *

+ * * @author Ozgur Demirtas - * + * */ -public class MonitoringUtil implements VoteAppConstants{ - static Logger logger = Logger.getLogger(MonitoringUtil.class.getName()); - - public static Map populateToolSessions(HttpServletRequest request, VoteContent voteContent, IVoteService voteService) - { - List sessionsList=voteService.getSessionNamesFromContent(voteContent); - logger.debug("sessionsList size is:..." + sessionsList.size()); - - Map sessionsMap=VoteUtils.convertToStringMap(sessionsList, "String"); - logger.debug("generated sessionsMap:..." + sessionsMap); - logger.debug("sessionsMap size:..." + sessionsMap.size()); - - if (sessionsMap.isEmpty()) - { - logger.debug("sessionsMap size is 0:"); - sessionsMap.put(new Long(1).toString() , "None"); - } - else - { - logger.debug("sessionsMap has some entries: " + sessionsMap.size()); - sessionsMap.put(new Long(sessionsMap.size()+ 1).toString() , "All"); - } - - logger.debug("final sessionsMap:" + sessionsMap); - return sessionsMap; +public class MonitoringUtil implements VoteAppConstants { + static Logger logger = Logger.getLogger(MonitoringUtil.class.getName()); + + public static Map populateToolSessions(HttpServletRequest request, VoteContent voteContent, IVoteService voteService) { + List sessionsList = voteService.getSessionNamesFromContent(voteContent); + logger.debug("sessionsList size is:..." + sessionsList.size()); + + Map sessionsMap = VoteUtils.convertToStringMap(sessionsList, "String"); + logger.debug("generated sessionsMap:..." + sessionsMap); + logger.debug("sessionsMap size:..." + sessionsMap.size()); + + if (sessionsMap.isEmpty()) { + logger.debug("sessionsMap size is 0:"); + sessionsMap.put(new Long(1).toString(), "None"); + } else { + logger.debug("sessionsMap has some entries: " + sessionsMap.size()); + sessionsMap.put(new Long(sessionsMap.size() + 1).toString(), "All"); } - /** - * - * used in presenting user votes data - * - * @param request - * @param voteContent - * @param isUserNamesVisible - * @param isLearnerRequest - * @param currentSessionId - * @param userId - * @param voteService - * @return - */ - public static List buildGroupsQuestionData(HttpServletRequest request, VoteContent voteContent, - boolean isUserNamesVisible, boolean isLearnerRequest, String currentSessionId, String userId, - IVoteService voteService) - { - logger.debug("isUserNamesVisible: " + isUserNamesVisible); - logger.debug("isLearnerRequest: " + isLearnerRequest); - logger.debug("userId: " + userId); - - logger.debug("voteService: " + voteService); - - logger.debug("will be building groups question data for content:..." + voteContent); - List listQuestions=voteService.getAllQuestionEntries(voteContent.getUid()); - logger.debug("listQuestions:..." + listQuestions); - - List listMonitoredAnswersContainerDTO= new LinkedList(); - - Iterator itListQuestions = listQuestions.iterator(); - while (itListQuestions.hasNext()) - { - VoteQueContent voteQueContent =(VoteQueContent)itListQuestions.next(); - logger.debug("voteQueContent:..." + voteQueContent); - - if (voteQueContent != null) - { - VoteMonitoredAnswersDTO voteMonitoredAnswersDTO= new VoteMonitoredAnswersDTO(); - voteMonitoredAnswersDTO.setQuestionUid(voteQueContent.getUid().toString()); - voteMonitoredAnswersDTO.setQuestion(voteQueContent.getQuestion()); - - logger.debug("using allUsersData to retrieve users data: " + isUserNamesVisible); - Map questionAttemptData= buildGroupsAttemptData(request, voteContent, voteQueContent, voteQueContent.getUid().toString(), - isUserNamesVisible,isLearnerRequest, currentSessionId, userId, voteService); - logger.debug("questionAttemptData:..." + questionAttemptData); - voteMonitoredAnswersDTO.setQuestionAttempts(questionAttemptData); - listMonitoredAnswersContainerDTO.add(voteMonitoredAnswersDTO); - - } - } - logger.debug("final listMonitoredAnswersContainerDTO:..." + listMonitoredAnswersContainerDTO); - return listMonitoredAnswersContainerDTO; + logger.debug("final sessionsMap:" + sessionsMap); + return sessionsMap; + } + + /** + * + * used in presenting user votes data + * + * @param request + * @param voteContent + * @param isUserNamesVisible + * @param isLearnerRequest + * @param currentSessionId + * @param userId + * @param voteService + * @return + */ + public static List buildGroupsQuestionData(HttpServletRequest request, VoteContent voteContent, + boolean isUserNamesVisible, boolean isLearnerRequest, String currentSessionId, String userId, + IVoteService voteService) { + logger.debug("isUserNamesVisible: " + isUserNamesVisible); + logger.debug("isLearnerRequest: " + isLearnerRequest); + logger.debug("userId: " + userId); + + logger.debug("voteService: " + voteService); + + logger.debug("will be building groups question data for content:..." + voteContent); + List listQuestions = voteService.getAllQuestionEntries(voteContent.getUid()); + logger.debug("listQuestions:..." + listQuestions); + + List listMonitoredAnswersContainerDTO = new LinkedList(); + + Iterator itListQuestions = listQuestions.iterator(); + while (itListQuestions.hasNext()) { + VoteQueContent voteQueContent = (VoteQueContent) itListQuestions.next(); + logger.debug("voteQueContent:..." + voteQueContent); + + if (voteQueContent != null) { + VoteMonitoredAnswersDTO voteMonitoredAnswersDTO = new VoteMonitoredAnswersDTO(); + voteMonitoredAnswersDTO.setQuestionUid(voteQueContent.getUid().toString()); + voteMonitoredAnswersDTO.setQuestion(voteQueContent.getQuestion()); + + logger.debug("using allUsersData to retrieve users data: " + isUserNamesVisible); + Map questionAttemptData = buildGroupsAttemptData(request, voteContent, voteQueContent, voteQueContent + .getUid().toString(), isUserNamesVisible, isLearnerRequest, currentSessionId, userId, + voteService); + logger.debug("questionAttemptData:..." + questionAttemptData); + voteMonitoredAnswersDTO.setQuestionAttempts(questionAttemptData); + listMonitoredAnswersContainerDTO.add(voteMonitoredAnswersDTO); + + } } - + logger.debug("final listMonitoredAnswersContainerDTO:..." + listMonitoredAnswersContainerDTO); + return listMonitoredAnswersContainerDTO; + } - /** - * groups user's votes - * - * @param request - * @param voteContent - * @param voteQueContent - * @param questionUid - * @param isUserNamesVisible - * @param isLearnerRequest - * @param currentSessionId - * @param userId - * @param voteService - * @return - */ - public static Map buildGroupsAttemptData(HttpServletRequest request, VoteContent voteContent, VoteQueContent voteQueContent, String questionUid, - boolean isUserNamesVisible, boolean isLearnerRequest, String currentSessionId, String userId, IVoteService voteService) - { - logger.debug("isUserNamesVisible: " + isUserNamesVisible); - logger.debug("isLearnerRequest: " + isLearnerRequest); - logger.debug("currentSessionId: " + currentSessionId); - logger.debug("userId: " + userId); - - logger.debug("doing buildGroupsAttemptData..."); - logger.debug("voteService: " + voteService); + /** + * groups user's votes + * + * @param request + * @param voteContent + * @param voteQueContent + * @param questionUid + * @param isUserNamesVisible + * @param isLearnerRequest + * @param currentSessionId + * @param userId + * @param voteService + * @return + */ + public static Map buildGroupsAttemptData(HttpServletRequest request, VoteContent voteContent, + VoteQueContent voteQueContent, String questionUid, boolean isUserNamesVisible, boolean isLearnerRequest, + String currentSessionId, String userId, IVoteService voteService) { + logger.debug("isUserNamesVisible: " + isUserNamesVisible); + logger.debug("isLearnerRequest: " + isLearnerRequest); + logger.debug("currentSessionId: " + currentSessionId); + logger.debug("userId: " + userId); - Map mapMonitoredAttemptsContainerDTO= new TreeMap(new VoteComparator()); - List listMonitoredAttemptsContainerDTO= new LinkedList(); - - Map summaryToolSessions=populateToolSessionsId(request, voteContent, voteService); - logger.debug("summaryToolSessions: " + summaryToolSessions); - - Iterator itMap = summaryToolSessions.entrySet().iterator(); - - - /*request is for monitoring summary */ - if (!isLearnerRequest) - { - while (itMap.hasNext()) - { - Map.Entry pairs = (Map.Entry)itMap.next(); - logger.debug("using the summary tool sessions pair: " + pairs.getKey() + " = " + pairs.getValue()); - - if (!(pairs.getValue().toString().equals("None")) && !(pairs.getValue().toString().equals("All"))) - { - logger.debug("using the numerical summary tool sessions pair: " + " = " + pairs.getValue()); - VoteSession voteSession= voteService.retrieveVoteSession(new Long(pairs.getValue().toString())); - logger.debug("voteSession: " + " = " + voteSession); - if (voteSession != null) - { - List listUsers=voteService.getUserBySessionOnly(voteSession); - logger.debug("listMcUsers for session id:" + voteSession.getVoteSessionId() + " = " + listUsers); - Map sessionUsersAttempts=populateSessionUsersAttempts(request,voteContent, voteSession.getVoteSessionId(), listUsers, questionUid, - isUserNamesVisible, isLearnerRequest, userId, voteService); - listMonitoredAttemptsContainerDTO.add(sessionUsersAttempts); - } - } - } - } - else - { - /*request is for learner report, use only the passed tool session in the report*/ - logger.debug("using currentSessionId for the learner report:" + currentSessionId); - while (itMap.hasNext()) - { - Map.Entry pairs = (Map.Entry)itMap.next(); - logger.debug("using the summary tool sessions pair: " + pairs.getKey() + " = " + pairs.getValue()); - - if (!(pairs.getValue().toString().equals("None")) && !(pairs.getValue().toString().equals("All"))) - { - logger.debug("using the numerical summary tool sessions pair: " + " = " + pairs.getValue()); - - if (currentSessionId.equals(pairs.getValue())) - { - logger.debug("only using this tool session for the learner report: " + " = " + pairs.getValue()); - VoteSession voteSession= voteService.retrieveVoteSession(new Long(pairs.getValue().toString())); - logger.debug("voteSession: " + " = " + voteSession); - if (voteSession != null) - { - List listUsers=voteService.getUserBySessionOnly(voteSession); - logger.debug("listMcUsers for session id:" + voteSession.getVoteSessionId() + " = " + listUsers); - Map sessionUsersAttempts=populateSessionUsersAttempts(request,voteContent, voteSession.getVoteSessionId(), listUsers, questionUid, - isUserNamesVisible, isLearnerRequest, userId, voteService); - listMonitoredAttemptsContainerDTO.add(sessionUsersAttempts); - } - } - } - } - } + logger.debug("doing buildGroupsAttemptData..."); + logger.debug("voteService: " + voteService); - logger.debug("final listMonitoredAttemptsContainerDTO:..." + listMonitoredAttemptsContainerDTO); - mapMonitoredAttemptsContainerDTO=convertToMap(listMonitoredAttemptsContainerDTO); - logger.debug("final mapMonitoredAttemptsContainerDTO:..." + mapMonitoredAttemptsContainerDTO); - return mapMonitoredAttemptsContainerDTO; + Map mapMonitoredAttemptsContainerDTO = new TreeMap(new VoteComparator()); + List listMonitoredAttemptsContainerDTO = new LinkedList(); + + Map summaryToolSessions = populateToolSessionsId(request, voteContent, voteService); + logger.debug("summaryToolSessions: " + summaryToolSessions); + + Iterator itMap = summaryToolSessions.entrySet().iterator(); + + /*request is for monitoring summary */ + if (!isLearnerRequest) { + while (itMap.hasNext()) { + Map.Entry pairs = (Map.Entry) itMap.next(); + logger.debug("using the summary tool sessions pair: " + pairs.getKey() + " = " + pairs.getValue()); + + if (!(pairs.getValue().toString().equals("None")) && !(pairs.getValue().toString().equals("All"))) { + logger.debug("using the numerical summary tool sessions pair: " + " = " + pairs.getValue()); + VoteSession voteSession = voteService.retrieveVoteSession(new Long(pairs.getValue().toString())); + logger.debug("voteSession: " + " = " + voteSession); + if (voteSession != null) { + List listUsers = voteService.getUserBySessionOnly(voteSession); + logger + .debug("listMcUsers for session id:" + voteSession.getVoteSessionId() + " = " + + listUsers); + Map sessionUsersAttempts = populateSessionUsersAttempts(request, voteContent, voteSession + .getVoteSessionId(), listUsers, questionUid, isUserNamesVisible, isLearnerRequest, + userId, voteService); + listMonitoredAttemptsContainerDTO.add(sessionUsersAttempts); + } + } + } + } else { + /*request is for learner report, use only the passed tool session in the report*/ + logger.debug("using currentSessionId for the learner report:" + currentSessionId); + while (itMap.hasNext()) { + Map.Entry pairs = (Map.Entry) itMap.next(); + logger.debug("using the summary tool sessions pair: " + pairs.getKey() + " = " + pairs.getValue()); + + if (!(pairs.getValue().toString().equals("None")) && !(pairs.getValue().toString().equals("All"))) { + logger.debug("using the numerical summary tool sessions pair: " + " = " + pairs.getValue()); + + if (currentSessionId.equals(pairs.getValue())) { + logger + .debug("only using this tool session for the learner report: " + " = " + + pairs.getValue()); + VoteSession voteSession = voteService + .retrieveVoteSession(new Long(pairs.getValue().toString())); + logger.debug("voteSession: " + " = " + voteSession); + if (voteSession != null) { + List listUsers = voteService.getUserBySessionOnly(voteSession); + logger.debug("listMcUsers for session id:" + voteSession.getVoteSessionId() + " = " + + listUsers); + Map sessionUsersAttempts = populateSessionUsersAttempts(request, voteContent, voteSession + .getVoteSessionId(), listUsers, questionUid, isUserNamesVisible, isLearnerRequest, + userId, voteService); + listMonitoredAttemptsContainerDTO.add(sessionUsersAttempts); + } + } + } + } } - - - public static Map populateSessionUsersAttempts(HttpServletRequest request, VoteContent voteContent, Long sessionId, List listUsers, - String questionUid, boolean isUserNamesVisible, boolean isLearnerRequest, String userId, IVoteService voteService) - { - logger.debug("doing populateSessionUsersAttempts for: " +questionUid); - logger.debug("isUserNamesVisible: " + isUserNamesVisible); - logger.debug("isLearnerRequest: " + isLearnerRequest); - logger.debug("voteContent: " + voteContent); - logger.debug("userId: " + userId); - - logger.debug("doing populateSessionUsersAttempts..."); - logger.debug("voteService: " + voteService); - - Map mapMonitoredUserContainerDTO= new TreeMap(new VoteStringComparator()); - List listMonitoredUserContainerDTO= new LinkedList(); - Iterator itUsers=listUsers.iterator(); - - - if (userId == null) - { - logger.debug("request is not for learner progress report"); - if ((isUserNamesVisible) && (!isLearnerRequest)) - { - logger.debug("summary reporting case 1" ); - logger.debug("isUserNamesVisible true, isLearnerRequest false" ); - logger.debug("getting alll the user' data"); - while (itUsers.hasNext()) - { - VoteQueUsr voteQueUsr=(VoteQueUsr)itUsers.next(); - logger.debug("voteQueUsr: " + voteQueUsr); - - if (voteQueUsr != null) - { - logger.debug("getting listUserAttempts for user id: " + voteQueUsr.getUid() + " and que content id: " + questionUid); - List listUserAttempts=voteService.getAttemptsListForUserAndQuestionContent(voteQueUsr.getUid(), new Long(questionUid)); - logger.debug("listUserAttempts: " + listUserAttempts); - - Iterator itAttempts=listUserAttempts.iterator(); - while (itAttempts.hasNext()) - { - VoteUsrAttempt voteUsrResp=(VoteUsrAttempt)itAttempts.next(); - logger.debug("voteUsrResp: " + voteUsrResp); - - if (voteUsrResp != null) - { - VoteMonitoredUserDTO voteMonitoredUserDTO = new VoteMonitoredUserDTO(); - voteMonitoredUserDTO.setAttemptTime(voteUsrResp.getAttemptTime()); - voteMonitoredUserDTO.setTimeZone(voteUsrResp.getTimeZone()); - voteMonitoredUserDTO.setUserName(voteQueUsr.getFullname()); - voteMonitoredUserDTO.setQueUsrId(voteQueUsr.getUid().toString()); - voteMonitoredUserDTO.setSessionId(sessionId.toString()); - voteMonitoredUserDTO.setUserEntry(voteUsrResp.getUserEntry()); - - logger.debug("attempt: " + voteUsrResp); - voteMonitoredUserDTO.setQuestionUid(questionUid); - - VoteQueContent voteQueContent=voteUsrResp.getVoteQueContent(); - logger.debug("voteQueContent: " + voteQueContent); - String entry=voteQueContent.getQuestion(); - logger.debug("entry: " + entry); - String voteQueContentId=voteUsrResp.getVoteQueContentId().toString(); - logger.debug("voteQueContentId: " + voteQueContentId); - - VoteSession localUserSession=voteUsrResp.getVoteQueUsr().getVoteSession(); - logger.debug("localUserSession: " + localUserSession); - logger.debug("localUserSession's content id: " + localUserSession.getVoteContentId()); - logger.debug("incoming content id versus localUserSession's content id: " + voteContent.getVoteContentId() + " versus " + localUserSession.getVoteContentId()); - logger.debug("summary reporting case 1" ); - if (voteContent.getVoteContentId().toString().equals(localUserSession.getVoteContentId().toString())) - { - if (entry != null) - { - if (entry.equals("sample nomination") && (voteQueContentId.equals("1"))) - { - logger.debug("this nomination entry points to a user entered nomination: " + voteUsrResp.getUserEntry()); - voteMonitoredUserDTO.setResponse(voteUsrResp.getUserEntry()); - } - else - { - logger.debug("this nomination entry points to a standard nomination: " + voteQueContent.getQuestion()); - voteMonitoredUserDTO.setResponse(voteQueContent.getQuestion()); - } - } - } - - listMonitoredUserContainerDTO.add(voteMonitoredUserDTO); - } - } - } + logger.debug("final listMonitoredAttemptsContainerDTO:..." + listMonitoredAttemptsContainerDTO); + mapMonitoredAttemptsContainerDTO = convertToMap(listMonitoredAttemptsContainerDTO); + logger.debug("final mapMonitoredAttemptsContainerDTO:..." + mapMonitoredAttemptsContainerDTO); + return mapMonitoredAttemptsContainerDTO; + } + + public static Map populateSessionUsersAttempts(HttpServletRequest request, VoteContent voteContent, Long sessionId, + List listUsers, String questionUid, boolean isUserNamesVisible, boolean isLearnerRequest, String userId, + IVoteService voteService) { + logger.debug("doing populateSessionUsersAttempts for: " + questionUid); + logger.debug("isUserNamesVisible: " + isUserNamesVisible); + logger.debug("isLearnerRequest: " + isLearnerRequest); + logger.debug("voteContent: " + voteContent); + logger.debug("userId: " + userId); + + logger.debug("doing populateSessionUsersAttempts..."); + logger.debug("voteService: " + voteService); + + Map mapMonitoredUserContainerDTO = new TreeMap(new VoteStringComparator()); + List listMonitoredUserContainerDTO = new LinkedList(); + Iterator itUsers = listUsers.iterator(); + + if (userId == null) { + logger.debug("request is not for learner progress report"); + if ((isUserNamesVisible) && (!isLearnerRequest)) { + logger.debug("summary reporting case 1"); + logger.debug("isUserNamesVisible true, isLearnerRequest false"); + logger.debug("getting alll the user' data"); + while (itUsers.hasNext()) { + VoteQueUsr voteQueUsr = (VoteQueUsr) itUsers.next(); + logger.debug("voteQueUsr: " + voteQueUsr); + + if (voteQueUsr != null) { + logger.debug("getting listUserAttempts for user id: " + voteQueUsr.getUid() + + " and que content id: " + questionUid); + List listUserAttempts = voteService.getAttemptsListForUserAndQuestionContent(voteQueUsr + .getUid(), new Long(questionUid)); + logger.debug("listUserAttempts: " + listUserAttempts); + + Iterator itAttempts = listUserAttempts.iterator(); + while (itAttempts.hasNext()) { + VoteUsrAttempt voteUsrResp = (VoteUsrAttempt) itAttempts.next(); + logger.debug("voteUsrResp: " + voteUsrResp); + + if (voteUsrResp != null) { + VoteMonitoredUserDTO voteMonitoredUserDTO = new VoteMonitoredUserDTO(); + voteMonitoredUserDTO.setAttemptTime(voteUsrResp.getAttemptTime()); + voteMonitoredUserDTO.setTimeZone(voteUsrResp.getTimeZone()); + voteMonitoredUserDTO.setUserName(voteQueUsr.getFullname()); + voteMonitoredUserDTO.setQueUsrId(voteQueUsr.getUid().toString()); + voteMonitoredUserDTO.setSessionId(sessionId.toString()); + voteMonitoredUserDTO.setUserEntry(voteUsrResp.getUserEntry()); + + logger.debug("attempt: " + voteUsrResp); + voteMonitoredUserDTO.setQuestionUid(questionUid); + + VoteQueContent voteQueContent = voteUsrResp.getVoteQueContent(); + logger.debug("voteQueContent: " + voteQueContent); + String entry = voteQueContent.getQuestion(); + logger.debug("entry: " + entry); + + String voteQueContentId = voteUsrResp.getVoteQueContentId().toString(); + logger.debug("voteQueContentId: " + voteQueContentId); + + VoteSession localUserSession = voteUsrResp.getVoteQueUsr().getVoteSession(); + logger.debug("localUserSession: " + localUserSession); + logger.debug("localUserSession's content id: " + localUserSession.getVoteContentId()); + logger.debug("incoming content id versus localUserSession's content id: " + + voteContent.getVoteContentId() + " versus " + + localUserSession.getVoteContentId()); + logger.debug("summary reporting case 1"); + if (voteContent.getVoteContentId().toString().equals( + localUserSession.getVoteContentId().toString())) { + if (entry != null) { + if (entry.equals("sample nomination") && (voteQueContentId.equals("1"))) { + logger.debug("this nomination entry points to a user entered nomination: " + + voteUsrResp.getUserEntry()); + voteMonitoredUserDTO.setResponse(voteUsrResp.getUserEntry()); + } else { + logger.debug("this nomination entry points to a standard nomination: " + + voteQueContent.getQuestion()); + voteMonitoredUserDTO.setResponse(voteQueContent.getQuestion()); + } + } } + + listMonitoredUserContainerDTO.add(voteMonitoredUserDTO); + } } - else if ((isUserNamesVisible) && (isLearnerRequest)) - { - logger.debug("summary reporting case 2" ); - logger.debug("just populating data normally just like monitoring summary, except that the data is ony for a specific session" ); - logger.debug("isUserNamesVisible true, isLearnerRequest true" ); - String userID= (String)request.getSession().getAttribute(USER_ID); - logger.debug("userID: " + userID); - VoteQueUsr voteQueUsr=voteService.getVoteQueUsrById(new Long(userID).longValue()); - logger.debug("the current user voteQueUsr " + voteQueUsr + " and username: " + voteQueUsr.getUsername()); - - while (itUsers.hasNext()) - { - voteQueUsr=(VoteQueUsr)itUsers.next(); - logger.debug("voteQueUsr: " + voteQueUsr); - - if (voteQueUsr != null) - { - logger.debug("getting listUserAttempts for user id: " + voteQueUsr.getUid() + " and que content id: " + questionUid); - List listUserAttempts=voteService.getAttemptsListForUserAndQuestionContent(voteQueUsr.getUid(), new Long(questionUid)); - logger.debug("listUserAttempts: " + listUserAttempts); - - Iterator itAttempts=listUserAttempts.iterator(); - while (itAttempts.hasNext()) - { - VoteUsrAttempt voteUsrResp=(VoteUsrAttempt)itAttempts.next(); - logger.debug("voteUsrResp: " + voteUsrResp); - - if (voteUsrResp != null) - { - VoteMonitoredUserDTO voteMonitoredUserDTO = new VoteMonitoredUserDTO(); - voteMonitoredUserDTO.setAttemptTime(voteUsrResp.getAttemptTime()); - voteMonitoredUserDTO.setTimeZone(voteUsrResp.getTimeZone()); - voteMonitoredUserDTO.setUid(voteUsrResp.getUid().toString()); - voteMonitoredUserDTO.setUserName(voteQueUsr.getFullname()); - voteMonitoredUserDTO.setQueUsrId(voteQueUsr.getUid().toString()); - voteMonitoredUserDTO.setSessionId(sessionId.toString()); - voteMonitoredUserDTO.setUserEntry(voteUsrResp.getUserEntry()); - logger.debug("attempt: " + voteUsrResp); - voteMonitoredUserDTO.setQuestionUid(questionUid); - - VoteQueContent voteQueContent=voteUsrResp.getVoteQueContent(); - logger.debug("voteQueContent: " + voteQueContent); - String entry=voteQueContent.getQuestion(); - logger.debug("entry: " + entry); - String voteQueContentId=voteUsrResp.getVoteQueContentId().toString(); - logger.debug("voteQueContentId: " + voteQueContentId); + } + } + } else if ((isUserNamesVisible) && (isLearnerRequest)) { + logger.debug("summary reporting case 2"); + logger + .debug("just populating data normally just like monitoring summary, except that the data is ony for a specific session"); + logger.debug("isUserNamesVisible true, isLearnerRequest true"); + String userID = (String) request.getSession().getAttribute(USER_ID); + logger.debug("userID: " + userID); + VoteQueUsr voteQueUsr = voteService.getVoteQueUsrById(new Long(userID).longValue()); + logger + .debug("the current user voteQueUsr " + voteQueUsr + " and username: " + + voteQueUsr.getUsername()); - VoteSession localUserSession=voteUsrResp.getVoteQueUsr().getVoteSession(); - logger.debug("localUserSession: " + localUserSession); - logger.debug("localUserSession's content id: " + localUserSession.getVoteContentId()); - logger.debug("incoming content id versus localUserSession's content id: " + voteContent.getVoteContentId() + " versus " + localUserSession.getVoteContentId()); - logger.debug("summary reporting case 2" ); - if (voteContent.getVoteContentId().toString().equals(localUserSession.getVoteContentId().toString())) - { - if (entry != null) - { - if (entry.equals("sample nomination") && (voteQueContentId.equals("1"))) - { - logger.debug("this nomination entry points to a user entered nomination: " + voteUsrResp.getUserEntry()); - voteMonitoredUserDTO.setResponse(voteUsrResp.getUserEntry()); - } - else - { - logger.debug("this nomination entry points to a standard nomination: " + voteQueContent.getQuestion()); - voteMonitoredUserDTO.setResponse(voteQueContent.getQuestion()); - } - } - } - - - listMonitoredUserContainerDTO.add(voteMonitoredUserDTO); - } - } - } + while (itUsers.hasNext()) { + voteQueUsr = (VoteQueUsr) itUsers.next(); + logger.debug("voteQueUsr: " + voteQueUsr); + + if (voteQueUsr != null) { + logger.debug("getting listUserAttempts for user id: " + voteQueUsr.getUid() + + " and que content id: " + questionUid); + List listUserAttempts = voteService.getAttemptsListForUserAndQuestionContent(voteQueUsr + .getUid(), new Long(questionUid)); + logger.debug("listUserAttempts: " + listUserAttempts); + + Iterator itAttempts = listUserAttempts.iterator(); + while (itAttempts.hasNext()) { + VoteUsrAttempt voteUsrResp = (VoteUsrAttempt) itAttempts.next(); + logger.debug("voteUsrResp: " + voteUsrResp); + + if (voteUsrResp != null) { + VoteMonitoredUserDTO voteMonitoredUserDTO = new VoteMonitoredUserDTO(); + voteMonitoredUserDTO.setAttemptTime(voteUsrResp.getAttemptTime()); + voteMonitoredUserDTO.setTimeZone(voteUsrResp.getTimeZone()); + voteMonitoredUserDTO.setUid(voteUsrResp.getUid().toString()); + voteMonitoredUserDTO.setUserName(voteQueUsr.getFullname()); + voteMonitoredUserDTO.setQueUsrId(voteQueUsr.getUid().toString()); + voteMonitoredUserDTO.setSessionId(sessionId.toString()); + voteMonitoredUserDTO.setUserEntry(voteUsrResp.getUserEntry()); + logger.debug("attempt: " + voteUsrResp); + voteMonitoredUserDTO.setQuestionUid(questionUid); + + VoteQueContent voteQueContent = voteUsrResp.getVoteQueContent(); + logger.debug("voteQueContent: " + voteQueContent); + String entry = voteQueContent.getQuestion(); + logger.debug("entry: " + entry); + String voteQueContentId = voteUsrResp.getVoteQueContentId().toString(); + logger.debug("voteQueContentId: " + voteQueContentId); + + VoteSession localUserSession = voteUsrResp.getVoteQueUsr().getVoteSession(); + logger.debug("localUserSession: " + localUserSession); + logger.debug("localUserSession's content id: " + localUserSession.getVoteContentId()); + logger.debug("incoming content id versus localUserSession's content id: " + + voteContent.getVoteContentId() + " versus " + + localUserSession.getVoteContentId()); + logger.debug("summary reporting case 2"); + if (voteContent.getVoteContentId().toString().equals( + localUserSession.getVoteContentId().toString())) { + if (entry != null) { + if (entry.equals("sample nomination") && (voteQueContentId.equals("1"))) { + logger.debug("this nomination entry points to a user entered nomination: " + + voteUsrResp.getUserEntry()); + voteMonitoredUserDTO.setResponse(voteUsrResp.getUserEntry()); + } else { + logger.debug("this nomination entry points to a standard nomination: " + + voteQueContent.getQuestion()); + voteMonitoredUserDTO.setResponse(voteQueContent.getQuestion()); } + } } - else if ((!isUserNamesVisible) && (isLearnerRequest)) - { - logger.debug("summary reporting case 3" ); - logger.debug("populating data normally exception are for a specific session and other user names are not visible."); - logger.debug("isUserNamesVisible false, isLearnerRequest true" ); - logger.debug("getting only current user's data" ); - String userID= (String)request.getSession().getAttribute(USER_ID); - logger.debug("userID: " + userID); - - while (itUsers.hasNext()) - { - VoteQueUsr voteQueUsr=(VoteQueUsr)itUsers.next(); - logger.debug("voteQueUsr: " + voteQueUsr); - - if (voteQueUsr != null) - { - logger.debug("getting listUserAttempts for user id: " + voteQueUsr.getUid() + " and que content id: " + questionUid); - List listUserAttempts=voteService.getAttemptsListForUserAndQuestionContent(voteQueUsr.getUid(), new Long(questionUid)); - logger.debug("listUserAttempts: " + listUserAttempts); - - Iterator itAttempts=listUserAttempts.iterator(); - while (itAttempts.hasNext()) - { - VoteUsrAttempt voteUsrResp=(VoteUsrAttempt)itAttempts.next(); - logger.debug("voteUsrResp: " + voteUsrResp); - - if (voteUsrResp != null) - { - VoteMonitoredUserDTO voteMonitoredUserDTO = new VoteMonitoredUserDTO(); - voteMonitoredUserDTO.setAttemptTime(voteUsrResp.getAttemptTime()); - voteMonitoredUserDTO.setTimeZone(voteUsrResp.getTimeZone()); - voteMonitoredUserDTO.setUid(voteUsrResp.getUid().toString()); - - logger.debug("userID versus queUsrId: " + userID + "-" + voteQueUsr.getQueUsrId()); - if (userID.equals(voteQueUsr.getQueUsrId().toString())) - { - logger.debug("this is current user, put his name normally."); - voteMonitoredUserDTO.setUserName(voteQueUsr.getFullname()); - } - else - { - logger.debug("this is not current user, put his name as blank."); - voteMonitoredUserDTO.setUserName("[ ]"); - } - - voteMonitoredUserDTO.setQueUsrId(voteQueUsr.getUid().toString()); - voteMonitoredUserDTO.setSessionId(sessionId.toString()); - logger.debug("attempt: " + voteUsrResp); - voteMonitoredUserDTO.setQuestionUid(questionUid); - voteMonitoredUserDTO.setUserEntry(voteUsrResp.getUserEntry()); - - VoteQueContent voteQueContent=voteUsrResp.getVoteQueContent(); - logger.debug("voteQueContent: " + voteQueContent); - String entry=voteQueContent.getQuestion(); - logger.debug("entry: " + entry); + listMonitoredUserContainerDTO.add(voteMonitoredUserDTO); + } + } + } + } + } else if ((!isUserNamesVisible) && (isLearnerRequest)) { + logger.debug("summary reporting case 3"); + logger + .debug("populating data normally exception are for a specific session and other user names are not visible."); + logger.debug("isUserNamesVisible false, isLearnerRequest true"); + logger.debug("getting only current user's data"); + String userID = (String) request.getSession().getAttribute(USER_ID); + logger.debug("userID: " + userID); - String voteQueContentId=voteUsrResp.getVoteQueContentId().toString(); - logger.debug("voteQueContentId: " + voteQueContentId); - - VoteSession localUserSession=voteUsrResp.getVoteQueUsr().getVoteSession(); - logger.debug("localUserSession: " + localUserSession); - logger.debug("localUserSession's content id: " + localUserSession.getVoteContentId()); - logger.debug("incoming content id versus localUserSession's content id: " + voteContent.getVoteContentId() + " versus " + localUserSession.getVoteContentId()); - logger.debug("summary reporting case 3" ); - if (voteContent.getVoteContentId().toString().equals(localUserSession.getVoteContentId().toString())) - { - if (entry != null) - { - if (entry.equals("sample nomination") && (voteQueContentId.equals("1"))) - { - logger.debug("this nomination entry points to a user entered nomination: " + voteUsrResp.getUserEntry()); - voteMonitoredUserDTO.setResponse(voteUsrResp.getUserEntry()); - } - else - { - logger.debug("this nomination entry points to a standard nomination: " + voteQueContent.getQuestion()); - voteMonitoredUserDTO.setResponse(voteQueContent.getQuestion()); - } - } - } + while (itUsers.hasNext()) { + VoteQueUsr voteQueUsr = (VoteQueUsr) itUsers.next(); + logger.debug("voteQueUsr: " + voteQueUsr); - listMonitoredUserContainerDTO.add(voteMonitoredUserDTO); + if (voteQueUsr != null) { + logger.debug("getting listUserAttempts for user id: " + voteQueUsr.getUid() + + " and que content id: " + questionUid); + List listUserAttempts = voteService.getAttemptsListForUserAndQuestionContent(voteQueUsr + .getUid(), new Long(questionUid)); + logger.debug("listUserAttempts: " + listUserAttempts); - } - } - } - } + Iterator itAttempts = listUserAttempts.iterator(); + while (itAttempts.hasNext()) { + VoteUsrAttempt voteUsrResp = (VoteUsrAttempt) itAttempts.next(); + logger.debug("voteUsrResp: " + voteUsrResp); + + if (voteUsrResp != null) { + VoteMonitoredUserDTO voteMonitoredUserDTO = new VoteMonitoredUserDTO(); + voteMonitoredUserDTO.setAttemptTime(voteUsrResp.getAttemptTime()); + voteMonitoredUserDTO.setTimeZone(voteUsrResp.getTimeZone()); + voteMonitoredUserDTO.setUid(voteUsrResp.getUid().toString()); + + logger.debug("userID versus queUsrId: " + userID + "-" + voteQueUsr.getQueUsrId()); + if (userID.equals(voteQueUsr.getQueUsrId().toString())) { + logger.debug("this is current user, put his name normally."); + voteMonitoredUserDTO.setUserName(voteQueUsr.getFullname()); + } else { + logger.debug("this is not current user, put his name as blank."); + voteMonitoredUserDTO.setUserName("[ ]"); } + + voteMonitoredUserDTO.setQueUsrId(voteQueUsr.getUid().toString()); + voteMonitoredUserDTO.setSessionId(sessionId.toString()); + + logger.debug("attempt: " + voteUsrResp); + voteMonitoredUserDTO.setQuestionUid(questionUid); + voteMonitoredUserDTO.setUserEntry(voteUsrResp.getUserEntry()); + + VoteQueContent voteQueContent = voteUsrResp.getVoteQueContent(); + logger.debug("voteQueContent: " + voteQueContent); + String entry = voteQueContent.getQuestion(); + logger.debug("entry: " + entry); + + String voteQueContentId = voteUsrResp.getVoteQueContentId().toString(); + logger.debug("voteQueContentId: " + voteQueContentId); + + VoteSession localUserSession = voteUsrResp.getVoteQueUsr().getVoteSession(); + logger.debug("localUserSession: " + localUserSession); + logger.debug("localUserSession's content id: " + localUserSession.getVoteContentId()); + logger.debug("incoming content id versus localUserSession's content id: " + + voteContent.getVoteContentId() + " versus " + + localUserSession.getVoteContentId()); + logger.debug("summary reporting case 3"); + if (voteContent.getVoteContentId().toString().equals( + localUserSession.getVoteContentId().toString())) { + if (entry != null) { + if (entry.equals("sample nomination") && (voteQueContentId.equals("1"))) { + logger.debug("this nomination entry points to a user entered nomination: " + + voteUsrResp.getUserEntry()); + voteMonitoredUserDTO.setResponse(voteUsrResp.getUserEntry()); + } else { + logger.debug("this nomination entry points to a standard nomination: " + + voteQueContent.getQuestion()); + voteMonitoredUserDTO.setResponse(voteQueContent.getQuestion()); + } + } + } + + listMonitoredUserContainerDTO.add(voteMonitoredUserDTO); + + } + } + } } - else - { - logger.debug("summary reporting case 4" ); - logger.debug("request is for learner progress report: " + userId); - while (itUsers.hasNext()) - { - VoteQueUsr voteQueUsr=(VoteQueUsr)itUsers.next(); - logger.debug("voteQueUsr: " + voteQueUsr); - - if (voteQueUsr != null) - { - logger.debug("getting listUserAttempts for user id: " + voteQueUsr.getUid() + " and que content id: " + questionUid); - List listUserAttempts=voteService.getAttemptsListForUserAndQuestionContent(voteQueUsr.getUid(), new Long(questionUid)); - logger.debug("listUserAttempts: " + listUserAttempts); + } + } else { + logger.debug("summary reporting case 4"); + logger.debug("request is for learner progress report: " + userId); + while (itUsers.hasNext()) { + VoteQueUsr voteQueUsr = (VoteQueUsr) itUsers.next(); + logger.debug("voteQueUsr: " + voteQueUsr); - Iterator itAttempts=listUserAttempts.iterator(); - while (itAttempts.hasNext()) - { - VoteUsrAttempt voteUsrResp=(VoteUsrAttempt)itAttempts.next(); - logger.debug("voteUsrResp: " + voteUsrResp); - - if (voteUsrResp != null) - { - logger.debug("userID versus queUsrId: " + userId + "-" + voteQueUsr.getQueUsrId()); - if (userId.equals(voteQueUsr.getQueUsrId().toString())) - { - logger.debug("this is the user requested , include his name for learner progress."); - VoteMonitoredUserDTO voteMonitoredUserDTO = new VoteMonitoredUserDTO(); - voteMonitoredUserDTO.setAttemptTime(voteUsrResp.getAttemptTime()); - voteMonitoredUserDTO.setTimeZone(voteUsrResp.getTimeZone()); - voteMonitoredUserDTO.setUid(voteUsrResp.getUid().toString()); - voteMonitoredUserDTO.setUserName(voteQueUsr.getFullname()); - voteMonitoredUserDTO.setQueUsrId(voteQueUsr.getUid().toString()); - voteMonitoredUserDTO.setSessionId(sessionId.toString()); - voteMonitoredUserDTO.setUserEntry(voteUsrResp.getUserEntry()); - logger.debug("attempt: " + voteUsrResp); - voteMonitoredUserDTO.setQuestionUid(questionUid); - - - VoteQueContent voteQueContent=voteUsrResp.getVoteQueContent(); - logger.debug("voteQueContent: " + voteQueContent); - String entry=voteQueContent.getQuestion(); - logger.debug("entry: " + entry); + if (voteQueUsr != null) { + logger.debug("getting listUserAttempts for user id: " + voteQueUsr.getUid() + + " and que content id: " + questionUid); + List listUserAttempts = voteService.getAttemptsListForUserAndQuestionContent(voteQueUsr.getUid(), + new Long(questionUid)); + logger.debug("listUserAttempts: " + listUserAttempts); - String voteQueContentId=voteUsrResp.getVoteQueContentId().toString(); - logger.debug("voteQueContentId: " + voteQueContentId); - - VoteSession localUserSession=voteUsrResp.getVoteQueUsr().getVoteSession(); - logger.debug("localUserSession: " + localUserSession); - logger.debug("localUserSession's content id: " + localUserSession.getVoteContentId()); - logger.debug("incoming content id versus localUserSession's content id: " + voteContent.getVoteContentId() + " versus " + localUserSession.getVoteContentId()); - logger.debug("summary reporting case 4" ); - if (voteContent.getVoteContentId().toString().equals(localUserSession.getVoteContentId().toString())) - { - if (entry != null) - { - if (entry.equals("sample nomination") && (voteQueContentId.equals("1"))) - { - logger.debug("this nomination entry points to a user entered nomination: " + voteUsrResp.getUserEntry()); - voteMonitoredUserDTO.setResponse(voteUsrResp.getUserEntry()); - } - else - { - logger.debug("this nomination entry points to a standard nomination: " + voteQueContent.getQuestion()); - voteMonitoredUserDTO.setResponse(voteQueContent.getQuestion()); - } - } - } + Iterator itAttempts = listUserAttempts.iterator(); + while (itAttempts.hasNext()) { + VoteUsrAttempt voteUsrResp = (VoteUsrAttempt) itAttempts.next(); + logger.debug("voteUsrResp: " + voteUsrResp); - listMonitoredUserContainerDTO.add(voteMonitoredUserDTO); - } - } - } - } - } - + if (voteUsrResp != null) { + logger.debug("userID versus queUsrId: " + userId + "-" + voteQueUsr.getQueUsrId()); + if (userId.equals(voteQueUsr.getQueUsrId().toString())) { + logger.debug("this is the user requested , include his name for learner progress."); + VoteMonitoredUserDTO voteMonitoredUserDTO = new VoteMonitoredUserDTO(); + voteMonitoredUserDTO.setAttemptTime(voteUsrResp.getAttemptTime()); + voteMonitoredUserDTO.setTimeZone(voteUsrResp.getTimeZone()); + voteMonitoredUserDTO.setUid(voteUsrResp.getUid().toString()); + voteMonitoredUserDTO.setUserName(voteQueUsr.getFullname()); + voteMonitoredUserDTO.setQueUsrId(voteQueUsr.getUid().toString()); + voteMonitoredUserDTO.setSessionId(sessionId.toString()); + voteMonitoredUserDTO.setUserEntry(voteUsrResp.getUserEntry()); + logger.debug("attempt: " + voteUsrResp); + voteMonitoredUserDTO.setQuestionUid(questionUid); + + VoteQueContent voteQueContent = voteUsrResp.getVoteQueContent(); + logger.debug("voteQueContent: " + voteQueContent); + String entry = voteQueContent.getQuestion(); + logger.debug("entry: " + entry); + + String voteQueContentId = voteUsrResp.getVoteQueContentId().toString(); + logger.debug("voteQueContentId: " + voteQueContentId); + + VoteSession localUserSession = voteUsrResp.getVoteQueUsr().getVoteSession(); + logger.debug("localUserSession: " + localUserSession); + logger.debug("localUserSession's content id: " + localUserSession.getVoteContentId()); + logger.debug("incoming content id versus localUserSession's content id: " + + voteContent.getVoteContentId() + " versus " + + localUserSession.getVoteContentId()); + logger.debug("summary reporting case 4"); + if (voteContent.getVoteContentId().toString().equals( + localUserSession.getVoteContentId().toString())) { + if (entry != null) { + if (entry.equals("sample nomination") && (voteQueContentId.equals("1"))) { + logger.debug("this nomination entry points to a user entered nomination: " + + voteUsrResp.getUserEntry()); + voteMonitoredUserDTO.setResponse(voteUsrResp.getUserEntry()); + } else { + logger.debug("this nomination entry points to a standard nomination: " + + voteQueContent.getQuestion()); + voteMonitoredUserDTO.setResponse(voteQueContent.getQuestion()); + } + } + } + + listMonitoredUserContainerDTO.add(voteMonitoredUserDTO); + } + } + } } - - - logger.debug("final listMonitoredUserContainerDTO: " + listMonitoredUserContainerDTO); - mapMonitoredUserContainerDTO=convertToVoteMonitoredUserDTOMap(listMonitoredUserContainerDTO); - logger.debug("final mapMonitoredUserContainerDTO:..." + mapMonitoredUserContainerDTO); - return mapMonitoredUserContainerDTO; + } + } - - - public static Map populateToolSessionsId(HttpServletRequest request, VoteContent voteContent, IVoteService voteService) - { - logger.debug("attempt populateToolSessionsId for: " + voteContent); - List sessionsList=voteService.getSessionsFromContent(voteContent); - logger.debug("sessionsList size is:..." + sessionsList.size()); - - Map sessionsMap=VoteUtils.convertToStringMap(sessionsList, "Long"); - logger.debug("generated sessionsMap:..." + sessionsMap); - logger.debug("sessionsMap size:..." + sessionsMap.size()); - - if (sessionsMap.isEmpty()) - { - logger.debug("sessionsMap size is 0:"); - sessionsMap.put(new Long(1).toString() , "None"); - } - else - { - logger.debug("sessionsMap has some entries: " + sessionsMap.size()); - sessionsMap.put(new Long(sessionsMap.size()+ 1).toString() , "All"); - } - - logger.debug("final sessionsMap:" + sessionsMap); - return sessionsMap; + logger.debug("final listMonitoredUserContainerDTO: " + listMonitoredUserContainerDTO); + mapMonitoredUserContainerDTO = convertToVoteMonitoredUserDTOMap(listMonitoredUserContainerDTO); + logger.debug("final mapMonitoredUserContainerDTO:..." + mapMonitoredUserContainerDTO); + return mapMonitoredUserContainerDTO; + } + + public static Map populateToolSessionsId(HttpServletRequest request, VoteContent voteContent, + IVoteService voteService) { + logger.debug("attempt populateToolSessionsId for: " + voteContent); + List sessionsList = voteService.getSessionsFromContent(voteContent); + logger.debug("sessionsList size is:..." + sessionsList.size()); + + Map sessionsMap = VoteUtils.convertToStringMap(sessionsList, "Long"); + logger.debug("generated sessionsMap:..." + sessionsMap); + logger.debug("sessionsMap size:..." + sessionsMap.size()); + + if (sessionsMap.isEmpty()) { + logger.debug("sessionsMap size is 0:"); + sessionsMap.put(new Long(1).toString(), "None"); + } else { + logger.debug("sessionsMap has some entries: " + sessionsMap.size()); + sessionsMap.put(new Long(sessionsMap.size() + 1).toString(), "All"); } - public static Map convertToVoteMonitoredUserDTOMap(List list) - { - logger.debug("using convertToVoteMonitoredUserDTOMap: " + list); - Map map= new TreeMap(new VoteComparator()); - - Iterator listIterator=list.iterator(); - Long mapIndex=new Long(1); - - while (listIterator.hasNext()) - { - VoteMonitoredUserDTO data=(VoteMonitoredUserDTO)listIterator.next(); - logger.debug("using data: " + data); - logger.debug("using data: " + data.getResponse()); - logger.debug("using session id: " + data.getSessionId()); - logger.debug("using question uid: " + data.getQuestionUid()) ; - - - map.put(mapIndex.toString(), data); - mapIndex=new Long(mapIndex.longValue()+1); - } - return map; + logger.debug("final sessionsMap:" + sessionsMap); + return sessionsMap; + } + + public static Map convertToVoteMonitoredUserDTOMap(List list) { + logger.debug("using convertToVoteMonitoredUserDTOMap: " + list); + Map map = new TreeMap(new VoteComparator()); + + Iterator listIterator = list.iterator(); + Long mapIndex = new Long(1); + + while (listIterator.hasNext()) { + VoteMonitoredUserDTO data = (VoteMonitoredUserDTO) listIterator.next(); + logger.debug("using data: " + data); + logger.debug("using data: " + data.getResponse()); + logger.debug("using session id: " + data.getSessionId()); + logger.debug("using question uid: " + data.getQuestionUid()); + + map.put(mapIndex.toString(), data); + mapIndex = new Long(mapIndex.longValue() + 1); } + return map; + } - - public static double calculateTotal(Map mapVoteRatesContent) - { - logger.debug("calculating total for: " + mapVoteRatesContent); - double total=0d; - Iterator itMap = mapVoteRatesContent.entrySet().iterator(); - while (itMap.hasNext()) { - Map.Entry pairs = (Map.Entry)itMap.next(); - logger.debug("using the pair: " + pairs.getKey() + " = " + pairs.getValue()); - - if (pairs.getValue() != null) - { - total=total+ new Double(pairs.getValue().toString()).doubleValue(); - } - logger.debug("total: " + total); - } - return total; + public static double calculateTotal(Map mapVoteRatesContent) { + logger.debug("calculating total for: " + mapVoteRatesContent); + double total = 0d; + Iterator itMap = mapVoteRatesContent.entrySet().iterator(); + while (itMap.hasNext()) { + Map.Entry pairs = (Map.Entry) itMap.next(); + logger.debug("using the pair: " + pairs.getKey() + " = " + pairs.getValue()); + + if (pairs.getValue() != null) { + total = total + new Double(pairs.getValue().toString()).doubleValue(); + } + logger.debug("total: " + total); } + return total; + } - - public static Map convertToMap(List list) - { - logger.debug("using convertToMap: " + list); - Map map= new TreeMap(new VoteComparator()); - - Iterator listIterator=list.iterator(); - Long mapIndex=new Long(1); - - while (listIterator.hasNext()) - { - Map data=(Map)listIterator.next(); - map.put(mapIndex.toString(), data); - mapIndex=new Long(mapIndex.longValue()+1); - } - return map; + public static Map convertToMap(List list) { + logger.debug("using convertToMap: " + list); + Map map = new TreeMap(new VoteComparator()); + + Iterator listIterator = list.iterator(); + Long mapIndex = new Long(1); + + while (listIterator.hasNext()) { + Map data = (Map) listIterator.next(); + map.put(mapIndex.toString(), data); + mapIndex = new Long(mapIndex.longValue() + 1); } + return map; + } - /** - * Generates JFreeChart data for all sessions in the Monitoring Summary. - * @param request - * @param voteService - * @param voteMonitoringForm - * @param toolContentID - * @return - */ - public static List prepareChartDTO(HttpServletRequest request, IVoteService voteService, VoteMonitoringForm voteMonitoringForm, - Long toolContentID, MessageService messageService) - { - logger.debug("start preparing ChartDTO with voteMonitoringForm: " + voteMonitoringForm); - logger.debug("start preparing ChartDTO with toolContentID: " + toolContentID); - - List listVoteAllSessionsDTO= new LinkedList(); + /** + * Generates JFreeChart data for all sessions in the Monitoring Summary. + * + * @param request + * @param voteService + * @param voteMonitoringForm + * @param toolContentID + * @return + */ + public static List prepareChartDTO(HttpServletRequest request, IVoteService voteService, + VoteMonitoringForm voteMonitoringForm, Long toolContentID, MessageService messageService) { + logger.debug("start preparing ChartDTO with voteMonitoringForm: " + voteMonitoringForm); + logger.debug("start preparing ChartDTO with toolContentID: " + toolContentID); - VoteContent voteContent=voteService.retrieveVote(toolContentID); - logger.debug("existing voteContent:" + voteContent); - logger.debug("will be building groups question data for content:..." + voteContent); - - Iterator itListSessions = voteContent.getVoteSessions().iterator(); - while (itListSessions.hasNext()) - { - VoteSession voteSession =(VoteSession)itListSessions.next(); - logger.debug("voteSession:..." + voteSession); - logger.debug("current voteSession id :..." + voteSession.getVoteSessionId()); - logger.debug("current toolSessionUid :..." + voteSession.getUid()); + List listVoteAllSessionsDTO = new LinkedList(); - Map mapOptionsContent= new TreeMap(new VoteComparator()); - logger.debug("mapOptionsContent: " + mapOptionsContent); + VoteContent voteContent = voteService.retrieveVote(toolContentID); + logger.debug("existing voteContent:" + voteContent); + logger.debug("will be building groups question data for content:..." + voteContent); - Map mapVoteRatesContent= new TreeMap(new VoteComparator()); - logger.debug("mapVoteRatesContent: " + mapVoteRatesContent); + Iterator itListSessions = voteContent.getVoteSessions().iterator(); + while (itListSessions.hasNext()) { + VoteSession voteSession = (VoteSession) itListSessions.next(); + logger.debug("voteSession:..." + voteSession); + logger.debug("current voteSession id :..." + voteSession.getVoteSessionId()); + logger.debug("current toolSessionUid :..." + voteSession.getUid()); - VoteAllSessionsDTO voteAllSessionsDTO= new VoteAllSessionsDTO(); - voteAllSessionsDTO.setSessionId(voteSession.getVoteSessionId().toString()); - voteAllSessionsDTO.setSessionName(voteSession.getSession_name()); - - int entriesCount=voteService.getSessionEntriesCount(voteSession.getUid()); - logger.debug("entriesCount: " + entriesCount); - Set userEntries=voteService.getSessionUserEntriesSet(voteSession.getUid()); - logger.debug("sessionUserCount: " + userEntries.size()); + Map mapOptionsContent = new TreeMap(new VoteComparator()); + logger.debug("mapOptionsContent: " + mapOptionsContent); - int potentialUserCount=voteService.getVoteSessionPotentialLearnersCount(voteSession.getUid()); - logger.debug("potentialUserCount: " + potentialUserCount); - voteAllSessionsDTO.setSessionUserCount(Integer.toString(potentialUserCount)); - - int completedSessionUserCount=voteService.getCompletedVoteUserBySessionUid(voteSession.getUid()); - logger.debug("completedSessionUserCount: " + completedSessionUserCount); - voteAllSessionsDTO.setCompletedSessionUserCount(new Integer(completedSessionUserCount).toString()); - - if (potentialUserCount != 0) - { - double completedPercent=(completedSessionUserCount*100) / potentialUserCount; - logger.debug("completed percent: " + completedPercent); - - if (completedPercent > 100) - completedPercent = 100; - - voteAllSessionsDTO.setCompletedSessionUserPercent(new Double(completedPercent).toString()); - } - else - { - voteAllSessionsDTO.setCompletedSessionUserPercent("Not Available"); - } - - - logger.debug("entriesCount: " + entriesCount); - logger.debug("userEntries: " + userEntries); - - Map mapStandardUserCount= new TreeMap(new VoteComparator()); + Map mapVoteRatesContent = new TreeMap(new VoteComparator()); + logger.debug("mapVoteRatesContent: " + mapVoteRatesContent); - logger.debug("setting existing content data from the db"); - mapOptionsContent.clear(); - Iterator queIterator=voteContent.getVoteQueContents().iterator(); - Long mapIndex=new Long(1); - logger.debug("mapOptionsContent: " + mapOptionsContent); - int totalStandardVotesCount=0; - - logger.debug("using entriesCount: " + entriesCount); - Map mapStandardNominationsHTMLedContent= new TreeMap(new VoteComparator()); - Map mapStandardQuestionUid= new TreeMap(new VoteComparator()); - Map mapStandardToolSessionUid= new TreeMap(new VoteComparator()); + VoteAllSessionsDTO voteAllSessionsDTO = new VoteAllSessionsDTO(); + voteAllSessionsDTO.setSessionId(voteSession.getVoteSessionId().toString()); + voteAllSessionsDTO.setSessionName(voteSession.getSession_name()); - while (queIterator.hasNext()) - { - VoteQueContent voteQueContent=(VoteQueContent) queIterator.next(); - if (voteQueContent != null) - { - logger.debug("question: " + voteQueContent.getQuestion()); - mapStandardNominationsHTMLedContent.put(mapIndex.toString(),voteQueContent.getQuestion()); - String noHTMLNomination = VoteUtils.stripHTML(voteQueContent.getQuestion()); - logger.debug("noHTMLNomination: " + noHTMLNomination); - mapOptionsContent.put(mapIndex.toString(),noHTMLNomination); - - int votesCount=0; - logger.debug("getting votesCount based on session: " + voteSession.getUid()); - votesCount=voteService.getStandardAttemptsForQuestionContentAndSessionUid(voteQueContent.getUid(), voteSession.getUid()); - - mapStandardQuestionUid.put(mapIndex.toString(),voteQueContent.getUid().toString()); - mapStandardToolSessionUid.put(mapIndex.toString(),voteSession.getUid()); - - logger.debug("votesCount for questionContent uid: " + votesCount + " for" + voteQueContent.getUid()); - mapStandardUserCount.put(mapIndex.toString(),new Integer(votesCount).toString()); - totalStandardVotesCount=totalStandardVotesCount + votesCount; + int entriesCount = voteService.getSessionEntriesCount(voteSession.getUid()); + logger.debug("entriesCount: " + entriesCount); + Set userEntries = voteService.getSessionUserEntriesSet(voteSession.getUid()); + logger.debug("sessionUserCount: " + userEntries.size()); - double voteRate=0d; - double doubleVotesCount=votesCount * 1d; - logger.debug("doubleVotesCount: " + doubleVotesCount); - double doubleEntriesCount=entriesCount * 1d; - logger.debug("doubleEntriesCount: " + doubleEntriesCount); + int potentialUserCount = voteService.getVoteSessionPotentialLearnersCount(voteSession.getUid()); + logger.debug("potentialUserCount: " + potentialUserCount); + voteAllSessionsDTO.setSessionUserCount(Integer.toString(potentialUserCount)); - if (entriesCount != 0) - { - voteRate=((doubleVotesCount * 100)/ doubleEntriesCount); - } + int completedSessionUserCount = voteService.getCompletedVoteUserBySessionUid(voteSession.getUid()); + logger.debug("completedSessionUserCount: " + completedSessionUserCount); + voteAllSessionsDTO.setCompletedSessionUserCount(new Integer(completedSessionUserCount).toString()); - logger.debug("voteRate" + voteRate); - - String stringVoteRate=new Double(voteRate).toString(); - int lengthVoteRate=stringVoteRate.length(); - logger.debug("lengthVoteRate" + lengthVoteRate); - if (lengthVoteRate > 5) - stringVoteRate=stringVoteRate.substring(0,6); - - - mapVoteRatesContent.put(mapIndex.toString(), stringVoteRate); - mapIndex=new Long(mapIndex.longValue()+1); - } - } - logger.debug("test1: Map initialized with existing contentid to: " + mapOptionsContent); - Map mapStandardNominationsContent= new TreeMap(new VoteComparator()); - mapStandardNominationsContent=mapOptionsContent; - logger.debug("mapStandardNominationsContent: " + mapStandardNominationsContent); - logger.debug("mapStandardNominationsHTMLedContent: " + mapStandardNominationsHTMLedContent); - - Map mapStandardRatesContent= new TreeMap(new VoteComparator()); - mapStandardRatesContent=mapVoteRatesContent; - logger.debug("test1: mapStandardRatesContent: " + mapStandardRatesContent); - logger.debug("test1: mapStandardUserCount: " + mapStandardUserCount); - - Iterator itListQuestions = userEntries.iterator(); - int mapVoteRatesSize=mapVoteRatesContent.size(); - logger.debug("mapVoteRatesSize: " + mapVoteRatesSize); - mapIndex=new Long(mapVoteRatesSize+1); - logger.debug("updated mapIndex: " + mapIndex); - - double total=MonitoringUtil.calculateTotal(mapVoteRatesContent); - logger.debug("updated mapIndex: " + mapIndex); - double share=100d-total ; - logger.debug("share: " + share); - - logger.debug("totalStandardVotesCount: " + totalStandardVotesCount); - int userEnteredVotesCount=entriesCount - totalStandardVotesCount; - logger.debug("userEnteredVotesCount for this session: " + userEnteredVotesCount); + if (potentialUserCount != 0) { + double completedPercent = (completedSessionUserCount * 100) / potentialUserCount; + logger.debug("completed percent: " + completedPercent); - if (userEnteredVotesCount != 0) - { - share=((userEnteredVotesCount * 100)/ entriesCount); - logger.debug("calculated share normally, userEnteredVotesCount: " + userEnteredVotesCount); - logger.debug("calculated share normally, entriesCount: " + entriesCount); - } - else - { - share=0; - logger.debug("reset share"); - } - logger.debug("final share: " + share); - - if (voteContent.isAllowText()) { - mapStandardNominationsContent.put(mapIndex.toString(), messageService.getMessage("label.open.vote")); - mapStandardNominationsHTMLedContent.put(mapIndex.toString(), messageService.getMessage("label.open.vote")); - } - mapStandardRatesContent.put(mapIndex.toString(), new Double(share).toString()); - mapStandardUserCount.put(mapIndex.toString(), new Integer(userEnteredVotesCount).toString()); - /**following are needed just for proper iteration in the summary jsp*/ - mapStandardQuestionUid.put(mapIndex.toString(),"1"); - mapStandardToolSessionUid.put(mapIndex.toString(),"1"); + if (completedPercent > 100) + completedPercent = 100; + voteAllSessionsDTO.setCompletedSessionUserPercent(new Double(completedPercent).toString()); + } else { + voteAllSessionsDTO.setCompletedSessionUserPercent("Not Available"); + } - logger.debug("processed for prepareChartDTO: mapStandardNominationsContent: " + mapStandardNominationsContent); - logger.debug("processed for prepareChartDTO: mapStandardNominationsHTMLedContent: " + mapStandardNominationsHTMLedContent); - logger.debug("processed for prepareChartDTO: mapStandardUserCount: " + mapStandardUserCount); - logger.debug("processed for prepareChartDTO: mapStandardRatesContent: " + mapStandardRatesContent); - - voteAllSessionsDTO.setMapStandardNominationsContent(mapStandardNominationsContent); - voteAllSessionsDTO.setMapStandardNominationsHTMLedContent(mapStandardNominationsHTMLedContent); - voteAllSessionsDTO.setMapStandardUserCount(mapStandardUserCount); - voteAllSessionsDTO.setMapStandardRatesContent(mapStandardRatesContent); - voteAllSessionsDTO.setMapStandardQuestionUid(mapStandardQuestionUid); - voteAllSessionsDTO.setMapStandardToolSessionUid(mapStandardToolSessionUid); - - VoteMonitoringAction voteMonitoringAction= new VoteMonitoringAction(); - List listUserEntries=voteMonitoringAction.processUserEnteredNominations(voteService, voteContent, voteSession.getVoteSessionId().toString(), true, null, false); - logger.debug("listUserEntries: " + listUserEntries); - voteAllSessionsDTO.setListUserEntries(listUserEntries); - - if (listUserEntries.size() > 0) - voteAllSessionsDTO.setExistsOpenVote (new Boolean(true).toString()); - else - voteAllSessionsDTO.setExistsOpenVote (new Boolean(false).toString()); - - listVoteAllSessionsDTO.add(voteAllSessionsDTO); - } - logger.debug("listVoteAllSessionsDTO: " + listVoteAllSessionsDTO); - - return listVoteAllSessionsDTO; - } - - /** - * Generates JFreeChart data for the learner module and - * monitoring module Summary tab (Individual Sessions mode) - * - * @param request - * @param voteService - * @param voteMonitoringForm - * @param toolContentID - * @param toolSessionUid - */ - public static void prepareChartData(HttpServletRequest request, IVoteService voteService, VoteMonitoringForm voteMonitoringForm, - String toolContentID, String toolSessionUid, VoteGeneralLearnerFlowDTO voteGeneralLearnerFlowDTO, - VoteGeneralMonitoringDTO voteGeneralMonitoringDTO, MessageService messageService) - { - logger.debug("starting prepareChartData, voteGeneralLearnerFlowDTO: " + voteGeneralLearnerFlowDTO); - logger.debug("starting prepareChartData, toolContentID: " + toolContentID); - logger.debug("starting prepareChartData, toolSessionUid: " + toolSessionUid); - VoteContent voteContent=voteService.retrieveVote(new Long(toolContentID)); - logger.debug("starting prepareChartData, voteContent uid: " + voteContent.getUid()); - - logger.debug("starting prepareChartData, voteMonitoringForm: " + voteMonitoringForm); - - logger.debug("existing voteContent:" + voteContent); - Map mapOptionsContent= new TreeMap(new VoteComparator()); - logger.debug("mapOptionsContent: " + mapOptionsContent); - - Map mapVoteRatesContent= new TreeMap(new VoteComparator()); - logger.debug("mapVoteRatesContent: " + mapVoteRatesContent); - - - List distinctSessionUsers=new ArrayList(); - boolean sessionLevelCharting=true; - int entriesCount=0; - Set userEntries=null; - if (toolSessionUid != null) - { - logger.debug("process for session: " + toolSessionUid); - entriesCount=voteService.getSessionEntriesCount(new Long(toolSessionUid)); - logger.debug("entriesCount: " + entriesCount); - userEntries=voteService.getSessionUserEntriesSet(new Long(toolSessionUid)); - logger.debug("sessionUserCount: " + userEntries.size()); - - int completedSessionUserCount=voteService.getCompletedVoteUserBySessionUid(new Long(toolSessionUid)); - logger.debug("completedSessionUserCount: " + completedSessionUserCount); - - - int completedEntriesCount=voteService.getCompletedSessionEntriesCount(new Long(toolSessionUid)); - logger.debug("completedEntriesCount: " + completedEntriesCount); + logger.debug("entriesCount: " + entriesCount); + logger.debug("userEntries: " + userEntries); - if (voteMonitoringForm != null) - { - int potentialUserCount=voteService.getVoteSessionPotentialLearnersCount(new Long(toolSessionUid)); - logger.debug("potentialUserCount: " + potentialUserCount); - voteMonitoringForm.setSessionUserCount(Integer.toString(potentialUserCount)); - voteMonitoringForm.setCompletedSessionUserCount(new Integer(completedSessionUserCount).toString()); + Map mapStandardUserCount = new TreeMap(new VoteComparator()); - if (voteGeneralMonitoringDTO != null) - { - voteGeneralMonitoringDTO.setSessionUserCount(Integer.toString(potentialUserCount)); - voteGeneralMonitoringDTO.setCompletedSessionUserCount(new Integer(completedSessionUserCount).toString()); - } + logger.debug("setting existing content data from the db"); + mapOptionsContent.clear(); + Iterator queIterator = voteContent.getVoteQueContents().iterator(); + Long mapIndex = new Long(1); + logger.debug("mapOptionsContent: " + mapOptionsContent); + int totalStandardVotesCount = 0; - if (potentialUserCount != 0) - { - double completedPercent=(completedSessionUserCount*100) / potentialUserCount; - logger.debug("completed percent: " + completedPercent); - - if (completedPercent > 100) - completedPercent = 100; - - voteMonitoringForm.setCompletedSessionUserPercent(new Double(completedPercent).toString()); - if (voteGeneralMonitoringDTO != null) - { - voteGeneralMonitoringDTO.setCompletedSessionUserPercent(new Double(completedPercent).toString()); - } - } - else - { - voteMonitoringForm.setCompletedSessionUserPercent("Not Available"); - if (voteGeneralMonitoringDTO != null) - { - voteGeneralMonitoringDTO.setCompletedSessionUserPercent("Not Available"); - } - } + logger.debug("using entriesCount: " + entriesCount); + Map mapStandardNominationsHTMLedContent = new TreeMap(new VoteComparator()); + Map mapStandardQuestionUid = new TreeMap(new VoteComparator()); + Map mapStandardToolSessionUid = new TreeMap(new VoteComparator()); + + while (queIterator.hasNext()) { + VoteQueContent voteQueContent = (VoteQueContent) queIterator.next(); + if (voteQueContent != null) { + logger.debug("question: " + voteQueContent.getQuestion()); + mapStandardNominationsHTMLedContent.put(mapIndex.toString(), voteQueContent.getQuestion()); + String noHTMLNomination = VoteUtils.stripHTML(voteQueContent.getQuestion()); + logger.debug("noHTMLNomination: " + noHTMLNomination); + mapOptionsContent.put(mapIndex.toString(), noHTMLNomination); + + int votesCount = 0; + logger.debug("getting votesCount based on session: " + voteSession.getUid()); + votesCount = voteService.getStandardAttemptsForQuestionContentAndSessionUid( + voteQueContent.getUid(), voteSession.getUid()); + + mapStandardQuestionUid.put(mapIndex.toString(), voteQueContent.getUid().toString()); + mapStandardToolSessionUid.put(mapIndex.toString(), voteSession.getUid()); + + logger + .debug("votesCount for questionContent uid: " + votesCount + " for" + + voteQueContent.getUid()); + mapStandardUserCount.put(mapIndex.toString(), new Integer(votesCount).toString()); + totalStandardVotesCount = totalStandardVotesCount + votesCount; + + double voteRate = 0d; + double doubleVotesCount = votesCount * 1d; + logger.debug("doubleVotesCount: " + doubleVotesCount); + double doubleEntriesCount = entriesCount * 1d; + logger.debug("doubleEntriesCount: " + doubleEntriesCount); + + if (entriesCount != 0) { + voteRate = ((doubleVotesCount * 100) / doubleEntriesCount); } - } - - logger.debug("entriesCount: " + entriesCount); - logger.debug("userEntries: " + userEntries); - logger.debug("sessionLevelCharting: " + sessionLevelCharting); - - - Map mapStandardUserCount= new TreeMap(new VoteComparator()); - logger.debug("setting existing content data from the db"); - mapOptionsContent.clear(); - Iterator queIterator=voteContent.getVoteQueContents().iterator(); - Long mapIndex=new Long(1); - logger.debug("mapOptionsContent: " + mapOptionsContent); - int totalStandardVotesCount=0; - - logger.debug("using entriesCount: " + entriesCount); - - Map mapStandardNominationsHTMLedContent= new TreeMap(new VoteComparator()); - Map mapStandardQuestionUid= new TreeMap(new VoteComparator()); - Map mapStandardToolSessionUid= new TreeMap(new VoteComparator()); - while (queIterator.hasNext()) - { - VoteQueContent voteQueContent=(VoteQueContent) queIterator.next(); - if (voteQueContent != null) - { - logger.debug("question: " + voteQueContent.getQuestion()); - mapStandardNominationsHTMLedContent.put(mapIndex.toString(), voteQueContent.getQuestion()); - String noHTMLNomination = VoteUtils.stripHTML(voteQueContent.getQuestion()); - logger.debug("noHTMLNomination: " + noHTMLNomination); - mapOptionsContent.put(mapIndex.toString(),noHTMLNomination); - - int votesCount=0; - if (sessionLevelCharting == true) - { - logger.debug("getting votesCount based on session: " + toolSessionUid); - votesCount=voteService.getStandardAttemptsForQuestionContentAndSessionUid(voteQueContent.getUid(), new Long(toolSessionUid)); - - mapStandardQuestionUid.put(mapIndex.toString(),voteQueContent.getUid().toString()); - mapStandardToolSessionUid.put(mapIndex.toString(),toolSessionUid.toString()); - - logger.debug("votesCount for questionContent uid: " + votesCount + " for" + voteQueContent.getUid()); - mapStandardUserCount.put(mapIndex.toString(),new Integer(votesCount).toString()); - totalStandardVotesCount=totalStandardVotesCount + votesCount; - } - else - { - logger.debug("getting votesCount based on content: " + voteQueContent.getUid()); - votesCount=voteService.getAttemptsForQuestionContent(voteQueContent.getUid()); - logger.debug("votesCount for questionContent uid: " + votesCount + " for" + voteQueContent.getUid()); - } - - double voteRate=0d; - double doubleVotesCount=votesCount * 1d; - logger.debug("doubleVotesCount: " + doubleVotesCount); - double doubleEntriesCount=entriesCount * 1d; - logger.debug("doubleEntriesCount: " + doubleEntriesCount); - if (entriesCount != 0) - { - voteRate=((doubleVotesCount * 100)/ doubleEntriesCount); - } + logger.debug("voteRate" + voteRate); - logger.debug("voteRate" + voteRate); - - String stringVoteRate=new Double(voteRate).toString(); - int lengthVoteRate=stringVoteRate.length(); - logger.debug("lengthVoteRate" + lengthVoteRate); - if (lengthVoteRate > 5) - stringVoteRate=stringVoteRate.substring(0,6); - - mapVoteRatesContent.put(mapIndex.toString(), stringVoteRate); - mapIndex=new Long(mapIndex.longValue()+1); - } + String stringVoteRate = new Double(voteRate).toString(); + int lengthVoteRate = stringVoteRate.length(); + logger.debug("lengthVoteRate" + lengthVoteRate); + if (lengthVoteRate > 5) + stringVoteRate = stringVoteRate.substring(0, 6); + + mapVoteRatesContent.put(mapIndex.toString(), stringVoteRate); + mapIndex = new Long(mapIndex.longValue() + 1); } - - logger.debug("test1: Map initialized with existing contentid to: " + mapOptionsContent); - Map mapStandardNominationsContent= new TreeMap(new VoteComparator()); - mapStandardNominationsContent=mapOptionsContent; - logger.debug("mapStandardNominationsContent: " + mapStandardNominationsContent); - logger.debug("mapStandardNominationsHTMLedContent: " + mapStandardNominationsHTMLedContent); - - Map mapStandardRatesContent= new TreeMap(new VoteComparator()); - mapStandardRatesContent=mapVoteRatesContent; - logger.debug("test1: mapStandardRatesContent: " + mapStandardRatesContent); - logger.debug("test1: mapStandardUserCount: " + mapStandardUserCount); - - int mapVoteRatesSize=mapVoteRatesContent.size(); + } + logger.debug("test1: Map initialized with existing contentid to: " + mapOptionsContent); + Map mapStandardNominationsContent = new TreeMap(new VoteComparator()); + mapStandardNominationsContent = mapOptionsContent; + logger.debug("mapStandardNominationsContent: " + mapStandardNominationsContent); + logger.debug("mapStandardNominationsHTMLedContent: " + mapStandardNominationsHTMLedContent); + + Map mapStandardRatesContent = new TreeMap(new VoteComparator()); + mapStandardRatesContent = mapVoteRatesContent; + logger.debug("test1: mapStandardRatesContent: " + mapStandardRatesContent); + logger.debug("test1: mapStandardUserCount: " + mapStandardUserCount); + + Iterator itListQuestions = userEntries.iterator(); + int mapVoteRatesSize = mapVoteRatesContent.size(); logger.debug("mapVoteRatesSize: " + mapVoteRatesSize); - mapIndex=new Long(mapVoteRatesSize+1); + mapIndex = new Long(mapVoteRatesSize + 1); logger.debug("updated mapIndex: " + mapIndex); - - double total=MonitoringUtil.calculateTotal(mapVoteRatesContent); + + double total = MonitoringUtil.calculateTotal(mapVoteRatesContent); logger.debug("updated mapIndex: " + mapIndex); - double share=100-total ; + double share = 100d - total; logger.debug("share: " + share); - + logger.debug("totalStandardVotesCount: " + totalStandardVotesCount); - int userEnteredVotesCount=entriesCount - totalStandardVotesCount; - logger.debug("userEnteredVotesCount for this session: " + userEnteredVotesCount); - - - if (userEnteredVotesCount != 0) - { - share=((userEnteredVotesCount * 100)/ entriesCount); - logger.debug("calculated share normally, userEnteredVotesCount: " + userEnteredVotesCount); - logger.debug("calculated share normally, entriesCount: " + entriesCount); + int userEnteredVotesCount = entriesCount - totalStandardVotesCount; + logger.debug("userEnteredVotesCount for this session: " + userEnteredVotesCount); + + if (userEnteredVotesCount != 0) { + share = ((userEnteredVotesCount * 100) / entriesCount); + logger.debug("calculated share normally, userEnteredVotesCount: " + userEnteredVotesCount); + logger.debug("calculated share normally, entriesCount: " + entriesCount); + } else { + share = 0; + logger.debug("reset share"); + } + logger.debug("final share: " + share); + + if (voteContent.isAllowText()) { + mapStandardNominationsContent.put(mapIndex.toString(), messageService.getMessage("label.open.vote")); + mapStandardNominationsHTMLedContent.put(mapIndex.toString(), messageService + .getMessage("label.open.vote")); + } + mapStandardRatesContent.put(mapIndex.toString(), new Double(share).toString()); + mapStandardUserCount.put(mapIndex.toString(), new Integer(userEnteredVotesCount).toString()); + /** following are needed just for proper iteration in the summary jsp */ + mapStandardQuestionUid.put(mapIndex.toString(), "1"); + mapStandardToolSessionUid.put(mapIndex.toString(), "1"); + + logger.debug("processed for prepareChartDTO: mapStandardNominationsContent: " + + mapStandardNominationsContent); + logger.debug("processed for prepareChartDTO: mapStandardNominationsHTMLedContent: " + + mapStandardNominationsHTMLedContent); + logger.debug("processed for prepareChartDTO: mapStandardUserCount: " + mapStandardUserCount); + logger.debug("processed for prepareChartDTO: mapStandardRatesContent: " + mapStandardRatesContent); + + voteAllSessionsDTO.setMapStandardNominationsContent(mapStandardNominationsContent); + voteAllSessionsDTO.setMapStandardNominationsHTMLedContent(mapStandardNominationsHTMLedContent); + voteAllSessionsDTO.setMapStandardUserCount(mapStandardUserCount); + voteAllSessionsDTO.setMapStandardRatesContent(mapStandardRatesContent); + voteAllSessionsDTO.setMapStandardQuestionUid(mapStandardQuestionUid); + voteAllSessionsDTO.setMapStandardToolSessionUid(mapStandardToolSessionUid); + + VoteMonitoringAction voteMonitoringAction = new VoteMonitoringAction(); + List listUserEntries = voteMonitoringAction.processUserEnteredNominations(voteService, voteContent, + voteSession.getVoteSessionId().toString(), true, null, false); + logger.debug("listUserEntries: " + listUserEntries); + voteAllSessionsDTO.setListUserEntries(listUserEntries); + + if (listUserEntries.size() > 0) + voteAllSessionsDTO.setExistsOpenVote(new Boolean(true).toString()); + else + voteAllSessionsDTO.setExistsOpenVote(new Boolean(false).toString()); + + listVoteAllSessionsDTO.add(voteAllSessionsDTO); + } + logger.debug("listVoteAllSessionsDTO: " + listVoteAllSessionsDTO); + + return listVoteAllSessionsDTO; + } + + /** + * Generates JFreeChart data for the learner module and monitoring module + * Summary tab (Individual Sessions mode) + * + * @param request + * @param voteService + * @param voteMonitoringForm + * @param toolContentID + * @param toolSessionUid + */ + public static void prepareChartData(HttpServletRequest request, IVoteService voteService, + VoteMonitoringForm voteMonitoringForm, String toolContentID, String toolSessionUid, + VoteGeneralLearnerFlowDTO voteGeneralLearnerFlowDTO, VoteGeneralMonitoringDTO voteGeneralMonitoringDTO, + MessageService messageService) { + logger.debug("starting prepareChartData, voteGeneralLearnerFlowDTO: " + voteGeneralLearnerFlowDTO); + logger.debug("starting prepareChartData, toolContentID: " + toolContentID); + logger.debug("starting prepareChartData, toolSessionUid: " + toolSessionUid); + VoteContent voteContent = voteService.retrieveVote(new Long(toolContentID)); + logger.debug("starting prepareChartData, voteContent uid: " + voteContent.getUid()); + + logger.debug("starting prepareChartData, voteMonitoringForm: " + voteMonitoringForm); + + logger.debug("existing voteContent:" + voteContent); + Map mapOptionsContent = new TreeMap(new VoteComparator()); + logger.debug("mapOptionsContent: " + mapOptionsContent); + + Map mapVoteRatesContent = new TreeMap(new VoteComparator()); + logger.debug("mapVoteRatesContent: " + mapVoteRatesContent); + + List distinctSessionUsers = new ArrayList(); + boolean sessionLevelCharting = true; + int entriesCount = 0; + Set userEntries = null; + if (toolSessionUid != null) { + logger.debug("process for session: " + toolSessionUid); + entriesCount = voteService.getSessionEntriesCount(new Long(toolSessionUid)); + logger.debug("entriesCount: " + entriesCount); + userEntries = voteService.getSessionUserEntriesSet(new Long(toolSessionUid)); + logger.debug("sessionUserCount: " + userEntries.size()); + + int completedSessionUserCount = voteService.getCompletedVoteUserBySessionUid(new Long(toolSessionUid)); + logger.debug("completedSessionUserCount: " + completedSessionUserCount); + + int completedEntriesCount = voteService.getCompletedSessionEntriesCount(new Long(toolSessionUid)); + logger.debug("completedEntriesCount: " + completedEntriesCount); + + if (voteMonitoringForm != null) { + int potentialUserCount = voteService.getVoteSessionPotentialLearnersCount(new Long(toolSessionUid)); + logger.debug("potentialUserCount: " + potentialUserCount); + voteMonitoringForm.setSessionUserCount(Integer.toString(potentialUserCount)); + voteMonitoringForm.setCompletedSessionUserCount(new Integer(completedSessionUserCount).toString()); + + if (voteGeneralMonitoringDTO != null) { + voteGeneralMonitoringDTO.setSessionUserCount(Integer.toString(potentialUserCount)); + voteGeneralMonitoringDTO.setCompletedSessionUserCount(new Integer(completedSessionUserCount) + .toString()); } - else - { - share=0; - logger.debug("reset share"); - } - logger.debug("final share: " + share); - if(voteContent.isAllowText()) { - mapStandardNominationsContent.put(mapIndex.toString(), messageService.getMessage("label.open.vote")); - mapStandardNominationsHTMLedContent.put(mapIndex.toString(), messageService.getMessage("label.open.vote")); + if (potentialUserCount != 0) { + double completedPercent = (completedSessionUserCount * 100) / potentialUserCount; + logger.debug("completed percent: " + completedPercent); + + if (completedPercent > 100) + completedPercent = 100; + + voteMonitoringForm.setCompletedSessionUserPercent(new Double(completedPercent).toString()); + if (voteGeneralMonitoringDTO != null) { + voteGeneralMonitoringDTO + .setCompletedSessionUserPercent(new Double(completedPercent).toString()); + } + } else { + voteMonitoringForm.setCompletedSessionUserPercent("Not Available"); + if (voteGeneralMonitoringDTO != null) { + voteGeneralMonitoringDTO.setCompletedSessionUserPercent("Not Available"); + } } - - mapStandardRatesContent.put(mapIndex.toString(), new Double(share).toString()); - mapStandardUserCount.put(mapIndex.toString(), new Integer(userEnteredVotesCount).toString()); - - /**following are needed just for proper iteration in the summary jsp*/ - mapStandardQuestionUid.put(mapIndex.toString(),"1"); - mapStandardToolSessionUid.put(mapIndex.toString(),"1"); + } + } - request.setAttribute(LIST_USER_ENTRIES_CONTENT, userEntries); - logger.debug("test2: mapUserEntriesContent: " + request.getSession().getAttribute(LIST_USER_ENTRIES_CONTENT)); + logger.debug("entriesCount: " + entriesCount); + logger.debug("userEntries: " + userEntries); + logger.debug("sessionLevelCharting: " + sessionLevelCharting); - request.getSession().setAttribute(MAP_STANDARD_NOMINATIONS_CONTENT, mapStandardNominationsContent); - logger.debug("test2: MAP_STANDARD_NOMINATIONS_CONTENT: " + request.getSession().getAttribute(MAP_STANDARD_NOMINATIONS_CONTENT)); + Map mapStandardUserCount = new TreeMap(new VoteComparator()); - request.getSession().setAttribute(MAP_STANDARD_RATES_CONTENT, mapStandardRatesContent); - logger.debug("test2: MAP_STANDARD_RATES_CONTENT: " + request.getSession().getAttribute(MAP_STANDARD_RATES_CONTENT)); + logger.debug("setting existing content data from the db"); + mapOptionsContent.clear(); + Iterator queIterator = voteContent.getVoteQueContents().iterator(); + Long mapIndex = new Long(1); + logger.debug("mapOptionsContent: " + mapOptionsContent); + int totalStandardVotesCount = 0; - if (voteGeneralLearnerFlowDTO !=null) - { - logger.debug("placing maps within voteGeneralLearnerFlowDTO"); - voteGeneralLearnerFlowDTO.setMapStandardNominationsContent(mapStandardNominationsContent); - voteGeneralLearnerFlowDTO.setMapStandardNominationsHTMLedContent(mapStandardNominationsHTMLedContent); - voteGeneralLearnerFlowDTO.setMapStandardRatesContent(mapStandardRatesContent); - voteGeneralLearnerFlowDTO.setMapStandardUserCount(mapStandardUserCount); - voteGeneralLearnerFlowDTO.setMapStandardToolSessionUid(mapStandardToolSessionUid); - voteGeneralLearnerFlowDTO.setMapStandardQuestionUid(mapStandardQuestionUid); + logger.debug("using entriesCount: " + entriesCount); + + Map mapStandardNominationsHTMLedContent = new TreeMap(new VoteComparator()); + Map mapStandardQuestionUid = new TreeMap(new VoteComparator()); + Map mapStandardToolSessionUid = new TreeMap(new VoteComparator()); + while (queIterator.hasNext()) { + VoteQueContent voteQueContent = (VoteQueContent) queIterator.next(); + if (voteQueContent != null) { + logger.debug("question: " + voteQueContent.getQuestion()); + mapStandardNominationsHTMLedContent.put(mapIndex.toString(), voteQueContent.getQuestion()); + String noHTMLNomination = VoteUtils.stripHTML(voteQueContent.getQuestion()); + logger.debug("noHTMLNomination: " + noHTMLNomination); + mapOptionsContent.put(mapIndex.toString(), noHTMLNomination); + + int votesCount = 0; + if (sessionLevelCharting == true) { + logger.debug("getting votesCount based on session: " + toolSessionUid); + votesCount = voteService.getStandardAttemptsForQuestionContentAndSessionUid( + voteQueContent.getUid(), new Long(toolSessionUid)); + + mapStandardQuestionUid.put(mapIndex.toString(), voteQueContent.getUid().toString()); + mapStandardToolSessionUid.put(mapIndex.toString(), toolSessionUid.toString()); + + logger + .debug("votesCount for questionContent uid: " + votesCount + " for" + + voteQueContent.getUid()); + mapStandardUserCount.put(mapIndex.toString(), new Integer(votesCount).toString()); + totalStandardVotesCount = totalStandardVotesCount + votesCount; + } else { + logger.debug("getting votesCount based on content: " + voteQueContent.getUid()); + votesCount = voteService.getAttemptsForQuestionContent(voteQueContent.getUid()); + logger + .debug("votesCount for questionContent uid: " + votesCount + " for" + + voteQueContent.getUid()); } - - if (voteGeneralMonitoringDTO !=null) - { - voteGeneralMonitoringDTO.setMapStandardNominationsContent(mapStandardNominationsContent); - voteGeneralMonitoringDTO.setMapStandardNominationsHTMLedContent(mapStandardNominationsHTMLedContent); - voteGeneralMonitoringDTO.setMapStandardRatesContent(mapStandardRatesContent); - voteGeneralMonitoringDTO.setMapStandardUserCount(mapStandardUserCount); - voteGeneralMonitoringDTO.setMapStandardToolSessionUid(mapStandardToolSessionUid); - voteGeneralMonitoringDTO.setMapStandardQuestionUid(mapStandardQuestionUid); + + double voteRate = 0d; + double doubleVotesCount = votesCount * 1d; + logger.debug("doubleVotesCount: " + doubleVotesCount); + double doubleEntriesCount = entriesCount * 1d; + logger.debug("doubleEntriesCount: " + doubleEntriesCount); + if (entriesCount != 0) { + voteRate = ((doubleVotesCount * 100) / doubleEntriesCount); } - logger.debug("end of prepareChartData, voteGeneralLearnerFlowDTO: " + voteGeneralLearnerFlowDTO); - request.setAttribute(VOTE_GENERAL_LEARNER_FLOW_DTO,voteGeneralLearnerFlowDTO); - - logger.debug("end of prepareChartData, voteGeneralMonitoringDTO: " + voteGeneralMonitoringDTO); - request.setAttribute(VOTE_GENERAL_MONITORING_DTO, voteGeneralMonitoringDTO); + logger.debug("voteRate" + voteRate); + + String stringVoteRate = new Double(voteRate).toString(); + int lengthVoteRate = stringVoteRate.length(); + logger.debug("lengthVoteRate" + lengthVoteRate); + if (lengthVoteRate > 5) + stringVoteRate = stringVoteRate.substring(0, 6); + + mapVoteRatesContent.put(mapIndex.toString(), stringVoteRate); + mapIndex = new Long(mapIndex.longValue() + 1); + } } - - /** - * generates JFreeChart for the teacher export portfolio - * - * @param request - * @param voteService - * @param voteMonitoringForm - * @param toolContentID - * @param toolSessionUid - */ - public static void prepareChartDataForExportTeacher(HttpServletRequest request, IVoteService voteService, - VoteMonitoringForm voteMonitoringForm, Long toolContentID, Long toolSessionUid, ExportPortfolioDTO exportPortfolioDTO, MessageService messageService) - { - logger.debug("starting prepareChartDataForExportTeacher, toolContentID: " + toolContentID); - logger.debug("starting prepareChartDataForExportTeacher, toolSessionUid: " + toolSessionUid); - logger.debug("pased exportPortfolioDTO: " + exportPortfolioDTO); - - VoteContent voteContent=voteService.retrieveVote(toolContentID); - logger.debug("starting prepareChartData, voteContent uid: " + voteContent.getUid()); - logger.debug("starting prepareChartDataForExport, voteMonitoringForm: " + voteMonitoringForm); - logger.debug("existing voteContent:" + voteContent); - - Map mapOptionsContent= new TreeMap(new VoteComparator()); - Map mapVoteRatesContent= new TreeMap(new VoteComparator()); - Map mapStandardUserCount= new TreeMap(new VoteComparator()); - - Iterator queIterator=voteContent.getVoteQueContents().iterator(); - Long mapIndex=new Long(1); - int totalStandardVotesCount=0; - int totalStandardContentVotesCount=0; - int entriesCount=0; - - logger.debug("get all entries for content: " + voteContent); - List setEntriesCount=voteService.getContentEntries(voteContent.getUid()); - logger.debug("setEntriesCount: " +setEntriesCount); - entriesCount=setEntriesCount.size(); - logger.debug("entriesCount: " + entriesCount); - - Map mapStandardNominationsHTMLedContent= new TreeMap(new VoteComparator()); + logger.debug("test1: Map initialized with existing contentid to: " + mapOptionsContent); + Map mapStandardNominationsContent = new TreeMap(new VoteComparator()); + mapStandardNominationsContent = mapOptionsContent; + logger.debug("mapStandardNominationsContent: " + mapStandardNominationsContent); + logger.debug("mapStandardNominationsHTMLedContent: " + mapStandardNominationsHTMLedContent); - while (queIterator.hasNext()) - { - VoteQueContent voteQueContent=(VoteQueContent) queIterator.next(); - if (voteQueContent != null) - { - logger.debug("question: " + voteQueContent.getQuestion()); - mapStandardNominationsHTMLedContent.put(mapIndex.toString(),voteQueContent.getQuestion()); - String noHTMLNomination = VoteUtils.stripHTML(voteQueContent.getQuestion()); - logger.debug("noHTMLNomination: " + noHTMLNomination); - mapOptionsContent.put(mapIndex.toString(),noHTMLNomination); + Map mapStandardRatesContent = new TreeMap(new VoteComparator()); + mapStandardRatesContent = mapVoteRatesContent; + logger.debug("test1: mapStandardRatesContent: " + mapStandardRatesContent); + logger.debug("test1: mapStandardUserCount: " + mapStandardUserCount); - int votesCount=voteService.getStandardAttemptsForQuestionContentAndContentUid(voteQueContent.getUid(), voteContent.getUid()); - logger.debug("standardContentAttemptCount: " + votesCount); - - mapStandardUserCount.put(mapIndex.toString(),new Integer(votesCount).toString()); - totalStandardVotesCount=totalStandardVotesCount + votesCount; + int mapVoteRatesSize = mapVoteRatesContent.size(); + logger.debug("mapVoteRatesSize: " + mapVoteRatesSize); + mapIndex = new Long(mapVoteRatesSize + 1); + logger.debug("updated mapIndex: " + mapIndex); - - double voteRate=0d; - double doubleVotesCount=votesCount * 1d; - logger.debug("doubleVotesCount: " + doubleVotesCount); - double doubleEntriesCount=entriesCount * 1d; - logger.debug("doubleEntriesCount: " + doubleEntriesCount); - if (entriesCount != 0) - { - voteRate=((doubleVotesCount * 100)/ doubleEntriesCount); - } + double total = MonitoringUtil.calculateTotal(mapVoteRatesContent); + logger.debug("updated mapIndex: " + mapIndex); + double share = 100 - total; + logger.debug("share: " + share); - logger.debug("voteRate" + voteRate); - String stringVoteRate=new Double(voteRate).toString(); - int lengthVoteRate=stringVoteRate.length(); - logger.debug("lengthVoteRate" + lengthVoteRate); - if (lengthVoteRate > 5) - stringVoteRate=stringVoteRate.substring(0,6); - - mapVoteRatesContent.put(mapIndex.toString(), stringVoteRate); - mapIndex=new Long(mapIndex.longValue()+1); + logger.debug("totalStandardVotesCount: " + totalStandardVotesCount); + int userEnteredVotesCount = entriesCount - totalStandardVotesCount; + logger.debug("userEnteredVotesCount for this session: " + userEnteredVotesCount); + + if (userEnteredVotesCount != 0) { + share = ((userEnteredVotesCount * 100) / entriesCount); + logger.debug("calculated share normally, userEnteredVotesCount: " + userEnteredVotesCount); + logger.debug("calculated share normally, entriesCount: " + entriesCount); + } else { + share = 0; + logger.debug("reset share"); + } + logger.debug("final share: " + share); + + if (voteContent.isAllowText()) { + mapStandardNominationsContent.put(mapIndex.toString(), messageService.getMessage("label.open.vote")); + mapStandardNominationsHTMLedContent.put(mapIndex.toString(), messageService.getMessage("label.open.vote")); + } + + mapStandardRatesContent.put(mapIndex.toString(), new Double(share).toString()); + mapStandardUserCount.put(mapIndex.toString(), new Integer(userEnteredVotesCount).toString()); + + /** following are needed just for proper iteration in the summary jsp */ + mapStandardQuestionUid.put(mapIndex.toString(), "1"); + mapStandardToolSessionUid.put(mapIndex.toString(), "1"); + + request.setAttribute(LIST_USER_ENTRIES_CONTENT, userEntries); + logger.debug("test2: mapUserEntriesContent: " + request.getSession().getAttribute(LIST_USER_ENTRIES_CONTENT)); + + request.getSession().setAttribute(MAP_STANDARD_NOMINATIONS_CONTENT, mapStandardNominationsContent); + logger.debug("test2: MAP_STANDARD_NOMINATIONS_CONTENT: " + + request.getSession().getAttribute(MAP_STANDARD_NOMINATIONS_CONTENT)); + + request.getSession().setAttribute(MAP_STANDARD_RATES_CONTENT, mapStandardRatesContent); + logger.debug("test2: MAP_STANDARD_RATES_CONTENT: " + + request.getSession().getAttribute(MAP_STANDARD_RATES_CONTENT)); + + if (voteGeneralLearnerFlowDTO != null) { + logger.debug("placing maps within voteGeneralLearnerFlowDTO"); + voteGeneralLearnerFlowDTO.setMapStandardNominationsContent(mapStandardNominationsContent); + voteGeneralLearnerFlowDTO.setMapStandardNominationsHTMLedContent(mapStandardNominationsHTMLedContent); + voteGeneralLearnerFlowDTO.setMapStandardRatesContent(mapStandardRatesContent); + voteGeneralLearnerFlowDTO.setMapStandardUserCount(mapStandardUserCount); + voteGeneralLearnerFlowDTO.setMapStandardToolSessionUid(mapStandardToolSessionUid); + voteGeneralLearnerFlowDTO.setMapStandardQuestionUid(mapStandardQuestionUid); + } + + if (voteGeneralMonitoringDTO != null) { + voteGeneralMonitoringDTO.setMapStandardNominationsContent(mapStandardNominationsContent); + voteGeneralMonitoringDTO.setMapStandardNominationsHTMLedContent(mapStandardNominationsHTMLedContent); + voteGeneralMonitoringDTO.setMapStandardRatesContent(mapStandardRatesContent); + voteGeneralMonitoringDTO.setMapStandardUserCount(mapStandardUserCount); + voteGeneralMonitoringDTO.setMapStandardToolSessionUid(mapStandardToolSessionUid); + voteGeneralMonitoringDTO.setMapStandardQuestionUid(mapStandardQuestionUid); + } + + logger.debug("end of prepareChartData, voteGeneralLearnerFlowDTO: " + voteGeneralLearnerFlowDTO); + request.setAttribute(VOTE_GENERAL_LEARNER_FLOW_DTO, voteGeneralLearnerFlowDTO); + + logger.debug("end of prepareChartData, voteGeneralMonitoringDTO: " + voteGeneralMonitoringDTO); + request.setAttribute(VOTE_GENERAL_MONITORING_DTO, voteGeneralMonitoringDTO); + } + + /** + * generates JFreeChart for the teacher export portfolio + * + * @param request + * @param voteService + * @param voteMonitoringForm + * @param toolContentID + * @param toolSessionUid + */ + public static void prepareChartDataForExportTeacher(HttpServletRequest request, IVoteService voteService, + VoteMonitoringForm voteMonitoringForm, Long toolContentID, Long toolSessionUid, + ExportPortfolioDTO exportPortfolioDTO, MessageService messageService) { + logger.debug("starting prepareChartDataForExportTeacher, toolContentID: " + toolContentID); + logger.debug("starting prepareChartDataForExportTeacher, toolSessionUid: " + toolSessionUid); + logger.debug("pased exportPortfolioDTO: " + exportPortfolioDTO); + + VoteContent voteContent = voteService.retrieveVote(toolContentID); + logger.debug("starting prepareChartData, voteContent uid: " + voteContent.getUid()); + logger.debug("starting prepareChartDataForExport, voteMonitoringForm: " + voteMonitoringForm); + logger.debug("existing voteContent:" + voteContent); + + Map mapOptionsContent = new TreeMap(new VoteComparator()); + Map mapVoteRatesContent = new TreeMap(new VoteComparator()); + Map mapStandardUserCount = new TreeMap(new VoteComparator()); + + Iterator queIterator = voteContent.getVoteQueContents().iterator(); + Long mapIndex = new Long(1); + int totalStandardVotesCount = 0; + int totalStandardContentVotesCount = 0; + int entriesCount = 0; + + logger.debug("get all entries for content: " + voteContent); + entriesCount = voteService.getUserEnteredVotesCountForContent(voteContent.getUid()); + logger.debug("entriesCount: " + entriesCount); + + Map mapStandardNominationsHTMLedContent = new TreeMap(new VoteComparator()); + + while (queIterator.hasNext()) { + VoteQueContent voteQueContent = (VoteQueContent) queIterator.next(); + if (voteQueContent != null) { + logger.debug("question: " + voteQueContent.getQuestion()); + mapStandardNominationsHTMLedContent.put(mapIndex.toString(), voteQueContent.getQuestion()); + String noHTMLNomination = VoteUtils.stripHTML(voteQueContent.getQuestion()); + logger.debug("noHTMLNomination: " + noHTMLNomination); + mapOptionsContent.put(mapIndex.toString(), noHTMLNomination); + + int votesCount = voteService.getStandardAttemptsForQuestionContentAndContentUid( + voteQueContent.getUid(), voteContent.getUid()); + logger.debug("standardContentAttemptCount: " + votesCount); + + mapStandardUserCount.put(mapIndex.toString(), new Integer(votesCount).toString()); + totalStandardVotesCount = totalStandardVotesCount + votesCount; + + double voteRate = 0d; + double doubleVotesCount = votesCount * 1d; + logger.debug("doubleVotesCount: " + doubleVotesCount); + double doubleEntriesCount = entriesCount * 1d; + logger.debug("doubleEntriesCount: " + doubleEntriesCount); + if (entriesCount != 0) { + voteRate = ((doubleVotesCount * 100) / doubleEntriesCount); + } + + logger.debug("voteRate" + voteRate); + String stringVoteRate = new Double(voteRate).toString(); + int lengthVoteRate = stringVoteRate.length(); + logger.debug("lengthVoteRate" + lengthVoteRate); + if (lengthVoteRate > 5) + stringVoteRate = stringVoteRate.substring(0, 6); + + mapVoteRatesContent.put(mapIndex.toString(), stringVoteRate); + mapIndex = new Long(mapIndex.longValue() + 1); + } + } + logger.debug("test1: Map initialized with existing contentid to: " + mapOptionsContent); + Map mapStandardNominationsContent = new TreeMap(new VoteComparator()); + mapStandardNominationsContent = mapOptionsContent; + logger.debug("mapStandardNominationsContent: " + mapStandardNominationsContent); + logger.debug("mapStandardNominationsHTMLedContent: " + mapStandardNominationsHTMLedContent); + + Map mapStandardRatesContent = new TreeMap(new VoteComparator()); + mapStandardRatesContent = mapVoteRatesContent; + logger.debug("test1: mapStandardRatesContent: " + mapStandardRatesContent); + logger.debug("test1: mapStandardUserCount: " + mapStandardUserCount); + + int mapVoteRatesSize = mapVoteRatesContent.size(); + logger.debug("mapVoteRatesSize: " + mapVoteRatesSize); + mapIndex = new Long(mapVoteRatesSize + 1); + logger.debug("updated mapIndex: " + mapIndex); + + double total = MonitoringUtil.calculateTotal(mapVoteRatesContent); + logger.debug("updated mapIndex: " + mapIndex); + double share = 100d - total; + logger.debug("share: " + share); + + logger.debug("totalStandardVotesCount: " + totalStandardVotesCount); + int userEnteredVotesCount = entriesCount - totalStandardVotesCount; + logger.debug("userEnteredVotesCount for this session: " + userEnteredVotesCount); + + if (userEnteredVotesCount != 0) { + share = ((userEnteredVotesCount * 100) / entriesCount); + logger.debug("calculated share normally, userEnteredVotesCount: " + userEnteredVotesCount); + logger.debug("calculated share normally, entriesCount: " + entriesCount); + } else { + share = 0; + logger.debug("reset share"); + } + logger.debug("final share: " + share); + + if (voteContent.isAllowText()) { + mapStandardNominationsContent.put(mapIndex.toString(), messageService.getMessage("label.open.vote")); + mapStandardNominationsHTMLedContent.put(mapIndex.toString(), messageService.getMessage("label.open.vote")); + } + mapStandardRatesContent.put(mapIndex.toString(), new Double(share).toString()); + mapStandardUserCount.put(mapIndex.toString(), new Integer(userEnteredVotesCount).toString()); + + if (exportPortfolioDTO != null) { + exportPortfolioDTO.setMapStandardNominationsHTMLedContent(mapStandardNominationsHTMLedContent); + exportPortfolioDTO.setMapStandardRatesContent(mapStandardRatesContent); + exportPortfolioDTO.setMapStandardUserCount(mapStandardUserCount); + exportPortfolioDTO.setMapStandardNominationsContent(mapStandardNominationsContent); + } + logger.debug("ending prepareChartDataForExportTeacher, exportPortfolioDTO: " + exportPortfolioDTO); + } + + public static boolean notebookEntriesExist(IVoteService voteService, VoteContent voteContent) { + logger.debug("finding out about content level notebook entries: " + voteContent); + Iterator iteratorSession = voteContent.getVoteSessions().iterator(); + while (iteratorSession.hasNext()) { + VoteSession voteSession = (VoteSession) iteratorSession.next(); + logger.debug("voteSession: " + voteSession); + + if (voteSession != null) { + logger.debug("voteSession id: " + voteSession.getVoteSessionId()); + + Iterator iteratorUser = voteSession.getVoteQueUsers().iterator(); + while (iteratorUser.hasNext()) { + VoteQueUsr voteQueUsr = (VoteQueUsr) iteratorUser.next(); + logger.debug("voteQueUsr: " + voteQueUsr); + + if (voteQueUsr != null) { + logger.debug("voteQueUsr id: " + voteQueUsr.getQueUsrId()); + + logger.debug("attempt getting notebookEntry: "); + NotebookEntry notebookEntry = voteService.getEntry(voteSession.getVoteSessionId(), + CoreNotebookConstants.NOTEBOOK_TOOL, MY_SIGNATURE, new Integer(voteQueUsr.getQueUsrId() + .intValue())); + + logger.debug("notebookEntry: " + notebookEntry); + if (notebookEntry != null) { + logger.debug("found at least one notebookEntry: " + notebookEntry.getEntry()); + return true; } + + } } - logger.debug("test1: Map initialized with existing contentid to: " + mapOptionsContent); - Map mapStandardNominationsContent= new TreeMap(new VoteComparator()); - mapStandardNominationsContent=mapOptionsContent; - logger.debug("mapStandardNominationsContent: " + mapStandardNominationsContent); - logger.debug("mapStandardNominationsHTMLedContent: " + mapStandardNominationsHTMLedContent); - - Map mapStandardRatesContent= new TreeMap(new VoteComparator()); - mapStandardRatesContent=mapVoteRatesContent; - logger.debug("test1: mapStandardRatesContent: " + mapStandardRatesContent); - logger.debug("test1: mapStandardUserCount: " + mapStandardUserCount); - - int mapVoteRatesSize=mapVoteRatesContent.size(); - logger.debug("mapVoteRatesSize: " + mapVoteRatesSize); - mapIndex=new Long(mapVoteRatesSize+1); - logger.debug("updated mapIndex: " + mapIndex); - - double total=MonitoringUtil.calculateTotal(mapVoteRatesContent); - logger.debug("updated mapIndex: " + mapIndex); - double share=100d-total ; - logger.debug("share: " + share); - - logger.debug("totalStandardVotesCount: " + totalStandardVotesCount); - int userEnteredVotesCount=entriesCount - totalStandardVotesCount; - logger.debug("userEnteredVotesCount for this session: " + userEnteredVotesCount); - - if (userEnteredVotesCount != 0) - { - share=((userEnteredVotesCount * 100)/ entriesCount); - logger.debug("calculated share normally, userEnteredVotesCount: " + userEnteredVotesCount); - logger.debug("calculated share normally, entriesCount: " + entriesCount); + } + } + return false; + } + + public static void buildVoteStatsDTO(HttpServletRequest request, IVoteService voteService, VoteContent voteContent) { + logger.debug("building voteStatsDTO: " + voteContent); + VoteStatsDTO voteStatsDTO = new VoteStatsDTO(); + + int countSessionComplete = 0; + int countAllUsers = 0; + logger.debug("finding out about content level notebook entries: " + voteContent); + Iterator iteratorSession = voteContent.getVoteSessions().iterator(); + while (iteratorSession.hasNext()) { + VoteSession voteSession = (VoteSession) iteratorSession.next(); + logger.debug("voteSession: " + voteSession); + + if (voteSession != null) { + logger.debug("voteSession id: " + voteSession.getVoteSessionId()); + + if (voteSession.getSessionStatus().equals(COMPLETED)) { + ++countSessionComplete; } - else - { - share=0; - logger.debug("reset share"); - } - logger.debug("final share: " + share); + Iterator iteratorUser = voteSession.getVoteQueUsers().iterator(); + while (iteratorUser.hasNext()) { + VoteQueUsr voteQueUsr = (VoteQueUsr) iteratorUser.next(); + logger.debug("voteQueUsr: " + voteQueUsr); - if(voteContent.isAllowText()) { - mapStandardNominationsContent.put(mapIndex.toString(), messageService.getMessage("label.open.vote")); - mapStandardNominationsHTMLedContent.put(mapIndex.toString(), messageService.getMessage("label.open.vote")); + if (voteQueUsr != null) { + logger.debug("voteQueUsr foundid"); + ++countAllUsers; + } } - mapStandardRatesContent.put(mapIndex.toString(), new Double(share).toString()); - mapStandardUserCount.put(mapIndex.toString(), new Integer(userEnteredVotesCount).toString()); - - if (exportPortfolioDTO != null) - { - exportPortfolioDTO.setMapStandardNominationsHTMLedContent(mapStandardNominationsHTMLedContent); - exportPortfolioDTO.setMapStandardRatesContent(mapStandardRatesContent); - exportPortfolioDTO.setMapStandardUserCount(mapStandardUserCount); - exportPortfolioDTO.setMapStandardNominationsContent(mapStandardNominationsContent); - } - logger.debug("ending prepareChartDataForExportTeacher, exportPortfolioDTO: " + exportPortfolioDTO); - } + } + } + logger.debug("countAllUsers: " + countAllUsers); + logger.debug("countSessionComplete: " + countSessionComplete); - public static boolean notebookEntriesExist(IVoteService voteService, VoteContent voteContent) - { - logger.debug("finding out about content level notebook entries: " + voteContent); - Iterator iteratorSession= voteContent.getVoteSessions().iterator(); - while (iteratorSession.hasNext()) - { - VoteSession voteSession=(VoteSession) iteratorSession.next(); - logger.debug("voteSession: " + voteSession); - - if (voteSession != null) - { - logger.debug("voteSession id: " + voteSession.getVoteSessionId()); - - Iterator iteratorUser=voteSession.getVoteQueUsers().iterator(); - while (iteratorUser.hasNext()) - { - VoteQueUsr voteQueUsr=(VoteQueUsr) iteratorUser.next(); - logger.debug("voteQueUsr: " + voteQueUsr); - - if (voteQueUsr != null) - { - logger.debug("voteQueUsr id: " + voteQueUsr.getQueUsrId()); - - logger.debug("attempt getting notebookEntry: "); - NotebookEntry notebookEntry = voteService.getEntry(voteSession.getVoteSessionId(), - CoreNotebookConstants.NOTEBOOK_TOOL, - MY_SIGNATURE, new Integer(voteQueUsr.getQueUsrId().intValue())); - - logger.debug("notebookEntry: " + notebookEntry); - if (notebookEntry != null) - { - logger.debug("found at least one notebookEntry: " + notebookEntry.getEntry()); - return true; - } - - } - } + voteStatsDTO.setCountAllUsers(new Integer(countAllUsers).toString()); + voteStatsDTO.setCountSessionComplete(new Integer(countSessionComplete).toString()); + + logger.debug("voteStatsDTO: " + voteStatsDTO); + + request.setAttribute(VOTE_STATS_DTO, voteStatsDTO); + } + + public static void generateGroupsSessionData(HttpServletRequest request, IVoteService voteService, + VoteContent voteContent) { + logger.debug("generateGroupsSessionData: " + voteContent); + + List listAllGroupsDTO = buildGroupBasedSessionData(request, voteContent, voteService); + logger.debug("listAllGroupsDTO: " + listAllGroupsDTO); + + request.setAttribute(LIST_ALL_GROUPS_DTO, listAllGroupsDTO); + } + + public static List buildGroupBasedSessionData(HttpServletRequest request, VoteContent voteContent, + IVoteService voteService) { + logger.debug("buildGroupBasedSessionData" + voteContent); + logger.debug("will be building groups question data for content:..." + voteContent); + List listQuestions = voteService.getAllQuestionEntries(voteContent.getUid()); + logger.debug("listQuestions:..." + listQuestions); + + List listAllGroupsContainerDTO = new LinkedList(); + + Iterator iteratorSession = voteContent.getVoteSessions().iterator(); + while (iteratorSession.hasNext()) { + VoteSession voteSession = (VoteSession) iteratorSession.next(); + logger.debug("iteration for group based session data: " + voteSession); + String currentSessionId = voteSession.getVoteSessionId().toString(); + logger.debug("currentSessionId: " + currentSessionId); + + String currentSessionName = voteSession.getSession_name(); + logger.debug("currentSessionName: " + currentSessionName); + + VoteAllGroupsDTO voteAllGroupsDTO = new VoteAllGroupsDTO(); + List listMonitoredAnswersContainerDTO = new LinkedList(); + + if (voteSession != null) { + Iterator itListQuestions = listQuestions.iterator(); + while (itListQuestions.hasNext()) { + VoteQueContent voteQueContent = (VoteQueContent) itListQuestions.next(); + logger.debug("voteQueContent:..." + voteQueContent); + + if (voteQueContent != null) { + logger.debug("populating VoteMonitoredAnswersDTO for : " + voteQueContent); + VoteMonitoredAnswersDTO voteMonitoredAnswersDTO = new VoteMonitoredAnswersDTO(); + voteMonitoredAnswersDTO.setQuestionUid(voteQueContent.getUid().toString()); + voteMonitoredAnswersDTO.setQuestion(voteQueContent.getQuestion()); + voteMonitoredAnswersDTO.setSessionId(currentSessionId); + voteMonitoredAnswersDTO.setSessionName(currentSessionName); + + Map questionAttemptData = buildGroupsAttemptData(request, voteContent, voteService, + voteQueContent, voteQueContent.getUid().toString(), true, false, currentSessionId, null); + logger.debug("generated questionAttemptData: " + questionAttemptData); + voteMonitoredAnswersDTO.setQuestionAttempts(questionAttemptData); + + logger.debug("adding voteMonitoredAnswersDTO to the listMonitoredAnswersContainerDTO: " + + voteMonitoredAnswersDTO); + listMonitoredAnswersContainerDTO.add(voteMonitoredAnswersDTO); } } - return false; + } + logger.debug("listMonitoredAnswersContainerDTO:" + listMonitoredAnswersContainerDTO); + + logger.debug("adding listMonitoredAnswersContainerDTO to the voteAllGroupsDTO:" + + listMonitoredAnswersContainerDTO); + voteAllGroupsDTO.setGroupData(listMonitoredAnswersContainerDTO); + voteAllGroupsDTO.setSessionName(currentSessionName); + voteAllGroupsDTO.setSessionId(currentSessionId); + + logger.debug("built voteAllGroupsDTO:" + voteAllGroupsDTO); + listAllGroupsContainerDTO.add(voteAllGroupsDTO); + } - - - public static void buildVoteStatsDTO(HttpServletRequest request, IVoteService voteService, VoteContent voteContent) - { - logger.debug("building voteStatsDTO: " + voteContent); - VoteStatsDTO voteStatsDTO= new VoteStatsDTO(); - - int countSessionComplete=0; - int countAllUsers=0; - logger.debug("finding out about content level notebook entries: " + voteContent); - Iterator iteratorSession= voteContent.getVoteSessions().iterator(); - while (iteratorSession.hasNext()) - { - VoteSession voteSession=(VoteSession) iteratorSession.next(); - logger.debug("voteSession: " + voteSession); - - if (voteSession != null) - { - logger.debug("voteSession id: " + voteSession.getVoteSessionId()); - - if (voteSession.getSessionStatus().equals(COMPLETED)) - { - ++countSessionComplete; + + logger.debug("final listAllGroupsContainerDTO:..." + listAllGroupsContainerDTO); + return listAllGroupsContainerDTO; + } + + public static Map buildGroupsAttemptData(HttpServletRequest request, VoteContent voteContent, + IVoteService voteService, VoteQueContent voteQueContent, String questionUid, boolean isUserNamesVisible, + boolean isLearnerRequest, String currentSessionId, String userId) { + logger.debug("doing buildGroupsAttemptData..."); + logger.debug("isUserNamesVisible: " + isUserNamesVisible); + logger.debug("isLearnerRequest: " + isLearnerRequest); + logger.debug("currentSessionId: " + currentSessionId); + logger.debug("userId: " + userId); + + logger.debug("voteService: " + voteService); + + Map mapMonitoredAttemptsContainerDTO = new TreeMap(new VoteStringComparator()); + List listMonitoredAttemptsContainerDTO = new LinkedList(); + + Map summaryToolSessions = populateToolSessionsId(request, voteContent, voteService); + logger.debug("summaryToolSessions: " + summaryToolSessions); + + Iterator itMap = summaryToolSessions.entrySet().iterator(); + + /*request is for monitoring summary */ + if (!isLearnerRequest) { + + if (currentSessionId != null) { + if (currentSessionId.equals("All")) { + logger.debug("**summary request is for All**:"); + while (itMap.hasNext()) { + Map.Entry pairs = (Map.Entry) itMap.next(); + logger.debug("using the summary tool sessions pair: " + pairs.getKey() + " = " + + pairs.getValue()); + + if (!(pairs.getValue().toString().equals("None")) + && !(pairs.getValue().toString().equals("All"))) { + logger + .debug("using the numerical summary tool sessions pair: " + " = " + + pairs.getValue()); + VoteSession voteSession = voteService.retrieveVoteSession(new Long(pairs.getValue() + .toString())); + logger.debug("voteSession: " + " = " + voteSession); + if (voteSession != null) { + List listUsers = voteService.getUserBySessionOnly(voteSession); + logger.debug("listMcUsers for session id:" + voteSession.getVoteSessionId() + " = " + + listUsers); + Map sessionUsersAttempts = populateSessionUsersAttempts(request, voteService, + voteSession.getVoteSessionId(), listUsers, questionUid, isUserNamesVisible, + isLearnerRequest, userId); + listMonitoredAttemptsContainerDTO.add(sessionUsersAttempts); } - - Iterator iteratorUser=voteSession.getVoteQueUsers().iterator(); - while (iteratorUser.hasNext()) - { - VoteQueUsr voteQueUsr=(VoteQueUsr) iteratorUser.next(); - logger.debug("voteQueUsr: " + voteQueUsr); - - if (voteQueUsr != null) - { - logger.debug("voteQueUsr foundid"); - ++countAllUsers; - } - } + } } + } else if (!currentSessionId.equals("All")) { + logger.debug("**summary request is for currentSessionId**:" + currentSessionId); + VoteSession voteSession = voteService.retrieveVoteSession(new Long(currentSessionId.toString())); + logger.debug("voteSession: " + " = " + voteSession); + + List listUsers = voteService.getUserBySessionOnly(voteSession); + logger.debug("listUsers: " + " = " + listUsers); + + Map sessionUsersAttempts = populateSessionUsersAttempts(request, voteService, new Long( + currentSessionId), listUsers, questionUid, isUserNamesVisible, isLearnerRequest, userId); + listMonitoredAttemptsContainerDTO.add(sessionUsersAttempts); } - logger.debug("countAllUsers: " + countAllUsers); - logger.debug("countSessionComplete: " + countSessionComplete); - - - voteStatsDTO.setCountAllUsers(new Integer(countAllUsers).toString()); - voteStatsDTO.setCountSessionComplete(new Integer(countSessionComplete).toString()); - - logger.debug("voteStatsDTO: " + voteStatsDTO); + } + } else { + /*request is for learner report, use only the passed tool session in the report*/ + logger.debug("using currentSessionId for the learner report:" + currentSessionId); + while (itMap.hasNext()) { + Map.Entry pairs = (Map.Entry) itMap.next(); + logger.debug("using the summary tool sessions pair: " + pairs.getKey() + " = " + pairs.getValue()); - request.setAttribute(VOTE_STATS_DTO, voteStatsDTO); + if (!(pairs.getValue().toString().equals("None")) && !(pairs.getValue().toString().equals("All"))) { + logger.debug("using the numerical summary tool sessions pair: " + " = " + pairs.getValue()); + + if (currentSessionId.equals(pairs.getValue())) { + logger + .debug("only using this tool session for the learner report: " + " = " + + pairs.getValue()); + VoteSession voteSession = voteService + .retrieveVoteSession(new Long(pairs.getValue().toString())); + logger.debug("voteSession: " + " = " + voteSession); + if (voteSession != null) { + List listUsers = voteService.getUserBySessionOnly(voteSession); + logger.debug("listVoteUsers for session id:" + voteSession.getVoteSessionId() + " = " + + listUsers); + Map sessionUsersAttempts = populateSessionUsersAttempts(request, voteService, voteSession + .getVoteSessionId(), listUsers, questionUid, isUserNamesVisible, isLearnerRequest, + userId); + listMonitoredAttemptsContainerDTO.add(sessionUsersAttempts); + } + } + } + } } - - public static void generateGroupsSessionData(HttpServletRequest request, IVoteService voteService, VoteContent voteContent) - { - logger.debug("generateGroupsSessionData: " + voteContent); - - List listAllGroupsDTO=buildGroupBasedSessionData(request, voteContent, voteService); - logger.debug("listAllGroupsDTO: " + listAllGroupsDTO); - - request.setAttribute(LIST_ALL_GROUPS_DTO, listAllGroupsDTO); - } - - - public static List buildGroupBasedSessionData(HttpServletRequest request, VoteContent voteContent, IVoteService voteService) - { - logger.debug("buildGroupBasedSessionData" + voteContent); - logger.debug("will be building groups question data for content:..." + voteContent); - List listQuestions=voteService.getAllQuestionEntries(voteContent.getUid()); - logger.debug("listQuestions:..." + listQuestions); - - List listAllGroupsContainerDTO= new LinkedList(); - - - Iterator iteratorSession= voteContent.getVoteSessions().iterator(); - while (iteratorSession.hasNext()) - { - VoteSession voteSession=(VoteSession) iteratorSession.next(); - logger.debug("iteration for group based session data: " + voteSession); - String currentSessionId=voteSession.getVoteSessionId().toString(); - logger.debug("currentSessionId: " + currentSessionId); - - String currentSessionName=voteSession.getSession_name(); - logger.debug("currentSessionName: " + currentSessionName); - - VoteAllGroupsDTO voteAllGroupsDTO= new VoteAllGroupsDTO(); - List listMonitoredAnswersContainerDTO= new LinkedList(); - - if (voteSession != null) - { - Iterator itListQuestions = listQuestions.iterator(); - while (itListQuestions.hasNext()) - { - VoteQueContent voteQueContent =(VoteQueContent)itListQuestions.next(); - logger.debug("voteQueContent:..." + voteQueContent); - - if (voteQueContent != null) - { - logger.debug("populating VoteMonitoredAnswersDTO for : " + voteQueContent); - VoteMonitoredAnswersDTO voteMonitoredAnswersDTO= new VoteMonitoredAnswersDTO(); - voteMonitoredAnswersDTO.setQuestionUid(voteQueContent.getUid().toString()); - voteMonitoredAnswersDTO.setQuestion(voteQueContent.getQuestion()); - voteMonitoredAnswersDTO.setSessionId(currentSessionId); - voteMonitoredAnswersDTO.setSessionName(currentSessionName); - - Map questionAttemptData= buildGroupsAttemptData(request, voteContent, voteService, voteQueContent, voteQueContent.getUid().toString(), - true,false, currentSessionId, null); - logger.debug("generated questionAttemptData: " + questionAttemptData); - voteMonitoredAnswersDTO.setQuestionAttempts(questionAttemptData); - - logger.debug("adding voteMonitoredAnswersDTO to the listMonitoredAnswersContainerDTO: " + voteMonitoredAnswersDTO); - listMonitoredAnswersContainerDTO.add(voteMonitoredAnswersDTO); - } + logger.debug("final listMonitoredAttemptsContainerDTO:..." + listMonitoredAttemptsContainerDTO); + mapMonitoredAttemptsContainerDTO = convertToMap(listMonitoredAttemptsContainerDTO); + logger.debug("final mapMonitoredAttemptsContainerDTO:..." + mapMonitoredAttemptsContainerDTO); + return mapMonitoredAttemptsContainerDTO; + } + + public static Map populateSessionUsersAttempts(HttpServletRequest request, IVoteService voteService, + Long sessionId, List listUsers, String questionUid, boolean isUserNamesVisible, boolean isLearnerRequest, + String userId) { + logger.debug("isUserNamesVisible: " + isUserNamesVisible); + logger.debug("isLearnerRequest: " + isLearnerRequest); + logger.debug("userId: " + userId); + + logger.debug("doing populateSessionUsersAttempts..."); + logger.debug("voteService: " + voteService); + + Map mapMonitoredUserContainerDTO = new TreeMap(new VoteStringComparator()); + List listMonitoredUserContainerDTO = new LinkedList(); + Iterator itUsers = listUsers.iterator(); + + if (userId == null) { + logger.debug("request is not for learner progress report"); + if ((isUserNamesVisible) && (!isLearnerRequest)) { + logger.debug("isUserNamesVisible true, isLearnerRequest false"); + logger.debug("getting alll the user' data"); + while (itUsers.hasNext()) { + VoteQueUsr voteQueUsr = (VoteQueUsr) itUsers.next(); + logger.debug("voteQueUsr: " + voteQueUsr); + + if (voteQueUsr != null) { + logger.debug("getting listUserAttempts for user id: " + voteQueUsr.getUid() + + " and que content id: " + questionUid); + List listUserAttempts = voteService.getAttemptsForUserAndQuestionContent(voteQueUsr.getUid(), + new Long(questionUid)); + logger.debug("listUserAttempts: " + listUserAttempts); + + Iterator itAttempts = listUserAttempts.iterator(); + while (itAttempts.hasNext()) { + VoteUsrAttempt voteUsrResp = (VoteUsrAttempt) itAttempts.next(); + logger.debug("voteUsrResp: " + voteUsrResp); + + if (voteUsrResp != null) { + VoteMonitoredUserDTO voteMonitoredUserDTO = new VoteMonitoredUserDTO(); + voteMonitoredUserDTO.setAttemptTime(voteUsrResp.getAttemptTime()); + //voteMonitoredUserDTO.setTimeZone(voteUsrResp.getTimezone()); + voteMonitoredUserDTO.setUid(voteUsrResp.getUid().toString()); + voteMonitoredUserDTO.setUserName(voteQueUsr.getFullname()); + voteMonitoredUserDTO.setQueUsrId(voteQueUsr.getUid().toString()); + voteMonitoredUserDTO.setSessionId(sessionId.toString()); + voteMonitoredUserDTO.setResponse(voteUsrResp.getUserEntry()); + + String responsePresentable = VoteUtils.replaceNewLines(voteUsrResp.getUserEntry()); + logger.debug("responsePresentable: " + responsePresentable); + voteMonitoredUserDTO.setResponsePresentable(responsePresentable); + + voteMonitoredUserDTO.setQuestionUid(questionUid); + voteMonitoredUserDTO.setVisible(new Boolean(voteUsrResp.isVisible()).toString()); + listMonitoredUserContainerDTO.add(voteMonitoredUserDTO); } + } } - logger.debug("listMonitoredAnswersContainerDTO:" + listMonitoredAnswersContainerDTO); - - logger.debug("adding listMonitoredAnswersContainerDTO to the voteAllGroupsDTO:" + listMonitoredAnswersContainerDTO); - voteAllGroupsDTO.setGroupData(listMonitoredAnswersContainerDTO); - voteAllGroupsDTO.setSessionName(currentSessionName); - voteAllGroupsDTO.setSessionId(currentSessionId); - - logger.debug("built voteAllGroupsDTO:" + voteAllGroupsDTO); - listAllGroupsContainerDTO.add(voteAllGroupsDTO); - } - - - logger.debug("final listAllGroupsContainerDTO:..." + listAllGroupsContainerDTO); - return listAllGroupsContainerDTO; - } - - - public static Map buildGroupsAttemptData(HttpServletRequest request, VoteContent voteContent, IVoteService voteService, VoteQueContent voteQueContent, String questionUid, - boolean isUserNamesVisible, boolean isLearnerRequest, String currentSessionId, String userId) - { - logger.debug("doing buildGroupsAttemptData..."); - logger.debug("isUserNamesVisible: " + isUserNamesVisible); - logger.debug("isLearnerRequest: " + isLearnerRequest); - logger.debug("currentSessionId: " + currentSessionId); - logger.debug("userId: " + userId); - - - logger.debug("voteService: " + voteService); + } else if ((isUserNamesVisible) && (isLearnerRequest)) { + logger + .debug("just populating data normally just like monitoring summary, except that the data is ony for a specific session"); + logger.debug("isUserNamesVisible true, isLearnerRequest true"); - Map mapMonitoredAttemptsContainerDTO= new TreeMap(new VoteStringComparator()); - List listMonitoredAttemptsContainerDTO= new LinkedList(); - - Map summaryToolSessions=populateToolSessionsId(request, voteContent, voteService); - logger.debug("summaryToolSessions: " + summaryToolSessions); - - Iterator itMap = summaryToolSessions.entrySet().iterator(); - - - /*request is for monitoring summary */ - if (!isLearnerRequest) - { + String userID = VoteUtils.getCurrentLearnerID(); + logger.debug("userID: " + userID); + VoteQueUsr voteQueUsr = voteService.getVoteQueUsrById(new Long(userID).longValue()); + logger + .debug("the current user voteQueUsr " + voteQueUsr + " and username: " + + voteQueUsr.getUsername()); - if (currentSessionId != null) - { - if (currentSessionId.equals("All")) - { - logger.debug("**summary request is for All**:"); - while (itMap.hasNext()) - { - Map.Entry pairs = (Map.Entry)itMap.next(); - logger.debug("using the summary tool sessions pair: " + pairs.getKey() + " = " + pairs.getValue()); - - if (!(pairs.getValue().toString().equals("None")) && !(pairs.getValue().toString().equals("All"))) - { - logger.debug("using the numerical summary tool sessions pair: " + " = " + pairs.getValue()); - VoteSession voteSession= voteService.retrieveVoteSession(new Long(pairs.getValue().toString())); - logger.debug("voteSession: " + " = " + voteSession); - if (voteSession != null) - { - List listUsers=voteService.getUserBySessionOnly(voteSession); - logger.debug("listMcUsers for session id:" + voteSession.getVoteSessionId() + " = " + listUsers); - Map sessionUsersAttempts=populateSessionUsersAttempts(request, voteService, voteSession.getVoteSessionId(), listUsers, questionUid, - isUserNamesVisible, isLearnerRequest, userId); - listMonitoredAttemptsContainerDTO.add(sessionUsersAttempts); - } - } - } - } - else if (!currentSessionId.equals("All")) - { - logger.debug("**summary request is for currentSessionId**:" + currentSessionId); - VoteSession voteSession= voteService.retrieveVoteSession(new Long(currentSessionId.toString())); - logger.debug("voteSession: " + " = " + voteSession); - - List listUsers=voteService.getUserBySessionOnly(voteSession); - logger.debug("listUsers: " + " = " + listUsers); - - Map sessionUsersAttempts=populateSessionUsersAttempts(request, voteService, new Long(currentSessionId), listUsers, questionUid, - isUserNamesVisible, isLearnerRequest, userId); - listMonitoredAttemptsContainerDTO.add(sessionUsersAttempts); - } - } - } - else - { - /*request is for learner report, use only the passed tool session in the report*/ - logger.debug("using currentSessionId for the learner report:" + currentSessionId); - while (itMap.hasNext()) - { - Map.Entry pairs = (Map.Entry)itMap.next(); - logger.debug("using the summary tool sessions pair: " + pairs.getKey() + " = " + pairs.getValue()); - - if (!(pairs.getValue().toString().equals("None")) && !(pairs.getValue().toString().equals("All"))) - { - logger.debug("using the numerical summary tool sessions pair: " + " = " + pairs.getValue()); - - if (currentSessionId.equals(pairs.getValue())) - { - logger.debug("only using this tool session for the learner report: " + " = " + pairs.getValue()); - VoteSession voteSession= voteService.retrieveVoteSession(new Long(pairs.getValue().toString())); - logger.debug("voteSession: " + " = " + voteSession); - if (voteSession != null) - { - List listUsers=voteService.getUserBySessionOnly(voteSession); - logger.debug("listVoteUsers for session id:" + voteSession.getVoteSessionId() + " = " + listUsers); - Map sessionUsersAttempts=populateSessionUsersAttempts(request, voteService, voteSession.getVoteSessionId(), listUsers, questionUid, - isUserNamesVisible, isLearnerRequest, userId); - listMonitoredAttemptsContainerDTO.add(sessionUsersAttempts); - } - } - } - } - } + while (itUsers.hasNext()) { + voteQueUsr = (VoteQueUsr) itUsers.next(); + logger.debug("voteQueUsr: " + voteQueUsr); - logger.debug("final listMonitoredAttemptsContainerDTO:..." + listMonitoredAttemptsContainerDTO); - mapMonitoredAttemptsContainerDTO=convertToMap(listMonitoredAttemptsContainerDTO); - logger.debug("final mapMonitoredAttemptsContainerDTO:..." + mapMonitoredAttemptsContainerDTO); - return mapMonitoredAttemptsContainerDTO; - } - + if (voteQueUsr != null) { + logger.debug("getting listUserAttempts for user id: " + voteQueUsr.getUid() + + " and que content id: " + questionUid); + List listUserAttempts = voteService.getAttemptsForUserAndQuestionContent(voteQueUsr.getUid(), + new Long(questionUid)); + logger.debug("listUserAttempts: " + listUserAttempts); - - public static Map populateSessionUsersAttempts(HttpServletRequest request,IVoteService voteService, Long sessionId, - List listUsers, String questionUid, boolean isUserNamesVisible, boolean isLearnerRequest, String userId) - { - logger.debug("isUserNamesVisible: " + isUserNamesVisible); - logger.debug("isLearnerRequest: " + isLearnerRequest); - logger.debug("userId: " + userId); - - logger.debug("doing populateSessionUsersAttempts..."); - logger.debug("voteService: " + voteService); - - Map mapMonitoredUserContainerDTO= new TreeMap(new VoteStringComparator()); - List listMonitoredUserContainerDTO= new LinkedList(); - Iterator itUsers=listUsers.iterator(); - - - if (userId == null) - { - logger.debug("request is not for learner progress report"); - if ((isUserNamesVisible) && (!isLearnerRequest)) - { - logger.debug("isUserNamesVisible true, isLearnerRequest false" ); - logger.debug("getting alll the user' data"); - while (itUsers.hasNext()) - { - VoteQueUsr voteQueUsr=(VoteQueUsr)itUsers.next(); - logger.debug("voteQueUsr: " + voteQueUsr); - - if (voteQueUsr != null) - { - logger.debug("getting listUserAttempts for user id: " + voteQueUsr.getUid() + " and que content id: " + questionUid); - List listUserAttempts=voteService.getAttemptsForUserAndQuestionContent(voteQueUsr.getUid(), new Long(questionUid)); - logger.debug("listUserAttempts: " + listUserAttempts); - - Iterator itAttempts=listUserAttempts.iterator(); - while (itAttempts.hasNext()) - { - VoteUsrAttempt voteUsrResp=(VoteUsrAttempt)itAttempts.next(); - logger.debug("voteUsrResp: " + voteUsrResp); - - if (voteUsrResp != null) - { - VoteMonitoredUserDTO voteMonitoredUserDTO = new VoteMonitoredUserDTO(); - voteMonitoredUserDTO.setAttemptTime(voteUsrResp.getAttemptTime()); - //voteMonitoredUserDTO.setTimeZone(voteUsrResp.getTimezone()); - voteMonitoredUserDTO.setUid(voteUsrResp.getUid().toString()); - voteMonitoredUserDTO.setUserName(voteQueUsr.getFullname()); - voteMonitoredUserDTO.setQueUsrId(voteQueUsr.getUid().toString()); - voteMonitoredUserDTO.setSessionId(sessionId.toString()); - voteMonitoredUserDTO.setResponse(voteUsrResp.getUserEntry()); - - String responsePresentable=VoteUtils.replaceNewLines(voteUsrResp.getUserEntry()); - logger.debug("responsePresentable: " + responsePresentable); - voteMonitoredUserDTO.setResponsePresentable(responsePresentable); - - voteMonitoredUserDTO.setQuestionUid(questionUid); - voteMonitoredUserDTO.setVisible(new Boolean(voteUsrResp.isVisible()).toString()); - listMonitoredUserContainerDTO.add(voteMonitoredUserDTO); - } - } - } - } + Iterator itAttempts = listUserAttempts.iterator(); + while (itAttempts.hasNext()) { + VoteUsrAttempt voteUsrResp = (VoteUsrAttempt) itAttempts.next(); + logger.debug("voteUsrResp: " + voteUsrResp); + + if (voteUsrResp != null) { + VoteMonitoredUserDTO voteMonitoredUserDTO = new VoteMonitoredUserDTO(); + voteMonitoredUserDTO.setAttemptTime(voteUsrResp.getAttemptTime()); + //voteMonitoredUserDTO.setTimeZone(voteUsrResp.getTimezone()); + voteMonitoredUserDTO.setUid(voteUsrResp.getUid().toString()); + voteMonitoredUserDTO.setUserName(voteQueUsr.getFullname()); + voteMonitoredUserDTO.setQueUsrId(voteQueUsr.getUid().toString()); + voteMonitoredUserDTO.setSessionId(sessionId.toString()); + voteMonitoredUserDTO.setResponse(voteUsrResp.getUserEntry()); + + String responsePresentable = VoteUtils.replaceNewLines(voteUsrResp.getUserEntry()); + logger.debug("responsePresentable: " + responsePresentable); + voteMonitoredUserDTO.setResponsePresentable(responsePresentable); + + voteMonitoredUserDTO.setQuestionUid(questionUid); + voteMonitoredUserDTO.setVisible(new Boolean(voteUsrResp.isVisible()).toString()); + listMonitoredUserContainerDTO.add(voteMonitoredUserDTO); + } } - else if ((isUserNamesVisible) && (isLearnerRequest)) - { - logger.debug("just populating data normally just like monitoring summary, except that the data is ony for a specific session" ); - logger.debug("isUserNamesVisible true, isLearnerRequest true" ); + } + } + } else if ((!isUserNamesVisible) && (isLearnerRequest)) { + logger + .debug("populating data normally exception are for a specific session and other user names are not visible."); + logger.debug("isUserNamesVisible false, isLearnerRequest true"); + logger.debug("getting only current user's data"); - String userID = VoteUtils.getCurrentLearnerID(); - logger.debug("userID: " + userID); - VoteQueUsr voteQueUsr=voteService.getVoteQueUsrById(new Long(userID).longValue()); - logger.debug("the current user voteQueUsr " + voteQueUsr + " and username: " + voteQueUsr.getUsername()); - - while (itUsers.hasNext()) - { - voteQueUsr=(VoteQueUsr)itUsers.next(); - logger.debug("voteQueUsr: " + voteQueUsr); - - if (voteQueUsr != null) - { - logger.debug("getting listUserAttempts for user id: " + voteQueUsr.getUid() + " and que content id: " + questionUid); - List listUserAttempts=voteService.getAttemptsForUserAndQuestionContent(voteQueUsr.getUid(), new Long(questionUid)); - logger.debug("listUserAttempts: " + listUserAttempts); - - Iterator itAttempts=listUserAttempts.iterator(); - while (itAttempts.hasNext()) - { - VoteUsrAttempt voteUsrResp=(VoteUsrAttempt)itAttempts.next(); - logger.debug("voteUsrResp: " + voteUsrResp); - - if (voteUsrResp != null) - { - VoteMonitoredUserDTO voteMonitoredUserDTO = new VoteMonitoredUserDTO(); - voteMonitoredUserDTO.setAttemptTime(voteUsrResp.getAttemptTime()); - //voteMonitoredUserDTO.setTimeZone(voteUsrResp.getTimezone()); - voteMonitoredUserDTO.setUid(voteUsrResp.getUid().toString()); - voteMonitoredUserDTO.setUserName(voteQueUsr.getFullname()); - voteMonitoredUserDTO.setQueUsrId(voteQueUsr.getUid().toString()); - voteMonitoredUserDTO.setSessionId(sessionId.toString()); - voteMonitoredUserDTO.setResponse(voteUsrResp.getUserEntry()); - - String responsePresentable=VoteUtils.replaceNewLines(voteUsrResp.getUserEntry()); - logger.debug("responsePresentable: " + responsePresentable); - voteMonitoredUserDTO.setResponsePresentable(responsePresentable); - - voteMonitoredUserDTO.setQuestionUid(questionUid); - voteMonitoredUserDTO.setVisible(new Boolean(voteUsrResp.isVisible()).toString()); - listMonitoredUserContainerDTO.add(voteMonitoredUserDTO); - } - } - } - } - } - else if ((!isUserNamesVisible) && (isLearnerRequest)) - { - logger.debug("populating data normally exception are for a specific session and other user names are not visible."); - logger.debug("isUserNamesVisible false, isLearnerRequest true" ); - logger.debug("getting only current user's data" ); + String userID = VoteUtils.getCurrentLearnerID(); + logger.debug("userID: " + userID); - String userID = VoteUtils.getCurrentLearnerID(); - logger.debug("userID: " + userID); - - while (itUsers.hasNext()) - { - VoteQueUsr voteQueUsr=(VoteQueUsr)itUsers.next(); - logger.debug("voteQueUsr: " + voteQueUsr); - - if (voteQueUsr != null) - { - logger.debug("getting listUserAttempts for user id: " + voteQueUsr.getUid() + " and que content id: " + questionUid); - List listUserAttempts=voteService.getAttemptsForUserAndQuestionContent(voteQueUsr.getUid(), new Long(questionUid)); - logger.debug("listUserAttempts: " + listUserAttempts); - - Iterator itAttempts=listUserAttempts.iterator(); - while (itAttempts.hasNext()) - { - VoteUsrAttempt voteUsrResp=(VoteUsrAttempt)itAttempts.next(); - logger.debug("voteUsrResp: " + voteUsrResp); - - if (voteUsrResp != null) - { - VoteMonitoredUserDTO voteMonitoredUserDTO = new VoteMonitoredUserDTO(); - voteMonitoredUserDTO.setAttemptTime(voteUsrResp.getAttemptTime()); - //voteMonitoredUserDTO.setTimeZone(voteUsrResp.getTimezone()); - voteMonitoredUserDTO.setUid(voteUsrResp.getUid().toString()); - - logger.debug("userID versus queUsrId: " + userID + "-" + voteQueUsr.getQueUsrId()); - if (userID.equals(voteQueUsr.getQueUsrId().toString())) - { - logger.debug("this is current user, put his name normally."); - voteMonitoredUserDTO.setUserName(voteQueUsr.getFullname()); - } - else - { - logger.debug("this is not current user, put his name as blank."); - voteMonitoredUserDTO.setUserName(" "); - } - - voteMonitoredUserDTO.setQueUsrId(voteQueUsr.getUid().toString()); - voteMonitoredUserDTO.setSessionId(sessionId.toString()); - voteMonitoredUserDTO.setResponse(voteUsrResp.getUserEntry()); - - String responsePresentable=VoteUtils.replaceNewLines(voteUsrResp.getUserEntry()); - logger.debug("responsePresentable: " + responsePresentable); - voteMonitoredUserDTO.setResponsePresentable(responsePresentable); + while (itUsers.hasNext()) { + VoteQueUsr voteQueUsr = (VoteQueUsr) itUsers.next(); + logger.debug("voteQueUsr: " + voteQueUsr); - voteMonitoredUserDTO.setQuestionUid(questionUid); - voteMonitoredUserDTO.setVisible(new Boolean(voteUsrResp.isVisible()).toString()); - listMonitoredUserContainerDTO.add(voteMonitoredUserDTO); - } - } - } - } + if (voteQueUsr != null) { + logger.debug("getting listUserAttempts for user id: " + voteQueUsr.getUid() + + " and que content id: " + questionUid); + List listUserAttempts = voteService.getAttemptsForUserAndQuestionContent(voteQueUsr.getUid(), + new Long(questionUid)); + logger.debug("listUserAttempts: " + listUserAttempts); + + Iterator itAttempts = listUserAttempts.iterator(); + while (itAttempts.hasNext()) { + VoteUsrAttempt voteUsrResp = (VoteUsrAttempt) itAttempts.next(); + logger.debug("voteUsrResp: " + voteUsrResp); + + if (voteUsrResp != null) { + VoteMonitoredUserDTO voteMonitoredUserDTO = new VoteMonitoredUserDTO(); + voteMonitoredUserDTO.setAttemptTime(voteUsrResp.getAttemptTime()); + //voteMonitoredUserDTO.setTimeZone(voteUsrResp.getTimezone()); + voteMonitoredUserDTO.setUid(voteUsrResp.getUid().toString()); + + logger.debug("userID versus queUsrId: " + userID + "-" + voteQueUsr.getQueUsrId()); + if (userID.equals(voteQueUsr.getQueUsrId().toString())) { + logger.debug("this is current user, put his name normally."); + voteMonitoredUserDTO.setUserName(voteQueUsr.getFullname()); + } else { + logger.debug("this is not current user, put his name as blank."); + voteMonitoredUserDTO.setUserName(" "); } + + voteMonitoredUserDTO.setQueUsrId(voteQueUsr.getUid().toString()); + voteMonitoredUserDTO.setSessionId(sessionId.toString()); + voteMonitoredUserDTO.setResponse(voteUsrResp.getUserEntry()); + + String responsePresentable = VoteUtils.replaceNewLines(voteUsrResp.getUserEntry()); + logger.debug("responsePresentable: " + responsePresentable); + voteMonitoredUserDTO.setResponsePresentable(responsePresentable); + + voteMonitoredUserDTO.setQuestionUid(questionUid); + voteMonitoredUserDTO.setVisible(new Boolean(voteUsrResp.isVisible()).toString()); + listMonitoredUserContainerDTO.add(voteMonitoredUserDTO); + } + } + } } - else - { - logger.debug("request is for learner progress report: " + userId); - while (itUsers.hasNext()) - { - VoteQueUsr voteQueUsr=(VoteQueUsr)itUsers.next(); - logger.debug("voteQueUsr: " + voteQueUsr); - - if (voteQueUsr != null) - { - logger.debug("getting listUserAttempts for user id: " + voteQueUsr.getUid() + " and que content id: " + questionUid); - List listUserAttempts=voteService.getAttemptsForUserAndQuestionContent(voteQueUsr.getUid(), new Long(questionUid)); - logger.debug("listUserAttempts: " + listUserAttempts); + } + } else { + logger.debug("request is for learner progress report: " + userId); + while (itUsers.hasNext()) { + VoteQueUsr voteQueUsr = (VoteQueUsr) itUsers.next(); + logger.debug("voteQueUsr: " + voteQueUsr); - Iterator itAttempts=listUserAttempts.iterator(); - while (itAttempts.hasNext()) - { - VoteUsrAttempt voteUsrResp=(VoteUsrAttempt)itAttempts.next(); - logger.debug("voteUsrResp: " + voteUsrResp); - - if (voteUsrResp != null) - { - logger.debug("userID versus queUsrId: " + userId + "-" + voteQueUsr.getQueUsrId()); - if (userId.equals(voteQueUsr.getQueUsrId().toString())) - { - logger.debug("this is the user requested , include his name for learner progress."); - VoteMonitoredUserDTO voteMonitoredUserDTO = new VoteMonitoredUserDTO(); - voteMonitoredUserDTO.setAttemptTime(voteUsrResp.getAttemptTime()); - //voteMonitoredUserDTO.setTimeZone(voteUsrResp.getTimezone()); - voteMonitoredUserDTO.setUid(voteUsrResp.getUid().toString()); - voteMonitoredUserDTO.setUserName(voteQueUsr.getFullname()); - voteMonitoredUserDTO.setQueUsrId(voteQueUsr.getUid().toString()); - voteMonitoredUserDTO.setSessionId(sessionId.toString()); - voteMonitoredUserDTO.setResponse(voteUsrResp.getUserEntry()); - - String responsePresentable=VoteUtils.replaceNewLines(voteUsrResp.getUserEntry()); - logger.debug("responsePresentable: " + responsePresentable); - voteMonitoredUserDTO.setResponsePresentable(responsePresentable); - - voteMonitoredUserDTO.setQuestionUid(questionUid); - voteMonitoredUserDTO.setVisible(new Boolean(voteUsrResp.isVisible()).toString()); - listMonitoredUserContainerDTO.add(voteMonitoredUserDTO); - } - } - } - } - } - + if (voteQueUsr != null) { + logger.debug("getting listUserAttempts for user id: " + voteQueUsr.getUid() + + " and que content id: " + questionUid); + List listUserAttempts = voteService.getAttemptsForUserAndQuestionContent(voteQueUsr.getUid(), + new Long(questionUid)); + logger.debug("listUserAttempts: " + listUserAttempts); + + Iterator itAttempts = listUserAttempts.iterator(); + while (itAttempts.hasNext()) { + VoteUsrAttempt voteUsrResp = (VoteUsrAttempt) itAttempts.next(); + logger.debug("voteUsrResp: " + voteUsrResp); + + if (voteUsrResp != null) { + logger.debug("userID versus queUsrId: " + userId + "-" + voteQueUsr.getQueUsrId()); + if (userId.equals(voteQueUsr.getQueUsrId().toString())) { + logger.debug("this is the user requested , include his name for learner progress."); + VoteMonitoredUserDTO voteMonitoredUserDTO = new VoteMonitoredUserDTO(); + voteMonitoredUserDTO.setAttemptTime(voteUsrResp.getAttemptTime()); + //voteMonitoredUserDTO.setTimeZone(voteUsrResp.getTimezone()); + voteMonitoredUserDTO.setUid(voteUsrResp.getUid().toString()); + voteMonitoredUserDTO.setUserName(voteQueUsr.getFullname()); + voteMonitoredUserDTO.setQueUsrId(voteQueUsr.getUid().toString()); + voteMonitoredUserDTO.setSessionId(sessionId.toString()); + voteMonitoredUserDTO.setResponse(voteUsrResp.getUserEntry()); + + String responsePresentable = VoteUtils.replaceNewLines(voteUsrResp.getUserEntry()); + logger.debug("responsePresentable: " + responsePresentable); + voteMonitoredUserDTO.setResponsePresentable(responsePresentable); + + voteMonitoredUserDTO.setQuestionUid(questionUid); + voteMonitoredUserDTO.setVisible(new Boolean(voteUsrResp.isVisible()).toString()); + listMonitoredUserContainerDTO.add(voteMonitoredUserDTO); + } + } + } } - - - logger.debug("final listMonitoredUserContainerDTO: " + listMonitoredUserContainerDTO); - mapMonitoredUserContainerDTO=convertToMcMonitoredUserDTOMap(listMonitoredUserContainerDTO); - logger.debug("final mapMonitoredUserContainerDTO:..." + mapMonitoredUserContainerDTO); - return mapMonitoredUserContainerDTO; + } + } - - public static Map convertToMcMonitoredUserDTOMap(List list) - { - logger.debug("using convertToVoteMonitoredUserDTOMap: " + list); - Map map= new TreeMap(new VoteStringComparator()); - - Iterator listIterator=list.iterator(); - Long mapIndex=new Long(1); - - while (listIterator.hasNext()) - { - VoteMonitoredUserDTO data=(VoteMonitoredUserDTO)listIterator.next(); - map.put(mapIndex.toString(), data); - mapIndex=new Long(mapIndex.longValue()+1); - } - return map; + logger.debug("final listMonitoredUserContainerDTO: " + listMonitoredUserContainerDTO); + mapMonitoredUserContainerDTO = convertToMcMonitoredUserDTOMap(listMonitoredUserContainerDTO); + logger.debug("final mapMonitoredUserContainerDTO:..." + mapMonitoredUserContainerDTO); + return mapMonitoredUserContainerDTO; + } + + public static Map convertToMcMonitoredUserDTOMap(List list) { + logger.debug("using convertToVoteMonitoredUserDTOMap: " + list); + Map map = new TreeMap(new VoteStringComparator()); + + Iterator listIterator = list.iterator(); + Long mapIndex = new Long(1); + + while (listIterator.hasNext()) { + VoteMonitoredUserDTO data = (VoteMonitoredUserDTO) listIterator.next(); + map.put(mapIndex.toString(), data); + mapIndex = new Long(mapIndex.longValue() + 1); } - + return map; + } + } Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/VoteLearningAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/VoteLearningAction.java,v diff -u -r1.48 -r1.49 --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/VoteLearningAction.java 13 May 2008 07:23:20 -0000 1.48 +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/VoteLearningAction.java 18 Feb 2009 23:06:58 -0000 1.49 @@ -26,8 +26,8 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; -import java.util.Set; import java.util.Map; +import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; @@ -61,1023 +61,938 @@ import org.lamsfoundation.lams.tool.vote.service.IVoteService; import org.lamsfoundation.lams.tool.vote.service.VoteServiceProxy; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; +import org.lamsfoundation.lams.util.MessageService; 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.util.MessageService; /** - *

Action class that controls the logic of tool behavior.

+ *

+ * Action class that controls the logic of tool behavior. + *

* - *

Note that Struts action class only has the responsibility to navigate - * page flow. All database operation should go to service layer and data - * transformation from domain model to struts form bean should go to form - * bean class. This ensure clean and maintainable code. + *

+ * Note that Struts action class only has the responsibility to navigate page + * flow. All database operation should go to service layer and data + * transformation from domain model to struts form bean should go to form bean + * class. This ensure clean and maintainable code. *

* * SystemException is thrown whenever an known error condition is - * identified. No system exception error handling code should appear in the - * Struts action class as all of them are handled in + * identified. No system exception error handling code should appear in the + * Struts action class as all of them are handled in * CustomStrutsExceptionHandler. * * @author Ozgur Demirtas * * - - - - - - + + - - - - + - + - - + - + - + - - - + - - + - * -*/ -public class VoteLearningAction extends LamsDispatchAction implements VoteAppConstants -{ - static Logger logger = Logger.getLogger(VoteLearningAction.class.getName()); - - /** - *

Default struts dispatch method.

+ + + + + + + + + +
+ + * + */ +public class VoteLearningAction extends LamsDispatchAction implements VoteAppConstants { + static Logger logger = Logger.getLogger(VoteLearningAction.class.getName()); + + /** + *

+ * Default struts dispatch method. + *

* - *

It is assuming that progress engine should pass in the tool access - * mode and the tool session id as http parameters.

+ *

+ * It is assuming that progress engine should pass in the tool access mode + * and the tool session id as http parameters. + *

* - * @param mapping An ActionMapping class that will be used by the Action class to tell - * the ActionServlet where to send the end-user. - * - * @param form The ActionForm class that will contain any data submitted - * by the end-user via a form. - * @param request A standard Servlet HttpServletRequest class. - * @param response A standard Servlet HttpServletResponse class. - * @return An ActionForward class that will be returned to the ActionServlet indicating where - * the user is to go next. + * @param mapping + * An ActionMapping class that will be used by the Action + * class to tell the ActionServlet where to send the + * end-user. + * + * @param form + * The ActionForm class that will contain any data submitted + * by the end-user via a form. + * @param request + * A standard Servlet HttpServletRequest class. + * @param response + * A standard Servlet HttpServletResponse class. + * @return An ActionForward class that will be returned to the ActionServlet + * indicating where the user is to go next. * @throws IOException * @throws ServletException - * @throws VoteApplicationException the known runtime exception + * @throws VoteApplicationException + * the known runtime exception * - * unspecified(ActionMapping mapping, - ActionForm form, - HttpServletRequest request, - HttpServletResponse response) throws IOException, - ServletException - - * main content/question content management and workflow logic - * - * if the passed toolContentID exists in the db, we need to get the relevant data into the Map - * if not, create the default Map - */ - public ActionForward unspecified(ActionMapping mapping, - ActionForm form, - HttpServletRequest request, - HttpServletResponse response) throws IOException, - ServletException - { - VoteLearningForm voteLearningForm = (VoteLearningForm) form; - voteLearningForm.setNominationsSubmited(new Boolean(false).toString()); - - repopulateRequestParameters(request,voteLearningForm); - - VoteUtils.cleanUpUserExceptions(request); - voteLearningForm.setMaxNominationCountReached(new Boolean(false).toString()); - return null; + * unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest + * request, HttpServletResponse response) throws IOException, + * ServletException + * + * main content/question content management and workflow logic + * + * if the passed toolContentID exists in the db, we need to get the relevant + * data into the Map if not, create the default Map + */ + public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException { + VoteLearningForm voteLearningForm = (VoteLearningForm) form; + voteLearningForm.setNominationsSubmited(new Boolean(false).toString()); + + repopulateRequestParameters(request, voteLearningForm); + + VoteUtils.cleanUpUserExceptions(request); + voteLearningForm.setMaxNominationCountReached(new Boolean(false).toString()); + return null; } - - public ActionForward viewAllResults(ActionMapping mapping, - ActionForm form, - HttpServletRequest request, - HttpServletResponse response) throws IOException, - ServletException - { - VoteUtils.cleanUpUserExceptions(request); - logger.debug("dispatching viewAllResults..."); - VoteLearningForm voteLearningForm = (VoteLearningForm) form; - VoteGeneralLearnerFlowDTO voteGeneralLearnerFlowDTO= new VoteGeneralLearnerFlowDTO(); - - voteLearningForm.setNominationsSubmited(new Boolean(false).toString()); - voteLearningForm.setMaxNominationCountReached(new Boolean(false).toString()); - - voteGeneralLearnerFlowDTO.setNominationsSubmited(new Boolean(false).toString()); - voteGeneralLearnerFlowDTO.setMaxNominationCountReached(new Boolean(false).toString()); - - IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext()); - logger.debug("retrieving voteService from session: " + voteService); + public ActionForward viewAllResults(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException { + VoteUtils.cleanUpUserExceptions(request); + logger.debug("dispatching viewAllResults..."); + VoteLearningForm voteLearningForm = (VoteLearningForm) form; + VoteGeneralLearnerFlowDTO voteGeneralLearnerFlowDTO = new VoteGeneralLearnerFlowDTO(); - repopulateRequestParameters(request,voteLearningForm); - - String toolSessionID=request.getParameter(TOOL_SESSION_ID); - logger.debug("toolSessionID: " + toolSessionID); - voteLearningForm.setToolSessionID(toolSessionID); - - String userID=request.getParameter(USER_ID); - logger.debug("userID: " + userID); - voteLearningForm.setUserID(userID); - - VoteSession voteSession=voteService.retrieveVoteSession(new Long(toolSessionID)); - logger.debug("retrieving voteSession: " + voteSession); - - VoteContent voteContent=voteSession.getVoteContent(); - logger.debug("retrieving voteContent: " + voteContent); - - voteGeneralLearnerFlowDTO.setActivityTitle(voteContent.getTitle()); - voteGeneralLearnerFlowDTO.setActivityInstructions(voteContent.getInstructions()); + voteLearningForm.setNominationsSubmited(new Boolean(false).toString()); + voteLearningForm.setMaxNominationCountReached(new Boolean(false).toString()); - Long toolContentID=voteContent.getVoteContentId(); - logger.debug("toolContentID: " + toolContentID); - - setContentInUse(request,voteService, toolContentID); - - - Long toolSessionUid=voteSession.getUid(); - logger.debug("toolSessionUid: " + toolSessionUid); - - VoteQueUsr existingVoteQueUsr=voteService.getVoteUserBySession(new Long(userID), voteSession.getUid()); - logger.debug("existingVoteQueUsr: " + existingVoteQueUsr); - - existingVoteQueUsr.setFinalScreenRequested(true); - voteService.updateVoteUser(existingVoteQueUsr); - logger.debug("final screen requested by: " + existingVoteQueUsr); + voteGeneralLearnerFlowDTO.setNominationsSubmited(new Boolean(false).toString()); + voteGeneralLearnerFlowDTO.setMaxNominationCountReached(new Boolean(false).toString()); + IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext()); + logger.debug("retrieving voteService from session: " + voteService); - Set userAttempts=voteService.getAttemptsForUserAndSession(existingVoteQueUsr.getUid(), toolSessionUid); - logger.debug("userAttempts: "+ userAttempts); - request.setAttribute(LIST_GENERAL_CHECKED_OPTIONS_CONTENT, userAttempts); - - request.setAttribute(LIST_GENERAL_CHECKED_OPTIONS_CONTENT, userAttempts); - Set userEntries = voteService.getSessionUserEntriesSet(new Long(voteSession.getUid())); - - logger.debug("voteSession uid:" + voteSession.getUid()); - logger.debug("calling prepareChartData:" + voteContent.getVoteContentId() + " " + voteSession.getUid()); + repopulateRequestParameters(request, voteLearningForm); - VoteGeneralMonitoringDTO voteGeneralMonitoringDTO=new VoteGeneralMonitoringDTO(); - MonitoringUtil.prepareChartData(request, voteService, null, voteContent.getVoteContentId().toString(), - voteSession.getUid().toString(), voteGeneralLearnerFlowDTO, voteGeneralMonitoringDTO, getMessageService()); - logger.debug("end of prepareChartData:" + voteContent.getVoteContentId() + " " + voteSession.getUid()); - - voteGeneralLearnerFlowDTO.setReflection(new Boolean(voteContent.isReflect()).toString()); - String reflectionSubject=VoteUtils.replaceNewLines(voteContent.getReflectionSubject()); - voteGeneralLearnerFlowDTO.setReflectionSubject(reflectionSubject); - - voteLearningForm.resetCommands(); - - logger.debug("view-only voteGeneralLearnerFlowDTO: " + voteGeneralLearnerFlowDTO); - request.setAttribute(VOTE_GENERAL_LEARNER_FLOW_DTO,voteGeneralLearnerFlowDTO); + String toolSessionID = request.getParameter(TOOL_SESSION_ID); + logger.debug("toolSessionID: " + toolSessionID); + voteLearningForm.setToolSessionID(toolSessionID); - - logger.debug("fwding to ALL_NOMINATIONS: "+ ALL_NOMINATIONS); - return (mapping.findForward(ALL_NOMINATIONS)); - } - - - public ActionForward viewAnswers(ActionMapping mapping, - ActionForm form, - HttpServletRequest request, - HttpServletResponse response) throws IOException, - ServletException - { - VoteUtils.cleanUpUserExceptions(request); - logger.debug("dispatching viewAnswers..."); - - VoteLearningForm voteLearningForm = (VoteLearningForm) form; - VoteGeneralLearnerFlowDTO voteGeneralLearnerFlowDTO= new VoteGeneralLearnerFlowDTO(); - - voteLearningForm.setNominationsSubmited(new Boolean(false).toString()); - voteLearningForm.setMaxNominationCountReached(new Boolean(false).toString()); - - voteGeneralLearnerFlowDTO.setNominationsSubmited(new Boolean(false).toString()); - voteGeneralLearnerFlowDTO.setMaxNominationCountReached(new Boolean(false).toString()); - - IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext()); - logger.debug("retrieving voteService from session: " + voteService); + String userID = request.getParameter(USER_ID); + logger.debug("userID: " + userID); + voteLearningForm.setUserID(userID); - repopulateRequestParameters(request,voteLearningForm); - - String toolSessionID=request.getParameter(TOOL_SESSION_ID); - logger.debug("toolSessionID: " + toolSessionID); - voteLearningForm.setToolSessionID(toolSessionID); - - String userID=request.getParameter(USER_ID); - logger.debug("userID: " + userID); - voteLearningForm.setUserID(userID); - - String revisitingUser=request.getParameter(REVISITING_USER); - logger.debug("revisitingUser: " + revisitingUser); - voteLearningForm.setRevisitingUser(revisitingUser); + VoteSession voteSession = voteService.retrieveVoteSession(new Long(toolSessionID)); + logger.debug("retrieving voteSession: " + voteSession); - VoteSession voteSession=voteService.retrieveVoteSession(new Long(toolSessionID)); - logger.debug("retrieving voteSession: " + voteSession); - - VoteContent voteContent=voteSession.getVoteContent(); - logger.debug("retrieving voteContent: " + voteContent); - - voteGeneralLearnerFlowDTO.setActivityTitle(voteContent.getTitle()); - voteGeneralLearnerFlowDTO.setActivityInstructions(voteContent.getInstructions()); + VoteContent voteContent = voteSession.getVoteContent(); + logger.debug("retrieving voteContent: " + voteContent); - - Long toolContentID=voteContent.getVoteContentId(); - logger.debug("toolContentID: " + toolContentID); - - setContentInUse(request, voteService, toolContentID); - - if (revisitingUser.equals("true")) - { - logger.debug("this is a revisiting user, get the nominations from the db: " + revisitingUser); - logger.debug("toolContentID: " + toolContentID); + voteGeneralLearnerFlowDTO.setActivityTitle(voteContent.getTitle()); + voteGeneralLearnerFlowDTO.setActivityInstructions(voteContent.getInstructions()); - VoteQueUsr voteQueUsr=LearningUtil.getUser(request, voteService); - logger.debug("voteQueUsr: " + voteQueUsr); + Long toolContentID = voteContent.getVoteContentId(); + logger.debug("toolContentID: " + toolContentID); - List attempts=voteService.getAttemptsForUser(voteQueUsr.getUid()); - logger.debug("attempts: " + attempts); - - Map mapQuestionsContent= new TreeMap(new VoteComparator()); - Iterator listIterator=attempts.iterator(); - int order=0; - while (listIterator.hasNext()) - { - VoteUsrAttempt attempt=(VoteUsrAttempt)listIterator.next(); - logger.debug("attempt: " + attempt); - VoteQueContent voteQueContent=attempt.getVoteQueContent(); - logger.debug("voteQueContent: " + voteQueContent); - order++; - if (voteQueContent != null) - { - mapQuestionsContent.put(new Integer(order).toString(),voteQueContent.getQuestion()); - } - } - request.setAttribute(MAP_GENERAL_CHECKED_OPTIONS_CONTENT, mapQuestionsContent); - } - else - { - logger.debug("this is not a revisiting user: " + revisitingUser); - } - - voteLearningForm.resetCommands(); - - logger.debug("final voteGeneralLearnerFlowDTO: " + voteGeneralLearnerFlowDTO); - request.setAttribute(VOTE_GENERAL_LEARNER_FLOW_DTO,voteGeneralLearnerFlowDTO); - - logger.debug("fwd'ing to : " + VIEW_ANSWERS); - return (mapping.findForward(VIEW_ANSWERS)); + setContentInUse(request, voteService, toolContentID); + + Long toolSessionUid = voteSession.getUid(); + logger.debug("toolSessionUid: " + toolSessionUid); + + VoteQueUsr existingVoteQueUsr = voteService.getVoteUserBySession(new Long(userID), voteSession.getUid()); + logger.debug("existingVoteQueUsr: " + existingVoteQueUsr); + + existingVoteQueUsr.setFinalScreenRequested(true); + voteService.updateVoteUser(existingVoteQueUsr); + logger.debug("final screen requested by: " + existingVoteQueUsr); + + Set userAttempts = voteService.getAttemptsForUserAndSession(existingVoteQueUsr.getUid(), toolSessionUid); + logger.debug("userAttempts: " + userAttempts); + request.setAttribute(LIST_GENERAL_CHECKED_OPTIONS_CONTENT, userAttempts); + + request.setAttribute(LIST_GENERAL_CHECKED_OPTIONS_CONTENT, userAttempts); + + logger.debug("voteSession uid:" + voteSession.getUid()); + logger.debug("calling prepareChartData:" + voteContent.getVoteContentId() + " " + voteSession.getUid()); + + VoteGeneralMonitoringDTO voteGeneralMonitoringDTO = new VoteGeneralMonitoringDTO(); + MonitoringUtil.prepareChartData(request, voteService, null, voteContent.getVoteContentId().toString(), + voteSession.getUid().toString(), voteGeneralLearnerFlowDTO, voteGeneralMonitoringDTO, + getMessageService()); + logger.debug("end of prepareChartData:" + voteContent.getVoteContentId() + " " + voteSession.getUid()); + + voteGeneralLearnerFlowDTO.setReflection(new Boolean(voteContent.isReflect()).toString()); + String reflectionSubject = VoteUtils.replaceNewLines(voteContent.getReflectionSubject()); + voteGeneralLearnerFlowDTO.setReflectionSubject(reflectionSubject); + + voteLearningForm.resetCommands(); + + logger.debug("view-only voteGeneralLearnerFlowDTO: " + voteGeneralLearnerFlowDTO); + request.setAttribute(VOTE_GENERAL_LEARNER_FLOW_DTO, voteGeneralLearnerFlowDTO); + + logger.debug("fwding to ALL_NOMINATIONS: " + ALL_NOMINATIONS); + return (mapping.findForward(ALL_NOMINATIONS)); } - - - public ActionForward redoQuestionsOk(ActionMapping mapping, - ActionForm form, - HttpServletRequest request, - HttpServletResponse response) throws IOException, - ServletException - { - VoteUtils.cleanUpUserExceptions(request); - logger.debug("dispatching redoQuestionsOk..."); - IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext()); - logger.debug("retrieving voteService from session: " + voteService); + public ActionForward viewAnswers(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException { + VoteUtils.cleanUpUserExceptions(request); + logger.debug("dispatching viewAnswers..."); - VoteLearningForm voteLearningForm = (VoteLearningForm) form; - VoteGeneralLearnerFlowDTO voteGeneralLearnerFlowDTO= new VoteGeneralLearnerFlowDTO(); + VoteLearningForm voteLearningForm = (VoteLearningForm) form; + VoteGeneralLearnerFlowDTO voteGeneralLearnerFlowDTO = new VoteGeneralLearnerFlowDTO(); - repopulateRequestParameters(request,voteLearningForm); - - String toolSessionID=request.getParameter(TOOL_SESSION_ID); - logger.debug("toolSessionID: " + toolSessionID); - voteLearningForm.setToolSessionID(toolSessionID); - - String userID=request.getParameter(USER_ID); - logger.debug("userID: " + userID); - voteLearningForm.setUserID(userID); - - String revisitingUser=request.getParameter(REVISITING_USER); - logger.debug("revisitingUser: " + revisitingUser); - voteLearningForm.setRevisitingUser(revisitingUser); + voteLearningForm.setNominationsSubmited(new Boolean(false).toString()); + voteLearningForm.setMaxNominationCountReached(new Boolean(false).toString()); - - voteLearningForm.setNominationsSubmited(new Boolean(false).toString()); - voteLearningForm.setMaxNominationCountReached(new Boolean(false).toString()); - - voteGeneralLearnerFlowDTO.setNominationsSubmited(new Boolean(false).toString()); - voteGeneralLearnerFlowDTO.setMaxNominationCountReached(new Boolean(false).toString()); + voteGeneralLearnerFlowDTO.setNominationsSubmited(new Boolean(false).toString()); + voteGeneralLearnerFlowDTO.setMaxNominationCountReached(new Boolean(false).toString()); - - VoteSession voteSession=voteService.retrieveVoteSession(new Long(toolSessionID)); - logger.debug("retrieving voteSession: " + voteSession); - - VoteContent voteContent=voteSession.getVoteContent(); - logger.debug("retrieving voteContent: " + voteContent); - - voteGeneralLearnerFlowDTO.setActivityTitle(voteContent.getTitle()); - voteGeneralLearnerFlowDTO.setActivityInstructions(voteContent.getInstructions()); + IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext()); + logger.debug("retrieving voteService from session: " + voteService); - Long toolContentID=voteContent.getVoteContentId(); - logger.debug("toolContentID: " + toolContentID); - - setContentInUse(request, voteService, toolContentID); - logger.debug("requested redoQuestionsOk, user is sure to redo the questions."); + repopulateRequestParameters(request, voteLearningForm); - voteGeneralLearnerFlowDTO.setReflection(new Boolean(voteContent.isReflect()).toString()); - String reflectionSubject=VoteUtils.replaceNewLines(voteContent.getReflectionSubject()); - voteGeneralLearnerFlowDTO.setReflectionSubject(reflectionSubject); - - voteLearningForm.resetCommands(); + String toolSessionID = request.getParameter(TOOL_SESSION_ID); + logger.debug("toolSessionID: " + toolSessionID); + voteLearningForm.setToolSessionID(toolSessionID); - logger.debug("final voteGeneralLearnerFlowDTO: " + voteGeneralLearnerFlowDTO); - request.setAttribute(VOTE_GENERAL_LEARNER_FLOW_DTO,voteGeneralLearnerFlowDTO); - return redoQuestions(mapping, form, request, response); - } + String userID = request.getParameter(USER_ID); + logger.debug("userID: " + userID); + voteLearningForm.setUserID(userID); - public ActionForward learnerFinished(ActionMapping mapping, - ActionForm form, - HttpServletRequest request, - HttpServletResponse response) throws IOException, - ServletException - { - logger.debug("dispatching learnerFinished"); - logger.debug("requested learner finished, the learner should be directed to next activity."); + String revisitingUser = request.getParameter(REVISITING_USER); + logger.debug("revisitingUser: " + revisitingUser); + voteLearningForm.setRevisitingUser(revisitingUser); - VoteGeneralLearnerFlowDTO voteGeneralLearnerFlowDTO= new VoteGeneralLearnerFlowDTO(); - VoteLearningForm voteLearningForm = (VoteLearningForm) form; - - voteLearningForm.setNominationsSubmited(new Boolean(false).toString()); - voteLearningForm.setMaxNominationCountReached(new Boolean(false).toString()); - - voteGeneralLearnerFlowDTO.setNominationsSubmited(new Boolean(false).toString()); - voteGeneralLearnerFlowDTO.setMaxNominationCountReached(new Boolean(false).toString()); + VoteSession voteSession = voteService.retrieveVoteSession(new Long(toolSessionID)); + logger.debug("retrieving voteSession: " + voteSession); - IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext()); - logger.debug("retrieving voteService from session: " + voteService); + VoteContent voteContent = voteSession.getVoteContent(); + logger.debug("retrieving voteContent: " + voteContent); - - repopulateRequestParameters(request,voteLearningForm); - - String toolSessionID=request.getParameter(TOOL_SESSION_ID); - logger.debug("toolSessionID: " + toolSessionID); - voteLearningForm.setToolSessionID(toolSessionID); - - VoteSession voteSession=voteService.retrieveVoteSession(new Long(toolSessionID)); - logger.debug("retrieving voteSession: " + voteSession); - - String userID=request.getParameter(USER_ID); - logger.debug("userID: " + userID); - voteLearningForm.setUserID(userID); - - VoteQueUsr voteQueUsr=voteService.getVoteUserBySession(new Long(userID), voteSession.getUid()); - logger.debug("voteQueUsr:" + voteQueUsr); - - - /* it is possible that voteQueUsr can be null if the content is set as runoffline and reflection is on*/ - if (voteQueUsr == null) - { - logger.debug("attempt creating user record since it must exist for the runOffline + reflection screens"); - HttpSession ss = SessionManager.getSession(); + voteGeneralLearnerFlowDTO.setActivityTitle(voteContent.getTitle()); + voteGeneralLearnerFlowDTO.setActivityInstructions(voteContent.getInstructions()); - UserDTO toolUser = (UserDTO) ss.getAttribute(AttributeNames.USER); - logger.debug("retrieving toolUser: " + toolUser); - logger.debug("retrieving toolUser userId: " + toolUser.getUserID()); - logger.debug("retrieving toolUser username: " + toolUser.getLogin()); + Long toolContentID = voteContent.getVoteContentId(); + logger.debug("toolContentID: " + toolContentID); - String userName=toolUser.getLogin(); - String fullName= toolUser.getFirstName() + " " + toolUser.getLastName(); - logger.debug("retrieving toolUser fullname: " + fullName); - - Long userId=new Long(toolUser.getUserID().longValue()); - logger.debug("retrieving toolUser fullname: " + fullName); - - voteQueUsr= new VoteQueUsr(new Long(userID), - userName, - fullName, - voteSession, - new TreeSet()); - voteService.createVoteQueUsr(voteQueUsr); - logger.debug("createVoteQueUsr - voteQueUsr: " + voteQueUsr); - logger.debug("session uid: " + voteSession.getUid()); - } + setContentInUse(request, voteService, toolContentID); - - voteQueUsr.setResponseFinalised(true); - if ( ! voteSession.getVoteContent().isShowResults() ) { - // if not isShowResults then we will have skipped the final screen. - voteQueUsr.setFinalScreenRequested(true); - } - voteService.updateVoteUser(voteQueUsr); - logger.debug("user's response is finalised:" + voteQueUsr); - - String revisitingUser=request.getParameter(REVISITING_USER); - logger.debug("revisitingUser: " + revisitingUser); - voteLearningForm.setRevisitingUser(revisitingUser); - - - VoteContent voteContent=voteSession.getVoteContent(); - logger.debug("retrieving voteContent: " + voteContent); - - voteGeneralLearnerFlowDTO.setActivityTitle(voteContent.getTitle()); - voteGeneralLearnerFlowDTO.setActivityInstructions(voteContent.getInstructions()); + if (revisitingUser.equals("true")) { + logger.debug("this is a revisiting user, get the nominations from the db: " + revisitingUser); + logger.debug("toolContentID: " + toolContentID); - logger.debug("attempting to leave/complete session with toolSessionID:" + toolSessionID + " and userID:"+userID); - - voteGeneralLearnerFlowDTO.setReflection(new Boolean(voteContent.isReflect()).toString()); - String reflectionSubject=VoteUtils.replaceNewLines(voteContent.getReflectionSubject()); - voteGeneralLearnerFlowDTO.setReflectionSubject(reflectionSubject); - - logger.debug("final voteGeneralLearnerFlowDTO: " + voteGeneralLearnerFlowDTO); - request.setAttribute(VOTE_GENERAL_LEARNER_FLOW_DTO,voteGeneralLearnerFlowDTO); + VoteQueUsr voteQueUsr = LearningUtil.getUser(request, voteService); + logger.debug("voteQueUsr: " + voteQueUsr); - - VoteUtils.cleanUpSessionAbsolute(request); - - String nextUrl=null; - try - { - nextUrl=voteService.leaveToolSession(new Long(toolSessionID), new Long(userID)); - logger.debug("nextUrl: "+ nextUrl); + List attempts = voteService.getAttemptsForUser(voteQueUsr.getUid()); + logger.debug("attempts: " + attempts); + + Map mapQuestionsContent = new TreeMap(new VoteComparator()); + Iterator listIterator = attempts.iterator(); + int order = 0; + while (listIterator.hasNext()) { + VoteUsrAttempt attempt = (VoteUsrAttempt) listIterator.next(); + logger.debug("attempt: " + attempt); + VoteQueContent voteQueContent = attempt.getVoteQueContent(); + logger.debug("voteQueContent: " + voteQueContent); + order++; + if (voteQueContent != null) { + mapQuestionsContent.put(new Integer(order).toString(), voteQueContent.getQuestion()); } - catch (DataMissingException e) - { - logger.debug("failure getting nextUrl: "+ e); - voteLearningForm.resetCommands(); - //throw new ServletException(e); - return (mapping.findForward(LEARNING_STARTER)); - } - catch (ToolException e) - { - logger.debug("failure getting nextUrl: "+ e); - voteLearningForm.resetCommands(); - //throw new ServletException(e); - return (mapping.findForward(LEARNING_STARTER)); - } - catch (Exception e) - { - logger.debug("unknown exception getting nextUrl: "+ e); - voteLearningForm.resetCommands(); - //throw new ServletException(e); - return (mapping.findForward(LEARNING_STARTER)); - } + } + request.setAttribute(MAP_GENERAL_CHECKED_OPTIONS_CONTENT, mapQuestionsContent); + } else { + logger.debug("this is not a revisiting user: " + revisitingUser); + } - logger.debug("success getting nextUrl: "+ nextUrl); - voteLearningForm.resetCommands(); - - /* pay attention here*/ - logger.debug("redirecting to the nextUrl: "+ nextUrl); - response.sendRedirect(nextUrl); - - return null; + voteLearningForm.resetCommands(); + logger.debug("final voteGeneralLearnerFlowDTO: " + voteGeneralLearnerFlowDTO); + request.setAttribute(VOTE_GENERAL_LEARNER_FLOW_DTO, voteGeneralLearnerFlowDTO); + + logger.debug("fwd'ing to : " + VIEW_ANSWERS); + return (mapping.findForward(VIEW_ANSWERS)); } - public ActionForward continueOptionsCombined(ActionMapping mapping, - ActionForm form, - HttpServletRequest request, - HttpServletResponse response) throws IOException, - ServletException - { - VoteUtils.cleanUpUserExceptions(request); - logger.debug("dispatching continueOptionsCombined..."); - - VoteGeneralLearnerFlowDTO voteGeneralLearnerFlowDTO= new VoteGeneralLearnerFlowDTO(); - VoteLearningForm voteLearningForm = (VoteLearningForm) form; - - IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext()); - logger.debug("retrieving voteService from session: " + voteService); + public ActionForward redoQuestionsOk(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException { + VoteUtils.cleanUpUserExceptions(request); + logger.debug("dispatching redoQuestionsOk..."); - repopulateRequestParameters(request,voteLearningForm); - - String toolSessionID=request.getParameter(TOOL_SESSION_ID); - logger.debug("toolSessionID: " + toolSessionID); - voteLearningForm.setToolSessionID(toolSessionID); - - String userID=request.getParameter(USER_ID); - logger.debug("userID: " + userID); - voteLearningForm.setUserID(userID); - - String maxNominationCount=request.getParameter(MAX_NOMINATION_COUNT); - logger.debug("maxNominationCount: " + maxNominationCount); - voteLearningForm.setMaxNominationCount(maxNominationCount); - - String userEntry=request.getParameter(USER_ENTRY); - logger.debug("userEntry: " + userEntry); - voteLearningForm.setUserEntry(userEntry); + IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext()); + logger.debug("retrieving voteService from session: " + voteService); + VoteLearningForm voteLearningForm = (VoteLearningForm) form; + VoteGeneralLearnerFlowDTO voteGeneralLearnerFlowDTO = new VoteGeneralLearnerFlowDTO(); - VoteSession voteSession=voteService.retrieveVoteSession(new Long(toolSessionID)); - logger.debug("retrieving voteSession: " + voteSession); + repopulateRequestParameters(request, voteLearningForm); - voteLearningForm.setNominationsSubmited(new Boolean(false).toString()); - voteLearningForm.setMaxNominationCountReached(new Boolean(false).toString()); + String toolSessionID = request.getParameter(TOOL_SESSION_ID); + logger.debug("toolSessionID: " + toolSessionID); + voteLearningForm.setToolSessionID(toolSessionID); - voteGeneralLearnerFlowDTO.setNominationsSubmited(new Boolean(false).toString()); - voteGeneralLearnerFlowDTO.setMaxNominationCountReached(new Boolean(false).toString()); - + String userID = request.getParameter(USER_ID); + logger.debug("userID: " + userID); + voteLearningForm.setUserID(userID); - Collection voteDisplayOrderIds = voteLearningForm.votesAsCollection(); - logger.debug("Checkbox votes "+voteDisplayOrderIds); - - // check number of votes - int castVoteCount= voteDisplayOrderIds!=null ? voteDisplayOrderIds.size() : 0; - logger.debug("userEntry: " + userEntry); - - if ((userEntry != null) && (userEntry.length() > 0)) - { - logger.debug("userEntry available: " + userEntry); - ++castVoteCount; - } - logger.debug("castVoteCount post user entry count: " + castVoteCount); - logger.debug("maxNominationCount: " + maxNominationCount); - - int intMaxNominationCount=0; - if (maxNominationCount != null) - intMaxNominationCount=new Integer(maxNominationCount).intValue(); - logger.debug("intMaxNominationCount: " + intMaxNominationCount); - logger.debug("intMaxNominationCount versus current voting count: " + intMaxNominationCount + " versus " + castVoteCount ); + String revisitingUser = request.getParameter(REVISITING_USER); + logger.debug("revisitingUser: " + revisitingUser); + voteLearningForm.setRevisitingUser(revisitingUser); - if (castVoteCount > intMaxNominationCount ) - { - voteLearningForm.setMaxNominationCountReached(new Boolean(true).toString()); - voteGeneralLearnerFlowDTO.setMaxNominationCountReached(new Boolean(true).toString()); - persistInRequestError(request, "error.maxNominationCount.reached"); - logger.debug("give warning, max nom count reached..."); - logger.debug("fwd'ing to: " + LOAD_LEARNER); - return (mapping.findForward(LOAD_LEARNER)); - } + voteLearningForm.setNominationsSubmited(new Boolean(false).toString()); + voteLearningForm.setMaxNominationCountReached(new Boolean(false).toString()); - VoteContent voteContent=voteSession.getVoteContent(); - logger.debug("retrieving voteContent: " + voteContent); + voteGeneralLearnerFlowDTO.setNominationsSubmited(new Boolean(false).toString()); + voteGeneralLearnerFlowDTO.setMaxNominationCountReached(new Boolean(false).toString()); - voteGeneralLearnerFlowDTO.setActivityTitle(voteContent.getTitle()); - voteGeneralLearnerFlowDTO.setActivityInstructions(voteContent.getInstructions()); + VoteSession voteSession = voteService.retrieveVoteSession(new Long(toolSessionID)); + logger.debug("retrieving voteSession: " + voteSession); - Long toolContentID=voteContent.getVoteContentId(); - logger.debug("toolContentID: " + toolContentID); + VoteContent voteContent = voteSession.getVoteContent(); + logger.debug("retrieving voteContent: " + voteContent); - Long toolContentUID=voteContent.getUid(); - logger.debug("toolContentUID: " + toolContentUID); - logger.debug("userEntry: " + userEntry); + voteGeneralLearnerFlowDTO.setActivityTitle(voteContent.getTitle()); + voteGeneralLearnerFlowDTO.setActivityInstructions(voteContent.getInstructions()); - setContentInUse(request,voteService, toolContentID); + Long toolContentID = voteContent.getVoteContentId(); + logger.debug("toolContentID: " + toolContentID); - boolean userEntryAvailable=false; - if ((userEntry != null) && (userEntry.length() > 0)) - { - logger.debug("userEntry available: " + userEntry); - userEntryAvailable=true; - } - logger.debug("userEntryAvailable " + userEntryAvailable); + setContentInUse(request, voteService, toolContentID); + logger.debug("requested redoQuestionsOk, user is sure to redo the questions."); - Long toolSessionUid=voteSession.getUid(); - logger.debug("toolSessionUid: " + toolSessionUid); + voteGeneralLearnerFlowDTO.setReflection(new Boolean(voteContent.isReflect()).toString()); + String reflectionSubject = VoteUtils.replaceNewLines(voteContent.getReflectionSubject()); + voteGeneralLearnerFlowDTO.setReflectionSubject(reflectionSubject); - - boolean isUserDefined=false; - logger.debug("userID: " + userID); - VoteQueUsr existingVoteQueUsr=voteService.getVoteUserBySession(new Long(userID), voteSession.getUid()); - logger.debug("existingVoteQueUsr: " + existingVoteQueUsr); - - if (existingVoteQueUsr != null) - isUserDefined=true; - - logger.debug("isUserDefined: " + isUserDefined); - - - VoteQueUsr voteQueUsr=null; - if (isUserDefined == false) - { - voteQueUsr=LearningUtil.createUser(request, voteService, new Long(toolSessionID)); - logger.debug("created user in the db"); - logger.debug("new create"); - } - else - { - voteQueUsr=existingVoteQueUsr; - logger.debug("assign"); - } - - logger.debug("voteQueUsr: " + voteQueUsr); - logger.debug("voteQueUsr is : " + voteQueUsr); - - if (existingVoteQueUsr != null) - { - logger.debug("attempt removing attempts for user id and session id:" + existingVoteQueUsr.getUid() + " " + voteSession.getUid() ); - voteService.removeAttemptsForUserandSession(existingVoteQueUsr.getUid(), voteSession.getUid()); - logger.debug("votes deleted for user: " + voteQueUsr.getUid()); - } - - /* to mimize changes to working code, convert the String[] array to the mapGeneralCheckedOptionsContent structure */ - Map mapGeneralCheckedOptionsContent = LearningUtil.buildQuestionContentMap(request, voteService, voteContent, voteDisplayOrderIds); - logger.debug("mapGeneralCheckedOptionsContent size: " + mapGeneralCheckedOptionsContent.size()); - - if (mapGeneralCheckedOptionsContent.size() > 0) - { - LearningUtil.createAttempt(request, voteService, voteQueUsr, mapGeneralCheckedOptionsContent, - userEntry, false, voteSession, toolContentUID); - } - - - if ((mapGeneralCheckedOptionsContent.size() == 0 && (userEntryAvailable == true))) - { - logger.debug("mapGeneralCheckedOptionsContent size is 0"); - Map mapLeanerCheckedOptionsContent= new TreeMap(new VoteComparator()); - - logger.debug("after mapsize check mapLeanerCheckedOptionsContent " + mapLeanerCheckedOptionsContent); - if (userEntry.length() > 0) - { - logger.debug("creating entry for: " + userEntry); - LearningUtil.createAttempt(request, voteService, voteQueUsr, mapLeanerCheckedOptionsContent, userEntry, - true, voteSession, toolContentUID); - } - } - - if ((mapGeneralCheckedOptionsContent.size() > 0) && (userEntryAvailable == true)) - { - logger.debug("mapGeneralCheckedOptionsContent size is > 0" + userEntry); - Map mapLeanerCheckedOptionsContent= new TreeMap(new VoteComparator()); - - logger.debug("after mapsize check mapLeanerCheckedOptionsContent " + mapLeanerCheckedOptionsContent); - if (userEntry.length() > 0) - { - logger.debug("creating entry for: " + userEntry); - LearningUtil.createAttempt(request, voteService, voteQueUsr, mapLeanerCheckedOptionsContent, userEntry, - false, voteSession, toolContentUID); - } - } - - - logger.debug("created user attempt in the db"); - - /* put the map in the request ready for the next screen */ - request.setAttribute(MAP_GENERAL_CHECKED_OPTIONS_CONTENT, mapGeneralCheckedOptionsContent); - logger.debug("final mapGeneralCheckedOptionsContent: " + mapGeneralCheckedOptionsContent); - voteLearningForm.setMapGeneralCheckedOptionsContent(mapGeneralCheckedOptionsContent); - voteGeneralLearnerFlowDTO.setMapGeneralCheckedOptionsContent(mapGeneralCheckedOptionsContent); - - voteLearningForm.setNominationsSubmited(new Boolean(true).toString()); - voteGeneralLearnerFlowDTO.setNominationsSubmited(new Boolean(true).toString()); - - VoteGeneralMonitoringDTO voteGeneralMonitoringDTO=new VoteGeneralMonitoringDTO(); - logger.debug("calling prepareChartData: " + toolContentID); - MonitoringUtil.prepareChartData(request, voteService, null, toolContentID.toString(), toolSessionUid.toString(), - voteGeneralLearnerFlowDTO, voteGeneralMonitoringDTO, getMessageService()); - - voteGeneralLearnerFlowDTO.setReflection(new Boolean(voteContent.isReflect()).toString()); - voteGeneralLearnerFlowDTO.setReflectionSubject(voteContent.getReflectionSubject()); - - logger.debug("fwding to INDIVIDUAL_REPORT: " + INDIVIDUAL_REPORT); - voteLearningForm.resetCommands(); - - logger.debug("final voteGeneralLearnerFlowDTO: " + voteGeneralLearnerFlowDTO); - request.setAttribute(VOTE_GENERAL_LEARNER_FLOW_DTO,voteGeneralLearnerFlowDTO); + voteLearningForm.resetCommands(); - return (mapping.findForward(INDIVIDUAL_REPORT)); + logger.debug("final voteGeneralLearnerFlowDTO: " + voteGeneralLearnerFlowDTO); + request.setAttribute(VOTE_GENERAL_LEARNER_FLOW_DTO, voteGeneralLearnerFlowDTO); + return redoQuestions(mapping, form, request, response); } - public ActionForward redoQuestions(ActionMapping mapping, - ActionForm form, - HttpServletRequest request, - HttpServletResponse response) throws IOException, - ServletException - { - logger.debug("dispatching redoQuestions..."); - VoteUtils.cleanUpUserExceptions(request); + public ActionForward learnerFinished(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException { + logger.debug("dispatching learnerFinished"); + logger.debug("requested learner finished, the learner should be directed to next activity."); - VoteGeneralLearnerFlowDTO voteGeneralLearnerFlowDTO= new VoteGeneralLearnerFlowDTO(); - VoteLearningForm voteLearningForm = (VoteLearningForm) form; - - IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext()); - logger.debug("retrieving voteService from session: " + voteService); + VoteGeneralLearnerFlowDTO voteGeneralLearnerFlowDTO = new VoteGeneralLearnerFlowDTO(); + VoteLearningForm voteLearningForm = (VoteLearningForm) form; - repopulateRequestParameters(request, voteLearningForm); - - String toolSessionID=request.getParameter(TOOL_SESSION_ID); - logger.debug("toolSessionID: " + toolSessionID); - voteLearningForm.setToolSessionID(toolSessionID); - - String userID=request.getParameter(USER_ID); - logger.debug("userID: " + userID); - voteLearningForm.setUserID(userID); - - String revisitingUser=request.getParameter(REVISITING_USER); - logger.debug("revisitingUser: " + revisitingUser); - voteLearningForm.setRevisitingUser(revisitingUser); + voteLearningForm.setNominationsSubmited(new Boolean(false).toString()); + voteLearningForm.setMaxNominationCountReached(new Boolean(false).toString()); - - VoteSession voteSession=voteService.retrieveVoteSession(new Long(toolSessionID)); - logger.debug("retrieving voteSession: " + voteSession); - - VoteContent voteContent=voteSession.getVoteContent(); - logger.debug("retrieving voteContent: " + voteContent); + voteGeneralLearnerFlowDTO.setNominationsSubmited(new Boolean(false).toString()); + voteGeneralLearnerFlowDTO.setMaxNominationCountReached(new Boolean(false).toString()); - voteGeneralLearnerFlowDTO.setActivityTitle(voteContent.getTitle()); - voteGeneralLearnerFlowDTO.setActivityInstructions(voteContent.getInstructions()); + IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext()); + logger.debug("retrieving voteService from session: " + voteService); - voteLearningForm.setNominationsSubmited(new Boolean(false).toString()); - voteLearningForm.setMaxNominationCountReached(new Boolean(false).toString()); - - voteGeneralLearnerFlowDTO.setNominationsSubmited(new Boolean(false).toString()); - voteGeneralLearnerFlowDTO.setMaxNominationCountReached(new Boolean(false).toString()); + repopulateRequestParameters(request, voteLearningForm); - Long toolContentID=voteContent.getVoteContentId(); - logger.debug("toolContentID:" + toolContentID); - - Map mapQuestionsContent= new TreeMap(new VoteComparator()); - mapQuestionsContent=LearningUtil.buildQuestionContentMap(request, voteService, voteContent,null); - logger.debug("mapQuestionsContent: " + mapQuestionsContent); - - request.setAttribute(MAP_QUESTION_CONTENT_LEARNER, mapQuestionsContent); - logger.debug("MAP_QUESTION_CONTENT_LEARNER: " + request.getAttribute(MAP_QUESTION_CONTENT_LEARNER)); - logger.debug("voteContent has : " + mapQuestionsContent.size() + " entries."); - - Map mapGeneralCheckedOptionsContent= new TreeMap(new VoteComparator()); - request.setAttribute(MAP_GENERAL_CHECKED_OPTIONS_CONTENT, mapGeneralCheckedOptionsContent); - - voteLearningForm.setUserEntry(""); - - voteGeneralLearnerFlowDTO.setReflection(new Boolean(voteContent.isReflect()).toString()); - voteGeneralLearnerFlowDTO.setReflectionSubject(voteContent.getReflectionSubject()); - - logger.debug("fwd'ing to LOAD_LEARNER : " + LOAD_LEARNER); + String toolSessionID = request.getParameter(TOOL_SESSION_ID); + logger.debug("toolSessionID: " + toolSessionID); + voteLearningForm.setToolSessionID(toolSessionID); + + VoteSession voteSession = voteService.retrieveVoteSession(new Long(toolSessionID)); + logger.debug("retrieving voteSession: " + voteSession); + + String userID = request.getParameter(USER_ID); + logger.debug("userID: " + userID); + voteLearningForm.setUserID(userID); + + VoteQueUsr voteQueUsr = voteService.getVoteUserBySession(new Long(userID), voteSession.getUid()); + logger.debug("voteQueUsr:" + voteQueUsr); + + /* it is possible that voteQueUsr can be null if the content is set as runoffline and reflection is on*/ + if (voteQueUsr == null) { + logger.debug("attempt creating user record since it must exist for the runOffline + reflection screens"); + HttpSession ss = SessionManager.getSession(); + + UserDTO toolUser = (UserDTO) ss.getAttribute(AttributeNames.USER); + logger.debug("retrieving toolUser: " + toolUser); + logger.debug("retrieving toolUser userId: " + toolUser.getUserID()); + logger.debug("retrieving toolUser username: " + toolUser.getLogin()); + + String userName = toolUser.getLogin(); + String fullName = toolUser.getFirstName() + " " + toolUser.getLastName(); + logger.debug("retrieving toolUser fullname: " + fullName); + + Long userId = new Long(toolUser.getUserID().longValue()); + logger.debug("retrieving toolUser fullname: " + fullName); + + voteQueUsr = new VoteQueUsr(new Long(userID), userName, fullName, voteSession, new TreeSet()); + voteService.createVoteQueUsr(voteQueUsr); + logger.debug("createVoteQueUsr - voteQueUsr: " + voteQueUsr); + logger.debug("session uid: " + voteSession.getUid()); + } + + voteQueUsr.setResponseFinalised(true); + if (!voteSession.getVoteContent().isShowResults()) { + // if not isShowResults then we will have skipped the final screen. + voteQueUsr.setFinalScreenRequested(true); + } + voteService.updateVoteUser(voteQueUsr); + logger.debug("user's response is finalised:" + voteQueUsr); + + String revisitingUser = request.getParameter(REVISITING_USER); + logger.debug("revisitingUser: " + revisitingUser); + voteLearningForm.setRevisitingUser(revisitingUser); + + VoteContent voteContent = voteSession.getVoteContent(); + logger.debug("retrieving voteContent: " + voteContent); + + voteGeneralLearnerFlowDTO.setActivityTitle(voteContent.getTitle()); + voteGeneralLearnerFlowDTO.setActivityInstructions(voteContent.getInstructions()); + + logger.debug("attempting to leave/complete session with toolSessionID:" + toolSessionID + " and userID:" + + userID); + + voteGeneralLearnerFlowDTO.setReflection(new Boolean(voteContent.isReflect()).toString()); + String reflectionSubject = VoteUtils.replaceNewLines(voteContent.getReflectionSubject()); + voteGeneralLearnerFlowDTO.setReflectionSubject(reflectionSubject); + + logger.debug("final voteGeneralLearnerFlowDTO: " + voteGeneralLearnerFlowDTO); + request.setAttribute(VOTE_GENERAL_LEARNER_FLOW_DTO, voteGeneralLearnerFlowDTO); + + VoteUtils.cleanUpSessionAbsolute(request); + + String nextUrl = null; + try { + nextUrl = voteService.leaveToolSession(new Long(toolSessionID), new Long(userID)); + logger.debug("nextUrl: " + nextUrl); + } catch (DataMissingException e) { + logger.debug("failure getting nextUrl: " + e); voteLearningForm.resetCommands(); - - logger.debug("final voteGeneralLearnerFlowDTO: " + voteGeneralLearnerFlowDTO); - request.setAttribute(VOTE_GENERAL_LEARNER_FLOW_DTO,voteGeneralLearnerFlowDTO); + //throw new ServletException(e); + return (mapping.findForward(LEARNING_STARTER)); + } catch (ToolException e) { + logger.debug("failure getting nextUrl: " + e); + voteLearningForm.resetCommands(); + //throw new ServletException(e); + return (mapping.findForward(LEARNING_STARTER)); + } catch (Exception e) { + logger.debug("unknown exception getting nextUrl: " + e); + voteLearningForm.resetCommands(); + //throw new ServletException(e); + return (mapping.findForward(LEARNING_STARTER)); + } + logger.debug("success getting nextUrl: " + nextUrl); + voteLearningForm.resetCommands(); + + /* pay attention here*/ + logger.debug("redirecting to the nextUrl: " + nextUrl); + response.sendRedirect(nextUrl); + + return null; + + } + + public ActionForward continueOptionsCombined(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException { + VoteUtils.cleanUpUserExceptions(request); + logger.debug("dispatching continueOptionsCombined..."); + + VoteGeneralLearnerFlowDTO voteGeneralLearnerFlowDTO = new VoteGeneralLearnerFlowDTO(); + VoteLearningForm voteLearningForm = (VoteLearningForm) form; + + IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext()); + logger.debug("retrieving voteService from session: " + voteService); + + repopulateRequestParameters(request, voteLearningForm); + + String toolSessionID = request.getParameter(TOOL_SESSION_ID); + logger.debug("toolSessionID: " + toolSessionID); + voteLearningForm.setToolSessionID(toolSessionID); + + String userID = request.getParameter(USER_ID); + logger.debug("userID: " + userID); + voteLearningForm.setUserID(userID); + + String maxNominationCount = request.getParameter(MAX_NOMINATION_COUNT); + logger.debug("maxNominationCount: " + maxNominationCount); + voteLearningForm.setMaxNominationCount(maxNominationCount); + + String userEntry = request.getParameter(USER_ENTRY); + logger.debug("userEntry: " + userEntry); + voteLearningForm.setUserEntry(userEntry); + + VoteSession voteSession = voteService.retrieveVoteSession(new Long(toolSessionID)); + logger.debug("retrieving voteSession: " + voteSession); + + voteLearningForm.setNominationsSubmited(new Boolean(false).toString()); + voteLearningForm.setMaxNominationCountReached(new Boolean(false).toString()); + + voteGeneralLearnerFlowDTO.setNominationsSubmited(new Boolean(false).toString()); + voteGeneralLearnerFlowDTO.setMaxNominationCountReached(new Boolean(false).toString()); + + Collection voteDisplayOrderIds = voteLearningForm.votesAsCollection(); + logger.debug("Checkbox votes " + voteDisplayOrderIds); + + // check number of votes + int castVoteCount = voteDisplayOrderIds != null ? voteDisplayOrderIds.size() : 0; + logger.debug("userEntry: " + userEntry); + + if ((userEntry != null) && (userEntry.length() > 0)) { + logger.debug("userEntry available: " + userEntry); + ++castVoteCount; + } + logger.debug("castVoteCount post user entry count: " + castVoteCount); + logger.debug("maxNominationCount: " + maxNominationCount); + + int intMaxNominationCount = 0; + if (maxNominationCount != null) + intMaxNominationCount = new Integer(maxNominationCount).intValue(); + logger.debug("intMaxNominationCount: " + intMaxNominationCount); + logger.debug("intMaxNominationCount versus current voting count: " + intMaxNominationCount + " versus " + + castVoteCount); + + if (castVoteCount > intMaxNominationCount) { + voteLearningForm.setMaxNominationCountReached(new Boolean(true).toString()); + voteGeneralLearnerFlowDTO.setMaxNominationCountReached(new Boolean(true).toString()); + persistInRequestError(request, "error.maxNominationCount.reached"); + logger.debug("give warning, max nom count reached..."); + logger.debug("fwd'ing to: " + LOAD_LEARNER); return (mapping.findForward(LOAD_LEARNER)); - } + } - - - protected void setContentInUse(HttpServletRequest request, IVoteService voteService, Long toolContentID) - { - logger.debug("toolContentID:" + toolContentID); - - VoteContent voteContent=voteService.retrieveVote(toolContentID); - logger.debug("voteContent:" + voteContent); - voteContent.setContentInUse(true); - logger.debug("content has been set to inuse"); - voteService.saveVoteContent(voteContent); + VoteContent voteContent = voteSession.getVoteContent(); + logger.debug("retrieving voteContent: " + voteContent); + + voteGeneralLearnerFlowDTO.setActivityTitle(voteContent.getTitle()); + voteGeneralLearnerFlowDTO.setActivityInstructions(voteContent.getInstructions()); + + Long toolContentID = voteContent.getVoteContentId(); + logger.debug("toolContentID: " + toolContentID); + + Long toolContentUID = voteContent.getUid(); + logger.debug("toolContentUID: " + toolContentUID); + logger.debug("userEntry: " + userEntry); + + setContentInUse(request, voteService, toolContentID); + + boolean userEntryAvailable = false; + if ((userEntry != null) && (userEntry.length() > 0)) { + logger.debug("userEntry available: " + userEntry); + userEntryAvailable = true; + } + logger.debug("userEntryAvailable " + userEntryAvailable); + + Long toolSessionUid = voteSession.getUid(); + logger.debug("toolSessionUid: " + toolSessionUid); + + boolean isUserDefined = false; + logger.debug("userID: " + userID); + VoteQueUsr existingVoteQueUsr = voteService.getVoteUserBySession(new Long(userID), voteSession.getUid()); + logger.debug("existingVoteQueUsr: " + existingVoteQueUsr); + + if (existingVoteQueUsr != null) + isUserDefined = true; + + logger.debug("isUserDefined: " + isUserDefined); + + VoteQueUsr voteQueUsr = null; + if (isUserDefined == false) { + voteQueUsr = LearningUtil.createUser(request, voteService, new Long(toolSessionID)); + logger.debug("created user in the db"); + logger.debug("new create"); + } else { + voteQueUsr = existingVoteQueUsr; + logger.debug("assign"); + } + + logger.debug("voteQueUsr: " + voteQueUsr); + logger.debug("voteQueUsr is : " + voteQueUsr); + + if (existingVoteQueUsr != null) { + logger.debug("attempt removing attempts for user id and session id:" + existingVoteQueUsr.getUid() + " " + + voteSession.getUid()); + voteService.removeAttemptsForUserandSession(existingVoteQueUsr.getUid(), voteSession.getUid()); + logger.debug("votes deleted for user: " + voteQueUsr.getUid()); + } + + /* to mimize changes to working code, convert the String[] array to the mapGeneralCheckedOptionsContent structure */ + Map mapGeneralCheckedOptionsContent = LearningUtil.buildQuestionContentMap(request, voteService, voteContent, + voteDisplayOrderIds); + logger.debug("mapGeneralCheckedOptionsContent size: " + mapGeneralCheckedOptionsContent.size()); + + if (mapGeneralCheckedOptionsContent.size() > 0) { + LearningUtil.createAttempt(request, voteService, voteQueUsr, mapGeneralCheckedOptionsContent, userEntry, + false, voteSession, toolContentUID); + } + + if ((mapGeneralCheckedOptionsContent.size() == 0 && (userEntryAvailable == true))) { + logger.debug("mapGeneralCheckedOptionsContent size is 0"); + Map mapLeanerCheckedOptionsContent = new TreeMap(new VoteComparator()); + + logger.debug("after mapsize check mapLeanerCheckedOptionsContent " + mapLeanerCheckedOptionsContent); + if (userEntry.length() > 0) { + logger.debug("creating entry for: " + userEntry); + LearningUtil.createAttempt(request, voteService, voteQueUsr, mapLeanerCheckedOptionsContent, userEntry, + true, voteSession, toolContentUID); + } + } + + if ((mapGeneralCheckedOptionsContent.size() > 0) && (userEntryAvailable == true)) { + logger.debug("mapGeneralCheckedOptionsContent size is > 0" + userEntry); + Map mapLeanerCheckedOptionsContent = new TreeMap(new VoteComparator()); + + logger.debug("after mapsize check mapLeanerCheckedOptionsContent " + mapLeanerCheckedOptionsContent); + if (userEntry.length() > 0) { + logger.debug("creating entry for: " + userEntry); + LearningUtil.createAttempt(request, voteService, voteQueUsr, mapLeanerCheckedOptionsContent, userEntry, + false, voteSession, toolContentUID); + } + } + + logger.debug("created user attempt in the db"); + + /* put the map in the request ready for the next screen */ + request.setAttribute(MAP_GENERAL_CHECKED_OPTIONS_CONTENT, mapGeneralCheckedOptionsContent); + logger.debug("final mapGeneralCheckedOptionsContent: " + mapGeneralCheckedOptionsContent); + voteLearningForm.setMapGeneralCheckedOptionsContent(mapGeneralCheckedOptionsContent); + voteGeneralLearnerFlowDTO.setMapGeneralCheckedOptionsContent(mapGeneralCheckedOptionsContent); + + voteLearningForm.setNominationsSubmited(new Boolean(true).toString()); + voteGeneralLearnerFlowDTO.setNominationsSubmited(new Boolean(true).toString()); + + VoteGeneralMonitoringDTO voteGeneralMonitoringDTO = new VoteGeneralMonitoringDTO(); + logger.debug("calling prepareChartData: " + toolContentID); + MonitoringUtil.prepareChartData(request, voteService, null, toolContentID.toString(), + toolSessionUid.toString(), voteGeneralLearnerFlowDTO, voteGeneralMonitoringDTO, getMessageService()); + + voteGeneralLearnerFlowDTO.setReflection(new Boolean(voteContent.isReflect()).toString()); + voteGeneralLearnerFlowDTO.setReflectionSubject(voteContent.getReflectionSubject()); + + logger.debug("fwding to INDIVIDUAL_REPORT: " + INDIVIDUAL_REPORT); + voteLearningForm.resetCommands(); + + logger.debug("final voteGeneralLearnerFlowDTO: " + voteGeneralLearnerFlowDTO); + request.setAttribute(VOTE_GENERAL_LEARNER_FLOW_DTO, voteGeneralLearnerFlowDTO); + + return (mapping.findForward(INDIVIDUAL_REPORT)); } + public ActionForward redoQuestions(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException { + logger.debug("dispatching redoQuestions..."); + VoteUtils.cleanUpUserExceptions(request); - + VoteGeneralLearnerFlowDTO voteGeneralLearnerFlowDTO = new VoteGeneralLearnerFlowDTO(); + VoteLearningForm voteLearningForm = (VoteLearningForm) form; + + IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext()); + logger.debug("retrieving voteService from session: " + voteService); + + repopulateRequestParameters(request, voteLearningForm); + + String toolSessionID = request.getParameter(TOOL_SESSION_ID); + logger.debug("toolSessionID: " + toolSessionID); + voteLearningForm.setToolSessionID(toolSessionID); + + String userID = request.getParameter(USER_ID); + logger.debug("userID: " + userID); + voteLearningForm.setUserID(userID); + + String revisitingUser = request.getParameter(REVISITING_USER); + logger.debug("revisitingUser: " + revisitingUser); + voteLearningForm.setRevisitingUser(revisitingUser); + + VoteSession voteSession = voteService.retrieveVoteSession(new Long(toolSessionID)); + logger.debug("retrieving voteSession: " + voteSession); + + VoteContent voteContent = voteSession.getVoteContent(); + logger.debug("retrieving voteContent: " + voteContent); + + voteGeneralLearnerFlowDTO.setActivityTitle(voteContent.getTitle()); + voteGeneralLearnerFlowDTO.setActivityInstructions(voteContent.getInstructions()); + + voteLearningForm.setNominationsSubmited(new Boolean(false).toString()); + voteLearningForm.setMaxNominationCountReached(new Boolean(false).toString()); + + voteGeneralLearnerFlowDTO.setNominationsSubmited(new Boolean(false).toString()); + voteGeneralLearnerFlowDTO.setMaxNominationCountReached(new Boolean(false).toString()); + + Long toolContentID = voteContent.getVoteContentId(); + logger.debug("toolContentID:" + toolContentID); + + Map mapQuestionsContent = new TreeMap(new VoteComparator()); + mapQuestionsContent = LearningUtil.buildQuestionContentMap(request, voteService, voteContent, null); + logger.debug("mapQuestionsContent: " + mapQuestionsContent); + + request.setAttribute(MAP_QUESTION_CONTENT_LEARNER, mapQuestionsContent); + logger.debug("MAP_QUESTION_CONTENT_LEARNER: " + request.getAttribute(MAP_QUESTION_CONTENT_LEARNER)); + logger.debug("voteContent has : " + mapQuestionsContent.size() + " entries."); + + Map mapGeneralCheckedOptionsContent = new TreeMap(new VoteComparator()); + request.setAttribute(MAP_GENERAL_CHECKED_OPTIONS_CONTENT, mapGeneralCheckedOptionsContent); + + voteLearningForm.setUserEntry(""); + + voteGeneralLearnerFlowDTO.setReflection(new Boolean(voteContent.isReflect()).toString()); + voteGeneralLearnerFlowDTO.setReflectionSubject(voteContent.getReflectionSubject()); + + logger.debug("fwd'ing to LOAD_LEARNER : " + LOAD_LEARNER); + voteLearningForm.resetCommands(); + + logger.debug("final voteGeneralLearnerFlowDTO: " + voteGeneralLearnerFlowDTO); + request.setAttribute(VOTE_GENERAL_LEARNER_FLOW_DTO, voteGeneralLearnerFlowDTO); + + return (mapping.findForward(LOAD_LEARNER)); + } + + protected void setContentInUse(HttpServletRequest request, IVoteService voteService, Long toolContentID) { + logger.debug("toolContentID:" + toolContentID); + + VoteContent voteContent = voteService.retrieveVote(toolContentID); + logger.debug("voteContent:" + voteContent); + voteContent.setContentInUse(true); + logger.debug("content has been set to inuse"); + voteService.saveVoteContent(voteContent); + } + /** * persists error messages to request scope + * * @param request * @param message */ - public void persistInRequestError(HttpServletRequest request, String message) - { - ActionMessages errors= new ActionMessages(); - errors.add(Globals.ERROR_KEY, new ActionMessage(message)); - logger.debug("add " + message +" to ActionMessages:"); - saveErrors(request,errors); + public void persistInRequestError(HttpServletRequest request, String message) { + ActionMessages errors = new ActionMessages(); + errors.add(Globals.ERROR_KEY, new ActionMessage(message)); + logger.debug("add " + message + " to ActionMessages:"); + saveErrors(request, errors); + } + + public ActionForward submitReflection(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException, ToolException { + logger.debug("dispatching submitReflection..."); + VoteLearningForm voteLearningForm = (VoteLearningForm) form; + + repopulateRequestParameters(request, voteLearningForm); + + IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext()); + logger.debug("voteService: " + voteService); + + String toolSessionID = request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); + logger.debug("toolSessionID: " + toolSessionID); + voteLearningForm.setToolSessionID(toolSessionID); + + String userID = request.getParameter("userID"); + logger.debug("userID: " + userID); + voteLearningForm.setUserID(userID); + + String reflectionEntry = request.getParameter(ENTRY_TEXT); + logger.debug("reflectionEntry: " + reflectionEntry); + + VoteSession voteSession = voteService.retrieveVoteSession(new Long(toolSessionID)); + logger.debug("retrieving voteSession: " + voteSession); + + VoteQueUsr voteQueUsr = voteService.getVoteUserBySession(new Long(userID), voteSession.getUid()); + logger.debug("voteQueUsr:" + voteQueUsr); + + /* it is possible that voteQueUsr can be null if the content is set as runoffline and reflection is on*/ + if (voteQueUsr == null) { + logger.debug("attempt creating user record since it must exist for the runOffline + reflection screens"); + HttpSession ss = SessionManager.getSession(); + + UserDTO toolUser = (UserDTO) ss.getAttribute(AttributeNames.USER); + logger.debug("retrieving toolUser: " + toolUser); + logger.debug("retrieving toolUser userId: " + toolUser.getUserID()); + logger.debug("retrieving toolUser username: " + toolUser.getLogin()); + + String userName = toolUser.getLogin(); + String fullName = toolUser.getFirstName() + " " + toolUser.getLastName(); + logger.debug("retrieving toolUser fullname: " + fullName); + + Long userId = new Long(toolUser.getUserID().longValue()); + logger.debug("retrieving toolUser fullname: " + fullName); + + voteQueUsr = new VoteQueUsr(new Long(userID), userName, fullName, voteSession, new TreeSet()); + voteService.createVoteQueUsr(voteQueUsr); + logger.debug("createVoteQueUsr - voteQueUsr: " + voteQueUsr); + logger.debug("session uid: " + voteSession.getUid()); } - - - public ActionForward submitReflection(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) - throws IOException, ServletException, ToolException - { - logger.debug("dispatching submitReflection..."); - VoteLearningForm voteLearningForm = (VoteLearningForm) form; - - repopulateRequestParameters(request,voteLearningForm); - - IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext()); - logger.debug("voteService: " + voteService); + logger.debug("voteQueUsr:" + voteQueUsr); + logger.debug("toolSessionID:" + toolSessionID); + logger.debug("CoreNotebookConstants.NOTEBOOK_TOOL:" + CoreNotebookConstants.NOTEBOOK_TOOL); + logger.debug("MY_SIGNATURE:" + MY_SIGNATURE); + logger.debug("userID:" + userID); + logger.debug("reflectionEntry:" + reflectionEntry); - String toolSessionID=request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); - logger.debug("toolSessionID: " + toolSessionID); - voteLearningForm.setToolSessionID(toolSessionID); + voteService.createNotebookEntry(new Long(toolSessionID), CoreNotebookConstants.NOTEBOOK_TOOL, MY_SIGNATURE, + new Integer(userID), reflectionEntry); - String userID=request.getParameter("userID"); - logger.debug("userID: " + userID); - voteLearningForm.setUserID(userID); - - String reflectionEntry=request.getParameter(ENTRY_TEXT); - logger.debug("reflectionEntry: " + reflectionEntry); + voteLearningForm.resetUserActions(); /*resets all except submitAnswersContent */ + return learnerFinished(mapping, form, request, response); + } - VoteSession voteSession=voteService.retrieveVoteSession(new Long(toolSessionID)); - logger.debug("retrieving voteSession: " + voteSession); - - VoteQueUsr voteQueUsr=voteService.getVoteUserBySession(new Long(userID), voteSession.getUid()); - logger.debug("voteQueUsr:" + voteQueUsr); - - /* it is possible that voteQueUsr can be null if the content is set as runoffline and reflection is on*/ - if (voteQueUsr == null) - { - logger.debug("attempt creating user record since it must exist for the runOffline + reflection screens"); - HttpSession ss = SessionManager.getSession(); + public ActionForward forwardtoReflection(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException, ToolException { + logger.debug("dispatching forwardtoReflection..."); + VoteLearningForm voteLearningForm = (VoteLearningForm) form; + IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext()); + logger.debug("voteService: " + voteService); - UserDTO toolUser = (UserDTO) ss.getAttribute(AttributeNames.USER); - logger.debug("retrieving toolUser: " + toolUser); - logger.debug("retrieving toolUser userId: " + toolUser.getUserID()); - logger.debug("retrieving toolUser username: " + toolUser.getLogin()); + String toolSessionID = request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); + logger.debug("toolSessionID: " + toolSessionID); - String userName=toolUser.getLogin(); - String fullName= toolUser.getFirstName() + " " + toolUser.getLastName(); - logger.debug("retrieving toolUser fullname: " + fullName); - - Long userId=new Long(toolUser.getUserID().longValue()); - logger.debug("retrieving toolUser fullname: " + fullName); - - voteQueUsr= new VoteQueUsr(new Long(userID), - userName, - fullName, - voteSession, - new TreeSet()); - voteService.createVoteQueUsr(voteQueUsr); - logger.debug("createVoteQueUsr - voteQueUsr: " + voteQueUsr); - logger.debug("session uid: " + voteSession.getUid()); - } - - logger.debug("voteQueUsr:" + voteQueUsr); - logger.debug("toolSessionID:" + toolSessionID); - logger.debug("CoreNotebookConstants.NOTEBOOK_TOOL:" + CoreNotebookConstants.NOTEBOOK_TOOL); - logger.debug("MY_SIGNATURE:" + MY_SIGNATURE); - logger.debug("userID:" + userID); - logger.debug("reflectionEntry:" + reflectionEntry); - - voteService.createNotebookEntry(new Long(toolSessionID), CoreNotebookConstants.NOTEBOOK_TOOL, - MY_SIGNATURE, new Integer(userID), reflectionEntry); - - voteLearningForm.resetUserActions(); /*resets all except submitAnswersContent */ - return learnerFinished(mapping, form, request, response); + VoteSession voteSession = voteService.retrieveVoteSession(new Long(toolSessionID)); + logger.debug("retrieving voteSession: " + voteSession); + + VoteContent voteContent = voteSession.getVoteContent(); + logger.debug("using voteContent: " + voteContent); + + VoteGeneralLearnerFlowDTO voteGeneralLearnerFlowDTO = new VoteGeneralLearnerFlowDTO(); + voteGeneralLearnerFlowDTO.setActivityTitle(voteContent.getTitle()); + + String reflectionSubject = voteContent.getReflectionSubject(); + reflectionSubject = VoteUtils.replaceNewLines(reflectionSubject); + + voteGeneralLearnerFlowDTO.setReflectionSubject(reflectionSubject); + + String userID = request.getParameter("userID"); + logger.debug("userID: " + userID); + voteLearningForm.setUserID(userID); + + logger.debug("attempt getting notebookEntry: "); + NotebookEntry notebookEntry = voteService.getEntry(new Long(toolSessionID), + CoreNotebookConstants.NOTEBOOK_TOOL, MY_SIGNATURE, new Integer(userID)); + + logger.debug("notebookEntry: " + notebookEntry); + + if (notebookEntry != null) { + String notebookEntryPresentable = notebookEntry.getEntry(); + logger.debug("notebookEntryPresentable: " + notebookEntryPresentable); + voteGeneralLearnerFlowDTO.setNotebookEntry(notebookEntryPresentable); + voteLearningForm.setEntryText(notebookEntryPresentable); } - - - public ActionForward forwardtoReflection(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) - throws IOException, ServletException, ToolException - { - logger.debug("dispatching forwardtoReflection..."); - VoteLearningForm voteLearningForm = (VoteLearningForm) form; - IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext()); - logger.debug("voteService: " + voteService); - - String toolSessionID=request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); - logger.debug("toolSessionID: " + toolSessionID); - - VoteSession voteSession=voteService.retrieveVoteSession(new Long(toolSessionID)); - logger.debug("retrieving voteSession: " + voteSession); - - VoteContent voteContent=voteSession.getVoteContent(); - logger.debug("using voteContent: " + voteContent); - - VoteGeneralLearnerFlowDTO voteGeneralLearnerFlowDTO= new VoteGeneralLearnerFlowDTO(); - voteGeneralLearnerFlowDTO.setActivityTitle(voteContent.getTitle()); - - String reflectionSubject=voteContent.getReflectionSubject(); - reflectionSubject=VoteUtils.replaceNewLines(reflectionSubject); - - voteGeneralLearnerFlowDTO.setReflectionSubject(reflectionSubject); - - String userID=request.getParameter("userID"); - logger.debug("userID: " + userID); - voteLearningForm.setUserID(userID); - - logger.debug("attempt getting notebookEntry: "); - NotebookEntry notebookEntry = voteService.getEntry(new Long(toolSessionID), - CoreNotebookConstants.NOTEBOOK_TOOL, - MY_SIGNATURE, new Integer(userID)); - - logger.debug("notebookEntry: " + notebookEntry); - - if (notebookEntry != null) { - String notebookEntryPresentable=notebookEntry.getEntry(); - logger.debug("notebookEntryPresentable: " + notebookEntryPresentable); - voteGeneralLearnerFlowDTO.setNotebookEntry(notebookEntryPresentable); - voteLearningForm.setEntryText(notebookEntryPresentable); - } - - - - request.setAttribute(VOTE_GENERAL_LEARNER_FLOW_DTO, voteGeneralLearnerFlowDTO); - - logger.debug("final voteGeneralLearnerFlowDTO: " + voteGeneralLearnerFlowDTO); - voteLearningForm.resetCommands(); - - logger.debug("fwd'ing to: " + NOTEBOOK); - return (mapping.findForward(NOTEBOOK)); - } - - protected void repopulateRequestParameters(HttpServletRequest request, VoteLearningForm voteLearningForm) - { - logger.debug("starting repopulateRequestParameters"); - - String toolSessionID=request.getParameter(TOOL_SESSION_ID); - logger.debug("toolSessionID: " + toolSessionID); - voteLearningForm.setToolSessionID(toolSessionID); - - String userID=request.getParameter(USER_ID); - logger.debug("userID: " + userID); - voteLearningForm.setUserID(userID); - String revisitingUser=request.getParameter(REVISITING_USER); - logger.debug("revisitingUser: " + revisitingUser); - voteLearningForm.setRevisitingUser(revisitingUser); + request.setAttribute(VOTE_GENERAL_LEARNER_FLOW_DTO, voteGeneralLearnerFlowDTO); - String previewOnly=request.getParameter(PREVIEW_ONLY); - logger.debug("previewOnly: " + previewOnly); - voteLearningForm.setPreviewOnly(previewOnly); + logger.debug("final voteGeneralLearnerFlowDTO: " + voteGeneralLearnerFlowDTO); + voteLearningForm.resetCommands(); - String maxNominationCount=request.getParameter(MAX_NOMINATION_COUNT); - logger.debug("maxNominationCount: " + maxNominationCount); - voteLearningForm.setMaxNominationCount(maxNominationCount); + logger.debug("fwd'ing to: " + NOTEBOOK); + return (mapping.findForward(NOTEBOOK)); + } - String allowTextEntry=request.getParameter(ALLOW_TEXT_ENTRY); - logger.debug("allowTextEntry: " + allowTextEntry); - voteLearningForm.setAllowTextEntry(allowTextEntry); - - String showResults=request.getParameter(SHOW_RESULTS); - voteLearningForm.setShowResults(showResults); - - String lockOnFinish=request.getParameter(LOCK_ON_FINISH); - logger.debug("lockOnFinish: " + lockOnFinish); - voteLearningForm.setLockOnFinish(lockOnFinish); + protected void repopulateRequestParameters(HttpServletRequest request, VoteLearningForm voteLearningForm) { + logger.debug("starting repopulateRequestParameters"); - String reportViewOnly=request.getParameter(REPORT_VIEW_ONLY); - logger.debug("reportViewOnly: " + reportViewOnly); - voteLearningForm.setReportViewOnly(reportViewOnly); - - String userEntry=request.getParameter(USER_ENTRY); - logger.debug("userEntry: " + userEntry); - voteLearningForm.setUserEntry(userEntry); + String toolSessionID = request.getParameter(TOOL_SESSION_ID); + logger.debug("toolSessionID: " + toolSessionID); + voteLearningForm.setToolSessionID(toolSessionID); + + String userID = request.getParameter(USER_ID); + logger.debug("userID: " + userID); + voteLearningForm.setUserID(userID); + + String revisitingUser = request.getParameter(REVISITING_USER); + logger.debug("revisitingUser: " + revisitingUser); + voteLearningForm.setRevisitingUser(revisitingUser); + + String previewOnly = request.getParameter(PREVIEW_ONLY); + logger.debug("previewOnly: " + previewOnly); + voteLearningForm.setPreviewOnly(previewOnly); + + String maxNominationCount = request.getParameter(MAX_NOMINATION_COUNT); + logger.debug("maxNominationCount: " + maxNominationCount); + voteLearningForm.setMaxNominationCount(maxNominationCount); + + String allowTextEntry = request.getParameter(ALLOW_TEXT_ENTRY); + logger.debug("allowTextEntry: " + allowTextEntry); + voteLearningForm.setAllowTextEntry(allowTextEntry); + + String showResults = request.getParameter(SHOW_RESULTS); + voteLearningForm.setShowResults(showResults); + + String lockOnFinish = request.getParameter(LOCK_ON_FINISH); + logger.debug("lockOnFinish: " + lockOnFinish); + voteLearningForm.setLockOnFinish(lockOnFinish); + + String reportViewOnly = request.getParameter(REPORT_VIEW_ONLY); + logger.debug("reportViewOnly: " + reportViewOnly); + voteLearningForm.setReportViewOnly(reportViewOnly); + + String userEntry = request.getParameter(USER_ENTRY); + logger.debug("userEntry: " + userEntry); + voteLearningForm.setUserEntry(userEntry); } - + /** - * Return ResourceService bean. - */ - private MessageService getMessageService() { - return (MessageService) VoteServiceProxy.getMessageService(getServlet().getServletContext()); - } + * Return ResourceService bean. + */ + private MessageService getMessageService() { + return (MessageService) VoteServiceProxy.getMessageService(getServlet().getServletContext()); + } } - -