1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.kuali.student.lum.service.assembler; |
17 |
|
|
18 |
|
import org.kuali.student.common.assembly.BaseDTOAssemblyNode; |
19 |
|
import org.kuali.student.common.assembly.BaseDTOAssemblyNode.NodeOperation; |
20 |
|
import org.kuali.student.common.assembly.data.AssemblyException; |
21 |
|
import org.kuali.student.common.dto.DtoConstants; |
22 |
|
import org.kuali.student.common.dto.RichTextInfo; |
23 |
|
import org.kuali.student.common.exceptions.DoesNotExistException; |
24 |
|
import org.kuali.student.common.exceptions.InvalidParameterException; |
25 |
|
import org.kuali.student.common.exceptions.MissingParameterException; |
26 |
|
import org.kuali.student.common.exceptions.OperationFailedException; |
27 |
|
import org.kuali.student.lum.course.dto.LoDisplayInfo; |
28 |
|
import org.kuali.student.lum.course.service.assembler.LoAssembler; |
29 |
|
import org.kuali.student.lum.lo.dto.LoInfo; |
30 |
|
import org.kuali.student.lum.lo.service.LearningObjectiveService; |
31 |
|
import org.kuali.student.lum.lu.dto.CluLoRelationInfo; |
32 |
|
import org.kuali.student.lum.lu.dto.CluResultInfo; |
33 |
|
import org.kuali.student.lum.lu.dto.ResultOptionInfo; |
34 |
|
import org.kuali.student.lum.lu.service.LuService; |
35 |
|
|
36 |
|
import java.util.ArrayList; |
37 |
|
import java.util.Date; |
38 |
|
import java.util.HashMap; |
39 |
|
import java.util.List; |
40 |
|
import java.util.Map; |
41 |
|
import java.util.Map.Entry; |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
@author |
47 |
|
|
48 |
|
|
|
|
| 83.1% |
Uncovered Elements: 25 (148) |
Complexity: 31 |
Complexity Density: 0.27 |
|
49 |
|
public class CluAssemblerUtils { |
50 |
|
private LuService luService; |
51 |
|
private LearningObjectiveService loService; |
52 |
|
private LoAssembler loAssembler; |
53 |
|
|
|
|
| 75% |
Uncovered Elements: 3 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
54 |
60
|
public List<String> assembleCluResults(List<String> resultTypes, List<CluResultInfo> cluResults) throws AssemblyException{... |
55 |
60
|
if(resultTypes==null){ |
56 |
0
|
throw new AssemblyException("result types can not be null"); |
57 |
|
} |
58 |
60
|
List<String> results = new ArrayList<String>(); |
59 |
|
|
60 |
60
|
for(CluResultInfo cluResult:cluResults){ |
61 |
57
|
if(resultTypes.contains(cluResult.getType())){ |
62 |
|
|
63 |
57
|
for(ResultOptionInfo resultOption: cluResult.getResultOptions()){ |
64 |
76
|
results.add(resultOption.getResultComponentId()); |
65 |
|
} |
66 |
|
} |
67 |
|
} |
68 |
60
|
return results; |
69 |
|
} |
70 |
|
|
|
|
| 85.2% |
Uncovered Elements: 9 (61) |
Complexity: 12 |
Complexity Density: 0.26 |
|
71 |
36
|
public BaseDTOAssemblyNode<?, ?> disassembleCluResults(String cluId,... |
72 |
|
String cluState, List<String> options, NodeOperation operation, String resultType, |
73 |
|
String resultsDescription, String resultDescription) throws AssemblyException { |
74 |
36
|
BaseDTOAssemblyNode<List<String>, CluResultInfo> cluResultNode = new BaseDTOAssemblyNode<List<String>, CluResultInfo>(null); |
75 |
36
|
if(resultType==null){ |
76 |
0
|
throw new AssemblyException("resultType can not be null"); |
77 |
|
} |
78 |
|
|
79 |
|
|
80 |
36
|
Map<String, ResultOptionInfo> currentResults = new HashMap<String, ResultOptionInfo>(); |
81 |
|
|
82 |
36
|
CluResultInfo cluResult = null; |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
36
|
if (!NodeOperation.CREATE.equals(operation)) { |
87 |
25
|
try { |
88 |
25
|
List<CluResultInfo> cluResultList = luService.getCluResultByClu(cluId); |
89 |
|
|
90 |
25
|
for (CluResultInfo currentResult : cluResultList) { |
91 |
18
|
if (resultType.equals(currentResult.getType())) { |
92 |
18
|
cluResult = currentResult; |
93 |
18
|
if(NodeOperation.DELETE.equals(operation)){ |
94 |
|
|
95 |
0
|
cluResultNode.setOperation(NodeOperation.DELETE); |
96 |
|
}else{ |
97 |
|
|
98 |
18
|
cluResultNode.setOperation(NodeOperation.UPDATE); |
99 |
|
|
100 |
18
|
for(ResultOptionInfo resultOption:currentResult.getResultOptions()){ |
101 |
|
|
102 |
|
|
103 |
24
|
resultOption.setState(cluState); |
104 |
24
|
currentResults.put(resultOption.getResultComponentId(), resultOption); |
105 |
|
} |
106 |
|
} |
107 |
|
} |
108 |
|
} |
109 |
|
} catch (DoesNotExistException e) { |
110 |
|
} catch (InvalidParameterException e) { |
111 |
0
|
throw new AssemblyException("Error getting related " + resultsDescription, e); |
112 |
|
} catch (MissingParameterException e) { |
113 |
0
|
throw new AssemblyException("Error getting related " + resultsDescription, e); |
114 |
|
} catch (OperationFailedException e) { |
115 |
0
|
throw new AssemblyException("Error getting related " + resultsDescription, e); |
116 |
|
} |
117 |
|
} |
118 |
|
|
119 |
|
|
120 |
36
|
if(!NodeOperation.DELETE.equals(operation)){ |
121 |
36
|
if(cluResult == null){ |
122 |
|
|
123 |
18
|
cluResult = new CluResultInfo(); |
124 |
18
|
cluResult.setCluId(cluId); |
125 |
18
|
cluResult.setState(cluState); |
126 |
18
|
cluResult.setType(resultType); |
127 |
18
|
RichTextInfo desc = new RichTextInfo(); |
128 |
18
|
desc.setPlain(resultsDescription); |
129 |
18
|
cluResult.setDesc(desc); |
130 |
18
|
cluResult.setEffectiveDate(new Date()); |
131 |
18
|
cluResultNode.setOperation(NodeOperation.CREATE); |
132 |
|
} |
133 |
|
|
134 |
|
|
135 |
36
|
cluResult.setResultOptions(new ArrayList<ResultOptionInfo>()); |
136 |
|
|
137 |
|
|
138 |
|
|
139 |
36
|
cluResult.setState(cluState); |
140 |
|
|
141 |
|
|
142 |
36
|
for (String optionType : options) { |
143 |
57
|
if(currentResults.containsKey(optionType)){ |
144 |
|
|
145 |
24
|
ResultOptionInfo resultOptionInfo = currentResults.get(optionType); |
146 |
|
|
147 |
|
|
148 |
|
|
149 |
24
|
resultOptionInfo.setState(cluState); |
150 |
24
|
cluResult.getResultOptions().add(resultOptionInfo); |
151 |
|
}else{ |
152 |
|
|
153 |
33
|
ResultOptionInfo resultOptionInfo = new ResultOptionInfo(); |
154 |
33
|
RichTextInfo desc = new RichTextInfo(); |
155 |
33
|
desc.setPlain(resultDescription); |
156 |
33
|
resultOptionInfo.setDesc(desc); |
157 |
33
|
resultOptionInfo.setResultComponentId(optionType); |
158 |
|
|
159 |
|
|
160 |
|
|
161 |
33
|
resultOptionInfo.setState(cluState); |
162 |
|
|
163 |
33
|
cluResult.getResultOptions().add(resultOptionInfo); |
164 |
|
} |
165 |
|
} |
166 |
|
} |
167 |
|
|
168 |
36
|
cluResultNode.setNodeData(cluResult); |
169 |
36
|
return cluResultNode; |
170 |
|
} |
171 |
|
|
|
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 2 |
Complexity Density: 0.22 |
|
172 |
97
|
public List<LoDisplayInfo> assembleLos(String cluId, boolean shallowBuild) throws AssemblyException {... |
173 |
97
|
List<LoDisplayInfo> loInfos = new ArrayList<LoDisplayInfo>(); |
174 |
97
|
try { |
175 |
97
|
List<CluLoRelationInfo> cluLoRelations = luService.getCluLoRelationsByClu(cluId); |
176 |
97
|
for (CluLoRelationInfo cluLoRelation : cluLoRelations) { |
177 |
82
|
String loId = cluLoRelation.getLoId(); |
178 |
82
|
LoInfo lo = loService.getLo(loId); |
179 |
82
|
loInfos.add(loAssembler.assemble(lo, null, shallowBuild)); |
180 |
|
} |
181 |
|
} catch (Exception e) { |
182 |
0
|
throw new AssemblyException("Error getting learning objectives", e); |
183 |
|
} |
184 |
|
|
185 |
97
|
return loInfos; |
186 |
|
} |
187 |
|
|
|
|
| 78.6% |
Uncovered Elements: 12 (56) |
Complexity: 11 |
Complexity Density: 0.23 |
|
188 |
61
|
public List<BaseDTOAssemblyNode<?, ?>> disassembleLos(String cluId, String cluState, List<LoDisplayInfo> loInfos,... |
189 |
|
NodeOperation operation) throws AssemblyException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException{ |
190 |
|
|
191 |
61
|
List<BaseDTOAssemblyNode<?, ?>> results = new ArrayList<BaseDTOAssemblyNode<?, ?>>(); |
192 |
|
|
193 |
|
|
194 |
|
|
195 |
61
|
Map<String, CluLoRelationInfo> currentCluLoRelations = new HashMap<String, CluLoRelationInfo>(); |
196 |
61
|
try { |
197 |
61
|
List<CluLoRelationInfo> cluLoRelations = luService.getCluLoRelationsByClu(cluId); |
198 |
61
|
for(CluLoRelationInfo cluLoRelation:cluLoRelations){ |
199 |
16
|
if(CluAssemblerConstants.CLU_LO_CLU_SPECIFIC_RELATION.equals(cluLoRelation.getType())){ |
200 |
16
|
currentCluLoRelations.put(cluLoRelation.getLoId(), cluLoRelation); |
201 |
|
} |
202 |
|
} |
203 |
|
} catch (DoesNotExistException e) { |
204 |
|
} catch (Exception e) { |
205 |
0
|
throw new AssemblyException("Error finding related Los", e); |
206 |
|
} |
207 |
|
|
208 |
|
|
209 |
61
|
for(LoDisplayInfo loDisplay : loInfos){ |
210 |
|
|
211 |
|
|
212 |
70
|
if (NodeOperation.CREATE == operation |
213 |
|
|| (NodeOperation.UPDATE == operation && !currentCluLoRelations.containsKey(loDisplay.getLoInfo().getId()))) { |
214 |
|
|
215 |
|
|
216 |
|
|
217 |
54
|
loDisplay.getLoInfo().setId(null); |
218 |
54
|
loDisplay.getLoInfo().setState(cluState); |
219 |
54
|
BaseDTOAssemblyNode<LoDisplayInfo, LoInfo> loNode = loAssembler |
220 |
|
.disassemble(loDisplay, NodeOperation.CREATE); |
221 |
54
|
results.add(loNode); |
222 |
|
|
223 |
|
|
224 |
54
|
CluLoRelationInfo relation = new CluLoRelationInfo(); |
225 |
54
|
relation.setCluId(cluId); |
226 |
54
|
relation.setLoId(loNode.getNodeData().getId()); |
227 |
54
|
relation.setType(CluAssemblerConstants.CLU_LO_CLU_SPECIFIC_RELATION); |
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
|
232 |
54
|
relation.setState(DtoConstants.STATE_ACTIVE); |
233 |
|
|
234 |
54
|
BaseDTOAssemblyNode<LoDisplayInfo, CluLoRelationInfo> relationNode = new BaseDTOAssemblyNode<LoDisplayInfo, CluLoRelationInfo>( |
235 |
|
null); |
236 |
54
|
relationNode.setNodeData(relation); |
237 |
54
|
relationNode.setOperation(NodeOperation.CREATE); |
238 |
|
|
239 |
54
|
results.add(relationNode); |
240 |
16
|
} else if (NodeOperation.UPDATE == operation |
241 |
|
&& currentCluLoRelations.containsKey(loDisplay.getLoInfo().getId())) { |
242 |
|
|
243 |
|
|
244 |
14
|
loDisplay.getLoInfo().setState(cluState); |
245 |
14
|
BaseDTOAssemblyNode<LoDisplayInfo, LoInfo> loNode = loAssembler |
246 |
|
.disassemble(loDisplay, NodeOperation.UPDATE); |
247 |
14
|
results.add(loNode); |
248 |
|
|
249 |
|
|
250 |
|
|
251 |
14
|
currentCluLoRelations.remove(loDisplay.getLoInfo().getId()); |
252 |
2
|
} else if (NodeOperation.DELETE == operation |
253 |
|
&& currentCluLoRelations.containsKey(loDisplay.getLoInfo().getId())) { |
254 |
|
|
255 |
|
|
256 |
2
|
CluLoRelationInfo relationToDelete = currentCluLoRelations.get(loDisplay.getLoInfo().getId()); |
257 |
2
|
BaseDTOAssemblyNode<LoDisplayInfo, CluLoRelationInfo> relationToDeleteNode = new BaseDTOAssemblyNode<LoDisplayInfo, CluLoRelationInfo>( |
258 |
|
null); |
259 |
2
|
relationToDeleteNode.setNodeData(relationToDelete); |
260 |
2
|
relationToDeleteNode.setOperation(NodeOperation.DELETE); |
261 |
2
|
results.add(relationToDeleteNode); |
262 |
|
|
263 |
2
|
BaseDTOAssemblyNode<LoDisplayInfo, LoInfo> loNode = loAssembler |
264 |
|
.disassemble(loDisplay, NodeOperation.DELETE); |
265 |
2
|
results.add(loNode); |
266 |
|
|
267 |
|
|
268 |
|
|
269 |
2
|
currentCluLoRelations.remove(loDisplay.getLoInfo().getId()); |
270 |
|
} |
271 |
|
} |
272 |
|
|
273 |
|
|
274 |
|
|
275 |
61
|
for (Entry<String, CluLoRelationInfo> entry : currentCluLoRelations.entrySet()) { |
276 |
|
|
277 |
|
|
278 |
0
|
CluLoRelationInfo relationToDelete = entry.getValue(); |
279 |
0
|
BaseDTOAssemblyNode<LoDisplayInfo, CluLoRelationInfo> relationToDeleteNode = new BaseDTOAssemblyNode<LoDisplayInfo, CluLoRelationInfo>( |
280 |
|
null); |
281 |
0
|
relationToDeleteNode.setNodeData(relationToDelete); |
282 |
0
|
relationToDeleteNode.setOperation(NodeOperation.DELETE); |
283 |
0
|
results.add(relationToDeleteNode); |
284 |
|
|
285 |
0
|
LoInfo loToDelete = loService.getLo(entry.getKey()); |
286 |
0
|
LoDisplayInfo loDisplayToDelete = loAssembler.assemble(loToDelete, null, false); |
287 |
0
|
BaseDTOAssemblyNode<LoDisplayInfo, LoInfo> loNode = loAssembler |
288 |
|
.disassemble(loDisplayToDelete, NodeOperation.DELETE); |
289 |
0
|
results.add(loNode); |
290 |
|
} |
291 |
|
|
292 |
61
|
return results; |
293 |
|
} |
294 |
|
|
295 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
296 |
2
|
public void setLuService(LuService luService) {... |
297 |
2
|
this.luService = luService; |
298 |
|
} |
299 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
300 |
2
|
public void setLoService(LearningObjectiveService loService) {... |
301 |
2
|
this.loService = loService; |
302 |
|
} |
303 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
304 |
2
|
public void setLoAssembler(LoAssembler loAssembler) {... |
305 |
2
|
this.loAssembler = loAssembler; |
306 |
|
} |
307 |
|
} |