Coverage Report - org.kuali.rice.kns.datadictionary.MaintenanceDocumentEntry
 
Classes in this File Line Coverage Branch Coverage Complexity
MaintenanceDocumentEntry
0%
0/87
0%
0/34
1.963
 
 1  
 /*
 2  
  * Copyright 2005-2008 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.kns.datadictionary;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.LinkedHashMap;
 20  
 import java.util.List;
 21  
 import java.util.Map;
 22  
 
 23  
 import org.kuali.rice.kns.bo.BusinessObject;
 24  
 import org.kuali.rice.kns.datadictionary.exception.AttributeValidationException;
 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.MaintenanceDocumentBase;
 29  
 import org.kuali.rice.kns.document.authorization.MaintenanceDocumentAuthorizer;
 30  
 import org.kuali.rice.kns.maintenance.Maintainable;
 31  
 
 32  
 /**
 33  
  * MaintenanceDocumentEntry
 34  
  * 
 35  
  * 
 36  
  */
 37  
 public class MaintenanceDocumentEntry extends DocumentEntry {
 38  
 
 39  
     protected Class<? extends BusinessObject> businessObjectClass;
 40  
     protected Class<? extends Maintainable> maintainableClass;
 41  
 
 42  0
     protected List<MaintainableSectionDefinition> maintainableSections = new ArrayList<MaintainableSectionDefinition>();
 43  0
     protected List<String> lockingKeys = new ArrayList<String>();
 44  0
     protected List<ApcRuleDefinition> apcRules = new ArrayList<ApcRuleDefinition>();
 45  0
     protected Map<String,MaintainableSectionDefinition> maintainableSectionMap = new LinkedHashMap<String, MaintainableSectionDefinition>();
 46  0
     protected Map<String,ApcRuleDefinition> apcRuleMap = new LinkedHashMap<String, ApcRuleDefinition>();
 47  
     
 48  0
     protected boolean allowsNewOrCopy = true;
 49  
     protected String additionalSectionsFile;
 50  
     
 51  
     //for issue KULRice3072, to enable PK field copy
 52  0
     protected boolean preserveLockingKeysOnCopy = false;
 53  
     
 54  
     // for issue KULRice3070, to enable deleting a db record using maintenance doc
 55  0
     protected boolean allowsRecordDeletion = false;
 56  
     
 57  0
     protected boolean translateCodes = false;
 58  
 
 59  
         public MaintenanceDocumentEntry() {
 60  0
         super();
 61  0
         setDocumentClass(getStandardDocumentBaseClass());
 62  0
     }
 63  
 
 64  
     public Class<? extends Document> getStandardDocumentBaseClass() {
 65  0
         return MaintenanceDocumentBase.class;
 66  
     }
 67  
 
 68  
     /*
 69  
             This attribute is used in many contexts, for example, in maintenance docs, it's used to specify the classname
 70  
             of the BO being maintained.
 71  
      */
 72  
     public void setBusinessObjectClass(Class<? extends BusinessObject> businessObjectClass) {
 73  0
         if (businessObjectClass == null) {
 74  0
             throw new IllegalArgumentException("invalid (null) businessObjectClass");
 75  
         }
 76  
 
 77  0
         this.businessObjectClass = businessObjectClass;
 78  0
     }
 79  
 
 80  
     public Class<? extends BusinessObject> getBusinessObjectClass() {
 81  0
         return businessObjectClass;
 82  
     }
 83  
 
 84  
     /**
 85  
      * @see org.kuali.rice.kns.datadictionary.DocumentEntry#getEntryClass()
 86  
      */
 87  
     @SuppressWarnings("unchecked")
 88  
         @Override
 89  
     public Class getEntryClass() {
 90  0
             return businessObjectClass;
 91  
     }
 92  
 
 93  
     /*
 94  
             The maintainableClass element specifies the name of the
 95  
             java class which is responsible for implementing the
 96  
             maintenance logic.
 97  
             The normal one is KualiMaintainableImpl.java.
 98  
      */
 99  
     public void setMaintainableClass(Class<? extends Maintainable> maintainableClass) {
 100  0
         if (maintainableClass == null) {
 101  0
             throw new IllegalArgumentException("invalid (null) maintainableClass");
 102  
         }
 103  0
         this.maintainableClass = maintainableClass;
 104  0
     }   
 105  
 
 106  
     public Class<? extends Maintainable> getMaintainableClass() {
 107  0
         return maintainableClass;
 108  
     }
 109  
 
 110  
     /**
 111  
      * @return List of MaintainableSectionDefinition objects contained in this document
 112  
      */
 113  
     public List<MaintainableSectionDefinition> getMaintainableSections() {
 114  0
         return maintainableSections;
 115  
     }
 116  
 
 117  
     /**
 118  
      * @return List of all lockingKey fieldNames associated with this LookupDefinition, in the order in which they were added
 119  
      */
 120  
     public List<String> getLockingKeyFieldNames() {
 121  0
         return lockingKeys;
 122  
     }
 123  
 
 124  
     /**
 125  
      * 
 126  
      * @return List of all apcRule ApcRuleDefinitions associated with this MaintenanceDocument, in the order in which they were
 127  
      *         added
 128  
      * 
 129  
      */
 130  
     public List<ApcRuleDefinition> getApcRules() {
 131  0
         return apcRules;
 132  
     }
 133  
 
 134  
     /**
 135  
      * 
 136  
      * @return List of all apcRule rule's fieldNames associated with this MaintenanceDocument, in the order in which they were added
 137  
      * 
 138  
      */
 139  
     public List<String> getApcRuleFieldNames() {
 140  0
         List<String> fieldNames = new ArrayList<String>();
 141  0
         fieldNames.addAll(this.apcRuleMap.keySet());
 142  
 
 143  0
         return fieldNames;
 144  
     }
 145  
     
 146  
 
 147  
     /**
 148  
      * Gets the allowsNewOrCopy attribute. 
 149  
      * @return Returns the allowsNewOrCopy.
 150  
      */
 151  
     public boolean getAllowsNewOrCopy() {
 152  0
         return allowsNewOrCopy;
 153  
     }
 154  
 
 155  
 
 156  
     /**
 157  
             The allowsNewOrCopy element contains a value of true or false.
 158  
             If true, this indicates the maintainable should allow the
 159  
             new and/or copy maintenance actions.
 160  
      */
 161  
     public void setAllowsNewOrCopy(boolean allowsNewOrCopy) {
 162  0
         this.allowsNewOrCopy = allowsNewOrCopy;
 163  0
     }
 164  
 
 165  
 
 166  
     /**
 167  
      * Directly validate simple fields, call completeValidation on Definition fields.
 168  
      * 
 169  
      * @see org.kuali.rice.kns.datadictionary.DocumentEntry#completeValidation()
 170  
      */
 171  
     public void completeValidation() {
 172  0
         super.completeValidation();
 173  
 
 174  0
         for ( MaintainableSectionDefinition maintainableSectionDefinition : maintainableSections ) {
 175  0
             maintainableSectionDefinition.completeValidation(businessObjectClass, null);
 176  
         }
 177  
 
 178  0
         for ( String lockingKey : lockingKeys ) {
 179  0
             if (!DataDictionary.isPropertyOf(businessObjectClass, lockingKey)) {
 180  0
                 throw new AttributeValidationException("unable to find attribute '" + lockingKey + "' for lockingKey in businessObjectClass '" + businessObjectClass.getName() );
 181  
             }
 182  
         }
 183  
 
 184  0
         for ( ReferenceDefinition reference : defaultExistenceChecks ) {
 185  0
             reference.completeValidation(businessObjectClass, null);
 186  
         }
 187  
 
 188  0
         for ( ApcRuleDefinition apcRule : apcRules ) {
 189  0
             apcRule.completeValidation(businessObjectClass, null);
 190  
         }
 191  
 
 192  0
         if (documentAuthorizerClass != null && !MaintenanceDocumentAuthorizer.class.isAssignableFrom(documentAuthorizerClass)) {
 193  0
             throw new ClassValidationException("This maintenance document for '" + businessObjectClass.getName() + "' has an invalid " + "documentAuthorizerClass ('" + documentAuthorizerClass.getName() + "').  " + "Maintenance Documents must use an implementation of MaintenanceDocumentAuthorizer.");
 194  
         }
 195  0
     }
 196  
 
 197  
 
 198  
     /**
 199  
      * @see java.lang.Object#toString()
 200  
      */
 201  
     public String toString() {
 202  0
         return "MaintenanceDocumentEntry for documentType " + getDocumentTypeName();
 203  
     }
 204  
 
 205  
 
 206  
     public String getAdditionalSectionsFile() {
 207  0
         return additionalSectionsFile;
 208  
     }
 209  
 
 210  
 
 211  
     /*
 212  
             The additionalSectionsFile element specifies the name of the location
 213  
             of an additional JSP file to include in the maintenance document
 214  
             after the generation sections but before the notes.
 215  
             The location semantics are those of jsp:include.
 216  
      */
 217  
     public void setAdditionalSectionsFile(String additionalSectionsFile) {
 218  0
         this.additionalSectionsFile = additionalSectionsFile;
 219  0
     }
 220  
 
 221  
 
 222  
     public List<String> getLockingKeys() {
 223  0
         return lockingKeys;
 224  
     }
 225  
 
 226  
 
 227  
     /*
 228  
             The lockingKeys element specifies a list of fields
 229  
             that comprise a unique key.  This is used for record locking
 230  
             during the file maintenance process.
 231  
      */
 232  
     public void setLockingKeys(List<String> lockingKeys) {
 233  0
         for ( String lockingKey : lockingKeys ) {
 234  0
             if (lockingKey == null) {
 235  0
                 throw new IllegalArgumentException("invalid (null) lockingKey");
 236  
             }
 237  
         }
 238  0
         this.lockingKeys = lockingKeys;
 239  0
     }
 240  
 
 241  
 
 242  
     /**
 243  
             The maintainableSections elements allows the maintenance document to
 244  
             be presented in sections.  Each section can have a different title.
 245  
 
 246  
             JSTL: maintainbleSections is a Map whichis accessed by a key
 247  
             of "maintainableSections".  This map contains entries with the
 248  
             following keys:
 249  
                 * "0"   (for first section)
 250  
                 * "1"   (for second section)
 251  
                 etc.
 252  
             The corresponding value for each entry is a maintainableSection ExportMap.
 253  
             See MaintenanceDocumentEntryMapper.java.
 254  
      */
 255  
     public void setMaintainableSections(List<MaintainableSectionDefinition> maintainableSections) {
 256  0
         maintainableSectionMap.clear();
 257  0
         for ( MaintainableSectionDefinition maintainableSectionDefinition : maintainableSections ) {
 258  0
             if (maintainableSectionDefinition == null) {
 259  0
                 throw new IllegalArgumentException("invalid (null) maintainableSectionDefinition");
 260  
             }
 261  
     
 262  0
             String sectionTitle = maintainableSectionDefinition.getTitle();
 263  0
             if (maintainableSectionMap.containsKey(sectionTitle)) {
 264  0
                 throw new DuplicateEntryException("section '" + sectionTitle + "' already defined for maintenanceDocument '" + getDocumentTypeName() + "'");
 265  
             }
 266  
     
 267  0
             maintainableSectionMap.put(sectionTitle, maintainableSectionDefinition);
 268  0
         }
 269  0
         this.maintainableSections = maintainableSections;
 270  0
     }
 271  
 
 272  
     /*
 273  
                     The apcRule element is used to specifiy legal values
 274  
                     for an attribute.  This is done by specifiying the key
 275  
                     to the System Parameters table that indicates
 276  
                     the allowable values.
 277  
 
 278  
                     JSTL: apcRules are Maps with the following keys:
 279  
                     * attributeName (String)
 280  
                     * parameterNamespace (String)
 281  
                     * parameterDetailType (String)
 282  
                     * parameterName (String)
 283  
                     * errorMessage (String) a property key usually defined in ApplicationResources.properties
 284  
 
 285  
                     See DictionaryValidationService.validateApcRule
 286  
      */
 287  
     public void setApcRules(List<ApcRuleDefinition> apcRules) {
 288  0
         apcRuleMap.clear();
 289  0
         for ( ApcRuleDefinition apcRule : apcRules ) {
 290  0
             if (apcRule == null) {
 291  0
                 throw new IllegalArgumentException("invalid (null) apcRule");
 292  
             }
 293  
     
 294  0
             String keyName = apcRule.getAttributeName();
 295  0
             if (apcRuleMap.containsKey(keyName)) {
 296  0
                 throw new DuplicateEntryException("duplicate apcRule entry for attribute '" + keyName + "'");
 297  
             }
 298  
     
 299  0
             apcRuleMap.put(keyName, apcRule);
 300  0
         }
 301  0
         this.apcRules = apcRules;
 302  0
     }
 303  
     
 304  
     /**
 305  
          * @return the preserveLockingKeysOnCopy
 306  
          */
 307  
         public boolean getPreserveLockingKeysOnCopy() {
 308  0
                 return this.preserveLockingKeysOnCopy;
 309  
         }
 310  
 
 311  
         /**
 312  
          * @param preserveLockingKeysOnCopy the preserveLockingKeysOnCopy to set
 313  
          */
 314  
         public void setPreserveLockingKeysOnCopy(boolean preserveLockingKeysOnCopy) {
 315  0
                 this.preserveLockingKeysOnCopy = preserveLockingKeysOnCopy;
 316  0
         }
 317  
         
 318  
         /**
 319  
          * @return the allowRecordDeletion
 320  
          */
 321  
         public boolean getAllowsRecordDeletion() {
 322  0
                 return this.allowsRecordDeletion;
 323  
         }
 324  
 
 325  
         /**
 326  
          * @param allowRecordDeletion the allowRecordDeletion to set
 327  
          */
 328  
         public void setAllowsRecordDeletion(boolean allowsRecordDeletion) {
 329  0
                 this.allowsRecordDeletion = allowsRecordDeletion;
 330  0
         }
 331  
 
 332  
         public boolean isTranslateCodes() {
 333  0
                 return this.translateCodes;
 334  
         }
 335  
 
 336  
         public void setTranslateCodes(boolean translateCodes) {
 337  0
                 this.translateCodes = translateCodes;
 338  0
         }
 339  
 
 340  
 }