Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/NoticeboardUser.java =================================================================== diff -u --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/NoticeboardUser.java (revision 0) +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/NoticeboardUser.java (revision 7bcfa73cac3014829779e4dc4b029573421e21ab) @@ -0,0 +1,144 @@ +/* + *Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * + *This program is free software; you can redistribute it and/or modify + *it under the terms of the GNU General Public License as published by + *the Free Software Foundation; either version 2 of the License, or + *(at your option) any later version. + * + *This program is distributed in the hope that it will be useful, + *but WITHOUT ANY WARRANTY; without even the implied warranty of + *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + *GNU General Public License for more details. + * + *You should have received a copy of the GNU General Public License + *along with this program; if not, write to the Free Software + *Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + *USA + * + *http://www.gnu.org/licenses/gpl.txt + */ +package org.lamsfoundation.lams.tool.noticeboard; + +import java.io.Serializable; +/* + * Created on Jun 30, 2005 + */ + +/** + * @author mtruong + * + * TODO To change the template for this generated type comment go to + * Window - Preferences - Java - Code Style - Code Templates + */ +public class NoticeboardUser implements Serializable { + + private Long uid; + private Long userId; + private NoticeboardSession nbSession; + private String username; + private String fullname; + private String userStatus; + + public final static String INCOMPLETE = "INCOMPLETE"; + + public static final String COMPLETED = "COMPLETED"; + + public NoticeboardUser() + { + + } + /** minimal constructor */ + public NoticeboardUser(Long userId, NoticeboardSession nbSession) + { + this.userId = userId; + this.nbSession = nbSession; + } + + /** full constructor */ + public NoticeboardUser(Long userId, + NoticeboardSession nbSession, + String username, + String fullname, + String status) + { + this.userId = userId; + this.nbSession = nbSession; + this.username = username; + this.fullname = fullname; + this.userStatus = status; + } + + /** + * @return Returns the fullname. + */ + public String getFullname() { + return fullname; + } + /** + * @param fullname The fullname to set. + */ + public void setFullname(String fullname) { + this.fullname = fullname; + } + /** + * @return Returns the nbSession. + */ + public NoticeboardSession getNbSession() { + return nbSession; + } + /** + * @param nbSession The nbSession to set. + */ + public void setNbSession(NoticeboardSession nbSession) { + this.nbSession = nbSession; + } + /** + * @return Returns the uid. + */ + public Long getUid() { + return uid; + } + /** + * @param uid The uid to set. + */ + public void setUid(Long uid) { + this.uid = uid; + } + /** + * @return Returns the userId. + */ + public Long getUserId() { + return userId; + } + /** + * @param userId The userId to set. + */ + public void setUserId(Long userId) { + this.userId = userId; + } + /** + * @return Returns the username. + */ + public String getUsername() { + return username; + } + /** + * @param username The username to set. + */ + public void setUsername(String username) { + this.username = username; + } + /** + * @return Returns the userStatus. + */ + public String getUserStatus() { + return userStatus; + } + /** + * @param userStatus The userStatus to set. + */ + public void setUserStatus(String userStatus) { + this.userStatus = userStatus; + } +} Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/dao/hibernate/NoticeboardSessionDAO.java =================================================================== diff -u -rcf79eb5bab20af171287d5153b3b8b6eb8c56aa7 -r7bcfa73cac3014829779e4dc4b029573421e21ab --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/dao/hibernate/NoticeboardSessionDAO.java (.../NoticeboardSessionDAO.java) (revision cf79eb5bab20af171287d5153b3b8b6eb8c56aa7) +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/dao/hibernate/NoticeboardSessionDAO.java (.../NoticeboardSessionDAO.java) (revision 7bcfa73cac3014829779e4dc4b029573421e21ab) @@ -25,14 +25,22 @@ import org.lamsfoundation.lams.tool.noticeboard.NoticeboardSession; import org.lamsfoundation.lams.tool.noticeboard.dao.INoticeboardSessionDAO; import org.springframework.orm.hibernate.support.HibernateDaoSupport; +import org.springframework.orm.hibernate.HibernateCallback; +import net.sf.hibernate.HibernateException; +import net.sf.hibernate.Session; + /** * @author mtruong * Hibernate implementation for database access to Noticeboard sessions for the noticeboard tool. */ public class NoticeboardSessionDAO extends HibernateDaoSupport implements INoticeboardSessionDAO { + private static final String LOAD_NBSESSION_BY_USER = "select ns from NoticeboardSession ns left join fetch " + + "ns.nbUsers user where user.userId=:userId"; + + /** *

Return the persistent instance of a NoticeboardSession * with the given identifier uid, returns null if not found.

@@ -130,4 +138,40 @@ this.getHibernateTemplate().delete(nbSession); } + /** + *

Returns the persistent instance of NoticeboardSession + * associated with the given noticeboard user, with user id userId, + * returns null if not found. + * + * @param userId The noticeboard user id + * @return a persistent instance of NoticeboardSessions or null if not found. + */ + public NoticeboardSession getNbSessionByUser(final Long userId) + { + return (NoticeboardSession) getHibernateTemplate().execute(new HibernateCallback() + { + + public Object doInHibernate(Session session) throws HibernateException + { + return session.createQuery(LOAD_NBSESSION_BY_USER) + .setLong("userId", + userId.longValue()) + .uniqueResult(); + } + }); + } + + /** + *

Deletes all instances of NoticeboardUser that are associated + * with the given instance of NoticeboardSession

+ * + * @param nbSession The instance of NoticeboardSession in which corresponding instances of NoticeboardUser should be deleted. + */ + public void removeNbUsers(NoticeboardSession nbSession) + { + this.getHibernateTemplate().deleteAll(nbSession.getNbUsers()); + } + + + } Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/ApplicationResources.properties =================================================================== diff -u -rdeeaba2ec6d90361b2d8a53dc36ef14793e08caa -r7bcfa73cac3014829779e4dc4b029573421e21ab --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/ApplicationResources.properties (.../ApplicationResources.properties) (revision deeaba2ec6d90361b2d8a53dc36ef14793e08caa) +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/ApplicationResources.properties (.../ApplicationResources.properties) (revision 7bcfa73cac3014829779e4dc4b029573421e21ab) @@ -1,5 +1,5 @@ # Resources for parameter 'org.lamsfoundation.lams.tool.noticeboard.web.ApplicationResources' -# Project P/lams_tool_noticeboard +# Project P/lams_tool_nb # ========== Authoring Page =========== @@ -14,8 +14,14 @@ #Instructions Page instructions.onlineInstructions=Online Instructions: instructions.offlineInstructions=Offline Instructions: +instructions.uploadOnlineInstr=Upload Online Instructions: +instructions.uploadOfflineInstr=Upload Offline Instructions: #buttons button.cancel=Cancel button.ok=OK -button.done=Done \ No newline at end of file +button.done=Done +button.finish=Finish + +#Exception Messages +error.missingParam={0} missing. Unable to continue. \ No newline at end of file Index: lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/dao/hibernate/TestNoticeboardContentDAO.java =================================================================== diff -u -rc4e52cfb69c2d7ca6178878497c2175537a837db -r7bcfa73cac3014829779e4dc4b029573421e21ab --- lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/dao/hibernate/TestNoticeboardContentDAO.java (.../TestNoticeboardContentDAO.java) (revision c4e52cfb69c2d7ca6178878497c2175537a837db) +++ lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/dao/hibernate/TestNoticeboardContentDAO.java (.../TestNoticeboardContentDAO.java) (revision 7bcfa73cac3014829779e4dc4b029573421e21ab) @@ -75,6 +75,7 @@ nbContent = noticeboardDAO.getNbContentByUID(new Long(1)); assertEquals(nbContent.getUid(), new Long(1)); + assertEquals(nbContent.getNbContentId(), DEFAULT_CONTENT_ID); assertContentEqualsDefaultData(nbContent); } Index: lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/dao/hibernate/TestNoticeboardSessionDAO.java =================================================================== diff -u -rc4e52cfb69c2d7ca6178878497c2175537a837db -r7bcfa73cac3014829779e4dc4b029573421e21ab --- lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/dao/hibernate/TestNoticeboardSessionDAO.java (.../TestNoticeboardSessionDAO.java) (revision c4e52cfb69c2d7ca6178878497c2175537a837db) +++ lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/dao/hibernate/TestNoticeboardSessionDAO.java (.../TestNoticeboardSessionDAO.java) (revision 7bcfa73cac3014829779e4dc4b029573421e21ab) @@ -73,7 +73,7 @@ } - public void testgetNbSessionByUID() + public void testgetNbSessionByUID() { nbSession = nbSessionDAO.getNbSessionByUID(new Long(1)); //default test data which is always in db @@ -172,6 +172,25 @@ assertSessionObjectIsNull(TEST_SESSION_ID); } + public void testGetNbSessionByUser() + { + nbSession = nbSessionDAO.getNbSessionByUser(TEST_USER_ID); + assertEqualsForSessionContent(nbSession); + } + public void testRemoveNbUsers() + { + nbSession = nbSessionDAO.findNbSessionById(TEST_SESSION_ID); + + nbSessionDAO.removeNbUsers(nbSession); + nbSession.getNbUsers().clear(); + nbSessionDAO.updateNbSession(nbSession); + + NoticeboardSession ns = nbSessionDAO.findNbSessionById(TEST_SESSION_ID); + + assertNotNull(ns); + assertUserObjectIsNull(TEST_USER_ID); + } + } Index: lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/dao/hibernate/TestNoticeboardUserDAO.java =================================================================== diff -u --- lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/dao/hibernate/TestNoticeboardUserDAO.java (revision 0) +++ lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/dao/hibernate/TestNoticeboardUserDAO.java (revision 7bcfa73cac3014829779e4dc4b029573421e21ab) @@ -0,0 +1,145 @@ +/* + *Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * + *This program is free software; you can redistribute it and/or modify + *it under the terms of the GNU General Public License as published by + *the Free Software Foundation; either version 2 of the License, or + *(at your option) any later version. + * + *This program is distributed in the hope that it will be useful, + *but WITHOUT ANY WARRANTY; without even the implied warranty of + *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + *GNU General Public License for more details. + * + *You should have received a copy of the GNU General Public License + *along with this program; if not, write to the Free Software + *Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + *USA + * + *http://www.gnu.org/licenses/gpl.txt + */ + +/* + * Created on Jul 1, 2005 + */ +package org.lamsfoundation.lams.tool.noticeboard.dao.hibernate; + +import org.lamsfoundation.lams.tool.noticeboard.NbDataAccessTestCase; +import org.lamsfoundation.lams.tool.noticeboard.NoticeboardUser; +import org.lamsfoundation.lams.tool.noticeboard.NoticeboardSession; + +/** + * @author mtruong + */ +public class TestNoticeboardUserDAO extends NbDataAccessTestCase { + + private NoticeboardUserDAO nbUserDAO; + private NoticeboardSessionDAO nbSessionDAO; + + private NoticeboardUser nbUser; + private NoticeboardSession nbSession; + + private boolean cleanContentData = true; + + public TestNoticeboardUserDAO(String name) + { + super(name); + } + + /** + * @see NbDataAccessTestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + nbSessionDAO = (NoticeboardSessionDAO) this.context.getBean("nbSessionDAO"); + nbUserDAO = (NoticeboardUserDAO) this.context.getBean("nbUserDAO"); + super.initAllData(); + + } + + protected void tearDown() throws Exception { + + super.tearDown(); + if(cleanContentData) + { + super.cleanNbContentData(TEST_NB_ID); + } + } + + public void testGetNbUserByUID() + { + nbUser = nbUserDAO.getNbUserByUID(new Long(1)); + + assertEquals(nbUser.getUserId(), DEFAULT_USER_ID); + assertEquals(nbUser.getFullname(), DEFAULT_FULLNAME); + assertEquals(nbUser.getUsername(), DEFAULT_USERNAME); + assertEquals(nbUser.getUserStatus(), DEFAULT_USER_STATUS); + } + + public void testGetNbUserByID() + { + nbUser = nbUserDAO.getNbUserByID(TEST_USER_ID); + + assertEqualsForNbUser(nbUser); + + Long nonExistentUserId = new Long(23321); + assertUserObjectIsNull(nonExistentUserId); + } + + + public void testSaveNbUser() + { + NoticeboardSession sessionToReference = nbSessionDAO.findNbSessionById(TEST_SESSION_ID); + + Long newUserId = new Long(3849); + + NoticeboardUser newUserObj = new NoticeboardUser(newUserId, + sessionToReference); + + sessionToReference.getNbUsers().add(newUserObj); + nbSessionDAO.updateNbSession(sessionToReference); + + nbUserDAO.saveNbUser(newUserObj); + + //Retrieve the newly added session object and test its values + nbUser = nbUserDAO.getNbUserByID(newUserId); + + assertEquals(nbUser.getUserId(), newUserId); + assertEquals(nbUser.getNbSession().getNbSessionId(),TEST_SESSION_ID); + } + + public void testUpdateNbUser() + { + nbUser = nbUserDAO.getNbUserByID(TEST_USER_ID); + nbUser.setUserStatus(NoticeboardUser.COMPLETED); + nbUserDAO.updateNbUser(nbUser); + + NoticeboardUser modifiedUser = nbUserDAO.getNbUserByID(TEST_USER_ID); + assertEquals(modifiedUser.getUserStatus(), NoticeboardUser.COMPLETED); + } + + public void testRemoveNbUserById() + { + nbUser = nbUserDAO.getNbUserByID(TEST_USER_ID); + nbSession = nbUser.getNbSession(); + nbSession.getNbUsers().remove(nbUser); + + nbUserDAO.removeNbUser(TEST_USER_ID); + nbSessionDAO.updateNbSession(nbSession); + + assertUserObjectIsNull(TEST_USER_ID); + } + + public void testRemoveNbUser() + { + nbUser = nbUserDAO.getNbUserByID(TEST_USER_ID); + nbSession = nbUser.getNbSession(); + nbSession.getNbUsers().remove(nbUser); + + nbUserDAO.removeNbUser(nbUser); + nbSessionDAO.updateNbSession(nbSession); + + assertUserObjectIsNull(TEST_USER_ID); + } + +} Index: lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/service/TestNoticeboardServicePOJO.java =================================================================== diff -u -rcf79eb5bab20af171287d5153b3b8b6eb8c56aa7 -r7bcfa73cac3014829779e4dc4b029573421e21ab --- lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/service/TestNoticeboardServicePOJO.java (.../TestNoticeboardServicePOJO.java) (revision cf79eb5bab20af171287d5153b3b8b6eb8c56aa7) +++ lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/service/TestNoticeboardServicePOJO.java (.../TestNoticeboardServicePOJO.java) (revision 7bcfa73cac3014829779e4dc4b029573421e21ab) @@ -30,21 +30,21 @@ import org.lamsfoundation.lams.tool.noticeboard.NbDataAccessTestCase; import org.lamsfoundation.lams.tool.noticeboard.NoticeboardContent; import org.lamsfoundation.lams.tool.noticeboard.NoticeboardSession; +import org.lamsfoundation.lams.tool.noticeboard.NoticeboardUser; import org.lamsfoundation.lams.tool.noticeboard.service.INoticeboardService; /** * @author mtruong * - * TODO To change the template for this generated type comment go to - * Window - Preferences - Java - Code Style - Code Templates */ public class TestNoticeboardServicePOJO extends NbDataAccessTestCase { private INoticeboardService nbService = null; private NoticeboardContent nbContent; private NoticeboardSession nbSession; + private NoticeboardUser nbUser; private boolean cleanContentData = true; @@ -74,6 +74,11 @@ } + + /* ============================================================================== + * Methods for access to NoticeboardContent objects + * ============================================================================== + */ public void testRetrieveNoticeboardByUID() { nbContent = nbService.retrieveNoticeboard(TEST_NB_ID); @@ -141,16 +146,16 @@ nbService.removeNoticeboard(testToolContentId); } - /** - * TODO: finish this one after testing sesssion - * - */ - /*public void testremoveNoticeboardSessions() + public void testremoveNoticeboardSessions() { nbContent = nbService.retrieveNoticeboard(TEST_NB_ID); - nbService.removeNoticeboardSessions(nbContent); - } */ + nbService.removeNoticeboardSessionsFromContent(nbContent); + + nbSession = nbService.retrieveNoticeboardSession(TEST_SESSION_ID); + assertNull(nbSession); + + } public void testRemoveNoticeboardByID() { @@ -170,6 +175,11 @@ assertNull(nb); } + /* ============================================================================== + * Methods for access to NoticeboardSession objects + * ============================================================================== + */ + public void testRetrieveNoticeboardSession() { nbSession = nbService.retrieveNoticeboardSession(TEST_SESSION_ID); @@ -200,7 +210,7 @@ nbContent, created, NoticeboardSession.NOT_ATTEMPTED); - nbContent.getNbSessions().add(nbSession); + nbService.saveNoticeboardSession(nbSession); @@ -232,27 +242,18 @@ public void testRemoveSessionByID() { - nbSession = nbService.retrieveNoticeboardSession(TEST_SESSION_ID); - - nbContent = nbSession.getNbContent(); - nbContent.getNbSessions().remove(nbSession); - + nbService.removeSession(TEST_SESSION_ID); - nbService.updateNoticeboard(nbContent); - + assertSessionObjectIsNull(TEST_SESSION_ID); } public void testRemoveSession() { nbSession = nbService.retrieveNoticeboardSession(TEST_SESSION_ID); - nbContent = nbSession.getNbContent(); - nbContent.getNbSessions().remove(nbSession); - nbService.removeSession(nbSession); - nbService.updateNoticeboard(nbContent); - + assertSessionObjectIsNull(TEST_SESSION_ID); } @@ -261,17 +262,87 @@ { nbSession = nbService.retrieveNoticeboardSession(TEST_SESSION_ID); Long uid = nbSession.getUid(); - - nbContent = nbSession.getNbContent(); - nbContent.getNbSessions().remove(nbSession); - + nbService.removeSessionByUID(uid); - nbService.updateNoticeboard(nbContent); - + assertSessionObjectIsNull(TEST_SESSION_ID); } + public void testRemoveNoticeboardUsersFromSession() + { + nbSession = nbService.retrieveNoticeboardSession(TEST_SESSION_ID); + + nbService.removeNoticeboardUsersFromSession(nbSession); + + nbUser = nbService.retrieveNoticeboardUser(TEST_USER_ID); + assertNull(nbUser); + + } + + /* ============================================================================== + * Methods for access to NoticeboardUser objects + * ============================================================================== + */ + public void testRetrieveNoticeboardUser() + { + nbUser = nbService.retrieveNoticeboardUser(TEST_USER_ID); + + assertEqualsForNbUser(nbUser); + } + + public void testRetrieveNoticeboardUserByUID() + { + nbUser = nbService.retrieveNoticeboardUserByUID(new Long(1)); + + assertEqualsForDefaultNbUser(nbUser); + } + + public void testSaveNoticeboardUser() + { + Long newUserId = new Long(8756); + nbSession = nbService.retrieveNoticeboardSession(TEST_SESSION_ID); + + NoticeboardUser user = new NoticeboardUser(newUserId, nbSession); + + + nbService.saveNoticeboardUser(user); + + NoticeboardUser userInDb = nbService.retrieveNoticeboardUser(newUserId); + assertEquals(userInDb.getUserId(), newUserId); + assertEquals(userInDb.getNbSession().getNbSessionId(), TEST_SESSION_ID); + } + + public void testUpdateNoticeboardUser() + { + nbUser = nbService.retrieveNoticeboardUser(TEST_USER_ID); + nbUser.setUserStatus(NoticeboardUser.COMPLETED); + + nbService.updateNoticeboardUser(nbUser); + + NoticeboardUser updatedUser = nbService.retrieveNoticeboardUser(TEST_USER_ID); + + assertEquals(updatedUser.getUserStatus(), NoticeboardUser.COMPLETED); + } + + public void testRemoveUserById() + { + + nbService.removeUser(TEST_USER_ID); + + assertUserObjectIsNull(TEST_USER_ID); + + } + + public void testRemoveUser() + { + nbUser = nbService.retrieveNoticeboardUser(TEST_USER_ID); + + nbService.removeUser(nbUser); + + assertUserObjectIsNull(TEST_USER_ID); + + } } \ No newline at end of file Index: lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/service/TestToolContentManager.java =================================================================== diff -u -rcf79eb5bab20af171287d5153b3b8b6eb8c56aa7 -r7bcfa73cac3014829779e4dc4b029573421e21ab --- lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/service/TestToolContentManager.java (.../TestToolContentManager.java) (revision cf79eb5bab20af171287d5153b3b8b6eb8c56aa7) +++ lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/service/TestToolContentManager.java (.../TestToolContentManager.java) (revision 7bcfa73cac3014829779e4dc4b029573421e21ab) @@ -22,8 +22,6 @@ /* * Created on May 24, 2005 * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates */ package org.lamsfoundation.lams.tool.noticeboard.service; @@ -36,8 +34,6 @@ /** * @author mtruong * - * TODO To change the template for this generated type comment go to - * Window - Preferences - Java - Code Style - Code Templates */ public class TestToolContentManager extends NbDataAccessTestCase { Index: lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/testApplicationContext.xml =================================================================== diff -u -r3ad0734e354d48a9cf04da55a8a1f1b2a0843ad7 -r7bcfa73cac3014829779e4dc4b029573421e21ab --- lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/testApplicationContext.xml (.../testApplicationContext.xml) (revision 3ad0734e354d48a9cf04da55a8a1f1b2a0843ad7) +++ lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/testApplicationContext.xml (.../testApplicationContext.xml) (revision 7bcfa73cac3014829779e4dc4b029573421e21ab) @@ -21,6 +21,7 @@ org/lamsfoundation/lams/tool/noticeboard/NoticeboardContent.hbm.xml org/lamsfoundation/lams/tool/noticeboard/NoticeboardSession.hbm.xml + org/lamsfoundation/lams/tool/noticeboard/NoticeboardUser.hbm.xml @@ -50,6 +51,7 @@ + @@ -88,6 +90,9 @@ + + +