Coverage Report - org.kuali.rice.kns.datadictionary.MaintenanceDocumentEntry
 
Classes in this File Line Coverage Branch Coverage Complexity
MaintenanceDocumentEntry
0%
0/68
0%
0/26
1.833
 
 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.document.authorization.MaintenanceDocumentAuthorizer;
 24  
 import org.kuali.rice.kns.bo.BusinessObject;
 25  
 import org.kuali.rice.kns.datadictionary.exception.AttributeValidationException;
 26  
 import org.kuali.rice.kns.datadictionary.exception.ClassValidationException;
 27  
 import org.kuali.rice.kns.datadictionary.exception.DuplicateEntryException;
 28  
 import org.kuali.rice.kns.document.Document;
 29  
 import org.kuali.rice.kns.document.MaintenanceDocumentBase;
 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  
 
 45  0
     protected Map<String,MaintainableSectionDefinition> maintainableSectionMap = new LinkedHashMap<String, MaintainableSectionDefinition>();
 46  
 
 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  
      * Gets the allowsNewOrCopy attribute. 
 126  
      * @return Returns the allowsNewOrCopy.
 127  
      */
 128  
     public boolean getAllowsNewOrCopy() {
 129  0
         return allowsNewOrCopy;
 130  
     }
 131  
 
 132  
 
 133  
     /**
 134  
             The allowsNewOrCopy element contains a value of true or false.
 135  
             If true, this indicates the maintainable should allow the
 136  
             new and/or copy maintenance actions.
 137  
      */
 138  
     public void setAllowsNewOrCopy(boolean allowsNewOrCopy) {
 139  0
         this.allowsNewOrCopy = allowsNewOrCopy;
 140  0
     }
 141  
 
 142  
 
 143  
     /**
 144  
      * Directly validate simple fields, call completeValidation on Definition fields.
 145  
      * 
 146  
      * @see org.kuali.rice.kns.datadictionary.DocumentEntry#completeValidation()
 147  
      */
 148  
     public void completeValidation() {
 149  0
         super.completeValidation();
 150  
 
 151  0
         for ( MaintainableSectionDefinition maintainableSectionDefinition : maintainableSections ) {
 152  0
             maintainableSectionDefinition.completeValidation(businessObjectClass, null);
 153  
         }
 154  
 
 155  0
         for ( String lockingKey : lockingKeys ) {
 156  0
             if (!DataDictionary.isPropertyOf(businessObjectClass, lockingKey)) {
 157  0
                 throw new AttributeValidationException("unable to find attribute '" + lockingKey + "' for lockingKey in businessObjectClass '" + businessObjectClass.getName() );
 158  
             }
 159  
         }
 160  
 
 161  0
         for ( ReferenceDefinition reference : defaultExistenceChecks ) {
 162  0
             reference.completeValidation(businessObjectClass, null);
 163  
         }
 164  
 
 165  0
         if (documentAuthorizerClass != null && !MaintenanceDocumentAuthorizer.class.isAssignableFrom(documentAuthorizerClass)) {
 166  0
             throw new ClassValidationException("This maintenance document for '" + businessObjectClass.getName() + "' has an invalid " + "documentAuthorizerClass ('" + documentAuthorizerClass.getName() + "').  " + "Maintenance Documents must use an implementation of MaintenanceDocumentAuthorizer.");
 167  
         }
 168  0
     }
 169  
 
 170  
 
 171  
     /**
 172  
      * @see java.lang.Object#toString()
 173  
      */
 174  
     public String toString() {
 175  0
         return "MaintenanceDocumentEntry for documentType " + getDocumentTypeName();
 176  
     }
 177  
 
 178  
     @Deprecated
 179  
     public String getAdditionalSectionsFile() {
 180  0
         return additionalSectionsFile;
 181  
     }
 182  
 
 183  
 
 184  
     /*
 185  
             The additionalSectionsFile element specifies the name of the location
 186  
             of an additional JSP file to include in the maintenance document
 187  
             after the generation sections but before the notes.
 188  
             The location semantics are those of jsp:include.
 189  
      */
 190  
     @Deprecated
 191  
     public void setAdditionalSectionsFile(String additionalSectionsFile) {
 192  0
         this.additionalSectionsFile = additionalSectionsFile;
 193  0
     }
 194  
 
 195  
 
 196  
     public List<String> getLockingKeys() {
 197  0
         return lockingKeys;
 198  
     }
 199  
 
 200  
 
 201  
     /*
 202  
             The lockingKeys element specifies a list of fields
 203  
             that comprise a unique key.  This is used for record locking
 204  
             during the file maintenance process.
 205  
      */
 206  
     public void setLockingKeys(List<String> lockingKeys) {
 207  0
         for ( String lockingKey : lockingKeys ) {
 208  0
             if (lockingKey == null) {
 209  0
                 throw new IllegalArgumentException("invalid (null) lockingKey");
 210  
             }
 211  
         }
 212  0
         this.lockingKeys = lockingKeys;
 213  0
     }
 214  
 
 215  
 
 216  
     /**
 217  
             The maintainableSections elements allows the maintenance document to
 218  
             be presented in sections.  Each section can have a different title.
 219  
 
 220  
             JSTL: maintainbleSections is a Map whichis accessed by a key
 221  
             of "maintainableSections".  This map contains entries with the
 222  
             following keys:
 223  
                 * "0"   (for first section)
 224  
                 * "1"   (for second section)
 225  
                 etc.
 226  
             The corresponding value for each entry is a maintainableSection ExportMap.
 227  
             See MaintenanceDocumentEntryMapper.java.
 228  
      */
 229  
     @Deprecated
 230  
     public void setMaintainableSections(List<MaintainableSectionDefinition> maintainableSections) {
 231  0
         maintainableSectionMap.clear();
 232  0
         for ( MaintainableSectionDefinition maintainableSectionDefinition : maintainableSections ) {
 233  0
             if (maintainableSectionDefinition == null) {
 234  0
                 throw new IllegalArgumentException("invalid (null) maintainableSectionDefinition");
 235  
             }
 236  
     
 237  0
             String sectionTitle = maintainableSectionDefinition.getTitle();
 238  0
             if (maintainableSectionMap.containsKey(sectionTitle)) {
 239  0
                 throw new DuplicateEntryException("section '" + sectionTitle + "' already defined for maintenanceDocument '" + getDocumentTypeName() + "'");
 240  
             }
 241  
     
 242  0
             maintainableSectionMap.put(sectionTitle, maintainableSectionDefinition);
 243  0
         }
 244  0
         this.maintainableSections = maintainableSections;
 245  0
     }
 246  
 
 247  
 
 248  
     
 249  
     /**
 250  
          * @return the preserveLockingKeysOnCopy
 251  
          */
 252  
         public boolean getPreserveLockingKeysOnCopy() {
 253  0
                 return this.preserveLockingKeysOnCopy;
 254  
         }
 255  
 
 256  
         /**
 257  
          * @param preserveLockingKeysOnCopy the preserveLockingKeysOnCopy to set
 258  
          */
 259  
         public void setPreserveLockingKeysOnCopy(boolean preserveLockingKeysOnCopy) {
 260  0
                 this.preserveLockingKeysOnCopy = preserveLockingKeysOnCopy;
 261  0
         }
 262  
         
 263  
         /**
 264  
          * @return the allowRecordDeletion
 265  
          */
 266  
         public boolean getAllowsRecordDeletion() {
 267  0
                 return this.allowsRecordDeletion;
 268  
         }
 269  
 
 270  
         /**
 271  
          * @param allowsRecordDeletion the allowRecordDeletion to set
 272  
          */
 273  
         public void setAllowsRecordDeletion(boolean allowsRecordDeletion) {
 274  0
                 this.allowsRecordDeletion = allowsRecordDeletion;
 275  0
         }
 276  
 
 277  
         @Deprecated
 278  
         public boolean isTranslateCodes() {
 279  0
                 return this.translateCodes;
 280  
         }
 281  
 
 282  
         @Deprecated
 283  
         public void setTranslateCodes(boolean translateCodes) {
 284  0
                 this.translateCodes = translateCodes;
 285  0
         }
 286  
 
 287  
 }