Index: samigo-api/src/java/org/sakaiproject/tool/assessment/shared/api/qti/QTIServiceAPI.java
===================================================================
--- samigo-api/src/java/org/sakaiproject/tool/assessment/shared/api/qti/QTIServiceAPI.java (revision 120660)
+++ samigo-api/src/java/org/sakaiproject/tool/assessment/shared/api/qti/QTIServiceAPI.java (working copy)
@@ -40,6 +40,15 @@
int qtiVersion);
/**
+ * Import an assessment XML document in QTI format, extract & persist the data.
+ * @param documentPath the pathname to a file with the assessment XML document in QTI format
+ * @param qtiVersion either 1=QTI VERSION 1.2 or 2=QTI Version 2.0
+ * @param siteId the site the assessment will be associated with
+ * @return a persisted assessment
+ */
+ public AssessmentIfc createImportedAssessment(String documentPath, int qtiVersion, String siteId);
+
+ /**
* Import an item XML document in QTI format, extract & persist the data.
* @param document the item XML document in QTI format
* @param qtiVersion either 1=QTI VERSION 1.2 or 2=QTI Version 2.0
@@ -59,6 +68,17 @@
public Document getExportedAssessment(String assessmentId, int qtiVersion);
/**
+ * Get an assessment in String form.
+ *
+ * Note: this service requires a Faces context.
+ *
+ * @param assessmentId the assessment's Id
+ * @param qtiVersion either 1=QTI VERSION 1.2 or 2=QTI Version 2.0
+ * @return the Document with the assessment data
+ */
+ public String getExportedAssessmentAsString(String assessmentId, int qtiVersion);
+
+ /**
* Get an item in Document form.
*
* Note: this service requires a Faces context.
Index: samigo-pack/src/webapp/WEB-INF/components.xml
===================================================================
--- samigo-pack/src/webapp/WEB-INF/components.xml (revision 120660)
+++ samigo-pack/src/webapp/WEB-INF/components.xml (working copy)
@@ -278,11 +278,17 @@
+
+
+
+
+
Index: samigo-pack/pom.xml
===================================================================
--- samigo-pack/pom.xml (revision 120660)
+++ samigo-pack/pom.xml (working copy)
@@ -59,6 +59,12 @@
jsr173
1.0_api
+
+
+ ${project.groupId}
+ samigo-qti
+
+
Index: samigo-app/src/java/org/sakaiproject/tool/assessment/shared/impl/qti/QTIServiceImpl.java
===================================================================
--- samigo-app/src/java/org/sakaiproject/tool/assessment/shared/impl/qti/QTIServiceImpl.java (revision 120660)
+++ samigo-app/src/java/org/sakaiproject/tool/assessment/shared/impl/qti/QTIServiceImpl.java (working copy)
@@ -30,6 +30,7 @@
import org.sakaiproject.tool.assessment.services.qti.QTIService;
import org.sakaiproject.tool.assessment.shared.api.qti.QTIServiceAPI;
import org.sakaiproject.tool.assessment.services.qti.QTIServiceException;
+import org.sakaiproject.tool.assessment.qti.util.XmlUtil;
/**
* QTIServiceImpl implements a shared interface to get/set assessment
@@ -63,7 +64,47 @@
return null;
}
+ public AssessmentIfc createImportedAssessment(Document document, int qtiVersion, String unzipLocation, String templateId, String siteId) {
+ try
+ {
+ QTIService nativeQTIService = new QTIService();
+ return (AssessmentIfc) nativeQTIService.createImportedAssessment(document, qtiVersion, unzipLocation, templateId, siteId);
+ }
+ catch (Exception ex)
+ {
+ log.warn("createImportedAssessment() returning null");
+ //new QTIServiceException(ex);
+ }
+ log.error("createImportedAssessment() returning null");
+ return null;
+
+ }
+
/**
+ * Import an assessment XML document in QTI format, extract & persist the data.
+ * @param documentPath the pathname to a file with the assessment XML document in QTI format
+ * @param qtiVersion either 1=QTI VERSION 1.2 or 2=QTI Version 2.0
+ * @param siteId the site the assessment will be associated with
+ * @return a persisted assessment
+ */
+ public AssessmentIfc createImportedAssessment(String documentPath, int qtiVersion, String siteId)
+ {
+ try
+ {
+ QTIService nativeQTIService = new QTIService();
+ return (AssessmentIfc) nativeQTIService.createImportedAssessment(documentPath, qtiVersion, siteId);
+ }
+ catch (Exception ex)
+ {
+ log.warn("createImportedAssessment() returning null");
+ //new QTIServiceException(ex);
+ }
+ log.error("createImportedAssessment() returning null");
+ return null;
+ }
+
+
+ /**
* Import an item XML document in QTI format, extract & persist the data.
* @param document the item XML document in QTI format
* @param qtiVersion either 1=QTI VERSION 1.2 or 2=QTI Version 2.0;
@@ -112,7 +153,24 @@
return null;
}
+
/**
+ * Get an assessment in String form.
+ *
+ * Note: this service requires a Faces context.
+ *
+ * @param assessmentId the assessment's Id
+ * @param qtiVersion either 1=QTI VERSION 1.2 or 2=QTI Version 2.0
+ * @return the Document with the assessment data
+ */
+ public String getExportedAssessmentAsString(String assessmentId, int qtiVersion)
+ {
+ return XmlUtil.getDOMString(getExportedAssessment(assessmentId, qtiVersion));
+ }
+
+
+
+ /**
* Get an item in Document form.
*
* Note: this service requires a Faces context.
Index: samigo-services/src/java/org/sakaiproject/tool/assessment/services/assessment/AssessmentEntityProducer.java
===================================================================
--- samigo-services/src/java/org/sakaiproject/tool/assessment/services/assessment/AssessmentEntityProducer.java (revision 120660)
+++ samigo-services/src/java/org/sakaiproject/tool/assessment/services/assessment/AssessmentEntityProducer.java (working copy)
@@ -1,5 +1,8 @@
package org.sakaiproject.tool.assessment.services.assessment;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@@ -23,16 +26,25 @@
import org.sakaiproject.tool.assessment.data.dao.assessment.AssessmentData;
import org.sakaiproject.tool.assessment.data.dao.assessment.ItemData;
import org.sakaiproject.tool.assessment.data.dao.assessment.ItemText;
+import org.sakaiproject.tool.assessment.data.ifc.assessment.AssessmentIfc;
import org.sakaiproject.tool.assessment.facade.AssessmentFacade;
import org.sakaiproject.tool.assessment.facade.SectionFacade;
+import org.sakaiproject.tool.assessment.shared.api.qti.QTIServiceAPI;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
public class AssessmentEntityProducer implements EntityTransferrer,
EntityProducer, EntityTransferrerRefMigrator {
- private static Log log = LogFactory.getLog(AssessmentEntityProducer.class);
+ private static final int QTI_VERSION = 1;
+ private static final String ARCHIVED_ELEMENT = "assessment";
+ private static Log log = LogFactory.getLog(AssessmentEntityProducer.class);
+ private QTIServiceAPI qtiService;
public void init() {
log.info("init()");
@@ -47,6 +59,10 @@
public void destroy() {
}
+ public void setQtiService(QTIServiceAPI qtiService) {
+ this.qtiService = qtiService;
+ }
+
public String[] myToolIds() {
String[] toolIds = { "sakai.samigo" };
return toolIds;
@@ -65,8 +81,51 @@
}
public String archive(String siteId, Document doc, Stack stack,
- String archivePath, List attachments) {
- return null;
+
+ String archivePath, List attachments) {
+ StringBuilder results = new StringBuilder();
+ results.append("archiving ").append(getLabel()).append("\n");
+
+ String qtiPath = archivePath + File.separator + "qti";
+ File qtiDir = new File(qtiPath);
+ if (!qtiDir.isDirectory() && !qtiDir.mkdir()) {
+ log.error("Could not create directory " + qtiPath);
+ results.append("Could not create " + qtiPath + "\n");
+ return results.toString();
+ }
+
+ Element element = doc.createElement(this.getClass().getName());
+ ((Element) stack.peek()).appendChild(element);
+ stack.push(element);
+ AssessmentService assessmentService = new AssessmentService();
+ List assessmentList
+ = (List) assessmentService.getAllActiveAssessmentsbyAgent(siteId);
+ for (AssessmentData data : assessmentList) {
+ Element assessmentXml = doc.createElement(ARCHIVED_ELEMENT);
+ String id = data.getAssessmentId().toString();
+ assessmentXml.setAttribute("id", id);
+ FileWriter writer = null;
+ try {
+ File assessmentFile = new File(qtiPath + File.separator + ARCHIVED_ELEMENT + id + ".xml");
+ writer = new FileWriter(assessmentFile);
+ writer.write(qtiService.getExportedAssessmentAsString(id, QTI_VERSION));
+ } catch (IOException e) {
+ results.append(e.getMessage() + "\n");
+ log.error(e.getMessage(), e);
+ } finally {
+ if (writer != null) {
+ try {
+ writer.close();
+ } catch (Throwable t) {
+ log.error(t.getMessage(), t);
+ }
+ }
+ }
+ element.appendChild(assessmentXml);
+
+ }
+ stack.pop();
+ return results.toString();
}
public Entity getEntity(Reference ref) {
@@ -100,7 +159,35 @@
public String merge(String siteId, Element root, String archivePath,
String fromSiteId, Map attachmentNames, Map userIdTrans,
Set userListAllowImport) {
- return null;
+ if (log.isDebugEnabled()) log.debug("merging " + getLabel());
+ StringBuilder results = new StringBuilder();
+ String qtiPath = (new File(archivePath)).getParent()
+ + File.separator + "qti" + File.separator;
+ //TODO: replaced by getChildren when we make sure we have the
+ NodeList assessments = root.getElementsByTagName(ARCHIVED_ELEMENT);
+
+ DocumentBuilder dbuilder = null;
+ try {
+ dbuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ } catch (Throwable t) {
+ log.error(t.getMessage(), t);
+ return getLabel() + " Error: " + t.getMessage();
+ }
+
+ for (int i=0; iThis service provides translation between database and QTI representations.
@@ -43,7 +45,7 @@
* @version $Id$
*/
-public class QTIService
+public class QTIService implements QTIServiceAPI
{
private static Log log = LogFactory.getLog(QTIService.class);
public QTIService()
@@ -111,6 +113,25 @@
throw new QTIServiceException(ex);
}
}
+
+ /**
+ * Import an assessment XML document in QTI format, extract & persist the data.
+ * @param documentPath the pathname to a file with the assessment XML document in QTI format
+ * @param qtiVersion either 1=QTI VERSION 1.2 or 2=QTI Version 2.0
+ * @param siteId the site the assessment will be associated with
+ * @return a persisted assessment
+ */
+ public AssessmentFacade createImportedAssessment(String documentPath, int qtiVersion, String siteId)
+ {
+ try {
+ return createImportedAssessment(XmlUtil.readDocument(documentPath, true),
+ qtiVersion, null, null, siteId);
+ } catch (Exception e) {
+ throw new QTIServiceException(e);
+ }
+
+ }
+
/**
* Import an assessment XML document in QTI format, extract & persist the data.
@@ -185,6 +206,21 @@
}
/**
+ * Get an assessment in String form.
+ *
+ * Note: this service requires a Faces context.
+ *
+ * @param assessmentId the assessment's Id
+ * @param qtiVersion either 1=QTI VERSION 1.2 or 2=QTI Version 2.0
+ * @return the Document with the assessment data
+ */
+ public String getExportedAssessmentAsString(String assessmentId, int qtiVersion)
+ {
+ return XmlUtil.getDOMString(getExportedAssessment(assessmentId, qtiVersion));
+ }
+
+
+ /**
* Get an item in Document form.
*
* Note: this service requires a Faces context.
Index: samigo-qti/src/java/org/sakaiproject/tool/assessment/qti/util/XmlUtil.java
===================================================================
--- samigo-qti/src/java/org/sakaiproject/tool/assessment/qti/util/XmlUtil.java (revision 120660)
+++ samigo-qti/src/java/org/sakaiproject/tool/assessment/qti/util/XmlUtil.java (working copy)
@@ -147,8 +147,6 @@
log.debug("readDocument(String " + path + ")");
}
- log.debug("readDocument(String " + path + ")");
-
Document document = null;
InputStream inputStream = context.getResourceAsStream(path);
String fullpath = context.getRealPath(path);
@@ -193,8 +191,6 @@
log.debug("readDocument(String " + path + ")");
}
- log.debug("readDocument(String " + path + ")");
-
Document document = null;
DocumentBuilderFactory builderFactory =
DocumentBuilderFactory.newInstance();
@@ -485,9 +481,6 @@
"Document transformDocument(Document " + document + ", Document " +
stylesheet + ")");
}
- log.debug(
- "Document transformDocument(Document " + document + ", Document " +
- stylesheet + ")");
Document transformedDoc = createDocument();
DOMSource docSource = new DOMSource(document);
@@ -505,7 +498,8 @@
public static Document transformDocument(Document document, Transformer transformer)
{
- log.debug("Document transformDocument(Document " + document + ", Trasformer " + transformer);
+ if(log.isDebugEnabled()) log.debug("Document transformDocument(Document " + document + ", Trasformer " + transformer);
+
Document transformedDoc = createDocument();
DOMSource docSource = new DOMSource(document);
DOMResult docResult = new DOMResult(transformedDoc);
Index: samigo-qti/pom.xml
===================================================================
--- samigo-qti/pom.xml (revision 120660)
+++ samigo-qti/pom.xml (working copy)
@@ -35,6 +35,11 @@
org.sakaiproject.kernel
sakai-component-manager
+
+ org.sakaiproject.kernel
+ sakai-kernel-util
+ provided
+
${project.groupId}
samigo-api
@@ -42,6 +47,7 @@
${project.groupId}
samigo-services
+ provided
${project.groupId}