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-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.kew.doctype;
 17  
 
 18  
 import org.kuali.rice.kew.doctype.bo.DocumentType;
 19  
 import org.kuali.rice.kew.api.KewApiConstants;
 20  
 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
 21  
 
 22  
 import javax.persistence.*;
 23  
 
 24  
 
 25  
 /**
 26  
  * Model bean representing a policy of a document type.
 27  
  *
 28  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 29  
  */
 30  
 @Entity
 31  
 @Table(name="KREW_DOC_TYP_PLCY_RELN_T")
 32  
 public class DocumentTypePolicy extends PersistableBusinessObjectBase {
 33  
         private static final long serialVersionUID = -4612246888683336474L;
 34  
 
 35  
         @EmbeddedId
 36  
         private DocumentTypePolicyId documentTypePolicyId;
 37  
     @Column(name="PLCY_NM")
 38  
         private Boolean policyValue;
 39  
     @Column(name="PLCY_VAL")
 40  
     private String policyStringValue;
 41  
     @Transient
 42  
     private Boolean inheritedFlag;
 43  
     @MapsId("documentTypeId")
 44  
     @ManyToOne(fetch=FetchType.EAGER)
 45  
         @JoinColumn(name="DOC_TYP_ID")
 46  
         private DocumentType documentType;
 47  
     
 48  
     @Transient
 49  
     private String documentTypeId;
 50  
     @Transient
 51  
     private String policyName;
 52  
 
 53  0
     public DocumentTypePolicy() {
 54  0
     }
 55  
 
 56  0
     public DocumentTypePolicy(String policyName, Boolean policyValue) {
 57  0
             this.policyName = policyName;
 58  0
             this.getDocumentTypePolicyId().setPolicyName(policyName);
 59  0
         this.policyValue = policyValue;
 60  0
     }
 61  
 
 62  
     public DocumentTypePolicyId getDocumentTypePolicyId() {
 63  0
             if (this.documentTypePolicyId == null) {
 64  0
                     this.documentTypePolicyId = new DocumentTypePolicyId();
 65  
             }
 66  0
                 return this.documentTypePolicyId;
 67  
         }
 68  
 
 69  
         public void setDocumentTypePolicyId(DocumentTypePolicyId documentTypePolicyId) {
 70  0
                 this.documentTypePolicyId = documentTypePolicyId;
 71  0
         }
 72  
 
 73  
         public String getPolicyDisplayValue() {
 74  0
         if(policyValue != null){
 75  0
             if(policyValue.booleanValue()){
 76  0
                 return "Active";
 77  
             } else {
 78  0
                 return "Inactive";
 79  
             }
 80  
         }
 81  0
         return "Inherited";
 82  
     }
 83  
 
 84  
     public Boolean getInheritedFlag() {
 85  0
         return inheritedFlag;
 86  
     }
 87  
 
 88  
     public void setInheritedFlag(Boolean inheritedFlag) {
 89  0
         this.inheritedFlag = inheritedFlag;
 90  0
     }
 91  
     
 92  
     public boolean isAllowUnrequestedAction() {
 93  0
         return KewApiConstants.ALLOW_UNREQUESTED_ACTION_POLICY.equals(this.getPolicyName());
 94  
     }
 95  
 
 96  
     public boolean isDefaultApprove() {
 97  0
         return KewApiConstants.DEFAULT_APPROVE_POLICY.equals(this.getPolicyName());
 98  
     }
 99  
 
 100  
     public boolean isDisApprove() {
 101  0
         return KewApiConstants.DISAPPROVE_POLICY.equals(this.getPolicyName());
 102  
     }
 103  
 
 104  
     public String getDocumentTypeId() {
 105  0
         return (getDocumentTypePolicyId().getDocumentTypeId() != null) ? getDocumentTypePolicyId().getDocumentTypeId() : this.documentTypeId;
 106  
     }
 107  
 
 108  
     public void setDocumentTypeId(String documentTypeId) {
 109  0
             this.documentTypeId = documentTypeId;
 110  0
         this.getDocumentTypePolicyId().setDocumentTypeId(documentTypeId);
 111  0
     }
 112  
 
 113  
     public String getPolicyName() {
 114  0
         return (this.getDocumentTypePolicyId().getPolicyName() != null) ? this.getDocumentTypePolicyId().getPolicyName() : this.policyName;
 115  
     }
 116  
 
 117  
     public void setPolicyName(String policyName) {
 118  
         /* Cleanse the input.
 119  
          * This is surely not the best way to validate the policy name;
 120  
          * it would probably be better to use typesafe enums accross the board
 121  
          * but that would probably entail refactoring large swaths of code, not
 122  
          * to mention reconfiguring OJB (can typesafe enums be used?) and dealing
 123  
          * with serialization compatibility issues (if any).
 124  
          * So instead, let's just be sure to fail-fast.
 125  
          */
 126  0
         DocumentTypePolicyEnum policy = DocumentTypePolicyEnum.lookup(policyName);
 127  0
         this.policyName = policy.getName();
 128  0
         this.getDocumentTypePolicyId().setPolicyName(policy.getName());
 129  0
     }
 130  
 
 131  
     public Boolean getPolicyValue() {
 132  0
         return policyValue;
 133  
     }
 134  
 
 135  
     public void setPolicyValue(Boolean policyValue) {
 136  0
         this.policyValue = policyValue;
 137  0
     }
 138  
 
 139  
     public String getPolicyStringValue() {
 140  0
         return policyStringValue;
 141  
     }
 142  
 
 143  
     public void setPolicyStringValue(String policyStringValue) {
 144  0
         this.policyStringValue = policyStringValue;
 145  0
     }
 146  
 
 147  
     public Object copy(boolean preserveKeys) {
 148  0
         DocumentTypePolicy clone = new DocumentTypePolicy();
 149  
 
 150  0
         if(preserveKeys && this.getDocumentTypeId() != null){
 151  0
             clone.setDocumentTypeId(this.getDocumentTypeId());
 152  
         }
 153  0
         if(this.getPolicyName() != null){
 154  0
             clone.setPolicyName(new String(this.getPolicyName()));
 155  
         }
 156  
 
 157  0
         if(policyValue != null){
 158  0
             clone.setPolicyValue(new Boolean(policyValue.booleanValue()));
 159  
         }
 160  
         
 161  0
         if(policyStringValue != null){
 162  0
             clone.setPolicyStringValue(new String(policyStringValue));
 163  
         }
 164  
 
 165  0
         return clone;
 166  
     }
 167  
 
 168  
     public DocumentType getDocumentType() {
 169  0
         return documentType;
 170  
     }
 171  
 
 172  
     public void setDocumentType(DocumentType documentType) {
 173  0
         this.documentType = documentType;
 174  0
     }
 175  
 }