1 package org.telscenter.pas.otrunk.skeleton.controllers;
2
3 import java.io.ByteArrayInputStream;
4 import java.io.IOException;
5 import java.io.InputStream;
6 import java.util.HashMap;
7 import java.util.List;
8 import java.util.Map;
9
10 import javax.xml.bind.JAXBException;
11
12 import net.sf.sail.core.entity.Rim;
13 import net.sf.sail.jaxb.extension.JaxbQtiMarshallingUtils;
14
15 import org.apache.commons.lang.StringUtils;
16 import org.concord.framework.otrunk.OTXMLString;
17 import org.imsglobal.xsd.imsqti_v2p0.AssessmentItemType;
18 import org.imsglobal.xsd.imsqti_v2p0.ResponseDeclarationType;
19 import org.telscenter.pas.otrunk.skeleton.steps.OTAssessment;
20 import org.telscenter.pas.steps.JaxbQtiStep;
21
22 /***
23 * Controller for assessments
24 *
25 * @author aperritano
26 *
27 */
28 public class OTAssessmentController extends OTPasStepController {
29
30 public static Class[] realObjectClasses = { JaxbQtiStep.class };
31 public static Class otObjectClass = OTAssessment.class;
32 public static String xmlHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
33
34
35 public void loadRealObject(Object realObject) {
36 super.loadRealObject(realObject);
37
38 JaxbQtiStep assessment = (JaxbQtiStep) realObject;
39 OTAssessment otAssessment = (OTAssessment) otObject;
40
41 OTXMLString jaxbXML = otAssessment.getJaxbXML();
42
43
44
45 if( jaxbXML != null ) {
46 InputStream is = new ByteArrayInputStream(jaxbXML.getContent().getBytes());
47 try {
48 AssessmentItemType unmarshallAssessmentItemType = JaxbQtiMarshallingUtils.unmarshallAssessmentItemType(is);
49 is.close();
50 assessment.setAssessmentItem(unmarshallAssessmentItemType);
51
52
53
54 List<ResponseDeclarationType> responseDeclaration = unmarshallAssessmentItemType.getResponseDeclaration();
55 if( !responseDeclaration.isEmpty() ) {
56 Map<ResponseDeclarationType, Rim> responseDeclarationsToRims = new HashMap<ResponseDeclarationType, Rim>();
57
58
59
60 for (ResponseDeclarationType responseDeclarationType : responseDeclaration) {
61 Rim rim = new OTrunkRim(responseDeclarationType.getIdentifier(), String.class, otAssessment);
62 responseDeclarationsToRims.put(responseDeclarationType, rim);
63 }
64
65 assessment.setResponseDeclarationsToRims(responseDeclarationsToRims);
66 }
67
68 } catch (JAXBException e) {
69 e.printStackTrace();
70 } catch (IOException e) {
71 e.printStackTrace();
72 }
73 }
74
75 assessment.setInjectPrompt(otAssessment.getIsInjectPrompt());
76
77
78
79 assessment.setLockStudentAnswers(otAssessment.isLockStudentAnswers());
80
81 }
82
83 public void registerRealObject(Object realObject) {
84
85 }
86
87 public void saveRealObject(Object realObject) {
88 super.saveRealObject(realObject);
89
90 JaxbQtiStep assessment = (JaxbQtiStep) realObject;
91 OTAssessment otAssessment = (OTAssessment) otObject;
92
93 otAssessment.setIsInjectPrompt(assessment.isInjectPrompt());
94
95
96 String xmlString = null;
97 try {
98 xmlString = JaxbQtiMarshallingUtils.marshallAssessmentItemTypeToString(assessment.getAssessmentItem());
99 StringBuffer parser = new StringBuffer(xmlString);
100 StringUtils.replace(xmlString, xmlHeader, "");
101 System.out.println("xmlString " + xmlString);
102
103 } catch (JAXBException e) {
104 e.printStackTrace();
105 }
106
107 OTXMLString jaxbXML = new OTXMLString(xmlString);
108 otAssessment.setJaxbXML(jaxbXML);
109 otAssessment.setLockStudentAnswers(assessment.isLockStudentAnswers());
110
111
112 }
113
114
115
116 }