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