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