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