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 java.util.ArrayList;
19  import java.util.List;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
23  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
24  import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
25  import org.kuali.rice.krad.document.Document;
26  import org.kuali.rice.krad.maintenance.Maintainable;
27  import org.kuali.rice.krad.maintenance.MaintenanceDocumentAuthorizer;
28  import org.kuali.rice.krad.maintenance.MaintenanceDocumentAuthorizerBase;
29  import org.kuali.rice.krad.maintenance.MaintenanceDocumentBase;
30  import org.kuali.rice.krad.maintenance.MaintenanceDocumentPresentationControllerBase;
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", 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      protected List<String> clearValueOnCopyPropertyNames = new ArrayList<String>();
46  
47      protected boolean allowsNewOrCopy = true;
48      protected boolean preserveLockingKeysOnCopy = false;
49      protected boolean allowsRecordDeletion = false;
50  
51      public MaintenanceDocumentEntry() {
52          super();
53  
54          setDocumentClass(getStandardDocumentBaseClass());
55          documentAuthorizerClass = MaintenanceDocumentAuthorizerBase.class;
56          documentPresentationControllerClass = MaintenanceDocumentPresentationControllerBase.class;
57      }
58  
59      public Class<? extends Document> getStandardDocumentBaseClass() {
60          return MaintenanceDocumentBase.class;
61      }
62  
63      /*
64              This attribute is used in many contexts, for example, in maintenance docs, it's used to specify the classname
65              of the BO being maintained.
66       */
67      public void setDataObjectClass(Class<?> dataObjectClass) {
68          this.dataObjectClass = dataObjectClass;
69      }
70  
71      @BeanTagAttribute(name = "dataObjectClass")
72      public Class<?> getDataObjectClass() {
73          return dataObjectClass;
74      }
75  
76      /**
77       * @see org.kuali.rice.krad.datadictionary.DocumentEntry#getEntryClass()
78       */
79      @SuppressWarnings("unchecked")
80      @Override
81      public Class getEntryClass() {
82          return dataObjectClass;
83      }
84  
85      /*
86              The maintainableClass element specifies the name of the
87              java class which is responsible for implementing the
88              maintenance logic.
89              The normal one is KualiMaintainableImpl.java.
90       */
91      public void setMaintainableClass(Class<? extends Maintainable> maintainableClass) {
92          this.maintainableClass = maintainableClass;
93      }
94  
95      @BeanTagAttribute(name = "maintainableClass")
96      public Class<? extends Maintainable> getMaintainableClass() {
97          return maintainableClass;
98      }
99  
100     /**
101      * @return List of all lockingKey fieldNames associated with this LookupDefinition, in the order in which they were
102      *         added
103      */
104     public List<String> getLockingKeyFieldNames() {
105         return lockingKeys;
106     }
107 
108     /**
109      * Gets the allowsNewOrCopy attribute.
110      *
111      * @return Returns the allowsNewOrCopy.
112      */
113     @BeanTagAttribute(name = "allowsNewOrCopy")
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     @Override
133     public void completeValidation(ValidationTrace tracer) {
134         super.completeValidation(tracer);
135 
136         if (dataObjectClass == null) {
137             String currentValues[] = {};
138             tracer.createError("invalid (null) dataObjectClass", currentValues);
139         }
140 
141         if (maintainableClass == null) {
142             String currentValues[] = {};
143             tracer.createError("invalid (null) maintainableClass", currentValues);
144         }
145 
146         for (String lockingKey : lockingKeys) {
147             if ( StringUtils.isBlank(lockingKey) ) {
148                 String currentValues[] = {"lockingKeys = " + lockingKeys};
149                 tracer.createError("invalid (blank) lockingKey", currentValues);
150             } else if (!DataDictionary.isPropertyOf(dataObjectClass, lockingKey)) {
151                 String currentValues[] = {"dataObjectClass = " + dataObjectClass, "lockingKey = " + lockingKey};
152                 tracer.createError("lockingKey not found in data object class", currentValues);
153             }
154         }
155 
156         for (String clearValueOnCopyPropertyName : clearValueOnCopyPropertyNames) {
157             if (StringUtils.isBlank(clearValueOnCopyPropertyName)) {
158                 String currentValues[] = {"clearValueOnCopyPropertyNames = " + clearValueOnCopyPropertyNames};
159                 tracer.createError("invalid (blank) clearValueOnCopyPropertyNames", currentValues);
160             } else if (!DataDictionary.isPropertyOf(dataObjectClass, clearValueOnCopyPropertyName)) {
161                 String currentValues[] = {"dataObjectClass = " + dataObjectClass,
162                         "clearValueOnCopyPropertyName = " + clearValueOnCopyPropertyName};
163                 tracer.createError("clearValueOnCopyPropertyName not found in data object class", currentValues);
164             }
165         }
166 
167         if (documentAuthorizerClass != null
168                 && !MaintenanceDocumentAuthorizer.class.isAssignableFrom(documentAuthorizerClass)) {
169             String currentValues[] = {"documentAuthorizerClass = " + documentAuthorizerClass.getName()};
170             tracer.createError("Maintenance Documents must use an implementation of MaintenanceDocumentAuthorizer", currentValues);
171         }
172     }
173 
174     @Override
175     protected void validateDefaultExistenceChecks( ValidationTrace tracer ) {
176         for ( ReferenceDefinition refDef : defaultExistenceChecks ) {
177             refDef.completeValidation(dataObjectClass, null, tracer.getCopy());
178         }
179     }
180 
181 
182     @BeanTagAttribute(name = "lockingKeys", type = BeanTagAttribute.AttributeType.LISTVALUE)
183     public List<String> getLockingKeys() {
184         return lockingKeys;
185     }
186 
187     /*
188            The lockingKeys element specifies a list of fields
189            that comprise a unique key.  This is used for record locking
190            during the file maintenance process.
191     */
192     public void setLockingKeys(List<String> lockingKeys) {
193         this.lockingKeys = lockingKeys;
194     }
195 
196     /**
197      * @return the preserveLockingKeysOnCopy
198      */
199     @BeanTagAttribute(name = "preserveLockingKeysOnCopy")
200     public boolean getPreserveLockingKeysOnCopy() {
201         return this.preserveLockingKeysOnCopy;
202     }
203 
204     /**
205      * @param preserveLockingKeysOnCopy the preserveLockingKeysOnCopy to set
206      */
207     public void setPreserveLockingKeysOnCopy(boolean preserveLockingKeysOnCopy) {
208         this.preserveLockingKeysOnCopy = preserveLockingKeysOnCopy;
209     }
210 
211     /**
212      * @return the clearValueOnCopyPropertyNames
213      */
214     @BeanTagAttribute(name = "clearValueOnCopyPropertyNames", type = BeanTagAttribute.AttributeType.LISTVALUE)
215     public List<String> getClearValueOnCopyPropertyNames() {
216         return clearValueOnCopyPropertyNames;
217     }
218 
219     /**
220      * @param clearValueOnCopyPropertyNames the clearValueOnCopyPropertyNames to set
221      */
222     public void setClearValueOnCopyPropertyNames(List<String> clearValueOnCopyPropertyNames) {
223         this.clearValueOnCopyPropertyNames = clearValueOnCopyPropertyNames;
224     }
225 
226     /**
227      * @return the allowRecordDeletion
228      */
229     @BeanTagAttribute(name = "allowsRecordDeletion")
230     public boolean getAllowsRecordDeletion() {
231         return this.allowsRecordDeletion;
232     }
233 
234     /**
235      * @param allowsRecordDeletion the allowRecordDeletion to set
236      */
237     public void setAllowsRecordDeletion(boolean allowsRecordDeletion) {
238         this.allowsRecordDeletion = allowsRecordDeletion;
239     }
240 
241 }