Coverage Report - org.kuali.rice.kew.doctype.DocumentTypePolicy
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentTypePolicy
0%
0/51
0%
0/20
1.571
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  *
 4  
  *
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.kew.doctype;
 18  
 
 19  
 import org.kuali.rice.kew.doctype.bo.DocumentType;
 20  
 import org.kuali.rice.kew.util.KEWConstants;
 21  
 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
 22  
 
 23  
 import javax.persistence.*;
 24  
 
 25  
 
 26  
 /**
 27  
  * Model bean representing a policy of a document type.
 28  
  *
 29  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 30  
  */
 31  
 @Entity
 32  
 @Table(name="KREW_DOC_TYP_PLCY_RELN_T")
 33  
 public class DocumentTypePolicy extends PersistableBusinessObjectBase {
 34  
         private static final long serialVersionUID = -4612246888683336474L;
 35  
 
 36  
         @EmbeddedId
 37  
         private DocumentTypePolicyId documentTypePolicyId;
 38  
     @Column(name="PLCY_NM")
 39  
         private Boolean policyValue;
 40  
     @Column(name="PLCY_VAL")
 41  
     private String policyStringValue;
 42  
     @Transient
 43  
     private Boolean inheritedFlag;
 44  
     @MapsId("documentTypeId")
 45  
     @ManyToOne(fetch=FetchType.EAGER)
 46  
         @JoinColumn(name="DOC_TYP_ID")
 47  
         private DocumentType documentType;
 48  
     
 49  
     @Transient
 50  
     private String documentTypeId;
 51  
     @Transient
 52  
     private String policyName;
 53  
 
 54  0
     public DocumentTypePolicy() {
 55  0
     }
 56  
 
 57  0
     public DocumentTypePolicy(String policyName, Boolean policyValue) {
 58  0
             this.policyName = policyName;
 59  0
             this.getDocumentTypePolicyId().setPolicyName(policyName);
 60  0
         this.policyValue = policyValue;
 61  0
     }
 62  
 
 63  
     public DocumentTypePolicyId getDocumentTypePolicyId() {
 64  0
             if (this.documentTypePolicyId == null) {
 65  0
                     this.documentTypePolicyId = new DocumentTypePolicyId();
 66  
             }
 67  0
                 return this.documentTypePolicyId;
 68  
         }
 69  
 
 70  
         public void setDocumentTypePolicyId(DocumentTypePolicyId documentTypePolicyId) {
 71  0
                 this.documentTypePolicyId = documentTypePolicyId;
 72  0
         }
 73  
 
 74  
         public String getPolicyDisplayValue() {
 75  0
         if(policyValue != null){
 76  0
             if(policyValue.booleanValue()){
 77  0
                 return "Active";
 78  
             } else {
 79  0
                 return "Inactive";
 80  
             }
 81  
         }
 82  0
         return "Inherited";
 83  
     }
 84  
 
 85  
     public Boolean getInheritedFlag() {
 86  0
         return inheritedFlag;
 87  
     }
 88  
 
 89  
     public void setInheritedFlag(Boolean inheritedFlag) {
 90  0
         this.inheritedFlag = inheritedFlag;
 91  0
     }
 92  
     
 93  
     public boolean isAllowUnrequestedAction() {
 94  0
         return KEWConstants.ALLOW_UNREQUESTED_ACTION_POLICY.equals(this.getPolicyName());
 95  
     }
 96  
 
 97  
     public boolean isDefaultApprove() {
 98  0
         return KEWConstants.DEFAULT_APPROVE_POLICY.equals(this.getPolicyName());
 99  
     }
 100  
 
 101  
     public boolean isDisApprove() {
 102  0
         return KEWConstants.DISAPPROVE_POLICY.equals(this.getPolicyName());
 103  
     }
 104  
 
 105  
     public String getDocumentTypeId() {
 106  0
         return (getDocumentTypePolicyId().getDocumentTypeId() != null) ? getDocumentTypePolicyId().getDocumentTypeId() : this.documentTypeId;
 107  
     }
 108  
 
 109  
     public void setDocumentTypeId(String documentTypeId) {
 110  0
             this.documentTypeId = documentTypeId;
 111  0
         this.getDocumentTypePolicyId().setDocumentTypeId(documentTypeId);
 112  0
     }
 113  
 
 114  
     public String getPolicyName() {
 115  0
         return (this.getDocumentTypePolicyId().getPolicyName() != null) ? this.getDocumentTypePolicyId().getPolicyName() : this.policyName;
 116  
     }
 117  
 
 118  
     public void setPolicyName(String policyName) {
 119  
         /* Cleanse the input.
 120  
          * This is surely not the best way to validate the policy name;
 121  
          * it would probably be better to use typesafe enums accross the board
 122  
          * but that would probably entail refactoring large swaths of code, not
 123  
          * to mention reconfiguring OJB (can typesafe enums be used?) and dealing
 124  
          * with serialization compatibility issues (if any).
 125  
          * So instead, let's just be sure to fail-fast.
 126  
          */
 127  0
         DocumentTypePolicyEnum policy = DocumentTypePolicyEnum.lookup(policyName);
 128  0
         this.policyName = policy.getName();
 129  0
         this.getDocumentTypePolicyId().setPolicyName(policy.getName());
 130  0
     }
 131  
 
 132  
     public Boolean getPolicyValue() {
 133  0
         return policyValue;
 134  
     }
 135  
 
 136  
     public void setPolicyValue(Boolean policyValue) {
 137  0
         this.policyValue = policyValue;
 138  0
     }
 139  
 
 140  
     public String getPolicyStringValue() {
 141  0
         return policyStringValue;
 142  
     }
 143  
 
 144  
     public void setPolicyStringValue(String policyStringValue) {
 145  0
         this.policyStringValue = policyStringValue;
 146  0
     }
 147  
 
 148  
     public Object copy(boolean preserveKeys) {
 149  0
         DocumentTypePolicy clone = new DocumentTypePolicy();
 150  
 
 151  0
         if(preserveKeys && this.getDocumentTypeId() != null){
 152  0
             clone.setDocumentTypeId(this.getDocumentTypeId());
 153  
         }
 154  0
         if(this.getPolicyName() != null){
 155  0
             clone.setPolicyName(new String(this.getPolicyName()));
 156  
         }
 157  
 
 158  0
         if(policyValue != null){
 159  0
             clone.setPolicyValue(new Boolean(policyValue.booleanValue()));
 160  
         }
 161  
         
 162  0
         if(policyStringValue != null){
 163  0
             clone.setPolicyStringValue(new String(policyStringValue));
 164  
         }
 165  
 
 166  0
         return clone;
 167  
     }
 168  
 
 169  
     public DocumentType getDocumentType() {
 170  0
         return documentType;
 171  
     }
 172  
 
 173  
     public void setDocumentType(DocumentType documentType) {
 174  0
         this.documentType = documentType;
 175  0
     }
 176  
 }