Coverage Report - org.kuali.student.r2.common.entity.MetaEntity
 
Classes in this File Line Coverage Branch Coverage Complexity
MetaEntity
0%
0/32
0%
0/2
1.091
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  */
 15  
 
 16  
 package org.kuali.student.r2.common.entity;
 17  
 
 18  
 import java.util.Date;
 19  
 
 20  
 import javax.persistence.Column;
 21  
 import javax.persistence.Embeddable;
 22  
 import javax.persistence.MappedSuperclass;
 23  
 import javax.persistence.Temporal;
 24  
 import javax.persistence.TemporalType;
 25  
 
 26  
 import org.kuali.student.common.dto.MetaInfo;
 27  
 import org.kuali.student.common.util.security.SecurityUtils;
 28  
 import org.kuali.student.core.entity.BaseEntity;
 29  
 
 30  
 @MappedSuperclass
 31  
 @Embeddable
 32  0
 public abstract class MetaEntity extends BaseEntity{
 33  
         
 34  
         // Hibernate will not allow @Version in @Embeddable for some annoying reason
 35  
 //        @Version
 36  
 //        private long versionInd;
 37  
         
 38  
         @Temporal(TemporalType.TIMESTAMP)
 39  
         @Column(updatable=false)
 40  
         private Date createTime;
 41  
 
 42  
         @Column(updatable=false)
 43  
         private String createId;
 44  
 
 45  
         @Temporal(TemporalType.TIMESTAMP)
 46  
         private Date updateTime;
 47  
 
 48  
         private String updateId;
 49  
 
 50  
 //        public long getVersionInd() {
 51  
 //            return versionInd;
 52  
 //        }
 53  
 
 54  
 //        public void setVersionInd(long versionInd) {
 55  
 //            this.versionInd = versionInd;
 56  
 //        }
 57  
                 
 58  
         public Date getCreateTime() {
 59  0
                 return createTime;
 60  
         }
 61  
 
 62  
         public void setCreateTime(Date createTime) {
 63  0
                 this.createTime = createTime;
 64  0
         }
 65  
 
 66  
         public String getCreateId() {
 67  0
                 return createId;
 68  
         }
 69  
 
 70  
         public void setCreateId(String createId) {
 71  0
                 this.createId = createId;
 72  0
         }
 73  
         
 74  
         public Date getUpdateTime() {
 75  0
                 return updateTime;
 76  
         }
 77  
 
 78  
         public void setUpdateTime(Date updateTime) {
 79  0
                 this.updateTime = updateTime;
 80  0
         }
 81  
 
 82  
         public String getUpdateId() {
 83  0
                 return updateId;
 84  
         }
 85  
 
 86  
         public void setUpdateId(String updateId) {
 87  0
                 this.updateId = updateId;
 88  0
         }
 89  
 
 90  
         @Override
 91  
         protected void onPrePersist(){
 92  0
                 super.onPrePersist();
 93  0
                 setCreateTime(new Date());
 94  0
                 setUpdateTime(new Date());
 95  
 
 96  0
                 String user = SecurityUtils.getCurrentUserId();
 97  0
                 setCreateId(user);
 98  0
                 setUpdateId(user);
 99  
                 
 100  0
         }
 101  
         
 102  
         @Override
 103  
         protected void onPreUpdate(){
 104  0
                 super.onPreUpdate();
 105  
                 //This code should not be here, but hibernate is calling update callback instead of prepersit if the id is not null.
 106  0
                 if(getCreateTime() == null){
 107  0
                         setCreateTime(new Date());
 108  
                 }
 109  
 
 110  0
                 String user = SecurityUtils.getCurrentUserId();
 111  0
                 setUpdateId(user);
 112  0
         }
 113  
 
 114  
         public MetaInfo toDTO() {
 115  0
                 MetaInfo.Builder miBuilder = new MetaInfo.Builder();
 116  0
                 miBuilder.setCreateId(getCreateId());
 117  0
                 miBuilder.setCreateTime(getCreateTime());
 118  0
                 miBuilder.setUpdateId(getUpdateId());
 119  0
                 miBuilder.setUpdateTime(getUpdateTime());
 120  
                 // TODO: what about versionInd?
 121  0
                 return miBuilder.build();
 122  
         }
 123  
 }