View Javadoc

1   /**
2    * Copyright 2005-2013 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.coreservice.impl.namespace;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
20  import org.kuali.rice.coreservice.api.namespace.Namespace;
21  import org.kuali.rice.coreservice.api.namespace.NamespaceService;
22  import org.kuali.rice.krad.service.BusinessObjectService;
23  
24  import java.util.ArrayList;
25  import java.util.Collections;
26  import java.util.List;
27  
28  import static java.util.Collections.singletonMap;
29  
30  public class NamespaceServiceImpl implements NamespaceService {
31  
32      private BusinessObjectService boService;
33  
34      @Override
35  	public Namespace getNamespace(String code) {
36          if (StringUtils.isBlank(code)) {
37              throw new RiceIllegalArgumentException("the code is blank");
38          } 
39  
40          return NamespaceBo.to(boService.findByPrimaryKey(NamespaceBo.class, singletonMap("code", code)));
41  	}
42  
43      @Override
44      public List<Namespace> findAllNamespaces() {
45          List<NamespaceBo> namespaceBos = (List<NamespaceBo>) boService.findAll(NamespaceBo.class);
46          List<Namespace> namespaces = new ArrayList<Namespace>();
47          
48          for (NamespaceBo bo : namespaceBos) {
49              namespaces.add(NamespaceBo.to(bo));
50          }
51          return Collections.unmodifiableList(namespaces);
52      }
53  
54      public void setBusinessObjectService(BusinessObjectService boService) {
55          this.boService = boService;
56      }
57  }