[virtualcommons-svn] SF.net SVN: virtualcommons:[354] mentalmodels/trunk/src/main/java/edu/asu/ com
Status: Beta
Brought to you by:
alllee
From: <see...@us...> - 2009-11-04 20:24:37
|
Revision: 354 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=354&view=rev Author: seematalele Date: 2009-11-04 20:24:26 +0000 (Wed, 04 Nov 2009) Log Message: ----------- Created a method getCurrentRoundNo(Game game) method in GameService. Bugs fixed : When first block was sent to the client, lazy initialization error was coming. Modified Paths: -------------- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/DayByDayDecisionsService.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/GameService.java Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/DayByDayDecisionsService.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/DayByDayDecisionsService.java 2009-11-03 20:19:28 UTC (rev 353) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/DayByDayDecisionsService.java 2009-11-04 20:24:26 UTC (rev 354) @@ -284,13 +284,13 @@ calculateHarvest(bay1StudentMap,"Bay1", game); /**calculateHarvest(bay2StudentMap,"Bay2"); calculateHarvest(bay3StudentMap,"Bay3"); - calculateHarvest(harborStudentMap,"Harbor"); + calculateHarvest(harborStudentMap,"Harbor"); **/ calculateTotalFishLeaving(game); - calculateFishReturned(); + /** calculateFishReturned(); - calculateNewPopulation(); **/ + calculateNewPopulation();**/ } @@ -446,14 +446,17 @@ double totalFishLeaving = 0; - Query query = studentDao.getCurrentSession().createQuery(groupsWithinGame); query.setLong("current_game_id", game.getId()); Iterator groups = query.list().iterator(); + GroupLocation groupLocation = null; while(groups.hasNext()) { - getLogger().debug("group id is: " + groups.next()); + Group group = (Group) groups.next(); + getLogger().debug("group id is: " + group.getId()); + groupLocation = groupLocationDao.findByProperty("group",group); + totalFishLeaving = totalFishLeaving + groupLocation.getFishLeaving(); } /*List<Student> students = studentDao.findAllByProperty("game", game); List<Long> groups = null; @@ -468,14 +471,9 @@ { groups.add(student.getGroup().getId()); } - } - */ + }*/ - /* for(Group group : groups) - { - totalFishLeaving = totalFishLeaving + location.getFishLeaving(); - } - setTotalFishLeaving(totalFishLeaving);*/ + setTotalFishLeaving(totalFishLeaving); } Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/GameService.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/GameService.java 2009-11-03 20:19:28 UTC (rev 353) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/GameService.java 2009-11-04 20:24:26 UTC (rev 354) @@ -6,6 +6,8 @@ import java.util.List; import java.util.Map; +import org.hibernate.Query; + import org.hibernate.Hibernate; import org.springframework.transaction.annotation.Transactional; @@ -60,6 +62,11 @@ MessageHandler msgHandler; + static final String roundNo = "SELECT gameRound.seqNo " + + "FROM GameRound gameRound, Game game " + + "where gameRound.gameConfig =:gameConfig and gameRound.round =:currentRound"; + + public GameService() { } @@ -143,7 +150,7 @@ { assignGroups(game); getLogger().debug("system has assigned groups. "); - //pushBlock(game); + pushBlock(game); flag = true; } else @@ -178,7 +185,6 @@ int i=0; try { - //while (i<noOfBlocks) { i++; newGameState = getBlock(game); game = newGameState; @@ -194,19 +200,7 @@ initializeCurrentBlock(block); msgHandler.sendBlock(block,newGameState); } - - /*if(block.getDescription().equalsIgnoreCase("Day-by-day decisions game")) - { - //start day by day decision - //getDayBydayDecisionService(). - - } - else if (block.getDescription().equalsIgnoreCase("Communication")) - { - //start communication round - - }*/ - //} + }catch (Exception e) { getLogger().debug(e); } @@ -815,10 +809,10 @@ Hibernate.initialize(questionGroup); // getLogger().debug(questionGroup.getDescription()); List<Question> questions = questionGroup.getQuestions(); - + Hibernate.initialize(questions); for(int j = 0; j < questions.size(); j++) { - Hibernate.initialize(questions.get(j)); + ///Hibernate.initialize(questions.get(j)); if(questions.get(j).getClass().getName().equalsIgnoreCase("edu.asu.commons.mme.entity.CategoricalQuestion")) { CategoricalQuestion categoricalQ = (CategoricalQuestion)questions.get(j); @@ -828,6 +822,7 @@ } } } + Module module = block.getModule(); Hibernate.initialize(module); @@ -892,17 +887,25 @@ setCurrentRound(currentRound); }*/ - - /*private int getCurrentRoundNo() { + // get the game as an parameter + private int getCurrentRoundNo(Game game) { // TODO Auto-generated method stub //FIXME: Game id 1 is hard coded but needs to make it dynamic - //Game game = gameDao.find(1L); - if(getCurrentGame().getCurrentRound() == null) - return 0; - else - return getCurrentGame().getCurrentRound().getRoundNo(); + Integer roundNo = 0; + Game currentGame = getDao().find(game.getId()); + if(currentGame.getCurrentRound() != null) + { + Query query = getDao().getCurrentSession().createQuery(GameService.roundNo); + query.setEntity("round", currentGame.getCurrentRound()); + query.setEntity("gameConfig", currentGame.getGameConfig()); + if(query.list().size() == 1) + roundNo = (Integer) query.list().get(0); + } + + return roundNo; - }*/ + } + public boolean isGameFinished(Game game) { GameConfig gameConfig = game.getGameConfig(); List<GameRound> gameRounds = getGameRoundDao().findAllByProperty("gameConfig",game.getGameConfig()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |