View Javadoc

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