View Javadoc
1   /*
2    * Copyright 2007-2008 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.module.purap.document.validation.event;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.apache.log4j.Logger;
20  import org.kuali.ole.integration.purap.ItemCapitalAsset;
21  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEventBase;
22  import org.kuali.rice.krad.document.Document;
23  
24  /**
25   * Event Base class for Purchasing Item Capital Asset
26   * <p/>
27   * contains the base methods for item events
28   */
29  public abstract class AttributedPurchasingItemCapitalAssetEventBase extends AttributedDocumentEventBase implements AttributedPurchasingItemCapitalAssetEvent {
30      private static final Logger LOG = Logger.getLogger(AttributedPurchasingItemCapitalAssetEventBase.class);
31  
32  
33      private final ItemCapitalAsset itemCapitalAsset;
34  
35      /**
36       * Copies the item and calls the super constructor
37       *
38       * @param description     the description of the event
39       * @param errorPathPrefix the error path
40       * @param document        the document the event is being called on
41       * @param item            the item that is having the event called on
42       */
43      public AttributedPurchasingItemCapitalAssetEventBase(String description, String errorPathPrefix, Document document, ItemCapitalAsset itemCapitalAsset) {
44          super(description, errorPathPrefix, document);
45  
46          this.itemCapitalAsset = itemCapitalAsset;
47  
48          logEvent();
49      }
50  
51      /**
52       * @see org.kuali.ole.module.purap.document.validation.event.PurchasingItemCapitalAssetEvent#getItemCapitalAsset()
53       */
54      public ItemCapitalAsset getItemCapitalAsset() {
55          return itemCapitalAsset;
56      }
57  
58  
59      /**
60       * @see org.kuali.core.rule.event.KualiDocumentEvent#validate()
61       */
62      public void validate() {
63          super.validate();
64          if (getItemCapitalAsset() == null) {
65              throw new IllegalArgumentException("invalid (null) item");
66          }
67      }
68  
69      /**
70       * Logs the event type and some information about the associated item
71       */
72      private void logEvent() {
73          StringBuffer logMessage = new StringBuffer(StringUtils.substringAfterLast(this.getClass().getName(), "."));
74          logMessage.append(" with ");
75  
76          // vary logging detail as needed
77          if (itemCapitalAsset == null) {
78              logMessage.append("null item capital asset");
79          } else {
80              logMessage.append(" item capital asset# ");
81              logMessage.append(itemCapitalAsset.getItemCapitalAssetIdentifier());
82          }
83  
84          LOG.debug(logMessage);
85      }
86  }