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.CashControlDetail;
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 CashControlDetailEventBase extends KualiDocumentEventBase implements CashControlDetailEvent {
026
027 private static final Logger LOG = Logger.getLogger(CashControlDetailEventBase.class);
028
029
030 private final CashControlDetail cashControlDetail;
031
032 /**
033 * Initializes fields common to all subclasses
034 *
035 * @param description
036 * @param errorPathPrefix
037 * @param document
038 * @param check
039 */
040 public CashControlDetailEventBase(String description, String errorPathPrefix, Document document, CashControlDetail cashControlDetail) {
041 super(description, errorPathPrefix, document);
042
043 // by doing a deep copy, we are ensuring that the business rule class can't update
044 // the original object by reference
045 this.cashControlDetail = (CashControlDetail) ObjectUtils.deepCopy(cashControlDetail);
046
047 logEvent();
048 }
049
050
051 /**
052 * @see org.kuali.kfs.module.ar.document.validation.event.CustomerInvoiceDetailEvent#getCustomerInvoiceDetail()
053 */
054 public CashControlDetail getCashControlDetail() {
055 return cashControlDetail;
056 }
057
058
059 /**
060 * @see org.kuali.rice.kns.rule.event.KualiDocumentEvent#validate()
061 */
062 public void validate() {
063 super.validate();
064 if (getCashControlDetail() == null) {
065 throw new IllegalArgumentException("invalid (null) cash control detail");
066 }
067 }
068
069 /**
070 * Logs the event type and some information about the associated accountingLine
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 (cashControlDetail == null) {
078 logMessage.append("null cashControlDetail");
079 }
080 else {
081 logMessage.append(" cashControlDetail# ");
082 logMessage.append(cashControlDetail.getDocumentNumber());
083 }
084
085 LOG.debug(logMessage);
086 }
087 }