01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/sam/tags/sakai_2-4-1/samigo-archive/sam-handlers/src/java/org/sakaiproject/importer/impl/handlers/SamigoHandler.java $
03: * $Id: SamigoHandler.java 19349 2006-12-09 15:31:23Z zach.thomas@txstate.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.importer.impl.handlers;
21:
22: import org.sakaiproject.importer.api.HandlesImportable;
23: import org.sakaiproject.importer.api.Importable;
24: import org.sakaiproject.importer.impl.importables.QuestionPool;
25: import org.sakaiproject.importer.impl.importables.Assessment;
26: import org.sakaiproject.tool.assessment.services.QuestionPoolService;
27: import org.sakaiproject.tool.assessment.services.qti.QTIService;
28: import org.sakaiproject.tool.assessment.facade.ItemFacade;
29: import org.sakaiproject.tool.assessment.facade.QuestionPoolFacade;
30: import org.sakaiproject.tool.assessment.qti.constants.QTIVersion;
31: import org.sakaiproject.tool.cover.SessionManager;
32:
33: /**
34: *
35: * @author Joshua Ryan joshua.ryan@asu.edu
36: *
37: */
38: public class SamigoHandler implements HandlesImportable {
39:
40: //won't be needed if we can get a createImportedQuestionPool(Document, int)
41: //added to QTIService
42: private QuestionPoolService qps = new QuestionPoolService();
43:
44: public boolean canHandleType(String typeName) {
45: return ("sakai-question-pool".equals(typeName) || "sakai-assessment"
46: .equals(typeName));
47: }
48:
49: public void handle(Importable thing, String siteId) {
50:
51: if ("sakai-assessment".equals(thing.getTypeName())) {
52: Assessment assessment = (Assessment) thing;
53: // Document document = assessment.getQti();
54: // String version = assessment.getVersion();
55:
56: QTIService qtiService = new QTIService();
57:
58: //default to qti 2.0, the latest version Samigo can handle currently
59: int version = QTIVersion.VERSION_2_0;
60: if ("1.2".equals(assessment.getVersion()))
61: version = QTIVersion.VERSION_1_2;
62:
63: try {
64: qtiService.createImportedAssessment(
65: assessment.getQti(), version);
66: } catch (Exception e) {
67: e.printStackTrace();
68: }
69: } else if ("sakai-question-pool".equals(thing.getTypeName())) {
70: QuestionPool sourcePool = (QuestionPool) thing;
71:
72: // plan 'A'
73: // QTI question pool import support is being added to samigo
74: // currently just use this.
75:
76: // plan 'B' is to use QTIService to import items then add them
77: // to a pool like Zach did in the old brute force version... a
78: // rough version of which is seen below.
79:
80: QuestionPoolService qps = new QuestionPoolService();
81:
82: QuestionPoolFacade destinationPool = new QuestionPoolFacade();
83: destinationPool.setOwnerId(SessionManager
84: .getCurrentSessionUserId());
85: destinationPool.setTitle(sourcePool.getTitle());
86: destinationPool.setDescription(sourcePool.getDescription());
87:
88: QuestionPoolFacade savedPool = qps
89: .savePool(destinationPool);
90: /*
91: for (Iterator i = questionItems.iterator();i.hasNext();) {
92: ItemFacade item =
93: QTIService.createImportedItem(Document document, int qtiVersion);
94: qps.addItemToPool(item.getItemIdString(),savedPool.getQuestionPoolId());
95: }
96: */
97: }
98: }
99: }
|