1 package org.kuali.student.lum.service.assembler;
2
3 import java.util.List;
4
5 import org.apache.log4j.Logger;
6 import org.kuali.student.common.assembly.BaseDTOAssemblyNode;
7 import org.kuali.student.common.assembly.BusinessServiceMethodInvoker;
8 import org.kuali.student.common.assembly.BaseDTOAssemblyNode.NodeOperation;
9 import org.kuali.student.common.assembly.data.AssemblyException;
10 import org.kuali.student.common.exceptions.AlreadyExistsException;
11 import org.kuali.student.common.exceptions.CircularReferenceException;
12 import org.kuali.student.common.exceptions.CircularRelationshipException;
13 import org.kuali.student.common.exceptions.DataValidationErrorException;
14 import org.kuali.student.common.exceptions.DependentObjectsExistException;
15 import org.kuali.student.common.exceptions.DoesNotExistException;
16 import org.kuali.student.common.exceptions.InvalidParameterException;
17 import org.kuali.student.common.exceptions.MissingParameterException;
18 import org.kuali.student.common.exceptions.OperationFailedException;
19 import org.kuali.student.common.exceptions.PermissionDeniedException;
20 import org.kuali.student.common.exceptions.UnsupportedActionException;
21 import org.kuali.student.common.exceptions.VersionMismatchException;
22 import org.kuali.student.core.atp.service.AtpService;
23 import org.kuali.student.core.organization.service.OrganizationService;
24 import org.kuali.student.core.statement.dto.RefStatementRelationInfo;
25 import org.kuali.student.core.statement.dto.ReqComponentInfo;
26 import org.kuali.student.core.statement.dto.StatementInfo;
27 import org.kuali.student.core.statement.dto.StatementTreeViewInfo;
28 import org.kuali.student.core.statement.service.StatementService;
29 import org.kuali.student.lum.course.service.assembler.LoCategoryRelationInfo;
30 import org.kuali.student.lum.lo.dto.LoInfo;
31 import org.kuali.student.lum.lo.dto.LoLoRelationInfo;
32 import org.kuali.student.lum.lo.service.LearningObjectiveService;
33 import org.kuali.student.lum.lrc.dto.ResultComponentInfo;
34 import org.kuali.student.lum.lrc.service.LrcService;
35 import org.kuali.student.lum.lu.dto.CluCluRelationInfo;
36 import org.kuali.student.lum.lu.dto.CluInfo;
37 import org.kuali.student.lum.lu.dto.CluLoRelationInfo;
38 import org.kuali.student.lum.lu.dto.CluPublicationInfo;
39 import org.kuali.student.lum.lu.dto.CluResultInfo;
40 import org.kuali.student.lum.lu.service.LuService;
41
42 public class LumServiceMethodInvoker implements BusinessServiceMethodInvoker {
43 final Logger LOG = Logger.getLogger(LumServiceMethodInvoker.class);
44 private LuService luService;
45 private StatementService statementService;
46 private LearningObjectiveService loService;
47 private OrganizationService orgService;
48 private AtpService atpService;
49 private LrcService lrcService;
50
51 @SuppressWarnings("unchecked")
52 public final void invokeServiceCalls(BaseDTOAssemblyNode results)
53 throws AlreadyExistsException, DataValidationErrorException,
54 DoesNotExistException, InvalidParameterException,
55 MissingParameterException, OperationFailedException,
56 PermissionDeniedException, VersionMismatchException,
57 DependentObjectsExistException, CircularRelationshipException,
58 AssemblyException, UnsupportedActionException, UnsupportedOperationException, CircularReferenceException {
59
60
61 if(NodeOperation.DELETE == results.getOperation()) {
62 for(BaseDTOAssemblyNode childNode: (List<BaseDTOAssemblyNode>) results.getChildNodes()){
63 invokeServiceCalls(childNode);
64 }
65 }
66
67 invokeServiceCallOnResult(results);
68
69
70 if(NodeOperation.DELETE != results.getOperation()) {
71 for(BaseDTOAssemblyNode childNode: (List<BaseDTOAssemblyNode>) results.getChildNodes()){
72 invokeServiceCalls(childNode);
73 }
74 }
75 }
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94 protected void invokeServiceCallOnResult(BaseDTOAssemblyNode results)
95 throws AlreadyExistsException, DataValidationErrorException,
96 DoesNotExistException, InvalidParameterException,
97 MissingParameterException, OperationFailedException,
98 PermissionDeniedException, AssemblyException,
99 VersionMismatchException, DependentObjectsExistException,
100 CircularRelationshipException, UnsupportedActionException,
101 UnsupportedOperationException, CircularReferenceException {
102 Object nodeData = results.getNodeData();
103 if (nodeData == null) {
104 return;
105 }
106
107 if (LOG.isDebugEnabled()) {
108 LOG.debug(results.getOperation() + ": " + nodeData);
109 }
110
111 if(nodeData instanceof CluInfo){
112 CluInfo clu = (CluInfo) nodeData;
113 switch(results.getOperation()){
114 case CREATE:
115 CluInfo newClu = luService.createClu(clu.getType(), clu);
116 if(results.getAssembler() != null) {
117 results.getAssembler().assemble(newClu, results.getBusinessDTORef(), true);
118 }
119 break;
120 case UPDATE:
121 CluInfo updatedClu = luService.updateClu(clu.getId(), clu);
122 if(results.getAssembler() != null) {
123 results.getAssembler().assemble(updatedClu, results.getBusinessDTORef(), true);
124 }
125 break;
126 case DELETE:
127 luService.deleteClu(clu.getId());
128 break;
129 }
130 }else if(nodeData instanceof CluCluRelationInfo){
131 CluCluRelationInfo relation = (CluCluRelationInfo) nodeData;
132 switch(results.getOperation()){
133 case CREATE:
134 CluCluRelationInfo newCluRel = luService.createCluCluRelation(relation.getCluId(), relation.getRelatedCluId(), relation.getType(), relation);
135
136 if(null != results.getBusinessDTORef()) {
137 results.getAssembler().assemble(newCluRel, results.getBusinessDTORef(), true);
138 }
139 break;
140 case UPDATE:
141 CluCluRelationInfo updatedCluRel = luService.updateCluCluRelation(relation.getId(), relation);
142
143 if(null != results.getBusinessDTORef()) {
144 results.getAssembler().assemble(updatedCluRel, results.getBusinessDTORef(), true);
145 }
146 break;
147 case DELETE:
148 luService.deleteCluCluRelation(relation.getId());
149 break;
150 }
151 }else if(nodeData instanceof CluResultInfo){
152 CluResultInfo cluResult = (CluResultInfo) nodeData;
153 switch(results.getOperation()){
154 case CREATE:
155 luService.createCluResult(cluResult.getCluId(), cluResult.getType(), cluResult);
156 break;
157 case UPDATE:
158 luService.updateCluResult(cluResult.getId(), cluResult);
159 break;
160 case DELETE:
161 luService.deleteCluResult(cluResult.getId());
162 break;
163 }
164 }else if(nodeData instanceof LoCategoryRelationInfo){
165 LoCategoryRelationInfo loCategoryRelation = (LoCategoryRelationInfo) nodeData;
166 switch(results.getOperation()){
167 case CREATE:
168 loService.addLoCategoryToLo(loCategoryRelation.getCategoryId(), loCategoryRelation.getLoId());
169 break;
170 case UPDATE:
171 throw new UnsupportedOperationException("Can't call update on lo category relations, just add and remove");
172 case DELETE:
173 loService.removeLoCategoryFromLo(loCategoryRelation.getCategoryId(), loCategoryRelation.getLoId());
174 break;
175 }
176 }else if(nodeData instanceof LoInfo){
177 LoInfo lo = (LoInfo) nodeData;
178 switch(results.getOperation()){
179 case CREATE:
180 LoInfo createdLo = loService.createLo(lo.getLoRepositoryKey(), lo.getType(), lo);
181 if(null != results.getBusinessDTORef()) {
182 results.getAssembler().assemble(createdLo, results.getBusinessDTORef(), true);
183 }
184 break;
185 case UPDATE:
186 LoInfo updatedLo = loService.updateLo(lo.getId(), lo);
187 if(null != results.getBusinessDTORef()) {
188 results.getAssembler().assemble(updatedLo, results.getBusinessDTORef(), true);
189 }
190 break;
191 case DELETE:
192 loService.deleteLo(lo.getId());
193 break;
194 }
195 }else if(nodeData instanceof LoLoRelationInfo){
196 LoLoRelationInfo loRelation = (LoLoRelationInfo) nodeData;
197 switch(results.getOperation()){
198 case CREATE:
199 loService.createLoLoRelation(loRelation.getLoId(), loRelation.getRelatedLoId(), loRelation.getType(), loRelation);
200 break;
201 case UPDATE:
202 loService.updateLoLoRelation(loRelation.getId(), loRelation);
203 break;
204 case DELETE:
205 loService.deleteLoLoRelation(loRelation.getId());
206 break;
207 }
208 }else if(nodeData instanceof CluLoRelationInfo){
209 CluLoRelationInfo cluLoRelation = (CluLoRelationInfo) nodeData;
210 switch(results.getOperation()){
211 case CREATE:
212 luService.createCluLoRelation(cluLoRelation.getCluId(), cluLoRelation.getLoId(), cluLoRelation.getType(), cluLoRelation);
213 break;
214 case UPDATE:
215 luService.updateCluLoRelation(cluLoRelation.getLoId(), cluLoRelation);
216 break;
217 case DELETE:
218 luService.deleteCluLoRelation(cluLoRelation.getId());
219 break;
220 }
221 }else if(nodeData instanceof ResultComponentInfo){
222 ResultComponentInfo resultComponent = (ResultComponentInfo) nodeData;
223 switch(results.getOperation()){
224 case CREATE:
225 ResultComponentInfo createdResultComponent = lrcService.createResultComponent(resultComponent.getType(), resultComponent);
226
227 if(results.getBusinessDTORef()!=null&& results.getBusinessDTORef() instanceof ResultComponentInfo){
228 ResultComponentInfo resultComponentToUpdate = (ResultComponentInfo) results.getBusinessDTORef();
229 resultComponentToUpdate.setId(createdResultComponent.getId());
230 resultComponentToUpdate.setType(createdResultComponent.getType());
231 resultComponentToUpdate.setDesc(createdResultComponent.getDesc());
232 resultComponentToUpdate.setEffectiveDate(createdResultComponent.getEffectiveDate());
233 resultComponentToUpdate.setExpirationDate(createdResultComponent.getExpirationDate());
234 resultComponentToUpdate.setMetaInfo(createdResultComponent.getMetaInfo());
235 resultComponentToUpdate.setName(createdResultComponent.getName());
236 resultComponentToUpdate.setResultValues(createdResultComponent.getResultValues());
237 resultComponentToUpdate.setState(createdResultComponent.getState());
238 }
239 break;
240 case UPDATE:
241 lrcService.updateResultComponent(resultComponent.getId(), resultComponent);
242 break;
243 case DELETE:
244 lrcService.deleteResultComponent(resultComponent.getId());
245 break;
246 }
247 } else if(nodeData instanceof RefStatementRelationInfo){
248 RefStatementRelationInfo relation = (RefStatementRelationInfo) nodeData;
249 switch(results.getOperation()){
250 case CREATE:
251 RefStatementRelationInfo created = statementService.createRefStatementRelation(relation);
252 relation.setMetaInfo(created.getMetaInfo());
253 break;
254 case UPDATE:
255 RefStatementRelationInfo updated = statementService.updateRefStatementRelation(relation.getId(), relation);
256 relation.setMetaInfo(updated.getMetaInfo());
257 break;
258 case DELETE:
259 statementService.deleteRefStatementRelation(relation.getId());
260 break;
261 }
262 } else if(nodeData instanceof StatementInfo){
263 StatementInfo statement = (StatementInfo) nodeData;
264 switch(results.getOperation()){
265 case CREATE:
266 StatementInfo created = statementService.createStatement(statement.getType(), statement);
267 if(results.getAssembler() != null && results.getBusinessDTORef() != null) {
268 results.getAssembler().assemble(created, results.getBusinessDTORef(), true);
269 }
270 break;
271 case UPDATE:
272 StatementInfo updated = statementService.updateStatement(statement.getId(), statement);
273 if(results.getAssembler() != null && results.getBusinessDTORef() != null) {
274 results.getAssembler().assemble(updated, results.getBusinessDTORef(), true);
275 }
276 break;
277 case DELETE:
278 statementService.deleteStatement(statement.getId());
279 break;
280 }
281 } else if(nodeData instanceof ReqComponentInfo){
282 ReqComponentInfo reqComp = (ReqComponentInfo) nodeData;
283 switch(results.getOperation()){
284 case CREATE:
285 ReqComponentInfo created = statementService.createReqComponent(reqComp.getType(), reqComp);
286 reqComp.setMetaInfo(created.getMetaInfo());
287 break;
288 case UPDATE:
289 ReqComponentInfo updated = statementService.updateReqComponent(reqComp.getId(), reqComp);
290 reqComp.setMetaInfo(updated.getMetaInfo());
291 break;
292 case DELETE:
293 statementService.deleteReqComponent(reqComp.getId());
294 break;
295 }
296 }else if(nodeData instanceof StatementTreeViewInfo){
297 StatementTreeViewInfo treeView = (StatementTreeViewInfo) nodeData;
298 switch(results.getOperation()){
299 case CREATE:
300 StatementTreeViewInfo created = statementService.createStatementTreeView(treeView);
301 if(results.getAssembler() != null && results.getBusinessDTORef() != null) {
302 results.getAssembler().assemble(created, results.getBusinessDTORef(), true);
303 }
304 break;
305 case UPDATE:
306 StatementTreeViewInfo updated = statementService.updateStatementTreeView(treeView.getId(), treeView);
307 if(results.getAssembler() != null && results.getBusinessDTORef() != null) {
308 results.getAssembler().assemble(updated, results.getBusinessDTORef(), true);
309 }
310 break;
311 case DELETE:
312 statementService.deleteStatementTreeView(treeView.getId());
313 break;
314 }
315 }else if(nodeData instanceof CluPublicationInfo){
316 CluPublicationInfo cluPublication = (CluPublicationInfo) nodeData;
317 switch(results.getOperation()){
318 case CREATE:
319 luService.createCluPublication(cluPublication.getCluId(), cluPublication.getType(), cluPublication);
320 break;
321 case UPDATE:
322 luService.updateCluPublication(cluPublication.getId(), cluPublication);
323 break;
324 case DELETE:
325 luService.deleteCluPublication(cluPublication.getId());
326 break;
327 }
328 }else{
329 throw new UnsupportedActionException("This service invoker does not know how to handle nodeData for "+nodeData.getClass().getName());
330 }
331
332 }
333
334 public LuService getLuService() {
335 return luService;
336 }
337
338 public void setLuService(LuService luService) {
339 this.luService = luService;
340 }
341
342 public StatementService getStatementService() {
343 return statementService;
344 }
345
346 public void setStatementService(StatementService statementService) {
347 this.statementService = statementService;
348 }
349
350 public LearningObjectiveService getLoService() {
351 return loService;
352 }
353
354 public void setLoService(LearningObjectiveService loService) {
355 this.loService = loService;
356 }
357
358 public OrganizationService getOrgService() {
359 return orgService;
360 }
361
362 public void setOrgService(OrganizationService orgService) {
363 this.orgService = orgService;
364 }
365
366 public AtpService getAtpService() {
367 return atpService;
368 }
369
370 public void setAtpService(AtpService atpService) {
371 this.atpService = atpService;
372 }
373
374 public void setLrcService(LrcService lrcService) {
375 this.lrcService = lrcService;
376 }
377
378 }