Coverage Report - org.kuali.rice.krad.datadictionary.MaintenanceDocumentEntry
 
Classes in this File Line Coverage Branch Coverage Complexity
MaintenanceDocumentEntry
0%
0/45
0%
0/18
1.778
 
 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.krad.datadictionary;
 17  
 
 18  
 import org.kuali.rice.krad.bo.BusinessObject;
 19  
 import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
 20  
 import org.kuali.rice.krad.datadictionary.exception.ClassValidationException;
 21  
 import org.kuali.rice.krad.document.Document;
 22  
 import org.kuali.rice.krad.document.MaintenanceDocumentBase;
 23  
 import org.kuali.rice.krad.document.authorization.MaintenanceDocumentAuthorizer;
 24  
 import org.kuali.rice.krad.maintenance.Maintainable;
 25  
 
 26  
 import java.util.ArrayList;
 27  
 import java.util.List;
 28  
 
 29  
 /**
 30  
  * Data dictionary entry class for <code>MaintenanceDocument</code>
 31  
  *
 32  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 33  
  */
 34  
 public class MaintenanceDocumentEntry extends DocumentEntry {
 35  
     protected Class<?> dataObjectClass;
 36  
     protected Class<? extends Maintainable> maintainableClass;
 37  
 
 38  0
     protected List<String> lockingKeys = new ArrayList<String>();
 39  
 
 40  0
     protected boolean allowsNewOrCopy = true;
 41  0
     protected boolean preserveLockingKeysOnCopy = false;
 42  0
     protected boolean allowsRecordDeletion = false;
 43  
 
 44  
     public MaintenanceDocumentEntry() {
 45  0
         super();
 46  0
         setDocumentClass(getStandardDocumentBaseClass());
 47  0
     }
 48  
 
 49  
     public Class<? extends Document> getStandardDocumentBaseClass() {
 50  0
         return MaintenanceDocumentBase.class;
 51  
     }
 52  
 
 53  
     /*
 54  
             This attribute is used in many contexts, for example, in maintenance docs, it's used to specify the classname
 55  
             of the BO being maintained.
 56  
      */
 57  
     public void setDataObjectClass(Class<?> dataObjectClass) {
 58  0
         if (dataObjectClass == null) {
 59  0
             throw new IllegalArgumentException("invalid (null) dataObjectClass");
 60  
         }
 61  
 
 62  0
         this.dataObjectClass = dataObjectClass;
 63  0
     }
 64  
 
 65  
     public Class<?> getDataObjectClass() {
 66  0
         return dataObjectClass;
 67  
     }
 68  
 
 69  
     /**
 70  
      * @see org.kuali.rice.krad.datadictionary.DocumentEntry#getEntryClass()
 71  
      */
 72  
     @SuppressWarnings("unchecked")
 73  
     @Override
 74  
     public Class getEntryClass() {
 75  0
         return dataObjectClass;
 76  
     }
 77  
 
 78  
     /*
 79  
             The maintainableClass element specifies the name of the
 80  
             java class which is responsible for implementing the
 81  
             maintenance logic.
 82  
             The normal one is KualiMaintainableImpl.java.
 83  
      */
 84  
     public void setMaintainableClass(Class<? extends Maintainable> maintainableClass) {
 85  0
         if (maintainableClass == null) {
 86  0
             throw new IllegalArgumentException("invalid (null) maintainableClass");
 87  
         }
 88  0
         this.maintainableClass = maintainableClass;
 89  0
     }
 90  
 
 91  
     public Class<? extends Maintainable> getMaintainableClass() {
 92  0
         return maintainableClass;
 93  
     }
 94  
 
 95  
     /**
 96  
      * @return List of all lockingKey fieldNames associated with this LookupDefinition, in the order in which they were
 97  
      *         added
 98  
      */
 99  
     public List<String> getLockingKeyFieldNames() {
 100  0
         return lockingKeys;
 101  
     }
 102  
 
 103  
     /**
 104  
      * Gets the allowsNewOrCopy attribute.
 105  
      *
 106  
      * @return Returns the allowsNewOrCopy.
 107  
      */
 108  
     public boolean getAllowsNewOrCopy() {
 109  0
         return allowsNewOrCopy;
 110  
     }
 111  
 
 112  
     /**
 113  
      * The allowsNewOrCopy element contains a value of true or false.
 114  
      * If true, this indicates the maintainable should allow the
 115  
      * new and/or copy maintenance actions.
 116  
      */
 117  
     public void setAllowsNewOrCopy(boolean allowsNewOrCopy) {
 118  0
         this.allowsNewOrCopy = allowsNewOrCopy;
 119  0
     }
 120  
 
 121  
     /**
 122  
      * Directly validate simple fields, call completeValidation on Definition fields.
 123  
      *
 124  
      * @see org.kuali.rice.krad.datadictionary.DocumentEntry#completeValidation()
 125  
      */
 126  
     public void completeValidation() {
 127  0
         super.completeValidation();
 128  
 
 129  0
         for (String lockingKey : lockingKeys) {
 130  0
             if (!DataDictionary.isPropertyOf(dataObjectClass, lockingKey)) {
 131  0
                 throw new AttributeValidationException(
 132  
                         "unable to find attribute '" + lockingKey + "' for lockingKey in dataObjectClass '" +
 133  
                                 dataObjectClass.getName());
 134  
             }
 135  
         }
 136  
 
 137  0
         for (ReferenceDefinition reference : defaultExistenceChecks) {
 138  0
             reference.completeValidation(dataObjectClass, null);
 139  
         }
 140  
 
 141  
 
 142  0
         if (documentAuthorizerClass != null &&
 143  
                 !MaintenanceDocumentAuthorizer.class.isAssignableFrom(documentAuthorizerClass)) {
 144  0
             throw new ClassValidationException(
 145  
                     "This maintenance document for '" + getDataObjectClass().getName() + "' has an invalid " +
 146  
                             "documentAuthorizerClass ('" + documentAuthorizerClass.getName() + "').  " +
 147  
                             "Maintenance Documents must use an implementation of MaintenanceDocumentAuthorizer.");
 148  
         }
 149  0
     }
 150  
 
 151  
     /**
 152  
      * @see java.lang.Object#toString()
 153  
      */
 154  
     public String toString() {
 155  0
         return "MaintenanceDocumentEntry for documentType " + getDocumentTypeName();
 156  
     }
 157  
 
 158  
     public List<String> getLockingKeys() {
 159  0
         return lockingKeys;
 160  
     }
 161  
 
 162  
     /*
 163  
            The lockingKeys element specifies a list of fields
 164  
            that comprise a unique key.  This is used for record locking
 165  
            during the file maintenance process.
 166  
     */
 167  
     public void setLockingKeys(List<String> lockingKeys) {
 168  0
         for (String lockingKey : lockingKeys) {
 169  0
             if (lockingKey == null) {
 170  0
                 throw new IllegalArgumentException("invalid (null) lockingKey");
 171  
             }
 172  
         }
 173  0
         this.lockingKeys = lockingKeys;
 174  0
     }
 175  
 
 176  
     /**
 177  
      * @return the preserveLockingKeysOnCopy
 178  
      */
 179  
     public boolean getPreserveLockingKeysOnCopy() {
 180  0
         return this.preserveLockingKeysOnCopy;
 181  
     }
 182  
 
 183  
     /**
 184  
      * @param preserveLockingKeysOnCopy the preserveLockingKeysOnCopy to set
 185  
      */
 186  
     public void setPreserveLockingKeysOnCopy(boolean preserveLockingKeysOnCopy) {
 187  0
         this.preserveLockingKeysOnCopy = preserveLockingKeysOnCopy;
 188  0
     }
 189  
 
 190  
     /**
 191  
      * @return the allowRecordDeletion
 192  
      */
 193  
     public boolean getAllowsRecordDeletion() {
 194  0
         return this.allowsRecordDeletion;
 195  
     }
 196  
 
 197  
     /**
 198  
      * @param allowsRecordDeletion the allowRecordDeletion to set
 199  
      */
 200  
     public void setAllowsRecordDeletion(boolean allowsRecordDeletion) {
 201  0
         this.allowsRecordDeletion = allowsRecordDeletion;
 202  0
     }
 203  
 
 204  
 }