[virtualcommons-svn] SF.net SVN: virtualcommons:[228] mentalmodels/trunk/src/main
Status: Beta
Brought to you by:
alllee
From: <see...@us...> - 2009-08-07 00:57:44
|
Revision: 228 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=228&view=rev Author: seematalele Date: 2009-08-07 00:57:34 +0000 (Fri, 07 Aug 2009) Log Message: ----------- Created HibernateGameDao.java and HibernateModuleRoundConfigDao.java Written code in RoundService.java which will return blocks but it is not working properly. StartGame.java pushes block to the clients once time is over. This code is not properly working. Deleted Gender.java Modified Paths: -------------- mentalmodels/trunk/src/main/db/init-mme.sql mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Game.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/AnsweringService.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/Feed.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/ModuleService.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/QuestionCreatorService.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/RoundService.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 mentalmodels/trunk/src/main/webapp/WEB-INF/hibernate.cfg.xml mentalmodels/trunk/src/main/webapp/WEB-INF/web.xml mentalmodels/trunk/src/main/webapp/startfeed.jsp Added Paths: ----------- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/dao/HibernateGameDao.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/dao/HibernateModuleRoundConfigDao.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java mentalmodels/trunk/src/main/webapp/StartGame.swf mentalmodels/trunk/src/main/webapp/WEB-INF/classes/applicationContext.xml Removed Paths: ------------- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Gender.java Modified: mentalmodels/trunk/src/main/db/init-mme.sql =================================================================== --- mentalmodels/trunk/src/main/db/init-mme.sql 2009-08-06 22:00:47 UTC (rev 227) +++ mentalmodels/trunk/src/main/db/init-mme.sql 2009-08-07 00:57:34 UTC (rev 228) @@ -262,31 +262,13 @@ -- Table structure for table `game` -- -DROP TABLE IF EXISTS `game`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `game` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `description` longtext, - `image_location` varchar(255) DEFAULT NULL, - `max_days` int(11) NOT NULL, - `max_fish_harvest` int(11) NOT NULL, - `money` double DEFAULT NULL, - `no_of_locations` int(11) NOT NULL, - `no_of_rounds` int(11) NOT NULL, - `timestamp` datetime NOT NULL, - `title` varchar(255) NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Dumping data for table `game` -- LOCK TABLES `game` WRITE; /*!40000 ALTER TABLE `game` DISABLE KEYS */; -INSERT INTO `game` VALUES (1,'First game','island.jpg',30,5,0,4,3,'2009-07-19 17:30:35','Mental Model Experiment'); +INSERT INTO `game` VALUES (1,'First game','island.jpg',30,5,0,4,3,'2009-07-19 17:30:35','Mental Model Experiment',null,null); /*!40000 ALTER TABLE `game` ENABLE KEYS */; UNLOCK TABLES; @@ -450,7 +432,7 @@ LOCK TABLES `module_round_config` WRITE; /*!40000 ALTER TABLE `module_round_config` DISABLE KEYS */; -INSERT INTO `module_round_config` VALUES (1,1,2,1),(2,1,3,2),(3,2,2,2); +INSERT INTO `module_round_config` VALUES (1,1,1,1),(2,1,2,2),(3,1,3,3),(4,2,4,3),(5,1,5,4); /*!40000 ALTER TABLE `module_round_config` ENABLE KEYS */; UNLOCK TABLES; @@ -593,7 +575,7 @@ LOCK TABLES `round_config` WRITE; /*!40000 ALTER TABLE `round_config` DISABLE KEYS */; -INSERT INTO `round_config` VALUES (1,0,1,1,NULL),(2,1,2,1,NULL); +INSERT INTO `round_config` VALUES (1,0,1,1,NULL),(2,0,2,1,NULL),(3,1,3,1,NULL),(4,0,4,1,NULL); /*!40000 ALTER TABLE `round_config` ENABLE KEYS */; UNLOCK TABLES; Added: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/dao/HibernateGameDao.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/dao/HibernateGameDao.java (rev 0) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/dao/HibernateGameDao.java 2009-08-07 00:57:34 UTC (rev 228) @@ -0,0 +1,12 @@ +package edu.asu.commons.mme.dao; + +import edu.asu.commons.mme.entity.Game; + +public class HibernateGameDao extends HibernateDao<Game>{ + + public HibernateGameDao() + { + super(Game.class); + } + +} Added: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/dao/HibernateModuleRoundConfigDao.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/dao/HibernateModuleRoundConfigDao.java (rev 0) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/dao/HibernateModuleRoundConfigDao.java 2009-08-07 00:57:34 UTC (rev 228) @@ -0,0 +1,13 @@ +package edu.asu.commons.mme.dao; + +import edu.asu.commons.mme.entity.ModuleRoundConfig; + +public class HibernateModuleRoundConfigDao extends HibernateDao<ModuleRoundConfig> +{ + + public HibernateModuleRoundConfigDao() { + super(ModuleRoundConfig.class); + // TODO Auto-generated constructor stub + } + +} Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Game.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Game.java 2009-08-06 22:00:47 UTC (rev 227) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Game.java 2009-08-07 00:57:34 UTC (rev 228) @@ -10,6 +10,7 @@ import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.Lob; +import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; @@ -55,14 +56,22 @@ @JoinColumn(name="rounds_id") private List<Round> rounds; + @ManyToOne + @JoinColumn(name="current_round_id", nullable=true) + private Round currentRound; + + @ManyToOne + @JoinColumn(name="current_block_id", nullable=true) + private Block currentBlock; + + public void setId(Long id) { this.id = id; } public Long getId() { return id; } - - + public void setTitle(String title) { this.title = title; } @@ -130,6 +139,18 @@ public void setRounds(List<Round> rounds) { this.rounds = rounds; } + public void setCurrentRound(Round currentRound) { + this.currentRound = currentRound; + } + public Round getCurrentRound() { + return currentRound; + } + public void setCurrentBlock(Block currentBlock) { + this.currentBlock = currentBlock; + } + public Block getCurrentBlock() { + return currentBlock; + } } Deleted: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Gender.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Gender.java 2009-08-06 22:00:47 UTC (rev 227) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Gender.java 2009-08-07 00:57:34 UTC (rev 228) @@ -1,5 +0,0 @@ -package edu.asu.commons.mme.entity; - -public enum Gender { - F, M -} Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/AnsweringService.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/AnsweringService.java 2009-08-06 22:00:47 UTC (rev 227) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/AnsweringService.java 2009-08-07 00:57:34 UTC (rev 228) @@ -23,7 +23,7 @@ StudentResponse studentResponse; Student student; - public Block saveQuestion(List<StudentResponse> studentResponses) + public void saveQuestion(List<StudentResponse> studentResponses) { for(int i = 0; i < studentResponses.size(); i++ ) { @@ -37,7 +37,7 @@ save(studentResponse); } - return moduleService.getNextBlock(); + //return moduleService.getBlock(); } public void daybydayOutput(DayByDayDecisions studentDecision) 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-06 22:00:47 UTC (rev 227) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/Feed.java 2009-08-07 00:57:34 UTC (rev 228) @@ -1,70 +1,50 @@ package edu.asu.commons.mme.service; -//package edu.asu.commons.mme.service; -import flex.messaging.MessageBroker; -import flex.messaging.messages.AsyncMessage; -import flex.messaging.util.UUIDUtils; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; -public class Feed{ +public class Feed implements ApplicationContextAware{ public static void main(String args[]) { Feed feed = new Feed(); feed.start(); } - - private static FeedThread thread; + private StartGame thread; + private ApplicationContext ctx; + public Feed() { } public void start() { - if (thread == null) { - thread = new FeedThread(); - thread.start(); + + try{ + if (thread == null) { + thread = (StartGame)ctx.getBean("startGame"); + thread.run(); + } + }catch(Exception e) + { + System.out.println(e.getStackTrace()); } } public void stop() { - thread.running = false; + thread.setRunning(false); thread = null; } - public static class FeedThread extends Thread { + @Override + public void setApplicationContext(ApplicationContext context) + throws BeansException { + // TODO Auto-generated method stub + this.ctx = context; - public boolean running = true; + } - public void run() { - MessageBroker msgBroker = MessageBroker.getMessageBroker(null); - String clientID = UUIDUtils.createUUID(); - - while (running) { - - try { - Thread.sleep(50000); - running = false; - } catch (InterruptedException e) { - } - AsyncMessage msg = new AsyncMessage(); - msg.setDestination("DataPush"); - //msg.setHeader("DSSubtopic", "hello"); - msg.setClientId(clientID); - msg.setMessageId(UUIDUtils.createUUID()); - msg.setTimestamp(System.currentTimeMillis()); - msg.setBody("Sorry time is expired!!! You can not Login."); - System.out.println("Message broker is: "+ msgBroker); - System.out.println("Message is: "+ msg); - msgBroker.routeMessageToService(msg, null); - - - - } - } - - - } - /*@Override public Object invoke(Message msg) { // TODO Auto-generated method stub Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/ModuleService.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/ModuleService.java 2009-08-06 22:00:47 UTC (rev 227) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/ModuleService.java 2009-08-07 00:57:34 UTC (rev 228) @@ -6,26 +6,180 @@ import org.hibernate.Hibernate; import org.springframework.transaction.annotation.Transactional; +import edu.asu.commons.mme.dao.HibernateGameDao; import edu.asu.commons.mme.dao.HibernateModuleDao; +import edu.asu.commons.mme.dao.HibernateModuleRoundConfigDao; import edu.asu.commons.mme.entity.Block; import edu.asu.commons.mme.entity.CategoricalOption; import edu.asu.commons.mme.entity.CategoricalQuestion; +import edu.asu.commons.mme.entity.Game; import edu.asu.commons.mme.entity.InformationWindow; import edu.asu.commons.mme.entity.Module; import edu.asu.commons.mme.entity.Question; import edu.asu.commons.mme.entity.QuestionGroup; +import edu.asu.commons.mme.entity.Round; @Transactional public class ModuleService extends Service.Base<Module, HibernateModuleDao>{ + + private HibernateGameDao gameDao; + private HibernateModuleRoundConfigDao moduleRoundConfigDao; + private Module currentModule; + private boolean startGame = true; + private Round currentRound; + private int blockSeqNo; + private Block currentBlock; - public Module getModule(int moduleNumber) + + public void test() { - // Enter the sequence number in new Integer(Sequence number of module u want to fetch) + getLogger().debug("test to check if module service is working...." ); + } + + public Block getBlock(Module module, int seqNo) + { + //Module module = new Module(); + // module = currentModule; + Block block = new Block(); + for(int i = 0; i < module.getBlocks().size(); i++) + { + block = module.getBlocks().get(i); + if(block.getSequenceNo() == seqNo) + { + return block; + } + } + + return block; + } + /* + *1) Find out the current round number + *2) Find out the current module number + *3) Find out the current block number + *4) Return the next block + */ + + + /*public Block getNextBlock() + { + int currentRoundNo = getCurrentRoundNo(); + getLogger().debug("current round number is: " + currentRoundNo); + + if(currentRoundNo == 0) + { + //get first round no + currentRound = getRound(1); + + } + currentBlock = new Block(); + //getLogger().debug("start module " + getStartModule()); + if(currentModule == null) + { + if(startGame) + { + //get the first module + currentModule = new Module(); + currentModule = getModule(1); + + //get the first block in the first module + currentBlock = getBlock(currentModule, 1); + // blockSeqNo = 1; + getLogger().debug(currentBlock.getDescription()); + //get the current game and set the current round and current block ids + + saveGameState(currentRound, currentBlock); + + startGame = false; + + //getBlock() + } + else if(isModuleFinished(currentModule)) + { + //get the current game + //get the current round + currentRound = getCurrentRound(); + //get the current module in the round + } + } + + else + { + + } + return currentBlock; + + }*/ + + + private Round getRound(int roundNo) { + // TODO Auto-generated method stub + currentRound = new Round(); + + + return null; + } + + private int getCurrentRoundNo() { + // TODO Auto-generated method stub + //FIXME: Game id 1 is hard coded but needs to make it dynamic + Game game = gameDao.find(1L); + if(game.getCurrentRound() == null) + return 0; + else + return game.getCurrentRound().getRoundNo(); + + } + + private boolean isModuleFinished(Module module) { + // TODO Auto-generated method stub + Block block = new Block(); + block = getFinishedBlock(); + module.getBlocks().size(); + //if(current) + return false; + } + + private Block getFinishedBlock() { + // TODO Auto-generated method stub + Block block = new Block(); + return block; + } + + private void saveGameState(Round round, Block block) { + + + //FIXME: Game id 1 is hard coded but needs to make it dynamic + Game game = gameDao.find(1L); + game.setCurrentBlock(block); + game.setCurrentRound(round); + gameDao.save(game); + + } + + public Module getModule(Round round, int moduleNumber) + { + // Enter the sequence number in new Integer(Sequence number of module u want to fetch) + Module module = getDao().findByProperty("sequenceNo", moduleNumber); - + Hibernate.initialize(module); getLogger().debug("Module object is " + module.getDescription()); - + initializeModule(module); + + return module; + } + + + public Integer getTimerforBlock(Block block) + { + return block.getDuration(); + + } + + + private void initializeModule(Module module) + { + // TODO Auto-generated method stub Iterator<Block> iterateBlock = module.getBlocks().iterator(); while(iterateBlock.hasNext()) { @@ -42,8 +196,9 @@ { QuestionGroup questionGroup = iteratorquestionGrp.next(); Hibernate.initialize(questionGroup); + // getLogger().debug(questionGroup.getDescription()); List<Question> questions = questionGroup.getQuestions(); - + for(int j = 0; j < questions.size(); j++) { Hibernate.initialize(questions.get(j)); @@ -56,24 +211,68 @@ } } } - + } - return module; + + } - public Block getNextBlock() { - /* - *1) Find out the current round number - *2) Find out the current module number - *3)Find out the current block number - *4)return the next block - */ - // TODO Auto-generated method stub - - - Block block = new Block(); - - return block; + + + + public void setCurrentModule(Module currentModule) { + this.currentModule = currentModule; } - + + + public Module getCurrentModule() { + return currentModule; + } + + + public void setCurrentRound(Round currentRound) { + this.currentRound = currentRound; + } + + + public Round getCurrentRound() { + return currentRound; + } + + + public void setStartModule(Boolean startModule) { + this.startGame = startModule; + } + + + public Boolean getStartModule() { + return startGame; + } + + + public void setGameDao(HibernateGameDao gameDao) { + this.gameDao = gameDao; + } + + public HibernateGameDao getGameDao() { + return gameDao; + } + + public void setBlockSeqNo(int blockSeqNo) { + this.blockSeqNo = blockSeqNo; + } + + public int getBlockSeqNo() { + return blockSeqNo; + } + + public void setModuleRoundConfigDao(HibernateModuleRoundConfigDao moduleRoundConfigDao) { + this.moduleRoundConfigDao = moduleRoundConfigDao; + } + + public HibernateModuleRoundConfigDao getModuleRoundConfigDao() { + return moduleRoundConfigDao; + } + + } Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/QuestionCreatorService.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/QuestionCreatorService.java 2009-08-06 22:00:47 UTC (rev 227) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/QuestionCreatorService.java 2009-08-07 00:57:34 UTC (rev 228) @@ -1,11 +1,8 @@ package edu.asu.commons.mme.service; -import java.lang.reflect.Field; import java.util.ArrayList; -import java.util.Arrays; import java.util.Iterator; import java.util.List; -import java.util.Set; import org.hibernate.Hibernate; import org.springframework.transaction.annotation.Transactional; @@ -17,14 +14,13 @@ import edu.asu.commons.mme.dao.HibernateQuestionDao; import edu.asu.commons.mme.dao.HibernateQuestionGroupDao; import edu.asu.commons.mme.entity.Block; -import edu.asu.commons.mme.entity.CategoricalQuestion; import edu.asu.commons.mme.entity.CategoricalOption; +import edu.asu.commons.mme.entity.CategoricalQuestion; import edu.asu.commons.mme.entity.InformationWindow; import edu.asu.commons.mme.entity.Module; import edu.asu.commons.mme.entity.PsychometricQuestion; import edu.asu.commons.mme.entity.Question; import edu.asu.commons.mme.entity.QuestionGroup; -import edu.asu.commons.mme.entity.Round; /** 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-06 22:00:47 UTC (rev 227) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/RoundService.java 2009-08-07 00:57:34 UTC (rev 228) @@ -1,20 +1,390 @@ package edu.asu.commons.mme.service; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.hibernate.Hibernate; +import org.hibernate.criterion.MatchMode; +import org.springframework.transaction.annotation.Transactional; + +import edu.asu.commons.mme.dao.HibernateBlockDao; +import edu.asu.commons.mme.dao.HibernateGameDao; +import edu.asu.commons.mme.dao.HibernateModuleDao; +import edu.asu.commons.mme.dao.HibernateModuleRoundConfigDao; import edu.asu.commons.mme.dao.HibernateRoundConfigDao; +import edu.asu.commons.mme.entity.Block; +import edu.asu.commons.mme.entity.CategoricalOption; +import edu.asu.commons.mme.entity.CategoricalQuestion; +import edu.asu.commons.mme.entity.Game; +import edu.asu.commons.mme.entity.InformationWindow; import edu.asu.commons.mme.entity.Module; +import edu.asu.commons.mme.entity.ModuleRoundConfig; +import edu.asu.commons.mme.entity.Question; +import edu.asu.commons.mme.entity.QuestionGroup; import edu.asu.commons.mme.entity.Round; +@Transactional public class RoundService extends Service.Base<Round, HibernateRoundConfigDao> { - private ModuleService moduleService; + private HibernateModuleDao moduleDao; + private HibernateBlockDao blockDao; + private HibernateGameDao gameDao; + private HibernateModuleRoundConfigDao moduleRoundDao; + + private Module currentModule; + private boolean startGame = true; + private Round currentRound; + private int blockSeqNo; + //private Block currentBlock; + + + public Module getNextModule(int sequenceNo) + { + return getModule(sequenceNo); + } + + + public void test() + { + getLogger().debug("test to check if module service is working...." ); + } - public void setModuleService(ModuleService moduleService) { - this.moduleService = moduleService; + public Block getBlock() + { + /* + *1) Find out the current round number + *2) Find out the current module number + *3) Find out the current block number + *4) Return the next block + */ + currentRound = new Round(); + int currentRoundNo = getCurrentRoundNo(); + getLogger().debug("current round number is: " + currentRoundNo); + Block currentBlock = null; + if(currentRoundNo == 0) + { + //get first round no + getLogger().debug("in if loop"); + setRound(1); + + currentModule = new Module(); + setModule(); + + //get the first block in the first module + currentBlock = new Block(); + currentBlock = getBlock(1); + getLogger().debug(currentBlock.getDescription()); + + //get the current game and set the current round and current block ids + saveGameState(currentBlock); + } + + else + { + /**Check if the current module is finished , if yes then get next module + * if no then get next block + */ + if(isCurrentModuleFinished(currentBlock)) + { + //get next module if any, else get next round + + getNextModule(); + } + else + { + //get next block + getNextBlock(getCurrentBlock()); + } + } + initializeCurrentBlock(currentBlock); + return currentBlock; + } + + private void setModule() { + // TODO Auto-generated method stub + + ModuleRoundConfig moduleRoundconfig = new ModuleRoundConfig(); + + moduleRoundconfig.setRound(currentRound); + getLogger().debug("currentround id is "+ currentRound.getId()); + moduleRoundconfig.setSequenceNo(1); + List<ModuleRoundConfig> moduleRoundConfigs = new ArrayList<ModuleRoundConfig> (); + + moduleRoundConfigs = moduleRoundDao.findByExampleLike(moduleRoundconfig, MatchMode.EXACT); + getLogger().debug("module size is " + moduleRoundConfigs.size()); + if(moduleRoundConfigs.size() == 1) + { + setCurrentModule(moduleRoundConfigs.get(0).getModule()); + getLogger().debug("module is set " + currentModule.getDescription()); + } + //return moduleRoundConfig; + } - public Module getNextModule(int sequenceNo) + + private void getNextModule() { + // TODO Auto-generated method stub + //moduleRoundDao.findAllByProperty("", propertyValue) + + } + + + public HibernateModuleDao getModuleDao() { + return moduleDao; + } + + + public void setModuleDao(HibernateModuleDao moduleDao) { + this.moduleDao = moduleDao; + } + + + private void initializeCurrentBlock(Block currentBlock) { + // TODO Auto-generated method stub + + Hibernate.initialize(currentBlock); + Iterator<QuestionGroup> iteratorquestionGrp = currentBlock.getQuestionGroups().iterator(); + { + while(iteratorquestionGrp.hasNext()) + { + QuestionGroup questionGroup = iteratorquestionGrp.next(); + Hibernate.initialize(questionGroup); +// getLogger().debug(questionGroup.getDescription()); + List<Question> questions = questionGroup.getQuestions(); + + for(int j = 0; j < questions.size(); 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); + Iterator<CategoricalOption> categoricalOption = categoricalQ.getCategoricalOptions().iterator(); + Hibernate.initialize(categoricalOption); + } + } + } + } + + } + private void getNextBlock(Block currentBlock) { + // TODO Auto-generated method stub + List<Block> blocks = new ArrayList<Block>(); + blocks = currentModule.getBlocks(); + + for(int i = 0; i < blocks.size(); i++) + { + if(currentBlock.getSequenceNo() < blocks.get(i).getSequenceNo()) + { + currentBlock = blocks.get(i); + } + + } + + } + + public Module getModule(int moduleNumber) { - return moduleService.getModule(sequenceNo); + // Enter the sequence number in new Integer(Sequence number of module u want to fetch) + + Module module = moduleDao.findByProperty("sequenceNo", moduleNumber); + + Hibernate.initialize(module); + getLogger().debug("Module object is " + module.getDescription()); + initializeModule(module); + + return module; } + + public Block getBlock(int seqNo) + { + //Module module = new Module(); + // module = currentModule; + Block block = new Block(); + for(int i = 0; i < currentModule.getBlocks().size(); i++) + { + block = currentModule.getBlocks().get(i); + if(block.getSequenceNo() == seqNo) + { + return block; + } + } + + return block; + } + + private void setRound(int roundNo) { + // TODO Auto-generated method stub + currentRound = new Round(); + + currentRound = getDao().findByProperty("roundNo", roundNo); + //Hibernate.initialize(currentRound); + //getLogger().debug("currentround object is "+ currentRound.getId()); + setCurrentRound(currentRound); + + } + + private int getCurrentRoundNo() { + // TODO Auto-generated method stub + //FIXME: Game id 1 is hard coded but needs to make it dynamic + Game game = gameDao.find(1L); + if(game.getCurrentRound() == null) + return 0; + else + return game.getCurrentRound().getRoundNo(); + + } + + private boolean isCurrentModuleFinished(Block currentBlock) { + // TODO Auto-generated method stub + List<Block> blocks = new ArrayList<Block>(); + blocks = currentModule.getBlocks(); + //select max(b.sequence_no) from block b where b.module_id=2; + + for(int i = 0; i < blocks.size(); i++) + { + if(currentBlock.getSequenceNo() < blocks.get(i).getSequenceNo()) + { + return false; + } + else + return true; + } + return false; + } + + private void saveGameState(Block currentBlock) { + + + //FIXME: Game id 1 is hard coded but needs to make it dynamic + Game game = gameDao.find(1L); + game.setCurrentBlock(currentBlock); + game.setCurrentRound(currentRound); + gameDao.save(game); + } + + + public Integer getTimerforBlock(Block block) + { + return block.getDuration(); + + } + + + private void initializeModule(Module module) + { + // TODO Auto-generated method stub + Iterator<Block> iterateBlock = module.getBlocks().iterator(); + while(iterateBlock.hasNext()) + { + Block block = iterateBlock.next(); + Hibernate.initialize(block); + Iterator<InformationWindow> infoWindow = block.getInformationWindows().iterator(); + while(infoWindow.hasNext()) + { + Hibernate.initialize(infoWindow.next()); + } + Iterator<QuestionGroup> iteratorquestionGrp = block.getQuestionGroups().iterator(); + { + while(iteratorquestionGrp.hasNext()) + { + QuestionGroup questionGroup = iteratorquestionGrp.next(); + Hibernate.initialize(questionGroup); + // getLogger().debug(questionGroup.getDescription()); + List<Question> questions = questionGroup.getQuestions(); + + for(int j = 0; j < questions.size(); 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); + Iterator<CategoricalOption> categoricalOption = categoricalQ.getCategoricalOptions().iterator(); + Hibernate.initialize(categoricalOption); + } + } + } + } + + } + + + } + + + public Block getCurrentBlock() { + //FIXEME: game id 1 is hard coded, it should be dynamic + Game game = gameDao.find(1L); + Block block = new Block(); + block = game.getCurrentBlock(); +// Hibernate.initialize(block); + + return block; + } + + + public void setCurrentModule(Module currentModule) { + this.currentModule = currentModule; + } + + + public Module getCurrentModule() { + return currentModule; + } + + + public void setCurrentRound(Round currentRound) { + this.currentRound = currentRound; + } + + + public Round getCurrentRound() { + return currentRound; + } + + + public void setStartModule(Boolean startModule) { + this.startGame = startModule; + } + + + public Boolean getStartModule() { + return startGame; + } + + + public void setGameDao(HibernateGameDao gameDao) { + this.gameDao = gameDao; + } + + public HibernateGameDao getGameDao() { + return gameDao; + } + + public void setBlockSeqNo(int blockSeqNo) { + this.blockSeqNo = blockSeqNo; + } + + public int getBlockSeqNo() { + return blockSeqNo; + } + public void setModuleRoundDao(HibernateModuleRoundConfigDao moduleRoundDao) { + this.moduleRoundDao = moduleRoundDao; + } + public HibernateModuleRoundConfigDao getModuleRoundDao() { + return moduleRoundDao; + } + public void setBlockDao(HibernateBlockDao blockDao) { + this.blockDao = blockDao; + } + public HibernateBlockDao getBlockDao() { + return blockDao; + } + + + + } Added: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java (rev 0) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java 2009-08-07 00:57:34 UTC (rev 228) @@ -0,0 +1,105 @@ +package edu.asu.commons.mme.service; + +import edu.asu.commons.mme.entity.Block; +import flex.messaging.MessageBroker; +import flex.messaging.messages.AsyncMessage; +import flex.messaging.util.UUIDUtils; + +public class StartGame extends Thread { + + private boolean running; + private RoundService roundService; + + public StartGame() + { + + System.out.println("module service object is "); + /*moduleService.test(); + moduleService.setStartModule(true);*/ + setRunning(true); + } + + /** + * 1)Initially first block will get pushed to all the clients. + * 2)get timer for that block + * 3)start the timer + * 4)Once the timer is over, push the next block + * + */ + public void run() { + + Block block = new Block(); + //roundService.test(); + roundService.setStartModule(true); + + MessageBroker msgBroker = MessageBroker.getMessageBroker(null); + String clientID = UUIDUtils.createUUID(); + + if(isGameOver()) + { + + } + else + { + while (running) { + + //Push the first block to the clients + AsyncMessage msg = new AsyncMessage(); + msg.setDestination("DataPush"); + //msg.setHeader("DSSubtopic", "hello"); + msg.setClientId(clientID); + msg.setMessageId(UUIDUtils.createUUID()); + msg.setTimestamp(System.currentTimeMillis()); + + block = roundService.getBlock(); + if(block != null) + { + 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); + + //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) { + } + } + else + { + running = false; + break; + } + + } + } + } + + + private boolean isGameOver() { + // TODO Auto-generated method stub + + return false; + } + + public RoundService getRoundService() { + return roundService; + } + + public void setRoundService(RoundService roundService) { + this.roundService = roundService; + } + + public void setRunning(boolean running) + { + this.running = running; + } + + + +} + 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-06 22:00:47 UTC (rev 227) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartupService.java 2009-08-07 00:57:34 UTC (rev 228) @@ -38,11 +38,11 @@ return studentService.createStudent(birthYear, semester, gender, major); } - public Module getFirstModule() + /*public Block getFirstBlock() { //studentService.formGroups(); - return moduleService.getModule(1); - } + return moduleService.getBlock(); + }*/ public void setModuleService(ModuleService moduleService) { 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-06 22:00:47 UTC (rev 227) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StudentService.java 2009-08-07 00:57:34 UTC (rev 228) @@ -1,14 +1,13 @@ package edu.asu.commons.mme.service; +import java.sql.Timestamp; import java.util.ArrayList; -import java.util.List; import java.util.Date; -import java.sql.Timestamp; +import java.util.List; import org.springframework.transaction.annotation.Transactional; import edu.asu.commons.mme.dao.HibernateStudentDao; -import edu.asu.commons.mme.entity.Gender; import edu.asu.commons.mme.entity.Student; /** Added: mentalmodels/trunk/src/main/webapp/StartGame.swf =================================================================== (Binary files differ) Property changes on: mentalmodels/trunk/src/main/webapp/StartGame.swf ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml =================================================================== --- mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml 2009-08-06 22:00:47 UTC (rev 227) +++ mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml 2009-08-07 00:57:34 UTC (rev 228) @@ -76,8 +76,15 @@ <property name='sessionFactory' ref='sessionFactory'/> </bean> - + <bean id='gameDao' class='edu.asu.commons.mme.dao.HibernateGameDao'> + <property name='sessionFactory' ref='sessionFactory'/> + </bean> + <bean id='moduleRoundDao' class='edu.asu.commons.mme.dao.HibernateModuleRoundConfigDao'> + <property name='sessionFactory' ref='sessionFactory'/> + </bean> + + <!-- spring managed service layer --> <bean id='dayByDayDecisionsService' class='edu.asu.commons.mme.service.DayByDayDecisionsService'> @@ -86,9 +93,11 @@ <bean id='roundService' class='edu.asu.commons.mme.service.RoundService'> <property name='dao' ref='roundConfigDao'/> - <property name='moduleService' ref='moduleService'/> - - </bean> + <property name='moduleDao' ref='moduleDao'/> + <property name='gameDao' ref='gameDao' /> + <property name='moduleRoundDao' ref='moduleRoundDao' /> + <property name='blockDao' ref='blockDao'/> +</bean> <bean id='answeringService' class='edu.asu.commons.mme.service.AnsweringService'> @@ -125,10 +134,24 @@ <!-- spring managed service layer --> <bean id='moduleService' class="edu.asu.commons.mme.service.ModuleService"> <property name='dao' ref='moduleDao'/> - </bean> + <property name='gameDao' ref='gameDao' /> + </bean> + + <!-- <bean id="testService" class="edu.asu.commons.mme.service.TestService"> + <property name='moduleService' ref='moduleService'/> + <property name="startModule" value="Testing String."/> + </bean> --> + <bean id="startGame" class="edu.asu.commons.mme.service.StartGame"> + <property name='roundService' ref='roundService'/> + </bean> + + <bean id="feed" class="edu.asu.commons.mme.service.Feed"> + + </bean> -<!-- Expose services for BlazeDS remoting --> + +<!-- Expose services for Flex/BlazeDS remoting --> <flex:remote-service ref="studentService" /> <flex:remote-service ref="moduleService" /> <flex:remote-service ref="questionCreatorService" /> @@ -136,6 +159,7 @@ <flex:remote-service ref="startupService" /> <flex:remote-service ref="answeringService" /> <flex:remote-service ref="locationService" /> + <flex:remote-service ref="feed" /> <!-- Flex related information ended--> Added: mentalmodels/trunk/src/main/webapp/WEB-INF/classes/applicationContext.xml =================================================================== --- mentalmodels/trunk/src/main/webapp/WEB-INF/classes/applicationContext.xml (rev 0) +++ mentalmodels/trunk/src/main/webapp/WEB-INF/classes/applicationContext.xml 2009-08-07 00:57:34 UTC (rev 228) @@ -0,0 +1,185 @@ +<?xml version="1.0"?> +<!-- + vim:sts=2:sw=2: +--> +<!-- + $Id: applicationContext.xml 617 2008-03-28 17:27:23Z alllee $ +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:flex="http://www.springframework.org/schema/flex" + xmlns:security="http://www.springframework.org/schema/security" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:aop="http://www.springframework.org/schema/aop" + xmlns:tx="http://www.springframework.org/schema/tx" + xsi:schemaLocation=" + + http://www.springframework.org/schema/tx + http://www.springframework.org/schema/tx/spring-tx-2.0.xsd + http://www.springframework.org/schema/aop + http://www.springframework.org/schema/aop/spring-aop-2.0.xsd + http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans-2.5.xsd + http://www.springframework.org/schema/flex + http://www.springframework.org/schema/flex/spring-flex-1.0.xsd + http://www.springframework.org/schema/security + http://www.springframework.org/schema/security/spring-security-2.0.4.xsd"> + + +<!-- Flex related information started --> + <flex:message-broker /> + +<!-- XXX: Split these out into separate XML files and import them if this file gets too large --> +<!-- spring managed daos --> + <bean id='studentDao' class='edu.asu.commons.mme.dao.HibernateStudentDao'> + <property name='sessionFactory' ref='sessionFactory'/> + </bean> + + <bean id='roundConfigDao' class='edu.asu.commons.mme.dao.HibernateRoundConfigDao'> + <property name='sessionFactory' ref='sessionFactory'/> + </bean> + + <bean id='moduleDao' class="edu.asu.commons.mme.dao.HibernateModuleDao"> + <property name='sessionFactory' ref='sessionFactory'/> + </bean> + + <bean id='blockDao' class='edu.asu.commons.mme.dao.HibernateBlockDao'> + <property name='sessionFactory' ref='sessionFactory'/> + </bean> + + <bean id='questionDao' class='edu.asu.commons.mme.dao.HibernateQuestionDao'> + <property name='sessionFactory' ref='sessionFactory'/> + </bean> + + <bean id='psychometricQuestionDao' class='edu.asu.commons.mme.dao.HibernatePsychometricQuestionDao'> + <property name='sessionFactory' ref='sessionFactory'/> + </bean> + + + <bean id='categoricalQuestionDao' class='edu.asu.commons.mme.dao.HibernateCategoricalQuestionDao'> + <property name='sessionFactory' ref='sessionFactory'/> + </bean> + + + <bean id='questionGroupDao' class='edu.asu.commons.mme.dao.HibernateQuestionGroupDao'> + <property name='sessionFactory' ref='sessionFactory'/> + </bean> + + <bean id='studentResponseDao' class='edu.asu.commons.mme.dao.HibernateStudentResponseDao'> + <property name='sessionFactory' ref='sessionFactory'/> + </bean> + + <bean id='dayByDayDecisionsDao' class='edu.asu.commons.mme.dao.HibernateDayByDayDecisionsDao'> + <property name='sessionFactory' ref='sessionFactory'/> + </bean> + + <bean id='locationDao' class='edu.asu.commons.mme.dao.HibernateLocationDao'> + <property name='sessionFactory' ref='sessionFactory'/> + </bean> + + <bean id='gameDao' class='edu.asu.commons.mme.dao.HibernateGameDao'> + <property name='sessionFactory' ref='sessionFactory'/> + </bean> + + +<!-- spring managed service layer --> + +<bean id='dayByDayDecisionsService' class='edu.asu.commons.mme.service.DayByDayDecisionsService'> + <property name='dao' ref='dayByDayDecisionsDao'/> + </bean> + +<bean id='roundService' class='edu.asu.commons.mme.service.RoundService'> + <property name='dao' ref='roundConfigDao'/> + <property name='moduleService' ref='moduleService'/> + + </bean> + + + <bean id='answeringService' class='edu.asu.commons.mme.service.AnsweringService'> + <property name='dao' ref='studentResponseDao'/> + <property name='studentDao' ref='studentDao'/> + <property name='dayByDayDecisionsService' ref='dayByDayDecisionsService'/> + + </bean> + + <bean id='questionCreatorService' class='edu.asu.commons.mme.service.QuestionCreatorService'> + <property name='dao' ref='questionDao'/> + <property name='blockDao' ref='blockDao'/> + <property name='moduleDao' ref='moduleDao'/> + <property name='questionGroupDao' ref='questionGroupDao'/> + <property name='psychometricQuestionDao' ref='psychometricQuestionDao'/> + <property name='categoricalQuestionDao' ref='categoricalQuestionDao'/> + + </bean> + + <bean id='startupService' class='edu.asu.commons.mme.service.StartupService'> + <property name='questionCreatorService' ref='questionCreatorService'/> + <property name='studentService' ref='studentService'/> + </bean> + + <bean id='locationService' class='edu.asu.commons.mme.service.LocationService'> + <property name='dao' ref='locationDao'/> + </bean> + + + <bean id='studentService' class='edu.asu.commons.mme.service.StudentService'> + <property name='dao' ref='studentDao'/> + </bean> + +<!-- spring managed service layer --> + <bean id='moduleService' class="edu.asu.commons.mme.service.ModuleService"> + <property name='dao' ref='moduleDao'/> + <property name='gameDao' ref='gameDao' /> + </bean> + + <bean id="startGame" class="edu.asu.commons.mme.service.StartGame"> + <property name='moduleService' ref='moduleService'/> + </bean> + + <bean id="testService" class="edu.asu.commons.mme.service.TestService"> + <property name='moduleService' ref='moduleService'/> + <property name="startModule" value="Testing String."/> + </bean> + + +<!-- Expose services for BlazeDS remoting --> + <flex:remote-service ref="studentService" /> + <flex:remote-service ref="moduleService" /> + <flex:remote-service ref="questionCreatorService" /> + <flex:remote-service ref="roundService" /> + <flex:remote-service ref="startupService" /> + <flex:remote-service ref="answeringService" /> + <flex:remote-service ref="locationService" /> + +<!-- Flex related information ended--> + + <bean id="mmeDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> + <property name="driverClassName" value="${hibernate.connection.driver_class}"/> + <property name="url" value="${hibernate.connection.url}"/> + <property name="username" value="${hibernate.connection.user}"/> + <property name="password" value="${hibernate.connection.password}"/> + </bean> + + <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> + <property name="location" value="/WEB-INF/hibernate.properties"/> + <property name="beanName" value="mmeDataSource"/> + </bean> + + <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> + <property name="configLocation" value="/WEB-INF/hibernate.cfg.xml"/> + <property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration"/> + <property name="hibernateProperties"> + <props> + <prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop> + <prop key="hibernate.show_sql">false</prop> + </props> + </property> + <property name="dataSource" ref="mmeDataSource"/> + </bean> + + <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> + <property name="sessionFactory" ref="sessionFactory"/> + </bean> + <!-- XXX: don't need proxy-target-class if services are interfaces instead --> + <tx:annotation-driven proxy-target-class="true"/> + +</beans> Modified: mentalmodels/trunk/src/main/webapp/WEB-INF/hibernate.cfg.xml =================================================================== --- mentalmodels/trunk/src/main/webapp/WEB-INF/hibernate.cfg.xml 2009-08-06 22:00:47 UTC (rev 227) +++ mentalmodels/trunk/src/main/webapp/WEB-INF/hibernate.cfg.xml 2009-08-07 00:57:34 UTC (rev 228) @@ -33,7 +33,7 @@ <mapping class='edu.asu.commons.mme.entity.ModuleRoundConfig'/> <mapping class='edu.asu.commons.mme.entity.InformationWindow'/> <mapping class='edu.asu.commons.mme.entity.DayByDayDecisions'/> - + </session-factory> </hibernate-configuration> Modified: mentalmodels/trunk/src/main/webapp/WEB-INF/web.xml =================================================================== --- mentalmodels/trunk/src/main/webapp/WEB-INF/web.xml 2009-08-06 22:00:47 UTC (rev 227) +++ mentalmodels/trunk/src/main/webapp/WEB-INF/web.xml 2009-08-07 00:57:34 UTC (rev 228) @@ -15,6 +15,7 @@ <url-pattern>/*</url-pattern> </filter-mapping> --> + <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> Modified: mentalmodels/trunk/src/main/webapp/startfeed.jsp =================================================================== --- mentalmodels/trunk/src/main/webapp/startfeed.jsp 2009-08-06 22:00:47 UTC (rev 227) +++ mentalmodels/trunk/src/main/webapp/startfeed.jsp 2009-08-07 00:57:34 UTC (rev 228) @@ -5,6 +5,6 @@ feed.start(); out.println("Server started to accept the students."); } catch (Exception e) { - out.println("A problem occured while starting the server: "+e.getMessage()); + out.println("A problem occured while starting the server: "+e.getStackTrace()); } %> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |