[virtualcommons-svn] SF.net SVN: virtualcommons:[249] mentalmodels/trunk
Status: Beta
Brought to you by:
alllee
From: <see...@us...> - 2009-08-13 20:53:21
|
Revision: 249 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=249&view=rev Author: seematalele Date: 2009-08-13 20:53:14 +0000 (Thu, 13 Aug 2009) Log Message: ----------- Solve the bug in simple CategoricalQuestion.java Problems- 1) if you want to update simple categorical question then it enters all the changes in the database but in GUI it does not show those changes. 2)if you want to update relative categorical question then it enters all the changes in the database but in GUI it does not show those changes. Created the HibernateCategoricalOptionDao.java Modified Paths: -------------- mentalmodels/trunk/flex/src/InitialiseDatabase.mxml mentalmodels/trunk/flex/src/custom/db/questions/CategoricalSimple.mxml mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/CategoricalQuestion.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/QuestionCreatorService.java mentalmodels/trunk/src/main/webapp/FisheryExperimentShell.swf mentalmodels/trunk/src/main/webapp/InitialiseDatabase.swf mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml Added Paths: ----------- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/dao/HibernateCategoricalOptionDao.java Modified: mentalmodels/trunk/flex/src/InitialiseDatabase.mxml =================================================================== --- mentalmodels/trunk/flex/src/InitialiseDatabase.mxml 2009-08-12 22:35:58 UTC (rev 248) +++ mentalmodels/trunk/flex/src/InitialiseDatabase.mxml 2009-08-13 20:53:14 UTC (rev 249) @@ -77,7 +77,6 @@ [Bindable] private var categoricalQuestions:XML = <list> <categorical type="Categorical Questions" id="0"/> - </list>; /** @@ -160,7 +159,9 @@ } } } - } + } + + } private function createModuleNode(module:actionscript.Module):XML @@ -290,7 +291,7 @@ var newOptionNode:XML = <option/>; newOptionNode.setLocalName("option"); newOptionNode.@name = options.optionKey; - if(options.choices.length == 0) + if(options.choices == null || options.choices.length == 0) { flagType = false } @@ -304,7 +305,9 @@ if(choices == "") { + //Alert.show("choices is eqaul to : " + choices); choices = options.choices[k]; + //Alert.show("choices is eqaul to : " + choices); } else { @@ -341,6 +344,24 @@ return newQNode; } + private function getCategoricalType(categorical:actionscript.questions.Categorical):String + { + //false means it is simple type, otherwise it is relative type + var type:String = null; + for(var x:int = 0; x < categorical.categoricalOptions.length ; x++) + { + var catOptions:actionscript.questions.CategoricalOption = new actionscript.questions.CategoricalOption(); + catOptions = actionscript.questions.CategoricalOption(categorical.categoricalOptions.getItemAt(x)); + //Alert.show("options.choices is: " + options.choices); + if((catOptions.choices == null) || (catOptions.choices.length == 0)) + type = "simple"; + else + type = "relative"; + } + return type; + + } + private function faultHandler(event:FaultEvent):void { Alert.show("event fault is " + event.fault.getStackTrace()); @@ -505,7 +526,7 @@ } else { - //Alert.show("Id is: " + module.id); + Alert.show("Id is: " + module.id); var newModuleNode:XML = createModuleNode(module); survey.appendChild(newModuleNode); } @@ -1008,17 +1029,19 @@ Options.choices = dict[key]; categoricalQuestion.categoricalOptions.addItem(Options); } + categoricalQuestion.type = questionInfo.getType(); categoricalQuestion.question = questionInfo.getQuestion(); categoricalQuestion.sequenceNo = int(questionInfo.getSequenceNo()); categoricalQuestion.communicationQ = questionInfo.isCommunicationQuestion(); - /*for(var i:int = 0; i < categoricalQuestion.categoricalOptions.length ; i++) + for(var i:int = 0; i < categoricalQuestion.categoricalOptions.length ; i++) { var testoption:actionscript.questions.CategoricalOption = new actionscript.questions.CategoricalOption(); testoption = actionscript.questions.CategoricalOption(categoricalQuestion.categoricalOptions.getItemAt(i)); - trace(testoption.optionKey); - trace(testoption.choices); - }*/ + Alert.show(testoption.optionKey); + for(var j:int =0; j<testoption.choices.length ;j++) + Alert.show(testoption.choices.getItemAt(j).toString()); + } if(questionInfo.getId() == 0) { if(checkSeqNoQuestion.length() > 0) @@ -1053,7 +1076,7 @@ { var OptionsSimple:actionscript.questions.CategoricalOption = new actionscript.questions.CategoricalOption(); OptionsSimple.optionKey = option.toString(); - //Alert.show("Key : " + option.toString()); + // Alert.show("Key : " + option.toString()); OptionsSimple.choices = Simpledict[key]; categoricalSimpleQuestion.categoricalOptions.addItem(OptionsSimple); } @@ -1061,12 +1084,12 @@ categoricalSimpleQuestion.question = questionInfo.getQuestion(); categoricalSimpleQuestion.sequenceNo = int(questionInfo.getSequenceNo()); categoricalSimpleQuestion.communicationQ = questionInfo.isCommunicationQuestion(); - /*for(var j:int = 0; j < categoricalSimpleQuestion.categoricalOptions.length ; j++) + /* for(var j:int = 0; j < categoricalSimpleQuestion.categoricalOptions.length ; j++) { - var testoption:ASCategoricalOption = new ASCategoricalOption(); - testoption = ASCategoricalOption(categoricalSimpleQuestion.categoricalOptions.getItemAt(i)); - trace(testoption.optionKey); - trace(testoption.choices); + var testoption:actionscript.questions.CategoricalOption = new actionscript.questions.CategoricalOption(); + testoption = actionscript.questions.CategoricalOption(categoricalSimpleQuestion.categoricalOptions.getItemAt(j)); + Alert.show(testoption.optionKey.toString()); + //Alert.show(testoption.choices); }*/ /*Alert.show("Question: " + categoricalSimpleQuestion.question); Alert.show("SeQ No: " + categoricalSimpleQuestion.sequenceNo); @@ -1075,12 +1098,16 @@ if(questionInfo.getId() == 0) { + if(checkSeqNoQuestion.length() > 0) { Alert.show("Sequence number " + questionInfo.getSequenceNo() + " already exists!"); } else + { roQuestionCreator.saveQuestion(categoricalSimpleQuestion,int(node.@id)); + //Alert.show( categoricalSimpleQuestion.question+ " is saved."); + } } else { @@ -1089,7 +1116,10 @@ Alert.show("Sequence number " + questionInfo.getSequenceNo() + " already exists!"); } else + { roQuestionCreator.updateQuestion(categoricalSimpleQuestion,int(node.@id), questionInfo.getId()); + //Alert.show( categoricalSimpleQuestion.question+ " is updated."); + } } } @@ -1166,6 +1196,16 @@ newNode.setLocalName("question"); var newQNode:XML = <question/>; newQNode.setLocalName("question"); + var questionXML:XMLList = survey.module.block.questiongroup.question.(@id == question.id); + + if(questionXML.length() > 0) + { + questionXML[0].@title = question.question; + questionXML[0].@sequenceNo = question.sequenceNo; + questionXML[0].@type = question.type; + questionXML[0].@communication = question.communicationQ; + } + var choices:String=""; if(question.type.toLowerCase() == "psychometric") { @@ -1184,10 +1224,10 @@ newPNode.@scale = psychometricResult.scale; newPNode.@maxSliderValue = psychometricResult.maxSliderValue; - newQNode.@sequenceNo = psychometricResult.sequenceNo; +/* newQNode.@sequenceNo = psychometricResult.sequenceNo; newQNode.@title = psychometricResult.question; newQNode.@type = psychometricResult.type; - newQNode.@communication = psychometricResult.communicationQ; + newQNode.@communication = psychometricResult.communicationQ; */ choices = ""; if(psychometricResult.choices != null) { @@ -1210,11 +1250,11 @@ else if(question.type.toLowerCase() == "categorical") { var categoricalResult:actionscript.questions.Categorical = actionscript.questions.Categorical(question); - newQNode.@sequenceNo = categoricalResult.sequenceNo; +/* newQNode.@sequenceNo = categoricalResult.sequenceNo; newQNode.@title = categoricalResult.question; newQNode.@type = categoricalResult.type; newQNode.@id = categoricalResult.id; - newQNode.@communication = categoricalResult.communicationQ; + newQNode.@communication = categoricalResult.communicationQ; */ //flagType false means it is simple type, otherwise it is relative type var flagType:Boolean = false; @@ -1225,7 +1265,7 @@ if( categoricalList.length() > 0 ) { - //remove all the <option> tags and then add those rather than modifying those. It is simple. + //remove all the <option> tags and then add new ones rather than modifying those. It is simple. var children:XMLList = categoricalList.children(); for(var l:Number=0; l < children.length(); l++) @@ -1235,6 +1275,7 @@ if(categoricalResult.categoricalOptions != null) { + Alert.show("categoricalResult.categoricalOptions.length : "+ categoricalResult.categoricalOptions.length); for(var i:int = 0; i < categoricalResult.categoricalOptions.length ; i++) { var options:actionscript.questions.CategoricalOption = new actionscript.questions.CategoricalOption(); @@ -1242,7 +1283,7 @@ var newOptionNode:XML = <option/>; newOptionNode.setLocalName("option"); newOptionNode.@name = options.optionKey; - if(options.choices.length == 0) + if((options.choices == null) || options.choices.length == 0) { flagType = false } @@ -1275,8 +1316,10 @@ { newCNode.@type = "simple"; } + newCNode.appendChild(newOptionNode); } + //Alert.show("after inserting into the XML: " + newOptionNode.attributes().toXMLString()); } } } @@ -1446,8 +1489,9 @@ outputchoices = choiceStr.split(","); - for(var i:int = 0; i < outputchoices.length; i++) + for(var i:int = 0; i < outputchoices.length - 1; i++) { + //Alert.show("counter i is: " + i + outputchoices[i]); dict[str].addItem(outputchoices[i]); } } @@ -1455,6 +1499,7 @@ } else if(categoricalQ[0].@type == "simple") { + //Alert.show(categoricalQuestions.categorical); compCategorical.setType("simple"); currentState = "simple"; var cat2obj:DisplayObject = pnlComponent.getChildAt(3); @@ -1463,6 +1508,7 @@ var dictionary:Dictionary = new Dictionary(); var attributeSimpleList:XMLList = categoricalQ[0].option.attributes(); + // Alert.show("attribute list is : " + attributeSimpleList.toXMLString()); var str1:String; for(var k:int = 0; k < attributeSimpleList.length(); k++) @@ -1472,7 +1518,8 @@ dictionary[str1] = new ArrayCollection(); dictionary[str1].addItem(null); } - compSimple.setDictionary(dictionary); + compSimple.setDictionary(dictionary); + } } } @@ -1496,7 +1543,7 @@ choiceStr = psychometricQ[0].@choices; outputchoices = choiceStr.split(","); - for(i = 0; i < outputchoices.length; i++) + for(i = 0; i < outputchoices.length - 1; i++) { compPsychometric.choice.addItem(outputchoices[i]); Modified: mentalmodels/trunk/flex/src/custom/db/questions/CategoricalSimple.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/db/questions/CategoricalSimple.mxml 2009-08-12 22:35:58 UTC (rev 248) +++ mentalmodels/trunk/flex/src/custom/db/questions/CategoricalSimple.mxml 2009-08-13 20:53:14 UTC (rev 249) @@ -89,8 +89,6 @@ public function reset():void { - - txtChoice.text = ""; lblHeader.text = ""; header.removeAll(); @@ -99,7 +97,7 @@ { for(var key:Object in dict) { - dict[key].removeAll(); + //dict[key].removeAll(); delete dict[key]; } } @@ -154,6 +152,12 @@ dict[txtChoice.text] = null; txtChoice.text = ""; } + //use following for loop to see the dictionary items after addition + /* for(var key:Object in dict) + { + //dict[key].removeAll(); + Alert.show("After addition dict item is: "+ key.toString() ); + } */ } @@ -171,15 +175,22 @@ } else { + + //Alert.show("selected item is : " +lstHeader.selectedItem.toString()); + delete dict[lstHeader.selectedItem]; header.removeItemAt(header.getItemIndex(lstHeader.selectedItem)); - delete dict[lstHeader.selectedItem]; + + //use following for loop to see the dictionary items after deletion + /* for(var key:Object in dict) + { + //dict[key].removeAll(); + Alert.show("After deletion dict item is: "+ key.toString() ); + } */ + + } } - - - - ]]> </mx:Script> <!-- <mx:VBox id="vboxHeaders" horizontalAlign="center"> @@ -194,7 +205,7 @@ <mx:HBox id="vboxSecondHeader" > <mx:VBox> <mx:Label text="Values" id="lblHeader" fontSize="12" fontWeight="bold" fontFamily="Verdana"/> - <mx:List id="lstHeader" wordWrap="true" dataProvider="{header}" allowMultipleSelection="false"/> + <mx:List id="lstHeader" wordWrap="false" dataProvider="{header}" allowMultipleSelection="false" height="300"/> <mx:FormItem id="frmitmAddChoice" label="Choice for Values: "> <mx:TextInput id="txtChoice" change="{validateForm(event)}"/> </mx:FormItem> Added: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/dao/HibernateCategoricalOptionDao.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/dao/HibernateCategoricalOptionDao.java (rev 0) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/dao/HibernateCategoricalOptionDao.java 2009-08-13 20:53:14 UTC (rev 249) @@ -0,0 +1,12 @@ +package edu.asu.commons.mme.dao; + +import edu.asu.commons.mme.entity.CategoricalOption; + +public class HibernateCategoricalOptionDao extends HibernateDao<CategoricalOption>{ + + public HibernateCategoricalOptionDao() + { + super(CategoricalOption.class); + } + +} Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/CategoricalQuestion.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/CategoricalQuestion.java 2009-08-12 22:35:58 UTC (rev 248) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/CategoricalQuestion.java 2009-08-13 20:53:14 UTC (rev 249) @@ -1,8 +1,11 @@ package edu.asu.commons.mme.entity; +import java.util.Iterator; import java.util.List; + + import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.JoinColumn; @@ -29,5 +32,7 @@ public List<CategoricalOption> getCategoricalOptions() { return categoricalOptions; } + + } 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-12 22:35:58 UTC (rev 248) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/QuestionCreatorService.java 2009-08-13 20:53:14 UTC (rev 249) @@ -8,6 +8,7 @@ import org.springframework.transaction.annotation.Transactional; import edu.asu.commons.mme.dao.HibernateBlockDao; +import edu.asu.commons.mme.dao.HibernateCategoricalOptionDao; import edu.asu.commons.mme.dao.HibernateCategoricalQuestionDao; import edu.asu.commons.mme.dao.HibernateModuleDao; import edu.asu.commons.mme.dao.HibernatePsychometricQuestionDao; @@ -34,31 +35,32 @@ @Transactional public class QuestionCreatorService extends Service.Base<Question, HibernateQuestionDao> { - + private HibernateBlockDao blockDao; private HibernateModuleDao moduleDao; private HibernateQuestionGroupDao questionGroupDao; private HibernatePsychometricQuestionDao psychometricQuestionDao; private HibernateCategoricalQuestionDao categoricalQuestionDao; - + private HibernateCategoricalOptionDao categoricalOptionDao; + Module module; Block block; QuestionGroup questionGroup; Question question; CategoricalQuestion categoricalQ; - + PsychometricQuestion psychometricQ; - + public List<Module> initializeData() { List<Module> modulelist = new ArrayList<Module>(); - + getLogger().debug("In InitializeData function"); modulelist = moduleDao.findAll(); - + getLogger().debug("Module length " + modulelist.size()); - + for(int i = 0; i<modulelist.size(); i++) { Module module = modulelist.get(i); @@ -78,7 +80,7 @@ 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)); @@ -91,7 +93,7 @@ } } } - + }*/ } /* @@ -100,18 +102,19 @@ * */ //getLogger().debug("questionGroup: " + modulelist.get(0).getBlocks().get(0).getQuestionGroups().get(0).getHeader()); - + return modulelist; - + } - - + + public Module saveModule(Integer sequenceNo, String description, Integer duration) { - Module module = moduleDao.findByProperty("sequenceNo", new Integer(sequenceNo)); + module = new Module(); + module = moduleDao.findByProperty("sequenceNo", new Integer(sequenceNo)); if(module == null) { - createModule(sequenceNo, description, duration); + module = createModule(sequenceNo, description, duration); } else { @@ -120,8 +123,8 @@ } return module; } - - + + public Module createModule(Integer sequenceNo, String description, Integer duration) { module = new Module(); @@ -130,11 +133,11 @@ module.setDuration(duration); moduleDao.save(module); getLogger().debug("module is created with Id: " + module.getId()); - + return module; - + } - + public Module updateModule(Long id, Integer sequenceNo, String description, Integer duration) { getLogger().debug("Id came from client is: " + id); @@ -155,7 +158,7 @@ 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)); @@ -168,7 +171,7 @@ } } } - + }*/ if( module != null) { @@ -177,22 +180,22 @@ module.setDuration(duration); moduleDao.save(module); getLogger().debug("module is updated with Id: " + module.getId()); - + } - + return module; - + } - + public Block saveBlock(Integer sequenceNo, String description, Integer duration, Long module_Id) { - + Block currentblock = new Block(); - + currentblock.setSequenceNo(sequenceNo); currentblock.setDescription(description); currentblock.setDuration(duration); - + module = moduleDao.find(module_Id); Hibernate.initialize(module); initializeModule(module); @@ -209,7 +212,7 @@ 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)); @@ -222,7 +225,7 @@ } } } - + }*/ if(currentblock != null) { @@ -231,9 +234,9 @@ } getLogger().debug("Block is created with Id: " + currentblock.getId()); return currentblock; - + } - + public Block updateBlock(Long id, Integer sequenceNo, String description, Integer duration, Long module_Id) { getLogger().debug("Id came from client is: " + id); @@ -246,9 +249,9 @@ { QuestionGroup questionGroup = iteratorquestionGrp.next(); Hibernate.initialize(questionGroup); -// getLogger().debug(questionGroup.getDescription()); + // getLogger().debug(questionGroup.getDescription()); List<Question> questions = questionGroup.getQuestions(); - + for(int j = 0; j < questions.size(); j++) { Hibernate.initialize(questions.get(j)); @@ -283,7 +286,7 @@ 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)); @@ -296,14 +299,14 @@ } } } - + }*/ block.setModule(module); blockDao.save(block); getLogger().debug("block is updated with Id: " + block.getId()); } return block; - + } public QuestionGroup saveQuestionGroup(Integer sequenceNo,String header, String description, Integer duration, Long block_id) @@ -331,7 +334,7 @@ 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)); @@ -344,25 +347,25 @@ } } } - + }*/ questionGroup.setBlock(block); questionGroupDao.save(questionGroup); getLogger().debug("QuestionGroup is created with Id: " + questionGroup.getId()); return questionGroup; - + } - + public QuestionGroup updateQuestionGroup(Integer sequenceNo,String header, String description, Integer duration,Long block_id,Long qg_id) { - + getLogger().debug("Id came from client is: " + qg_id); QuestionGroup questionGroup = questionGroupDao.findByProperty("id", qg_id); getLogger().debug(questionGroup); Hibernate.initialize(questionGroup); List<Question> questions = questionGroup.getQuestions(); - + for(int j = 0; j < questions.size(); j++) { Hibernate.initialize(questions.get(j)); @@ -378,7 +381,7 @@ module = block.getModule(); Hibernate.initialize(module); initializeModule(module); - + questionGroup.setSequenceNo(sequenceNo); questionGroup.setDescription(description); questionGroup.setHeader(header); @@ -388,7 +391,7 @@ return questionGroup; } - + private void initializeModule(Module module1) { // TODO Auto-generated method stub @@ -408,9 +411,9 @@ { QuestionGroup questionGroup = iteratorquestionGrp.next(); Hibernate.initialize(questionGroup); - // getLogger().debug(questionGroup.getDescription()); + // getLogger().debug(questionGroup.getDescription()); List<Question> questions = questionGroup.getQuestions(); - + for(int j = 0; j < questions.size(); j++) { Hibernate.initialize(questions.get(j)); @@ -423,10 +426,10 @@ } } } - + } - - + + } @@ -436,7 +439,7 @@ getLogger().debug("questionGroup_id: " + questionGroup_id); if(questionInfo.getClass().getName().equalsIgnoreCase("edu.asu.commons.mme.entity.PsychometricQuestion")) { - + PsychometricQuestion psychometricQ = new PsychometricQuestion(); PsychometricQuestion psychometric = (PsychometricQuestion)questionInfo; psychometricQ.setScale(psychometric.getScale().toLowerCase()); @@ -447,122 +450,138 @@ psychometricQ.setQuestion(psychometric.getQuestion()); psychometricQ.setType(psychometric.getType().toLowerCase()); psychometricQ.setCommunicationQ(psychometric.isCommunicationQ()); - - + + getLogger().debug("Scale: " + psychometric.getScale()); getLogger().debug("Max slider value: " + psychometric.getMaxSliderValue()); for(int i=0;i < psychometric.getChoices().size();i++) { getLogger().debug("Choice" + i+" : "+ psychometric.getChoices().get(i)); - + } - + getLogger().debug("Seq no: " + psychometric.getSequenceNo()); getLogger().debug("Question: " + psychometric.getQuestion()); getLogger().debug("Type: " + psychometric.getType()); - - + + questionGroup = questionGroupDao.findByProperty("id",questionGroup_id); Hibernate.initialize(questionGroup); block = questionGroup.getBlock(); Hibernate.initialize(block); module = block.getModule(); Hibernate.initialize(module); - + initializeModule(module); psychometricQ.setQuestionGroup(questionGroup); - + psychometricQuestionDao.save(psychometricQ); getLogger().debug("Question is created with Id: " + psychometricQ.getId() + "and type is: " + psychometricQ.getType()); Hibernate.initialize(psychometricQ); returnQuestion = psychometricQ; - + } else if(questionInfo.getClass().getName().equalsIgnoreCase("edu.asu.commons.mme.entity.CategoricalQuestion")) { - + CategoricalQuestion categoricalQ = new CategoricalQuestion(); - + CategoricalQuestion categoricalInfo = (CategoricalQuestion)questionInfo; getLogger().debug("Question from client is: " + categoricalInfo.getQuestion()); List<CategoricalOption> options = categoricalInfo.getCategoricalOptions(); - + for(int i = 0; i< options.size(); i++) { CategoricalOption test1 = new CategoricalOption(); test1 = (CategoricalOption)options.get(i); - + getLogger().debug("Option: " + i + test1.getOptionKey()); } - - + + //List<CategoricalOption> options = categoricalInfo.getCategoricalOptions(); categoricalQ.setCategoricalOptions(options); - + categoricalQ.setQuestion(categoricalInfo.getQuestion()); categoricalQ.setSequenceNo(categoricalInfo.getSequenceNo()); categoricalQ.setType(categoricalInfo.getType().toLowerCase()); /*Set<Round> round_configs = categoricalInfo.getRound_configs(); categoricalQ.setRound_configs(round_configs);*/ categoricalQ.setCommunicationQ(categoricalInfo.isCommunicationQ()); - - + + questionGroup = questionGroupDao.findByProperty("id",questionGroup_id); Hibernate.initialize(questionGroup); block = questionGroup.getBlock(); Hibernate.initialize(block); module = block.getModule(); Hibernate.initialize(module); - + initializeModule(module); categoricalQ.setQuestionGroup(questionGroup); - + categoricalQuestionDao.save(categoricalQ); - + returnQuestion = categoricalQ; getLogger().debug("Question is created with Id: " + categoricalQ.getId() + "and type is: " + categoricalQ.getType()); - + } else if(questionInfo.getClass().getName().equalsIgnoreCase("edu.asu.commons.mme.entity.Question")) { question = new Question(); - + Question otherTypeQuestionInfo = (Question)questionInfo; getLogger().debug("Question from client is: " + otherTypeQuestionInfo.getQuestion()); question.setQuestion(otherTypeQuestionInfo.getQuestion()); question.setSequenceNo(otherTypeQuestionInfo.getSequenceNo()); question.setType(otherTypeQuestionInfo.getType().toLowerCase()); question.setCommunicationQ(otherTypeQuestionInfo.isCommunicationQ()); - - + + questionGroup = questionGroupDao.findByProperty("id",questionGroup_id); Hibernate.initialize(questionGroup); block = questionGroup.getBlock(); Hibernate.initialize(block); module = block.getModule(); Hibernate.initialize(module); - + initializeModule(module); question.setQuestionGroup(questionGroup); - + save(question); - + returnQuestion = question; - + } - - + + return returnQuestion; } - + + private void resetCategoricalOptions(CategoricalQuestion categoricalQ) { + // TODO Auto-generated method stub + + try + { + getCategoricalOptionDao().delete(categoricalQ.getCategoricalOptions()); + }catch(Exception e) + { + e.printStackTrace(); + } + + //return categoricalOptions; + + } + + public Object updateQuestion(Object questionInfo,Long questionGroupId, Long questionId) { Object returnQuestion = new Object(); getLogger().debug("questionGroup_id: " + questionGroupId); if(questionInfo.getClass().getName().equalsIgnoreCase("edu.asu.commons.mme.entity.PsychometricQuestion")) { - + //PsychometricQuestion psychometricQ = new PsychometricQuestion(); PsychometricQuestion psychometricQ = psychometricQuestionDao.find(questionId); Hibernate.initialize(psychometricQ); @@ -575,83 +594,85 @@ psychometricQ.setQuestion(psychometric.getQuestion()); psychometricQ.setType(psychometric.getType().toLowerCase()); psychometricQ.setCommunicationQ(psychometric.isCommunicationQ()); - - + + getLogger().debug("Scale: " + psychometric.getScale()); getLogger().debug("Max slider value: " + psychometric.getMaxSliderValue()); for(int i=0;i < psychometric.getChoices().size();i++) { getLogger().debug("Choice" + i+" : "+ psychometric.getChoices().get(i)); - + } - + getLogger().debug("Seq no: " + psychometric.getSequenceNo()); getLogger().debug("Question: " + psychometric.getQuestion()); getLogger().debug("Type: " + psychometric.getType()); - - + + questionGroup = questionGroupDao.findByProperty("id",questionGroupId); Hibernate.initialize(questionGroup); block = questionGroup.getBlock(); Hibernate.initialize(block); module = block.getModule(); Hibernate.initialize(module); - + initializeModule(module); psychometricQ.setQuestionGroup(questionGroup); - + psychometricQuestionDao.save(psychometricQ); - getLogger().debug("Question is created with Id: " + psychometricQ.getId() + "and type is: " + psychometricQ.getType()); + getLogger().debug("Question is updated with Id: " + psychometricQ.getId() + "and type is: " + psychometricQ.getType()); Hibernate.initialize(psychometricQ); returnQuestion = psychometricQ; - + } else if(questionInfo.getClass().getName().equalsIgnoreCase("edu.asu.commons.mme.entity.CategoricalQuestion")) { - + CategoricalQuestion categoricalQ = categoricalQuestionDao.find(questionId); Hibernate.initialize(categoricalQ); Iterator<CategoricalOption> categoricalOption = categoricalQ.getCategoricalOptions().iterator(); Hibernate.initialize(categoricalOption); + //reset the privious entries + resetCategoricalOptions(categoricalQ); CategoricalQuestion categoricalInfo = (CategoricalQuestion)questionInfo; getLogger().debug("Question from client is: " + categoricalInfo.getQuestion()); List<CategoricalOption> options = categoricalInfo.getCategoricalOptions(); - + for(int i = 0; i< options.size(); i++) { CategoricalOption test1 = new CategoricalOption(); test1 = (CategoricalOption)options.get(i); - + getLogger().debug("Option: " + i + test1.getOptionKey()); } - - + + //List<CategoricalOption> options = categoricalInfo.getCategoricalOptions(); categoricalQ.setCategoricalOptions(options); - + categoricalQ.setQuestion(categoricalInfo.getQuestion()); categoricalQ.setSequenceNo(categoricalInfo.getSequenceNo()); categoricalQ.setType(categoricalInfo.getType().toLowerCase()); categoricalQ.setCommunicationQ(categoricalInfo.isCommunicationQ()); - - + + questionGroup = questionGroupDao.findByProperty("id",questionGroupId); Hibernate.initialize(questionGroup); block = questionGroup.getBlock(); Hibernate.initialize(block); module = block.getModule(); Hibernate.initialize(module); - + initializeModule(module); categoricalQ.setQuestionGroup(questionGroup); - + save(categoricalQ); - + returnQuestion = categoricalQ; - getLogger().debug("Question is created with Id: " + categoricalQ.getId() + "and type is: " + categoricalQ.getType()); - + getLogger().debug("Question is updated with Id: " + categoricalQ.getId() + "and type is: " + categoricalQ.getType()); + } else if(questionInfo.getClass().getName().equalsIgnoreCase("edu.asu.commons.mme.entity.Question")) { @@ -664,36 +685,36 @@ module = block.getModule(); Hibernate.initialize(module); initializeModule(module); - + Question otherTypeQuestionInfo = (Question)questionInfo; getLogger().debug("Question from client is: " + otherTypeQuestionInfo.getQuestion()); question.setQuestion(otherTypeQuestionInfo.getQuestion()); question.setSequenceNo(otherTypeQuestionInfo.getSequenceNo()); question.setType(otherTypeQuestionInfo.getType().toLowerCase()); question.setCommunicationQ(otherTypeQuestionInfo.isCommunicationQ()); - - + + questionGroup = questionGroupDao.findByProperty("id",questionGroupId); Hibernate.initialize(questionGroup); block = questionGroup.getBlock(); Hibernate.initialize(block); module = block.getModule(); Hibernate.initialize(module); - + initializeModule(module); question.setQuestionGroup(questionGroup); - + save(question); - + returnQuestion = question; - + } - - + + return returnQuestion; } - - + + public void createQuestions() { // check if we need to recreate these questions. block = blockDao.find(3L); @@ -704,9 +725,9 @@ return; } }*/ - // createSubjectGoalQuestionGroup(); + // createSubjectGoalQuestionGroup(); } - + /*private void createSubjectGoalQuestionGroup() { QuestionGroup subjectGoalQuestionGroup = new QuestionGroup(); subjectGoalQuestionGroup.setHeader("<b>What goals did you follow when designing your strategy?</b>"); @@ -716,7 +737,7 @@ subjectGoalQuestionGroup.setDuration(30); subjectGoalQuestionGroup.setBlock(blockDao.find(3L)); subjectGoalQuestionGroup.setSequenceNo(3); - + List<CategoricalOption> categoricalOptions = new ArrayList<CategoricalOption>(); // focus on own earnings option CategoricalOption ownEarningsOption = new CategoricalOption(); @@ -746,15 +767,15 @@ "Act against rules I expect the others to know" )); categoricalOptions.add(othersOption); - + CategoricalQuestion mostImportantGoal = new CategoricalQuestion(); mostImportantGoal.setCategoricalOptions(categoricalOptions); mostImportantGoal.setQuestion("Most important goal:"); mostImportantGoal.setSequenceNo(1); mostImportantGoal.setType("categorical"); subjectGoalQuestionGroup.add(mostImportantGoal); - - + + CategoricalQuestion secondMostImportantGoal = new CategoricalQuestion(); secondMostImportantGoal.setCategoricalOptions(categoricalOptions); secondMostImportantGoal.setQuestion("Second most important goal:"); @@ -762,8 +783,8 @@ secondMostImportantGoal.setType("categorical"); subjectGoalQuestionGroup.add(secondMostImportantGoal); // secondMostImportantGoal.setQuestionGroup(subjectGoalQuestionGroup); - + CategoricalQuestion thirdMostImportantGoal = new CategoricalQuestion(); thirdMostImportantGoal.setCategoricalOptions(categoricalOptions); thirdMostImportantGoal.setQuestion("Third most important goal:"); @@ -773,14 +794,14 @@ // thirdMostImportantGoal.setQuestionGroup(subjectGoalQuestionGroup); // save(thirdMostImportantGoal); //save(subjectGoalQuestionGroup); - - - + + + /*** - * - * create sample psychometric question - */ - /*PsychometricQuestion psychometricQ = new PsychometricQuestion(); + * + * create sample psychometric question + */ + /*PsychometricQuestion psychometricQ = new PsychometricQuestion(); psychometricQ.setScale("Unipolar".toLowerCase()); psychometricQ.setMaxSliderValue(21); List<String> choices = new ArrayList<String>(); @@ -791,46 +812,46 @@ psychometricQ.setQuestion("Compared to the most important goal, this goal is"); psychometricQ.setType("psychometric"); subjectGoalQuestionGroup.add(psychometricQ); - - + + /** - * Create test Sample categorical Simple quesiton - * - - + * Create test Sample categorical Simple quesiton + * + + CategoricalQuestion testSimple = new CategoricalQuestion(); CategoricalOption simple1 = new CategoricalOption(); List<CategoricalOption> OptionsList = new ArrayList<CategoricalOption>(); - + simple1.setOptionKey("choice1"); simple1.setChoices(null); - + CategoricalOption simple2 = new CategoricalOption(); simple2.setOptionKey("choice2"); simple2.setChoices(null); - + CategoricalOption simple3 = new CategoricalOption(); simple3.setOptionKey("choice3"); simple3.setChoices(null); - + OptionsList.add(simple1); OptionsList.add(simple2); OptionsList.add(simple3); - + testSimple.setCategoricalOptions(OptionsList); testSimple.setQuestion("Test Categrical Simple"); testSimple.setSequenceNo(5); testSimple.setType("categorical"); - + subjectGoalQuestionGroup.add(testSimple);*/ - - /*questionGroupDao.save(subjectGoalQuestionGroup); + + /*questionGroupDao.save(subjectGoalQuestionGroup); }*/ - + public void setBlockDao(HibernateBlockDao blockDao) { this.blockDao = blockDao; } - + public void setModuleDao(HibernateModuleDao moduleDao) { this.moduleDao = moduleDao; } @@ -838,12 +859,22 @@ public void setQuestionGroupDao(HibernateQuestionGroupDao questionGroupDao) { this.questionGroupDao = questionGroupDao; } - + public void setPsychometricQuestionDao(HibernatePsychometricQuestionDao psychometricQuestionDao) { this.psychometricQuestionDao = psychometricQuestionDao; } public void setCategoricalQuestionDao(HibernateCategoricalQuestionDao categoricalQuestionDao) { this.categoricalQuestionDao = categoricalQuestionDao; } - + + + public void setCategoricalOptionDao(HibernateCategoricalOptionDao categoricalOptionDao) { + this.categoricalOptionDao = categoricalOptionDao; + } + + + public HibernateCategoricalOptionDao getCategoricalOptionDao() { + return categoricalOptionDao; + } + } Modified: mentalmodels/trunk/src/main/webapp/FisheryExperimentShell.swf =================================================================== (Binary files differ) Modified: mentalmodels/trunk/src/main/webapp/InitialiseDatabase.swf =================================================================== (Binary files differ) Modified: mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml =================================================================== --- mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml 2009-08-12 22:35:58 UTC (rev 248) +++ mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml 2009-08-13 20:53:14 UTC (rev 249) @@ -60,6 +60,10 @@ </bean> + <bean id='categoricalOptionDao' class='edu.asu.commons.mme.dao.HibernateCategoricalOptionDao'> + <property name='sessionFactory' ref='sessionFactory'/> + </bean> + <bean id='questionGroupDao' class='edu.asu.commons.mme.dao.HibernateQuestionGroupDao'> <property name='sessionFactory' ref='sessionFactory'/> </bean> @@ -119,6 +123,7 @@ <property name='questionGroupDao' ref='questionGroupDao'/> <property name='psychometricQuestionDao' ref='psychometricQuestionDao'/> <property name='categoricalQuestionDao' ref='categoricalQuestionDao'/> + <property name='categoricalOptionDao' ref='categoricalOptionDao'/> </bean> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |