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