View Javadoc

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