[virtualcommons-svn] SF.net SVN: virtualcommons:[257] mentalmodels/trunk/src/main
Status: Beta
Brought to you by:
alllee
From: <see...@us...> - 2009-08-18 21:56:59
|
Revision: 257 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=257&view=rev Author: seematalele Date: 2009-08-18 21:56:49 +0000 (Tue, 18 Aug 2009) Log Message: ----------- Created the HibernateGroupDao Modified Paths: -------------- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Student.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/Feed.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/RoundService.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartupService.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StudentService.java mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml Added Paths: ----------- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/dao/HibernateGroupDao.java Added: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/dao/HibernateGroupDao.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/dao/HibernateGroupDao.java (rev 0) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/dao/HibernateGroupDao.java 2009-08-18 21:56:49 UTC (rev 257) @@ -0,0 +1,11 @@ +package edu.asu.commons.mme.dao; + +import edu.asu.commons.mme.entity.Group; + +public class HibernateGroupDao extends HibernateDao<Group> { + + public HibernateGroupDao() + { + super(Group.class); + } +} Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Student.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Student.java 2009-08-18 18:41:59 UTC (rev 256) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Student.java 2009-08-18 21:56:49 UTC (rev 257) @@ -50,6 +50,8 @@ private String gender; + private String gameCode; + public Long getId() { return id; } @@ -122,4 +124,12 @@ return game; } + public void setGameCode(String gameCode) { + this.gameCode = gameCode; + } + + public String getGameCode() { + return gameCode; + } + } Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/Feed.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/Feed.java 2009-08-18 18:41:59 UTC (rev 256) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/Feed.java 2009-08-18 21:56:49 UTC (rev 257) @@ -43,8 +43,6 @@ } - - /*@Override public Object invoke(Message msg) { // TODO Auto-generated method stub Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/RoundService.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/RoundService.java 2009-08-18 18:41:59 UTC (rev 256) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/RoundService.java 2009-08-18 21:56:49 UTC (rev 257) @@ -60,9 +60,24 @@ currentGame = new Game(); currentGame = game; getGameDao().save(currentGame); + currentGame.setDescription(currentGame.getDescription()+currentGame.getId()); + getGameDao().save(currentGame); setCurrentGame(currentGame); + initializeCurrentGame(); return getCurrentGame(); } + private void initializeCurrentGame() { + // TODO Auto-generated method stub + Hibernate.initialize(currentGame); + Hibernate.initialize(currentGame.getCurrentBlock()); + Hibernate.initialize(currentGame.getCurrentRound()); + Iterator<Round> rounds = currentGame.getRounds().iterator(); + while(rounds.hasNext()) + { + initializeRound(rounds.next()); + } + } + public Module getNextModule(int sequenceNo) { return getModule(sequenceNo); @@ -487,12 +502,12 @@ public Round getCurrentRound() { - initializeCurrentRound(); + initializeRound(currentRound); return currentRound; } - private void initializeCurrentRound() { + private void initializeRound(Round currentRound) { // TODO Auto-generated method stub Hibernate.initialize(currentRound); @@ -508,7 +523,6 @@ { Hibernate.initialize(roundlocations.get(k)); } - } /*public void setStartModule(Boolean startModule) { Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java 2009-08-18 18:41:59 UTC (rev 256) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java 2009-08-18 21:56:49 UTC (rev 257) @@ -1,7 +1,9 @@ package edu.asu.commons.mme.service; import edu.asu.commons.mme.entity.Block; +import edu.asu.commons.mme.entity.Game; import edu.asu.commons.mme.entity.ModuleRoundConfig; +import edu.asu.commons.mme.entity.Student; import flex.messaging.MessageBroker; import flex.messaging.messages.AsyncMessage; import flex.messaging.util.UUIDUtils; @@ -12,10 +14,9 @@ private RoundService roundService; private LocationService locationService; private DayByDayDecisionsService dayBydayDecisionService; - - + private StudentService studentService; private ModuleRoundConfig currentModuleRoundConfig; - + public StartGame() { @@ -25,6 +26,30 @@ setRunning(true); } + + public Student createStudent(Student student) { + Game game = new Game(); + game = roundService.getCurrentGame(); + Student studentReturn = null; + if(game.getDescription() == student.getGameCode()) + { + student.setGame(game); + studentReturn = new Student(); + studentReturn = studentService.createStudent(student); + } + return studentReturn; + } + + public Game createGame(Game game) + { + return roundService.createGame(game); + } + + public void assignGroups() + { + studentService.assignGroups(); + } + /** * 1)Initially first block will get pushed to all the clients. * 2)get timer for that block @@ -38,12 +63,12 @@ Block block = new Block(); //roundService.test(); - + MessageBroker msgBroker = MessageBroker.getMessageBroker(null); String clientID = UUIDUtils.createUUID(); int i=0; - while (i<15) { + while (running) { i++; /*if(getCurrentModuleRoundConfig() == null) @@ -53,42 +78,44 @@ }*/ //Push the first block to the clients - if(block == null) + AsyncMessage msg = new AsyncMessage(); + msg.setDestination("DataPush"); + //msg.setHeader("DSSubtopic", "hello"); + msg.setClientId(clientID); + msg.setMessageId(UUIDUtils.createUUID()); + msg.setTimestamp(System.currentTimeMillis()); + System.out.println("in while loop: "); + block = roundService.getBlock(); + System.out.println("after block "); + msg.setBody("Here is a block!!!" + block); + System.out.println("Message broker is: "+ msgBroker); + System.out.println("Message is: "+ block.getDescription()); + msgBroker.routeMessageToService(msg, null); + if(block.getDescription().equalsIgnoreCase("Day-by-day decisions game")) { - AsyncMessage msg = new AsyncMessage(); - msg.setDestination("DataPush"); - //msg.setHeader("DSSubtopic", "hello"); - msg.setClientId(clientID); - msg.setMessageId(UUIDUtils.createUUID()); - msg.setTimestamp(System.currentTimeMillis()); - System.out.println("in while loop: "); - block = roundService.getBlock(); - System.out.println("after block "); - msg.setBody("Here is a block!!!" + block); - System.out.println("Message broker is: "+ msgBroker); - System.out.println("Message is: "+ block.getDescription()); - msgBroker.routeMessageToService(msg, null); - if(block.getDescription().equalsIgnoreCase("Day-by-day decisions game")) + //start day by day decision + //getDayBydayDecisionService(). + + } + else if (block.getDescription().equalsIgnoreCase("Communication")) + { + //start communication round + + } + //get the timer for the block + Integer timer = roundService.getTimerforBlock(block); + //start the timer for the block sent + try { + //for testing purpose 5000 is given as an argument + Thread.sleep(5000); + if(block == null) { - //start day by day decision - //getDayBydayDecisionService(). - - } - else if (block.getDescription().equalsIgnoreCase("Communication")) - { - //start communication round - - } - //get the timer for the block - Integer timer = roundService.getTimerforBlock(block); - //start the timer for the block sent - try { - Thread.sleep(5000); running = false; - } catch (InterruptedException e) { } + } catch (InterruptedException e) { } + } } @@ -136,6 +163,9 @@ public DayByDayDecisionsService getDayBydayDecisionService() { return dayBydayDecisionService; } + public void setStudentService(StudentService studentService) { + this.studentService = studentService; + } } Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartupService.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartupService.java 2009-08-18 18:41:59 UTC (rev 256) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartupService.java 2009-08-18 21:56:49 UTC (rev 257) @@ -16,33 +16,27 @@ public class StartupService implements ApplicationContextAware { //private QuestionCreatorService questionCreatorService; - private StudentService studentService; - private RoundService roundService; - private StartGame thread; + private StartGame startGame; private ApplicationContext ctx; /*public void setQuestionCreatorService(QuestionCreatorService questionCreatorService) { this.questionCreatorService = questionCreatorService; }*/ - public void setStudentService(StudentService studentService) { - this.studentService = studentService; - } - public Student createStudent(Integer birthYear, String semester,String gender,String major) { + public Student createStudent(Student student) { - return studentService.createStudent(birthYear, semester, gender, major); + return getStartGame().createStudent(student); } public Game createGame(Game game) { - return roundService.createGame(game); - + return getStartGame().createGame(game); } public void assignGroups() { - studentService.assignGroups(); + getStartGame().assignGroups(); } public void startGame() @@ -50,20 +44,12 @@ //push assign groups to all the students //start the game - try{ - if (thread == null) { - thread = (StartGame)ctx.getBean("startGame"); - thread.run(); - } - }catch(Exception e) - { - System.out.println(e.getStackTrace()); - } + } public void stop() { - thread.setRunning(false); - thread = null; + startGame.setRunning(false); + startGame = null; } @@ -72,15 +58,24 @@ throws BeansException { // TODO Auto-generated method stub this.ctx = context; - } - public void setRoundService(RoundService roundService) { - this.roundService = roundService; + + public void setStartGame() { + try{ + if (startGame == null) { + this.startGame = (StartGame)ctx.getBean("startGame"); + //this.startGame.run(); + } + }catch(Exception e) + { + System.out.println(e.getStackTrace()); + } } - public RoundService getRoundService() { - return roundService; + public StartGame getStartGame() { + + return startGame; } Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StudentService.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StudentService.java 2009-08-18 18:41:59 UTC (rev 256) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StudentService.java 2009-08-18 21:56:49 UTC (rev 257) @@ -5,9 +5,12 @@ import java.util.Date; import java.util.List; +import org.hibernate.Hibernate; import org.springframework.transaction.annotation.Transactional; +import edu.asu.commons.mme.dao.HibernateGroupDao; import edu.asu.commons.mme.dao.HibernateStudentDao; +import edu.asu.commons.mme.entity.Group; import edu.asu.commons.mme.entity.Student; /** @@ -22,33 +25,32 @@ @Transactional public class StudentService extends Service.Base<Student, HibernateStudentDao> { + HibernateGroupDao groupDao; + + + private List<Student> students = new ArrayList<Student>(); - - public Student createStudent(Integer birthYear, String semester,String gender,String major) { -// System.out.println("Birthyear " + birthYear); -// System.out.println("Ethnicity " + semester); -// System.out.println("Gender " + gender); -// System.out.println("Major " + major); - - Student student = new Student(); - student.setBirthYear(birthYear); - student.setSemester(semester); - student.setGender(gender); - student.setMajor(major); - student.setTimestamp(new Timestamp(new Date().getTime())); - save(student); - getLogger().debug("Student id is: " + student.getId()); - if(!checkStudentAlreadyExists(student)) + public Student createStudent(Student student) { + + Student studentSave = new Student(); + studentSave = student; + studentSave.setTimestamp(new Timestamp(new Date().getTime())); + save(studentSave); + getLogger().debug("Student id is: " + studentSave.getId()); + if(!checkStudentAlreadyExists(studentSave)) { - students.add(student); + students.add(studentSave); } else return null; - + Hibernate.initialize(student); + Hibernate.initialize(student.getGame()); + Hibernate.initialize(student.getGroup()); + return student; } - + public boolean checkStudentAlreadyExists(Student student) { for(int i = 0; i < students.size(); i++) @@ -59,56 +61,99 @@ } return false; } - - + + public void assignGroups() { //write an algorithm to form groups - + int totalStudents = students.size(); - int groupSize3=0; - int groupSize4=0; - int groupSize5=0; + int noOfGroupsWithSize3=0; + int noOfGroupsWithSize4=0; + int noOfGroupsWithSize5=0; int x; - - - //no of groups - groupSize5=((int)(totalStudents/5)); - x= totalStudents%5; - /* if(x==0) + //no of groups + noOfGroupsWithSize5=((int)(totalStudents/5)); + + x= totalStudents%5; + + /* if(x==0) { totalGroups=groupSize5; } else*/ - if(x==1) - { - groupSize5=groupSize5 - 1; - groupSize3=2; - // totalGroups=groupSize5 + groupSize3; - } + if(x==1) + { + noOfGroupsWithSize5=noOfGroupsWithSize5 - 1; + noOfGroupsWithSize3=2; + // totalGroups=groupSize5 + groupSize3; + } - else if(x==2) - { - groupSize5=groupSize5-1; - groupSize3=1; - groupSize4=1; - // totalGroups=groupSize5 + groupSize3 + groupSize4; - } - else if(x==3) - { - groupSize3=1; - // totalGroups=groupSize3 + groupSize5; - } + else if(x==2) + { + noOfGroupsWithSize5=noOfGroupsWithSize5-1; + noOfGroupsWithSize4=1; + noOfGroupsWithSize3=1; + // totalGroups=groupSize5 + groupSize3 + groupSize4; + } + else if(x==3) + { + noOfGroupsWithSize3=1; + // totalGroups=groupSize3 + groupSize5; + } - else if(x==4) - { - groupSize4=1; -// totalGroups=groupSize4 + groupSize5; - } - + else if(x==4) + { + noOfGroupsWithSize4=1; + // totalGroups=groupSize4 + groupSize5; + } + //assign every student a number and group + if(!students.isEmpty()) + { + assignGroupstoStudents(5,noOfGroupsWithSize5); + assignGroupstoStudents(4,noOfGroupsWithSize4); + assignGroupstoStudents(3,noOfGroupsWithSize3); + + } + } - + + private void assignGroupstoStudents(int groupSize, int noOfGroups) { + // TODO Auto-generated method stub + Student student = new Student(); + + for(int grpno = 0,studentNo = 1; grpno < noOfGroups; grpno++,studentNo++) + { + //create group + Group grp = new Group(); + grp.setNumber(grpno + 1); + getGroupDao().save(grp); + for(int i = 0; i < groupSize; i++) + { + //get a student from a list + student = students.get(i); + if(student.getGroup() == null) + { + //assign student no and group to each student + student.setStudentNo(studentNo); + student.setGroup(grp); + students.remove(i); + } + } + } + } + + + + public HibernateGroupDao getGroupDao() { + return groupDao; + } + + public void setGroupDao(HibernateGroupDao groupDao) { + this.groupDao = groupDao; + } + } Modified: mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml =================================================================== --- mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml 2009-08-18 18:41:59 UTC (rev 256) +++ mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml 2009-08-18 21:56:49 UTC (rev 257) @@ -34,6 +34,10 @@ <property name='sessionFactory' ref='sessionFactory'/> </bean> + <bean id='groupDao' class='edu.asu.commons.mme.dao.HibernateGroupDao'> + <property name='sessionFactory' ref='sessionFactory'/> + </bean> + <bean id='roundConfigDao' class='edu.asu.commons.mme.dao.HibernateRoundConfigDao'> <property name='sessionFactory' ref='sessionFactory'/> </bean> @@ -139,6 +143,7 @@ <bean id='studentService' class='edu.asu.commons.mme.service.StudentService'> <property name='dao' ref='studentDao'/> + <property name='groupDao' ref='groupDao'/> </bean> <!-- spring managed service layer --> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |