View Javadoc

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      protected List<String> lockingKeys = new ArrayList<String>();
39  
40      protected boolean allowsNewOrCopy = true;
41      protected boolean preserveLockingKeysOnCopy = false;
42      protected boolean allowsRecordDeletion = false;
43  
44      public MaintenanceDocumentEntry() {
45          super();
46          setDocumentClass(getStandardDocumentBaseClass());
47      }
48  
49      public Class<? extends Document> getStandardDocumentBaseClass() {
50          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          if (dataObjectClass == null) {
59              throw new IllegalArgumentException("invalid (null) dataObjectClass");
60          }
61  
62          this.dataObjectClass = dataObjectClass;
63      }
64  
65      public Class<?> getDataObjectClass() {
66          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          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          if (maintainableClass == null) {
86              throw new IllegalArgumentException("invalid (null) maintainableClass");
87          }
88          this.maintainableClass = maintainableClass;
89      }
90  
91      public Class<? extends Maintainable> getMaintainableClass() {
92          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         return lockingKeys;
101     }
102 
103     /**
104      * Gets the allowsNewOrCopy attribute.
105      *
106      * @return Returns the allowsNewOrCopy.
107      */
108     public boolean getAllowsNewOrCopy() {
109         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         this.allowsNewOrCopy = allowsNewOrCopy;
119     }
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         super.completeValidation();
128 
129         for (String lockingKey : lockingKeys) {
130             if (!DataDictionary.isPropertyOf(dataObjectClass, lockingKey)) {
131                 throw new AttributeValidationException(
132                         "unable to find attribute '" + lockingKey + "' for lockingKey in dataObjectClass '" +
133                                 dataObjectClass.getName());
134             }
135         }
136 
137         for (ReferenceDefinition reference : defaultExistenceChecks) {
138             reference.completeValidation(dataObjectClass, null);
139         }
140 
141 
142         if (documentAuthorizerClass != null &&
143                 !MaintenanceDocumentAuthorizer.class.isAssignableFrom(documentAuthorizerClass)) {
144             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     }
150 
151     /**
152      * @see java.lang.Object#toString()
153      */
154     public String toString() {
155         return "MaintenanceDocumentEntry for documentType " + getDocumentTypeName();
156     }
157 
158     public List<String> getLockingKeys() {
159         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         for (String lockingKey : lockingKeys) {
169             if (lockingKey == null) {
170                 throw new IllegalArgumentException("invalid (null) lockingKey");
171             }
172         }
173         this.lockingKeys = lockingKeys;
174     }
175 
176     /**
177      * @return the preserveLockingKeysOnCopy
178      */
179     public boolean getPreserveLockingKeysOnCopy() {
180         return this.preserveLockingKeysOnCopy;
181     }
182 
183     /**
184      * @param preserveLockingKeysOnCopy the preserveLockingKeysOnCopy to set
185      */
186     public void setPreserveLockingKeysOnCopy(boolean preserveLockingKeysOnCopy) {
187         this.preserveLockingKeysOnCopy = preserveLockingKeysOnCopy;
188     }
189 
190     /**
191      * @return the allowRecordDeletion
192      */
193     public boolean getAllowsRecordDeletion() {
194         return this.allowsRecordDeletion;
195     }
196 
197     /**
198      * @param allowsRecordDeletion the allowRecordDeletion to set
199      */
200     public void setAllowsRecordDeletion(boolean allowsRecordDeletion) {
201         this.allowsRecordDeletion = allowsRecordDeletion;
202     }
203 
204 }