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.integration.purap.ItemCapitalAsset;
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 Item Capital Asset
026     * 
027     * contains the base methods for item events
028     */
029    public abstract class AttributedPurchasingItemCapitalAssetEventBase extends AttributedDocumentEventBase implements AttributedPurchasingItemCapitalAssetEvent {
030        private static final Logger LOG = Logger.getLogger(AttributedPurchasingItemCapitalAssetEventBase.class);
031    
032    
033        private final ItemCapitalAsset itemCapitalAsset;
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 AttributedPurchasingItemCapitalAssetEventBase(String description, String errorPathPrefix, Document document, ItemCapitalAsset itemCapitalAsset) {
044            super(description, errorPathPrefix, document);
045    
046            this.itemCapitalAsset = itemCapitalAsset;
047    
048            logEvent();
049        }
050    
051        /**
052         * @see org.kuali.kfs.module.purap.document.validation.event.PurchasingItemCapitalAssetEvent#getItemCapitalAsset()
053         */
054        public ItemCapitalAsset getItemCapitalAsset() {
055            return itemCapitalAsset;
056        }
057    
058    
059        /**
060         * @see org.kuali.core.rule.event.KualiDocumentEvent#validate()
061         */
062        public void validate() {
063            super.validate();
064            if (getItemCapitalAsset() == null) {
065                throw new IllegalArgumentException("invalid (null) item");
066            }
067        }
068    
069        /**
070         * Logs the event type and some information about the associated item
071         */
072        private void logEvent() {
073            StringBuffer logMessage = new StringBuffer(StringUtils.substringAfterLast(this.getClass().getName(), "."));
074            logMessage.append(" with ");
075    
076            // vary logging detail as needed
077            if (itemCapitalAsset == null) {
078                logMessage.append("null item capital asset");
079            }
080            else {
081                logMessage.append(" item capital asset# ");
082                logMessage.append(itemCapitalAsset.getItemCapitalAssetIdentifier());
083            }
084    
085            LOG.debug(logMessage);
086        }
087    }