001/**
002 * Copyright 2005-2018 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.krad.service;
017
018import org.kuali.rice.krad.bo.BusinessObject;
019import org.kuali.rice.krad.bo.PersistableBusinessObject;
020import org.kuali.rice.krad.util.LegacyDataFramework;
021
022import java.util.Collection;
023import java.util.List;
024import java.util.Map;
025
026/**
027 * Defines methods that a BusinessObjectService must provide
028 * 
029 * @author Kuali Rice Team (rice.collab@kuali.org)
030 * @deprecated use new KRAD Data framework {@link org.kuali.rice.krad.data.DataObjectService}
031 */
032@Deprecated
033@LegacyDataFramework
034public interface BusinessObjectService {
035
036    /**
037     * Saves the passed in object via the persistence layer.
038     * 
039     * This will throw an IllegalArgumentException (runtime exception) if the object passed in is not a descendent of
040     * BusinessObject.
041     * 
042     * @param bo A BusinessObject instance or descendent that you wish to be stored.
043     */
044    public <T extends PersistableBusinessObject> T save(T bo);
045
046    /**
047     * Saves the businessObjects on the list via the persistence layer.
048     * 
049     * This will throw an IllegalArgumentException (runtime exception) if any of the objects passed in is not a descendent of
050     * BusinessObject.
051     * 
052     * @param businessObjects A List<PersistableBusinessObject> of objects to persist.
053     */
054    public List<? extends PersistableBusinessObject> save(List<? extends PersistableBusinessObject> businessObjects);
055
056    /**
057     * Links up any contained objects, and then Saves the passed in object via the persistence layer.
058     * 
059     * This will throw an IllegalArgumentException (runtime exception) if the object passed in is not a descendent of
060     * BusinessObject.
061     * 
062     * @param bo A BusinessObject instance or descendent that you wish to be stored.
063     */
064    public PersistableBusinessObject linkAndSave(PersistableBusinessObject bo);
065
066    /**
067     * Links up any contained objects, and Saves the businessObjects on the list via the persistence layer.
068     * 
069     * This will throw an IllegalArgumentException (runtime exception) if any of the objects passed in is not a descendent of
070     * BusinessObject.
071     * 
072     * @param businessObjects A List<BusinessObject> of objects to persist.
073     * 
074     */
075    public List<? extends PersistableBusinessObject> linkAndSave(List<? extends PersistableBusinessObject> businessObjects);
076
077    /**
078     * Retrieves an object instance identified by its primary key. For composite keys, use {@link #findByPrimaryKey(Class, Map)}
079     * 
080     * @param clazz
081     * @param primaryKey
082     * @return
083     */
084    public <T extends BusinessObject> T findBySinglePrimaryKey(Class<T> clazz, Object primaryKey);
085    
086    /**
087     * Retrieves an object instance identified by its primary keys and values. This can be done by constructing a map where the key
088     * to the map entry is the primary key attribute and the value of the entry being the primary key value. For composite keys,
089     * pass in each primaryKey attribute and its value as a map entry.
090     * 
091     * @param clazz
092     * @param primaryKeys
093     * @return
094     */
095    public <T extends BusinessObject> T findByPrimaryKey(Class<T> clazz, Map<String, ?> primaryKeys);
096
097    /**
098     * Retrieves an object instance identified by the class of the given object and the object's primary key values.
099     * 
100     * @param object
101     * @return
102     */
103    public Object retrieve(Object object);
104
105    /**
106     * Retrieves a collection of business objects populated with data, such that each record in the database populates a new object
107     * instance. This will only retrieve business objects by class type.
108     * 
109     * @param clazz
110     * @return
111     */
112    public <T extends BusinessObject> Collection<T> findAll(Class<T> clazz);
113
114    /**
115     * Retrieves a collection of business objects populated with data, such that each record in the database populates a new object
116     * instance. This will only retrieve business objects by class type.
117     * 
118     * @param clazz
119     * @return
120     */
121    public <T extends BusinessObject> Collection<T> findAllOrderBy( Class<T> clazz, String sortField, boolean sortAscending );
122    
123    /**
124     * This method retrieves a collection of business objects populated with data, such that each record in the database populates a
125     * new object instance. This will retrieve business objects by class type and also by criteria passed in as key-value pairs,
126     * specifically attribute name and its expected value.
127     * 
128     * @param clazz
129     * @param fieldValues
130     * @return
131     */
132    public <T extends BusinessObject> Collection<T> findMatching(Class<T> clazz, Map<String, ?> fieldValues);
133    
134    /**
135     * Finds all entities matching the passed in Rice JPA criteria
136     * 
137     * @param <T> the type of the entity that will be returned
138     * @param criteria the criteria to form the query with
139     * @return a Collection (most likely a List) of all matching entities 
140     */
141    //public abstract <T extends BusinessObject> Collection<T> findMatching(Criteria criteria);
142
143    /**
144     * This method retrieves a count of the business objects populated with data which match the criteria in the given Map.
145     * 
146     * @param clazz
147     * @param fieldValues
148     * @return number of businessObjects of the given class whose fields match the values in the given expected-value Map
149     */
150    public int countMatching(Class clazz, Map<String, ?> fieldValues);
151
152    /**
153     * This method retrieves a count of the business objects populated with data which match both the positive criteria 
154     * and the negative criteria in the given Map.
155     * 
156     * @param clazz
157     * @param positiveFieldValues
158     * @param negativeFieldValues
159     * @return number of businessObjects of the given class whose fields match the values in the given expected-value Maps
160     */
161    public int countMatching(Class clazz, Map<String, ?> positiveFieldValues, Map<String, ?> negativeFieldValues);
162    
163    /**
164     * This method retrieves a collection of business objects populated with data, such that each record in the database populates a
165     * new object instance. This will retrieve business objects by class type and also by criteria passed in as key-value pairs,
166     * specifically attribute name and its expected value. Performs an order by on sort field.
167     * 
168     * @param clazz
169     * @param fieldValues
170     * @return
171     */
172    public <T extends BusinessObject> Collection<T> findMatchingOrderBy(Class<T> clazz, Map<String, ?> fieldValues, String sortField, boolean sortAscending);
173
174    /**
175     * Deletes a business object from the database.
176     * 
177     * @param bo
178     */
179    public void delete(Object bo);
180
181    /**
182     * Deletes each business object in the given List.
183     * 
184     * @param boList
185     */
186    public void delete(List<? extends PersistableBusinessObject> boList);
187
188    /**
189     * Deletes the object(s) matching the given field values
190     * 
191     * @param clazz
192     * @param fieldValues
193     */
194    public void deleteMatching(Class clazz, Map<String, ?> fieldValues);
195
196    /**
197     * 
198     * This method attempts to retrieve the reference from a BO if it exists.
199     * 
200     * @param bo - populated BusinessObject instance that includes the referenceName property
201     * @param referenceName - name of the member/property to load
202     * @return A populated object from the DB, if it exists
203     * 
204     */
205    public BusinessObject getReferenceIfExists(BusinessObject bo, String referenceName);
206
207    /**
208     * 
209     * Updates all KualiUser or Person objects contained within this BO, based on the UserID as the authoritative key. The
210     * appropriate foreign-key field in the BO itself is also updated.
211     * 
212     * This allows UserIDs to be entered on forms, and the back-end will link up correctly based on this non-key field.
213     * 
214     * @param bo The populated BO (or descendent) instance to be linked & updated
215     * 
216     */
217    public void linkUserFields(Object bo);
218
219    /**
220     * Merges the given business object, but tells the ORM that the object is to be treated as Read Only,
221     * and even if it has changes, it will not be persisted to the database 
222     * 
223     * @param bo the business object to managed
224     * @return the managed copied of the business object
225     */
226    public PersistableBusinessObject manageReadOnly(PersistableBusinessObject bo);
227
228}
229