Index: lams_tool_vote/conf/hibernate/mappings/org/lamsfoundation/lams/tool/vote/VoteQueContent.hbm.xml =================================================================== diff -u -rae28185f07883077586773f760d1bde953e2d9bf -rc3d18ff9199715376d8d75d0173bbc595e53f4b5 --- lams_tool_vote/conf/hibernate/mappings/org/lamsfoundation/lams/tool/vote/VoteQueContent.hbm.xml (.../VoteQueContent.hbm.xml) (revision ae28185f07883077586773f760d1bde953e2d9bf) +++ lams_tool_vote/conf/hibernate/mappings/org/lamsfoundation/lams/tool/vote/VoteQueContent.hbm.xml (.../VoteQueContent.hbm.xml) (revision c3d18ff9199715376d8d75d0173bbc595e53f4b5) @@ -73,7 +73,7 @@ > - + - + + + - + + + + + + Index: lams_tool_vote/db/model/lams_tool_vote.clay =================================================================== diff -u -rae28185f07883077586773f760d1bde953e2d9bf -rc3d18ff9199715376d8d75d0173bbc595e53f4b5 --- lams_tool_vote/db/model/lams_tool_vote.clay (.../lams_tool_vote.clay) (revision ae28185f07883077586773f760d1bde953e2d9bf) +++ lams_tool_vote/db/model/lams_tool_vote.clay (.../lams_tool_vote.clay) (revision c3d18ff9199715376d8d75d0173bbc595e53f4b5) @@ -100,7 +100,7 @@ - + @@ -128,11 +128,24 @@ - + + + + + + + + + + + + + + @@ -188,12 +201,19 @@ + + + + + + + - + @@ -274,7 +294,7 @@
- + Index: lams_tool_vote/db/sql/create_lams_tool_vote.sql =================================================================== diff -u -rae28185f07883077586773f760d1bde953e2d9bf -rc3d18ff9199715376d8d75d0173bbc595e53f4b5 --- lams_tool_vote/db/sql/create_lams_tool_vote.sql (.../create_lams_tool_vote.sql) (revision ae28185f07883077586773f760d1bde953e2d9bf) +++ lams_tool_vote/db/sql/create_lams_tool_vote.sql (.../create_lams_tool_vote.sql) (revision c3d18ff9199715376d8d75d0173bbc595e53f4b5) @@ -60,7 +60,8 @@ CREATE TABLE tl_lavote11_usr_attempt ( uid BIGINT(20) NOT NULL AUTO_INCREMENT , que_usr_id BIGINT(20) NOT NULL - , vote_que_content_id BIGINT(20) NOT NULL + , vote_session_id BIGINT(20) NOT NULL + , vote_nomination_content_id BIGINT(20) NOT NULL , attempt_time DATETIME , time_zone VARCHAR(255) , userEntry VARCHAR(255) @@ -69,8 +70,11 @@ , INDEX (que_usr_id) , CONSTRAINT FK_tl_lavote11_usr_attempt_2 FOREIGN KEY (que_usr_id) REFERENCES tl_lavote11_usr (uid) - , INDEX (vote_que_content_id) - , CONSTRAINT FK_tl_lavote11_usr_attempt_3 FOREIGN KEY (vote_que_content_id) + , INDEX (vote_session_id) + , CONSTRAINT FK_tl_lavote11_usr_attempt_4 FOREIGN KEY (vote_session_id) + REFERENCES tl_lavote11_session (uid) + , INDEX (vote_nomination_content_id) + , CONSTRAINT FK_tl_lavote11_usr_attempt_3 FOREIGN KEY (vote_nomination_content_id) REFERENCES tl_lavote11_nomination_content (uid) )TYPE=InnoDB; @@ -86,6 +90,7 @@ REFERENCES tl_lavote11_content (uid) )TYPE=InnoDB; + INSERT INTO tl_lavote11_content(uid, content_id , title , instructions , creation_date , created_by , run_offline , define_later, offline_instructions, online_instructions, content_in_use, retries) VALUES (1, ${default_content_id} ,'Voting Title','Voting Instructions', NOW(), 1,0, 0, 'offline instructions','online instructions', 0, 0); INSERT INTO tl_lavote11_nomination_content (uid,nomination, display_order, vote_content_id) VALUES (1, 'sample nomination', 1, 1); \ No newline at end of file Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/dao/IVoteUsrAttemptDAO.java =================================================================== diff -u -re6d4c9ba0ba0e2b42b4ff2f997618bfedc28dd7c -rc3d18ff9199715376d8d75d0173bbc595e53f4b5 --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/dao/IVoteUsrAttemptDAO.java (.../IVoteUsrAttemptDAO.java) (revision e6d4c9ba0ba0e2b42b4ff2f997618bfedc28dd7c) +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/dao/IVoteUsrAttemptDAO.java (.../IVoteUsrAttemptDAO.java) (revision c3d18ff9199715376d8d75d0173bbc595e53f4b5) @@ -47,10 +47,14 @@ public void removeAttemptsForUser(final Long queUsrId); + public void removeAttemptsForUserandSession(final Long queUsrId, final Long voteSessionId); + public int getLastNominationCount(Long userId); public VoteUsrAttempt getAttemptsForUserAndQuestionContent(final Long queUsrId, final Long voteQueContentId); + public VoteUsrAttempt getAttemptsForUserAndQuestionContentAndSession(final Long queUsrId, final Long voteQueContentId, final Long voteSessionId); + public List getAttemptsListForUserAndQuestionContent(final Long queUsrId, final Long voteQueContentId); public List getAttemptForQueContent(final Long queUsrId, final Long voteQueContentId); Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/dao/hibernate/VoteUsrAttemptDAO.java =================================================================== diff -u -rae28185f07883077586773f760d1bde953e2d9bf -rc3d18ff9199715376d8d75d0173bbc595e53f4b5 --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/dao/hibernate/VoteUsrAttemptDAO.java (.../VoteUsrAttemptDAO.java) (revision ae28185f07883077586773f760d1bde953e2d9bf) +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/dao/hibernate/VoteUsrAttemptDAO.java (.../VoteUsrAttemptDAO.java) (revision c3d18ff9199715376d8d75d0173bbc595e53f4b5) @@ -49,6 +49,8 @@ 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 and voteUsrAttempt.voteSessionId=:voteSessionId"; + 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 "; @@ -102,7 +104,29 @@ } } + public void removeAttemptsForUserandSession(final Long queUsrId, final Long voteSessionId) + { + String strGetUser = "from voteUsrAttempt in class VoteUsrAttempt where voteUsrAttempt.queUsrId=:queUsrId and voteUsrAttempt.voteSessionId=:voteSessionId"; + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(strGetUser) + .setLong("queUsrId", queUsrId.longValue()) + .setLong("voteSessionId", voteSessionId.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 getAttemptsForUserAndQuestionContent(final Long queUsrId, final Long voteQueContentId) { HibernateTemplate templ = this.getHibernateTemplate(); @@ -119,7 +143,27 @@ return null; } + + 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()) + .setLong("voteSessionId", voteSessionId.longValue()) + .list(); + + if(list != null && list.size() > 0){ + VoteUsrAttempt voteA = (VoteUsrAttempt) list.get(0); + return voteA; + } + + return null; + } + + + public List getAttemptsListForUserAndQuestionContent(final Long queUsrId, final Long voteQueContentId) { HibernateTemplate templ = this.getHibernateTemplate(); Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/pojos/VoteUsrAttempt.java =================================================================== diff -u -rae28185f07883077586773f760d1bde953e2d9bf -rc3d18ff9199715376d8d75d0173bbc595e53f4b5 --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/pojos/VoteUsrAttempt.java (.../VoteUsrAttempt.java) (revision ae28185f07883077586773f760d1bde953e2d9bf) +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/pojos/VoteUsrAttempt.java (.../VoteUsrAttempt.java) (revision c3d18ff9199715376d8d75d0173bbc595e53f4b5) @@ -54,6 +54,8 @@ private Long queUsrId; + private Long voteSessionId; + private boolean singleUserEntry; private Long voteQueContentId; @@ -64,7 +66,10 @@ /** persistent field */ private org.lamsfoundation.lams.tool.vote.pojos.VoteQueUsr voteQueUsr; + /** persistent field */ + private org.lamsfoundation.lams.tool.vote.pojos.VoteSession voteSession; + /** full constructor */ public VoteUsrAttempt(Long attemptId, Date attemptTime, String timeZone, org.lamsfoundation.lams.tool.vote.pojos.VoteQueContent voteQueContent, org.lamsfoundation.lams.tool.vote.pojos.VoteQueUsr voteQueUsr) { @@ -103,7 +108,19 @@ this.singleUserEntry=singleUserEntry; } + public VoteUsrAttempt(Date attemptTime, String timeZone, org.lamsfoundation.lams.tool.vote.pojos.VoteQueContent voteQueContent, + org.lamsfoundation.lams.tool.vote.pojos.VoteQueUsr voteQueUsr, VoteSession voteSession, String userEntry, boolean singleUserEntry) { + this.attemptTime = attemptTime; + this.timeZone = timeZone; + this.voteQueContent = voteQueContent; + this.voteQueUsr = voteQueUsr; + this.voteSession= voteSession; + this.userEntry=userEntry; + this.singleUserEntry=singleUserEntry; + } + + public VoteUsrAttempt(String userEntry, Date attemptTime, String timeZone, org.lamsfoundation.lams.tool.vote.pojos.VoteQueContent voteQueContent, org.lamsfoundation.lams.tool.vote.pojos.VoteQueUsr voteQueUsr) { this.userEntry=userEntry; @@ -242,4 +259,29 @@ this.singleUserEntry = singleUserEntry; } + /** + * @return Returns the voteSessionId. + */ + public Long getVoteSessionId() { + return voteSessionId; + } + /** + * @param voteSessionId The voteSessionId to set. + */ + public void setVoteSessionId(Long voteSessionId) { + this.voteSessionId = voteSessionId; + } + /** + * @return Returns the voteSession. + */ + public org.lamsfoundation.lams.tool.vote.pojos.VoteSession getVoteSession() { + return voteSession; + } + /** + * @param voteSession The voteSession to set. + */ + public void setVoteSession( + org.lamsfoundation.lams.tool.vote.pojos.VoteSession voteSession) { + this.voteSession = voteSession; + } } Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/IVoteService.java =================================================================== diff -u -re6d4c9ba0ba0e2b42b4ff2f997618bfedc28dd7c -rc3d18ff9199715376d8d75d0173bbc595e53f4b5 --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/IVoteService.java (.../IVoteService.java) (revision e6d4c9ba0ba0e2b42b4ff2f997618bfedc28dd7c) +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/IVoteService.java (.../IVoteService.java) (revision c3d18ff9199715376d8d75d0173bbc595e53f4b5) @@ -84,6 +84,8 @@ public VoteUsrAttempt getAttemptsForUserAndQuestionContent(final Long queUsrId, final Long voteQueContentId) throws VoteApplicationException; + public VoteUsrAttempt getAttemptsForUserAndQuestionContentAndSession(final Long queUsrId, final Long voteQueContentId, final Long toolSessionUid) throws VoteApplicationException; + public List retrieveVoteQueContentsByToolContentId(long qaContentId) throws VoteApplicationException; public VoteQueContent retrieveVoteQueContentByUID(Long uid) throws VoteApplicationException; @@ -112,6 +114,8 @@ public void removeAttemptsForUser(final Long queUsrId) throws VoteApplicationException; + public void removeAttemptsForUserandSession(final Long queUsrId, final Long voteSessionId) throws VoteApplicationException; + public List getAllQuestionEntries(final Long mcContentId) throws VoteApplicationException; public VoteQueUsr getVoteQueUsrById(long voteQueUsrId) throws VoteApplicationException; Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/VoteServicePOJO.java =================================================================== diff -u -re6d4c9ba0ba0e2b42b4ff2f997618bfedc28dd7c -rc3d18ff9199715376d8d75d0173bbc595e53f4b5 --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/VoteServicePOJO.java (.../VoteServicePOJO.java) (revision e6d4c9ba0ba0e2b42b4ff2f997618bfedc28dd7c) +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/VoteServicePOJO.java (.../VoteServicePOJO.java) (revision c3d18ff9199715376d8d75d0173bbc595e53f4b5) @@ -500,6 +500,19 @@ } + public VoteUsrAttempt getAttemptsForUserAndQuestionContentAndSession(final Long queUsrId, final Long voteQueContentId, final Long toolSessionUid) throws VoteApplicationException + { + try + { + return voteUsrAttemptDAO.getAttemptsForUserAndQuestionContentAndSession(queUsrId, voteQueContentId, toolSessionUid); + } + catch (DataAccessException e) + { + throw new VoteApplicationException("Exception occured when lams is updating vote UsrAttempt: " + + e.getMessage(), + e); + } + } public void updateVoteUsrAttempt(VoteUsrAttempt voteUsrAttempt) throws VoteApplicationException { @@ -515,6 +528,19 @@ } } + public void removeAttemptsForUserandSession(final Long queUsrId, final Long voteSessionId) throws VoteApplicationException + { + try + { + voteUsrAttemptDAO.removeAttemptsForUserandSession(queUsrId, voteSessionId); + } + catch (DataAccessException e) + { + throw new VoteApplicationException("Exception occured when lams is removing by user and votesession id : " + + e.getMessage(), + e); + } + } public List getAttemptsForUser(final Long queUsrId) throws VoteApplicationException { Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/LearningUtil.java =================================================================== diff -u -r6e806e2588289bb42a1791b145a0f403a72a883d -rc3d18ff9199715376d8d75d0173bbc595e53f4b5 --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/LearningUtil.java (.../LearningUtil.java) (revision 6e806e2588289bb42a1791b145a0f403a72a883d) +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/LearningUtil.java (.../LearningUtil.java) (revision c3d18ff9199715376d8d75d0173bbc595e53f4b5) @@ -114,8 +114,9 @@ } - public static void createAttempt(HttpServletRequest request, VoteQueUsr voteQueUsr, Map mapGeneralCheckedOptionsContent, String userEntry, boolean singleUserEntry) + public static void createAttempt(HttpServletRequest request, VoteQueUsr voteQueUsr, Map mapGeneralCheckedOptionsContent, String userEntry, boolean singleUserEntry, VoteSession voteSession) { + logger.debug("doing voteSession: " + voteSession); logger.debug("doing createAttempt: " + mapGeneralCheckedOptionsContent); logger.debug("userEntry: " + userEntry); logger.debug("singleUserEntry: " + singleUserEntry); @@ -142,29 +143,29 @@ logger.debug("voteQueContent: " + voteQueContent); if (voteQueContent != null) { - createIndividualOptions(request, voteQueContent, voteQueUsr, attempTime, timeZone, userEntry, false); + createIndividualOptions(request, voteQueContent, voteQueUsr, attempTime, timeZone, userEntry, false, voteSession); } else if ((voteQueContent == null) && (questionDisplayOrder.toString().equals("101"))) { logger.debug("creating user entry record, 101"); VoteQueContent localVoteQueContent=voteService.getToolDefaultQuestionContent(1); logger.debug("localVoteQueContent: " + localVoteQueContent); - createIndividualOptions(request, localVoteQueContent, voteQueUsr, attempTime, timeZone, userEntry, true); + createIndividualOptions(request, localVoteQueContent, voteQueUsr, attempTime, timeZone, userEntry, true, voteSession); } else if ((voteQueContent == null) && (questionDisplayOrder.toString().equals("102"))) { logger.debug("creating user entry record, 102"); VoteQueContent localVoteQueContent=voteService.getToolDefaultQuestionContent(1); logger.debug("localVoteQueContent: " + localVoteQueContent); - createIndividualOptions(request, localVoteQueContent, voteQueUsr, attempTime, timeZone, userEntry, false); + createIndividualOptions(request, localVoteQueContent, voteQueUsr, attempTime, timeZone, userEntry, false, voteSession); } } } } - public static void createIndividualOptions(HttpServletRequest request, VoteQueContent voteQueContent, VoteQueUsr voteQueUsr, Date attempTime, String timeZone, String userEntry, boolean singleUserEntry) + public static void createIndividualOptions(HttpServletRequest request, VoteQueContent voteQueContent, VoteQueUsr voteQueUsr, Date attempTime, String timeZone, String userEntry, boolean singleUserEntry, VoteSession voteSession) { - logger.debug("doing createIndividualOptions"); + logger.debug("doing voteSession: " + voteSession); logger.debug("userEntry: " + userEntry); logger.debug("singleUserEntry: " + singleUserEntry); @@ -176,7 +177,8 @@ if (voteQueContent != null) { - VoteUsrAttempt existingVoteUsrAttempt=voteService.getAttemptsForUserAndQuestionContent(voteQueUsr.getQueUsrId(),voteQueContent.getVoteContentId()); + //VoteUsrAttempt existingVoteUsrAttempt=voteService.getAttemptsForUserAndQuestionContent(voteQueUsr.getQueUsrId(),voteQueContent.getVoteContentId()); + VoteUsrAttempt existingVoteUsrAttempt=voteService.getAttemptsForUserAndQuestionContentAndSession(voteQueUsr.getQueUsrId(),voteQueContent.getVoteContentId(), voteSession.getUid()); logger.debug("existingVoteUsrAttempt: " + existingVoteUsrAttempt); if (existingVoteUsrAttempt != null) @@ -191,7 +193,7 @@ else { logger.debug("create new attempt"); - VoteUsrAttempt voteUsrAttempt=new VoteUsrAttempt(attempTime, timeZone, voteQueContent, voteQueUsr, userEntry, singleUserEntry); + VoteUsrAttempt voteUsrAttempt=new VoteUsrAttempt(attempTime, timeZone, voteQueContent, voteQueUsr, voteSession, userEntry, singleUserEntry); logger.debug("voteUsrAttempt: " + voteUsrAttempt); voteService.createVoteUsrAttempt(voteUsrAttempt); logger.debug("created voteUsrAttempt in the db :" + voteUsrAttempt); Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/VoteLearningAction.java =================================================================== diff -u -r6e806e2588289bb42a1791b145a0f403a72a883d -rc3d18ff9199715376d8d75d0173bbc595e53f4b5 --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/VoteLearningAction.java (.../VoteLearningAction.java) (revision 6e806e2588289bb42a1791b145a0f403a72a883d) +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/VoteLearningAction.java (.../VoteLearningAction.java) (revision c3d18ff9199715376d8d75d0173bbc595e53f4b5) @@ -425,17 +425,18 @@ //VoteQueUsr voteQueUsr=LearningUtil.getUser(request); logger.debug("voteQueUsr is : " + voteQueUsr); - logger.debug("creating attemps with mapGeneralCheckedOptionsContent " + mapGeneralCheckedOptionsContent); if (existingVoteQueUsr != null) { - voteService.removeAttemptsForUser(existingVoteQueUsr.getUid()); - logger.debug("nominations deleted for user: " + voteQueUsr.getUid()); + //voteService.removeAttemptsForUser(existingVoteQueUsr.getUid()); + 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()); } logger.debug("mapGeneralCheckedOptionsContent size: " + mapGeneralCheckedOptionsContent.size()); if (mapGeneralCheckedOptionsContent.size() > 0) { - LearningUtil.createAttempt(request, voteQueUsr, mapGeneralCheckedOptionsContent, userEntry, false); + LearningUtil.createAttempt(request, voteQueUsr, mapGeneralCheckedOptionsContent, userEntry, false, voteSession); } @@ -449,7 +450,7 @@ if (userEntry.length() > 0) { logger.debug("creating entry for: " + userEntry); - LearningUtil.createAttempt(request, voteQueUsr, mapLeanerCheckedOptionsContent, userEntry, true); + LearningUtil.createAttempt(request, voteQueUsr, mapLeanerCheckedOptionsContent, userEntry, true, voteSession); } } if ((mapGeneralCheckedOptionsContent.size() > 0) && (userEntryAvailable == true)) @@ -462,7 +463,7 @@ if (userEntry.length() > 0) { logger.debug("creating entry for: " + userEntry); - LearningUtil.createAttempt(request, voteQueUsr, mapLeanerCheckedOptionsContent, userEntry, false); + LearningUtil.createAttempt(request, voteQueUsr, mapLeanerCheckedOptionsContent, userEntry, false, voteSession); } } Index: lams_tool_vote/test/java/org/lamsfoundation/lams/tool/vote/VoteQueContent.hbm.xml =================================================================== diff -u -rae28185f07883077586773f760d1bde953e2d9bf -rc3d18ff9199715376d8d75d0173bbc595e53f4b5 --- lams_tool_vote/test/java/org/lamsfoundation/lams/tool/vote/VoteQueContent.hbm.xml (.../VoteQueContent.hbm.xml) (revision ae28185f07883077586773f760d1bde953e2d9bf) +++ lams_tool_vote/test/java/org/lamsfoundation/lams/tool/vote/VoteQueContent.hbm.xml (.../VoteQueContent.hbm.xml) (revision c3d18ff9199715376d8d75d0173bbc595e53f4b5) @@ -24,9 +24,9 @@ @@ -73,7 +73,7 @@ > - + - + + + - + + + + + +