001/**
002 * Copyright 2005-2016 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.maintenance;
017
018import org.kuali.rice.kim.api.identity.Person;
019import org.kuali.rice.krad.bo.BusinessObject;
020import org.kuali.rice.krad.bo.DocumentHeader;
021import org.kuali.rice.krad.bo.PersistableBusinessObject;
022import org.kuali.rice.krad.uif.service.ViewHelperService;
023
024import java.util.List;
025import java.util.Map;
026
027/**
028 * Provides contract for implementing a maintenance object within the maintenance framework
029 *
030 * <p> Currently the <code>Maintainable</code> serves many purposes. First since all maintenance documents share the
031 * same document class <code>MaintenanceDocumentBase</code> certain document callbacks such as workflow post processing
032 * are invoked on the maintainable. Second the maintainable provides a hook for custom actions on the maintenance view.
033 * Finally since the maintainable extends <code>ViewHelperService</code> it is used to customize <code>View</code>
034 * configuration for <code>MaintenanceView</code> instances </p>
035 *
036 * @author Kuali Rice Team (rice.collab@kuali.org)
037 */
038public interface Maintainable extends ViewHelperService, java.io.Serializable {
039
040    /**
041     * Sets the document number on this maintainable for referencing back to the containing
042     * <code>MaintenanceDocument</code>
043     *
044     * @param documentNumber - document number for the containing maintenance document
045     */
046    public void setDocumentNumber(String documentNumber);
047
048    /**
049     * Invoked when setting the title for the document instance in workflow (doc search results)
050     * to customize the title
051     *
052     * @param document - maintenance document instance to build title for
053     * @return String document title
054     */
055    public String getDocumentTitle(MaintenanceDocument document);
056
057    /**
058     * Returns instance of the data object that is being maintained
059     *
060     * @return Object data object instance
061     */
062    public Object getDataObject();
063
064    /**
065     * Sets an instance of a data object that should be maintained
066     *
067     * @param object - data object instance
068     */
069    public void setDataObject(Object object);
070
071    /**
072     * Returns the class for the data object being maintained
073     *
074     * @return Class data object class
075     */
076    public Class getDataObjectClass();
077
078    /**
079     * Sets the class for the data object that will be maintained
080     *
081     * @param dataObjectClass - class for maintenance data object
082     */
083    public void setDataObjectClass(Class dataObjectClass);
084
085    /**
086     * Indicates whether the object can be locked
087     *
088     * <p>
089     * If this method is overridden, most likely  getPersistableBusinessObject() should be
090     * overridden as well.
091     * </p>
092     *
093     * @return true if maintenance is lockable, false otherwise
094     */
095    public boolean isLockable();
096
097    /**
098     * Returns the persistable business object or null if none exists.
099     *
100     * @return persistable buisness object
101     */
102    public PersistableBusinessObject getPersistableBusinessObject();
103
104    /**
105     * Returns the type of maintenance action this maintainable has been configured with
106     *
107     * @return String maintenance action string
108     */
109    public String getMaintenanceAction();
110
111    /**
112     * Sets the type of maintenance action to be performed (new, edit, or copy)
113     *
114     * @param maintenanceAction - string identifying the action type
115     */
116    public void setMaintenanceAction(String maintenanceAction);
117
118    /**
119     * Invoked to generating the list of maintenance locks used to block other edits
120     * of the same data object record
121     *
122     * @return the locking representation(s) of this document, which are reproducible
123     *         given the same keys and the same maintainable object
124     */
125    public List<MaintenanceLock> generateMaintenanceLocks();
126
127    /**
128     * Invoked to persist changes to the data object being maintained
129     *
130     * <p>
131     * Called after the maintenance document has become final indicating
132     * the changes should be applied
133     * </p>
134     */
135    public void saveDataObject();
136
137    /**
138     * Invokes to delete the data object being maintained
139     *
140     * <p>
141     * Called after the maintenance document has become final indicating
142     * the changes should be applied
143     * </p>
144     */
145    public void deleteDataObject();
146
147    /**
148     * Invoked do perform custom processing when the route status for the containing
149     * maintenance document changes
150     *
151     * <p>
152     * Usually used for determining when the document has become final so further actions
153     * can take place in addition to the usual persistence of the object changes
154     * </p>
155     *
156     * @param documentHeader - document header instance for containing maintenance document which
157     * can be used to check the new status
158     */
159    public void doRouteStatusChange(DocumentHeader documentHeader);
160
161    /**
162     * Retrieves the locking document id for the maintainable which is used to create the
163     * maintenance lock string
164     *
165     * @return String locking id
166     */
167    public String getLockingDocumentId();
168
169    /**
170     * Return an array of document ids to lock prior to processing this document
171     * in the workflow engine
172     *
173     * @return List<String> list of document ids
174     */
175    public List<String> getWorkflowEngineDocumentIdsToLock();
176
177    /**
178     * Indicates whether or not this maintainable supports custom lock
179     * descriptors for pessimistic locking.
180     *
181     * @return boolean true if the maintainable can generate custom lock descriptors,
182     *         false otherwise
183     * @see #getCustomLockDescriptor(Map, org.kuali.rice.kim.api.identity.Person)
184     */
185    public boolean useCustomLockDescriptors();
186
187    /**
188     * Generates a custom lock descriptor for pessimistic locking. This method
189     * should not be called unless {@link #useCustomLockDescriptors()} returns
190     * true
191     *
192     * @param user - the user trying to establish the lock
193     * @return String representing the lock descriptor
194     * @see #useCustomLockDescriptors()
195     * @see org.kuali.rice.krad.service.PessimisticLockService
196     * @see org.kuali.rice.krad.service.impl.PessimisticLockServiceImpl
197     */
198    public String getCustomLockDescriptor(Person user);
199
200    /**
201     * Indicates whether this maintainable supports notes on the maintenance object
202     *
203     * <p>
204     * Note this is only applicable if the data object is an instance of <code>BusinessObject</code>
205     * </p>
206     *
207     * @return boolean true if notes are supported, false if they are not supported
208     */
209    public boolean isNotesEnabled();
210
211    /**
212     * Indicates whether the object being maintained is an instance of <code>ExternalizableBusinessObject</code>
213     *
214     * <p>
215     * For the case when we want to maintain a business object that doesn't
216     * necessarily map to a single table in the database or may doesn't map to a
217     * database at all
218     * </p>
219     *
220     * @return boolean true if the data object is an external business object, false if not
221     */
222    public boolean isExternalBusinessObject();
223
224    /**
225     * Invoked to prepare a new <code>BusinessObject</code> instance that is external
226     *
227     * @param businessObject - new business object instance to prepare
228     */
229    public void prepareExternalBusinessObject(BusinessObject businessObject);
230
231    /**
232     * Indicates whether their is an old data object for the maintainable
233     *
234     * @return boolean true if old data object exists, false if not
235     */
236    public boolean isOldDataObjectInDocument();
237
238    /**
239     * Hook for performing any custom processing before the maintenance object is saved
240     */
241    public void prepareForSave();
242
243    /**
244     * Hook for performing any custom processing after the maintenance object is retrieved from persistence storage
245     */
246    public void processAfterRetrieve();
247
248    /**
249     * Called during setupMaintenanceObject to retrieve the original dataObject that is being
250     * edited or copied.  Override this method for non BusinessObject external persistence,
251     * Maintainable objects that extend BO should override isExternalBusinessObject and
252     * prepareBusinessObject instead.
253     *
254     * Do not override this method and isExternalBusinessObject.
255     *
256     * @param document document instance for the maintenance object
257     * @param dataObjectKeys Map of keys for the requested object
258     * @return the object identified by the dataObjectKeys
259     */
260    public Object retrieveObjectForEditOrCopy(MaintenanceDocument document, Map<String, String> dataObjectKeys);
261
262    /**
263     * Performs the setting of some attributes that might be necessary
264     * if we're creating a new business object using on an existing business object.
265     * For example, create a division Vendor based on an existing parent Vendor.
266     * (Please see VendorMaintainableImpl.java)
267     *
268     * @param document - maintenance document instance this maintainable belong to
269     * @param requestParameters - map of request parameters sent for the request
270     */
271    public void setupNewFromExisting(MaintenanceDocument document, Map<String, String[]> parameters);
272
273    /**
274     * Hook for performing any custom processing after the maintenance object has been setup for a copy action
275     *
276     * @param document - maintenance document instance this maintainable belong to
277     * @param requestParameters - map of request parameters sent for the copy request
278     */
279    public void processAfterCopy(MaintenanceDocument document, Map<String, String[]> requestParameters);
280
281    /**
282     * Hook for performing any custom processing after the maintenance object has been setup for a edit action
283     *
284     * @param document - maintenance document instance this maintainable belong to
285     * @param requestParameters - map of request parameters sent for the copy request
286     */
287    public void processAfterEdit(MaintenanceDocument document, Map<String, String[]> requestParameters);
288
289    /**
290     * Hook for performing any custom processing after the maintenance object has been setup for a new action
291     *
292     * @param document - maintenance document instance this maintainable belong to
293     * @param requestParameters - map of request parameters sent for the copy request
294     */
295    public void processAfterNew(MaintenanceDocument document, Map<String, String[]> requestParameters);
296
297    /**
298     * Hook for performing any custom processing after each posting of the maintenance document (for various actions
299     * like add line, refresh)
300     *
301     * @param document - maintenance document instance this maintainable belong to
302     * @param requestParameters - map of request parameters from the post
303     */
304    public void processAfterPost(MaintenanceDocument document, Map<String, String[]> requestParameters);
305}