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.CapitalAssetLocation;
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 AttributedPurchasingCapitalAssetLocationEventBase extends AttributedDocumentEventBase implements AttributedPurchasingCapitalAssetLocationEvent {
030        private static final Logger LOG = Logger.getLogger(AttributedPurchasingCapitalAssetLocationEventBase.class);
031    
032    
033        private final CapitalAssetLocation capitalAssetLocation;
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 location the location that is having the event called on
042         */
043        public AttributedPurchasingCapitalAssetLocationEventBase(String description, String errorPathPrefix, Document document, CapitalAssetLocation capitalAssetLocation) {
044            super(description, errorPathPrefix, document);
045    
046            this.capitalAssetLocation = capitalAssetLocation;
047    
048            logEvent();
049        }
050    
051        /**     
052         * @see org.kuali.kfs.module.purap.document.validation.event.PurchasingCapitalAssetLocationEvent#getCapitalAssetLocation()
053         */
054        public CapitalAssetLocation getCapitalAssetLocation() {
055            return capitalAssetLocation;
056        }
057    
058        /**
059         * @see org.kuali.core.rule.event.KualiDocumentEvent#validate()
060         */
061        public void validate() {
062            super.validate();
063            if (getCapitalAssetLocation() == null) {
064                throw new IllegalArgumentException("invalid (null) location");
065            }
066        }
067    
068        /**
069         * Logs the event type and some information about the associated location
070         */
071        private void logEvent() {
072            StringBuffer logMessage = new StringBuffer(StringUtils.substringAfterLast(this.getClass().getName(), "."));
073            logMessage.append(" with ");
074    
075            // vary logging detail as needed
076            if (capitalAssetLocation == null) {
077                logMessage.append("null capital asset location");
078            }
079            else {
080                logMessage.append(" capital asset location# ");
081                logMessage.append(capitalAssetLocation.getCapitalAssetLocationIdentifier());
082            }
083    
084            LOG.debug(logMessage);
085        }
086    }