Coverage Report - org.kuali.rice.krad.datadictionary.DocumentEntry
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentEntry
0%
0/102
0%
0/32
1.61
 
 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.datadictionary;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.krad.datadictionary.exception.ClassValidationException;
 20  
 import org.kuali.rice.krad.datadictionary.exception.DuplicateEntryException;
 21  
 import org.kuali.rice.krad.document.Document;
 22  
 import org.kuali.rice.krad.document.authorization.DocumentAuthorizer;
 23  
 import org.kuali.rice.krad.document.authorization.DocumentPresentationController;
 24  
 import org.kuali.rice.krad.keyvalues.KeyValuesFinder;
 25  
 import org.kuali.rice.krad.rule.BusinessRule;
 26  
 
 27  
 import java.util.ArrayList;
 28  
 import java.util.LinkedHashMap;
 29  
 import java.util.List;
 30  
 import java.util.Map;
 31  
 
 32  
 /**
 33  
  * A single Document entry in the DataDictionary, which contains information relating to the display, validation, and
 34  
  * general
 35  
  * maintenance of a Document (transactional or maintenance) and its attributes.
 36  
  * <p/>
 37  
  * Note: the setters do copious amounts of validation, to facilitate generating errors during the parsing process
 38  
  *
 39  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 40  
  */
 41  0
 abstract public class DocumentEntry extends DataDictionaryEntryBase {
 42  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DocumentEntry.class);
 43  
     private static final long serialVersionUID = 8231730871830055356L;
 44  
 
 45  
     protected String documentTypeName;
 46  
 
 47  
     protected Class<? extends Document> documentClass;
 48  
     protected Class<? extends Document> baseDocumentClass;
 49  
     protected Class<? extends BusinessRule> businessRulesClass;
 50  
 
 51  0
     protected boolean allowsNoteAttachments = true;
 52  0
     protected boolean allowsNoteFYI = false;
 53  
     protected Class<? extends KeyValuesFinder> attachmentTypesValuesFinderClass;
 54  0
     protected boolean displayTopicFieldInNotes = false;
 55  0
     protected boolean usePessimisticLocking = false;
 56  0
     protected boolean useWorkflowPessimisticLocking = false;
 57  0
     protected boolean encryptDocumentDataInPersistentSessionStorage = false;
 58  
 
 59  0
     protected boolean allowsCopy = false;
 60  
     protected WorkflowProperties workflowProperties;
 61  
     protected WorkflowAttributes workflowAttributes;
 62  
 
 63  0
     protected List<ReferenceDefinition> defaultExistenceChecks = new ArrayList<ReferenceDefinition>();
 64  0
     protected Map<String, ReferenceDefinition> defaultExistenceCheckMap =
 65  
             new LinkedHashMap<String, ReferenceDefinition>();
 66  
 
 67  
     protected Class<? extends DocumentAuthorizer> documentAuthorizerClass;
 68  
     protected Class<? extends DocumentPresentationController> documentPresentationControllerClass;
 69  
 
 70  
     /**
 71  
      * @see org.kuali.rice.krad.datadictionary.DataDictionaryEntry#getJstlKey()
 72  
      */
 73  
     public String getJstlKey() {
 74  0
         return documentTypeName;
 75  
     }
 76  
 
 77  
     /**
 78  
      * The documentClass element is the name of the java class
 79  
      * associated with the document.
 80  
      */
 81  
     public void setDocumentClass(Class<? extends Document> documentClass) {
 82  0
         if (documentClass == null) {
 83  0
             throw new IllegalArgumentException("invalid (null) documentClass");
 84  
         }
 85  
 
 86  0
         this.documentClass = documentClass;
 87  0
     }
 88  
 
 89  
     public Class<? extends Document> getDocumentClass() {
 90  0
         return documentClass;
 91  
     }
 92  
 
 93  
     /**
 94  
      * The optional baseDocumentClass element is the name of the java superclass
 95  
      * associated with the document. This gives the data dictionary the ability
 96  
      * to index by the superclass in addition to the current class.
 97  
      */
 98  
     public void setBaseDocumentClass(Class<? extends Document> baseDocumentClass) {
 99  0
         this.baseDocumentClass = baseDocumentClass;
 100  0
     }
 101  
 
 102  
     public Class<? extends Document> getBaseDocumentClass() {
 103  0
         return baseDocumentClass;
 104  
     }
 105  
 
 106  
     /**
 107  
      * The businessRulesClass element is the full class name of the java
 108  
      * class which contains the business rules for a document.
 109  
      */
 110  
     public void setBusinessRulesClass(Class<? extends BusinessRule> businessRulesClass) {
 111  0
         this.businessRulesClass = businessRulesClass;
 112  0
     }
 113  
 
 114  
     public Class<? extends BusinessRule> getBusinessRulesClass() {
 115  0
         return businessRulesClass;
 116  
     }
 117  
 
 118  
     /**
 119  
      * The documentTypeName element is the name of the document
 120  
      * as defined in the workflow system.
 121  
      * Example: "AddressTypeMaintenanceDocument"
 122  
      */
 123  
     public void setDocumentTypeName(String documentTypeName) {
 124  0
         if (StringUtils.isBlank(documentTypeName)) {
 125  0
             throw new IllegalArgumentException("invalid (blank) documentTypeName");
 126  
         }
 127  0
         this.documentTypeName = documentTypeName;
 128  0
     }
 129  
 
 130  
     public String getDocumentTypeName() {
 131  0
         return this.documentTypeName;
 132  
     }
 133  
 
 134  
     /**
 135  
      * Validate common fields for subclass' benefit.
 136  
      *
 137  
      * @see org.kuali.rice.krad.datadictionary.DataDictionaryEntry#completeValidation()
 138  
      */
 139  
     public void completeValidation() {
 140  0
         super.completeValidation();
 141  
 
 142  0
         if (baseDocumentClass != null && !baseDocumentClass.isAssignableFrom(documentClass)) {
 143  0
             throw new ClassValidationException("The baseDocumentClass " + baseDocumentClass.getName() +
 144  
                     " is not a superclass of the documentClass " + documentClass.getName());
 145  
         }
 146  
 
 147  0
         if (workflowProperties != null && workflowAttributes != null) {
 148  0
             throw new DataDictionaryException(documentTypeName +
 149  
                     ": workflowProperties and workflowAttributes cannot both be defined for a document");
 150  
         }
 151  0
     }
 152  
 
 153  
     /**
 154  
      * @see org.kuali.rice.krad.datadictionary.DataDictionaryEntry#getFullClassName()
 155  
      */
 156  
     public String getFullClassName() {
 157  0
         if (getBaseDocumentClass() != null) {
 158  0
             return getBaseDocumentClass().getName();
 159  
         }
 160  0
         if (getDocumentClass() != null) {
 161  0
             return getDocumentClass().getName();
 162  
         }
 163  0
         return "";
 164  
     }
 165  
 
 166  
     /**
 167  
      * @see org.kuali.rice.krad.datadictionary.DataDictionaryEntryBase#getEntryClass()
 168  
      */
 169  
     public Class getEntryClass() {
 170  0
         return getDocumentClass();
 171  
     }
 172  
 
 173  
     public String toString() {
 174  0
         return "DocumentEntry for documentType " + documentTypeName;
 175  
     }
 176  
 
 177  
     /**
 178  
      * Accessor method for contained displayTopicFieldInNotes
 179  
      *
 180  
      * @return displayTopicFieldInNotes boolean
 181  
      */
 182  
     public boolean getDisplayTopicFieldInNotes() {
 183  0
         return displayTopicFieldInNotes;
 184  
     }
 185  
 
 186  
     /**
 187  
      * This field contains a value of true or false.
 188  
      * If true, then the "Notes and Attachments" tab will render a column for a note topic.
 189  
      */
 190  
     public void setDisplayTopicFieldInNotes(boolean displayTopicFieldInNotes) {
 191  0
         this.displayTopicFieldInNotes = displayTopicFieldInNotes;
 192  0
     }
 193  
 
 194  
     /**
 195  
      * Accessor method for contained usePessimisticLocking
 196  
      *
 197  
      * @return usePessimisticLocking boolean
 198  
      */
 199  
     public boolean getUsePessimisticLocking() {
 200  0
         return this.usePessimisticLocking;
 201  
     }
 202  
 
 203  
     /**
 204  
      * @param usePessimisticLocking
 205  
      */
 206  
     public void setUsePessimisticLocking(boolean usePessimisticLocking) {
 207  0
         if (LOG.isDebugEnabled()) {
 208  0
             LOG.debug("calling setUsePessimisticLocking '" + usePessimisticLocking + "'");
 209  
         }
 210  
 
 211  0
         this.usePessimisticLocking = usePessimisticLocking;
 212  0
     }
 213  
 
 214  
     /**
 215  
      * Accessor method for contained useWorkflowPessimisticLocking
 216  
      *
 217  
      * @return useWorkflowPessimisticLocking boolean
 218  
      */
 219  
     public boolean getUseWorkflowPessimisticLocking() {
 220  0
         return this.useWorkflowPessimisticLocking;
 221  
     }
 222  
 
 223  
     /**
 224  
      * @param useWorkflowPessimisticLocking
 225  
      */
 226  
     public void setUseWorkflowPessimisticLocking(boolean useWorkflowPessimisticLocking) {
 227  0
         if (LOG.isDebugEnabled()) {
 228  0
             LOG.debug("calling setuseWorkflowPessimisticLocking '" + useWorkflowPessimisticLocking + "'");
 229  
         }
 230  
 
 231  0
         this.useWorkflowPessimisticLocking = useWorkflowPessimisticLocking;
 232  0
     }
 233  
 
 234  
     /**
 235  
      * The attachmentTypesValuesFinderClass specifies the name of a values finder
 236  
      * class. This is used to determine the set of file types that are allowed
 237  
      * to be attached to the document.
 238  
      */
 239  
     public void setAttachmentTypesValuesFinderClass(Class<? extends KeyValuesFinder> attachmentTypesValuesFinderClass) {
 240  0
         if (attachmentTypesValuesFinderClass == null) {
 241  0
             throw new IllegalArgumentException("invalid (null) attachmentTypesValuesFinderClass");
 242  
         }
 243  
 
 244  0
         this.attachmentTypesValuesFinderClass = attachmentTypesValuesFinderClass;
 245  0
     }
 246  
 
 247  
     /**
 248  
      * @see org.kuali.rice.krad.datadictionary.control.ControlDefinition#getKeyValuesFinder()
 249  
      */
 250  
     public Class<? extends KeyValuesFinder> getAttachmentTypesValuesFinderClass() {
 251  0
         return attachmentTypesValuesFinderClass;
 252  
     }
 253  
 
 254  
     /**
 255  
      * The allowsCopy element contains a true or false value.
 256  
      * If true, then a user is allowed to make a copy of the
 257  
      * record using the maintenance screen.
 258  
      */
 259  
     public void setAllowsCopy(boolean allowsCopy) {
 260  0
         this.allowsCopy = allowsCopy;
 261  0
     }
 262  
 
 263  
     public boolean getAllowsCopy() {
 264  0
         return allowsCopy;
 265  
     }
 266  
 
 267  
     /**
 268  
      * @return the allowsNoteAttachments
 269  
      */
 270  
     public boolean getAllowsNoteAttachments() {
 271  0
         return this.allowsNoteAttachments;
 272  
     }
 273  
 
 274  
     /**
 275  
      * The allowsNoteAttachments element contains a true or false value.
 276  
      * If true, then a document screen includes notes with attachments. Otherwise,
 277  
      * only notes is displayed.
 278  
      */
 279  
     public void setAllowsNoteAttachments(boolean allowsNoteAttachments) {
 280  0
         this.allowsNoteAttachments = allowsNoteAttachments;
 281  0
     }
 282  
 
 283  
     /**
 284  
      * @return the allowsNoteFYI
 285  
      */
 286  
     public boolean getAllowsNoteFYI() {
 287  0
         return allowsNoteFYI;
 288  
     }
 289  
 
 290  
     /**
 291  
      * This is an indicator for determining whether to render the AdHoc FYI recipient box and Send FYI button.
 292  
      */
 293  
     public void setAllowsNoteFYI(boolean allowsNoteFYI) {
 294  0
         this.allowsNoteFYI = allowsNoteFYI;
 295  0
     }
 296  
 
 297  
     public WorkflowProperties getWorkflowProperties() {
 298  0
         return this.workflowProperties;
 299  
     }
 300  
 
 301  
     /**
 302  
      * This element is used to define a set of workflowPropertyGroups, which are used to
 303  
      * specify which document properties should be serialized during the document serialization
 304  
      * process.
 305  
      */
 306  
     public void setWorkflowProperties(WorkflowProperties workflowProperties) {
 307  0
         this.workflowProperties = workflowProperties;
 308  0
     }
 309  
 
 310  
     public WorkflowAttributes getWorkflowAttributes() {
 311  0
         return this.workflowAttributes;
 312  
     }
 313  
 
 314  
     public void setWorkflowAttributes(WorkflowAttributes workflowAttributes) {
 315  0
         this.workflowAttributes = workflowAttributes;
 316  0
     }
 317  
 
 318  
     /**
 319  
      * @return List of all defaultExistenceCheck ReferenceDefinitions associated with this MaintenanceDocument, in the
 320  
      *         order in
 321  
      *         which they were added
 322  
      */
 323  
     public List<ReferenceDefinition> getDefaultExistenceChecks() {
 324  0
         return defaultExistenceChecks;
 325  
     }
 326  
 
 327  
     /*
 328  
            The defaultExistenceChecks element contains a list of
 329  
            reference object names which are required to exist when maintaining a BO.
 330  
            Optionally, the reference objects can be required to be active.
 331  
 
 332  
            JSTL: defaultExistenceChecks is a Map of Reference elements,
 333  
            whose entries are keyed by attributeName
 334  
     */
 335  
     public void setDefaultExistenceChecks(List<ReferenceDefinition> defaultExistenceChecks) {
 336  0
         this.defaultExistenceChecks = defaultExistenceChecks;
 337  0
     }
 338  
 
 339  
     /**
 340  
      * @return List of all defaultExistenceCheck reference fieldNames associated with this MaintenanceDocument, in the
 341  
      *         order in
 342  
      *         which they were added
 343  
      */
 344  
     public List<String> getDefaultExistenceCheckFieldNames() {
 345  0
         List<String> fieldNames = new ArrayList<String>();
 346  0
         fieldNames.addAll(this.defaultExistenceCheckMap.keySet());
 347  
 
 348  0
         return fieldNames;
 349  
     }
 350  
 
 351  
     public boolean isEncryptDocumentDataInPersistentSessionStorage() {
 352  0
         return this.encryptDocumentDataInPersistentSessionStorage;
 353  
     }
 354  
 
 355  
     public void setEncryptDocumentDataInPersistentSessionStorage(
 356  
             boolean encryptDocumentDataInPersistentSessionStorage) {
 357  0
         this.encryptDocumentDataInPersistentSessionStorage = encryptDocumentDataInPersistentSessionStorage;
 358  0
     }
 359  
 
 360  
     /**
 361  
      * The documentAuthorizerClass element is the full class name of the
 362  
      * java class which will determine what features are available to the
 363  
      * user based on the user role and document state.
 364  
      */
 365  
     public void setDocumentAuthorizerClass(Class<? extends DocumentAuthorizer> documentAuthorizerClass) {
 366  0
         this.documentAuthorizerClass = documentAuthorizerClass;
 367  0
     }
 368  
 
 369  
     /**
 370  
      * Returns the document authorizer class for the document.  Only framework code should be calling this method.
 371  
      * Client devs should use {@link DocumentTypeService#getDocumentAuthorizer(org.kuali.rice.krad.document.Document)}
 372  
      * or
 373  
      * {@link DocumentTypeService#getDocumentAuthorizer(String)}
 374  
      *
 375  
      * @return a document authorizer class
 376  
      */
 377  
     public Class<? extends DocumentAuthorizer> getDocumentAuthorizerClass() {
 378  0
         return documentAuthorizerClass;
 379  
     }
 380  
 
 381  
     /**
 382  
      * Returns the document presentation controller class for the document.  Only framework code should be calling this
 383  
      * method.
 384  
      * Client devs should use {@link DocumentTypeService#getDocumentPresentationController(org.kuali.rice.krad.document.Document)}
 385  
      * or
 386  
      * {@link DocumentTypeService#getDocumentPresentationController(String)}
 387  
      *
 388  
      * @return the documentPresentationControllerClass
 389  
      */
 390  
     public Class<? extends DocumentPresentationController> getDocumentPresentationControllerClass() {
 391  0
         return this.documentPresentationControllerClass;
 392  
     }
 393  
 
 394  
     /**
 395  
      * @param documentPresentationControllerClass the documentPresentationControllerClass to set
 396  
      */
 397  
     public void setDocumentPresentationControllerClass(
 398  
             Class<? extends DocumentPresentationController> documentPresentationControllerClass) {
 399  0
         this.documentPresentationControllerClass = documentPresentationControllerClass;
 400  0
     }
 401  
 
 402  
     /**
 403  
      * This overridden method ...
 404  
      *
 405  
      * @see org.kuali.rice.krad.datadictionary.DataDictionaryEntryBase#afterPropertiesSet()
 406  
      */
 407  
     @Override
 408  
     public void afterPropertiesSet() throws Exception {
 409  0
         super.afterPropertiesSet();
 410  0
         if (defaultExistenceChecks != null) {
 411  0
             defaultExistenceCheckMap.clear();
 412  0
             for (ReferenceDefinition reference : defaultExistenceChecks) {
 413  0
                 if (reference == null) {
 414  0
                     throw new IllegalArgumentException("invalid (null) defaultExistenceCheck");
 415  
                 }
 416  
 
 417  0
                 String keyName = reference.isCollectionReference() ?
 418  
                         (reference.getCollection() + "." + reference.getAttributeName()) : reference.getAttributeName();
 419  0
                 if (defaultExistenceCheckMap.containsKey(keyName)) {
 420  0
                     throw new DuplicateEntryException(
 421  
                             "duplicate defaultExistenceCheck entry for attribute '" + keyName + "'");
 422  
                 }
 423  0
                 reference.setBusinessObjectClass(getEntryClass());
 424  0
                 defaultExistenceCheckMap.put(keyName, reference);
 425  0
             }
 426  
         }
 427  0
     }
 428  
 }