001    /*
002     * Copyright 2011 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     */
016    package org.kuali.kfs.module.purap.document.validation.event;
017    
018    import org.apache.commons.lang.StringUtils;
019    import org.apache.log4j.Logger;
020    import org.kuali.kfs.module.purap.businessobject.PurApItem;
021    import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEventBase;
022    import org.kuali.rice.kns.document.Document;
023    
024    /**
025     * Event Base class for Purchasing Accounts Payable Item
026     * 
027     * contains the base methods for item events
028     */
029    public abstract class AttributedPurchasingAccountsPayableItemEventBase extends AttributedDocumentEventBase implements AttributedPurchasingAccountsPayableItemEvent {
030        private static final Logger LOG = Logger.getLogger(AttributedPurchasingAccountsPayableItemEventBase.class);
031    
032    
033        private final PurApItem item;
034    
035        /**
036         * Copies the item and calls the super constructor
037         * 
038         * @param description the description of the event
039         * @param errorPathPrefix the error path
040         * @param document the document the event is being called on
041         * @param item the item that is having the event called on
042         */
043        public AttributedPurchasingAccountsPayableItemEventBase(String description, String errorPathPrefix, Document document, PurApItem item) {
044            super(description, errorPathPrefix, document);
045    
046            this.item = item;
047    
048            logEvent();
049        }
050    
051        /**
052         * 
053         * @see org.kuali.kfs.module.purap.document.validation.event.PurchasingAccountsPayableItemEvent#getItem()
054         */
055        public PurApItem getItem() {
056            return item;
057        }
058    
059    
060        /**
061         * @see org.kuali.rice.kns.rule.event.KualiDocumentEvent#validate()
062         */
063        public void validate() {
064            super.validate();
065            if (getItem() == null) {
066                throw new IllegalArgumentException("invalid (null) item");
067            }
068        }
069    
070        /**
071         * Logs the event type and some information about the associated item
072         */
073        private void logEvent() {
074            StringBuffer logMessage = new StringBuffer(StringUtils.substringAfterLast(this.getClass().getName(), "."));
075            logMessage.append(" with ");
076    
077            // vary logging detail as needed
078            if (item == null) {
079                logMessage.append("null item");
080            }
081            else {
082                logMessage.append(" item# ");
083                logMessage.append(item.getItemIdentifier());
084            }
085    
086            LOG.debug(logMessage);
087        }
088    }