View Javadoc
1   /**
2    * Copyright 2005-2014 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.krms.impl.repository;
17  
18  import java.util.List;
19  import java.util.Map;
20  
21  import org.kuali.rice.krms.api.repository.type.KrmsAttributeDefinition;
22  import org.kuali.rice.krms.api.repository.type.KrmsTypeDefinition;
23  import org.springframework.cache.annotation.CacheEvict;
24  import org.springframework.cache.annotation.Cacheable;
25  
26  public interface KrmsAttributeDefinitionService {
27  
28      /**
29       * This will create a {@link KrmsAttributeDefinition} exactly like the parameter passed in.
30       *
31       * @param attributeDefinition - KrmsAttributeDefinition
32       * @throws IllegalArgumentException if the attribute definition is null
33       * @throws IllegalStateException if the attribute definition already exists in the system
34       */
35      @CacheEvict(value={KrmsAttributeDefinition.Cache.NAME}, allEntries = true)
36  	public KrmsAttributeDefinition createAttributeDefinition(KrmsAttributeDefinition attributeDefinition);
37  
38      /**
39       * This will update a {@link KrmsAttributeDefinition}.
40       *
41       *
42       * @param attributeDefinition - KrmsAttributeDefinition
43       * @throws IllegalArgumentException if the attribute definition is null
44       * @throws IllegalStateException if the attribute definition does not exist in the system
45       */
46      @CacheEvict(value={KrmsAttributeDefinition.Cache.NAME}, allEntries = true)
47  	public void updateAttributeDefinition(KrmsAttributeDefinition attributeDefinition);
48  
49      /**
50       * Lookup a KrmsAttributeDefinition based on the given id.
51       *
52       * @param id the given KrmsAttributeDefinition id
53       * @return a KrmsAttributeDefinition object with the given id.  A null reference is returned if an invalid or
54       *         non-existant id is supplied.
55       */
56      @Cacheable(value= KrmsAttributeDefinition.Cache.NAME, key="'attributeDefinitionId=' + #p0")
57  	public KrmsAttributeDefinition getAttributeDefinitionById(String id);
58  
59      /**
60       * Get a KrmsAttributeDefinition object based on name and namespace
61       *
62       * @param name the given name
63       * @param namespace the given type namespace
64       * @return A KrmsAttributeDefinition object with the given namespace and name if one with that name and namespace
65       *         exists.  Otherwise, null is returned.
66       * @throws IllegalStateException if multiple KrmsAttributeDefinitions exist with the same name and namespace
67       */
68      @Cacheable(value= KrmsAttributeDefinition.Cache.NAME, key="'namespaceCode=' + #p0 + '|' + 'name=' + #p1")
69  	public KrmsAttributeDefinition getAttributeDefinitionByNameAndNamespace(String name, String namespace);
70  
71     /**
72       * Returns all KrmsAttributeDefinition that for a given namespace.
73       *
74       * @return all KrmsAttributeDefinition for a namespace
75       */
76      @Cacheable(value= KrmsAttributeDefinition.Cache.NAME, key="'namespace=' + #p0")
77  	public List<KrmsAttributeDefinition> findAttributeDefinitionsByNamespace(String namespace);
78  
79  
80      /**
81        * Returns all KrmsAttributeDefinition that for a given type.
82        *
83        * @return all KrmsAttributeDefinition for a type.  May be empty, will not be null;
84        */
85      @Cacheable(value= KrmsAttributeDefinition.Cache.NAME, key="'typeId=' + #p0")
86       public List<KrmsAttributeDefinition> findAttributeDefinitionsByType(String typeId);
87  
88  
89      /**
90       * Returns all KrmsAttributeDefinitions
91       *
92       * @return all KrmsAttributeDefinitions
93       */
94      @Cacheable(value= KrmsAttributeDefinition.Cache.NAME, key="'all'")
95  	public List<KrmsAttributeDefinition> findAllAttributeDefinitions();
96  
97  	/**
98  	 * This method converts a collection of name/value attribute pairs to
99  	 * id/value attribute pairs.
100 	 * <p>
101 	 * At the api layer, attributes are represented as name/value pairs.
102 	 * However, in the database, the names of the attribute and the values are
103 	 * stored separately. The attribute definitions contain the attribute names.
104 	 * All defined attributes(for the various krms entity types) are stored 
105 	 * together in a single table. The attribute values themselves are stored 
106 	 * in separate tables for each entity type, and then reference the attribute
107 	 * definitions by the attribute definition id.
108 	 * <p>
109 	 * This method converts the name/value pairs to id/value pairs so they
110 	 * can be searched from a single table. This simplifies the queries for 
111 	 * attributes.
112 	 * <p>
113 	 * 
114 	 * @param attributesByName - a Map<String/String> containing the name/value
115 	 * 	pairs for the set of attributes.
116 	 * @param namespace - the namespace code of the set of attributes
117 	 * @return a Map<String,String> containing the id/value pairs for the set
118 	 * of attributes.
119 	 */
120 	public Map<String,String> convertAttributeKeys(Map<String,String> attributesByName, String namespace);
121 
122 	/**
123 	 * This method gets the attribute definition ID for a given attribute
124 	 * 
125 	 * @param attributeName - the name of the attribute
126 	 * @param namespace - the namespace code of the attribute
127 	 * @return - the attribute definition id 
128 	 */
129     @Cacheable(value= KrmsAttributeDefinition.Cache.NAME, key="'{ID}namespaceCode=' + #p0 + '|' + 'name=' + #p1")
130 	public String getKrmsAttributeId( String attributeName, String namespace);
131 	
132 	/**
133 	 * This method gets a KrmsAttributeDefinitionBo object for a given attribute.
134 	 * 
135 	 * @param attributeName - the name of the attribute
136 	 * @param namespace - the namespace code of the attribute
137 	 * @return - the attribute definition id 
138 	 */
139 	public KrmsAttributeDefinitionBo getKrmsAttributeBo( String attributeName, String namespace);
140 
141 	
142 }