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