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