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