[virtualcommons-svn] SF.net SVN: virtualcommons:[284] mentalmodels/trunk/src/main/java/edu/asu/ com
Status: Beta
Brought to you by:
alllee
|
From: <see...@us...> - 2009-10-01 01:17:03
|
Revision: 284
http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=284&view=rev
Author: seematalele
Date: 2009-10-01 01:16:55 +0000 (Thu, 01 Oct 2009)
Log Message:
-----------
1) Created GameService.java. Need to enter into the ApplicationContext file.
2) Changed the assignGrouptoStudents method. Need to test it.Sometimes it creates groups in the database, sometimes it does not.
Modified Paths:
--------------
mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Student.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
Added Paths:
-----------
mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/GameService.java
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-09-28 22:57:24 UTC (rev 283)
+++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Student.java 2009-10-01 01:16:55 UTC (rev 284)
@@ -44,7 +44,6 @@
@Temporal(TemporalType.TIMESTAMP)
private Date timestamp;
-
private String gender;
Added: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/GameService.java
===================================================================
--- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/GameService.java (rev 0)
+++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/GameService.java 2009-10-01 01:16:55 UTC (rev 284)
@@ -0,0 +1,11 @@
+package edu.asu.commons.mme.service;
+
+import edu.asu.commons.mme.dao.HibernateGameDao;
+import edu.asu.commons.mme.entity.Game;
+
+public class GameService extends Service.Base<Game, HibernateGameDao>{
+
+
+
+
+}
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-09-28 22:57:24 UTC (rev 283)
+++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java 2009-10-01 01:16:55 UTC (rev 284)
@@ -1,5 +1,6 @@
package edu.asu.commons.mme.service;
+import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import edu.asu.commons.mme.entity.Block;
@@ -53,9 +54,30 @@
}
- public List<Student> assignGroups()
+ public List<Student> assignGroups(Game game)
{
- return studentService.assignGroups();
+ List<Student> students = null;
+ students = studentService.assignGroups(game);
+ if(students != null)
+ {
+ MessageBroker msgBroker = MessageBroker.getMessageBroker("_messageBroker");
+
+ String clientID = UUIDUtils.createUUID();
+ AsyncMessage msg = new AsyncMessage();
+ msg.setDestination("mme");
+ String msgDestination = game.getGameCode();
+ msg.setHeader("DSSubtopic", msgDestination);
+ msg.setClientId(clientID);
+ msg.setMessageId(UUIDUtils.createUUID());
+ msg.setTimestamp(System.currentTimeMillis());
+
+ msg.setBody(students);
+ System.out.println("Message broker is: "+ msgBroker);
+ System.out.println("Students size is: " + students.size());
+
+ msgBroker.routeMessageToService(msg, null);
+ }
+ return students;
}
/**
@@ -84,7 +106,7 @@
//Push the first block to the clients
AsyncMessage msg = new AsyncMessage();
-
+
msg.setDestination("mme");
msg.setHeader("DSSubtopic", msgDestination);
msg.setClientId(clientID);
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-09-28 22:57:24 UTC (rev 283)
+++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartupService.java 2009-10-01 01:16:55 UTC (rev 284)
@@ -1,7 +1,6 @@
package edu.asu.commons.mme.service;
import java.util.ArrayList;
-import java.util.List;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
@@ -10,9 +9,6 @@
import edu.asu.commons.mme.entity.Game;
import edu.asu.commons.mme.entity.Student;
-import flex.messaging.MessageBroker;
-import flex.messaging.messages.AsyncMessage;
-import flex.messaging.util.UUIDUtils;
@Transactional
@@ -22,11 +18,16 @@
private StartGame startGame;
private ApplicationContext ctx;
private ArrayList<StartGame> currentGames;
+
+ private GameService gameService;
+ public void setGameService(GameService gameService) {
+ this.gameService = gameService;
+ }
+
/*public void setQuestionCreatorService(QuestionCreatorService questionCreatorService) {
this.questionCreatorService = questionCreatorService;
}*/
-
public Student createStudent(Student student) {
//Game game = student.getGame();
@@ -69,30 +70,14 @@
return newGame;
}
- public void assignGroups()
- {
- MessageBroker msgBroker = MessageBroker.getMessageBroker(null);
- String clientID = UUIDUtils.createUUID();
- AsyncMessage msg = new AsyncMessage();
- msg.setDestination("DataPush");
- //msg.setHeader("DSSubtopic", "hello");
- msg.setClientId(clientID);
- msg.setMessageId(UUIDUtils.createUUID());
- msg.setTimestamp(System.currentTimeMillis());
- List<Student> students = new ArrayList<Student>();
-
- msg.setBody(students);
- System.out.println("Message broker is: "+ msgBroker);
- System.out.println("Students size is: " + students.size());
-
- msgBroker.routeMessageToService(msg, null);
- }
-
public void startGame(Game game)
{
//push assign groups to all the students
- //assignGroups();
-
+
+ //FIXME: get persistence entity from database rather than using the game obejct came from Flex.
+
+ //Game gameEntity = gameDao.find(game.getId());
+
//start the game
System.out.println("Game came from client is to start: " + game.getId() + "size of currentGame is " + currentGames.size());
try
@@ -104,6 +89,7 @@
if(currentGames.get(i).getGame().getId().equals(game.getId()))
{
System.out.println("Game is found");
+ currentGames.get(i).assignGroups(game);
currentGames.get(i).run();
}
}
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-09-28 22:57:24 UTC (rev 283)
+++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StudentService.java 2009-10-01 01:16:55 UTC (rev 284)
@@ -1,8 +1,6 @@
package edu.asu.commons.mme.service;
-import java.sql.Timestamp;
import java.util.ArrayList;
-import java.util.Date;
import java.util.List;
import org.hibernate.Hibernate;
@@ -10,6 +8,7 @@
import edu.asu.commons.mme.dao.HibernateGroupDao;
import edu.asu.commons.mme.dao.HibernateStudentDao;
+import edu.asu.commons.mme.entity.Game;
import edu.asu.commons.mme.entity.Group;
import edu.asu.commons.mme.entity.Student;
@@ -26,33 +25,31 @@
public class StudentService extends Service.Base<Student, HibernateStudentDao> {
HibernateGroupDao groupDao;
- private List<Student> studentWithGroupsAssigned = new ArrayList<Student>();
- private List<Student> students = new ArrayList<Student>();
-
public Student createStudent(Student student) {
- Student studentSave = new Student();
- studentSave.setBirthYear(student.getBirthYear());
- studentSave.setGame(student.getGame());
- studentSave.setGameCode(student.getGameCode());
- studentSave.setGender(student.getGender());
- studentSave.setMajor(student.getMajor());
- studentSave.setSemester(student.getSemester());
- studentSave.setTimestamp(student.getTimestamp());
-
- //studentSave.setTimestamp(new Timestamp(new Date().getTime()));
- save(studentSave);
- getLogger().debug("Student id is: " + studentSave.getId());
- /*if(!checkStudentAlreadyExists(studentSave))
+ Student studentSave = null;
+ if(!checkStudentAlreadyExists(student))
{
- students.add(studentSave);
+ studentSave = new Student();
+ studentSave.setBirthYear(student.getBirthYear());
+ studentSave.setGame(student.getGame());
+ studentSave.setGameCode(student.getGameCode());
+ studentSave.setGender(student.getGender());
+ studentSave.setMajor(student.getMajor());
+ studentSave.setSemester(student.getSemester());
+ studentSave.setTimestamp(student.getTimestamp());
+
+ //studentSave.setTimestamp(new Timestamp(new Date().getTime()));
+ getDao().
+ save(studentSave);
+ getLogger().debug("Student id is: " + studentSave.getId());
+
}
- else
- return null;*/
+
initializeStudent(student);
- return student;
+ return studentSave;
}
private void initializeStudent(Student student) {
@@ -63,6 +60,8 @@
public boolean checkStudentAlreadyExists(Student student)
{
+ List<Student> students = new ArrayList<Student>();
+ students = getDao().findAllByProperty("game",student.getGame());
for(int i = 0; i < students.size(); i++)
{
if(students.get(i).equals(student)){
@@ -73,97 +72,152 @@
}
- public List<Student> assignGroups()
+ public List<Student> assignGroups(Game game)
{
- //write an algorithm to form groups
- int totalStudents = students.size();
- int noOfGroupsWithSize3=0;
- int noOfGroupsWithSize4=0;
- int noOfGroupsWithSize5=0;
- int x;
+ //createGroup(1);
+ List<Student> studentWithGroupsAssigned = new ArrayList<Student>();
+ List<Student> students = new ArrayList<Student>();
+ try{
+ getLogger().debug("In the assigngroups." + game.getId());
+ students = getDao().findAllByProperty("game", game);
+
+ getLogger().debug("test student object is : " + students.size());
+ if(students.size() > 1)
+ {
+ //write an algorithm to form groups
+ int totalStudents = students.size();
+ int noOfGroupsWithSize3=0;
+ int noOfGroupsWithSize4=0;
+ int noOfGroupsWithSize5=0;
+ int x;
- //no of groups
- noOfGroupsWithSize5=((int)(totalStudents/5));
- x= totalStudents%5;
+ //no of groups
+ noOfGroupsWithSize5=((int)(totalStudents/5));
- /* if(x==0)
+
+ x= totalStudents%5;
+
+ /* if(x==0)
{
totalGroups=groupSize5;
}
else*/
- if(x==1)
- {
- noOfGroupsWithSize5=noOfGroupsWithSize5 - 1;
- noOfGroupsWithSize3=2;
- // totalGroups=groupSize5 + groupSize3;
- }
+ if(x==1)
+ {
+ noOfGroupsWithSize5=noOfGroupsWithSize5 - 1;
+ noOfGroupsWithSize3=2;
+ // totalGroups=groupSize5 + groupSize3;
+ }
- 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==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)
- {
- noOfGroupsWithSize4=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);
+ getLogger().debug("size of 4 : " + noOfGroupsWithSize4);
+ getLogger().debug("size of 3 : " + noOfGroupsWithSize3);
+ getLogger().debug("size of 5 : " + noOfGroupsWithSize5);
+
+ //assign every student a number and group
+ if(!students.isEmpty())
+ {
+ if(noOfGroupsWithSize5 > 0)
+ {
+ studentWithGroupsAssigned.addAll(assignGroupstoStudents(5,noOfGroupsWithSize5,students));
+ getLogger().debug("student size after 5 is: " + students.size());
+ getLogger().debug("student with groups assigned: " + studentWithGroupsAssigned.size());
+ }
+ if(noOfGroupsWithSize4 > 0)
+ {
+ studentWithGroupsAssigned.addAll(assignGroupstoStudents(4,noOfGroupsWithSize4,students));
+ getLogger().debug("student size after 4 is: " + students.size());
+ getLogger().debug("student with groups assigned: " + studentWithGroupsAssigned.size());
+ }
+ if(noOfGroupsWithSize3 > 0)
+ {
+ studentWithGroupsAssigned.addAll(assignGroupstoStudents(3,noOfGroupsWithSize3,students));
+ getLogger().debug("student size after 3 is: " + students.size());
+ getLogger().debug("student with groups assigned: " + studentWithGroupsAssigned.size());
+ }
+ }
}
+ getLogger().debug("Final student with groups assigned: " + studentWithGroupsAssigned.size());
+ }catch(Exception e)
+ {
+ getLogger().error(e);
+ }
return studentWithGroupsAssigned;
}
- private void assignGroupstoStudents(int groupSize, int noOfGroups) {
+ private List<Student> assignGroupstoStudents(int groupSize, int noOfGroups,List<Student> students) {
// TODO Auto-generated method stub
Student student = new Student();
-
- for(int grpno = 0,studentNo = 1; grpno < noOfGroups; grpno++,studentNo++)
+ List<Student> studentWithGroupsAssigned = new ArrayList<Student>();
+ getLogger().debug("group size is : "+groupSize);
+ int k = 0;
+ for(int grpno = 0; grpno < noOfGroups; grpno++)
{
//create group
Group grp = new Group();
- grp.setNumber(grpno + 1);
- getGroupDao().save(grp);
- for(int i = 0; i < groupSize; i++)
+ k= grpno+1;
+ grp.setNumber(k);
+ groupDao.save(grp);
+ getLogger().info("Group is created with id: " + grp.getId());
+ int studentNo = 1;
+ int j = 0;
+ for(int i = 0; i <= groupSize-1 ; i++)
{
//get a student from a list
- student = students.get(i);
+ student = students.get(0);
+ getLogger().debug("i is: " + i +"student id is : "+student.getId());
if(student.getGroup() == null)
{
//assign student no and group to each student
+ getLogger().debug("group assigned is : " + grp.getId());
student.setStudentNo(studentNo);
student.setGroup(grp);
- save(student);
+ getDao().save(student);
+ studentNo++;
initializeStudent(student);
studentWithGroupsAssigned.add(student);
- students.remove(i);
+
+ students.remove(0);
}
+ j++;
}
}
+ return students;
}
-
-
- public HibernateGroupDao getGroupDao() {
+ public Group createGroup(int groupNo)
+ {
+ Group grp = new Group();
+ grp.setNumber(groupNo);
+ groupDao.save(grp);
+ getLogger().info("Group is created with id: " + grp.getId());
+ return grp;
+ }
+ /*public HibernateGroupDao getGroupDao() {
return groupDao;
- }
+ }*/
public void setGroupDao(HibernateGroupDao groupDao) {
this.groupDao = groupDao;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|