Coverage Report - org.kuali.rice.krms.impl.repository.TermBoServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
TermBoServiceImpl
0%
0/46
0%
0/22
3.125
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl1.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.krms.impl.repository;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.Collection;
 20  
 import java.util.Collections;
 21  
 import java.util.HashMap;
 22  
 import java.util.List;
 23  
 import java.util.Map;
 24  
 
 25  
 import org.apache.commons.lang.StringUtils;
 26  
 import org.kuali.rice.krad.service.BusinessObjectService;
 27  
 import org.kuali.rice.krms.api.repository.term.TermDefinition;
 28  
 import org.kuali.rice.krms.api.repository.term.TermResolverDefinition;
 29  
 import org.kuali.rice.krms.api.repository.term.TermSpecificationDefinition;
 30  
 import org.springframework.util.CollectionUtils;
 31  
 
 32  
 /**
 33  
  * Implementation of {@link TermBoService}
 34  
  * 
 35  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 36  
  *
 37  
  */
 38  0
 public class TermBoServiceImpl implements TermBoService {
 39  
         
 40  
         private BusinessObjectService businessObjectService;
 41  
 
 42  
         /**
 43  
          * @param businessObjectService the businessObjectService to set
 44  
          */
 45  
         public void setBusinessObjectService(BusinessObjectService businessObjectService) {
 46  0
                 this.businessObjectService = businessObjectService;
 47  0
         }
 48  
         
 49  
         /**
 50  
          * @see org.kuali.rice.krms.impl.repository.TermBoService#getTermSpecificationById(java.lang.String)
 51  
          */
 52  
         @Override
 53  
         public TermSpecificationDefinition getTermSpecificationById(String id) {
 54  0
                 TermSpecificationBo termSpecificationBo = 
 55  
                         businessObjectService.findBySinglePrimaryKey(TermSpecificationBo.class, id);
 56  0
                 return TermSpecificationDefinition.Builder.create(termSpecificationBo).build();
 57  
         }
 58  
         
 59  
         /**
 60  
          * @see org.kuali.rice.krms.impl.repository.TermBoService#createTermSpecification(org.kuali.rice.krms.api.repository.term.TermSpecificationDefinition)
 61  
          */
 62  
         @Override
 63  
         public TermSpecificationDefinition createTermSpecification(TermSpecificationDefinition termSpec) {
 64  0
                 if (!StringUtils.isBlank(termSpec.getId())) {
 65  0
                         throw new IllegalArgumentException("for creation, TermSpecification.id must be null");
 66  
                 }
 67  
                 
 68  0
                 TermSpecificationBo termSpecBo = TermSpecificationBo.from(termSpec);
 69  
                 
 70  0
                 businessObjectService.save(termSpecBo);
 71  
                 
 72  0
                 return TermSpecificationBo.to(termSpecBo);
 73  
         }
 74  
         
 75  
         /**
 76  
          * @see org.kuali.rice.krms.impl.repository.TermBoService#createTermDefinition(org.kuali.rice.krms.api.repository.term.TermDefinition)
 77  
          */
 78  
         @Override
 79  
         public TermDefinition createTermDefinition(TermDefinition termDef) {
 80  0
                 if (!StringUtils.isBlank(termDef.getId())) {
 81  0
                         throw new IllegalArgumentException("for creation, TermDefinition.id must be null");
 82  
                 }
 83  
                 
 84  0
                 TermBo termBo = TermBo.from(termDef);
 85  
                 
 86  0
                 businessObjectService.save(termBo);
 87  
                 
 88  0
                 return TermBo.to(termBo);
 89  
         }
 90  
         
 91  
         /**
 92  
          * @see org.kuali.rice.krms.impl.repository.TermBoService#createTermResolver(org.kuali.rice.krms.api.repository.term.TermResolverDefinition)
 93  
          */
 94  
         @Override
 95  
         public TermResolverDefinition createTermResolver(TermResolverDefinition termResolver) {
 96  0
                 if (!StringUtils.isBlank(termResolver.getId())) {
 97  0
                         throw new IllegalArgumentException("for creation, TermResolverDefinition.id must be null");
 98  
                 }
 99  
                 
 100  0
                 TermResolverBo termResolverBo = TermResolverBo.from(termResolver);
 101  
                 
 102  0
                 termResolverBo = (TermResolverBo)businessObjectService.save(termResolverBo);
 103  
                 
 104  0
                 return TermResolverBo.to(termResolverBo);
 105  
         }
 106  
         
 107  
         /**
 108  
          * @see org.kuali.rice.krms.impl.repository.TermBoService#getTermById(java.lang.String)
 109  
          */
 110  
         @Override
 111  
         public TermDefinition getTermById(String id) {
 112  0
                 TermDefinition result = null;
 113  
                 
 114  0
                 if (StringUtils.isBlank(id)) {
 115  0
                         throw new IllegalArgumentException("id must not be blank or null");
 116  
                 }
 117  0
                 TermBo termBo = businessObjectService.findBySinglePrimaryKey(TermBo.class, id);
 118  
                 
 119  0
                 if (termBo != null) {
 120  0
                         result= TermBo.to(termBo);
 121  
                 }
 122  
                 
 123  0
                 return result;
 124  
         }
 125  
         
 126  
         /**
 127  
          * @see org.kuali.rice.krms.impl.repository.TermBoService#getTermResolverById(java.lang.String)
 128  
          */
 129  
         @Override
 130  
         public TermResolverDefinition getTermResolverById(String id) {
 131  0
                 TermResolverDefinition result = null;
 132  
                 
 133  0
                 if (StringUtils.isBlank(id)) {
 134  0
                         throw new IllegalArgumentException("id must not be blank or null");
 135  
                 }
 136  0
                 TermResolverBo termResolverBo = businessObjectService.findBySinglePrimaryKey(TermResolverBo.class, id);
 137  
                 
 138  0
                 if (termResolverBo != null) {
 139  0
                         result = TermResolverBo.to(termResolverBo);
 140  
                 }
 141  
                 
 142  0
                 return result;
 143  
         }
 144  
         
 145  
         /**
 146  
          * @see org.kuali.rice.krms.impl.repository.TermBoService#getTermResolversByContextId(java.lang.String)
 147  
          */
 148  
         @SuppressWarnings("unchecked")
 149  
         @Override
 150  
         public List<TermResolverDefinition> getTermResolversByContextId(String id) {
 151  0
                 List<TermResolverDefinition> results = null;
 152  
                 
 153  0
                 if (StringUtils.isBlank(id)) {
 154  0
                         throw new IllegalArgumentException("id must not be blank or null");
 155  
                 }
 156  
                 
 157  0
                 Map fieldValues = new HashMap();
 158  0
                 fieldValues.put("contextId", id);
 159  
                 
 160  0
                 Collection<TermResolverBo> termResolverBos = businessObjectService.findMatching(TermResolverBo.class, fieldValues);
 161  
                 
 162  0
                 if (!CollectionUtils.isEmpty(termResolverBos)) {
 163  0
                         results = new ArrayList<TermResolverDefinition>(termResolverBos.size());
 164  
                         
 165  0
                         for (TermResolverBo termResolverBo : termResolverBos) if (termResolverBo != null) {
 166  0
                                 results.add(TermResolverBo.to(termResolverBo));
 167  
                         }
 168  
                 } else {
 169  0
                         results = Collections.emptyList();
 170  
                 }
 171  
                 
 172  0
                 return results;
 173  
         }
 174  
 
 175  
 }