Clover Coverage Report - Kuali Student 1.1.0-M10-SNAPSHOT (Aggregated)
Coverage timestamp: Fri Dec 17 2010 05:04:51 EST
../../../../../../../img/srcFileCovDistChart8.png 36% of files have more coverage
1,215   3,267   350   7.99
292   2,577   0.29   152
152     2.3  
1    
 
  LuServiceImpl       Line # 150 1,215 0% 350 329 80.2% 0.8016878
 
  (163)
 
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.lu.service.impl;
17   
18    import java.util.ArrayList;
19    import java.util.Date;
20    import java.util.HashMap;
21    import java.util.HashSet;
22    import java.util.Iterator;
23    import java.util.List;
24    import java.util.Map;
25    import java.util.Map.Entry;
26    import java.util.Set;
27   
28    import javax.jws.WebService;
29    import javax.persistence.NoResultException;
30   
31    import org.apache.log4j.Logger;
32    import org.kuali.student.common.validator.Validator;
33    import org.kuali.student.common.validator.ValidatorFactory;
34    import org.kuali.student.core.dictionary.dto.ObjectStructureDefinition;
35    import org.kuali.student.core.dictionary.service.DictionaryService;
36    import org.kuali.student.core.dto.CurrencyAmountInfo;
37    import org.kuali.student.core.dto.StatusInfo;
38    import org.kuali.student.core.entity.Amount;
39    import org.kuali.student.core.entity.TimeAmount;
40    import org.kuali.student.core.entity.Version;
41    import org.kuali.student.core.entity.VersionEntity;
42    import org.kuali.student.core.exceptions.AlreadyExistsException;
43    import org.kuali.student.core.exceptions.CircularRelationshipException;
44    import org.kuali.student.core.exceptions.DataValidationErrorException;
45    import org.kuali.student.core.exceptions.DependentObjectsExistException;
46    import org.kuali.student.core.exceptions.DoesNotExistException;
47    import org.kuali.student.core.exceptions.IllegalVersionSequencingException;
48    import org.kuali.student.core.exceptions.InvalidParameterException;
49    import org.kuali.student.core.exceptions.MissingParameterException;
50    import org.kuali.student.core.exceptions.OperationFailedException;
51    import org.kuali.student.core.exceptions.PermissionDeniedException;
52    import org.kuali.student.core.exceptions.UnsupportedActionException;
53    import org.kuali.student.core.exceptions.VersionMismatchException;
54    import org.kuali.student.core.search.dto.SearchCriteriaTypeInfo;
55    import org.kuali.student.core.search.dto.SearchRequest;
56    import org.kuali.student.core.search.dto.SearchResult;
57    import org.kuali.student.core.search.dto.SearchResultCell;
58    import org.kuali.student.core.search.dto.SearchResultRow;
59    import org.kuali.student.core.search.dto.SearchResultTypeInfo;
60    import org.kuali.student.core.search.dto.SearchTypeInfo;
61    import org.kuali.student.core.search.service.SearchManager;
62    import org.kuali.student.core.validation.dto.ValidationResultInfo;
63    import org.kuali.student.core.versionmanagement.dto.VersionDisplayInfo;
64    import org.kuali.student.lum.lu.LUConstants;
65    import org.kuali.student.lum.lu.dao.LuDao;
66    import org.kuali.student.lum.lu.dto.AccreditationInfo;
67    import org.kuali.student.lum.lu.dto.AdminOrgInfo;
68    import org.kuali.student.lum.lu.dto.AffiliatedOrgInfo;
69    import org.kuali.student.lum.lu.dto.CluCluRelationInfo;
70    import org.kuali.student.lum.lu.dto.CluFeeRecordInfo;
71    import org.kuali.student.lum.lu.dto.CluIdentifierInfo;
72    import org.kuali.student.lum.lu.dto.CluInfo;
73    import org.kuali.student.lum.lu.dto.CluInstructorInfo;
74    import org.kuali.student.lum.lu.dto.CluLoRelationInfo;
75    import org.kuali.student.lum.lu.dto.CluLoRelationTypeInfo;
76    import org.kuali.student.lum.lu.dto.CluPublicationInfo;
77    import org.kuali.student.lum.lu.dto.CluResultInfo;
78    import org.kuali.student.lum.lu.dto.CluResultTypeInfo;
79    import org.kuali.student.lum.lu.dto.CluSetInfo;
80    import org.kuali.student.lum.lu.dto.CluSetTreeViewInfo;
81    import org.kuali.student.lum.lu.dto.CluSetTypeInfo;
82    import org.kuali.student.lum.lu.dto.DeliveryMethodTypeInfo;
83    import org.kuali.student.lum.lu.dto.FieldInfo;
84    import org.kuali.student.lum.lu.dto.InstructionalFormatTypeInfo;
85    import org.kuali.student.lum.lu.dto.LuCodeInfo;
86    import org.kuali.student.lum.lu.dto.LuCodeTypeInfo;
87    import org.kuali.student.lum.lu.dto.LuLuRelationTypeInfo;
88    import org.kuali.student.lum.lu.dto.LuPublicationTypeInfo;
89    import org.kuali.student.lum.lu.dto.LuTypeInfo;
90    import org.kuali.student.lum.lu.dto.LuiInfo;
91    import org.kuali.student.lum.lu.dto.LuiLuiRelationInfo;
92    import org.kuali.student.lum.lu.dto.MembershipQueryInfo;
93    import org.kuali.student.lum.lu.dto.ResultOptionInfo;
94    import org.kuali.student.lum.lu.dto.ResultUsageTypeInfo;
95    import org.kuali.student.lum.lu.entity.Clu;
96    import org.kuali.student.lum.lu.entity.CluAccounting;
97    import org.kuali.student.lum.lu.entity.CluAccountingAttribute;
98    import org.kuali.student.lum.lu.entity.CluAccreditation;
99    import org.kuali.student.lum.lu.entity.CluAccreditationAttribute;
100    import org.kuali.student.lum.lu.entity.CluAdminOrg;
101    import org.kuali.student.lum.lu.entity.CluAdminOrgAttribute;
102    import org.kuali.student.lum.lu.entity.CluAtpTypeKey;
103    import org.kuali.student.lum.lu.entity.CluAttribute;
104    import org.kuali.student.lum.lu.entity.CluCampusLocation;
105    import org.kuali.student.lum.lu.entity.CluCluRelation;
106    import org.kuali.student.lum.lu.entity.CluCluRelationAttribute;
107    import org.kuali.student.lum.lu.entity.CluFee;
108    import org.kuali.student.lum.lu.entity.CluIdentifier;
109    import org.kuali.student.lum.lu.entity.CluInstructor;
110    import org.kuali.student.lum.lu.entity.CluInstructorAttribute;
111    import org.kuali.student.lum.lu.entity.CluLoRelation;
112    import org.kuali.student.lum.lu.entity.CluLoRelationAttribute;
113    import org.kuali.student.lum.lu.entity.CluLoRelationType;
114    import org.kuali.student.lum.lu.entity.CluPublication;
115    import org.kuali.student.lum.lu.entity.CluPublicationAttribute;
116    import org.kuali.student.lum.lu.entity.CluPublicationType;
117    import org.kuali.student.lum.lu.entity.CluPublicationVariant;
118    import org.kuali.student.lum.lu.entity.CluResult;
119    import org.kuali.student.lum.lu.entity.CluResultType;
120    import org.kuali.student.lum.lu.entity.CluSet;
121    import org.kuali.student.lum.lu.entity.CluSetAttribute;
122    import org.kuali.student.lum.lu.entity.CluSetJoinVersionIndClu;
123    import org.kuali.student.lum.lu.entity.CluSetType;
124    import org.kuali.student.lum.lu.entity.DeliveryMethodType;
125    import org.kuali.student.lum.lu.entity.InstructionalFormatType;
126    import org.kuali.student.lum.lu.entity.LuCode;
127    import org.kuali.student.lum.lu.entity.LuCodeAttribute;
128    import org.kuali.student.lum.lu.entity.LuCodeType;
129    import org.kuali.student.lum.lu.entity.LuLuRelationType;
130    import org.kuali.student.lum.lu.entity.LuPublicationType;
131    import org.kuali.student.lum.lu.entity.LuRichText;
132    import org.kuali.student.lum.lu.entity.LuType;
133    import org.kuali.student.lum.lu.entity.Lui;
134    import org.kuali.student.lum.lu.entity.LuiAttribute;
135    import org.kuali.student.lum.lu.entity.LuiLuiRelation;
136    import org.kuali.student.lum.lu.entity.LuiLuiRelationAttribute;
137    import org.kuali.student.lum.lu.entity.MembershipQuery;
138    import org.kuali.student.lum.lu.entity.ResultOption;
139    import org.kuali.student.lum.lu.entity.ResultUsageType;
140    import org.kuali.student.lum.lu.service.LuService;
141    import org.kuali.student.lum.lu.service.LuServiceConstants;
142    import org.springframework.beans.BeanUtils;
143    import org.springframework.transaction.annotation.Transactional;
144   
145    import edu.emory.mathcs.backport.java.util.Collections;
146   
147   
148    @WebService(endpointInterface = "org.kuali.student.lum.lu.service.LuService", serviceName = "LuService", portName = "LuService", targetNamespace = "http://student.kuali.org/wsdl/lu")
149    @Transactional(noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class})
 
150    public class LuServiceImpl implements LuService {
151   
152    final Logger logger = Logger.getLogger(LuServiceImpl.class);
153   
154    private LuDao luDao;
155    private SearchManager searchManager;
156    private DictionaryService dictionaryServiceDelegate;
157    private ValidatorFactory validatorFactory;
158   
 
159  5 toggle public void setSearchManager(SearchManager searchManager) {
160  5 this.searchManager = searchManager;
161    }
162   
 
163  3 toggle public void setDictionaryServiceDelegate(
164    DictionaryService dictionaryServiceDelegate) {
165  3 this.dictionaryServiceDelegate = dictionaryServiceDelegate;
166    }
167   
 
168  0 toggle public DictionaryService getDictionaryServiceDelegate() {
169  0 return dictionaryServiceDelegate;
170    }
171   
172   
173    /**************************************************************************
174    * SETUP OPERATION *
175    **************************************************************************/
176   
 
177  0 toggle @Override
178    public List<DeliveryMethodTypeInfo> getDeliveryMethodTypes()
179    throws OperationFailedException {
180  0 return LuServiceAssembler.toDeliveryMethodTypeInfos(luDao
181    .find(DeliveryMethodType.class));
182    }
183   
 
184  0 toggle @Override
185    public DeliveryMethodTypeInfo getDeliveryMethodType(
186    String deliveryMethodTypeKey) throws DoesNotExistException,
187    InvalidParameterException, MissingParameterException,
188    OperationFailedException {
189   
190  0 checkForMissingParameter(deliveryMethodTypeKey, "deliveryMethodTypeKey");
191   
192  0 return LuServiceAssembler.toDeliveryMethodTypeInfo(luDao.fetch(
193    DeliveryMethodType.class, deliveryMethodTypeKey));
194    }
195   
 
196  0 toggle @Override
197    public List<InstructionalFormatTypeInfo> getInstructionalFormatTypes()
198    throws OperationFailedException {
199  0 return LuServiceAssembler.toInstructionalFormatTypeInfos(luDao
200    .find(InstructionalFormatType.class));
201    }
202   
 
203  0 toggle @Override
204    public InstructionalFormatTypeInfo getInstructionalFormatType(
205    String instructionalFormatTypeKey) throws DoesNotExistException,
206    InvalidParameterException, MissingParameterException,
207    OperationFailedException {
208  0 checkForMissingParameter(instructionalFormatTypeKey,
209    "instructionalFormatTypeKey");
210   
211  0 return LuServiceAssembler.toInstructionalFormatTypeInfo(luDao.fetch(
212    InstructionalFormatType.class, instructionalFormatTypeKey));
213    }
214   
 
215  0 toggle @Override
216    public List<LuTypeInfo> getLuTypes() throws OperationFailedException {
217  0 return LuServiceAssembler.toLuTypeInfos(luDao.find(LuType.class));
218    }
219   
 
220  0 toggle @Override
221    public LuTypeInfo getLuType(String luTypeKey) throws DoesNotExistException,
222    InvalidParameterException, MissingParameterException,
223    OperationFailedException {
224  0 checkForMissingParameter(luTypeKey, "luTypeKey");
225   
226  0 return LuServiceAssembler.toLuTypeInfo(luDao.fetch(LuType.class,
227    luTypeKey));
228    }
229   
 
230  0 toggle @Override
231    public LuCodeTypeInfo getLuCodeType(String luCodeTypeKey)
232    throws DoesNotExistException, InvalidParameterException,
233    MissingParameterException, OperationFailedException {
234  0 checkForMissingParameter(luCodeTypeKey, "luCodeTypeKey");
235  0 return LuServiceAssembler.toLuCodeTypeInfo(luDao.fetch(
236    LuCodeType.class, luCodeTypeKey));
237    }
238   
 
239  0 toggle @Override
240    public List<LuCodeTypeInfo> getLuCodeTypes()
241    throws OperationFailedException {
242  0 return LuServiceAssembler.toLuCodeTypeInfos(luDao
243    .find(LuCodeType.class));
244    }
245   
 
246  1 toggle @Override
247    public List<LuLuRelationTypeInfo> getLuLuRelationTypes()
248    throws OperationFailedException {
249  1 return LuServiceAssembler.toLuLuRelationTypeInfos(luDao
250    .find(LuLuRelationType.class));
251    }
252   
 
253  4 toggle @Override
254    public LuLuRelationTypeInfo getLuLuRelationType(String luLuRelationTypeKey)
255    throws OperationFailedException, MissingParameterException,
256    DoesNotExistException {
257  4 checkForMissingParameter(luLuRelationTypeKey, "luLuRelationTypeKey");
258   
259  3 LuLuRelationType luLuRelationType = luDao.fetch(LuLuRelationType.class,
260    luLuRelationTypeKey);
261  2 return LuServiceAssembler.toLuLuRelationTypeInfo(luLuRelationType);
262    }
263   
 
264  0 toggle @Override
265    public List<String> getAllowedLuLuRelationTypesForLuType(String luTypeKey,
266    String relatedLuTypeKey) throws DoesNotExistException,
267    InvalidParameterException, MissingParameterException,
268    OperationFailedException {
269  0 checkForMissingParameter(luTypeKey, "luTypeKey");
270  0 checkForMissingParameter(relatedLuTypeKey, "relatedLuTypeKey");
271   
272  0 return luDao.getAllowedLuLuRelationTypesForLuType(luTypeKey,
273    relatedLuTypeKey);
274    }
275   
 
276  0 toggle @Override
277    public List<LuPublicationTypeInfo> getLuPublicationTypes()
278    throws OperationFailedException {
279  0 return LuServiceAssembler.toLuPublicationTypeInfos(luDao
280    .find(LuPublicationType.class));
281    }
282   
 
283  0 toggle @Override
284    public LuPublicationTypeInfo getLuPublicationType(
285    String luPublicationTypeKey) throws DoesNotExistException,
286    InvalidParameterException, MissingParameterException,
287    OperationFailedException {
288  0 checkForMissingParameter(luPublicationTypeKey, "luPublicationTypeKey");
289   
290  0 return LuServiceAssembler.toLuPublicationTypeInfo(luDao.fetch(
291    LuPublicationType.class, luPublicationTypeKey));
292    }
293   
 
294  0 toggle @Override
295    public List<String> getLuPublicationTypesForLuType(String luTypeKey)
296    throws DoesNotExistException, InvalidParameterException,
297    MissingParameterException, OperationFailedException {
298  0 throw new UnsupportedOperationException("getLuPublicationTypesForLuType");
299    }
300   
 
301  0 toggle @Override
302    public List<CluResultTypeInfo> getCluResultTypes()
303    throws OperationFailedException {
304  0 return LuServiceAssembler.toCluResultTypeInfos(luDao
305    .find(CluResultType.class));
306    }
307   
 
308  0 toggle @Override
309    public CluResultTypeInfo getCluResultType(String cluResultTypeKey)
310    throws DoesNotExistException, InvalidParameterException,
311    MissingParameterException, OperationFailedException {
312  0 return LuServiceAssembler.toCluResultTypeInfo(luDao.fetch(
313    CluResultType.class, cluResultTypeKey));
314    }
315   
 
316  0 toggle @Override
317    public List<CluResultTypeInfo> getCluResultTypesForLuType(String luTypeKey)
318    throws DoesNotExistException, InvalidParameterException,
319    MissingParameterException, OperationFailedException {
320  0 checkForMissingParameter(luTypeKey, "luTypeKey");
321  0 return LuServiceAssembler.toCluResultTypeInfos((luDao
322    .getAllowedCluResultTypesForLuType(luTypeKey)));
323    }
324   
 
325  1 toggle @Override
326    public List<ResultUsageTypeInfo> getResultUsageTypes()
327    throws OperationFailedException {
328  1 return LuServiceAssembler.toResultUsageTypeInfos(luDao
329    .find(ResultUsageType.class));
330    }
331   
 
332  1 toggle @Override
333    public ResultUsageTypeInfo getResultUsageType(String resultUsageTypeKey)
334    throws DoesNotExistException, InvalidParameterException,
335    MissingParameterException, OperationFailedException {
336  1 checkForMissingParameter(resultUsageTypeKey, "resultUsageTypeKey");
337  1 return LuServiceAssembler.toResultUsageTypeInfo(luDao.fetch(
338    ResultUsageType.class, resultUsageTypeKey));
339    }
340   
 
341  0 toggle @Override
342    public List<String> getAllowedResultUsageTypesForLuType(String luTypeKey)
343    throws DoesNotExistException, InvalidParameterException,
344    MissingParameterException, OperationFailedException {
345  0 checkForMissingParameter(luTypeKey, "luTypeKey");
346   
347  0 return luDao.getAllowedResultUsageTypesForLuType(luTypeKey);
348    }
349   
 
350  0 toggle @Override
351    public List<String> getAllowedResultComponentTypesForResultUsageType(
352    String resultUsageTypeKey) throws DoesNotExistException,
353    InvalidParameterException, MissingParameterException,
354    OperationFailedException {
355   
356  0 checkForMissingParameter(resultUsageTypeKey, "resultUsageTypeKey");
357   
358  0 return luDao
359    .getAllowedResultComponentTypesForResultUsageType(resultUsageTypeKey);
360    }
361   
 
362  0 toggle @Override
363    public CluLoRelationTypeInfo getCluLoRelationType(
364    String cluLoRelationTypeKey) throws DoesNotExistException,
365    InvalidParameterException, MissingParameterException,
366    OperationFailedException {
367  0 checkForMissingParameter(cluLoRelationTypeKey, "cluLoRelationTypeKey");
368   
369  0 CluLoRelationType cluLoRelationType = luDao.fetch(
370    CluLoRelationType.class, cluLoRelationTypeKey);
371  0 return LuServiceAssembler.toCluLoRelationTypeInfo(cluLoRelationType);
372    }
373   
 
374  0 toggle @Override
375    public List<CluLoRelationTypeInfo> getCluLoRelationTypes()
376    throws OperationFailedException {
377  0 return LuServiceAssembler.toCluLoRelationTypeInfos(luDao
378    .find(CluLoRelationType.class));
379    }
380   
 
381  0 toggle @Override
382    public List<String> getAllowedCluLoRelationTypesForLuType(String luTypeKey)
383    throws DoesNotExistException, InvalidParameterException,
384    MissingParameterException, OperationFailedException {
385   
386  0 checkForMissingParameter(luTypeKey, luTypeKey);
387   
388  0 return luDao.getAllowedCluLoRelationTypesForLuType(luTypeKey);
389    }
390   
 
391  0 toggle @Override
392    public List<CluSetTypeInfo> getCluSetTypes()
393    throws OperationFailedException {
394  0 return LuServiceAssembler.toCluSetTypeInfos(luDao
395    .find(CluSetType.class));
396    }
397   
 
398  0 toggle @Override
399    public CluSetTypeInfo getCluSetType(String cluSetTypeKey)
400    throws DoesNotExistException, InvalidParameterException,
401    MissingParameterException, OperationFailedException {
402  0 checkForMissingParameter(cluSetTypeKey, "cluSetTypeKey");
403  0 return LuServiceAssembler.toCluSetTypeInfo(luDao.fetch(
404    CluSetType.class, cluSetTypeKey));
405    }
406   
407    /**************************************************************************
408    * READ OPERATION *
409    **************************************************************************/
410   
411    // **** Core **********
 
412  180 toggle @Override
413    public CluInfo getClu(String cluId) throws DoesNotExistException,
414    InvalidParameterException, MissingParameterException,
415    OperationFailedException {
416   
417  180 checkForMissingParameter(cluId, "cluId");
418   
419  179 Clu clu = luDao.fetch(Clu.class, cluId);
420  174 return LuServiceAssembler.toCluInfo(clu);
421    }
422   
 
423  3 toggle @Override
424    public List<CluInfo> getClusByIdList(List<String> cluIdList)
425    throws DoesNotExistException, InvalidParameterException,
426    MissingParameterException, OperationFailedException {
427  3 checkForMissingParameter(cluIdList, "cluIdList");
428  2 checkForEmptyList(cluIdList, "cluIdList");
429  2 List<Clu> clus = luDao.getClusByIdList(cluIdList);
430  2 return LuServiceAssembler.toCluInfos(clus);
431    }
432   
 
433  5 toggle @Override
434    public List<CluInfo> getClusByLuType(String luTypeKey, String luState)
435    throws DoesNotExistException, InvalidParameterException,
436    MissingParameterException, OperationFailedException {
437  5 checkForMissingParameter(luTypeKey, "luTypeKey");
438  4 checkForMissingParameter(luState, "lustate");
439  3 List<Clu> clus = luDao.getClusByLuType(luTypeKey, luState);
440  3 return LuServiceAssembler.toCluInfos(clus);
441    }
442   
 
443  5 toggle @Override
444    public List<String> getCluIdsByLuType(String luTypeKey, String luState)
445    throws DoesNotExistException, InvalidParameterException,
446    MissingParameterException, OperationFailedException {
447  5 checkForMissingParameter(luTypeKey, "luTypeKey");
448  4 checkForMissingParameter(luState, "luState");
449  3 List<Clu> clus = luDao.getClusByLuType(luTypeKey, luState);
450  3 List<String> ids = new ArrayList<String>(clus.size());
451  3 for (Clu clu : clus) {
452  1 ids.add(clu.getId());
453    }
454  3 return ids;
455    }
456   
457    // ****** Relations
458   
 
459  0 toggle @Override
460    public List<String> getAllowedLuLuRelationTypesByCluId(String cluId,
461    String relatedCluId) throws DoesNotExistException,
462    InvalidParameterException, MissingParameterException,
463    OperationFailedException {
464  0 checkForMissingParameter(cluId, "cluId");
465  0 checkForMissingParameter(relatedCluId, "relatedCluId");
466   
467  0 return luDao.getAllowedLuLuRelationTypesByCluId(cluId, relatedCluId);
468    }
469   
 
470  5 toggle @Override
471    public List<CluInfo> getClusByRelation(String relatedCluId,
472    String luLuRelationTypeKey) throws DoesNotExistException,
473    InvalidParameterException, MissingParameterException,
474    OperationFailedException {
475  5 checkForMissingParameter(relatedCluId, "relatedCluId");
476  4 checkForMissingParameter(luLuRelationTypeKey, "luLuRelationTypeKey");
477   
478  3 List<Clu> clus = luDao.getClusByRelation(relatedCluId,
479    luLuRelationTypeKey);
480  3 List<CluInfo> result = LuServiceAssembler.toCluInfos(clus);
481  3 return result;
482   
483    }
484   
 
485  19 toggle @Override
486    public List<String> getCluIdsByRelation(String relatedCluId,
487    String luLuRelationTypeKey) throws DoesNotExistException,
488    InvalidParameterException, MissingParameterException,
489    OperationFailedException {
490  19 checkForMissingParameter(relatedCluId, "relatedCluId");
491  18 checkForMissingParameter(luLuRelationTypeKey, "luLuRelationTypeKey");
492   
493  17 List<String> cluIds = luDao.getCluIdsByRelatedCluId(relatedCluId, luLuRelationTypeKey);
494  17 return cluIds;
495    }
496   
 
497  61 toggle @Override
498    public List<CluInfo> getRelatedClusByCluId(String cluId,
499    String luLuRelationTypeKey) throws DoesNotExistException,
500    InvalidParameterException, MissingParameterException,
501    OperationFailedException {
502  61 checkForMissingParameter(cluId, "cluId");
503  61 checkForMissingParameter(luLuRelationTypeKey, "luLuRelationTypeKey");
504  61 List<Clu> relatedClus = luDao.getRelatedClusByCluId(cluId,
505    luLuRelationTypeKey);
506  61 return LuServiceAssembler.toCluInfos(relatedClus);
507    }
508   
 
509  85 toggle @Override
510    public List<String> getRelatedCluIdsByCluId(String cluId,
511    String luLuRelationTypeKey) throws DoesNotExistException,
512    InvalidParameterException, MissingParameterException,
513    OperationFailedException {
514  85 checkForMissingParameter(cluId, "cluId");
515  85 checkForMissingParameter(luLuRelationTypeKey, "luLuRelationTypeKey");
516  85 List<String> relatedCluIds = luDao.getRelatedCluIdsByCluId(cluId,
517    luLuRelationTypeKey);
518  85 return relatedCluIds;
519    }
520   
 
521  2 toggle @Override
522    public CluCluRelationInfo getCluCluRelation(String cluCluRelationId)
523    throws DoesNotExistException, InvalidParameterException,
524    MissingParameterException, OperationFailedException {
525  2 checkForMissingParameter(cluCluRelationId, "cluCluRelationId");
526  2 return LuServiceAssembler.toCluCluRelationInfo(luDao.fetch(
527    CluCluRelation.class, cluCluRelationId));
528    }
529   
 
530  80 toggle @Override
531    public List<CluCluRelationInfo> getCluCluRelationsByClu(String cluId)
532    throws DoesNotExistException, InvalidParameterException,
533    MissingParameterException, OperationFailedException {
534  80 checkForMissingParameter(cluId, "cluId");
535  79 List<CluCluRelation> cluCluRelations = luDao
536    .getCluCluRelationsByClu(cluId);
537  79 return LuServiceAssembler.toCluCluRelationInfos(cluCluRelations);
538    }
539   
540    // **** Publication
 
541  185 toggle @Override
542    public List<CluPublicationInfo> getCluPublicationsByCluId(String cluId)
543    throws DoesNotExistException, InvalidParameterException,
544    MissingParameterException, OperationFailedException {
545  185 checkForMissingParameter(cluId, "cluId");
546  185 List<CluPublication> cluPublications = luDao.getCluPublicationsByCluId(cluId);
547  185 return LuServiceAssembler.toCluPublicationInfos(cluPublications);
548    }
549   
 
550  1 toggle @Override
551    public List<CluPublicationInfo> getCluPublicationsByType(
552    String luPublicationTypeKey) throws DoesNotExistException,
553    InvalidParameterException, MissingParameterException,
554    OperationFailedException {
555  1 checkForMissingParameter(luPublicationTypeKey, "luPublicationTypeKey");
556  1 List<CluPublication> cluPublications = luDao.getCluPublicationsByType(luPublicationTypeKey);
557  1 return LuServiceAssembler.toCluPublicationInfos(cluPublications);
558    }
559   
 
560  1 toggle @Override
561    public CluPublicationInfo getCluPublication(String cluPublicationId)
562    throws DoesNotExistException, InvalidParameterException,
563    MissingParameterException, OperationFailedException {
564  1 checkForMissingParameter(cluPublicationId, "cluPublicationId");
565  1 CluPublication cluPublication = luDao.fetch(CluPublication.class, cluPublicationId);
566  1 return LuServiceAssembler.toCluPublicationInfo(cluPublication);
567    }
568   
569    // **** Results
570   
 
571  4 toggle @Override
572    public CluResultInfo getCluResult(String cluResultId)
573    throws DoesNotExistException, InvalidParameterException,
574    MissingParameterException, OperationFailedException {
575   
576  4 checkForMissingParameter(cluResultId, "cluResultId");
577   
578  4 CluResult cluResult = luDao.fetch(CluResult.class, cluResultId);
579  4 return LuServiceAssembler.toCluResultInfo(cluResult);
580    }
581   
 
582  122 toggle @Override
583    public List<CluResultInfo> getCluResultByClu(String cluId)
584    throws DoesNotExistException, InvalidParameterException,
585    MissingParameterException, OperationFailedException {
586   
587  122 checkForMissingParameter(cluId, "cluId");
588   
589  122 return LuServiceAssembler.toCluResultInfos(luDao
590    .getCluResultByClu(cluId));
591    }
592   
 
593  0 toggle @Override
594    public List<String> getCluIdsByResultUsageType(String resultUsageTypeKey)
595    throws DoesNotExistException, InvalidParameterException,
596    MissingParameterException, OperationFailedException {
597  0 return luDao.getCluIdsByResultUsageType(resultUsageTypeKey);
598    }
599   
 
600  0 toggle @Override
601    public List<String> getCluIdsByResultComponent(String resultComponentId)
602    throws DoesNotExistException, InvalidParameterException,
603    MissingParameterException, OperationFailedException {
604  0 return luDao.getCluIdsByResultComponentId(resultComponentId);
605    }
606   
607    // **** Learning Objectives
608   
 
609  1 toggle @Override
610    public CluLoRelationInfo getCluLoRelation(String cluLoRelationId)
611    throws DoesNotExistException, InvalidParameterException,
612    MissingParameterException, OperationFailedException,
613    PermissionDeniedException {
614   
615  1 checkForMissingParameter(cluLoRelationId, "cluLoRelationId");
616   
617  1 CluLoRelation reltn = luDao.fetch(CluLoRelation.class, cluLoRelationId);
618  1 return LuServiceAssembler.toCluLoRelationInfo(reltn);
619   
620    }
621   
 
622  182 toggle @Override
623    public List<CluLoRelationInfo> getCluLoRelationsByClu(String cluId)
624    throws DoesNotExistException, InvalidParameterException,
625    MissingParameterException, OperationFailedException {
626   
627  182 checkForMissingParameter(cluId, "cluId");
628  182 List<CluLoRelation> cluLoRelations = luDao
629    .getCluLoRelationsByClu(cluId);
630  182 return LuServiceAssembler.toCluLoRelationInfos(cluLoRelations);
631   
632    }
633   
 
634  1 toggle @Override
635    public List<CluLoRelationInfo> getCluLoRelationsByLo(String loId)
636    throws DoesNotExistException, InvalidParameterException,
637    MissingParameterException, OperationFailedException {
638  1 checkForMissingParameter(loId, "loId");
639  1 List<CluLoRelation> cluLoRelations = luDao.getCluLoRelationsByLo(loId);
640  1 return LuServiceAssembler.toCluLoRelationInfos(cluLoRelations);
641    }
642   
643    // *** Resources
644   
 
645  0 toggle @Override
646    public List<String> getResourceRequirementsForCluId(String cluId)
647    throws DoesNotExistException, InvalidParameterException,
648    MissingParameterException, OperationFailedException {
649  0 throw new UnsupportedOperationException("Method not yet implemented!");
650    }
651   
652    // *** Sets
653   
 
654  126 toggle @Override
655    public CluSetInfo getCluSetInfo(String cluSetId)
656    throws DoesNotExistException, InvalidParameterException,
657    MissingParameterException, OperationFailedException,
658    PermissionDeniedException {
659  126 checkForMissingParameter(cluSetId, "cluSetId");
660  125 CluSet cluSet = luDao.fetch(CluSet.class, cluSetId);
661  122 CluSetInfo cluSetInfo = LuServiceAssembler.toCluSetInfo(cluSet);
662  122 setMembershipQuerySearchResult(cluSetInfo);
663  122 return cluSetInfo;
664    }
665   
 
666  49 toggle @Override
667    public CluSetTreeViewInfo getCluSetTreeView(String cluSetId)
668    throws DoesNotExistException, InvalidParameterException,
669    MissingParameterException, OperationFailedException,
670    PermissionDeniedException {
671   
672  49 checkForMissingParameter(cluSetId, "cluSetId");
673  48 CluSetInfo cluSet = getCluSetInfo(cluSetId);
674  47 if (cluSet == null) {
675  0 return null;
676    }
677   
678  47 CluSetTreeViewInfo cluSetTreeView = new CluSetTreeViewInfo();
679  47 getCluSetTreeViewHelper(cluSet, cluSetTreeView);
680  47 return cluSetTreeView;
681    }
682   
683    /**
684    * Go through the list of CluSets and retrieve all the information regarding child
685    * Clu Sets and associated Clus
686    *
687    * @param cluSetInfo
688    * @param cluSetTreeViewInfo
689    * @throws DoesNotExistException
690    * @throws InvalidParameterException
691    * @throws MissingParameterException
692    * @throws OperationFailedException
693    * @throws PermissionDeniedException
694    */
 
695  51 toggle private void getCluSetTreeViewHelper(CluSetInfo cluSetInfo,
696    CluSetTreeViewInfo cluSetTreeViewInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
697  51 cluSetTreeViewInfo.setName(cluSetInfo.getName());
698  51 cluSetTreeViewInfo.setDescr(cluSetInfo.getDescr());
699  51 cluSetTreeViewInfo.setEffectiveDate(cluSetInfo.getEffectiveDate());
700  51 cluSetTreeViewInfo.setExpirationDate(cluSetInfo.getExpirationDate());
701  51 cluSetTreeViewInfo.setAdminOrg(cluSetInfo.getAdminOrg());
702  51 cluSetTreeViewInfo.setIsReusable(cluSetInfo.getIsReusable());
703  51 cluSetTreeViewInfo.setIsReferenceable(cluSetInfo.getIsReferenceable());
704  51 cluSetTreeViewInfo.setMetaInfo(cluSetInfo.getMetaInfo());
705  51 cluSetTreeViewInfo.setAttributes(cluSetInfo.getAttributes());
706  51 cluSetTreeViewInfo.setType(cluSetInfo.getType());
707  51 cluSetTreeViewInfo.setState(cluSetInfo.getState());
708  51 cluSetTreeViewInfo.setId(cluSetInfo.getId());
709   
710  51 if (!cluSetInfo.getCluSetIds().isEmpty()) {
711  2 for (String cluSetId : cluSetInfo.getCluSetIds()) {
712  4 CluSetInfo subCluSet = getCluSetInfo(cluSetId);
713  4 List<CluSetTreeViewInfo> cluSets =
714  4 cluSetTreeViewInfo.getCluSets() == null ?
715    new ArrayList<CluSetTreeViewInfo>(0) : cluSetTreeViewInfo.getCluSets();
716   
717  4 CluSetTreeViewInfo subCluSetTreeViewInfo = new CluSetTreeViewInfo();
718  4 getCluSetTreeViewHelper(subCluSet, subCluSetTreeViewInfo);
719  4 cluSets.add(subCluSetTreeViewInfo);
720   
721  4 cluSetTreeViewInfo.setCluSets(cluSets);
722    }
723    }
724  51 List<CluInfo> clus = new ArrayList<CluInfo>(cluSetInfo.getCluIds().size());
725  51 for (String cluId : cluSetInfo.getCluIds()) {
726  194 if(cluId!=null){
727  194 clus.add(LuServiceAssembler.toCluInfo(luDao.getCurrentCluVersion(cluId)));
728    }
729    }
730  51 cluSetTreeViewInfo.setClus(clus);
731    }
732   
 
733  5 toggle @Override
734    public List<CluSetInfo> getCluSetInfoByIdList(List<String> cluSetIdList)
735    throws DoesNotExistException, InvalidParameterException,
736    MissingParameterException, OperationFailedException,
737    PermissionDeniedException {
738  5 checkForMissingParameter(cluSetIdList, "cluSetIdList");
739  4 checkForEmptyList(cluSetIdList, "cluSetIdList");
740  4 List<CluSet> cluSets = luDao.getCluSetInfoByIdList(cluSetIdList);
741  4 return LuServiceAssembler.toCluSetInfos(cluSets);
742    }
743   
 
744  0 toggle @Override
745    public List<String> getCluSetIdsFromCluSet(String cluSetId)
746    throws DoesNotExistException, InvalidParameterException,
747    MissingParameterException, OperationFailedException,
748    PermissionDeniedException {
749  0 checkForMissingParameter(cluSetId, "cluSetId");
750  0 CluSet cluSet = luDao.fetch(CluSet.class, cluSetId);
751  0 List<String> ids = new ArrayList<String>(cluSet.getCluVerIndIds().size());
752  0 if(cluSet.getCluSets()!=null){
753  0 for (CluSet cluSet2 : cluSet.getCluSets()) {
754  0 ids.add(cluSet2.getId());
755    }
756    }
757  0 return ids;
758    }
759   
 
760  0 toggle @Override
761    public Boolean isCluSetDynamic(String cluSetId)
762    throws DoesNotExistException, InvalidParameterException,
763    MissingParameterException, OperationFailedException,
764    PermissionDeniedException {
765  0 throw new UnsupportedOperationException("Method not yet implemented!");
766    }
767   
 
768  3 toggle @Override
769    public List<CluInfo> getClusFromCluSet(String cluSetId)
770    throws DoesNotExistException, InvalidParameterException,
771    MissingParameterException, OperationFailedException,
772    PermissionDeniedException {
773  3 checkForMissingParameter(cluSetId, "cluSetId");
774  2 CluSet cluSet = luDao.fetch(CluSet.class, cluSetId);
775  1 List<CluInfo> clus = new ArrayList<CluInfo>(cluSet.getCluVerIndIds().size());
776  1 for (CluSetJoinVersionIndClu cluSetJnClu : cluSet.getCluVerIndIds()) {
777  2 clus.add(LuServiceAssembler.toCluInfo(luDao.getCurrentCluVersion(cluSetJnClu.getCluVersionIndId())));
778    }
779  1 return clus;
780    }
781   
 
782  3 toggle @Override
783    public List<String> getCluIdsFromCluSet(String cluSetId)
784    throws DoesNotExistException, InvalidParameterException,
785    MissingParameterException, OperationFailedException,
786    PermissionDeniedException {
787  3 checkForMissingParameter(cluSetId, "cluSetId");
788  2 CluSet cluSet = luDao.fetch(CluSet.class, cluSetId);
789  1 List<String> ids = new ArrayList<String>(cluSet.getCluVerIndIds().size());
790  1 for (CluSetJoinVersionIndClu cluSetJnClu : cluSet.getCluVerIndIds()) {
791  2 ids.add(cluSetJnClu.getCluVersionIndId());
792    }
793  1 return ids;
794    }
795   
 
796  2 toggle @Override
797    public List<CluInfo> getAllClusInCluSet(String cluSetId)
798    throws DoesNotExistException, InvalidParameterException,
799    MissingParameterException, OperationFailedException,
800    PermissionDeniedException {
801  2 checkForMissingParameter(cluSetId, "cluSetId");
802  2 List<String> cluIndIds = new ArrayList<String>();
803  2 CluSet cluSet = luDao.fetch(CluSet.class, cluSetId);
804  2 findClusInCluSet(cluIndIds, cluSet);
805  2 List<CluInfo> infos = new ArrayList<CluInfo>(cluIndIds.size());
806  2 for (String cluIndId : cluIndIds) {
807  5 infos.add(LuServiceAssembler.toCluInfo(luDao.getCurrentCluVersion(cluIndId)));
808    }
809  2 return infos;
810    }
811   
 
812  1 toggle @Override
813    public List<String> getAllCluIdsInCluSet(String cluSetId)
814    throws DoesNotExistException, InvalidParameterException,
815    MissingParameterException, OperationFailedException,
816    PermissionDeniedException {
817  1 checkForMissingParameter(cluSetId, "cluSetId");
818  0 List<String> ids = new ArrayList<String>();
819  0 CluSet cluSet = luDao.fetch(CluSet.class, cluSetId);
820  0 findClusInCluSet(ids, cluSet);
821  0 return ids;
822    }
823   
 
824  6 toggle @Override
825    public Boolean isCluInCluSet(String cluId, String cluSetId)
826    throws DoesNotExistException, InvalidParameterException,
827    MissingParameterException, OperationFailedException,
828    PermissionDeniedException {
829  6 checkForMissingParameter(cluId, "cluId");
830  5 checkForMissingParameter(cluSetId, "cluSetId");
831  4 return luDao.isCluInCluSet(cluId, cluSetId);
832    }
833   
834    // ******** LUI OPERATIONS
835    // *** Core
836   
 
837  4 toggle @Override
838    public LuiInfo getLui(String luiId) throws DoesNotExistException,
839    InvalidParameterException, MissingParameterException,
840    OperationFailedException {
841   
842  4 checkForMissingParameter(luiId, "luiId");
843   
844  3 Lui lui = luDao.fetch(Lui.class, luiId);
845  2 return LuServiceAssembler.toLuiInfo(lui);
846    }
847   
 
848  3 toggle @Override
849    public List<LuiInfo> getLuisByIdList(List<String> luiIdList)
850    throws DoesNotExistException, InvalidParameterException,
851    MissingParameterException, OperationFailedException {
852  3 checkForMissingParameter(luiIdList, "luiIdList");
853  2 checkForEmptyList(luiIdList, "luiIdList");
854  2 List<Lui> luis = luDao.getLuisByIdList(luiIdList);
855  2 return LuServiceAssembler.toLuiInfos(luis);
856    }
857   
 
858  0 toggle @Override
859    public List<LuiInfo> getLuisInAtpByCluId(String cluId, String atpKey)
860    throws DoesNotExistException, InvalidParameterException,
861    MissingParameterException, OperationFailedException {
862  0 throw new UnsupportedOperationException("Method not yet implemented!");
863    }
864   
 
865  4 toggle @Override
866    public List<String> getLuiIdsByCluId(String cluId)
867    throws DoesNotExistException, InvalidParameterException,
868    MissingParameterException, OperationFailedException {
869   
870  4 checkForMissingParameter(cluId, "cluId");
871   
872  3 return luDao.getLuiIdsByCluId(cluId);
873    }
874   
 
875  6 toggle @Override
876    public List<String> getLuiIdsInAtpByCluId(String cluId, String atpKey)
877    throws DoesNotExistException, InvalidParameterException,
878    MissingParameterException, OperationFailedException {
879   
880  6 checkForMissingParameter(cluId, "cluId");
881  5 checkForMissingParameter(atpKey, "atpKey");
882  4 return luDao.getLuiIdsInAtpByCluId(cluId, atpKey);
883    }
884   
885    // *** Relations
886   
 
887  0 toggle @Override
888    public List<String> getAllowedLuLuRelationTypesByLuiId(String luiId,
889    String relatedLuiId) throws DoesNotExistException,
890    InvalidParameterException, MissingParameterException,
891    OperationFailedException {
892   
893  0 checkForMissingParameter(luiId, "luiId");
894  0 checkForMissingParameter(relatedLuiId, "relatedLuiId");
895   
896  0 return luDao.getAllowedLuLuRelationTypesByLuiId(luiId, relatedLuiId);
897    }
898   
 
899  2 toggle @Override
900    public List<LuiInfo> getLuisByRelation(String luiId,
901    String luLuRelationTypeKey) throws DoesNotExistException,
902    InvalidParameterException, MissingParameterException,
903    OperationFailedException {
904  2 checkForMissingParameter(luiId, "luiId");
905  2 checkForMissingParameter(luLuRelationTypeKey, "luLuRelationTypeKey");
906   
907  2 return LuServiceAssembler.toLuiInfos(luDao.getLuisByRelationType(luiId,
908    luLuRelationTypeKey));
909    }
910   
 
911  2 toggle @Override
912    public List<String> getLuiIdsByRelation(String luiId,
913    String luLuRelationTypeKey) throws DoesNotExistException,
914    InvalidParameterException, MissingParameterException,
915    OperationFailedException {
916  2 checkForMissingParameter(luiId, "luiId");
917  2 checkForMissingParameter(luLuRelationTypeKey, "luLuRelationTypeKey");
918   
919  2 return luDao.getLuiIdsByRelationType(luiId, luLuRelationTypeKey);
920    }
921   
 
922  1 toggle @Override
923    public List<LuiInfo> getRelatedLuisByLuiId(String luiId,
924    String luLuRelationTypeKey) throws DoesNotExistException,
925    InvalidParameterException, MissingParameterException,
926    OperationFailedException {
927  1 checkForMissingParameter(luiId, "luiId");
928  1 checkForMissingParameter(luLuRelationTypeKey, "luLuRelationTypeKey");
929  1 List<Lui> relatedLuis = luDao.getRelatedLuisByLuiId(luiId,
930    luLuRelationTypeKey);
931  1 return LuServiceAssembler.toLuiInfos(relatedLuis);
932    }
933   
 
934  1 toggle @Override
935    public List<String> getRelatedLuiIdsByLuiId(String luiId,
936    String luLuRelationTypeKey) throws DoesNotExistException,
937    InvalidParameterException, MissingParameterException,
938    OperationFailedException {
939  1 checkForMissingParameter(luiId, "luiId");
940  1 checkForMissingParameter(luLuRelationTypeKey, "luLuRelationTypeKey");
941  1 List<String> relatedLuiIds = luDao.getRelatedLuiIdsByLuiId(luiId,
942    luLuRelationTypeKey);
943  1 return relatedLuiIds;
944    }
945   
 
946  2 toggle @Override
947    public LuiLuiRelationInfo getLuiLuiRelation(String luiLuiRelationId)
948    throws DoesNotExistException, InvalidParameterException,
949    MissingParameterException, OperationFailedException {
950  2 checkForMissingParameter(luiLuiRelationId, "luiLuiRelationId");
951  2 LuiLuiRelation luiLuiRelation = luDao.fetch(LuiLuiRelation.class,
952    luiLuiRelationId);
953  1 return LuServiceAssembler.toLuiLuiRelationInfo(luiLuiRelation);
954    }
955   
 
956  3 toggle @Override
957    public List<LuiLuiRelationInfo> getLuiLuiRelationsByLui(String luiId)
958    throws DoesNotExistException, InvalidParameterException,
959    MissingParameterException, OperationFailedException {
960  3 checkForMissingParameter(luiId, "luiId");
961  3 List<LuiLuiRelation> entities = luDao.getLuiLuiRelations(luiId);
962  3 return LuServiceAssembler.toLuiLuiRelationInfos(entities);
963    }
964   
965    /**************************************************************************
966    * MAINTENANCE OPERATIONS *
967    **************************************************************************/
968   
 
969  233 toggle @Override
970    public List<ValidationResultInfo> validateClu(String validationType,
971    CluInfo cluInfo) throws DoesNotExistException,
972    InvalidParameterException, MissingParameterException,
973    OperationFailedException {
974  233 checkForMissingParameter(validationType, "validationType");
975  233 checkForMissingParameter(cluInfo, "cluInfo");
976   
977  233 ObjectStructureDefinition objStructure = this.getObjectStructure(CluInfo.class.getName());
978  233 Validator defaultValidator = validatorFactory.getValidator();
979  233 List<ValidationResultInfo> validationResults = defaultValidator.validateObject(cluInfo, objStructure);
980   
981  233 return validationResults;
982    }
983   
 
984  164 toggle @Override
985    public CluInfo createClu(String luTypeKey, CluInfo cluInfo)
986    throws AlreadyExistsException, DataValidationErrorException,
987    DoesNotExistException, InvalidParameterException,
988    MissingParameterException, OperationFailedException,
989    PermissionDeniedException {
990  164 Clu clu = toCluForCreate(luTypeKey,cluInfo);
991    //Set current (since this is brand new and every verIndId needs one current)
992  164 if(clu.getVersion() == null){
993  164 clu.setVersion(new Version());
994    }
995  164 clu.getVersion().setCurrentVersionStart(new Date());
996  164 luDao.create(clu);
997  164 return LuServiceAssembler.toCluInfo(clu);
998    }
999   
 
1000  182 toggle public Clu toCluForCreate(String luTypeKey, CluInfo cluInfo)
1001    throws AlreadyExistsException, DataValidationErrorException,
1002    DoesNotExistException, InvalidParameterException,
1003    MissingParameterException, OperationFailedException,
1004    PermissionDeniedException {
1005  182 checkForMissingParameter(luTypeKey, "luTypeKey");
1006  182 checkForMissingParameter(cluInfo, "cluInfo");
1007   
1008    // Validate CLU
1009  182 List<ValidationResultInfo> val = validateClu("SYSTEM", cluInfo);
1010  182 if(null != val && val.size() > 0) {
1011  0 throw new DataValidationErrorException("Validation error!", val);
1012    }
1013   
1014  182 Clu clu = new Clu();
1015   
1016  182 LuType luType = luDao.fetch(LuType.class, luTypeKey);
1017  182 clu.setLuType(luType);
1018   
1019  182 if (cluInfo.getOfficialIdentifier() != null) {
1020  56 clu.setOfficialIdentifier(LuServiceAssembler.createOfficialIdentifier(cluInfo));
1021    }
1022  182 clu.setAlternateIdentifiers(LuServiceAssembler.createAlternateIdentifiers(cluInfo));
1023  182 if (cluInfo.getDescr() != null) {
1024  56 LuRichText descr = LuServiceAssembler.toRichText(LuRichText.class, cluInfo.getDescr());
1025  56 if (descr.getPlain() != null || descr.getFormatted() != null) {
1026  56 clu.setDescr(descr);
1027    }
1028    }
1029   
1030  182 if (clu.getAdminOrgs() == null) {
1031  182 clu.setAdminOrgs(new ArrayList<CluAdminOrg>(0));
1032    }
1033  182 List<CluAdminOrg> adminOrgs = clu.getAdminOrgs();
1034  182 for (AdminOrgInfo orgInfo : cluInfo.getAdminOrgs()) {
1035  480 CluAdminOrg instructor = new CluAdminOrg();
1036  480 BeanUtils.copyProperties(orgInfo, instructor,
1037    new String[] { "attributes" });
1038  480 instructor.setAttributes(LuServiceAssembler.toGenericAttributes(
1039    CluAdminOrgAttribute.class, orgInfo.getAttributes(),
1040    instructor, luDao));
1041  480 instructor.setClu(clu);
1042  480 adminOrgs.add(instructor);
1043    }
1044   
1045  182 if (cluInfo.getPrimaryInstructor() != null) {
1046  25 CluInstructor primaryInstructor = new CluInstructor();
1047  25 BeanUtils.copyProperties(cluInfo.getPrimaryInstructor(),
1048    primaryInstructor, new String[] { "attributes" });
1049  25 primaryInstructor.setAttributes(LuServiceAssembler
1050    .toGenericAttributes(CluInstructorAttribute.class, cluInfo
1051    .getPrimaryInstructor().getAttributes(),
1052    primaryInstructor, luDao));
1053  25 clu.setPrimaryInstructor(primaryInstructor);
1054    }
1055   
1056  182 if (clu.getInstructors() == null) {
1057  182 clu.setInstructors(new ArrayList<CluInstructor>(0));
1058    }
1059  182 List<CluInstructor> instructors = clu.getInstructors();
1060  182 for (CluInstructorInfo instructorInfo : cluInfo.getInstructors()) {
1061  60 CluInstructor instructor = new CluInstructor();
1062  60 BeanUtils.copyProperties(instructorInfo, instructor,
1063    new String[] { "attributes" });
1064  60 instructor.setAttributes(LuServiceAssembler.toGenericAttributes(
1065    CluInstructorAttribute.class, instructorInfo
1066    .getAttributes(), instructor, luDao));
1067  60 instructors.add(instructor);
1068    }
1069   
1070  182 if (cluInfo.getStdDuration() != null) {
1071  121 clu.setStdDuration(LuServiceAssembler.toTimeAmount(cluInfo
1072    .getStdDuration()));
1073    }
1074   
1075  182 if (clu.getLuCodes() == null) {
1076  182 clu.setLuCodes(new ArrayList<LuCode>(0));
1077    }
1078  182 List<LuCode> luCodes = clu.getLuCodes();
1079  182 for (LuCodeInfo luCodeInfo : cluInfo.getLuCodes()) {
1080  101 LuCode luCode = new LuCode();
1081  101 luCode.setAttributes(LuServiceAssembler.toGenericAttributes(
1082    LuCodeAttribute.class, luCodeInfo.getAttributes(), luCode,
1083    luDao));
1084  101 BeanUtils.copyProperties(luCodeInfo, luCode, new String[] {
1085    "attributes", "metaInfo" });
1086  101 luCode.setDescr(luCodeInfo.getDescr());
1087  101 luCode.setClu(clu);
1088  101 luCodes.add(luCode);
1089    }
1090   
1091  182 if (clu.getOfferedAtpTypes() == null) {
1092  182 clu.setOfferedAtpTypes(new ArrayList<CluAtpTypeKey>(0));
1093    }
1094  182 List<CluAtpTypeKey> offeredAtpTypes = clu.getOfferedAtpTypes();
1095  182 for (String atpTypeKey : cluInfo.getOfferedAtpTypes()) {
1096  50 CluAtpTypeKey cluAtpTypeKey = new CluAtpTypeKey();
1097  50 cluAtpTypeKey.setAtpTypeKey(atpTypeKey);
1098  50 cluAtpTypeKey.setClu(clu);
1099  50 offeredAtpTypes.add(cluAtpTypeKey);
1100    }
1101   
1102    // FEE INFO
1103  182 if (cluInfo.getFeeInfo() != null) {
1104  25 CluFee cluFee = null;
1105  25 try {
1106  25 cluFee = LuServiceAssembler.toCluFee(clu, false, cluInfo
1107    .getFeeInfo(), luDao);
1108    } catch (VersionMismatchException e) {
1109    // Version Mismatch Should Happen only for updates
1110    }
1111  25 clu.setFee(cluFee);
1112    }
1113   
1114  182 if (cluInfo.getAccountingInfo() != null) {
1115  25 CluAccounting cluAccounting = new CluAccounting();
1116  25 cluAccounting.setAttributes(LuServiceAssembler.toGenericAttributes(
1117    CluAccountingAttribute.class, cluInfo.getAccountingInfo()
1118    .getAttributes(), cluAccounting, luDao));
1119  25 cluAccounting.setAffiliatedOrgs(LuServiceAssembler
1120    .toAffiliatedOrgs(false, cluAccounting.getAffiliatedOrgs(),
1121    cluInfo.getAccountingInfo().getAffiliatedOrgs(),
1122    luDao));
1123  25 clu.setAccounting(cluAccounting);
1124    }
1125   
1126  182 clu.setAttributes(LuServiceAssembler.toGenericAttributes(
1127    CluAttribute.class, cluInfo.getAttributes(), clu, luDao));
1128   
1129   
1130  182 if (cluInfo.getIntensity() != null) {
1131  121 clu.setIntensity(LuServiceAssembler
1132    .toAmount(cluInfo.getIntensity()));
1133    }
1134   
1135  182 if (clu.getCampusLocations() == null) {
1136  182 clu.setCampusLocations(new ArrayList<CluCampusLocation>(0));
1137    }
1138  182 List<CluCampusLocation> locations = clu.getCampusLocations();
1139  182 for (String locationName : cluInfo.getCampusLocations()) {
1140  82 CluCampusLocation location = new CluCampusLocation();
1141  82 location.setCampusLocation(locationName);
1142  82 location.setClu(clu);
1143  82 locations.add(location);
1144    }
1145   
1146  182 if (clu.getAccreditations() == null) {
1147  182 clu.setAccreditations(new ArrayList<CluAccreditation>(0));
1148    }
1149  182 List<CluAccreditation> accreditations = clu.getAccreditations();
1150  182 for (AccreditationInfo accreditationInfo : cluInfo.getAccreditations()) {
1151  18 CluAccreditation accreditation = new CluAccreditation();
1152  18 BeanUtils.copyProperties(accreditationInfo, accreditation,
1153    new String[] { "attributes" });
1154  18 accreditation.setAttributes(LuServiceAssembler.toGenericAttributes(
1155    CluAccreditationAttribute.class, accreditationInfo
1156    .getAttributes(), accreditation, luDao));
1157  18 accreditations.add(accreditation);
1158    }
1159   
1160    // Now copy all not standard properties
1161  182 BeanUtils.copyProperties(cluInfo, clu, new String[] { "luType",
1162    "officialIdentifier", "alternateIdentifiers", "descr",
1163    "luCodes", "primaryInstructor", "instructors", "stdDuration",
1164    "offeredAtpTypes", "feeInfo", "accountingInfo", "attributes",
1165    "metaInfo", "versionInfo", "intensity",
1166    "campusLocations", "accreditations",
1167    "adminOrgs" });
1168   
1169  182 return clu;
1170    }
1171   
 
1172  50 toggle @Override
1173    public CluInfo updateClu(String cluId, CluInfo cluInfo)
1174    throws DataValidationErrorException, DoesNotExistException,
1175    InvalidParameterException, MissingParameterException,
1176    OperationFailedException, PermissionDeniedException,
1177    VersionMismatchException {
1178   
1179  50 checkForMissingParameter(cluId, "cluId");
1180  50 checkForMissingParameter(cluInfo, "cluInfo");
1181   
1182    // Validate CLU
1183  50 List<ValidationResultInfo> val = validateClu("SYSTEM", cluInfo);
1184  50 if(null != val && val.size() > 0) {
1185  0 throw new DataValidationErrorException("Validation error!", val);
1186    }
1187   
1188  50 Clu clu = luDao.fetch(Clu.class, cluId);
1189   
1190  50 if (!String.valueOf(clu.getVersionNumber()).equals(
1191    cluInfo.getMetaInfo().getVersionInd())) {
1192  2 throw new VersionMismatchException(
1193    "Clu to be updated is not the current version");
1194    }
1195   
1196  48 LuType luType = luDao.fetch(LuType.class, cluInfo.getType());
1197  48 clu.setLuType(luType);
1198   
1199  48 if (cluInfo.getOfficialIdentifier() != null) {
1200  46 LuServiceAssembler.updateOfficialIdentifier(clu, cluInfo);
1201  2 } else if (clu.getOfficialIdentifier() != null) {
1202  0 luDao.delete(clu.getOfficialIdentifier());
1203    }
1204   
1205    // Update the list of Alternate Identifiers
1206    // Get a map of Id->object of all the currently persisted objects in the
1207    // list
1208  48 Map<String, CluIdentifier> oldAltIdMap = new HashMap<String, CluIdentifier>();
1209  48 LuServiceAssembler.updateAlternateIdentifier(oldAltIdMap, clu, cluInfo);
1210    // Now delete anything left over
1211  48 for (Entry<String, CluIdentifier> entry : oldAltIdMap.entrySet()) {
1212  1 luDao.delete(entry.getValue());
1213    }
1214   
1215  48 if (cluInfo.getDescr() != null && (cluInfo.getDescr().getPlain() != null || cluInfo.getDescr().getFormatted() != null)) {
1216  46 if (clu.getDescr() == null) {
1217  0 clu.setDescr(new LuRichText());
1218    }
1219  46 BeanUtils.copyProperties(cluInfo.getDescr(), clu.getDescr());
1220  2 } else if (clu.getDescr() != null) {
1221  0 luDao.delete(clu.getDescr());
1222  0 clu.setDescr(null);//TODO is the is the best method of doing this? what if the user passes in a new made up id, does that mean we have orphaned richtexts?
1223    }
1224   
1225  48 if (cluInfo.getPrimaryInstructor() != null) {
1226  36 if (clu.getPrimaryInstructor() == null) {
1227  0 clu.setPrimaryInstructor(new CluInstructor());
1228    }
1229  36 BeanUtils.copyProperties(cluInfo.getPrimaryInstructor(), clu
1230    .getPrimaryInstructor(), new String[] { "attributes" });
1231  36 clu.getPrimaryInstructor().setAttributes(
1232    LuServiceAssembler.toGenericAttributes(
1233    CluInstructorAttribute.class, cluInfo
1234    .getPrimaryInstructor().getAttributes(),
1235    clu.getPrimaryInstructor(), luDao));
1236  12 } else if (clu.getPrimaryInstructor() != null) {
1237  0 luDao.delete(clu.getPrimaryInstructor());
1238    }
1239   
1240    // Update the List of instructors
1241    // Get a map of Id->object of all the currently persisted objects in the
1242    // list
1243  48 Map<String, CluInstructor> oldInstructorMap = new HashMap<String, CluInstructor>();
1244  48 for (CluInstructor cluInstructor : clu.getInstructors()) {
1245  30 oldInstructorMap.put(cluInstructor.getOrgId() + "_"
1246    + cluInstructor.getPersonId(), cluInstructor);
1247    }
1248  48 clu.getInstructors().clear();
1249   
1250    // Loop through the new list, if the item exists already update and
1251    // remove from the list
1252    // otherwise create a new entry
1253  48 for (CluInstructorInfo instructorInfo : cluInfo.getInstructors()) {
1254  30 CluInstructor cluInstructor = oldInstructorMap
1255    .remove(instructorInfo.getOrgId() + "_"
1256    + instructorInfo.getPersonId());
1257  30 if (cluInstructor == null) {
1258  3 cluInstructor = new CluInstructor();
1259    }
1260    // Do Copy
1261  30 BeanUtils.copyProperties(instructorInfo, cluInstructor,
1262    new String[] { "attributes" });
1263  30 cluInstructor.setAttributes(LuServiceAssembler.toGenericAttributes(
1264    CluInstructorAttribute.class, instructorInfo
1265    .getAttributes(), cluInstructor, luDao));
1266  30 clu.getInstructors().add(cluInstructor);
1267    }
1268   
1269    // Now delete anything left over
1270  48 for (Entry<String, CluInstructor> entry : oldInstructorMap.entrySet()) {
1271  1 luDao.delete(entry.getValue());
1272    }
1273   
1274  48 if (cluInfo.getStdDuration() != null) {
1275  36 if (clu.getStdDuration() == null) {
1276  0 clu.setStdDuration(new TimeAmount());
1277    }
1278  36 BeanUtils.copyProperties(cluInfo.getStdDuration(), clu
1279    .getStdDuration());
1280  12 } else if (clu.getStdDuration() != null) {
1281  0 luDao.delete(clu.getStdDuration());
1282    }
1283   
1284    // Update the LuCodes
1285    // Get a map of Id->object of all the currently persisted objects in the
1286    // list
1287  48 Map<String, LuCode> oldLuCodeMap = new HashMap<String, LuCode>();
1288  48 for (LuCode luCode : clu.getLuCodes()) {
1289  138 oldLuCodeMap.put(luCode.getId(), luCode);
1290    }
1291  48 clu.getLuCodes().clear();
1292   
1293    // Loop through the new list, if the item exists already update and
1294    // remove from the list
1295    // otherwise create a new entry
1296  48 for (LuCodeInfo luCodeInfo : cluInfo.getLuCodes()) {
1297  136 LuCode luCode = oldLuCodeMap.remove(luCodeInfo.getId());
1298  136 if (luCode == null) {
1299  135 luCode = new LuCode();
1300    } else {
1301  1 if (!String.valueOf(luCode.getVersionNumber()).equals(
1302    luCodeInfo.getMetaInfo().getVersionInd())) {
1303  0 throw new VersionMismatchException(
1304    "LuCode to be updated is not the current version");
1305    }
1306    }
1307    // Do Copy
1308  136 luCode.setAttributes(LuServiceAssembler.toGenericAttributes(
1309    LuCodeAttribute.class, luCodeInfo.getAttributes(), luCode,
1310    luDao));
1311  136 BeanUtils.copyProperties(luCodeInfo, luCode, new String[] {
1312    "attributes", "metaInfo" });
1313  136 luCode.setDescr(luCodeInfo.getDescr());
1314  136 luCode.setClu(clu);
1315  136 clu.getLuCodes().add(luCode);
1316    }
1317   
1318    // Now delete anything left over
1319  48 for (Entry<String, LuCode> entry : oldLuCodeMap.entrySet()) {
1320  137 luDao.delete(entry.getValue());
1321    }
1322   
1323    // Update the list of AtpTypeKeys
1324    // Get a map of Id->object of all the currently persisted objects in the
1325    // list
1326  48 Map<String, CluAtpTypeKey> oldOfferedAtpTypesMap = new HashMap<String, CluAtpTypeKey>();
1327  48 for (CluAtpTypeKey cluAtpTypeKey : clu.getOfferedAtpTypes()) {
1328  20 oldOfferedAtpTypesMap.put(cluAtpTypeKey.getAtpTypeKey(),
1329    cluAtpTypeKey);
1330    }
1331  48 clu.getOfferedAtpTypes().clear();
1332   
1333    // Loop through the new list, if the item exists already update and
1334    // remove from the list
1335    // otherwise create a new entry
1336  48 for (String atpTypeKey : cluInfo.getOfferedAtpTypes()) {
1337  20 CluAtpTypeKey cluAtpTypeKey = oldOfferedAtpTypesMap
1338    .remove(atpTypeKey);
1339  20 if (cluAtpTypeKey == null) {
1340  1 cluAtpTypeKey = new CluAtpTypeKey();
1341    }
1342    // Do Copy
1343  20 cluAtpTypeKey.setAtpTypeKey(atpTypeKey);
1344  20 cluAtpTypeKey.setClu(clu);
1345  20 clu.getOfferedAtpTypes().add(cluAtpTypeKey);
1346    }
1347   
1348    // Now delete anything left over
1349  48 for (Entry<String, CluAtpTypeKey> entry : oldOfferedAtpTypesMap
1350    .entrySet()) {
1351  1 luDao.delete(entry.getValue());
1352    }
1353   
1354  48 if (cluInfo.getFeeInfo() != null) {
1355  10 if (clu.getFee() == null) {
1356  0 clu.setFee(LuServiceAssembler.toCluFee(clu, false, cluInfo
1357    .getFeeInfo(), luDao));
1358    } else {
1359  10 clu.setFee(LuServiceAssembler.toCluFee(clu, true, cluInfo
1360    .getFeeInfo(), luDao));
1361    }
1362  38 } else if (clu.getFee() != null) {
1363  0 luDao.delete(clu.getFee());
1364  0 clu.setFee(null);
1365    }
1366   
1367  48 if (cluInfo.getAccountingInfo() != null) {
1368  10 if (clu.getAccounting() == null) {
1369  0 clu.setAccounting(new CluAccounting());
1370    }
1371  10 clu.getAccounting().setAttributes(
1372    LuServiceAssembler.toGenericAttributes(
1373    CluAccountingAttribute.class, cluInfo
1374    .getAccountingInfo().getAttributes(), clu
1375    .getAccounting(), luDao));
1376  10 clu.getAccounting().setAffiliatedOrgs(LuServiceAssembler
1377    .toAffiliatedOrgs(true, clu.getAccounting().getAffiliatedOrgs(),
1378    cluInfo.getAccountingInfo().getAffiliatedOrgs(),
1379    luDao));
1380   
1381  38 } else if (clu.getAccounting() != null) {
1382  0 clu.setAccounting(null);
1383    }
1384   
1385  48 clu.setAttributes(LuServiceAssembler.toGenericAttributes(
1386    CluAttribute.class, cluInfo.getAttributes(), clu, luDao));
1387   
1388  48 if (cluInfo.getIntensity() != null) {
1389  36 if (clu.getIntensity() == null) {
1390  0 clu.setIntensity(new Amount());
1391    }
1392  36 BeanUtils
1393    .copyProperties(cluInfo.getIntensity(), clu.getIntensity());
1394  12 } else if (clu.getIntensity() != null) {
1395  0 luDao.delete(clu.getIntensity());
1396    }
1397   
1398    // Update the list of campusLocations
1399    // Get a map of Id->object of all the currently persisted objects in the
1400    // list
1401  48 Map<String, CluCampusLocation> oldLocationsMap = new HashMap<String, CluCampusLocation>();
1402  48 for (CluCampusLocation campus : clu.getCampusLocations()) {
1403  75 oldLocationsMap.put(campus.getCampusLocation(), campus);
1404    }
1405  48 clu.getCampusLocations().clear();
1406   
1407    // Loop through the new list, if the item exists already update and
1408    // remove from the list
1409    // otherwise create a new entry
1410  48 for (String locationName : cluInfo.getCampusLocations()) {
1411  77 CluCampusLocation location = oldLocationsMap.remove(locationName);
1412  77 if (location == null) {
1413  4 location = new CluCampusLocation();
1414    }
1415    // Do Copy
1416  77 location.setCampusLocation(locationName);
1417  77 location.setClu(clu);
1418  77 clu.getCampusLocations().add(location);
1419    }
1420   
1421    // Now delete anything left over
1422  48 for (Entry<String, CluCampusLocation> entry : oldLocationsMap
1423    .entrySet()) {
1424  2 luDao.delete(entry.getValue());
1425    }
1426   
1427    // Update the List of accreditations
1428    // Get a map of Id->object of all the currently persisted objects in the
1429    // list
1430  48 Map<String, CluAccreditation> oldAccreditationMap = new HashMap<String, CluAccreditation>();
1431  48 for (CluAccreditation cluAccreditation : clu.getAccreditations()) {
1432  12 oldAccreditationMap.put(cluAccreditation.getId(),
1433    cluAccreditation);
1434    }
1435  48 clu.getAccreditations().clear();
1436   
1437    // Loop through the new list, if the item exists already update and
1438    // remove from the list
1439    // otherwise create a new entry
1440  48 for (AccreditationInfo accreditationInfo : cluInfo.getAccreditations()) {
1441  13 CluAccreditation cluAccreditation = null;
1442  13 if(accreditationInfo.getId()!=null){
1443  11 cluAccreditation = oldAccreditationMap.remove(accreditationInfo.getId());
1444    }
1445   
1446  13 if (cluAccreditation == null) {
1447  2 cluAccreditation = new CluAccreditation();
1448    }
1449    // Do Copy
1450  13 BeanUtils.copyProperties(accreditationInfo, cluAccreditation,
1451    new String[] { "attributes" });
1452  13 cluAccreditation.setAttributes(LuServiceAssembler
1453    .toGenericAttributes(CluAccreditationAttribute.class,
1454    accreditationInfo.getAttributes(),
1455    cluAccreditation, luDao));
1456  13 clu.getAccreditations().add(cluAccreditation);
1457    }
1458   
1459    // Now delete anything left over
1460  48 for (Entry<String, CluAccreditation> entry : oldAccreditationMap
1461    .entrySet()) {
1462  1 luDao.delete(entry.getValue());
1463    }
1464   
1465    // Update the List of alternate admin orgs
1466    // Get a map of Id->object of all the currently persisted objects in the
1467    // list
1468  48 Map<String, CluAdminOrg> oldAdminOrgsMap = new HashMap<String, CluAdminOrg>();
1469  48 if(clu.getAdminOrgs()!=null){
1470  48 for (CluAdminOrg cluOrg : clu.getAdminOrgs()) {
1471  413 oldAdminOrgsMap.put(cluOrg.getId(), cluOrg);
1472    }
1473    }
1474  48 clu.setAdminOrgs(new ArrayList<CluAdminOrg>());
1475   
1476    // Loop through the new list, if the item exists already update and
1477    // remove from the list
1478    // otherwise create a new entry
1479  48 for (AdminOrgInfo orgInfo : cluInfo.getAdminOrgs()) {
1480  412 CluAdminOrg cluOrg = null;
1481  412 if(orgInfo.getId() != null){
1482  2 cluOrg = oldAdminOrgsMap.remove(orgInfo.getId());
1483    }
1484   
1485  412 if (cluOrg == null) {
1486  410 cluOrg = new CluAdminOrg();
1487    }
1488   
1489    // Do Copy
1490  412 BeanUtils.copyProperties(orgInfo, cluOrg,
1491    new String[] { "attributes","id" });
1492  412 cluOrg.setAttributes(LuServiceAssembler.toGenericAttributes(
1493    CluAdminOrgAttribute.class, orgInfo.getAttributes(),
1494    cluOrg, luDao));
1495  412 cluOrg.setClu(clu);
1496  412 clu.getAdminOrgs().add(cluOrg);
1497    }
1498   
1499  48 for (Entry<String, CluAdminOrg> entry : oldAdminOrgsMap.entrySet()) {
1500  411 luDao.delete(entry.getValue());
1501    }
1502   
1503    // Now copy all not standard properties
1504  48 BeanUtils.copyProperties(cluInfo, clu, new String[] { "luType",
1505    "officialIdentifier", "alternateIdentifiers", "descr",
1506    "luCodes", "primaryInstructor", "instructors", "stdDuration",
1507    "offeredAtpTypes", "feeInfo", "accountingInfo", "attributes",
1508    "metaInfo","intensity",
1509    "campusLocations", "accreditations",
1510    "adminOrgs" });
1511  48 Clu updated = null;
1512  48 try {
1513  48 updated = luDao.update(clu);
1514    } catch (Exception e) {
1515  0 logger.error("Exception occured: ", e);
1516    }
1517  48 return LuServiceAssembler.toCluInfo(updated);
1518    }
1519   
 
1520  14 toggle @Override
1521    public StatusInfo deleteClu(String cluId) throws DoesNotExistException,
1522    InvalidParameterException, MissingParameterException,
1523    DependentObjectsExistException, OperationFailedException,
1524    PermissionDeniedException {
1525  14 checkForMissingParameter(cluId, "cluId");
1526   
1527  14 luDao.delete(Clu.class, cluId);
1528   
1529  14 StatusInfo statusInfo = new StatusInfo();
1530  14 statusInfo.setSuccess(true);
1531   
1532  14 return statusInfo;
1533    }
1534   
 
1535  0 toggle @Override
1536    public CluInfo updateCluState(String cluId, String luState)
1537    throws DataValidationErrorException, DoesNotExistException,
1538    InvalidParameterException, MissingParameterException,
1539    OperationFailedException, PermissionDeniedException {
1540    // Check Missing params
1541  0 checkForMissingParameter(cluId, "cluId");
1542  0 checkForMissingParameter(luState, "luState");
1543  0 Clu clu = luDao.fetch(Clu.class, cluId);
1544  0 clu.setState(luState);
1545  0 Clu updated = luDao.update(clu);
1546  0 return LuServiceAssembler.toCluInfo(updated);
1547    }
1548   
 
1549  178 toggle @Override
1550    public List<ValidationResultInfo> validateCluCluRelation(
1551    String validationType, CluCluRelationInfo cluCluRelationInfo)
1552    throws DoesNotExistException, InvalidParameterException,
1553    MissingParameterException, OperationFailedException {
1554  178 checkForMissingParameter(validationType, "validationType");
1555  178 checkForMissingParameter(cluCluRelationInfo, "cluCluRelationInfo");
1556   
1557  178 ObjectStructureDefinition objStructure = this.getObjectStructure(CluCluRelationInfo.class.getName());
1558  178 Validator defaultValidator = validatorFactory.getValidator();
1559  178 List<ValidationResultInfo> validationResults = defaultValidator.validateObject(cluCluRelationInfo, objStructure);
1560   
1561  178 return validationResults;
1562    }
1563   
 
1564  176 toggle @Override
1565    public CluCluRelationInfo createCluCluRelation(String cluId,
1566    String relatedCluId, String luLuRelationTypeKey,
1567    CluCluRelationInfo cluCluRelationInfo)
1568    throws AlreadyExistsException, DataValidationErrorException,
1569    DoesNotExistException, InvalidParameterException,
1570    MissingParameterException, OperationFailedException,
1571    PermissionDeniedException, CircularRelationshipException {
1572  176 checkForMissingParameter(cluId, "cluId");
1573  176 checkForMissingParameter(relatedCluId, "relatedCluId");
1574  176 checkForMissingParameter(luLuRelationTypeKey, "luLuRelationTypeKey");
1575  176 checkForMissingParameter(cluCluRelationInfo, "cluCluRelationInfo");
1576   
1577  176 if (cluId.equals(relatedCluId)) {
1578  0 throw new CircularRelationshipException(
1579    "Can not relate a Clu to itself");
1580    }
1581   
1582    // Validate CluCluRelationInfo
1583  176 List<ValidationResultInfo> val = validateCluCluRelation("SYSTEM", cluCluRelationInfo);
1584  176 if(null != val && val.size() > 0) {
1585  0 throw new DataValidationErrorException("Validation error!", val);
1586    }
1587   
1588   
1589  176 Clu clu = luDao.fetch(Clu.class, cluId);
1590  176 Clu relatedClu = luDao.fetch(Clu.class, relatedCluId);
1591   
1592  176 CluCluRelation cluCluRelation = new CluCluRelation();
1593  176 BeanUtils.copyProperties(cluCluRelationInfo, cluCluRelation,
1594    new String[] { "cluId", "relatedCluId",
1595    "isCluRelationRequired", "attributes", "metaInfo" });
1596   
1597  176 cluCluRelation.setClu(clu);
1598  176 cluCluRelation.setRelatedClu(relatedClu);
1599  176 cluCluRelation.setCluRelationRequired(cluCluRelationInfo
1600    .getIsCluRelationRequired() == null ? true : cluCluRelationInfo
1601    .getIsCluRelationRequired()); // TODO maybe this is unnecessary,
1602    // contract specifies not null
1603  176 cluCluRelation.setAttributes(LuServiceAssembler.toGenericAttributes(
1604    CluCluRelationAttribute.class, cluCluRelationInfo
1605    .getAttributes(), cluCluRelation, luDao));
1606   
1607  176 LuLuRelationType luLuRelationType = luDao.fetch(LuLuRelationType.class,
1608    luLuRelationTypeKey);
1609   
1610  176 cluCluRelation.setLuLuRelationType(luLuRelationType);
1611   
1612  176 luDao.create(cluCluRelation);
1613   
1614  176 return LuServiceAssembler.toCluCluRelationInfo(cluCluRelation);
1615    }
1616   
 
1617  2 toggle @Override
1618    public CluCluRelationInfo updateCluCluRelation(
1619    final String cluCluRelationId,
1620    final CluCluRelationInfo cluCluRelationInfo)
1621    throws DataValidationErrorException, DoesNotExistException,
1622    InvalidParameterException, MissingParameterException,
1623    OperationFailedException, PermissionDeniedException,
1624    VersionMismatchException {
1625  2 checkForMissingParameter(cluCluRelationId, "cluCluRelationId");
1626  2 checkForMissingParameter(cluCluRelationInfo, "cluCluRelationInfo");
1627   
1628    // Validate CluCluRelationInfo
1629  2 List<ValidationResultInfo> val = validateCluCluRelation("SYSTEM", cluCluRelationInfo);
1630  2 if(null != val && val.size() > 0) {
1631  0 throw new DataValidationErrorException("Validation error!", val);
1632    }
1633   
1634  2 final CluCluRelation cluCluRelation = luDao.fetch(CluCluRelation.class,
1635    cluCluRelationId);
1636  2 BeanUtils.copyProperties(cluCluRelationInfo, cluCluRelation,
1637    new String[] { "cluId", "relatedCluId",
1638    "isCluRelationRequired", "attributes", "metaInfo" });
1639   
1640  2 cluCluRelation.setClu(luDao.fetch(Clu.class, cluCluRelationInfo
1641    .getCluId()));
1642  2 cluCluRelation.setRelatedClu(luDao.fetch(Clu.class, cluCluRelationInfo
1643    .getRelatedCluId()));
1644  2 cluCluRelation.setCluRelationRequired(cluCluRelationInfo
1645    .getIsCluRelationRequired() == null ? true : cluCluRelationInfo
1646    .getIsCluRelationRequired()); // TODO maybe this is unnecessary,
1647    // contract specifies not null
1648  2 cluCluRelation.setAttributes(LuServiceAssembler.toGenericAttributes(
1649    CluCluRelationAttribute.class, cluCluRelationInfo
1650    .getAttributes(), cluCluRelation, luDao));
1651   
1652  2 cluCluRelation.setLuLuRelationType(luDao.fetch(LuLuRelationType.class,
1653    cluCluRelationInfo.getType()));
1654   
1655  2 final CluCluRelation update = luDao.update(cluCluRelation);
1656   
1657  2 return LuServiceAssembler.toCluCluRelationInfo(update);
1658    }
1659   
 
1660  20 toggle @Override
1661    public StatusInfo deleteCluCluRelation(String cluCluRelationId)
1662    throws DoesNotExistException, InvalidParameterException,
1663    MissingParameterException, OperationFailedException,
1664    PermissionDeniedException {
1665  20 checkForMissingParameter(cluCluRelationId, "cluCluRelationId");
1666   
1667  20 luDao.delete(CluCluRelation.class, cluCluRelationId);
1668   
1669  20 StatusInfo statusInfo = new StatusInfo();
1670  20 statusInfo.setSuccess(true);
1671   
1672  20 return statusInfo;
1673    }
1674   
 
1675  79 toggle @Override
1676    public List<ValidationResultInfo> validateCluPublication(
1677    String validationType, CluPublicationInfo cluPublicationInfo)
1678    throws DoesNotExistException, InvalidParameterException,
1679    MissingParameterException, OperationFailedException {
1680   
1681  79 checkForMissingParameter(validationType, "validationType");
1682  79 checkForMissingParameter(cluPublicationInfo, "cluPublicationInfo");
1683   
1684  79 ObjectStructureDefinition objStructure = this.getObjectStructure(CluPublicationInfo.class.getName());
1685  79 Validator defaultValidator = validatorFactory.getValidator();
1686  79 List<ValidationResultInfo> validationResults = defaultValidator.validateObject(cluPublicationInfo, objStructure);
1687  79 return validationResults;
1688    }
1689   
 
1690  58 toggle @Override
1691    public CluPublicationInfo createCluPublication(String cluId,
1692    String luPublicationType, CluPublicationInfo cluPublicationInfo)
1693    throws AlreadyExistsException, DataValidationErrorException,
1694    InvalidParameterException, MissingParameterException,
1695    OperationFailedException, PermissionDeniedException {
1696  58 checkForMissingParameter(cluId, "cluId");
1697  58 checkForMissingParameter(luPublicationType, "luPublicationType");
1698  58 checkForMissingParameter(cluPublicationInfo, "cluPublicationInfo");
1699   
1700    // Validate CLU
1701  58 List<ValidationResultInfo> val;
1702  58 try {
1703  58 val = validateCluPublication("SYSTEM", cluPublicationInfo);
1704  58 if(null != val && val.size() > 0) {
1705  0 throw new DataValidationErrorException("Validation error!", val);
1706    }
1707    } catch (DoesNotExistException e) {
1708  0 throw new OperationFailedException("Error creating clu",e);
1709    }
1710   
1711   
1712  58 CluPublication cluPub = new CluPublication();
1713  58 Clu clu;
1714  58 try {
1715  58 clu = luDao.fetch(Clu.class, cluId);
1716    } catch (DoesNotExistException e) {
1717  0 throw new InvalidParameterException("Clu does not exist for id:"+cluId);
1718    }
1719   
1720  58 CluPublicationType type;
1721  58 try{
1722  58 type = luDao.fetch(CluPublicationType.class, luPublicationType);
1723    } catch (DoesNotExistException e) {
1724  0 throw new InvalidParameterException("CluPublication Type does not exist for id:" + luPublicationType);
1725    }
1726   
1727  58 cluPub.setClu(clu);
1728  58 cluPub.setId(cluPublicationInfo.getId());
1729  58 cluPub.setEndCycle(cluPublicationInfo.getEndCycle());
1730  58 cluPub.setStartCycle(cluPublicationInfo.getStartCycle());
1731  58 cluPub.setEffectiveDate(cluPublicationInfo.getEffectiveDate());
1732  58 cluPub.setExpirationDate(cluPublicationInfo.getExpirationDate());
1733  58 cluPub.setState(cluPublicationInfo.getState());
1734  58 cluPub.setType(type);
1735  58 cluPub.setAttributes(LuServiceAssembler.toGenericAttributes(CluPublicationAttribute.class, cluPublicationInfo.getAttributes(), cluPub, luDao));
1736  58 cluPub.setVariants(LuServiceAssembler.toCluPublicationVariants(cluPublicationInfo.getVariants(), cluPub, luDao));
1737   
1738  58 luDao.create(cluPub);
1739   
1740  58 return LuServiceAssembler.toCluPublicationInfo(cluPub);
1741    }
1742   
 
1743  21 toggle @Override
1744    public CluPublicationInfo updateCluPublication(String cluPublicationId,
1745    CluPublicationInfo cluPublicationInfo)
1746    throws DataValidationErrorException, DoesNotExistException,
1747    InvalidParameterException, MissingParameterException,
1748    OperationFailedException, PermissionDeniedException,
1749    VersionMismatchException {
1750  21 checkForMissingParameter(cluPublicationId, "cluPublicationId");
1751  21 checkForMissingParameter(cluPublicationInfo, "cluPublicationInfo");
1752   
1753    // Validate CLU
1754  21 List<ValidationResultInfo> val;
1755  21 try {
1756  21 val = validateCluPublication("SYSTEM", cluPublicationInfo);
1757  21 if(null != val && val.size() > 0) {
1758  0 throw new DataValidationErrorException("Validation error!", val);
1759    }
1760    } catch (DoesNotExistException e) {
1761  0 throw new OperationFailedException("Error creating clu",e);
1762    }
1763   
1764  21 CluPublication cluPub = luDao.fetch(CluPublication.class, cluPublicationId);
1765   
1766  21 if (!String.valueOf(cluPub.getVersionNumber()).equals(
1767    cluPublicationInfo.getMetaInfo().getVersionInd())) {
1768  1 throw new VersionMismatchException(
1769    "CluPublication to be updated is not the current version");
1770    }
1771   
1772  20 Clu clu;
1773  20 try {
1774  20 clu = luDao.fetch(Clu.class, cluPublicationInfo.getCluId());
1775    } catch (DoesNotExistException e) {
1776  0 throw new InvalidParameterException("Clu does not exist for id:"+cluPublicationInfo.getCluId());
1777    }
1778   
1779  20 CluPublicationType type;
1780  20 try{
1781  20 type = luDao.fetch(CluPublicationType.class, cluPublicationInfo.getType());
1782    } catch (DoesNotExistException e) {
1783  0 throw new InvalidParameterException("CluPublication Type does not exist for id:" + cluPublicationInfo.getType());
1784    }
1785   
1786    // Update the list of variants
1787    // Get a map of Id->object of all the currently persisted objects in the
1788    // list
1789  20 Map<String, CluPublicationVariant> oldVariantMap = new HashMap<String, CluPublicationVariant>();
1790  20 for (CluPublicationVariant variant : cluPub.getVariants()) {
1791  21 oldVariantMap.put(variant.getKey(), variant);
1792    }
1793  20 cluPub.getVariants().clear();
1794   
1795    // Loop through the new list, if the item exists already update and
1796    // remove from the list otherwise create a new entry
1797  20 CluPublicationVariant variant = null;
1798  20 for (FieldInfo fieldInfo : cluPublicationInfo.getVariants()) {
1799  21 if (!oldVariantMap.containsKey(fieldInfo.getId())) {
1800    // New variant key
1801  2 variant = new CluPublicationVariant();
1802  2 variant.setKey(fieldInfo.getId());
1803  2 variant.setValue(fieldInfo.getValue());
1804    } else {
1805    // Update existing variant
1806  19 variant = oldVariantMap.get(fieldInfo.getId());
1807  19 variant.setValue(fieldInfo.getValue());
1808  19 oldVariantMap.remove(fieldInfo.getId());
1809    }
1810   
1811  21 cluPub.getVariants().add(variant);
1812    }
1813   
1814    // Now delete anything left over
1815  20 for (Entry<String, CluPublicationVariant> entry : oldVariantMap.entrySet()) {
1816  2 luDao.delete(entry.getValue());
1817    }
1818   
1819  20 cluPub.setClu(clu);
1820  20 cluPub.setEndCycle(cluPublicationInfo.getEndCycle());
1821  20 cluPub.setStartCycle(cluPublicationInfo.getStartCycle());
1822  20 cluPub.setEffectiveDate(cluPublicationInfo.getEffectiveDate());
1823  20 cluPub.setExpirationDate(cluPublicationInfo.getExpirationDate());
1824  20 cluPub.setState(cluPublicationInfo.getState());
1825  20 cluPub.setType(type);
1826  20 cluPub.setAttributes(LuServiceAssembler.toGenericAttributes(CluPublicationAttribute.class, cluPublicationInfo.getAttributes(), cluPub, luDao));
1827   
1828  20 CluPublication updated = luDao.update(cluPub);
1829   
1830  20 return LuServiceAssembler.toCluPublicationInfo(updated);
1831    }
1832   
 
1833  0 toggle @Override
1834    public StatusInfo deleteCluPublication(String cluPublicationId)
1835    throws DoesNotExistException, InvalidParameterException,
1836    MissingParameterException, DependentObjectsExistException,
1837    OperationFailedException, PermissionDeniedException {
1838  0 checkForMissingParameter(cluPublicationId, "cluPublicationId");
1839   
1840  0 luDao.delete(CluPublication.class, cluPublicationId);
1841   
1842  0 StatusInfo statusInfo = new StatusInfo();
1843  0 statusInfo.setSuccess(true);
1844   
1845  0 return statusInfo; }
1846   
 
1847  107 toggle @Override
1848    public List<ValidationResultInfo> validateCluResult(String validationType,
1849    CluResultInfo cluResultInfo) throws DoesNotExistException,
1850    InvalidParameterException, MissingParameterException,
1851    OperationFailedException {
1852  107 checkForMissingParameter(validationType, "validationType");
1853  107 checkForMissingParameter(cluResultInfo, "cluResultInfo");
1854   
1855  107 ObjectStructureDefinition objStructure = this.getObjectStructure(CluResultInfo.class.getName());
1856  107 Validator defaultValidator = validatorFactory.getValidator();
1857  107 List<ValidationResultInfo> validationResults = defaultValidator.validateObject(cluResultInfo, objStructure);
1858  107 return validationResults;
1859    }
1860   
 
1861  86 toggle @Override
1862    public CluResultInfo createCluResult(String cluId, String cluResultTypeKey,
1863    CluResultInfo cluResultInfo) throws AlreadyExistsException,
1864    DataValidationErrorException, InvalidParameterException,
1865    MissingParameterException, OperationFailedException,
1866    PermissionDeniedException, DoesNotExistException {
1867   
1868  86 checkForMissingParameter(cluId, "cluId");
1869  86 checkForMissingParameter(cluResultTypeKey, "cluResultTypeKey");
1870  86 checkForMissingParameter(cluResultInfo, "cluResultInfo");
1871   
1872    // Validate CluResult
1873  86 List<ValidationResultInfo> val = validateCluResult("SYSTEM", cluResultInfo);
1874  86 if(null != val && val.size() > 0) {
1875  0 throw new DataValidationErrorException("Validation error!", val);
1876    }
1877   
1878  86 cluResultInfo.setType(cluResultTypeKey);
1879  86 cluResultInfo.setCluId(cluId);
1880   
1881  86 List<ResultOption> resOptList = new ArrayList<ResultOption>();
1882  86 for (ResultOptionInfo resOptInfo : cluResultInfo.getResultOptions()) {
1883  121 ResultOption resOpt = new ResultOption();
1884  121 BeanUtils.copyProperties(resOptInfo, resOpt, new String[] { "id",
1885    "metaInfo", "resultUsageType", "desc" });
1886   
1887  121 if(resOptInfo.getResultUsageTypeKey() != null) {
1888  0 ResultUsageType resUsageType = luDao.fetch(ResultUsageType.class,
1889    resOptInfo.getResultUsageTypeKey());
1890  0 resOpt.setResultUsageType(resUsageType);
1891    }
1892  121 resOpt.setDesc(LuServiceAssembler.toRichText(LuRichText.class, resOptInfo.getDesc()));
1893  121 luDao.create(resOpt);
1894  121 resOptList.add(resOpt);
1895    }
1896   
1897  86 CluResult cluResult = new CluResult();
1898  86 BeanUtils.copyProperties(cluResultInfo, cluResult, new String[] { "id",
1899    "desc", "resultOptions", "metaInfo" });
1900   
1901  86 cluResult.setDesc(LuServiceAssembler
1902    .toRichText(LuRichText.class, cluResultInfo.getDesc()));
1903  86 cluResult.setResultOptions(resOptList);
1904   
1905  86 Clu clu = luDao.fetch(Clu.class, cluId);
1906  86 cluResult.setClu(clu);
1907   
1908  86 CluResultType type = luDao.fetch(CluResultType.class, cluResultTypeKey);
1909  86 cluResult.setCluResultType(type);
1910   
1911  86 luDao.create(cluResult);
1912   
1913  86 return LuServiceAssembler.toCluResultInfo(cluResult);
1914    }
1915   
 
1916  21 toggle @Override
1917    public CluResultInfo updateCluResult(String cluResultId,
1918    CluResultInfo cluResultInfo) throws DataValidationErrorException,
1919    DoesNotExistException, InvalidParameterException,
1920    MissingParameterException, OperationFailedException,
1921    PermissionDeniedException, VersionMismatchException {
1922   
1923  21 checkForMissingParameter(cluResultId, "cluResultId");
1924  21 checkForMissingParameter(cluResultInfo, "cluResultInfo");
1925   
1926    // Validate CluResult
1927  21 List<ValidationResultInfo> val = validateCluResult("SYSTEM", cluResultInfo);
1928  21 if(null != val && val.size() > 0) {
1929  0 throw new DataValidationErrorException("Validation error!", val);
1930    }
1931   
1932  21 CluResult result = luDao.fetch(CluResult.class, cluResultId);
1933  21 if (!String.valueOf(result.getVersionNumber()).equals(
1934    cluResultInfo.getMetaInfo().getVersionInd())) {
1935  0 throw new VersionMismatchException(
1936    "CluResult to be updated is not the current version");
1937    }
1938   
1939    // Update the list of resultoptions
1940    // Get a map of Id->object of all the currently persisted objects in the
1941    // list
1942  21 Map<String, ResultOption> oldResultOptionMap = new HashMap<String, ResultOption>();
1943  21 for (ResultOption opt : result.getResultOptions()) {
1944  28 oldResultOptionMap.put(opt.getId(), opt);
1945    }
1946  21 result.getResultOptions().clear();
1947   
1948    // Loop through the new list, if the item exists already update and
1949    // remove from the list otherwise create a new entry
1950  21 for (ResultOptionInfo resOptInfo : cluResultInfo.getResultOptions()) {
1951  27 ResultOption opt = oldResultOptionMap.remove(resOptInfo.getId());
1952  27 if (opt == null) {
1953    // New result option
1954  1 opt = new ResultOption();
1955    // Copy properties
1956  1 BeanUtils.copyProperties(resOptInfo, opt, new String[] {
1957    "resultUsageType", "desc" });
1958    } else {
1959    // Get existing result option
1960  26 opt = luDao.fetch(ResultOption.class, resOptInfo.getId());
1961    // Copy properties
1962  26 BeanUtils.copyProperties(resOptInfo, opt, new String[] {
1963    "id", "resultUsageType", "desc" });
1964    }
1965  27 if(resOptInfo.getResultUsageTypeKey() != null && !resOptInfo.getResultUsageTypeKey().isEmpty()) {
1966  1 ResultUsageType resUsageType = luDao.fetch(ResultUsageType.class,
1967    resOptInfo.getResultUsageTypeKey());
1968  1 opt.setResultUsageType(resUsageType);
1969    }
1970  27 opt.setDesc(LuServiceAssembler.toRichText(LuRichText.class, resOptInfo.getDesc()));
1971  27 result.getResultOptions().add(opt);
1972    }
1973   
1974    // Now delete anything left over
1975  21 for (Entry<String, ResultOption> entry : oldResultOptionMap.entrySet()) {
1976  2 luDao.delete(entry.getValue());
1977    }
1978   
1979  21 BeanUtils.copyProperties(cluResultInfo, result, new String[] { "id",
1980    "desc", "resultOptions" });
1981   
1982  21 result.setDesc(LuServiceAssembler.toRichText(LuRichText.class, cluResultInfo.getDesc()));
1983  21 CluResultType type = luDao.fetch(CluResultType.class, cluResultInfo.getType());
1984  21 result.setCluResultType(type);
1985   
1986  21 CluResult updated = luDao.update(result);
1987   
1988  21 return LuServiceAssembler.toCluResultInfo(updated);
1989    }
1990   
 
1991  4 toggle @Override
1992    public StatusInfo deleteCluResult(String cluResultId)
1993    throws DoesNotExistException, InvalidParameterException,
1994    MissingParameterException, DependentObjectsExistException,
1995    OperationFailedException, PermissionDeniedException {
1996   
1997  4 checkForMissingParameter(cluResultId, "cluResultId");
1998   
1999  4 luDao.delete(CluResult.class, cluResultId);
2000   
2001  4 StatusInfo statusInfo = new StatusInfo();
2002  4 statusInfo.setSuccess(true);
2003   
2004  4 return statusInfo;
2005    }
2006   
 
2007  102 toggle @Override
2008    public List<ValidationResultInfo> validateCluLoRelation(
2009    String validationType, CluLoRelationInfo cluLoRelationInfo)
2010    throws DoesNotExistException, InvalidParameterException,
2011    MissingParameterException, OperationFailedException {
2012   
2013  102 checkForMissingParameter(validationType, "validationType");
2014  102 checkForMissingParameter(cluLoRelationInfo, "cluLoRelationInfo");
2015   
2016  102 ObjectStructureDefinition objStructure = this.getObjectStructure(CluLoRelation.class.getName());
2017  102 Validator defaultValidator = validatorFactory.getValidator();
2018  102 List<ValidationResultInfo> validationResults = defaultValidator.validateObject(cluLoRelationInfo, objStructure);
2019  102 return validationResults;
2020    }
2021   
 
2022  101 toggle @Override
2023    public CluLoRelationInfo createCluLoRelation(String cluId, String loId,
2024    String cluLoRelationType, CluLoRelationInfo cluLoRelationInfo)
2025    throws AlreadyExistsException, DoesNotExistException,
2026    InvalidParameterException, MissingParameterException,
2027    OperationFailedException, PermissionDeniedException, DataValidationErrorException {
2028  101 checkForMissingParameter(loId, "loId");
2029  101 checkForMissingParameter(cluId, "cluId");
2030  101 checkForEmptyList(cluLoRelationType, "cluLoRelationType");
2031  101 checkForEmptyList(cluLoRelationInfo, "cluLoRelationInfo");
2032   
2033    // Validate CluLoRelation
2034  101 List<ValidationResultInfo> val = validateCluLoRelation("SYSTEM", cluLoRelationInfo);
2035  101 if(null != val && val.size() > 0) {
2036  0 throw new DataValidationErrorException("Validation error!", val);
2037    }
2038   
2039  101 Clu clu = luDao.fetch(Clu.class, cluId);
2040  100 if (clu == null) {
2041  0 throw new DoesNotExistException("Clu does not exist for id: "
2042    + cluId);
2043    }
2044   
2045  100 CluLoRelationType cluLoRelationTypeEntity = luDao.fetch(CluLoRelationType.class, cluLoRelationType);
2046  100 if (cluLoRelationTypeEntity == null) {
2047  0 throw new DoesNotExistException("CluLoRelationType does not exist for id: "
2048    + cluLoRelationType);
2049    }
2050   
2051    // Check to see if this relation already exists
2052  100 List<CluLoRelation> reltns = luDao.getCluLoRelationsByCludIdAndLoId(
2053    cluId, loId);
2054  100 if (reltns.size() > 0) {
2055  1 throw new AlreadyExistsException(
2056    "Relation already exists for cluId:" + cluId + " and Lo:"
2057    + loId);
2058    }
2059   
2060  99 CluLoRelation cluLoRelation = new CluLoRelation();
2061  99 BeanUtils.copyProperties(cluLoRelationInfo, cluLoRelation,
2062    new String[] { "cluId", "attributes", "metaInfo", "type" });
2063   
2064  99 cluLoRelation.setClu(clu);
2065  99 cluLoRelation.setAttributes(LuServiceAssembler.toGenericAttributes(
2066    CluLoRelationAttribute.class,
2067    cluLoRelationInfo.getAttributes(), cluLoRelation, luDao));
2068  99 cluLoRelation.setType(cluLoRelationTypeEntity);
2069   
2070  99 luDao.create(cluLoRelation);
2071   
2072  99 return LuServiceAssembler.toCluLoRelationInfo(cluLoRelation);
2073    }
2074   
 
2075  1 toggle @Override
2076    public CluLoRelationInfo updateCluLoRelation(String cluLoRelationId,
2077    CluLoRelationInfo cluLoRelationInfo)
2078    throws DataValidationErrorException, DoesNotExistException,
2079    InvalidParameterException, MissingParameterException,
2080    OperationFailedException, PermissionDeniedException,
2081    VersionMismatchException {
2082  1 checkForMissingParameter(cluLoRelationId, "cluLoRelationId");
2083  1 checkForMissingParameter(cluLoRelationInfo, "cluLoRelationInfo");
2084   
2085    // Validate CluLoRelation
2086  1 List<ValidationResultInfo> val = validateCluLoRelation("SYSTEM", cluLoRelationInfo);
2087  1 if(null != val && val.size() > 0) {
2088  0 throw new DataValidationErrorException("Validation error!", val);
2089    }
2090   
2091  1 CluLoRelation reltn = luDao.fetch(CluLoRelation.class, cluLoRelationId);
2092   
2093  1 if (!String.valueOf(reltn.getVersionNumber()).equals(
2094    cluLoRelationInfo.getMetaInfo().getVersionInd())) {
2095  0 throw new VersionMismatchException(
2096    "CluLoRelation to be updated is not the current version");
2097    }
2098   
2099  1 Clu clu = luDao.fetch(Clu.class, cluLoRelationInfo.getCluId());
2100  1 if (clu == null) {
2101  0 throw new DoesNotExistException("Clu does not exist for id: "
2102    + cluLoRelationInfo.getCluId());
2103    }
2104   
2105  1 CluLoRelationType cluLoRelationTypeEntity = luDao.fetch(CluLoRelationType.class, cluLoRelationInfo.getType());
2106  1 if (cluLoRelationTypeEntity == null) {
2107  0 throw new DoesNotExistException("CluLoRelationType does not exist for id: "
2108    + cluLoRelationInfo.getType());
2109    }
2110   
2111  1 BeanUtils.copyProperties(cluLoRelationInfo, reltn, new String[] {
2112    "cluId", "attributes", "metaInfo", "type"});
2113   
2114  1 reltn.setClu(clu);
2115  1 reltn.setAttributes(LuServiceAssembler.toGenericAttributes(
2116    CluLoRelationAttribute.class,
2117    cluLoRelationInfo.getAttributes(), reltn, luDao));
2118  1 reltn.setType(cluLoRelationTypeEntity);
2119  1 CluLoRelation updated = luDao.update(reltn);
2120   
2121  1 return LuServiceAssembler.toCluLoRelationInfo(updated);
2122    }
2123   
 
2124  7 toggle @Override
2125    public StatusInfo deleteCluLoRelation(String cluLoRelationId)
2126    throws DoesNotExistException, InvalidParameterException,
2127    MissingParameterException, OperationFailedException,
2128    PermissionDeniedException {
2129  7 checkForMissingParameter(cluLoRelationId, "cluLoRelationId");
2130   
2131  7 CluLoRelation reltn = luDao.fetch(CluLoRelation.class, cluLoRelationId);
2132  7 if (reltn == null) {
2133  0 throw new DoesNotExistException(
2134    "CluLoRelation does not exist for id: " + cluLoRelationId);
2135    }
2136   
2137  7 luDao.delete(CluLoRelation.class, cluLoRelationId);
2138   
2139  7 StatusInfo statusInfo = new StatusInfo();
2140  7 statusInfo.setSuccess(true);
2141   
2142  7 return statusInfo;
2143    }
2144   
 
2145  0 toggle @Override
2146    public StatusInfo addCluResourceRequirement(String resourceTypeKey,
2147    String cluId) throws AlreadyExistsException, DoesNotExistException,
2148    InvalidParameterException, MissingParameterException,
2149    OperationFailedException, PermissionDeniedException {
2150  0 throw new UnsupportedOperationException("Method not yet implemented!");
2151    }
2152   
 
2153  0 toggle @Override
2154    public StatusInfo removeCluResourceRequirement(String resourceTypeKey,
2155    String cluId) throws DoesNotExistException,
2156    InvalidParameterException, MissingParameterException,
2157    OperationFailedException, PermissionDeniedException {
2158    // TODO Auto-generated method stub
2159  0 return null;
2160    }
2161   
 
2162  46 toggle @Override
2163    public List<ValidationResultInfo> validateCluSet(String validationType,
2164    CluSetInfo cluSetInfo) throws DoesNotExistException,
2165    InvalidParameterException, MissingParameterException,
2166    OperationFailedException {
2167  46 checkForMissingParameter(validationType, "validationType");
2168  46 checkForMissingParameter(cluSetInfo, "cluSetInfo");
2169   
2170  46 ObjectStructureDefinition objStructure = this.getObjectStructure(CluSetInfo.class.getName());
2171  46 Validator defaultValidator = validatorFactory.getValidator();
2172  46 List<ValidationResultInfo> validationResults = defaultValidator.validateObject(cluSetInfo, objStructure);
2173  46 return validationResults;
2174    }
2175   
 
2176  39 toggle @Override
2177    public CluSetInfo createCluSet(String cluSetType, CluSetInfo cluSetInfo)
2178    throws AlreadyExistsException, DataValidationErrorException,
2179    InvalidParameterException, MissingParameterException,
2180    OperationFailedException, PermissionDeniedException,
2181    UnsupportedActionException {
2182   
2183  39 checkForMissingParameter(cluSetType, "cluSetType");
2184  39 checkForMissingParameter(cluSetInfo, "cluSetInfo");
2185   
2186  39 cluSetInfo.setType(cluSetType);
2187   
2188  39 validateCluSet(cluSetInfo);
2189   
2190    // Validate CluSet
2191  36 List<ValidationResultInfo> val;
2192  36 try {
2193  36 val = validateCluSet("SYSTEM", cluSetInfo);
2194    } catch (DoesNotExistException e) {
2195  0 throw new DataValidationErrorException("Validation error! " + e.getMessage());
2196    }
2197  36 if(null != val && val.size() > 0) {
2198  0 throw new DataValidationErrorException("Validation error!", val);
2199    }
2200   
2201  36 List<String> cluIdList = getMembershipQuerySearchResult(cluSetInfo.getMembershipQuery());
2202   
2203  36 CluSet cluSet = null;
2204  36 try {
2205  36 cluSet = LuServiceAssembler.toCluSetEntity(cluSetInfo, this.luDao);
2206    } catch (DoesNotExistException e) {
2207  0 throw new DataValidationErrorException("Creating CluSet entity failed. Clu or CluSet does not exist: " + e.getMessage());
2208    }
2209   
2210  36 cluSet = luDao.create(cluSet);
2211   
2212  36 CluSetInfo newCluSetInfo = LuServiceAssembler.toCluSetInfo(cluSet);
2213   
2214  36 if(cluIdList != null) {
2215  6 newCluSetInfo.getCluIds().addAll(cluIdList);
2216    }
2217   
2218  36 return newCluSetInfo;
2219    }
2220   
 
2221  122 toggle private void setMembershipQuerySearchResult(CluSetInfo cluSetInfo) throws MissingParameterException {
2222  122 if(cluSetInfo.getMembershipQuery() == null) {
2223  117 return;
2224    }
2225  5 List<String> cluIds = getMembershipQuerySearchResult(cluSetInfo.getMembershipQuery());
2226  5 cluSetInfo.getCluIds().addAll(cluIds);
2227    }
2228   
 
2229  51 toggle private List<String> getMembershipQuerySearchResult(MembershipQueryInfo query) throws MissingParameterException {
2230  51 if(query == null) {
2231  39 return null;
2232    }
2233  12 SearchRequest sr = new SearchRequest();
2234  12 sr.setSearchKey(query.getSearchTypeKey());
2235  12 sr.setParams(query.getQueryParamValueList());
2236   
2237  12 SearchResult result = search(sr);
2238   
2239  12 Set<String> cluIds = new HashSet<String>();
2240  12 List<SearchResultRow> rows = result.getRows();
2241  12 for(SearchResultRow row : rows) {
2242  827 List<SearchResultCell> cells = row.getCells();
2243  827 for(SearchResultCell cell : cells) {
2244  2481 if(cell.getKey().equals("lu.resultColumn.luOptionalVersionIndId")&&cell.getValue()!=null) {
2245  799 cluIds.add(cell.getValue());
2246    }
2247    }
2248    }
2249  12 return new ArrayList<String>(cluIds);
2250    }
2251   
 
2252  49 toggle private void validateCluSet(CluSetInfo cluSetInfo) throws UnsupportedActionException {
2253  49 MembershipQueryInfo mqInfo = cluSetInfo.getMembershipQuery();
2254   
2255  49 if (cluSetInfo.getType() == null) {
2256  0 throw new UnsupportedActionException("CluSet type cannot be null. CluSet id="+cluSetInfo.getId());
2257    }
2258  49 else if(mqInfo != null && mqInfo.getSearchTypeKey() != null && !mqInfo.getSearchTypeKey().isEmpty() &&
2259    (cluSetInfo.getCluIds().size() > 0 || cluSetInfo.getCluSetIds().size() > 0)) {
2260  2 throw new UnsupportedActionException("Dynamic CluSet cannot contain Clus and/or CluSets. CluSet id="+cluSetInfo.getId());
2261    }
2262  47 else if (cluSetInfo.getCluIds().size() > 0 && cluSetInfo.getCluSetIds().size() > 0) {
2263  1 throw new UnsupportedActionException("CluSet cannot contain both Clus and CluSets. CluSet id="+cluSetInfo.getId());
2264    }
2265    }
2266   
 
2267  10 toggle @Override
2268    public CluSetInfo updateCluSet(String cluSetId, CluSetInfo cluSetInfo)
2269    throws DataValidationErrorException, DoesNotExistException,
2270    InvalidParameterException, MissingParameterException,
2271    OperationFailedException, PermissionDeniedException,
2272    VersionMismatchException, CircularRelationshipException,
2273    UnsupportedActionException {
2274   
2275    // Check Missing params
2276  10 checkForMissingParameter(cluSetId, "cluSetId");
2277  10 checkForMissingParameter(cluSetInfo, "cluSetInfo");
2278   
2279    // Validate CluSet
2280  10 List<ValidationResultInfo> val = validateCluSet("SYSTEM", cluSetInfo);
2281  10 if(null != val && val.size() > 0) {
2282  0 throw new DataValidationErrorException("Validation error!", val);
2283    }
2284   
2285  10 cluSetInfo.setId(cluSetId);
2286   
2287  10 validateCluSet(cluSetInfo);
2288   
2289  10 List<String> cluIdList = getMembershipQuerySearchResult(cluSetInfo.getMembershipQuery());
2290   
2291  10 CluSet cluSet = luDao.fetch(CluSet.class, cluSetId);
2292   
2293  10 if (!cluSetInfo.getType().equals(cluSet.getType())) {
2294  0 throw new UnsupportedActionException("CluSet type is set at creation time and cannot be updated. CluSet id="+cluSetId);
2295    }
2296   
2297  10 if (!String.valueOf(cluSet.getVersionNumber()).equals(
2298    cluSetInfo.getMetaInfo().getVersionInd())) {
2299  1 throw new VersionMismatchException(
2300    "CluSet (id=" + cluSetId +
2301    ") to be updated is not the current version " +
2302    "(version=" + cluSetInfo.getMetaInfo().getVersionInd() +
2303    "), current version="+cluSet.getVersionNumber());
2304    }
2305   
2306    // update the cluIds
2307  9 Map<String, CluSetJoinVersionIndClu> oldClus = new HashMap<String, CluSetJoinVersionIndClu>();
2308  9 for(CluSetJoinVersionIndClu join:cluSet.getCluVerIndIds()){
2309  8 oldClus.put(join.getCluVersionIndId(), join);
2310    }
2311   
2312  9 cluSet.getCluVerIndIds().clear();
2313    // Loop through the new list, if the item exists already update and remove from the list otherwise create a new entry
2314  9 for (String newCluId : cluSetInfo.getCluIds()) {
2315  6 CluSetJoinVersionIndClu join = oldClus.remove(newCluId);
2316  6 if (join == null) {
2317  2 join = new CluSetJoinVersionIndClu();
2318  2 join.setCluSet(cluSet);
2319  2 join.setCluVersionIndId(newCluId);
2320    }
2321  6 cluSet.getCluVerIndIds().add(join);
2322    }
2323   
2324    // Now delete anything left over
2325  9 for (Entry<String, CluSetJoinVersionIndClu> entry : oldClus.entrySet()) {
2326  4 luDao.delete(entry.getValue());
2327    }
2328   
2329    // clean up existing wrappers if any
2330  9 if (cluSetInfo.getId() != null) {
2331  9 CluSetInfo originalCluSet = getCluSetInfo(cluSetInfo.getId());
2332  9 List<CluSetInfo> origSubCSs = null;
2333  9 List<String> origSubCSIds = originalCluSet.getCluSetIds();
2334  9 if (origSubCSIds != null && !origSubCSIds.isEmpty()) {
2335  2 origSubCSs = getCluSetInfoByIdList(origSubCSIds);
2336    }
2337  9 if (origSubCSs != null) {
2338  2 for (CluSetInfo origSubCS : origSubCSs) {
2339  6 if (!origSubCS.getIsReusable()) {
2340  0 deleteCluSet(origSubCS.getId());
2341    }
2342    }
2343    }
2344    }
2345   
2346    // update the cluSetIds
2347  9 if(cluSet.getCluSets()==null){
2348  0 cluSet.setCluSets(new ArrayList<CluSet>());
2349    }
2350  9 cluSet.setCluSets(null);
2351  9 if(!cluSetInfo.getCluSetIds().isEmpty()) {
2352  3 Set<String> newCluSetIds = new HashSet<String>(cluSetInfo.getCluSetIds());
2353  3 if(cluSet.getCluSets()!=null){
2354  0 for (Iterator<CluSet> i = cluSet.getCluSets().iterator(); i.hasNext();) {
2355  0 if (!newCluSetIds.remove(i.next().getId())) {
2356  0 i.remove();
2357    }
2358    }
2359    }
2360  3 List<CluSet> cluSetList = luDao.getCluSetInfoByIdList(new ArrayList<String>(newCluSetIds));
2361  3 cluSet.setCluSets(cluSetList);
2362    }
2363   
2364  9 BeanUtils.copyProperties(cluSetInfo, cluSet, new String[] { "descr",
2365    "attributes", "metaInfo", "membershipQuery" });
2366  9 cluSet.setAttributes(LuServiceAssembler.toGenericAttributes(
2367    CluSetAttribute.class, cluSetInfo.getAttributes(), cluSet, luDao));
2368  9 cluSet.setDescr(LuServiceAssembler.toRichText(LuRichText.class, cluSetInfo.getDescr()));
2369   
2370  9 MembershipQuery mq = LuServiceAssembler.toMembershipQueryEntity(cluSetInfo.getMembershipQuery());
2371  9 cluSet.setMembershipQuery(mq);
2372   
2373  9 CluSet updated = luDao.update(cluSet);
2374   
2375  9 CluSetInfo updatedCluSetInfo = LuServiceAssembler.toCluSetInfo(updated);
2376   
2377  9 if(cluIdList != null) {
2378  1 updatedCluSetInfo.getCluIds().addAll(cluIdList);
2379    }
2380   
2381  9 return updatedCluSetInfo;
2382    }
2383   
 
2384  1 toggle @Override
2385    public StatusInfo deleteCluSet(String cluSetId)
2386    throws DoesNotExistException, InvalidParameterException,
2387    MissingParameterException, OperationFailedException,
2388    PermissionDeniedException {
2389   
2390  1 checkForMissingParameter(cluSetId, "cluSetId");
2391   
2392  1 luDao.delete(CluSet.class, cluSetId);
2393   
2394  1 StatusInfo statusInfo = new StatusInfo();
2395  1 statusInfo.setSuccess(true);
2396   
2397  1 return statusInfo;
2398    }
2399   
 
2400  27 toggle @Override
2401    public StatusInfo addCluSetToCluSet(String cluSetId, String addedCluSetId)
2402    throws DoesNotExistException, InvalidParameterException,
2403    MissingParameterException, OperationFailedException,
2404    PermissionDeniedException, UnsupportedActionException,
2405    CircularRelationshipException {
2406  27 checkForMissingParameter(cluSetId, "cluSetId");
2407  27 checkForMissingParameter(addedCluSetId, "addedCluSetId");
2408   
2409  27 CluSet cluSet = luDao.fetch(CluSet.class, cluSetId);
2410   
2411  27 checkCluSetAlreadyAdded(cluSet, addedCluSetId);
2412   
2413  25 CluSet addedCluSet = luDao.fetch(CluSet.class, addedCluSetId);
2414   
2415  23 checkCluSetCircularReference(addedCluSet, cluSetId);
2416   
2417  19 if(cluSet.getCluSets()==null){
2418  0 cluSet.setCluSets(new ArrayList<CluSet>());
2419    }
2420  19 cluSet.getCluSets().add(addedCluSet);
2421   
2422  19 luDao.update(cluSet);
2423   
2424  19 StatusInfo statusInfo = new StatusInfo();
2425  19 statusInfo.setSuccess(true);
2426   
2427  19 return statusInfo;
2428    }
2429   
 
2430  1 toggle @Override
2431    public StatusInfo removeCluSetFromCluSet(String cluSetId,
2432    String removedCluSetId) throws DoesNotExistException,
2433    InvalidParameterException, MissingParameterException,
2434    OperationFailedException, PermissionDeniedException,
2435    UnsupportedActionException {
2436   
2437  1 checkForMissingParameter(cluSetId, "cluSetId");
2438  1 checkForMissingParameter(removedCluSetId, "removedCluSetId");
2439   
2440  1 CluSet cluSet = luDao.fetch(CluSet.class, cluSetId);
2441  1 if(cluSet.getCluSets()!=null){
2442  2 for (Iterator<CluSet> i = cluSet.getCluSets().iterator(); i.hasNext();) {
2443  2 CluSet childCluSet = i.next();
2444  2 if (childCluSet.getId().equals(removedCluSetId)) {
2445  1 i.remove();
2446  1 luDao.update(cluSet);
2447  1 StatusInfo statusInfo = new StatusInfo();
2448  1 statusInfo.setSuccess(true);
2449   
2450  1 return statusInfo;
2451    }
2452    }
2453    }
2454   
2455  0 StatusInfo statusInfo = new StatusInfo();
2456  0 statusInfo.setSuccess(false);
2457  0 statusInfo.setMessage("CluSet does not contain CluSet:"
2458    + removedCluSetId);
2459   
2460  0 return statusInfo;
2461    }
2462   
 
2463  14 toggle @Override
2464    public StatusInfo addCluToCluSet(String cluId, String cluSetId)
2465    throws DoesNotExistException, InvalidParameterException,
2466    MissingParameterException, OperationFailedException,
2467    PermissionDeniedException, UnsupportedActionException {
2468   
2469  14 checkForMissingParameter(cluId, "cluId");
2470  14 checkForMissingParameter(cluSetId, "cluSetId");
2471   
2472  14 CluSet cluSet = luDao.fetch(CluSet.class, cluSetId);
2473   
2474  13 checkCluAlreadyAdded(cluSet, cluId);
2475   
2476  11 try{
2477  11 luDao.getCurrentCluVersionInfo(cluId, LuServiceConstants.CLU_NAMESPACE_URI);
2478    }catch(NoResultException e){
2479  1 throw new DoesNotExistException();
2480    }
2481   
2482  10 CluSetJoinVersionIndClu join = new CluSetJoinVersionIndClu();
2483  10 join.setCluSet(cluSet);
2484  10 join.setCluVersionIndId(cluId);
2485   
2486  10 cluSet.getCluVerIndIds().add(join);
2487   
2488  10 luDao.update(cluSet);
2489   
2490  10 StatusInfo statusInfo = new StatusInfo();
2491  10 statusInfo.setSuccess(true);
2492   
2493  10 return statusInfo;
2494    }
2495   
 
2496  1 toggle @Override
2497    public StatusInfo removeCluFromCluSet(String cluId, String cluSetId)
2498    throws DoesNotExistException, InvalidParameterException,
2499    MissingParameterException, OperationFailedException,
2500    PermissionDeniedException, UnsupportedActionException {
2501   
2502  1 checkForMissingParameter(cluId, "cluId");
2503  1 checkForMissingParameter(cluSetId, "cluSetId");
2504   
2505  1 CluSet cluSet = luDao.fetch(CluSet.class, cluSetId);
2506   
2507  2 for (Iterator<CluSetJoinVersionIndClu> i = cluSet.getCluVerIndIds().iterator(); i.hasNext();) {
2508  2 CluSetJoinVersionIndClu join = i.next();
2509  2 if (join.getCluVersionIndId().equals(cluId)) {
2510  1 i.remove();
2511  1 luDao.delete(join);
2512  1 luDao.update(cluSet);
2513  1 StatusInfo statusInfo = new StatusInfo();
2514  1 statusInfo.setSuccess(true);
2515   
2516  1 return statusInfo;
2517    }
2518    }
2519   
2520  0 StatusInfo statusInfo = new StatusInfo();
2521  0 statusInfo.setSuccess(false);
2522  0 statusInfo.setMessage("Clu set does not contain Clu:" + cluId);
2523   
2524  0 return statusInfo;
2525    }
2526   
 
2527  4 toggle @Override
2528    public List<ValidationResultInfo> validateLui(String validationType,
2529    LuiInfo luiInfo) throws DoesNotExistException,
2530    InvalidParameterException, MissingParameterException,
2531    OperationFailedException {
2532  4 checkForMissingParameter(validationType, "validationType");
2533  4 checkForMissingParameter(luiInfo, "luiInfo");
2534   
2535  4 ObjectStructureDefinition objStructure = this.getObjectStructure(LuiInfo.class.getName());
2536  4 Validator defaultValidator = validatorFactory.getValidator();
2537  4 List<ValidationResultInfo> validationResults = defaultValidator.validateObject(luiInfo, objStructure);
2538  4 return validationResults;
2539    }
2540   
 
2541  2 toggle @Override
2542    public LuiInfo createLui(String cluId, String atpKey, LuiInfo luiInfo)
2543    throws AlreadyExistsException, DataValidationErrorException,
2544    DoesNotExistException, InvalidParameterException,
2545    MissingParameterException, OperationFailedException,
2546    PermissionDeniedException {
2547  2 checkForMissingParameter(cluId, "cludId");
2548  2 checkForMissingParameter(atpKey, "atpKey");
2549  2 checkForMissingParameter(luiInfo, "luiInfo");
2550   
2551    // Validate Lui
2552  2 List<ValidationResultInfo> val = validateLui("SYSTEM", luiInfo);
2553  2 if(null != val && val.size() > 0) {
2554  0 throw new DataValidationErrorException("Validation error!", val);
2555    }
2556   
2557  2 Lui lui = new Lui();
2558  2 luiInfo.setCluId(cluId);
2559  2 luiInfo.setAtpId(atpKey);
2560   
2561  2 try {
2562  2 lui = LuServiceAssembler.toLui(false, luiInfo, luDao);
2563    } catch (VersionMismatchException vme) {
2564    }
2565   
2566  2 luDao.create(lui);
2567   
2568  2 return LuServiceAssembler.toLuiInfo(lui);
2569    }
2570   
 
2571  2 toggle @Override
2572    public LuiInfo updateLui(String luiId, LuiInfo luiInfo)
2573    throws DataValidationErrorException, DoesNotExistException,
2574    InvalidParameterException, MissingParameterException,
2575    OperationFailedException, PermissionDeniedException,
2576    VersionMismatchException {
2577   
2578  2 checkForMissingParameter(luiId, "luiId");
2579  2 checkForMissingParameter(luiInfo, "luiInfo");
2580   
2581    // Validate Lui
2582  2 List<ValidationResultInfo> val = validateLui("SYSTEM", luiInfo);
2583  2 if(null != val && val.size() > 0) {
2584  0 throw new DataValidationErrorException("Validation error!", val);
2585    }
2586   
2587  2 Lui lui = luDao.fetch(Lui.class, luiId);
2588   
2589  2 if (!String.valueOf(lui.getVersionNumber()).equals(
2590    luiInfo.getMetaInfo().getVersionInd())) {
2591  1 throw new VersionMismatchException(
2592    "Lui to be updated is not the current version");
2593    }
2594   
2595  1 Clu clu = luDao.fetch(Clu.class, luiInfo.getCluId());
2596  1 lui.setClu(clu);
2597   
2598  1 lui.setAttributes(LuServiceAssembler.toGenericAttributes(
2599    LuiAttribute.class, luiInfo.getAttributes(), lui, luDao));
2600   
2601    // Now copy standard properties
2602  1 BeanUtils.copyProperties(luiInfo, lui, new String[] { "cluId",
2603    "attributes" });
2604   
2605  1 Lui updated = luDao.update(lui);
2606   
2607  1 return LuServiceAssembler.toLuiInfo(updated);
2608    }
2609   
 
2610  3 toggle @Override
2611    public StatusInfo deleteLui(String luiId)
2612    throws DependentObjectsExistException, DoesNotExistException,
2613    InvalidParameterException, MissingParameterException,
2614    OperationFailedException, PermissionDeniedException {
2615   
2616  3 checkForMissingParameter(luiId, "luiId");
2617   
2618  3 luDao.delete(Lui.class, luiId);
2619   
2620  2 StatusInfo statusInfo = new StatusInfo();
2621  2 statusInfo.setSuccess(true);
2622   
2623  2 return statusInfo;
2624    }
2625   
 
2626  3 toggle @Override
2627    public LuiInfo updateLuiState(String luiId, String luiState)
2628    throws DataValidationErrorException, DoesNotExistException,
2629    InvalidParameterException, MissingParameterException,
2630    OperationFailedException, PermissionDeniedException {
2631   
2632    // check for missing params
2633  3 checkForMissingParameter(luiId, "luiId");
2634  2 checkForMissingParameter(luiState, "luiState");
2635  1 Lui lui = luDao.fetch(Lui.class, luiId);
2636  1 lui.setState(luiState);
2637  1 Lui updated = luDao.update(lui);
2638  1 return LuServiceAssembler.toLuiInfo(updated);
2639    }
2640   
 
2641  3 toggle @Override
2642    public List<ValidationResultInfo> validateLuiLuiRelation(
2643    String validationType, LuiLuiRelationInfo luiLuiRelationInfo)
2644    throws DoesNotExistException, InvalidParameterException,
2645    MissingParameterException, OperationFailedException {
2646  3 checkForMissingParameter(validationType, "validationType");
2647  3 checkForMissingParameter(luiLuiRelationInfo, "luiLuiRelationInfo");
2648   
2649  3 ObjectStructureDefinition objStructure = this.getObjectStructure(LuiLuiRelation.class.getName());
2650  3 Validator defaultValidator = validatorFactory.getValidator();
2651  3 List<ValidationResultInfo> validationResults = defaultValidator.validateObject(luiLuiRelationInfo, objStructure);
2652  3 return validationResults;
2653    }
2654   
 
2655  1 toggle @Override
2656    public LuiLuiRelationInfo createLuiLuiRelation(String luiId,
2657    String relatedLuiId, String luLuRelationTypeKey,
2658    LuiLuiRelationInfo luiLuiRelationInfo)
2659    throws AlreadyExistsException, CircularRelationshipException,
2660    DataValidationErrorException, DoesNotExistException,
2661    InvalidParameterException, MissingParameterException,
2662    OperationFailedException, PermissionDeniedException {
2663  1 checkForMissingParameter(luiId, "luiId");
2664  1 checkForMissingParameter(relatedLuiId, "relatedLuiId");
2665  1 checkForMissingParameter(luLuRelationTypeKey, "luLuRelationTypeKey");
2666  1 checkForMissingParameter(luiLuiRelationInfo, "luiLuiRelationInfo");
2667   
2668    // Validate LuiLuiRelation
2669  1 List<ValidationResultInfo> val = validateLuiLuiRelation("SYSTEM", luiLuiRelationInfo);
2670  1 if(null != val && val.size() > 0) {
2671  0 throw new DataValidationErrorException("Validation error!", val);
2672    }
2673   
2674  1 if (luiId.equals(relatedLuiId)) {
2675  0 throw new CircularRelationshipException(
2676    "Can not relate a Lui to itself");
2677    }
2678   
2679  1 Lui lui = luDao.fetch(Lui.class, luiId);
2680  1 Lui relatedLui = luDao.fetch(Lui.class, relatedLuiId);
2681   
2682  1 LuiLuiRelation luiLuiRelation = new LuiLuiRelation();
2683  1 BeanUtils.copyProperties(luiLuiRelationInfo, luiLuiRelation,
2684    new String[] { "luiId", "relatedLuiId", "attributes",
2685    "metaInfo" });
2686   
2687  1 luiLuiRelation.setLui(lui);
2688  1 luiLuiRelation.setRelatedLui(relatedLui);
2689  1 luiLuiRelation.setAttributes(LuServiceAssembler.toGenericAttributes(
2690    LuiLuiRelationAttribute.class, luiLuiRelationInfo
2691    .getAttributes(), luiLuiRelation, luDao));
2692   
2693  1 LuLuRelationType luLuRelationType = luDao.fetch(LuLuRelationType.class,
2694    luLuRelationTypeKey);
2695   
2696  1 luiLuiRelation.setLuLuRelationType(luLuRelationType);
2697   
2698  1 luDao.create(luiLuiRelation);
2699   
2700  1 return LuServiceAssembler.toLuiLuiRelationInfo(luiLuiRelation);
2701    }
2702   
 
2703  2 toggle @Override
2704    public LuiLuiRelationInfo updateLuiLuiRelation(String luiLuiRelationId,
2705    LuiLuiRelationInfo luiLuiRelationInfo)
2706    throws DataValidationErrorException, DoesNotExistException,
2707    InvalidParameterException, MissingParameterException,
2708    OperationFailedException, PermissionDeniedException,
2709    VersionMismatchException {
2710   
2711  2 checkForMissingParameter(luiLuiRelationId, "luiLuiRelationId");
2712  2 checkForMissingParameter(luiLuiRelationInfo, "luiLuiRelationInfo");
2713   
2714    // Validate LuiLuiRelation
2715  2 List<ValidationResultInfo> val = validateLuiLuiRelation("SYSTEM", luiLuiRelationInfo);
2716  2 if(null != val && val.size() > 0) {
2717  0 throw new DataValidationErrorException("Validation error!", val);
2718    }
2719   
2720  2 LuiLuiRelation luiLuiRelation = luDao.fetch(LuiLuiRelation.class,
2721    luiLuiRelationId);
2722   
2723  2 if (!String.valueOf(luiLuiRelation.getVersionNumber()).equals(
2724    luiLuiRelationInfo.getMetaInfo().getVersionInd())) {
2725  1 throw new VersionMismatchException(
2726    "LuiLuiRelation to be updated is not the current version");
2727    }
2728   
2729  1 BeanUtils.copyProperties(luiLuiRelationInfo, luiLuiRelation,
2730    new String[] { "luiId", "relatedLuiId", "attributes",
2731    "metaInfo" });
2732   
2733  1 if (!luiLuiRelationInfo.getLuiId().equals(
2734    luiLuiRelation.getLui().getId())) {
2735  1 luiLuiRelation.setLui(luDao.fetch(Lui.class, luiLuiRelationInfo
2736    .getLuiId()));
2737    }
2738   
2739  1 if (!luiLuiRelationInfo.getRelatedLuiId().equals(
2740    luiLuiRelation.getRelatedLui().getId())) {
2741  1 luiLuiRelation.setRelatedLui(luDao.fetch(Lui.class,
2742    luiLuiRelationInfo.getRelatedLuiId()));
2743    }
2744   
2745  1 luiLuiRelation.setAttributes(LuServiceAssembler.toGenericAttributes(
2746    LuiLuiRelationAttribute.class, luiLuiRelationInfo
2747    .getAttributes(), luiLuiRelation, luDao));
2748   
2749  1 if (!luiLuiRelationInfo.getType().equals(
2750    luiLuiRelation.getLuLuRelationType().getId())) {
2751  1 luiLuiRelation.setLuLuRelationType(luDao.fetch(
2752    LuLuRelationType.class, luiLuiRelationInfo.getType()));
2753    }
2754   
2755  1 LuiLuiRelation updated = luDao.update(luiLuiRelation);
2756   
2757  1 return LuServiceAssembler.toLuiLuiRelationInfo(updated);
2758    }
2759   
 
2760  1 toggle @Override
2761    public StatusInfo deleteLuiLuiRelation(String luiLuiRelationId)
2762    throws DoesNotExistException, InvalidParameterException,
2763    MissingParameterException, OperationFailedException,
2764    PermissionDeniedException {
2765   
2766  1 checkForMissingParameter(luiLuiRelationId, "luiLuiRelationId");
2767   
2768  1 luDao.delete(LuiLuiRelation.class, luiLuiRelationId);
2769   
2770  1 StatusInfo statusInfo = new StatusInfo();
2771  1 statusInfo.setSuccess(true);
2772   
2773  1 return statusInfo;
2774    }
2775   
2776    /**************************************************************************
2777    * SEARCH OPERATIONS *
2778    **************************************************************************/
2779   
 
2780  0 toggle @Override
2781    public SearchCriteriaTypeInfo getSearchCriteriaType(
2782    String searchCriteriaTypeKey) throws DoesNotExistException,
2783    InvalidParameterException, MissingParameterException,
2784    OperationFailedException {
2785   
2786  0 return searchManager.getSearchCriteriaType(searchCriteriaTypeKey);
2787    }
2788   
 
2789  0 toggle @Override
2790    public List<SearchCriteriaTypeInfo> getSearchCriteriaTypes()
2791    throws OperationFailedException {
2792  0 return searchManager.getSearchCriteriaTypes();
2793    }
2794   
 
2795  0 toggle @Override
2796    public SearchResultTypeInfo getSearchResultType(String searchResultTypeKey)
2797    throws DoesNotExistException, InvalidParameterException,
2798    MissingParameterException, OperationFailedException {
2799  0 checkForMissingParameter(searchResultTypeKey, "searchResultTypeKey");
2800  0 return searchManager.getSearchResultType(searchResultTypeKey);
2801    }
2802   
 
2803  0 toggle @Override
2804    public List<SearchResultTypeInfo> getSearchResultTypes()
2805    throws OperationFailedException {
2806  0 return searchManager.getSearchResultTypes();
2807    }
2808   
 
2809  0 toggle @Override
2810    public SearchTypeInfo getSearchType(String searchTypeKey)
2811    throws DoesNotExistException, InvalidParameterException,
2812    MissingParameterException, OperationFailedException {
2813  0 checkForMissingParameter(searchTypeKey, "searchTypeKey");
2814  0 return searchManager.getSearchType(searchTypeKey);
2815    }
2816   
 
2817  0 toggle @Override
2818    public List<SearchTypeInfo> getSearchTypes()
2819    throws OperationFailedException {
2820  0 return searchManager.getSearchTypes();
2821    }
2822   
 
2823  0 toggle @Override
2824    public List<SearchTypeInfo> getSearchTypesByCriteria(
2825    String searchCriteriaTypeKey) throws DoesNotExistException,
2826    InvalidParameterException, MissingParameterException,
2827    OperationFailedException {
2828  0 checkForMissingParameter(searchCriteriaTypeKey, "searchCriteriaTypeKey");
2829  0 return searchManager.getSearchTypesByCriteria(searchCriteriaTypeKey);
2830    }
2831   
 
2832  0 toggle @Override
2833    public List<SearchTypeInfo> getSearchTypesByResult(
2834    String searchResultTypeKey) throws DoesNotExistException,
2835    InvalidParameterException, MissingParameterException,
2836    OperationFailedException {
2837  0 checkForMissingParameter(searchResultTypeKey, "searchResultTypeKey");
2838  0 return searchManager.getSearchTypesByResult(searchResultTypeKey);
2839    }
2840   
 
2841  13 toggle private void checkCluAlreadyAdded(CluSet cluSet, String cluId)
2842    throws OperationFailedException {
2843  13 for (CluSetJoinVersionIndClu join : cluSet.getCluVerIndIds()) {
2844  13 if (join.getCluVersionIndId().equals(cluId)) {
2845  2 throw new OperationFailedException("CluSet already contains Clu (id='" + cluId + "')");
2846    }
2847    }
2848    }
2849   
 
2850  27 toggle private void checkCluSetAlreadyAdded(CluSet cluSet, String cluSetIdToAdd)
2851    throws OperationFailedException {
2852  27 if(cluSet.getCluSets()!=null){
2853  27 for (CluSet childCluSet : cluSet.getCluSets()) {
2854  20 if (childCluSet.getId().equals(cluSetIdToAdd)) {
2855  2 throw new OperationFailedException("CluSet (id=" + cluSet.getId() +
2856    ") already contains CluSet (id='" + cluSetIdToAdd + "')");
2857    }
2858    }
2859    }
2860    }
2861   
 
2862  77 toggle private void checkCluSetCircularReference(CluSet addedCluSet, String hostCluSetId)
2863    throws CircularRelationshipException {
2864  77 if (addedCluSet.getId().equals(hostCluSetId)) {
2865  2 throw new CircularRelationshipException(
2866    "Cannot add a CluSet (id=" + hostCluSetId + ") to ifself");
2867    }
2868  75 if(addedCluSet.getCluSets()!=null){
2869  75 for (CluSet childSet : addedCluSet.getCluSets()) {
2870  56 if (childSet.getId().equals(hostCluSetId)) {
2871  2 throw new CircularRelationshipException(
2872    "CluSet (id=" + hostCluSetId +
2873    ") already contains this CluSet (id=" +
2874    childSet.getId() + ")");
2875    }
2876  54 checkCluSetCircularReference(childSet, hostCluSetId);
2877    }
2878    }
2879    }
2880   
 
2881  2 toggle private void findClusInCluSet(List<String> clus, CluSet parentCluSet)
2882    throws DoesNotExistException {
2883  2 List<String> processedCluSetIds = new ArrayList<String>();
2884  2 doFindClusInCluSet(processedCluSetIds, clus, parentCluSet);
2885    }
2886   
 
2887  4 toggle private void doFindClusInCluSet(List<String> processedCluSetIds,
2888    List<String> clus, CluSet parentCluSet) {
2889  4 for (CluSetJoinVersionIndClu join : parentCluSet.getCluVerIndIds()) {
2890  7 if (!clus.contains(join.getCluVersionIndId())) {
2891  5 clus.add(join.getCluVersionIndId());
2892    }
2893    }
2894  4 if(parentCluSet.getCluSets()!=null){
2895  4 for (CluSet cluSet : parentCluSet.getCluSets()) {
2896    // This condition avoids infinite recursion problem
2897  2 if (!processedCluSetIds.contains(cluSet.getId())) {
2898  2 processedCluSetIds.add(cluSet.getId());
2899  2 doFindClusInCluSet(processedCluSetIds, clus, cluSet);
2900    }
2901    }
2902    }
2903    }
2904   
 
2905  752 toggle @Override
2906    public ObjectStructureDefinition getObjectStructure(String objectTypeKey) {
2907  752 return dictionaryServiceDelegate.getObjectStructure(objectTypeKey);
2908    }
2909   
 
2910  0 toggle @Override
2911    public List<String> getObjectTypes() {
2912  0 return dictionaryServiceDelegate.getObjectTypes();
2913    }
2914   
 
2915  0 toggle public LuDao getLuDao() {
2916  0 return luDao;
2917    }
2918   
 
2919  5 toggle public void setLuDao(LuDao luDao) {
2920  5 this.luDao = luDao;
2921    }
2922   
 
2923  18 toggle @Override
2924    public SearchResult search(SearchRequest searchRequest) throws MissingParameterException {
2925  18 checkForMissingParameter(searchRequest, "searchRequest");
2926  18 return searchManager.search(searchRequest, luDao);
2927    }
2928   
2929    /**
2930    * Check for missing parameter and throw localized exception if missing
2931    *
2932    * @param param
2933    * @param parameter
2934    * name
2935    * @throws MissingParameterException
2936    */
 
2937  5055 toggle private void checkForMissingParameter(Object param, String paramName)
2938    throws MissingParameterException {
2939  5055 if (param == null) {
2940  27 throw new MissingParameterException(paramName + " can not be null");
2941    }
2942    }
2943   
2944    /**
2945    * @param param
2946    * @param paramName
2947    * @throws MissingParameterException
2948    */
 
2949  210 toggle private void checkForEmptyList(Object param, String paramName)
2950    throws MissingParameterException {
2951  210 if (param != null && param instanceof List<?>
2952    && ((List<?>) param).size() == 0) {
2953  0 throw new MissingParameterException(paramName
2954    + " can not be an empty list");
2955    }
2956    }
2957   
 
2958  7 toggle @Override
2959    public StatusInfo addCluSetsToCluSet(String cluSetId, List<String> cluSetIdList)
2960    throws CircularRelationshipException,
2961    DoesNotExistException, InvalidParameterException,
2962    MissingParameterException, OperationFailedException,
2963    PermissionDeniedException, UnsupportedActionException {
2964   
2965  7 checkForMissingParameter(cluSetId, "cluSetId");
2966  7 checkForMissingParameter(cluSetIdList, "cluSetIdList");
2967   
2968    // Check that CluSet exists
2969  7 luDao.fetch(CluSet.class, cluSetId);
2970   
2971  7 for(String cluSetIdToAdd : cluSetIdList) {
2972  19 StatusInfo status = addCluSetToCluSet(cluSetId, cluSetIdToAdd);
2973  15 if (!status.getSuccess()) {
2974  0 return status;
2975    }
2976    }
2977   
2978  3 StatusInfo statusInfo = new StatusInfo();
2979  3 statusInfo.setSuccess(true);
2980   
2981  3 return statusInfo;
2982    }
2983   
 
2984  4 toggle @Override
2985    public StatusInfo addClusToCluSet(List<String> cluIdList, String cluSetId)
2986    throws DoesNotExistException, InvalidParameterException,
2987    MissingParameterException, OperationFailedException,
2988    PermissionDeniedException, UnsupportedActionException {
2989   
2990  4 checkForMissingParameter(cluIdList, "cluIdList");
2991  4 checkForMissingParameter(cluSetId, "cluSetId");
2992   
2993  4 for(String cluId : cluIdList) {
2994  11 StatusInfo status = addCluToCluSet(cluId, cluSetId);
2995  8 if (!status.getSuccess()) {
2996  0 return status;
2997    }
2998    }
2999   
3000  1 StatusInfo statusInfo = new StatusInfo();
3001  1 statusInfo.setSuccess(true);
3002   
3003  1 return statusInfo;
3004    }
3005   
 
3006  0 toggle public ValidatorFactory getValidatorFactory() {
3007  0 return validatorFactory;
3008    }
3009   
 
3010  3 toggle public void setValidatorFactory(ValidatorFactory validatorFactory) {
3011  3 this.validatorFactory = validatorFactory;
3012    }
3013   
3014    /********* Versioning Methods ***************************/
3015   
 
3016  18 toggle @Override
3017    public CluInfo createNewCluVersion(String versionIndCluId, String versionComment) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException {
3018  18 Clu latestClu;
3019  18 Clu currentClu;
3020  18 try{
3021  18 latestClu = luDao.getLatestCluVersion(versionIndCluId);
3022    }catch(NoResultException e){
3023  0 throw new DoesNotExistException("There are no matching versions of this clu", e);
3024    }
3025  18 try{
3026  18 currentClu = luDao.getCurrentCluVersion(versionIndCluId);
3027    }catch(NoResultException e){
3028  0 throw new DoesNotExistException("There is no current version of this clu. Only current clus can be versioned. Use setCurrentCluVersion to make a clu current.", e);
3029    }
3030   
3031  18 CluInfo cluInfo = LuServiceAssembler.toCluInfo(currentClu);
3032   
3033    // Reset the Clu
3034  18 clearCluIds(cluInfo);
3035   
3036    // Create the new Clu Version
3037  18 CluInfo newClu = null;
3038   
3039  18 try {
3040  18 Clu clu = toCluForCreate(cluInfo.getType(), cluInfo);
3041    //Set the Version data
3042  18 Version version = new Version();
3043  18 version.setSequenceNumber(latestClu.getVersion().getSequenceNumber() + 1);
3044  18 version.setVersionIndId(versionIndCluId);
3045  18 version.setCurrentVersionStart(null);
3046  18 version.setCurrentVersionEnd(null);
3047  18 version.setVersionComment(versionComment);
3048  18 version.setVersionedFromId(currentClu.getId());
3049  18 clu.setVersion(version);
3050  18 luDao.create(clu);
3051  18 newClu = LuServiceAssembler.toCluInfo(clu);
3052    } catch (AlreadyExistsException e) {
3053  0 throw new OperationFailedException("Error creating a new clu version", e);
3054    }
3055   
3056  18 return newClu;
3057    }
3058   
 
3059  18 toggle private void clearCluIds(CluInfo clu) {
3060    // Clear out all ids so a copy can be made
3061  18 clu.setState(LUConstants.LU_STATE_DRAFT);// TODO check if this should be set from outside
3062  18 clu.setId(null);
3063   
3064  18 if(clu.getAccountingInfo()!=null){
3065  10 clu.getAccountingInfo().setId(null);
3066   
3067  10 for(AffiliatedOrgInfo affiliatedOrg:clu.getAccountingInfo().getAffiliatedOrgs()){
3068  16 affiliatedOrg.setId(null);
3069    }
3070    }
3071  18 for(AccreditationInfo accredation:clu.getAccreditations()){
3072  8 accredation.setId(null);
3073    }
3074  18 for(AdminOrgInfo adminOrg:clu.getAdminOrgs()){
3075  174 adminOrg.setId(null);
3076    }
3077  18 for(CluIdentifierInfo alternateIdentifier:clu.getAlternateIdentifiers()){
3078  34 alternateIdentifier.setId(null);
3079    }
3080  18 if(clu.getFeeInfo()!=null){
3081  10 clu.getFeeInfo().setId(null);
3082  10 for(CluFeeRecordInfo cluFeeRecord:clu.getFeeInfo().getCluFeeRecords()){
3083  36 cluFeeRecord.setId(null);
3084  36 for(AffiliatedOrgInfo affiliatedOrg:cluFeeRecord.getAffiliatedOrgs()){
3085  40 affiliatedOrg.setId(null);
3086    }
3087  36 for(CurrencyAmountInfo feeAmount:cluFeeRecord.getFeeAmounts()){
3088  38 feeAmount.setId(null);
3089    }
3090    }
3091    }
3092  18 for(LuCodeInfo luCode:clu.getLuCodes()){
3093  36 luCode.setId(null);
3094    }
3095  18 if(clu.getOfficialIdentifier()!=null){
3096  18 clu.getOfficialIdentifier().setId(null);
3097    }
3098    }
3099   
3100    /**
3101    * This method sets the CLU with ID of cluVersionId as the current version and will set the version end date of the previously current version to currentVersionStart or now() if null. This will NOT update state of the current or previously current CLU. All state changes must be handled either by the business service or from the client application.
3102    *
3103    * @param currentVersionStart if set to null, will default the current version start to the time when this method is called.
3104    * You can set this to a future date as well.
3105    */
 
3106  8 toggle @Override
3107    public StatusInfo setCurrentCluVersion(String cluVersionId, Date currentVersionStart) throws DoesNotExistException, InvalidParameterException, MissingParameterException, IllegalVersionSequencingException, OperationFailedException, PermissionDeniedException {
3108    //Check params
3109  8 Date currentDbDate = new Date();//FIXME, this should be DB time
3110  8 if(currentVersionStart!=null&&currentVersionStart.compareTo(currentDbDate)<0){
3111  1 throw new InvalidParameterException("currentVersionStart must be in the future.");
3112    }
3113    //Default the currentVersionStart to the current date
3114  7 if(currentVersionStart==null){
3115  5 currentVersionStart = currentDbDate;
3116    }
3117   
3118    //get the clu we are setting as current
3119  7 Clu clu = luDao.fetch(Clu.class, cluVersionId);
3120  7 String versionIndId = clu.getVersion().getVersionIndId();
3121   
3122  7 Clu oldClu = null;
3123  7 try{
3124  7 oldClu = luDao.getCurrentCluVersion(versionIndId);
3125    }catch(NoResultException e){}
3126   
3127    //Check that the clu you are trying to version has a sequence number greater than the current clu
3128  7 if(oldClu!=null){
3129  7 if(clu.getVersion().getSequenceNumber()<=oldClu.getVersion().getSequenceNumber()){
3130  0 throw new OperationFailedException("Clu to make current must have been versioned from the current Clu");
3131    }
3132    }else{
3133    //Ignore the start date set if this is the first version (it will be set to the current time to avoid weird time problems)
3134  0 currentVersionStart = currentDbDate;
3135    }
3136   
3137   
3138    //Get any clus that are set to become current in the future, and clear their current dates
3139  7 List<VersionDisplayInfo> versionsInFuture = luDao.getVersionsInDateRange(versionIndId, null, currentDbDate, null);
3140  7 for(VersionDisplayInfo versionInFuture:versionsInFuture){
3141  0 if(oldClu==null || !versionInFuture.getId().equals(oldClu.getId())){
3142  0 VersionEntity futureClu = luDao.fetch(Clu.class, versionInFuture.getId());
3143  0 futureClu.getVersion().setCurrentVersionStart(null);
3144  0 futureClu.getVersion().setCurrentVersionEnd(null);
3145  0 futureClu = luDao.update(futureClu);
3146    }
3147    }
3148   
3149    //If there is a current clu, set its end date to the new clu's start date
3150  7 if(oldClu!=null){
3151  7 oldClu.getVersion().setCurrentVersionEnd(currentVersionStart);
3152  7 oldClu = luDao.update(oldClu);
3153    }
3154   
3155    //Set the startdate of the new current clu
3156  7 clu.getVersion().setCurrentVersionStart(currentVersionStart);
3157  7 clu.getVersion().setCurrentVersionEnd(null);
3158  7 clu = luDao.update(clu);
3159   
3160  7 StatusInfo statusInfo = new StatusInfo();
3161  7 statusInfo.setSuccess(true);
3162  7 return statusInfo;
3163    }
3164   
 
3165  0 toggle @Override
3166    public VersionDisplayInfo getLatestVersion(String refObjectTypeURI, String refObjectId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
3167  0 VersionDisplayInfo versionInfo = null;
3168  0 if(LuServiceConstants.CLU_NAMESPACE_URI.equals(refObjectTypeURI)){
3169  0 try{
3170  0 versionInfo = luDao.getLatestVersion(refObjectId, refObjectTypeURI);
3171    }catch(NoResultException e){
3172  0 throw new DoesNotExistException();
3173    }
3174    }else{
3175  0 throw new UnsupportedOperationException("This method does not know how to handle object type:"+refObjectTypeURI);
3176    }
3177  0 return versionInfo;
3178    }
3179   
 
3180  25 toggle @Override
3181    public VersionDisplayInfo getCurrentVersion(String refObjectTypeURI, String refObjectId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
3182  25 VersionDisplayInfo versionInfo = null;
3183  25 if(LuServiceConstants.CLU_NAMESPACE_URI.equals(refObjectTypeURI)){
3184  25 try{
3185  25 versionInfo = luDao.getCurrentCluVersionInfo(refObjectId, refObjectTypeURI);
3186    }catch(NoResultException e){
3187  0 throw new DoesNotExistException();
3188    }
3189    }else{
3190  0 throw new UnsupportedOperationException("This method does not know how to handle object type:"+refObjectTypeURI);
3191    }
3192  25 return versionInfo;
3193    }
3194   
 
3195  3 toggle @Override
3196    public VersionDisplayInfo getCurrentVersionOnDate(String refObjectTypeURI, String refObjectId, Date date) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
3197  3 VersionDisplayInfo versionInfo = null;
3198  3 if(LuServiceConstants.CLU_NAMESPACE_URI.equals(refObjectTypeURI)){
3199  3 try{
3200  3 versionInfo = luDao.getCurrentVersionOnDate(refObjectId, refObjectTypeURI, date);
3201    }catch(NoResultException e){
3202  0 throw new DoesNotExistException();
3203    }
3204    }else{
3205  0 throw new UnsupportedOperationException("This method does not know how to handle object type:"+refObjectTypeURI);
3206    }
3207  3 return versionInfo;
3208    }
3209   
 
3210  1 toggle @Override
3211    public VersionDisplayInfo getFirstVersion(String refObjectTypeURI, String refObjectId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
3212  1 VersionDisplayInfo versionInfo = null;
3213  1 if(LuServiceConstants.CLU_NAMESPACE_URI.equals(refObjectTypeURI)){
3214  1 try{
3215  1 versionInfo = luDao.getFirstVersion(refObjectId, refObjectTypeURI);
3216    }catch(NoResultException e){
3217  0 throw new DoesNotExistException();
3218    }
3219    }else{
3220  0 throw new UnsupportedOperationException("This method does not know how to handle object type:"+refObjectTypeURI);
3221    }
3222  1 return versionInfo;
3223    }
3224   
 
3225  1 toggle @Override
3226    public VersionDisplayInfo getVersionBySequenceNumber(String refObjectTypeURI, String refObjectId, Long sequence) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
3227  1 VersionDisplayInfo versionInfo = null;
3228  1 if(LuServiceConstants.CLU_NAMESPACE_URI.equals(refObjectTypeURI)){
3229  1 try{
3230  1 versionInfo = luDao.getVersionBySequenceNumber(refObjectId, refObjectTypeURI, sequence);
3231    }catch(NoResultException e){
3232  0 throw new DoesNotExistException();
3233    }
3234    }else{
3235  0 throw new UnsupportedOperationException("This method does not know how to handle object type:"+refObjectTypeURI);
3236    }
3237  1 return versionInfo;
3238    }
3239   
 
3240  2 toggle @Override
3241    public List<VersionDisplayInfo> getVersions(String refObjectTypeURI, String refObjectId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
3242  2 List<VersionDisplayInfo> versionInfos = null;
3243  2 if(LuServiceConstants.CLU_NAMESPACE_URI.equals(refObjectTypeURI)){
3244  2 versionInfos = luDao.getVersions(refObjectId, refObjectTypeURI);
3245  2 if(versionInfos==null){
3246  0 versionInfos = Collections.emptyList();
3247    }
3248    }else{
3249  0 throw new UnsupportedOperationException("This method does not know how to handle object type:"+refObjectTypeURI);
3250    }
3251  2 return versionInfos;
3252    }
3253   
 
3254  1 toggle @Override
3255    public List<VersionDisplayInfo> getVersionsInDateRange(String refObjectTypeURI, String refObjectId, Date from, Date to) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
3256  1 List<VersionDisplayInfo> versionInfos = null;
3257  1 if(LuServiceConstants.CLU_NAMESPACE_URI.equals(refObjectTypeURI)){
3258  1 versionInfos = luDao.getVersionsInDateRange(refObjectId, refObjectTypeURI, from, to);
3259  1 if(versionInfos==null){
3260  0 versionInfos = Collections.emptyList();
3261    }
3262    }else{
3263  0 throw new UnsupportedOperationException("This method does not know how to handle object type:"+refObjectTypeURI);
3264    }
3265  1 return versionInfos;
3266    }
3267    }