Coverage Report - org.kuali.student.lum.lo.service.impl.LearningObjectiveServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
LearningObjectiveServiceImpl
74%
238/321
48%
55/114
2.429
 
 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.lo.service.impl;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.HashMap;
 20  
 import java.util.Iterator;
 21  
 import java.util.List;
 22  
 import java.util.Map;
 23  
 
 24  
 import javax.jws.WebService;
 25  
 
 26  
 import org.kuali.student.common.dictionary.dto.ObjectStructureDefinition;
 27  
 import org.kuali.student.common.dictionary.service.DictionaryService;
 28  
 import org.kuali.student.common.dto.DtoConstants;
 29  
 import org.kuali.student.common.dto.StatusInfo;
 30  
 import org.kuali.student.common.exceptions.AlreadyExistsException;
 31  
 import org.kuali.student.common.exceptions.DataValidationErrorException;
 32  
 import org.kuali.student.common.exceptions.DependentObjectsExistException;
 33  
 import org.kuali.student.common.exceptions.DoesNotExistException;
 34  
 import org.kuali.student.common.exceptions.InvalidParameterException;
 35  
 import org.kuali.student.common.exceptions.MissingParameterException;
 36  
 import org.kuali.student.common.exceptions.OperationFailedException;
 37  
 import org.kuali.student.common.exceptions.PermissionDeniedException;
 38  
 import org.kuali.student.common.exceptions.UnsupportedActionException;
 39  
 import org.kuali.student.common.exceptions.VersionMismatchException;
 40  
 import org.kuali.student.common.search.dto.SearchCriteriaTypeInfo;
 41  
 import org.kuali.student.common.search.dto.SearchParam;
 42  
 import org.kuali.student.common.search.dto.SearchRequest;
 43  
 import org.kuali.student.common.search.dto.SearchResult;
 44  
 import org.kuali.student.common.search.dto.SearchResultCell;
 45  
 import org.kuali.student.common.search.dto.SearchResultRow;
 46  
 import org.kuali.student.common.search.dto.SearchResultTypeInfo;
 47  
 import org.kuali.student.common.search.dto.SearchTypeInfo;
 48  
 import org.kuali.student.common.search.service.SearchManager;
 49  
 import org.kuali.student.common.validation.dto.ValidationResultInfo;
 50  
 import org.kuali.student.common.validator.Validator;
 51  
 import org.kuali.student.common.validator.ValidatorFactory;
 52  
 import org.kuali.student.lum.lo.dao.LoDao;
 53  
 import org.kuali.student.lum.lo.dto.LoCategoryInfo;
 54  
 import org.kuali.student.lum.lo.dto.LoCategoryTypeInfo;
 55  
 import org.kuali.student.lum.lo.dto.LoInfo;
 56  
 import org.kuali.student.lum.lo.dto.LoLoRelationInfo;
 57  
 import org.kuali.student.lum.lo.dto.LoLoRelationTypeInfo;
 58  
 import org.kuali.student.lum.lo.dto.LoRepositoryInfo;
 59  
 import org.kuali.student.lum.lo.dto.LoTypeInfo;
 60  
 import org.kuali.student.lum.lo.entity.Lo;
 61  
 import org.kuali.student.lum.lo.entity.LoCategory;
 62  
 import org.kuali.student.lum.lo.entity.LoCategoryType;
 63  
 import org.kuali.student.lum.lo.entity.LoLoRelation;
 64  
 import org.kuali.student.lum.lo.entity.LoLoRelationType;
 65  
 import org.kuali.student.lum.lo.entity.LoRepository;
 66  
 import org.kuali.student.lum.lo.entity.LoType;
 67  
 import org.kuali.student.lum.lo.service.LearningObjectiveService;
 68  
 import org.springframework.transaction.annotation.Transactional;
 69  
 
 70  
 /*n
 71  
  * @author Kuali Student team
 72  
  *
 73  
  */
 74  
 @WebService(endpointInterface = "org.kuali.student.lum.lo.service.LearningObjectiveService", serviceName = "LearningObjectiveService", portName = "LearningObjectiveService", targetNamespace = "http://student.kuali.org/wsdl/lo")
 75  6
 public class LearningObjectiveServiceImpl implements LearningObjectiveService {
 76  
     private LoDao loDao;
 77  
         private SearchManager searchManager;
 78  
     private DictionaryService dictionaryServiceDelegate;
 79  
         private ValidatorFactory validatorFactory;
 80  
 
 81  
         public LoDao getLoDao() {
 82  0
         return loDao;
 83  
     }
 84  
 
 85  
     public void setLoDao(LoDao dao) {
 86  3
         this.loDao = dao;
 87  3
     }
 88  
 
 89  
         public void setSearchManager(SearchManager searchManager) {
 90  3
                 this.searchManager = searchManager;
 91  3
         }
 92  
 
 93  
     public void setDictionaryServiceDelegate(DictionaryService dictionaryServiceDelegate) {
 94  3
         this.dictionaryServiceDelegate = dictionaryServiceDelegate;
 95  3
     }
 96  
 
 97  
         public ValidatorFactory getValidatorFactory() {
 98  0
         return validatorFactory;
 99  
     }
 100  
 
 101  
     public void setValidatorFactory(ValidatorFactory validatorFactory) {
 102  3
         this.validatorFactory = validatorFactory;
 103  3
     }
 104  
 
 105  
     /*
 106  
      * (non-Javadoc)
 107  
      * @see org.kuali.student.lum.lo.service.LearningObjectiveService#getLoRepositories()
 108  
      */
 109  
         @Override
 110  
     @Transactional(readOnly=true)
 111  
         public List<LoRepositoryInfo> getLoRepositories()
 112  
                         throws OperationFailedException {
 113  1
             List<LoRepository> repositories = loDao.find(LoRepository.class);
 114  1
                 return LearningObjectiveServiceAssembler.toLoRepositoryInfos(repositories);
 115  
         }
 116  
         
 117  
         /*
 118  
          * (non-Javadoc)
 119  
          * @see org.kuali.student.lum.lo.service.LearningObjectiveService#getLoRepository(java.lang.String)
 120  
          */
 121  
         @Override
 122  
     @Transactional(readOnly=true)
 123  
         public LoRepositoryInfo getLoRepository(String loRepositoryKey)
 124  
                         throws DoesNotExistException, InvalidParameterException,
 125  
                         MissingParameterException, OperationFailedException {
 126  2
             checkForMissingParameter(loRepositoryKey, "loRepositoryKey");
 127  1
                 return LearningObjectiveServiceAssembler.toLoRepositoryInfo(loDao.fetch(LoRepository.class, loRepositoryKey));
 128  
         }
 129  
 
 130  
         /*
 131  
          * (non-Javadoc)
 132  
          * @see org.kuali.student.lum.lo.service.LearningObjectiveService#getLoTypes()
 133  
          */
 134  
         @Override
 135  
     @Transactional(readOnly=true)
 136  
         public List<LoTypeInfo> getLoTypes() throws OperationFailedException {
 137  1
             List<LoType> find = loDao.find(LoType.class);
 138  1
                 return LearningObjectiveServiceAssembler.toLoTypeInfos(find);
 139  
         }
 140  
 
 141  
         /*
 142  
          * (non-Javadoc)
 143  
          * @see org.kuali.student.lum.lo.service.LearningObjectiveService#getLoType(java.lang.String)
 144  
          */
 145  
         @Override
 146  
     @Transactional(readOnly=true)
 147  
         public LoTypeInfo getLoType(String loTypeKey) throws DoesNotExistException,
 148  
                         InvalidParameterException, MissingParameterException,
 149  
                         OperationFailedException {
 150  3
             checkForMissingParameter(loTypeKey, "loTypeKey");
 151  2
             LoType fetch = loDao.fetch(LoType.class, loTypeKey);
 152  2
                 return LearningObjectiveServiceAssembler.toLoTypeInfo(fetch);
 153  
         }
 154  
 
 155  
         /*
 156  
          * (non-Javadoc)
 157  
          * @see org.kuali.student.lum.lo.service.LearningObjectiveService#getLoLoRelationTypes()
 158  
          */
 159  
         @Override
 160  
     @Transactional(readOnly=true)
 161  
         public List<LoLoRelationTypeInfo> getLoLoRelationTypes()
 162  
                         throws OperationFailedException {
 163  1
             List<LoLoRelationType> fetch = loDao.find(LoLoRelationType.class);
 164  1
                 return LearningObjectiveServiceAssembler.toLoLoRelationTypeInfos(fetch);
 165  
         }
 166  
 
 167  
         /*
 168  
          * (non-Javadoc)
 169  
          * @see org.kuali.student.lum.lo.service.LearningObjectiveService#getLoLoRelationType(java.lang.String)
 170  
          */
 171  
         @Override
 172  
     @Transactional(readOnly=true)
 173  
         public LoLoRelationTypeInfo getLoLoRelationType(String loLoRelationTypeKey)
 174  
                         throws OperationFailedException, MissingParameterException, DoesNotExistException {
 175  2
             checkForMissingParameter(loLoRelationTypeKey, "loLoRelationTypeKey");
 176  1
                 return LearningObjectiveServiceAssembler.toLoLoRelationTypeInfo(loDao.fetch(LoLoRelationType.class, loLoRelationTypeKey));
 177  
         }
 178  
 
 179  
         @Override
 180  
     @Transactional(readOnly=true)
 181  
         public List<String> getAllowedLoLoRelationTypesForLoType(String loTypeKey, String relatedLoTypeKey)
 182  
                         throws DoesNotExistException, InvalidParameterException,
 183  
                                         MissingParameterException, OperationFailedException {
 184  2
             checkForMissingParameter(loTypeKey, "loTypeKey");
 185  2
             checkForMissingParameter(relatedLoTypeKey, "relatedLoTypeKey");
 186  
             
 187  2
             return loDao.getAllowedLoLoRelationTypesForLoType(loTypeKey, relatedLoTypeKey);
 188  
         }
 189  
 
 190  
     /*
 191  
          * (non-Javadoc)
 192  
          * @see org.kuali.student.lum.lo.service.LearningObjectiveService#addLoCategoryToLo(java.lang.String, java.lang.String)
 193  
          */
 194  
         @Override
 195  
         @Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class})
 196  
         public StatusInfo addLoCategoryToLo(String loCategoryId, String loId)
 197  
                         throws AlreadyExistsException, DoesNotExistException,
 198  
                         InvalidParameterException, MissingParameterException,
 199  
                         OperationFailedException, PermissionDeniedException,
 200  
                         UnsupportedActionException {
 201  1291
             checkForMissingParameter(loCategoryId, "loCategoryId");
 202  1291
             checkForMissingParameter(loId, "loId");
 203  1291
         StatusInfo statusInfo = new StatusInfo();
 204  1291
         statusInfo.setSuccess(loDao.addLoCategoryToLo(loCategoryId, loId));
 205  1291
         return statusInfo;
 206  
         }
 207  
 
 208  
         /* (non-Javadoc)
 209  
          * @see org.kuali.student.lum.lo.service.LearningObjectiveService#createLo(java.lang.String, java.lang.String, org.kuali.student.lum.lo.dto.LoInfo)
 210  
          */
 211  
         @Override
 212  
         @Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class})
 213  
         public LoInfo createLo(String repositoryId, String loType, LoInfo loInfo)
 214  
                         throws DataValidationErrorException, DoesNotExistException,
 215  
                         InvalidParameterException, MissingParameterException,
 216  
                         OperationFailedException, PermissionDeniedException {
 217  656
             checkForMissingParameter(repositoryId, "repositoryId");
 218  655
             checkForMissingParameter(loType, "loType");
 219  654
             checkForMissingParameter(loInfo, "loInfo");
 220  
             
 221  
             
 222  
                 // Validate LO
 223  653
                 List<ValidationResultInfo> val = validateLo("SYSTEM", loInfo);
 224  653
                 if(null != val && val.size() > 0) {
 225  1
                         for (ValidationResultInfo result : val) {
 226  1
                                 System.err.println("Validation error. Element: " + result.getElement() + ",  Value: " + result.getMessage());
 227  
                         }
 228  1
             throw new DataValidationErrorException("Validation error!", val);
 229  
                 }
 230  
                 
 231  
             // make sure LoType and LoRepository exist before trying to create
 232  
             // if checkForMissingParameter above did its job, we don't have to null-check these id's
 233  652
             LoType type = null;
 234  652
             LoRepository repository = null;
 235  
             try {
 236  652
                     type = loDao.fetch(LoType.class, loType);
 237  652
                     repository = loDao.fetch(LoRepository.class, repositoryId); 
 238  0
             } catch (DoesNotExistException dnee) {
 239  0
                     throw new DoesNotExistException("Specified " + (null == type ? "LoType" : "LoRepository") + " does not exist", dnee);
 240  652
             }
 241  
             
 242  652
             loInfo.setLoRepositoryKey(repositoryId);
 243  652
             loInfo.setType(loType);
 244  
             
 245  652
             Lo lo = null;
 246  
             try {
 247  652
                     lo = LearningObjectiveServiceAssembler.toLo(false, loInfo, loDao);
 248  0
             } catch (VersionMismatchException vme) {
 249  
                     // should never happen in a create call, but
 250  0
                     throw new OperationFailedException("VersionMismatchException caught during Learning Objective creation");
 251  652
             }
 252  652
             lo.setLoType(type);
 253  652
             lo.setLoRepository(repository);
 254  652
             loDao.create(lo);
 255  
             
 256  652
                 return LearningObjectiveServiceAssembler.toLoInfo(lo);
 257  
         }
 258  
 
 259  
         /* (non-Javadoc)
 260  
          * @see org.kuali.student.lum.lo.service.LearningObjectiveService#deleteLo(java.lang.String)
 261  
          */
 262  
         @Override
 263  
         @Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class})
 264  
         public StatusInfo deleteLo(String loId)
 265  
                         throws DependentObjectsExistException, DoesNotExistException,
 266  
                         InvalidParameterException, MissingParameterException,
 267  
                         OperationFailedException, PermissionDeniedException {
 268  25
             checkForMissingParameter(loId, "loId");
 269  
             
 270  25
             StatusInfo returnStatus = new StatusInfo();
 271  25
             returnStatus.setSuccess(loDao.deleteLo(loId));
 272  24
                 return returnStatus;
 273  
         }
 274  
 
 275  
         /* (non-Javadoc)
 276  
          * @see org.kuali.student.lum.lo.service.LearningObjectiveService#deleteLoCategory(java.lang.String)
 277  
          */
 278  
         @Override
 279  
         @Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class})
 280  
         public StatusInfo deleteLoCategory(String loCategoryId)
 281  
                         throws DependentObjectsExistException, DoesNotExistException,
 282  
                         InvalidParameterException, MissingParameterException,
 283  
                         OperationFailedException, PermissionDeniedException {
 284  6
             checkForMissingParameter(loCategoryId, "loCategoryId");
 285  
             
 286  6
             loDao.deleteLoCategory(loCategoryId);
 287  
             
 288  5
                 return new StatusInfo();
 289  
         }
 290  
 
 291  
         /* (non-Javadoc)
 292  
          * @see org.kuali.student.lum.lo.service.LearningObjectiveService#getLo(java.lang.String)
 293  
          */
 294  
         @Override
 295  
     @Transactional(readOnly=true)
 296  
         public LoInfo getLo(String loId) throws DoesNotExistException,
 297  
                         InvalidParameterException, MissingParameterException,
 298  
                         OperationFailedException {
 299  86
             checkForMissingParameter(loId, "loId");
 300  
             
 301  85
                 return LearningObjectiveServiceAssembler.toLoInfo(loDao.fetch(Lo.class, loId));
 302  
         }
 303  
 
 304  
         /* (non-Javadoc)
 305  
          * @see org.kuali.student.lum.lo.service.LearningObjectiveService#getLoByIdList(java.util.List)
 306  
          */
 307  
         @Override
 308  
     @Transactional(readOnly=true)
 309  
         public List<LoInfo> getLoByIdList(List<String> loIds)
 310  
                         throws InvalidParameterException, MissingParameterException,
 311  
                         OperationFailedException {
 312  1
             checkForMissingParameter(loIds, "loId");
 313  1
             checkForEmptyList(loIds, "loId");
 314  1
             List<Lo> los = loDao.getLoByIdList(loIds);
 315  1
                 return LearningObjectiveServiceAssembler.toLoInfos(los);
 316  
         }
 317  
 
 318  
         /* (non-Javadoc)
 319  
          * @see org.kuali.student.lum.lo.service.LearningObjectiveService#getLoCategories(java.lang.String)
 320  
          */
 321  
         @Override
 322  
     @Transactional(readOnly=true)
 323  
         public List<LoCategoryInfo> getLoCategories(String loRepositoryKey)
 324  
                         throws DoesNotExistException, InvalidParameterException,
 325  
                         MissingParameterException, OperationFailedException {
 326  3
             checkForMissingParameter(loRepositoryKey, "loRepositoryKey");
 327  3
             List<LoCategory> categories = loDao.getLoCategories(loRepositoryKey);
 328  3
         return LearningObjectiveServiceAssembler.toLoCategoryInfos(categories);
 329  
         }
 330  
 
 331  
         /* (non-Javadoc)
 332  
          * @see org.kuali.student.lum.lo.service.LearningObjectiveService#getLoCategoriesForLo(java.lang.String)
 333  
          */
 334  
         @Override
 335  
     @Transactional(readOnly=true)
 336  
         public List<LoCategoryInfo> getLoCategoriesForLo(String loId)
 337  
                         throws DoesNotExistException, InvalidParameterException,
 338  
                         MissingParameterException, OperationFailedException {
 339  446
             checkForMissingParameter(loId, "loId");
 340  446
             List<LoCategory> categories = loDao.getLoCategoriesForLo(loId);
 341  446
                 return LearningObjectiveServiceAssembler.toLoCategoryInfos(categories);
 342  
         }
 343  
 
 344  
         /* (non-Javadoc)
 345  
          * @see org.kuali.student.lum.lo.service.LearningObjectiveService#getLoCategory(java.lang.String)
 346  
          */
 347  
         @Override
 348  
     @Transactional(readOnly=true)
 349  
         public LoCategoryInfo getLoCategory(String loCategoryId)
 350  
                         throws DoesNotExistException, InvalidParameterException,
 351  
                         MissingParameterException, OperationFailedException {
 352  3
             checkForMissingParameter(loCategoryId, "loCategoryId");
 353  
             
 354  3
                 return LearningObjectiveServiceAssembler.toLoCategoryInfo(loDao.fetch(LoCategory.class, loCategoryId));
 355  
         }
 356  
 
 357  
         /* (non-Javadoc)
 358  
          * @see org.kuali.student.lum.lo.service.LearningObjectiveService#getLoParents(java.lang.String)
 359  
         public List<LoInfo> getLoParents(String loId) throws DoesNotExistException,
 360  
                         InvalidParameterException, MissingParameterException,
 361  
                         OperationFailedException {
 362  
             checkForMissingParameter(loId, "loId");
 363  
             List<Lo> loParents = loDao.getLoParents(loId);
 364  
                 return LearningObjectiveServiceAssembler.toLoInfos(loParents);
 365  
         }
 366  
          */
 367  
 
 368  
         /* (non-Javadoc)
 369  
          * @see org.kuali.student.lum.lo.service.LearningObjectiveService#getLosByLoCategory(java.lang.String)
 370  
          */
 371  
         @Override
 372  
     @Transactional(readOnly=true)
 373  
         public List<LoInfo> getLosByLoCategory(String loCategoryId)
 374  
                         throws DoesNotExistException, InvalidParameterException,
 375  
                         MissingParameterException, OperationFailedException {
 376  5
             checkForMissingParameter(loCategoryId, "loCategoryId");
 377  5
             List<Lo> los = loDao.getLosByLoCategory(loCategoryId);
 378  5
                 return LearningObjectiveServiceAssembler.toLoInfos(los);
 379  
         }
 380  
 
 381  
         /* (non-Javadoc)
 382  
          * @see org.kuali.student.lum.lo.service.LearningObjectiveService#isDescendant(java.lang.String, java.lang.String)
 383  
         @Override
 384  
         public Boolean isDescendant(String loId, String descendantLoId)
 385  
                         throws DoesNotExistException, InvalidParameterException,
 386  
                         MissingParameterException, OperationFailedException {
 387  
             checkForMissingParameter(loId, "loId");
 388  
             checkForMissingParameter(descendantLoId, "descendantLoId");
 389  
                 return loDao.isDescendant(loId, descendantLoId);
 390  
         }
 391  
          */
 392  
 
 393  
         /* (non-Javadoc)
 394  
          * @see org.kuali.student.lum.lo.service.LearningObjectiveService#isEquivalent(java.lang.String, java.lang.String)
 395  
         @Override
 396  
         public Boolean isEquivalent(String loId, String equivalentLoId)
 397  
                         throws DoesNotExistException, InvalidParameterException,
 398  
                         MissingParameterException, OperationFailedException {
 399  
             checkForMissingParameter(loId, "loId");
 400  
             checkForMissingParameter(equivalentLoId, "equivalentLoId");
 401  
                 return loDao.isEquivalent(loId, equivalentLoId);
 402  
         }
 403  
          */
 404  
 
 405  
         /* (non-Javadoc)
 406  
          * @see org.kuali.student.lum.lo.service.LearningObjectiveService#removeChildLoFromLo(java.lang.String, java.lang.String)
 407  
         @Override
 408  
         @Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class})
 409  
         public StatusInfo removeChildLoFromLo(String loId, String parentLoId)
 410  
                         throws DependentObjectsExistException, DoesNotExistException,
 411  
                         InvalidParameterException, MissingParameterException,
 412  
                         OperationFailedException, PermissionDeniedException {
 413  
             checkForMissingParameter(loId, "loId");
 414  
             checkForMissingParameter(parentLoId, "parentLoId");
 415  
             
 416  
             StatusInfo statusInfo = new StatusInfo();
 417  
             statusInfo.setSuccess(loDao.removeChildLoFromLo(loId, parentLoId));
 418  
                 return statusInfo;
 419  
         }
 420  
          */
 421  
 
 422  
         /* (non-Javadoc)
 423  
          * @see org.kuali.student.lum.lo.service.LearningObjectiveService#removeEquivalentLoFromLo(java.lang.String, java.lang.String)
 424  
         @Override
 425  
         @Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class})
 426  
         public StatusInfo removeEquivalentLoFromLo(String loId,
 427  
                         String equivalentLoId) throws DoesNotExistException,
 428  
                         InvalidParameterException, MissingParameterException,
 429  
                         OperationFailedException, PermissionDeniedException {
 430  
             checkForMissingParameter(loId, "loId");
 431  
             checkForMissingParameter(equivalentLoId, "equivalentLoId");
 432  
             
 433  
         StatusInfo statusInfo = new StatusInfo();
 434  
         statusInfo.setSuccess(loDao.removeEquivalentLoFromLo(loId, equivalentLoId));
 435  
         return statusInfo;
 436  
         }
 437  
          */
 438  
 
 439  
         /* (non-Javadoc)
 440  
          * @see org.kuali.student.lum.lo.service.LearningObjectiveService#removeLoCategoryFromLo(java.lang.String, java.lang.String)
 441  
          */
 442  
         @Override
 443  
         @Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class})
 444  
         public StatusInfo removeLoCategoryFromLo(String loCategoryId, String loId)
 445  
                         throws DoesNotExistException, InvalidParameterException,
 446  
                         MissingParameterException, OperationFailedException,
 447  
                         PermissionDeniedException, UnsupportedActionException {
 448  44
             checkForMissingParameter(loCategoryId, "loCategoryId");
 449  44
             checkForMissingParameter(loId, "loId");
 450  
             
 451  44
         StatusInfo statusInfo = new StatusInfo();
 452  44
         statusInfo.setSuccess(loDao.removeLoCategoryFromLo(loCategoryId, loId));
 453  44
         return statusInfo;
 454  
         }
 455  
 
 456  
         /* (non-Javadoc)
 457  
          * @see org.kuali.student.lum.lo.service.LearningObjectiveService#updateLo(java.lang.String, org.kuali.student.lum.lo.dto.LoInfo)
 458  
          */
 459  
         @Override
 460  
         @Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class})
 461  
         public LoInfo updateLo(String loId, LoInfo loInfo)
 462  
                         throws DataValidationErrorException, DoesNotExistException,
 463  
                         InvalidParameterException, MissingParameterException,
 464  
                         OperationFailedException, PermissionDeniedException,
 465  
                         VersionMismatchException {
 466  25
             checkForMissingParameter(loId, "loId");
 467  24
             checkForMissingParameter(loInfo, "loInfo");
 468  
 
 469  
                 // Validate LO
 470  23
                 List<ValidationResultInfo> val = validateLo("SYSTEM", loInfo);
 471  23
                 if(null != val && val.size() > 0) {
 472  0
                         for (ValidationResultInfo result : val) {
 473  0
                                 System.err.println("Validation error. Element: " + result.getElement() + ",  Value: " + result.getMessage());
 474  
                         }
 475  0
                         throw new DataValidationErrorException("Validation error!", val);
 476  
                 }
 477  
                 
 478  23
             Lo lo = loDao.fetch(Lo.class, loId);
 479  
         
 480  23
         if (!String.valueOf(lo.getVersionNumber()).equals(loInfo.getMetaInfo().getVersionInd())){
 481  1
             throw new VersionMismatchException("LO to be updated is not the current version");
 482  
         }
 483  
         
 484  22
         lo = LearningObjectiveServiceAssembler.toLo(true, lo, loInfo, loDao);
 485  22
         loDao.update(lo);
 486  22
         return LearningObjectiveServiceAssembler.toLoInfo(lo);
 487  
         }
 488  
 
 489  
         /* (non-Javadoc)
 490  
          * @see org.kuali.student.lum.lo.service.LearningObjectiveService#updateLoCategory(java.lang.String, org.kuali.student.lum.lo.dto.LoCategoryInfo)
 491  
          */
 492  
         @Override
 493  
         @Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class})
 494  
         public LoCategoryInfo updateLoCategory(String loCategoryId,
 495  
                         LoCategoryInfo loCategoryInfo) throws DataValidationErrorException,
 496  
                         DoesNotExistException, InvalidParameterException,
 497  
                         MissingParameterException, OperationFailedException,
 498  
                         PermissionDeniedException, VersionMismatchException {
 499  3
             checkForMissingParameter(loCategoryId, "loCategoryId");
 500  3
             checkForMissingParameter(loCategoryInfo, "loCategoryInfo");
 501  
             
 502  
                 // Validate LoCategory
 503  3
                 List<ValidationResultInfo> val = validateLoCategory("SYSTEM", loCategoryInfo);
 504  
 
 505  
                 //kslum-136 - don't allow dups w/ same name (case insensitive), type, state & repository
 506  3
         if (doesLoCategoryExist(loCategoryInfo.getLoRepository(), loCategoryInfo, loCategoryId)) {
 507  2
             ValidationResultInfo vr = new ValidationResultInfo();
 508  2
             vr.setElement("LO Category Name");
 509  2
             vr.setError("LO Category already exists");
 510  2
             val.add(vr);
 511  
         }
 512  3
         if(null != val && val.size() > 0) {
 513  2
             for (ValidationResultInfo result : val) {
 514  2
                 System.err.println("Validation error. Element: " + result.getElement() + ",  Value: " + result.getMessage());
 515  
             }
 516  2
             throw new DataValidationErrorException("Validation error!", val);
 517  
         }
 518  1
             LoCategory loCategory = loDao.fetch(LoCategory.class, loCategoryId);
 519  
         
 520  1
         if (!String.valueOf(loCategory.getVersionNumber()).equals(loCategoryInfo.getMetaInfo().getVersionInd())){
 521  0
             throw new VersionMismatchException("LoCategory to be updated is not the current version");
 522  
         }
 523  
         
 524  
         // if state is changing from "active"
 525  1
         if (loCategory.getState().equals("active") && ( ! loCategoryInfo.getState().equals("active") )) {
 526  
                     // N.B. - ability to 'retire' LoCategory's that are still associated w/ active
 527  
                     // LO's is configured and enforced on the client
 528  0
                 List<LoInfo> loInfos = getLosByLoCategory(loCategoryId);
 529  0
                     if (null != loInfos) {
 530  
                                 // remove associations of this LoCategory from active LO's
 531  0
                             for (LoInfo info : loInfos) {
 532  0
                                     if (info.getState().equals("active"))  {
 533  
                                             try {
 534  0
                                                         removeLoCategoryFromLo(loCategoryId, info.getId());
 535  0
                                                 } catch (UnsupportedActionException uaee) {
 536  0
                                                     throw new OperationFailedException("Unable to update LoCategory: could not remove association with active LearningObjective", uaee);
 537  0
                                                 }
 538  
                                     }
 539  
                             }
 540  
                     }
 541  
         }
 542  
                 
 543  
         // if type is changing
 544  1
         if ( ! loCategory.getLoCategoryType().getId().equals(loCategoryInfo.getType()) ) {
 545  1
                 loCategory = cloneLoCategory(loCategory, loCategoryInfo);
 546  
         } else {
 547  0
                 loCategory = LearningObjectiveServiceAssembler.toLoCategory(loCategory, loCategoryInfo, loDao);
 548  0
                 loDao.update(loCategory);
 549  
         }
 550  1
         return LearningObjectiveServiceAssembler.toLoCategoryInfo(loCategory);
 551  
         }
 552  
 
 553  
     // inactivate current LoCategory & clone it w/ its relationships,
 554  
         // used when changing immutable type of LoCategory
 555  
         // https://test.kuali.org/confluence/display/KULSTG/DS+-+LO+Centrally+Maintain+Categories
 556  
         private LoCategory cloneLoCategory(LoCategory loCategory, LoCategoryInfo loCategoryInfo) throws DoesNotExistException, InvalidParameterException, OperationFailedException {
 557  1
             LoCategoryType catType = null;
 558  
             
 559  
             try {
 560  1
                 catType = loDao.fetch(LoCategoryType.class, loCategoryInfo.getType());
 561  0
             } catch (DoesNotExistException dnee) {
 562  0
                     throw new DoesNotExistException("Attempt to set LoCategory's type to nonexistent LoCategoryType", dnee);
 563  1
             }
 564  
                 
 565  
             // clone the existing LO
 566  1
             LoCategoryInfo newLoCategoryInfo = LearningObjectiveServiceAssembler.toLoCategoryInfo(loCategory);
 567  1
             newLoCategoryInfo.setType(catType.getId());
 568  1
             newLoCategoryInfo.setName(loCategoryInfo.getName());
 569  1
             LoCategory newLoCategory = loDao.create(LearningObjectiveServiceAssembler.toLoCategory(newLoCategoryInfo, loDao));
 570  
                 
 571  
             // clone Lo-LoCategory relations
 572  1
             List<Lo> catsLos = loDao.getLosByLoCategory(loCategory.getId());                 
 573  1
             for (Lo lo : catsLos) {
 574  
                     try {
 575  
                             // create the new one
 576  2
                                 loDao.addLoCategoryToLo(newLoCategory.getId(), lo.getId());
 577  
                                 // remove the old one
 578  2
                                 loDao.removeLoCategoryFromLo(loCategory.getId(), lo.getId());
 579  0
                         } catch (UnsupportedActionException uae) {
 580  0
                                 throw new OperationFailedException(uae.getMessage(), uae);
 581  2
                         }
 582  
             }
 583  
                 
 584  
             // suspend old LoCategory
 585  1
             loCategory.setState("Suspended");
 586  1
             loDao.update(loCategory);
 587  
                 
 588  1
             return newLoCategory;
 589  
         }
 590  
 
 591  
         /* (non-Javadoc)
 592  
          * @see org.kuali.student.lum.lo.service.LearningObjectiveService#validateLo(java.lang.String, org.kuali.student.lum.lo.dto.LoInfo)
 593  
          */
 594  
         @Override
 595  
         public List<ValidationResultInfo> validateLo(String validationType,
 596  
                         LoInfo loInfo) throws DoesNotExistException,
 597  
                         InvalidParameterException, MissingParameterException,
 598  
                         OperationFailedException {
 599  676
             checkForMissingParameter(validationType, "validationType");
 600  676
             checkForMissingParameter(loInfo, "loInfo");
 601  
 
 602  
      // this is the job of the validator not some hard coded value
 603  
 //            try{
 604  
 //                    String loDesc = loInfo.getDesc().getPlain();
 605  
 //                    checkForEmptyString(loDesc, "loInfo.Desc");
 606  
 //            } catch (NullPointerException e){
 607  
 //                        //do not checkForEmptyString
 608  
 //                }
 609  
             
 610  676
             ObjectStructureDefinition objStructure = this.getObjectStructure(LoInfo.class.getName());
 611  676
             Validator validator = validatorFactory.getValidator();
 612  676
             return validator.validateObject(loInfo, objStructure);
 613  
         }
 614  
 
 615  
         /* (non-Javadoc)
 616  
          * @see org.kuali.student.lum.lo.service.LearningObjectiveService#validateLoCategory(java.lang.String, org.kuali.student.lum.lo.dto.LoCategoryInfo)
 617  
          */
 618  
         @Override
 619  
         public List<ValidationResultInfo> validateLoCategory(String validationType,
 620  
                         LoCategoryInfo loCategoryInfo) throws DoesNotExistException,
 621  
                         InvalidParameterException, MissingParameterException,
 622  
                         OperationFailedException {
 623  10
             checkForMissingParameter(validationType, "validationType");
 624  10
             checkForMissingParameter(loCategoryInfo, "loCategoryInfo");
 625  
 
 626  
      // this is the job of the validator not some hard coded logic
 627  
 //            try{
 628  
 //                    String catDesc = loCategoryInfo.getDesc().getPlain();
 629  
 //                    checkForEmptyString(catDesc, "loCategoryInfo.Desc");
 630  
 //            } catch (NullPointerException e){
 631  
 //                        //do not checkForEmptyString
 632  
 //                }
 633  
 
 634  10
         ObjectStructureDefinition objStructure = this.getObjectStructure(LoCategoryInfo.class.getName());
 635  10
         Validator validator = validatorFactory.getValidator();
 636  10
         return validator.validateObject(loCategoryInfo, objStructure);
 637  
 
 638  
         }
 639  
 
 640  
         @Override
 641  
         public List<ValidationResultInfo> validateLoLoRelation(
 642  
                         String validationType, LoLoRelationInfo loLoRelationInfo)
 643  
                         throws DoesNotExistException, InvalidParameterException,
 644  
                         MissingParameterException, OperationFailedException {
 645  
 
 646  554
         ObjectStructureDefinition objStructure = this.getObjectStructure(LoLoRelationInfo.class.getName());
 647  554
         Validator validator = validatorFactory.getValidator();
 648  554
         return validator.validateObject(loLoRelationInfo, objStructure);
 649  
         }
 650  
 
 651  
     /**
 652  
      * Check for missing parameter and throw localized exception if missing
 653  
      *
 654  
      * @param param
 655  
      * @param parameter name
 656  
      * @throws MissingParameterException
 657  
      */
 658  
     private void checkForMissingParameter(Object param, String paramName)
 659  
             throws MissingParameterException {
 660  9706
         if (param == null) {
 661  16
             throw new MissingParameterException(paramName + " can not be null");
 662  
         }
 663  9690
     }
 664  
 
 665  
     /**
 666  
      * @param param
 667  
      * @param paramName
 668  
      * @throws MissingParameterException
 669  
      */
 670  
     private void checkForEmptyList(Object param, String paramName)
 671  
             throws MissingParameterException {
 672  1
         if (param != null && param instanceof List && ((List<?>)param).size() == 0) {
 673  0
             throw new MissingParameterException(paramName + " can not be an empty list");
 674  
         }
 675  1
     }
 676  
 
 677  
     // this is the job of the validator not some hard coded logic
 678  
     // besides it should create a validation result not a missing parameter exeception
 679  
 //    /**
 680  
 //     * @param param
 681  
 //     * @param paramName
 682  
 //     * @throws MissingParameterException
 683  
 //     */
 684  
 //    private void checkForEmptyString(String param, String paramName)
 685  
 //            throws MissingParameterException {
 686  
 //        if (param != null && "".equals(param.trim())) {
 687  
 //            throw new MissingParameterException(paramName + " can not be empty");
 688  
 //        }
 689  
 //    }
 690  
 //
 691  
     /**
 692  
      * @param loRepositoryKey
 693  
      * @param loCategoryInfo
 694  
      * @param loCategoryId
 695  
      * @throws MissingParameterException,OperationFailedException
 696  
      */
 697  
     private boolean doesLoCategoryExist(String loRepositoryKey, LoCategoryInfo loCategoryInfo, String loCategoryId)
 698  
             throws MissingParameterException, DataValidationErrorException {
 699  10
     if (loCategoryInfo.getName() == null)
 700  
     {
 701  1
      return false;
 702  
     }
 703  9
         boolean exists = false;
 704  9
             SearchRequest request = new SearchRequest();
 705  9
             request.setSearchKey("lo.search.loCategoriesByNameRepoTypeState");
 706  
             
 707  9
                  List<SearchParam> searchParams = new ArrayList<SearchParam>();
 708  9
                 SearchParam qpv1 = new SearchParam();
 709  9
                 qpv1.setKey("lo.queryParam.loCategoryName");
 710  9
                 qpv1.setValue(loCategoryInfo.getName().toLowerCase());
 711  9
                 searchParams.add(qpv1);
 712  9
                 SearchParam qpv2 = new SearchParam();
 713  9
                 qpv2.setKey("lo.queryParam.loCategoryRepo");
 714  9
                 qpv2.setValue(loRepositoryKey);
 715  9
                 searchParams.add(qpv2);
 716  9
                 SearchParam qpv3 = new SearchParam();
 717  9
                 qpv3.setKey("lo.queryParam.loCategoryType");
 718  9
                 qpv3.setValue(loCategoryInfo.getType());
 719  9
                 searchParams.add(qpv3);
 720  9
                 SearchParam qpv4 = new SearchParam();
 721  9
                 qpv4.setKey("lo.queryParam.loCategoryState");
 722  9
                 qpv4.setValue(loCategoryInfo.getState());
 723  9
                 searchParams.add(qpv4);
 724  
                 
 725  9
                 request.setParams(searchParams);
 726  
                 
 727  9
                 SearchResult result = search(request);
 728  
                 
 729  9
                 if(loCategoryId != null && !loCategoryId.trim().equals("")){
 730  3
                         if (result.getRows().size() > 0) {
 731  2
                                 for(SearchResultRow srrow : result.getRows()){
 732  2
                                         List<SearchResultCell> srCells = srrow.getCells();
 733  2
                                         if(srCells != null && srCells.size() > 0){
 734  2
                                                 for(SearchResultCell srcell : srCells){
 735  2
                                                         if(!srcell.getValue().equals(loCategoryId)) {
 736  2
                                 exists = true;
 737  
                             }
 738  
                                                 }
 739  
                                         }
 740  2
                                 }
 741  
                         }
 742  
                 }
 743  
                 else{
 744  6
                         if (result.getRows().size() > 0) {
 745  2
                 exists = true;
 746  
                         }
 747  
                 }
 748  9
         return exists;
 749  
     }
 750  
     
 751  
     @Override
 752  
     public ObjectStructureDefinition getObjectStructure(String objectTypeKey) {
 753  1240
         return dictionaryServiceDelegate.getObjectStructure(objectTypeKey);
 754  
     }
 755  
 
 756  
     @Override
 757  
     public List<String> getObjectTypes() {
 758  0
         return dictionaryServiceDelegate.getObjectTypes();
 759  
     }
 760  
 
 761  
         /* (non-Javadoc)
 762  
          * @see org.kuali.student.common.search.service.SearchService#getSearchCriteriaType(java.lang.String)
 763  
          */
 764  
     @Override
 765  
     public SearchCriteriaTypeInfo getSearchCriteriaType(
 766  
             String searchCriteriaTypeKey) throws DoesNotExistException,
 767  
             InvalidParameterException, MissingParameterException,
 768  
             OperationFailedException {
 769  
 
 770  0
         return searchManager.getSearchCriteriaType(searchCriteriaTypeKey);
 771  
     }
 772  
 
 773  
         /* (non-Javadoc)
 774  
          * @see org.kuali.student.common.search.service.SearchService#getSearchCriteriaTypes()
 775  
          */
 776  
     @Override
 777  
     public List<SearchCriteriaTypeInfo> getSearchCriteriaTypes()
 778  
     throws OperationFailedException {
 779  0
         return searchManager.getSearchCriteriaTypes();
 780  
     }
 781  
 
 782  
         /* (non-Javadoc)
 783  
          * @see org.kuali.student.common.search.service.SearchService#getSearchResultType(java.lang.String)
 784  
          */
 785  
     @Override
 786  
     public SearchResultTypeInfo getSearchResultType(String searchResultTypeKey)
 787  
     throws DoesNotExistException, InvalidParameterException,
 788  
     MissingParameterException, OperationFailedException {
 789  0
         checkForMissingParameter(searchResultTypeKey, "searchResultTypeKey");
 790  0
         return searchManager.getSearchResultType(searchResultTypeKey);
 791  
     }
 792  
 
 793  
         /* (non-Javadoc)
 794  
          * @see org.kuali.student.common.search.service.SearchService#getSearchResultTypes()
 795  
          */
 796  
     @Override
 797  
     public List<SearchResultTypeInfo> getSearchResultTypes()
 798  
     throws OperationFailedException {
 799  0
         return searchManager.getSearchResultTypes();
 800  
     }
 801  
 
 802  
         /* (non-Javadoc)
 803  
          * @see org.kuali.student.common.search.service.SearchService#getSearchType(java.lang.String)
 804  
          */
 805  
     @Override
 806  
     public SearchTypeInfo getSearchType(String searchTypeKey)
 807  
     throws DoesNotExistException, InvalidParameterException,
 808  
     MissingParameterException, OperationFailedException {
 809  0
         checkForMissingParameter(searchTypeKey, "searchTypeKey");
 810  0
         return searchManager.getSearchType(searchTypeKey);
 811  
     }
 812  
 
 813  
         /* (non-Javadoc)
 814  
          * @see org.kuali.student.common.search.service.SearchService#getSearchTypes()
 815  
          */
 816  
     @Override
 817  
     public List<SearchTypeInfo> getSearchTypes()
 818  
     throws OperationFailedException {
 819  0
         return searchManager.getSearchTypes();
 820  
     }
 821  
 
 822  
         /* (non-Javadoc)
 823  
          * @see org.kuali.student.common.search.service.SearchService#getSearchTypesByCriteria(java.lang.String)
 824  
          */
 825  
     @Override
 826  
     public List<SearchTypeInfo> getSearchTypesByCriteria(
 827  
             String searchCriteriaTypeKey) throws DoesNotExistException,
 828  
             InvalidParameterException, MissingParameterException,
 829  
             OperationFailedException {
 830  0
         checkForMissingParameter(searchCriteriaTypeKey, "searchCriteriaTypeKey");
 831  0
         return searchManager.getSearchTypesByCriteria(searchCriteriaTypeKey);
 832  
     }
 833  
 
 834  
         /* (non-Javadoc)
 835  
          * @see org.kuali.student.common.search.service.SearchService#getSearchTypesByResult(java.lang.String)
 836  
          */
 837  
     @Override
 838  
     public List<SearchTypeInfo> getSearchTypesByResult(
 839  
             String searchResultTypeKey) throws DoesNotExistException,
 840  
             InvalidParameterException, MissingParameterException,
 841  
             OperationFailedException {
 842  0
         checkForMissingParameter(searchResultTypeKey, "searchResultTypeKey");
 843  0
         return searchManager.getSearchTypesByResult(searchResultTypeKey);
 844  
     }
 845  
 
 846  
         @Override
 847  
         @Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class})
 848  
         public LoLoRelationInfo createLoLoRelation(String loId, String relatedLoId,
 849  
                         String loLoRelationType, LoLoRelationInfo loLoRelationInfo)
 850  
                         throws AlreadyExistsException, 
 851  
                         DataValidationErrorException, DoesNotExistException,
 852  
                         InvalidParameterException, MissingParameterException,
 853  
                         OperationFailedException, PermissionDeniedException {
 854  558
             checkForMissingParameter(loId, "loId");
 855  557
             checkForMissingParameter(relatedLoId, "relatedLoId");
 856  556
             checkForMissingParameter(loLoRelationType, "loLoRelationType");
 857  555
             checkForMissingParameter(loLoRelationInfo, "loLoRelationInfo");
 858  
             
 859  
                 // Validate LoLoRelation
 860  554
                 List<ValidationResultInfo> val = validateLoLoRelation("SYSTEM", loLoRelationInfo);
 861  554
                 if(null != val && val.size() > 0) {
 862  0
                         for (ValidationResultInfo result : val) {
 863  0
                                 System.err.println("Validation error. Element: " + result.getElement() + ",  Value: " + result.getMessage());
 864  
                         }
 865  0
                         throw new DataValidationErrorException("Validation error!", val);
 866  
                 }
 867  
             
 868  554
             if (null == loLoRelationInfo.getState()) {
 869  2
                     loLoRelationInfo.setState(DtoConstants.STATE_DRAFT);
 870  
             }
 871  554
             Lo lo = loDao.fetch(Lo.class, loId);
 872  554
             Lo relatedLo = loDao.fetch(Lo.class, relatedLoId);
 873  554
             LoLoRelationType type = loDao.fetch(LoLoRelationType.class, loLoRelationType);
 874  554
             loLoRelationInfo.setLoId(loId);
 875  554
             loLoRelationInfo.setRelatedLoId(relatedLoId);
 876  554
             loLoRelationInfo.setType(loLoRelationType);
 877  
             
 878  554
             LoLoRelation relation = null;
 879  
             try {
 880  554
                     relation = LearningObjectiveServiceAssembler.toLoLoRelation(false, loLoRelationInfo, loDao);
 881  0
             } catch (VersionMismatchException vme) {
 882  
                     // should never happen in a create call, but
 883  0
                     throw new OperationFailedException("VersionMismatchException caught during LoLoRelation creation");
 884  554
             }
 885  554
             relation.setLo(lo);
 886  554
             relation.setRelatedLo(relatedLo);
 887  554
             relation.setLoLoRelationType(type);
 888  
             
 889  554
             relation = loDao.create(relation);
 890  
             
 891  554
                 return LearningObjectiveServiceAssembler.toLoLoRelationInfo(relation);
 892  
         }
 893  
 
 894  
         @Override
 895  
         @Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class})
 896  
         public StatusInfo deleteLoLoRelation(String loLoRelationId)
 897  
                         throws DoesNotExistException, InvalidParameterException,
 898  
                         MissingParameterException, OperationFailedException,
 899  
                         PermissionDeniedException {
 900  18
             checkForMissingParameter(loLoRelationId, "loLoRelationId");
 901  
             
 902  18
             loDao.deleteLoLoRelation(loLoRelationId);
 903  
             
 904  18
                 return new StatusInfo();
 905  
         }
 906  
 
 907  
         @Override
 908  
     @Transactional(readOnly=true)
 909  
         public LoLoRelationInfo getLoLoRelation(String loLoRelationId)
 910  
                         throws DoesNotExistException, InvalidParameterException,
 911  
                         MissingParameterException, OperationFailedException {
 912  4
             checkForMissingParameter(loLoRelationId, "loLoRelationId");
 913  3
                 return LearningObjectiveServiceAssembler.toLoLoRelationInfo(loDao.fetch(LoLoRelation.class, loLoRelationId));
 914  
         }
 915  
 
 916  
         @Override
 917  
     @Transactional(readOnly=true)
 918  
         public List<LoLoRelationInfo> getLoLoRelationsByLoId(String loId)
 919  
                         throws DoesNotExistException, InvalidParameterException,
 920  
                         MissingParameterException, OperationFailedException {
 921  52
                 List<LoLoRelation> llRelations = loDao.getLoLoRelationsByLoId(loId);
 922  52
                 return LearningObjectiveServiceAssembler.toLoLoRelationInfos(llRelations);
 923  
         }
 924  
 
 925  
         @Override
 926  
     @Transactional(readOnly=true)
 927  
         public List<LoInfo> getLosByRelatedLoId(String relatedLoId,
 928  
                         String loLoRelationType) throws DoesNotExistException,
 929  
                         InvalidParameterException, MissingParameterException,
 930  
                         OperationFailedException {
 931  0
                 List<Lo> relatedLos = loDao.getLosByRelatedLoId(relatedLoId, loLoRelationType);
 932  0
                 return LearningObjectiveServiceAssembler.toLoInfos(relatedLos);
 933  
         }
 934  
 
 935  
         @Override
 936  
     @Transactional(readOnly=true)
 937  
         public List<LoInfo> getRelatedLosByLoId(String loId, String loLoRelationTypeKey)
 938  
                         throws DoesNotExistException, InvalidParameterException,
 939  
                         MissingParameterException, OperationFailedException {
 940  390
             checkForMissingParameter(loId, "loId");
 941  389
             checkForMissingParameter(loLoRelationTypeKey, "loLoRelationTypeKey");
 942  388
             List<Lo> relatedLos = loDao.getRelatedLosByLoId(loId, loLoRelationTypeKey);
 943  388
                 return LearningObjectiveServiceAssembler.toLoInfos(relatedLos);
 944  
         }
 945  
 
 946  
         @Override
 947  
         @Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class})
 948  
         public LoLoRelationInfo updateLoLoRelation(String loLoRelationId,
 949  
                         LoLoRelationInfo loLoRelationInfo)
 950  
                         throws DataValidationErrorException, DoesNotExistException,
 951  
                         InvalidParameterException, MissingParameterException,
 952  
                         OperationFailedException, PermissionDeniedException,
 953  
                         VersionMismatchException {
 954  
                 
 955  
 
 956  
                 // Validate LoLoRelation
 957  0
                 List<ValidationResultInfo> val = validateLoLoRelation("SYSTEM", loLoRelationInfo);
 958  0
                 if(null != val && val.size() > 0) {
 959  0
                         throw new DataValidationErrorException("Validation error!", val);
 960  
                 }
 961  
 
 962  
             
 963  0
                 return null;
 964  
         }
 965  
 
 966  
         @Override
 967  
         @Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class})
 968  
         public LoCategoryInfo createLoCategory(String loRepositoryKey,
 969  
                         String loCategoryTypeKey, LoCategoryInfo loCategoryInfo)
 970  
                         throws DataValidationErrorException, DoesNotExistException,
 971  
                         InvalidParameterException, MissingParameterException,
 972  
                         OperationFailedException, PermissionDeniedException {
 973  7
             checkForMissingParameter(loRepositoryKey, "loRepositoryKey");
 974  7
             checkForMissingParameter(loCategoryTypeKey, "loCategoryTypeKey");
 975  7
             checkForMissingParameter(loCategoryInfo, "loCategoryInfo");
 976  
             
 977  
                 // Validate LoCategory
 978  7
                 List<ValidationResultInfo> val = validateLoCategory("SYSTEM", loCategoryInfo);
 979  
 
 980  
         //kslum-136 - don't allow dups w/ same name (case insensitive), type, state & repository       
 981  7
         if (doesLoCategoryExist(loRepositoryKey, loCategoryInfo, null)) {
 982  2
             ValidationResultInfo vr = new ValidationResultInfo();
 983  2
             vr.setElement("LO Category Name");
 984  2
             vr.setError("LO Category already exists");
 985  2
             val.add(vr);
 986  
         }
 987  7
         if(null != val && val.size() > 0) {
 988  3
                         for (ValidationResultInfo result : val) {
 989  3
                                 System.err.println("Validation error. Element: " + result.getElement() + ",  Value: " + result.getMessage());
 990  
                         }
 991  3
                         throw new DataValidationErrorException("Validation error!", val);
 992  
                 }
 993  
 
 994  4
             LoCategory category = LearningObjectiveServiceAssembler.toLoCategory(loCategoryInfo, loDao);
 995  4
             LoCategoryType loCatType = loDao.fetch(LoCategoryType.class, loCategoryTypeKey);
 996  4
             category.setLoCategoryType(loCatType);
 997  4
             LoRepository loRepository = loDao.fetch(LoRepository.class, loRepositoryKey);
 998  4
             category.setLoRepository(loRepository);
 999  4
             loDao.create(category);
 1000  4
                 return LearningObjectiveServiceAssembler.toLoCategoryInfo(category);
 1001  
         }
 1002  
 
 1003  
         @Override
 1004  
     @Transactional(readOnly=true)
 1005  
         public LoCategoryTypeInfo getLoCategoryType(String loCategoryTypeKey)
 1006  
                         throws DoesNotExistException, InvalidParameterException,
 1007  
                         MissingParameterException, OperationFailedException {
 1008  0
             checkForMissingParameter(loCategoryTypeKey, "loCategoryTypeKey");
 1009  0
             LoCategoryType loCatType = loDao.fetch(LoCategoryType.class, loCategoryTypeKey);
 1010  0
             return LearningObjectiveServiceAssembler.toLoCategoryTypeInfo(loCatType);
 1011  
         }
 1012  
 
 1013  
         @Override
 1014  
     @Transactional(readOnly=true)
 1015  
         public List<LoCategoryTypeInfo> getLoCategoryTypes()
 1016  
                         throws OperationFailedException {
 1017  1
                 List<LoCategoryType> categoryTypes = loDao.find(LoCategoryType.class);
 1018  1
                 return LearningObjectiveServiceAssembler.toLoCategoryTypeInfos(categoryTypes);
 1019  
         }
 1020  
 
 1021  
         @Override
 1022  
     @Transactional(readOnly=true)
 1023  
         public List<LoInfo> getLosByRepository(String loRepositoryKey,
 1024  
                         String loTypeKey, String loStateKey)
 1025  
                         throws InvalidParameterException, MissingParameterException,
 1026  
                         OperationFailedException {
 1027  0
             checkForMissingParameter(loRepositoryKey, "loRepositoryKey");
 1028  0
             List<Lo> los = loDao.getLosByRepository(loRepositoryKey);
 1029  0
                 return LearningObjectiveServiceAssembler.toLoInfos(los);
 1030  
         }
 1031  
 
 1032  
         @Override
 1033  
         public SearchResult search(SearchRequest searchRequest) throws MissingParameterException {
 1034  10
         checkForMissingParameter(searchRequest, "searchRequest");
 1035  10
         SearchResult result =  searchManager.search(searchRequest, loDao);
 1036  10
         if("lo.search.loByCategory".equals(searchRequest.getSearchKey())){
 1037  
 //                for(SearchParam param:searchRequest.getParams()){
 1038  
 //                        if("lo.queryParam.groupCategories".equals(param.getKey())&&"true".equals(param.getValue())){
 1039  0
                 groupCategories(result);
 1040  
 //                        }
 1041  
 //                }
 1042  
         }
 1043  
         
 1044  10
         return result;
 1045  
         }
 1046  
 
 1047  
         //Updates search results grouping category names as a comma delimited list
 1048  
         private void groupCategories(SearchResult result) {
 1049  0
                 Map<String,SearchResultCell> idToCellMap = new HashMap<String,SearchResultCell>();
 1050  0
                 for(Iterator<SearchResultRow> iter = result.getRows().iterator();iter.hasNext();){
 1051  0
                         SearchResultRow row = iter.next();
 1052  0
                         SearchResultCell categoryCell = null;
 1053  0
                         String loId = null;
 1054  
                         //Get search result cell values
 1055  0
                         for(SearchResultCell cell:row.getCells()){
 1056  0
                                 if("lo.resultColumn.categoryName".equals(cell.getKey())){
 1057  0
                                         categoryCell = cell;
 1058  0
                                         break;
 1059  0
                                 }else if("lo.resultColumn.loId".equals(cell.getKey())){
 1060  0
                                         loId = cell.getValue();
 1061  
                                 }
 1062  
                         }
 1063  
                         //If a row exists with the same loId, append the category to the existing row and remove the current row.
 1064  0
                         if(loId!=null){
 1065  0
                                 if(idToCellMap.containsKey(loId)){
 1066  0
                                         SearchResultCell cell = idToCellMap.get(loId);
 1067  0
                                         if(cell == null){
 1068  0
                                                 cell = new SearchResultCell("lo.resultColumn.categoryName","");
 1069  0
                                                 idToCellMap.put(loId, cell);
 1070  
                                         }
 1071  0
                                         if(categoryCell!=null){
 1072  0
                                                 if(cell.getValue()==null||cell.getValue().isEmpty()){
 1073  0
                                                         cell.setValue(categoryCell.getValue());
 1074  0
                                                 }else if(categoryCell.getValue()!=null && !categoryCell.getValue().isEmpty()){
 1075  0
                                                         cell.setValue(cell.getValue()+", "+categoryCell.getValue());
 1076  
                                                 }
 1077  
                                         }
 1078  
                                         //Remove this row since we alreay have a mapping to a row with this lo Id
 1079  0
                                         iter.remove();
 1080  0
                                 } else {
 1081  
                                         //Otherwise add a mapping and continue
 1082  0
                                         idToCellMap.put(loId, categoryCell);
 1083  
                                 }
 1084  
                         }
 1085  0
                 }
 1086  0
         }
 1087  
         
 1088  
 }