001/* 002 * Copyright 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.sys.businessobject; 017 018import java.sql.Timestamp; 019import java.util.Date; 020 021import org.apache.commons.lang.StringUtils; 022import org.kuali.ole.sys.context.SpringContext; 023import org.kuali.rice.kim.api.identity.Person; 024import org.kuali.rice.krad.bo.PersistableBusinessObjectBase; 025import org.kuali.rice.krad.util.GlobalVariables; 026 027public abstract class TimestampedBusinessObjectBase extends PersistableBusinessObjectBase implements TimestampedBusinessObject { 028 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(TimestampedBusinessObjectBase.class); 029 030 private Timestamp lastUpdate; 031 private String lastUpdateUserId; 032 033 /** 034 * @see org.kuali.ole.sys.businessobject.TimestampedBusinessObject#getLastUpdate() 035 */ 036 public Timestamp getLastUpdate() { 037 return this.lastUpdate; 038 } 039 040 /** 041 * @see org.kuali.ole.sys.businessobject.TimestampedBusinessObject#getLastUpdateUser() 042 */ 043 public Person getLastUpdateUser() { 044 Person user = null; 045 if (StringUtils.isNotBlank(lastUpdateUserId)) { 046 user = SpringContext.getBean(org.kuali.rice.kim.api.identity.PersonService.class).getPersonByPrincipalName(lastUpdateUserId); 047 } 048 049 return user; 050 } 051 052 /** 053 * @see org.kuali.ole.sys.businessobject.TimestampedBusinessObject#getLastUpdateUserId() 054 */ 055 public String getLastUpdateUserId() { 056 return this.lastUpdateUserId; 057 } 058 059 /** 060 * @param lastUpdateUserId The lastUpdateUserId to set. 061 */ 062 public void setLastUpdateUserId(String lastUpdateUserId) { 063 this.lastUpdateUserId = lastUpdateUserId; 064 } 065 066 /** 067 * @param lastUpdate The lastUpdate to set. 068 */ 069 public void setLastUpdate(Timestamp lastUpdate) { 070 this.lastUpdate = lastUpdate; 071 } 072 073 @Override protected void prePersist() { 074 super.prePersist(); 075 076 lastUpdate = new Timestamp((new Date()).getTime()); 077 lastUpdateUserId = GlobalVariables.getUserSession().getPerson().getPrincipalName(); 078 } 079 080 @Override protected void preUpdate() { 081 super.preUpdate(); 082 083 lastUpdate = new Timestamp((new Date()).getTime()); 084 lastUpdateUserId = GlobalVariables.getUserSession().getPerson().getPrincipalName(); 085 } 086}