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