001/**
002 * Copyright 2005-2015 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 */
016package org.kuali.rice.krms.impl.repository;
017
018import java.util.List;
019import java.util.Map;
020
021import org.kuali.rice.krms.api.repository.type.KrmsAttributeDefinition;
022import org.kuali.rice.krms.api.repository.type.KrmsTypeDefinition;
023import org.springframework.cache.annotation.CacheEvict;
024import org.springframework.cache.annotation.Cacheable;
025
026public interface KrmsAttributeDefinitionService {
027
028    /**
029     * This will create a {@link KrmsAttributeDefinition} exactly like the parameter passed in.
030     *
031     * @param attributeDefinition - KrmsAttributeDefinition
032     * @throws IllegalArgumentException if the attribute definition is null
033     * @throws IllegalStateException if the attribute definition already exists in the system
034     */
035    @CacheEvict(value={KrmsAttributeDefinition.Cache.NAME}, allEntries = true)
036        public KrmsAttributeDefinition createAttributeDefinition(KrmsAttributeDefinition attributeDefinition);
037
038    /**
039     * This will update a {@link KrmsAttributeDefinition}.
040     *
041     *
042     * @param attributeDefinition - KrmsAttributeDefinition
043     * @throws IllegalArgumentException if the attribute definition is null
044     * @throws IllegalStateException if the attribute definition does not exist in the system
045     */
046    @CacheEvict(value={KrmsAttributeDefinition.Cache.NAME}, allEntries = true)
047        public void updateAttributeDefinition(KrmsAttributeDefinition attributeDefinition);
048
049    /**
050     * Lookup a KrmsAttributeDefinition based on the given id.
051     *
052     * @param id the given KrmsAttributeDefinition id
053     * @return a KrmsAttributeDefinition object with the given id.  A null reference is returned if an invalid or
054     *         non-existant id is supplied.
055     */
056    @Cacheable(value= KrmsAttributeDefinition.Cache.NAME, key="'attributeDefinitionId=' + #p0")
057        public KrmsAttributeDefinition getAttributeDefinitionById(String id);
058
059    /**
060     * Get a KrmsAttributeDefinition object based on name and namespace
061     *
062     * @param name the given name
063     * @param namespace the given type namespace
064     * @return A KrmsAttributeDefinition object with the given namespace and name if one with that name and namespace
065     *         exists.  Otherwise, null is returned.
066     * @throws IllegalStateException if multiple KrmsAttributeDefinitions exist with the same name and namespace
067     */
068    @Cacheable(value= KrmsAttributeDefinition.Cache.NAME, key="'namespaceCode=' + #p0 + '|' + 'name=' + #p1")
069        public KrmsAttributeDefinition getAttributeDefinitionByNameAndNamespace(String name, String namespace);
070
071   /**
072     * Returns all KrmsAttributeDefinition that for a given namespace.
073     *
074     * @return all KrmsAttributeDefinition for a namespace
075     */
076    @Cacheable(value= KrmsAttributeDefinition.Cache.NAME, key="'namespace=' + #p0")
077        public List<KrmsAttributeDefinition> findAttributeDefinitionsByNamespace(String namespace);
078
079
080    /**
081      * Returns all KrmsAttributeDefinition that for a given type.
082      *
083      * @return all KrmsAttributeDefinition for a type.  May be empty, will not be null;
084      */
085    @Cacheable(value= KrmsAttributeDefinition.Cache.NAME, key="'typeId=' + #p0")
086     public List<KrmsAttributeDefinition> findAttributeDefinitionsByType(String typeId);
087
088
089    /**
090     * Returns all KrmsAttributeDefinitions
091     *
092     * @return all KrmsAttributeDefinitions
093     */
094    @Cacheable(value= KrmsAttributeDefinition.Cache.NAME, key="'all'")
095        public List<KrmsAttributeDefinition> findAllAttributeDefinitions();
096
097        /**
098         * This method converts a collection of name/value attribute pairs to
099         * 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}