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