001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/sam/trunk/component/src/java/org/sakaiproject/tool/assessment/facade/ItemManager.java $
003: * $Id: ItemManager.java 9273 2006-05-10 22:34:28Z daisyf@stanford.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the"License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.tool.assessment.facade;
021:
022: import java.util.Date;
023: import java.util.HashSet;
024:
025: import org.sakaiproject.tool.assessment.data.dao.assessment.Answer;
026: import org.sakaiproject.tool.assessment.data.dao.assessment.AnswerFeedback;
027: import org.sakaiproject.tool.assessment.data.dao.assessment.ItemData;
028: import org.sakaiproject.tool.assessment.data.dao.assessment.ItemMetaData;
029: import org.sakaiproject.tool.assessment.data.dao.assessment.ItemText;
030: import org.sakaiproject.tool.assessment.data.ifc.assessment.ItemDataIfc;
031: import org.apache.commons.logging.Log;
032: import org.apache.commons.logging.LogFactory;
033:
034: public class ItemManager {
035: private static Log log = LogFactory.getLog(ItemManager.class);
036:
037: public ItemManager() {
038: }
039:
040: public static void main(String[] args) {
041: //ItemManager instance = new ItemManager();
042: System.exit(0);
043: }
044:
045: public ItemData prepareItem() {
046: ItemData item = new ItemData();
047: item.setInstruction("Matching game");
048: item.setTypeId(new Long(9));
049: item.setScore(new Float(10));
050: item.setHasRationale(Boolean.FALSE);
051: item.setStatus(new Integer(1));
052: item.setCreatedBy("1");
053: item.setCreatedDate(new Date());
054: item.setLastModifiedBy("1");
055: item.setLastModifiedDate(new Date());
056:
057: // prepare itemText
058: item.setItemTextSet(prepareText(item));
059: item.addItemText("I have", new HashSet());
060:
061: // prepare MetaData
062: item.setItemMetaDataSet(prepareMetaData(item));
063: item.addItemMetaData("ITEM_OBJECTIVE",
064: "the objective is to ...");
065:
066: // prepare feedback
067: item.setCorrectItemFeedback("well done!");
068: item.setInCorrectItemFeedback("better luck next time!");
069: log.debug("****item in ItemManager =" + item);
070: return item;
071: }
072:
073: private HashSet prepareText(ItemData item) {
074: HashSet textSet = new HashSet();
075: ItemText text1 = new ItemText();
076: text1.setItem(item);
077: text1.setSequence(new Long(1));
078: text1.setText("cat has");
079: HashSet answerSet1 = new HashSet();
080: HashSet answerFeedbackSet1 = new HashSet();
081: Answer answer1 = new Answer(text1, "2 legs", new Long(1), "i",
082: Boolean.FALSE, null, new Float(0));
083: answerFeedbackSet1.add(new AnswerFeedback(answer1, "incorrect",
084: "sorry"));
085: answer1.setAnswerFeedbackSet(answerFeedbackSet1);
086: answerSet1.add(answer1);
087: answerSet1.add(new Answer(text1, "3 legs", new Long(2), "ii",
088: Boolean.FALSE, null, new Float(0)));
089: answerSet1.add(new Answer(text1, "4 legs", new Long(3), "iii",
090: Boolean.TRUE, null, new Float(5)));
091: text1.setAnswerSet(answerSet1);
092:
093: textSet.add(text1);
094:
095: ItemText text2 = new ItemText();
096: text2.setItem(item);
097: text2.setSequence(new Long(2));
098: text2.setText("chicken has");
099: HashSet answerSet2 = new HashSet();
100: answerSet2.add(new Answer(text2, "2 legs", new Long(1), "i",
101: Boolean.TRUE, null, new Float(5)));
102: answerSet2.add(new Answer(text2, "3 legs", new Long(2), "ii",
103: Boolean.FALSE, null, new Float(0)));
104: answerSet2.add(new Answer(text2, "4 legs", new Long(3), "iii",
105: Boolean.FALSE, null, new Float(0)));
106: text2.setAnswerSet(answerSet2);
107: textSet.add(text2);
108:
109: ItemText text3 = new ItemText();
110: text3.setItem(item);
111: text3.setSequence(new Long(3));
112: text3.setText("baby has");
113: HashSet answerSet3 = new HashSet();
114: answerSet3.add(new Answer(text3, "2 legs", new Long(1), "i",
115: Boolean.FALSE, null, new Float(0)));
116: answerSet3.add(new Answer(text3, "3 legs", new Long(2), "ii",
117: Boolean.FALSE, null, new Float(0)));
118: answerSet3.add(new Answer(text3, "4 legs", new Long(3), "iii",
119: Boolean.TRUE, null, new Float(5)));
120: text3.setAnswerSet(answerSet3);
121: textSet.add(text3);
122: return textSet;
123: }
124:
125: private HashSet prepareMetaData(ItemData item) {
126: HashSet set = new HashSet();
127: set.add(new ItemMetaData(item, "qmd_itemtype", "Matching"));
128: set.add(new ItemMetaData(item, "TEXT_FORMAT", "HTML"));
129: set.add(new ItemMetaData(item, "MUTUALLY_EXCLUSIVE", "True"));
130: return set;
131: }
132:
133: /*
134: private void printItem(ItemData item) {
135: log.debug("**Id = " + item.getItemId());
136: log.debug("**score = " + item.getScore());
137: log.debug("**grade = " + item.getGrade());
138: log.debug("**CorrectFeedback is lazy = " +
139: item.getCorrectItemFeedback());
140: log.debug("**Objective not lazy = " +
141: item.getItemMetaDataByLabel("ITEM_OBJECTIVE"));
142: }
143:
144: private void printIfcItem(ItemDataIfc item) {
145: log.debug("**Id = " + item.getItemId());
146: log.debug("**score = " + item.getScore());
147: log.debug("**grade = " + item.getGrade());
148: log.debug("**CorrectFeedback is lazy = " +
149: item.getCorrectItemFeedback());
150: log.debug("**Objective not lazy = " +
151: item.getItemMetaDataByLabel("ITEM_OBJECTIVE"));
152: log.debug("**createdDate = " +
153: item.getCreatedDate());
154: }
155:
156: private void printFacadeItem(ItemDataIfc item) {
157: ItemFacade f = new ItemFacade(item);
158: log.debug("****Id = " + f.getItemId());
159: log.debug("****score = " + f.getScore());
160: log.debug("****grade = " + f.getGrade());
161: log.debug("****CorrectFeedback is lazy = " +
162: f.getCorrectItemFeedback());
163: log.debug("****Objective not lazy = " +
164: f.getItemMetaDataByLabel("ITEM_OBJECTIVE"));
165: log.debug("****createdDate = " +
166: f.getCreatedDate());
167: log.debug("****ItemType = " +
168: f.getItemType().getKeyword());
169: }
170: */
171:
172: /*
173: private void exportXml(ItemDataIfc item) {
174: XStream xstream = new XStream();
175: xstream = new XStream(new DomDriver());
176: xstream.alias("item", ItemData.class);
177: xstream.alias("itemText", ItemText.class);
178: xstream.alias("itemFeedback", ItemFeedback.class);
179: xstream.alias("itemMetaData", ItemMetaData.class);
180: xstream.alias("answer", Answer.class);
181: xstream.alias("answerFeedback", AnswerFeedback.class);
182: String xml = xstream.toXML(item);
183: byte[] b = xml.getBytes();
184: try {
185: FileOutputStream out = new FileOutputStream("out");
186: out.write(b);
187: }
188: catch (FileNotFoundException ex) {
189: }
190: catch (IOException ex1) {
191: }
192: }
193: */
194: }
|