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.ar.document.validation.event;
017    
018    import org.apache.commons.lang.StringUtils;
019    import org.apache.log4j.Logger;
020    import org.kuali.kfs.module.ar.businessobject.CustomerCreditMemoDetail;
021    import org.kuali.rice.kns.document.Document;
022    import org.kuali.rice.kns.rule.event.KualiDocumentEventBase;
023    import org.kuali.rice.kns.util.ObjectUtils;
024    
025    public abstract class CustomerCreditMemoDetailEventBase extends KualiDocumentEventBase implements CustomerCreditMemoDetailEvent{
026    
027        private static final Logger LOG = Logger.getLogger(CustomerCreditMemoDetailEventBase.class);
028        private final CustomerCreditMemoDetail customerCreditMemoDetail;
029        
030        public CustomerCreditMemoDetailEventBase(String description, String errorPathPrefix, Document document, CustomerCreditMemoDetail customerCreditMemoDetail) {
031            super(description, errorPathPrefix, document);
032    
033            // by doing a deep copy, we are ensuring that the business rule class can't update
034            // the original object by reference
035            this.customerCreditMemoDetail = (CustomerCreditMemoDetail) ObjectUtils.deepCopy(customerCreditMemoDetail);
036            
037            logEvent();
038        }
039        
040        public CustomerCreditMemoDetail getCustomerCreditMemoDetail() {
041            return customerCreditMemoDetail;
042        }
043        
044        /**
045         * @see org.kuali.rice.kns.rule.event.KualiDocumentEvent#validate()
046         */
047        public void validate() {
048            super.validate();
049            if (customerCreditMemoDetail == null) {
050                throw new IllegalArgumentException("invalid (null) customer credit memo detail");
051            }
052        }
053    
054        /**
055         * Logs the event type and some information about the associated accountingLine
056         */
057        private void logEvent() {
058            StringBuffer logMessage = new StringBuffer(StringUtils.substringAfterLast(this.getClass().getName(), "."));
059            logMessage.append(" with ");
060    
061            // vary logging detail as needed
062            if (customerCreditMemoDetail == null) {
063                logMessage.append("null customerCreditMemoDetail");
064            }
065            else {
066                logMessage.append(" customer credit memo detail# ");
067                logMessage.append( customerCreditMemoDetail.getReferenceInvoiceItemNumber() );
068            }
069    
070            LOG.debug(logMessage);
071        }
072    
073    }