001/* 002 * Copyright 2007-2008 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 */ 016package org.kuali.ole.module.purap.document.validation.event; 017 018import org.apache.commons.lang.StringUtils; 019import org.apache.log4j.Logger; 020import org.kuali.ole.integration.purap.CapitalAssetLocation; 021import org.kuali.ole.sys.document.validation.event.AttributedDocumentEventBase; 022import org.kuali.rice.krad.document.Document; 023 024/** 025 * Event Base class for Purchasing Item Capital Asset 026 * <p/> 027 * contains the base methods for item events 028 */ 029public 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.ole.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 } else { 079 logMessage.append(" capital asset location# "); 080 logMessage.append(capitalAssetLocation.getCapitalAssetLocationIdentifier()); 081 } 082 083 LOG.debug(logMessage); 084 } 085}