Coverage Report - org.kuali.rice.krad.document.authorization.PessimisticLock
 
Classes in this File Line Coverage Branch Coverage Complexity
PessimisticLock
0%
0/28
N/A
1
 
 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.rice.krad.document.authorization;
 17  
 
 18  
 import org.hibernate.annotations.GenericGenerator;
 19  
 import org.hibernate.annotations.Parameter;
 20  
 import org.kuali.rice.core.api.CoreApiServiceLocator;
 21  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 22  
 import org.kuali.rice.kim.bo.Person;
 23  
 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
 24  
 
 25  
 import javax.persistence.*;
 26  
 import java.sql.Timestamp;
 27  
 
 28  
 /**
 29  
  * This is a business object used to lock a document pessimistically.
 30  
  * Pessimistic locking is more strick than optimistic locking and assumes if a
 31  
  * lock exists that a user should only have read-only access to a document. For
 32  
  * more information see documentation pages.
 33  
  * 
 34  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 35  
  * 
 36  
  */
 37  
 
 38  
 @Entity
 39  
 @Table(name="KRNS_PESSIMISTIC_LOCK_T")
 40  
 public class PessimisticLock extends PersistableBusinessObjectBase {
 41  
     
 42  
     private static final long serialVersionUID = -5210762282545093555L;
 43  
     
 44  0
     public static final String DEFAULT_LOCK_DESCRIPTOR = null;
 45  
     
 46  
     // id is sequence number and primary key
 47  
     @Id
 48  
     @GeneratedValue(generator="KRNS_LOCK_S")
 49  
         @GenericGenerator(name="KRNS_LOCK_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
 50  
                         @Parameter(name="sequence_name",value="KRNS_LOCK_S"),
 51  
                         @Parameter(name="value_column",value="id")
 52  
         })
 53  
     @Column(name="PESSIMISTIC_LOCK_ID")
 54  
     private Long id;
 55  
     
 56  
     @Column(name="PRNCPL_ID")
 57  
     private String ownedByPrincipalIdentifier;
 58  
     
 59  
     @Column(name="LOCK_DESC_TXT")
 60  
     private String lockDescriptor; // this will be defaulted to the value of DEFAULT_LOCK_DESCRIPTOR constant above
 61  
     
 62  
     @Column(name="GNRT_DT")
 63  
     private Timestamp generatedTimestamp;
 64  
     
 65  
     @Column(name="DOC_HDR_ID")
 66  
     private String documentNumber; // foreign key to document
 67  
     
 68  
     @Transient
 69  
     private Person ownedByUser;
 70  
 
 71  
     
 72  
     /**
 73  
      * This constructs an empty lock using the logged in user and default lock descriptor type
 74  
      * but will NOT assign a document number.  Use another constructor.
 75  
      * @deprecated
 76  
      */
 77  
     @Deprecated
 78  0
     public PessimisticLock() {}
 79  
     
 80  
     /**
 81  
      * This constructs a lock object using the logged in user and given lock type
 82  
      */
 83  0
     public PessimisticLock(String documentNumber, String lockDescriptor, Person user) {
 84  0
         this.documentNumber = documentNumber;
 85  0
         this.ownedByPrincipalIdentifier = user.getPrincipalId();
 86  0
         this.lockDescriptor = lockDescriptor;  
 87  0
         this.generatedTimestamp = CoreApiServiceLocator.getDateTimeService().getCurrentTimestamp();
 88  0
     }
 89  
     
 90  
     public boolean isOwnedByUser(Person user) {
 91  0
         return user.getPrincipalId().equals(getOwnedByPrincipalIdentifier());
 92  
     }
 93  
     
 94  
     /**
 95  
      * @return the id
 96  
      */
 97  
     public Long getId() {
 98  0
         return this.id;
 99  
     }
 100  
 
 101  
     /**
 102  
      * @param id the id to set
 103  
      */
 104  
     public void setId(Long id) {
 105  0
         this.id = id;
 106  0
     }
 107  
 
 108  
     /**
 109  
      * @return the ownedByPrincipalIdentifier
 110  
      */
 111  
     public String getOwnedByPrincipalIdentifier() {
 112  0
         return this.ownedByPrincipalIdentifier;
 113  
     }
 114  
 
 115  
     /**
 116  
      * @param ownedByPrincipalIdentifier the ownedByPrincipalIdentifier to set
 117  
      */
 118  
     public void setOwnedByPrincipalIdentifier(String ownedByPrincipalIdentifier) {
 119  0
         this.ownedByPrincipalIdentifier = ownedByPrincipalIdentifier;
 120  0
     }
 121  
 
 122  
     /**
 123  
      * @return the lockDescriptor
 124  
      */
 125  
     public String getLockDescriptor() {
 126  0
         return this.lockDescriptor;
 127  
     }
 128  
 
 129  
     /**
 130  
      * @param lockDescriptor the lockDescriptor to set
 131  
      */
 132  
     public void setLockDescriptor(String lockDescriptor) {
 133  0
         this.lockDescriptor = lockDescriptor;
 134  0
     }
 135  
 
 136  
     /**
 137  
      * @return the generatedTimestamp
 138  
      */
 139  
     public Timestamp getGeneratedTimestamp() {
 140  0
         return this.generatedTimestamp;
 141  
     }
 142  
 
 143  
     /**
 144  
      * @param generatedTimestamp the generatedTimestamp to set
 145  
      */
 146  
     public void setGeneratedTimestamp(Timestamp generatedTimestamp) {
 147  0
         this.generatedTimestamp = generatedTimestamp;
 148  0
     }
 149  
 
 150  
     /**
 151  
      * @return the documentNumber
 152  
      */
 153  
     public String getDocumentNumber() {
 154  0
         return this.documentNumber;
 155  
     }
 156  
 
 157  
     /**
 158  
      * @param documentNumber the documentNumber to set
 159  
      */
 160  
     public void setDocumentNumber(String documentNumber) {
 161  0
         this.documentNumber = documentNumber;
 162  0
     }
 163  
 
 164  
     /**
 165  
      * @return the ownedByUser
 166  
      */
 167  
     public Person getOwnedByUser() {
 168  0
         ownedByUser = KimApiServiceLocator.getPersonService().updatePersonIfNecessary(ownedByPrincipalIdentifier, ownedByUser);
 169  0
         return ownedByUser;
 170  
     }
 171  
 
 172  
     /**
 173  
      * @param ownedByUser the ownedByUser to set
 174  
      */
 175  
     public void setOwnedByUser(Person ownedByUser) {
 176  0
         this.ownedByUser = ownedByUser;
 177  0
     }
 178  
 }
 179