001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/sam/trunk/component/src/java/org/sakaiproject/tool/assessment/services/qti/QTIService.java $
003: * $Id: QTIService.java 9273 2006-05-10 22:34:28Z daisyf@stanford.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 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.services.qti;
021:
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024: import org.sakaiproject.tool.assessment.facade.AssessmentFacade;
025: import org.sakaiproject.tool.assessment.facade.ItemFacade;
026: import org.sakaiproject.tool.assessment.facade.QuestionPoolFacade;
027: import org.sakaiproject.tool.assessment.qti.constants.QTIVersion;
028: import org.sakaiproject.tool.assessment.qti.helper.AuthoringHelper;
029: import org.w3c.dom.Document;
030:
031: /**
032: * <p>This service provides translation between database and QTI representations.
033: * This is used to import/export IMS QTI format XML, and for web services.
034: * </p>
035: * <p>Copyright: Copyright (c) 2005 Sakai</p>
036: * <p> </p>
037: * @author Ed Smiley esmiley@stanford.edu
038: * @version $Id: QTIService.java 9273 2006-05-10 22:34:28Z daisyf@stanford.edu $
039: */
040:
041: public class QTIService {
042: private static Log log = LogFactory.getLog(QTIService.class);
043:
044: public QTIService() {
045: }
046:
047: /**
048: * Import an assessment XML document in QTI format, extract & persist the data.
049: * @param document the assessment XML document in QTI format
050: * @param qtiVersion either QTIVersion.VERSION_1_2 or QTIVersion.VERSION_2_0;
051: * @return a persisted assessment
052: */
053: public AssessmentFacade createImportedAssessment(Document document,
054: int qtiVersion) {
055: testQtiVersion(qtiVersion);
056:
057: try {
058: AuthoringHelper helper = new AuthoringHelper(qtiVersion);
059: return helper.createImportedAssessment(document);
060: } catch (Exception ex) {
061: throw new QTIServiceException(ex);
062: }
063: }
064:
065: public AssessmentFacade createImportedAssessment(Document document,
066: int qtiVersion, String unzipLocation, String templateId) {
067: testQtiVersion(qtiVersion);
068:
069: try {
070: AuthoringHelper helper = new AuthoringHelper(qtiVersion);
071: return helper.createImportedAssessment(document,
072: unzipLocation, templateId);
073: } catch (Exception ex) {
074: throw new QTIServiceException(ex);
075: }
076: }
077:
078: /**
079: * Import an assessment XML document in QTI format, extract & persist the data.
080: * @param document the assessment XML document in QTI format
081: * @param qtiVersion either QTIVersion.VERSION_1_2 or QTIVersion.VERSION_2_0;
082: * @return a persisted assessment
083: */
084: public AssessmentFacade createImportedAssessment(Document document,
085: int qtiVersion, String unzipLocation) {
086: testQtiVersion(qtiVersion);
087:
088: try {
089: AuthoringHelper helper = new AuthoringHelper(qtiVersion);
090: return helper.createImportedAssessment(document,
091: unzipLocation);
092: } catch (Exception ex) {
093: throw new QTIServiceException(ex);
094: }
095: }
096:
097: /**
098: * Import an assessment XML document in QTI format, extract & persist the data.
099: * import process assumes assessment structure, not objectbank or itembank
100: * based on usage in other potential migration systems, Respondus, BlackBoard, etc.
101: * QTI version 2.x will probably focus on content packaging for question pools
102: * @param document the assessment XML document in QTI format
103: * @param qtiVersion QTIVersion.VERSION_1_2;
104: * @return a persisted assessment
105: */
106: public QuestionPoolFacade createImportedQuestionPool(
107: Document document, int qtiVersion) {
108: testQtiVersion(qtiVersion);
109:
110: try {
111: AuthoringHelper helper = new AuthoringHelper(qtiVersion);
112: return helper.createImportedQuestionPool(document);
113: } catch (Exception ex) {
114: throw new QTIServiceException(ex);
115: }
116: }
117:
118: /**
119: * Import an item XML document in QTI format, extract & persist the data.
120: * @param document the item XML document in QTI format
121: * @param qtiVersion either QTIVersion.VERSION_1_2 or QTIVersion.VERSION_2_0;
122: * @return a persisted item
123: */
124: public ItemFacade createImportedItem(Document document,
125: int qtiVersion) {
126: testQtiVersion(qtiVersion);
127:
128: try {
129: AuthoringHelper helper = new AuthoringHelper(qtiVersion);
130: return helper.createImportedItem(document);
131: } catch (Exception ex) {
132: throw new QTIServiceException(ex);
133: }
134:
135: }
136:
137: /**
138: * Get an assessment in Document form.
139: *
140: * Note: this service requires a Faces context.
141: *
142: * @param assessmentId the assessment's Id
143: * @param qtiVersion either QTIVersion.VERSION_1_2 or QTIVersion.VERSION_2_0;
144: * @return the Document with the assessment data
145: */
146: public Document getExportedAssessment(String assessmentId,
147: int qtiVersion) {
148: testQtiVersion(qtiVersion);
149:
150: try {
151: AuthoringHelper helper = new AuthoringHelper(qtiVersion);
152: return helper.getAssessment(assessmentId);
153: } catch (Exception ex) {
154: throw new QTIServiceException(ex);
155: }
156: }
157:
158: /**
159: * Get an item in Document form.
160: *
161: * Note: this service requires a Faces context.
162: *
163: * @param itemId the item's Id
164: * @param qtiVersion either QTIVersion.VERSION_1_2 or QTIVersion.VERSION_2_0;
165: * @return the Document with the assessment data
166: */
167: public Document getExportedItem(String itemId, int qtiVersion) {
168: testQtiVersion(qtiVersion);
169:
170: try {
171: AuthoringHelper helper = new AuthoringHelper(qtiVersion);
172: return helper.getItem(itemId);
173: } catch (Exception ex) {
174: throw new QTIServiceException(ex);
175: }
176: }
177:
178: /**
179: * Get an item bank in Document form.
180: *
181: * Note: this service requires a Faces context.
182: *
183: * @param itemIds an array of item ids
184: * @param qtiVersion either QTIVersion.VERSION_1_2 or QTIVersion.VERSION_2_0;
185: * @return the Document with the item bank
186: */
187: public Document getExportedItemBank(String itemIds[], int qtiVersion) {
188: testQtiVersion(qtiVersion);
189:
190: try {
191: AuthoringHelper helper = new AuthoringHelper(qtiVersion);
192: return helper.getItemBank(itemIds);
193: } catch (Exception ex) {
194: throw new QTIServiceException(ex);
195: }
196: }
197:
198: /**
199: * utility method
200: * @param qtiVersion
201: */
202: private void testQtiVersion(int qtiVersion) {
203: if (!QTIVersion.isValid(qtiVersion)) {
204: throw new QTIServiceException(new IllegalArgumentException(
205: "NOT Legal Qti Version."));
206: }
207: }
208:
209: }
|