1 /***
2 * Created on Jan 10, 2006, Copyright UC Regents
3 */
4 package org.telscenter.pas.util;
5
6 import static net.sf.sail.core.util.PodUtils.createRimInPod;
7
8 import java.util.ArrayList;
9 import java.util.List;
10
11 import net.sf.sail.core.beans.Pod;
12 import net.sf.sail.core.entity.Rim;
13 import net.sf.sail.core.util.PodUtils;
14
15 import org.telscenter.pas.steps.Assessment;
16 import org.telscenter.pas.steps.domain.AssessmentItem;
17 import org.telscenter.pas.steps.domain.BlockInteraction;
18 import org.telscenter.pas.steps.domain.ChoiceInteraction;
19 import org.telscenter.pas.steps.domain.ResponseDeclaration;
20 import org.telscenter.pas.steps.domain.SimpleChoice;
21
22 /***
23 * @author aperritano
24 *
25 */
26 public class QTIUtils {
27
28 public static final String RESPONSE_ID = "RESPONSE_ID";
29 public static final String SIMPLE_CHOICE = "SIMPLE_CHOICE";
30
31 /***
32 *
33 */
34 public QTIUtils() {
35 super();
36
37 }
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 public static void removeBlockInteraction(AssessmentItem assItem,
60 BlockInteraction interaction) {
61
62 if (assItem == null)
63 return;
64
65 if (interaction == null)
66 return;
67
68 assItem.getItemBody().getInteractions().remove(interaction);
69
70 }
71
72 /***
73 * @param interaction
74 * @param newSimpleChoice
75 * @param newChoiceIndex
76 */
77 public static void addChoice(BlockInteraction interaction,
78 SimpleChoice<String> newSimpleChoice, int newChoiceIndex) {
79 if (interaction == null)
80 return;
81
82 if (newSimpleChoice == null)
83 return;
84
85 ChoiceInteraction<String> ci = (ChoiceInteraction<String>) interaction;
86 ci.getSimpleChoices().add(newChoiceIndex - 1, newSimpleChoice);
87 }
88
89 /***
90 * @param interaction
91 * @param simpleChoice
92 */
93 public static void removeChoice(BlockInteraction interaction,
94 SimpleChoice<String> simpleChoice) {
95 if (interaction == null)
96 return;
97
98 if (simpleChoice == null)
99 return;
100
101 ChoiceInteraction<String> ci = (ChoiceInteraction<String>) interaction;
102 ci.getSimpleChoices().remove(simpleChoice);
103 }
104
105 /***
106 * @param assmtBean
107 * @param bi
108 * @param string
109 * @param rimIndex
110 * @param responseDeclarations
111 */
112 public static void addBlockInteraction(Assessment assmtBean,
113 BlockInteraction interaction, String keyString, int rimIndex,
114 List<ResponseDeclaration> responseDeclarations) {
115
116 if (assmtBean.getAssessmentItem() == null) {
117 return;
118 }
119
120 if (interaction == null)
121 return;
122
123 ResponseDeclaration rd = new ResponseDeclaration();
124
125 rd.setIdentifier(keyString + "_" + rimIndex);
126 interaction.setResponseIdentifier(rd.getIdentifier());
127
128 responseDeclarations.add(rd);
129 assmtBean.getAssessmentItem().getItemBody().getInteractions().add(
130 interaction);
131
132
133
134 Pod stepPod = PodUtils.resolvePod(assmtBean);
135
136 Rim<String> rim = createRimInPod(stepPod, String.class,
137 keyString + "_RIM_" + rimIndex);
138
139 rd.setRim(rim);
140
141
142
143
144
145
146
147
148 assmtBean.getAssessmentItem().setResponseDeclarations(
149 responseDeclarations);
150
151 }
152
153 /***
154 * @param assmtBean
155 * @param bi
156 * @param string
157 * @param rimIndex
158 * @param responseDeclarations
159 */
160 public static void addJaxbBlockInteraction(Assessment assmtBean,
161 BlockInteraction interaction, String keyString, int rimIndex,
162 List<ResponseDeclaration> responseDeclarations) {
163
164 if (assmtBean.getAssessmentItem() == null) {
165 return;
166 }
167
168 if (interaction == null)
169 return;
170
171 ResponseDeclaration rd = new ResponseDeclaration();
172
173 rd.setIdentifier(keyString + "_" + rimIndex);
174 interaction.setResponseIdentifier(rd.getIdentifier());
175
176 responseDeclarations.add(rd);
177 assmtBean.getAssessmentItem().getItemBody().getInteractions().add(
178 interaction);
179
180
181
182 Pod stepPod = PodUtils.resolvePod(assmtBean);
183
184 Rim<String> rim = createRimInPod(stepPod, String.class,
185 keyString + "_RIM_" + rimIndex);
186
187 rd.setRim(rim);
188
189
190
191
192
193
194
195
196 assmtBean.getAssessmentItem().setResponseDeclarations(
197 responseDeclarations);
198
199 }
200
201 /***
202 * Gets the correct responses for this choice
203 *
204 * @param responseDeclarations
205 * @param interaction
206 */
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223 /***
224 * Checks the answerID vs the correct answer id in response declaration
225 *
226 * @param rd
227 * @param answerId
228 * @return
229 */
230 public static boolean isCorrectAnswer(ResponseDeclaration rd, String answerId) {
231 return rd.getCorrectResponses().contains(answerId);
232 }
233 }