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.rules;
017
018import org.kuali.rice.krad.document.Document;
019import org.kuali.rice.krad.maintenance.MaintenanceDocument;
020import org.kuali.rice.krad.rules.rule.event.AddCollectionLineEvent;
021import org.kuali.rice.krad.rules.rule.event.ApproveDocumentEvent;
022
023/**
024 * Rule event interface for implementing business rules against a maintenance document.
025 *
026 * @author Kuali Rice Team (rice.collab@kuali.org)
027 */
028public interface MaintenanceDocumentRule {
029
030    /**
031     * Runs all business rules needed prior to saving. This includes both common rules for all maintenance documents,
032     * plus class-specific business rules.
033     *
034     * Will only return false if it fails the isValidForSave() test. Otherwise, it will always return positive
035     * regardless of the outcome of the business rules. However, any error messages resulting from the business rules
036     * will still be populated, for display to the consumer of this service.
037     *
038     * @see org.kuali.rice.krad.rules.rule.SaveDocumentRule#processSaveDocument(org.kuali.rice.krad.document.Document)
039     */
040    public abstract boolean processSaveDocument(Document document);
041
042    /**
043     * Runs all business rules needed prior to routing. This includes both common rules for all maintenance documents,
044     * plus class-specific business rules.
045     *
046     * Will return false if any business rule fails, or if the document is in an invalid state, and not routable (see
047     * isDocumentValidForRouting()).
048     *
049     * @see org.kuali.rice.krad.rules.rule.RouteDocumentRule#processRouteDocument(org.kuali.rice.krad.document.Document)
050     */
051    public abstract boolean processRouteDocument(Document document);
052
053    /**
054     * Runs all business rules needed prior to approving. This includes both common rules for all maintenance documents,
055     * plus class-specific business rules.
056     *
057     * Will return false if any business rule fails, or if the document is in an invalid state, and not approvable (see
058     * isDocumentValidForApproving()).
059     *
060     * @see org.kuali.rice.krad.rules.rule.ApproveDocumentRule#processApproveDocument(org.kuali.rice.krad.rules.rule.event.ApproveDocumentEvent)
061     */
062    public abstract boolean processApproveDocument(ApproveDocumentEvent approveEvent);
063
064    /**
065     * Runs all business rules needed prior to adding a collection to a line. This includes both common rules for all
066     * maintenance documents, plus class-specific business rules.
067     *
068     * Will return false if any business rule fails.
069     *
070     * @see org.kuali.rice.krad.rules.rule.AddCollectionLineRule#processAddCollectionLine(org.kuali.rice.krad.rules.rule.event.AddCollectionLineEvent)
071     */
072    public abstract boolean processAddCollectionLine(AddCollectionLineEvent addEvent);
073
074    /**
075     * Sets the convenience objects like newAccount and oldAccount, so you have short and easy handles to the new and
076     * old objects contained in the maintenance document.
077     *
078     * It also calls the BusinessObjectBase.refresh(), which will attempt to load all sub-objects from the DB by their
079     * primary keys, if available.
080     *
081     * @param document - the maintenanceDocument being evaluated
082     */
083    public void setupBaseConvenienceObjects(MaintenanceDocument document);
084
085    /**
086     * Should always be overriden if a subclass is created.
087     *
088     * The goal for this is to cast the oldBo and newBo into the correct types of the subclass.
089     */
090    public void setupConvenienceObjects();
091}