View Javadoc
1   /**
2    * Copyright 2005-2015 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 static java.util.Collections.singletonMap;
19  
20  import java.util.ArrayList;
21  import java.util.Collections;
22  import java.util.List;
23  
24  import org.apache.commons.lang.StringUtils;
25  import org.kuali.rice.core.api.criteria.QueryResults;
26  import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
27  import org.kuali.rice.coreservice.api.namespace.Namespace;
28  import org.kuali.rice.coreservice.api.namespace.NamespaceService;
29  import org.kuali.rice.krad.data.CompoundKey;
30  import org.kuali.rice.krad.data.DataObjectService;
31  import org.springframework.beans.factory.annotation.Required;
32  import org.springframework.transaction.annotation.Transactional;
33  
34  @Transactional(readOnly=true)
35  public class NamespaceServiceImpl implements NamespaceService {
36      private DataObjectService dataObjectService;
37  
38      @Override
39  	public Namespace getNamespace(String code) {
40          if (StringUtils.isBlank(code)) {
41              throw new RiceIllegalArgumentException("the code is blank");
42          }
43          return NamespaceBo.to(dataObjectService.find(NamespaceBo.class, new CompoundKey(singletonMap("code", code))));
44  	}
45  
46      @Override
47      public List<Namespace> findAllNamespaces() {
48          QueryResults<NamespaceBo> namespaceBos = dataObjectService.findAll(NamespaceBo.class);
49          List<Namespace> namespaces = new ArrayList<Namespace>();
50          if(namespaceBos != null){
51              for (NamespaceBo bo : namespaceBos.getResults()) {
52                  namespaces.add(NamespaceBo.to(bo));
53              }
54          }
55  
56          return Collections.unmodifiableList(namespaces);
57      }
58  
59      public DataObjectService getDataObjectService() {
60          return dataObjectService;
61      }
62      @Required
63      public void setDataObjectService(DataObjectService dataObjectService) {
64          this.dataObjectService = dataObjectService;
65      }
66  }