View Javadoc
1   /*
2    * Copyright 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.sys.businessobject;
17  
18  import java.sql.Timestamp;
19  import java.util.Date;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.kuali.ole.sys.context.SpringContext;
23  import org.kuali.rice.kim.api.identity.Person;
24  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
25  import org.kuali.rice.krad.util.GlobalVariables;
26  
27  public abstract class TimestampedBusinessObjectBase extends PersistableBusinessObjectBase implements TimestampedBusinessObject {
28      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(TimestampedBusinessObjectBase.class);
29  
30      private Timestamp lastUpdate;
31      private String lastUpdateUserId;
32  
33      /**
34       * @see org.kuali.ole.sys.businessobject.TimestampedBusinessObject#getLastUpdate()
35       */
36      public Timestamp getLastUpdate() {
37          return this.lastUpdate;
38      }
39  
40      /**
41       * @see org.kuali.ole.sys.businessobject.TimestampedBusinessObject#getLastUpdateUser()
42       */
43      public Person getLastUpdateUser() {
44          Person user = null;
45          if (StringUtils.isNotBlank(lastUpdateUserId)) {
46              user = SpringContext.getBean(org.kuali.rice.kim.api.identity.PersonService.class).getPersonByPrincipalName(lastUpdateUserId);
47          }
48  
49          return user;
50      }
51  
52      /**
53       * @see org.kuali.ole.sys.businessobject.TimestampedBusinessObject#getLastUpdateUserId()
54       */
55      public String getLastUpdateUserId() {
56          return this.lastUpdateUserId;
57      }
58  
59      /**
60       * @param lastUpdateUserId The lastUpdateUserId to set.
61       */
62      public void setLastUpdateUserId(String lastUpdateUserId) {
63          this.lastUpdateUserId = lastUpdateUserId;
64      }
65  
66      /**
67       * @param lastUpdate The lastUpdate to set.
68       */
69      public void setLastUpdate(Timestamp lastUpdate) {
70          this.lastUpdate = lastUpdate;
71      }
72  
73      @Override protected void prePersist() {
74          super.prePersist();
75  
76          lastUpdate = new Timestamp((new Date()).getTime());
77          lastUpdateUserId = GlobalVariables.getUserSession().getPerson().getPrincipalName();
78      }
79  
80      @Override protected void preUpdate() {
81          super.preUpdate();
82  
83          lastUpdate = new Timestamp((new Date()).getTime());
84          lastUpdateUserId = GlobalVariables.getUserSession().getPerson().getPrincipalName();
85      }
86  }