View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.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/ecl2.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.location.impl.campus;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
20  import org.kuali.rice.krad.service.BusinessObjectService;
21  import org.kuali.rice.location.api.campus.Campus;
22  import org.kuali.rice.location.api.campus.CampusService;
23  import org.kuali.rice.location.api.campus.CampusType;
24  
25  import java.util.ArrayList;
26  import java.util.Collections;
27  import java.util.List;
28  
29  import static java.util.Collections.singletonMap;
30  
31  public class CampusServiceImpl implements CampusService {
32  
33  	private BusinessObjectService boService;
34  	
35  	/**
36       * @see org.kuali.rice.location.api.campus.CampusService#getCampus(String code)
37       */
38  	@Override
39  	public Campus getCampus(String code) {
40  		if (StringUtils.isBlank(code)) {
41              throw new RiceIllegalArgumentException("code is blank");
42          }
43  
44          CampusBo campusBo = boService.findByPrimaryKey(CampusBo.class, singletonMap("code", code));
45  
46          return CampusBo.to(campusBo);
47  	}
48  
49  	/**
50       * @see org.kuali.rice.location.api.campus.CampusService#findAllCampuses
51       */
52  	@Override
53  	public List<Campus> findAllCampuses() {
54  		List<CampusBo> campusBos = (List<CampusBo>) boService.findMatching(CampusBo.class, singletonMap("active", "true"));
55  
56          return this.convertListOfCampusBosToImmutables(campusBos);
57  	}
58  
59  	/**
60       * @see org.kuali.rice.location.api.campus.CampusService#getCampusType(String code)
61       */
62  	@Override
63  	public CampusType getCampusType(String code) {
64  		if (StringUtils.isBlank(code)) {
65              throw new RiceIllegalArgumentException("code is blank");
66          }
67  
68  		CampusTypeBo campusTypeBo = boService.findByPrimaryKey(CampusTypeBo.class, singletonMap("code", code));
69  
70          return CampusTypeBo.to(campusTypeBo);
71  	}
72  
73  	/**
74       * @see org.kuali.rice.location.api.campus.CampusService#findAllCampusTypes
75       */
76  	@Override
77  	public List<CampusType> findAllCampusTypes() {
78  		List<CampusTypeBo> campusTypeBos = (List<CampusTypeBo>)boService.findMatching(CampusTypeBo.class, singletonMap("active", "true"));
79  		return this.convertListOfCampusTypesBosToImmutables(campusTypeBos);
80  	}
81      
82      public void setBusinessObjectService(BusinessObjectService boService) {
83          this.boService = boService;
84      }
85  
86      private List<Campus> convertListOfCampusBosToImmutables(List<CampusBo> campusBos) {
87          ArrayList<Campus> campuses = new ArrayList<Campus>();
88          for (CampusBo bo : campusBos) {
89              Campus campus = CampusBo.to(bo);
90              campuses.add(campus) ;
91          }
92          return Collections.unmodifiableList(campuses);
93      }
94      
95      private List<CampusType> convertListOfCampusTypesBosToImmutables(List<CampusTypeBo> campusTypeBos) {
96          ArrayList<CampusType> campusTypes = new ArrayList<CampusType>();
97          for (CampusTypeBo bo : campusTypeBos) {
98              CampusType campusType = CampusTypeBo.to(bo);
99              campusTypes.add(campusType) ;
100         }
101         return Collections.unmodifiableList(campusTypes);
102     }
103 }