001 /** 002 * Copyright 2005-2011 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.location.impl.campus; 017 018 import org.apache.commons.lang.StringUtils; 019 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException; 020 import org.kuali.rice.krad.service.BusinessObjectService; 021 import org.kuali.rice.location.api.campus.Campus; 022 import org.kuali.rice.location.api.campus.CampusService; 023 import org.kuali.rice.location.api.campus.CampusType; 024 025 import java.util.ArrayList; 026 import java.util.Collections; 027 import java.util.List; 028 029 import static java.util.Collections.singletonMap; 030 031 public class CampusServiceImpl implements CampusService { 032 033 private BusinessObjectService boService; 034 035 /** 036 * @see org.kuali.rice.location.api.campus.CampusService#getCampus(String code) 037 */ 038 @Override 039 public Campus getCampus(String code) { 040 if (StringUtils.isBlank(code)) { 041 throw new RiceIllegalArgumentException("code is blank"); 042 } 043 044 CampusBo campusBo = boService.findByPrimaryKey(CampusBo.class, singletonMap("code", code)); 045 046 return CampusBo.to(campusBo); 047 } 048 049 /** 050 * @see org.kuali.rice.location.api.campus.CampusService#findAllCampuses 051 */ 052 @Override 053 public List<Campus> findAllCampuses() { 054 List<CampusBo> campusBos = (List<CampusBo>) boService.findMatching(CampusBo.class, singletonMap("active", "true")); 055 056 return this.convertListOfCampusBosToImmutables(campusBos); 057 } 058 059 /** 060 * @see org.kuali.rice.location.api.campus.CampusService#getCampusType(String code) 061 */ 062 @Override 063 public CampusType getCampusType(String code) { 064 if (StringUtils.isBlank(code)) { 065 throw new RiceIllegalArgumentException("code is blank"); 066 } 067 068 CampusTypeBo campusTypeBo = boService.findByPrimaryKey(CampusTypeBo.class, singletonMap("code", code)); 069 070 return CampusTypeBo.to(campusTypeBo); 071 } 072 073 /** 074 * @see org.kuali.rice.location.api.campus.CampusService#findAllCampusTypes 075 */ 076 @Override 077 public List<CampusType> findAllCampusTypes() { 078 List<CampusTypeBo> campusTypeBos = (List<CampusTypeBo>)boService.findMatching(CampusTypeBo.class, singletonMap("active", "true")); 079 return this.convertListOfCampusTypesBosToImmutables(campusTypeBos); 080 } 081 082 public void setBusinessObjectService(BusinessObjectService boService) { 083 this.boService = boService; 084 } 085 086 private List<Campus> convertListOfCampusBosToImmutables(List<CampusBo> campusBos) { 087 ArrayList<Campus> campuses = new ArrayList<Campus>(); 088 for (CampusBo bo : campusBos) { 089 Campus campus = CampusBo.to(bo); 090 campuses.add(campus) ; 091 } 092 return Collections.unmodifiableList(campuses); 093 } 094 095 private List<CampusType> convertListOfCampusTypesBosToImmutables(List<CampusTypeBo> campusTypeBos) { 096 ArrayList<CampusType> campusTypes = new ArrayList<CampusType>(); 097 for (CampusTypeBo bo : campusTypeBos) { 098 CampusType campusType = CampusTypeBo.to(bo); 099 campusTypes.add(campusType) ; 100 } 101 return Collections.unmodifiableList(campusTypes); 102 } 103 }