View Javadoc

1   /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  
16  package org.kuali.student.lum.lrc.service.impl;
17  
18  import java.util.List;
19  
20  import javax.jws.WebService;
21  
22  import org.kuali.student.common.dictionary.dto.ObjectStructureDefinition;
23  import org.kuali.student.common.dictionary.service.DictionaryService;
24  import org.kuali.student.common.dto.StatusInfo;
25  import org.kuali.student.common.exceptions.AlreadyExistsException;
26  import org.kuali.student.common.exceptions.DataValidationErrorException;
27  import org.kuali.student.common.exceptions.DoesNotExistException;
28  import org.kuali.student.common.exceptions.InvalidParameterException;
29  import org.kuali.student.common.exceptions.MissingParameterException;
30  import org.kuali.student.common.exceptions.OperationFailedException;
31  import org.kuali.student.common.exceptions.PermissionDeniedException;
32  import org.kuali.student.common.exceptions.VersionMismatchException;
33  import org.kuali.student.common.search.dto.SearchCriteriaTypeInfo;
34  import org.kuali.student.common.search.dto.SearchRequest;
35  import org.kuali.student.common.search.dto.SearchResult;
36  import org.kuali.student.common.search.dto.SearchResultTypeInfo;
37  import org.kuali.student.common.search.dto.SearchTypeInfo;
38  import org.kuali.student.common.search.service.SearchManager;
39  import org.kuali.student.common.validation.dto.ValidationResultInfo;
40  import org.kuali.student.common.validator.Validator;
41  import org.kuali.student.common.validator.ValidatorFactory;
42  import org.kuali.student.lum.lrc.dao.LrcDao;
43  import org.kuali.student.lum.lrc.dto.CredentialInfo;
44  import org.kuali.student.lum.lrc.dto.CredentialTypeInfo;
45  import org.kuali.student.lum.lrc.dto.CreditInfo;
46  import org.kuali.student.lum.lrc.dto.CreditTypeInfo;
47  import org.kuali.student.lum.lrc.dto.GradeInfo;
48  import org.kuali.student.lum.lrc.dto.GradeTypeInfo;
49  import org.kuali.student.lum.lrc.dto.ResultComponentInfo;
50  import org.kuali.student.lum.lrc.dto.ResultComponentTypeInfo;
51  import org.kuali.student.lum.lrc.dto.ScaleInfo;
52  import org.kuali.student.lum.lrc.entity.ResultComponent;
53  import org.kuali.student.lum.lrc.entity.ResultComponentType;
54  import org.kuali.student.lum.lrc.entity.Scale;
55  import org.kuali.student.lum.lrc.service.LrcService;
56  import org.springframework.transaction.annotation.Transactional;
57  
58  /**
59   * @author lindholm
60   *
61   */
62  @WebService(endpointInterface = "org.kuali.student.lum.lrc.service.LrcService", serviceName = "LrcService", portName = "LrcService", targetNamespace = "http://student.kuali.org/wsdl/lrc")
63  public class LrcServiceImpl implements LrcService {
64  	private LrcDao lrcDao;
65      private SearchManager searchManager;
66      private DictionaryService dictionaryServiceDelegate;
67      private ValidatorFactory validatorFactory;
68      
69  
70  	/* (non-Javadoc)
71  	 * @see org.kuali.student.lum.lrc.service.LrcService#compareGrades(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
72  	 */
73  	@Override
74  	public String compareGrades(String gradeKey, String scaleKey,
75  			String compareGradeKey, String compareScaleKey)
76  			throws InvalidParameterException, MissingParameterException,
77  			OperationFailedException {
78  		throw new UnsupportedOperationException("Method not yet implemented!");
79  	}
80  
81  	/* (non-Javadoc)
82  	 * @see org.kuali.student.lum.lrc.service.LrcService#createResultComponent(java.lang.String, org.kuali.student.lum.lrc.dto.ResultComponentInfo)
83  	 */
84  	@Override
85  	@Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class})
86  	public ResultComponentInfo createResultComponent(
87  			String resultComponentTypeKey,
88  			ResultComponentInfo resultComponentInfo)
89  			throws AlreadyExistsException, DataValidationErrorException,
90  			DoesNotExistException, InvalidParameterException,
91  			MissingParameterException, OperationFailedException,
92  			PermissionDeniedException {
93  	    checkForMissingParameter(resultComponentTypeKey, "resultComponentTypeKey");
94  	    checkForMissingParameter(resultComponentInfo, "resultComponentInfo");
95  
96  	    // Validate Result component
97          ObjectStructureDefinition objStructure = this.getObjectStructure(ResultComponentInfo.class.getName());
98          Validator defaultValidator = validatorFactory.getValidator();
99          List<ValidationResultInfo> validationResults = defaultValidator.validateObject(resultComponentInfo, objStructure);
100 
101         if (null != validationResults && validationResults.size() > 0) {
102             throw new DataValidationErrorException("Validation error!", validationResults);
103         }
104                 
105 	    ResultComponent rc = LrcServiceAssembler.toResultComponent(resultComponentTypeKey, resultComponentInfo, lrcDao);
106 	    lrcDao.create(rc);
107 	    return LrcServiceAssembler.toResultComponentInfo(rc);
108 	}
109 
110 	/* (non-Javadoc)
111 	 * @see org.kuali.student.lum.lrc.service.LrcService#deleteResultComponent(java.lang.String)
112 	 */
113 	@Override
114 	@Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class})
115 	public StatusInfo deleteResultComponent(String resultComponentId)
116 			throws DoesNotExistException, InvalidParameterException,
117 			MissingParameterException, OperationFailedException,
118 			PermissionDeniedException {
119 	    checkForMissingParameter(resultComponentId, "resultComponentId");
120 		lrcDao.delete(ResultComponent.class, resultComponentId);
121 		StatusInfo statusInfo = new StatusInfo();
122 		return statusInfo;
123 	}
124 
125 	/* (non-Javadoc)
126 	 * @see org.kuali.student.lum.lrc.service.LrcService#getCredential(java.lang.String)
127 	 */
128 	@Override
129 	public CredentialInfo getCredential(String credentialKey)
130 			throws DoesNotExistException, InvalidParameterException,
131 			MissingParameterException, OperationFailedException {
132 		throw new UnsupportedOperationException();
133 	}
134 
135 	/* (non-Javadoc)
136 	 * @see org.kuali.student.lum.lrc.service.LrcService#getCredentialKeysByCredentialType(java.lang.String)
137 	 */
138 	@Override
139 	public List<String> getCredentialKeysByCredentialType(
140 			String credentialTypeKey) throws DoesNotExistException,
141 			InvalidParameterException, MissingParameterException,
142 			OperationFailedException {
143 		throw new UnsupportedOperationException();
144 	}
145 
146 	/* (non-Javadoc)
147 	 * @see org.kuali.student.lum.lrc.service.LrcService#getCredentialType(java.lang.String)
148 	 */
149 	@Override
150 	public CredentialTypeInfo getCredentialType(String credentialTypeKey)
151 			throws DoesNotExistException, InvalidParameterException,
152 			MissingParameterException, OperationFailedException {
153 		throw new UnsupportedOperationException();
154 	}
155 
156 	/* (non-Javadoc)
157 	 * @see org.kuali.student.lum.lrc.service.LrcService#getCredentialTypes()
158 	 */
159 	@Override
160 	public List<CredentialTypeInfo> getCredentialTypes()
161 			throws OperationFailedException {
162 		throw new UnsupportedOperationException();
163 	}
164 
165 	/* (non-Javadoc)
166 	 * @see org.kuali.student.lum.lrc.service.LrcService#getCredentialsByKeyList(java.util.List)
167 	 */
168 	@Override
169 	public List<CredentialInfo> getCredentialsByKeyList(
170 			List<String> credentialKeyList) throws DoesNotExistException,
171 			InvalidParameterException, MissingParameterException,
172 			OperationFailedException {
173 		throw new UnsupportedOperationException();
174 	}
175 
176 	/* (non-Javadoc)
177 	 * @see org.kuali.student.lum.lrc.service.LrcService#getCredit(java.lang.String)
178 	 */
179 	@Override
180 	public CreditInfo getCredit(String creditKey) throws DoesNotExistException,
181 			InvalidParameterException, MissingParameterException,
182 			OperationFailedException {
183 		throw new UnsupportedOperationException();
184 	}
185 
186 	/* (non-Javadoc)
187 	 * @see org.kuali.student.lum.lrc.service.LrcService#getCreditKeysByCreditType(java.lang.String)
188 	 */
189 	@Override
190 	public List<String> getCreditKeysByCreditType(String creditTypeKey)
191 			throws DoesNotExistException, InvalidParameterException,
192 			MissingParameterException, OperationFailedException {
193 		throw new UnsupportedOperationException();
194 	}
195 
196 	/* (non-Javadoc)
197 	 * @see org.kuali.student.lum.lrc.service.LrcService#getCreditType(java.lang.String)
198 	 */
199 	@Override
200 	public CreditTypeInfo getCreditType(String creditTypeKey)
201 			throws DoesNotExistException, InvalidParameterException,
202 			MissingParameterException, OperationFailedException {
203 		throw new UnsupportedOperationException();
204 	}
205 
206 	/* (non-Javadoc)
207 	 * @see org.kuali.student.lum.lrc.service.LrcService#getCreditTypes()
208 	 */
209 	@Override
210 	public List<CreditTypeInfo> getCreditTypes()
211 			throws OperationFailedException {
212 		throw new UnsupportedOperationException();
213 	}
214 
215 	/* (non-Javadoc)
216 	 * @see org.kuali.student.lum.lrc.service.LrcService#getCreditsByKeyList(java.util.List)
217 	 */
218 	@Override
219 	public List<CreditInfo> getCreditsByKeyList(List<String> creditKeyList)
220 			throws DoesNotExistException, InvalidParameterException,
221 			MissingParameterException, OperationFailedException {
222 		throw new UnsupportedOperationException();
223 	}
224 
225     /* (non-Javadoc)
226      * @see org.kuali.student.lum.lrc.service.LrcService#getGrade(java.lang.String)
227      */
228     @Override
229     public GradeInfo getGrade(String gradeKey) throws DoesNotExistException,
230             InvalidParameterException, MissingParameterException,
231             OperationFailedException {
232 		throw new UnsupportedOperationException();
233     }
234 
235     /* (non-Javadoc)
236      * @see org.kuali.student.lum.lrc.service.LrcService#getGradeKeysByGradeType(java.lang.String)
237      */
238     @Override
239     public List<String> getGradeKeysByGradeType(String gradeTypeKey)
240             throws DoesNotExistException, InvalidParameterException,
241             MissingParameterException, OperationFailedException {
242 		throw new UnsupportedOperationException();
243     }
244 
245     /* (non-Javadoc)
246      * @see org.kuali.student.lum.lrc.service.LrcService#getGradeType(java.lang.String)
247      */
248     @Override
249     public GradeTypeInfo getGradeType(String gradeTypeKey)
250             throws DoesNotExistException, InvalidParameterException,
251             MissingParameterException, OperationFailedException {
252 		throw new UnsupportedOperationException();
253     }
254 
255     /* (non-Javadoc)
256      * @see org.kuali.student.lum.lrc.service.LrcService#getGradeTypes()
257      */
258     @Override
259     public List<GradeTypeInfo> getGradeTypes() throws OperationFailedException {
260 		throw new UnsupportedOperationException();
261     }
262 
263     /* (non-Javadoc)
264      * @see org.kuali.student.lum.lrc.service.LrcService#getGradesByKeyList(java.util.List)
265      */
266     @Override
267     public List<GradeInfo> getGradesByKeyList(List<String> gradeKeyList)
268             throws DoesNotExistException, InvalidParameterException,
269             MissingParameterException, OperationFailedException {
270 		throw new UnsupportedOperationException();
271     }
272 	/* (non-Javadoc)
273 	 * @see org.kuali.student.lum.lrc.service.LrcService#getGradesByScale(java.lang.String)
274 	 */
275 	@Override
276 	public List<GradeInfo> getGradesByScale(String scale)
277 			throws DoesNotExistException, InvalidParameterException,
278 			MissingParameterException, OperationFailedException {
279 		throw new UnsupportedOperationException();
280 	}
281 
282 	/* (non-Javadoc)
283 	 * @see org.kuali.student.lum.lrc.service.LrcService#getResultComponent(java.lang.String)
284 	 */
285 	@Override
286     @Transactional(readOnly=true)
287 	public ResultComponentInfo getResultComponent(String resultComponentId)
288 			throws DoesNotExistException, InvalidParameterException,
289 			MissingParameterException, OperationFailedException {
290 	    checkForMissingParameter(resultComponentId, "resultComponentId");
291 	    ResultComponent resultComponent = lrcDao.fetch(ResultComponent.class, resultComponentId);
292 
293 	    return LrcServiceAssembler.toResultComponentInfo(resultComponent);
294 	}
295 
296 	/* (non-Javadoc)
297 	 * @see org.kuali.student.lum.lrc.service.LrcService#getResultComponentIdsByResult(java.lang.String, java.lang.String)
298 	 */
299 	@Override
300     @Transactional(readOnly=true)
301 	public List<String> getResultComponentIdsByResult(String resultValueId,
302 			String resultComponentTypeKey) throws DoesNotExistException,
303 			InvalidParameterException, MissingParameterException,
304 			OperationFailedException {
305 	    checkForMissingParameter(resultValueId, "resultValueId");
306 	    checkForMissingParameter(resultComponentTypeKey, "resultComponentTypeKey");
307 	    List<String> ids = lrcDao.getResultComponentIdsByResult(resultValueId, resultComponentTypeKey);
308 	    return ids;
309 	}
310 
311 	/* (non-Javadoc)
312 	 * @see org.kuali.student.lum.lrc.service.LrcService#getResultComponentIdsByResultComponentType(java.lang.String)
313 	 */
314 	@Override
315     @Transactional(readOnly=true)
316 	public List<String> getResultComponentIdsByResultComponentType(
317 			String resultComponentTypeKey) throws DoesNotExistException,
318 			InvalidParameterException, MissingParameterException,
319 			OperationFailedException {
320 	    checkForMissingParameter(resultComponentTypeKey, "resultComponentTypeKey");
321         List<String> ids = lrcDao.getResultComponentIdsByResultComponentType(resultComponentTypeKey);
322         return ids;
323 	}
324 
325 	/* (non-Javadoc)
326 	 * @see org.kuali.student.lum.lrc.service.LrcService#getResultComponentType(java.lang.String)
327 	 */
328 	@Override
329     @Transactional(readOnly=true)
330 	public ResultComponentTypeInfo getResultComponentType(
331 			String resultComponentTypeKey) throws DoesNotExistException,
332 			InvalidParameterException, MissingParameterException,
333 			OperationFailedException {
334 		checkForMissingParameter(resultComponentTypeKey, "resultComponentTypeKey");
335 		ResultComponentType entity = lrcDao.getResultComponentType(resultComponentTypeKey);
336 		return LrcServiceAssembler.toResultComponentTypeInfo(entity);
337 	}
338 
339 	/* (non-Javadoc)
340 	 * @see org.kuali.student.lum.lrc.service.LrcService#getResultComponentTypes()
341 	 */
342 	@Override
343     @Transactional(readOnly=true)
344 	public List<ResultComponentTypeInfo> getResultComponentTypes()
345 			throws OperationFailedException {
346 		List<ResultComponentType> rct = lrcDao.find(ResultComponentType.class);
347 		return LrcServiceAssembler.toResultComponentTypeInfos(rct);
348 	}
349 
350 	/* (non-Javadoc)
351 	 * @see org.kuali.student.lum.lrc.service.LrcService#getScale(java.lang.String)
352 	 */
353 	@Override
354     @Transactional(readOnly=true)
355 	public ScaleInfo getScale(String scaleKey) throws DoesNotExistException,
356 			InvalidParameterException, MissingParameterException,
357 			OperationFailedException {
358 		checkForMissingParameter(scaleKey, "scaleKey");
359 		Scale scale = lrcDao.fetch(Scale.class, scaleKey);
360 		return LrcServiceAssembler.toScaleInfo(scale);
361 	}
362 
363 	/* (non-Javadoc)
364 	 * @see org.kuali.student.lum.lrc.service.LrcService#translateGrade(java.lang.String, java.lang.String, java.lang.String)
365 	 */
366 	@Override
367 	public List<GradeInfo> translateGrade(String gradeKey, String scaleKey,
368 			String translateScaleKey) throws InvalidParameterException,
369 			MissingParameterException, OperationFailedException {
370 		throw new UnsupportedOperationException("Method not yet implemented!");
371 	}
372 
373 	/* (non-Javadoc)
374 	 * @see org.kuali.student.lum.lrc.service.LrcService#updateResultComponent(java.lang.String, org.kuali.student.lum.lrc.dto.ResultComponentInfo)
375 	 */
376 	@Override
377 	@Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class})
378 	public ResultComponentInfo updateResultComponent(String resultComponentId,
379 			ResultComponentInfo resultComponentInfo)
380 			throws DataValidationErrorException, DoesNotExistException,
381 			InvalidParameterException, MissingParameterException,
382 			OperationFailedException, PermissionDeniedException,
383 			VersionMismatchException {
384 	    checkForMissingParameter(resultComponentId, "resultComponentId");
385         checkForMissingParameter(resultComponentInfo, "resultComponentInfo");
386         
387         // Validate Result component
388         ObjectStructureDefinition objStructure = this.getObjectStructure(ResultComponentInfo.class.getName());
389         Validator defaultValidator = validatorFactory.getValidator();
390         List<ValidationResultInfo> validationResults = defaultValidator.validateObject(resultComponentInfo, objStructure);
391 
392         if (null != validationResults && validationResults.size() > 0) {
393             throw new DataValidationErrorException("Validation error!", validationResults);
394         }
395         
396         ResultComponent entity = lrcDao.fetch(ResultComponent.class, resultComponentId);
397         
398 		if (!String.valueOf(entity.getVersionNumber()).equals(resultComponentInfo.getMetaInfo().getVersionInd())){
399 			throw new VersionMismatchException("ResultComponent to be updated is not the current version");
400 		}
401         
402         LrcServiceAssembler.toResultComponent(entity, resultComponentInfo, lrcDao);
403         lrcDao.update(entity);
404         return LrcServiceAssembler.toResultComponentInfo(entity);
405     }
406 
407 	/**
408 	 * @return the lrcDao
409 	 */
410 	public LrcDao getLrcDao() {
411 		return lrcDao;
412 	}
413 
414 	/**
415 	 * @param lrcDao the lrcDao to set
416 	 */
417 	public void setLrcDao(LrcDao lrcDao) {
418 		this.lrcDao = lrcDao;
419 	}
420 
421     /**
422      * Check for missing parameter and throw localized exception if missing
423      *
424      * @param param
425      * @param parameter name
426      * @throws MissingParameterException
427      */
428     private void checkForMissingParameter(Object param, String paramName)
429             throws MissingParameterException {
430         if (param == null) {
431             throw new MissingParameterException(paramName + " can not be null");
432         }
433     }
434 
435 	@Override
436 	public SearchCriteriaTypeInfo getSearchCriteriaType(
437 			String searchCriteriaTypeKey) throws DoesNotExistException,
438 			InvalidParameterException, MissingParameterException,
439 			OperationFailedException {
440 
441 		return searchManager.getSearchCriteriaType(searchCriteriaTypeKey);
442 	}
443 
444 	@Override
445 	public List<SearchCriteriaTypeInfo> getSearchCriteriaTypes()
446 			throws OperationFailedException {
447 		return searchManager.getSearchCriteriaTypes();
448 	}
449 
450 	@Override
451 	public SearchResultTypeInfo getSearchResultType(String searchResultTypeKey)
452 			throws DoesNotExistException, InvalidParameterException,
453 			MissingParameterException, OperationFailedException {
454 		checkForMissingParameter(searchResultTypeKey, "searchResultTypeKey");
455 		return searchManager.getSearchResultType(searchResultTypeKey);
456 	}
457 
458 	@Override
459 	public List<SearchResultTypeInfo> getSearchResultTypes()
460 			throws OperationFailedException {
461 		return searchManager.getSearchResultTypes();
462 	}
463 
464 	@Override
465 	public SearchTypeInfo getSearchType(String searchTypeKey)
466 			throws DoesNotExistException, InvalidParameterException,
467 			MissingParameterException, OperationFailedException {
468 		checkForMissingParameter(searchTypeKey, "searchTypeKey");
469 		return searchManager.getSearchType(searchTypeKey);
470 	}
471 
472 	@Override
473 	public List<SearchTypeInfo> getSearchTypes()
474 			throws OperationFailedException {
475 		return searchManager.getSearchTypes();
476 	}
477 
478 	@Override
479 	public List<SearchTypeInfo> getSearchTypesByCriteria(
480 			String searchCriteriaTypeKey) throws DoesNotExistException,
481 			InvalidParameterException, MissingParameterException,
482 			OperationFailedException {
483 		checkForMissingParameter(searchCriteriaTypeKey, "searchCriteriaTypeKey");
484 		return searchManager.getSearchTypesByCriteria(searchCriteriaTypeKey);
485 	}
486 
487 	@Override
488 	public List<SearchTypeInfo> getSearchTypesByResult(
489 			String searchResultTypeKey) throws DoesNotExistException,
490 			InvalidParameterException, MissingParameterException,
491 			OperationFailedException {
492 		checkForMissingParameter(searchResultTypeKey, "searchResultTypeKey");
493 		return searchManager.getSearchTypesByResult(searchResultTypeKey);
494 	}
495 
496 	public SearchManager getSearchManager() {
497 		return searchManager;
498 	}
499 
500 	public void setSearchManager(SearchManager searchManager) {
501 		this.searchManager = searchManager;
502 	}
503 
504 	@Override
505 	public SearchResult search(SearchRequest searchRequest) throws MissingParameterException {
506         checkForMissingParameter(searchRequest, "searchRequest");
507         return searchManager.search(searchRequest, lrcDao);
508 	}
509 
510     @Override
511     public ObjectStructureDefinition getObjectStructure(String objectTypeKey) {
512         return dictionaryServiceDelegate.getObjectStructure(objectTypeKey);
513     }
514     @Override
515     public List<String> getObjectTypes() {
516         return dictionaryServiceDelegate.getObjectTypes();
517     }
518 
519     /**
520      * @return the validatorFactory
521      */
522     public ValidatorFactory getValidatorFactory() {
523         return validatorFactory;
524     }
525 
526     /**
527      * @param validatorFactory the validatorFactory to set
528      */
529     public void setValidatorFactory(ValidatorFactory validatorFactory) {
530         this.validatorFactory = validatorFactory;
531     }
532 
533     public DictionaryService getDictionaryServiceDelegate() {
534         return dictionaryServiceDelegate;
535     }
536 
537     public void setDictionaryServiceDelegate(DictionaryService dictionaryServiceDelegate) {
538         this.dictionaryServiceDelegate = dictionaryServiceDelegate;
539     }
540 }