View Javadoc

1   /**
2    * Copyright 2005-2013 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.kns.datadictionary;
17  
18  import org.kuali.rice.kns.document.authorization.DocumentAuthorizer;
19  import org.kuali.rice.kns.document.authorization.DocumentPresentationController;
20  import org.kuali.rice.kns.document.authorization.MaintenanceDocumentAuthorizerBase;
21  import org.kuali.rice.kns.document.authorization.MaintenanceDocumentPresentationControllerBase;
22  import org.kuali.rice.kns.rule.PromptBeforeValidation;
23  import org.kuali.rice.kns.web.derivedvaluesetter.DerivedValuesSetter;
24  import org.kuali.rice.krad.bo.BusinessObject;
25  import org.kuali.rice.krad.datadictionary.DataDictionaryException;
26  import org.kuali.rice.krad.datadictionary.exception.DuplicateEntryException;
27  import org.kuali.rice.krad.document.Document;
28  import org.kuali.rice.kns.document.MaintenanceDocumentBase;
29  import org.kuali.rice.kns.maintenance.Maintainable;
30  import org.kuali.rice.kns.rules.MaintenanceDocumentRule;
31  import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
32  
33  import java.util.ArrayList;
34  import java.util.LinkedHashMap;
35  import java.util.List;
36  import java.util.Map;
37  
38  /**
39   * @author Kuali Rice Team (rice.collab@kuali.org)
40   */
41  @Deprecated
42  public class MaintenanceDocumentEntry extends org.kuali.rice.krad.datadictionary.MaintenanceDocumentEntry implements KNSDocumentEntry {
43      protected List<MaintainableSectionDefinition> maintainableSections = new ArrayList<MaintainableSectionDefinition>();
44      protected List<String> lockingKeys = new ArrayList<String>();
45  
46      protected Map<String, MaintainableSectionDefinition> maintainableSectionMap =
47              new LinkedHashMap<String, MaintainableSectionDefinition>();
48  
49      protected boolean allowsNewOrCopy = true;
50      protected String additionalSectionsFile;
51  
52      //for issue KULRice3072, to enable PK field copy
53      protected boolean preserveLockingKeysOnCopy = false;
54  
55      // for issue KULRice3070, to enable deleting a db record using maintenance doc
56      protected boolean allowsRecordDeletion = false;
57  
58      protected boolean translateCodes = false;
59  
60      protected Class<? extends PromptBeforeValidation> promptBeforeValidationClass;
61      protected Class<? extends DerivedValuesSetter> derivedValuesSetterClass;
62      protected List<String> webScriptFiles = new ArrayList<String>(3);
63      protected List<HeaderNavigation> headerNavigationList = new ArrayList<HeaderNavigation>();
64  
65      protected boolean sessionDocument = false;
66  
67      public MaintenanceDocumentEntry() {
68          super();
69  
70          documentAuthorizerClass = MaintenanceDocumentAuthorizerBase.class;
71          documentPresentationControllerClass = MaintenanceDocumentPresentationControllerBase.class;
72      }
73  
74       /**
75       * @return Returns the preRulesCheckClass.
76       */
77      public Class<? extends PromptBeforeValidation> getPromptBeforeValidationClass() {
78          return promptBeforeValidationClass;
79      }
80  
81      /**
82       * The promptBeforeValidationClass element is the full class name of the java
83       * class which determines whether the user should be asked any questions prior to running validation.
84       *
85       * @see KualiDocumentActionBase#promptBeforeValidation(org.apache.struts.action.ActionMapping,
86       *      org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest,
87       *      javax.servlet.http.HttpServletResponse, String)
88       */
89      public void setPromptBeforeValidationClass(Class<? extends PromptBeforeValidation> preRulesCheckClass) {
90          this.promptBeforeValidationClass = preRulesCheckClass;
91      }
92  
93      @Override
94      public Class<? extends Document> getStandardDocumentBaseClass() {
95          return MaintenanceDocumentBase.class;
96      }
97  
98      /*
99             This attribute is used in many contexts, for example, in maintenance docs, it's used to specify the classname
100            of the BO being maintained.
101     */
102     public void setBusinessObjectClass(Class<? extends BusinessObject> businessObjectClass) {
103         if (businessObjectClass == null) {
104             throw new IllegalArgumentException("invalid (null) dataObjectClass");
105         }
106 
107         setDataObjectClass(businessObjectClass);
108     }
109 
110     public Class<? extends BusinessObject> getBusinessObjectClass() {
111         return (Class<? extends BusinessObject>) getDataObjectClass();
112     }
113 
114     /**
115      * @see org.kuali.rice.krad.datadictionary.DocumentEntry#getEntryClass()
116      */
117     @SuppressWarnings("unchecked")
118     @Override
119     public Class getEntryClass() {
120         return getDataObjectClass();
121     }
122 
123     public Class<? extends Maintainable> getMaintainableClass() {
124         return (Class<? extends Maintainable>) super.getMaintainableClass();
125     }
126 
127     /**
128      * @return List of MaintainableSectionDefinition objects contained in this document
129      */
130     public List<MaintainableSectionDefinition> getMaintainableSections() {
131         return maintainableSections;
132     }
133 
134     /**
135      * @return List of all lockingKey fieldNames associated with this LookupDefinition, in the order in which they were
136      *         added
137      */
138     public List<String> getLockingKeyFieldNames() {
139         return lockingKeys;
140     }
141 
142     /**
143      * Gets the allowsNewOrCopy attribute.
144      *
145      * @return Returns the allowsNewOrCopy.
146      */
147     public boolean getAllowsNewOrCopy() {
148         return allowsNewOrCopy;
149     }
150 
151     /**
152      * The allowsNewOrCopy element contains a value of true or false.
153      * If true, this indicates the maintainable should allow the
154      * new and/or copy maintenance actions.
155      */
156     public void setAllowsNewOrCopy(boolean allowsNewOrCopy) {
157         this.allowsNewOrCopy = allowsNewOrCopy;
158     }
159 
160     /**
161      * Directly validate simple fields, call completeValidation on Definition fields.
162      *
163      * @see org.kuali.rice.krad.datadictionary.DocumentEntry#completeValidation()
164      */
165     public void completeValidation() {
166         if ( !MaintenanceDocumentRule.class.isAssignableFrom( getBusinessRulesClass() ) ) {
167            throw new DataDictionaryException( "ERROR: Business rules class for KNS Maintenance document entry " +
168                    getBusinessRulesClass().getName() + " does not implement the expected " +
169                    MaintenanceDocumentRule.class.getName() + " interface.");
170         }
171         super.completeValidation();
172 
173         for (MaintainableSectionDefinition maintainableSectionDefinition : maintainableSections) {
174             maintainableSectionDefinition.completeValidation(getDataObjectClass(), null);
175         }
176     }
177 
178     /**
179      * @see java.lang.Object#toString()
180      */
181     public String toString() {
182         return "MaintenanceDocumentEntry for documentType " + getDocumentTypeName();
183     }
184 
185     @Deprecated
186     public String getAdditionalSectionsFile() {
187         return additionalSectionsFile;
188     }
189 
190     /*
191            The additionalSectionsFile element specifies the name of the location
192            of an additional JSP file to include in the maintenance document
193            after the generation sections but before the notes.
194            The location semantics are those of jsp:include.
195     */
196     @Deprecated
197     public void setAdditionalSectionsFile(String additionalSectionsFile) {
198         this.additionalSectionsFile = additionalSectionsFile;
199     }
200 
201     public List<String> getLockingKeys() {
202         return lockingKeys;
203     }
204 
205     /*
206            The lockingKeys element specifies a list of fields
207            that comprise a unique key.  This is used for record locking
208            during the file maintenance process.
209     */
210     public void setLockingKeys(List<String> lockingKeys) {
211         for (String lockingKey : lockingKeys) {
212             if (lockingKey == null) {
213                 throw new IllegalArgumentException("invalid (null) lockingKey");
214             }
215         }
216         this.lockingKeys = lockingKeys;
217     }
218 
219     /**
220      * The maintainableSections elements allows the maintenance document to
221      * be presented in sections.  Each section can have a different title.
222      *
223      * JSTL: maintainbleSections is a Map whichis accessed by a key
224      * of "maintainableSections".  This map contains entries with the
225      * following keys:
226      * "0"   (for first section)
227      * "1"   (for second section)
228      * etc.
229      * The corresponding value for each entry is a maintainableSection ExportMap.
230      * See MaintenanceDocumentEntryMapper.java.
231      */
232     @Deprecated
233     public void setMaintainableSections(List<MaintainableSectionDefinition> maintainableSections) {
234         maintainableSectionMap.clear();
235         for (MaintainableSectionDefinition maintainableSectionDefinition : maintainableSections) {
236             if (maintainableSectionDefinition == null) {
237                 throw new IllegalArgumentException("invalid (null) maintainableSectionDefinition");
238             }
239 
240             String sectionTitle = maintainableSectionDefinition.getTitle();
241             if (maintainableSectionMap.containsKey(sectionTitle)) {
242                 throw new DuplicateEntryException(
243                         "section '" + sectionTitle + "' already defined for maintenanceDocument '" +
244                                 getDocumentTypeName() + "'");
245             }
246 
247             maintainableSectionMap.put(sectionTitle, maintainableSectionDefinition);
248         }
249         this.maintainableSections = maintainableSections;
250     }
251 
252     /**
253      * @return the preserveLockingKeysOnCopy
254      */
255     public boolean getPreserveLockingKeysOnCopy() {
256         return this.preserveLockingKeysOnCopy;
257     }
258 
259     /**
260      * @param preserveLockingKeysOnCopy the preserveLockingKeysOnCopy to set
261      */
262     public void setPreserveLockingKeysOnCopy(boolean preserveLockingKeysOnCopy) {
263         this.preserveLockingKeysOnCopy = preserveLockingKeysOnCopy;
264     }
265 
266     /**
267      * @return the allowRecordDeletion
268      */
269     public boolean getAllowsRecordDeletion() {
270         return this.allowsRecordDeletion;
271     }
272 
273     /**
274      * @param allowsRecordDeletion the allowRecordDeletion to set
275      */
276     public void setAllowsRecordDeletion(boolean allowsRecordDeletion) {
277         this.allowsRecordDeletion = allowsRecordDeletion;
278     }
279 
280     @Deprecated
281     public boolean isTranslateCodes() {
282         return this.translateCodes;
283     }
284 
285     @Deprecated
286     public void setTranslateCodes(boolean translateCodes) {
287         this.translateCodes = translateCodes;
288     }
289 
290     /**
291      * Returns the document authorizer class for the document.  Only framework code should be calling this method.
292      * Client devs should use {@link DocumentTypeService#getDocumentAuthorizer(org.kuali.rice.krad.document.Document)}
293      * or
294      * {@link DocumentTypeService#getDocumentAuthorizer(String)}
295      *
296      * @return a document authorizer class
297      */
298     @Override
299     public Class<? extends DocumentAuthorizer> getDocumentAuthorizerClass() {
300         return (Class<? extends DocumentAuthorizer>) super.getDocumentAuthorizerClass();
301     }
302 
303     /**
304      * Returns the document presentation controller class for the document.  Only framework code should be calling this
305      * method.
306      * Client devs should use {@link DocumentTypeService#getDocumentPresentationController(org.kuali.rice.krad.document.Document)}
307      * or
308      * {@link DocumentTypeService#getDocumentPresentationController(String)}
309      *
310      * @return the documentPresentationControllerClass
311      */
312     @Override
313     public Class<? extends DocumentPresentationController> getDocumentPresentationControllerClass() {
314         return (Class<? extends DocumentPresentationController>)  super.getDocumentPresentationControllerClass();
315     }
316 
317     public List<HeaderNavigation> getHeaderNavigationList() {
318         return headerNavigationList;
319     }
320 
321     public List<String> getWebScriptFiles() {
322         return webScriptFiles;
323     }
324 
325     /**
326      * The webScriptFile element defines the name of javascript files
327      * that are necessary for processing the document.  The specified
328      * javascript files will be included in the generated html.
329      */
330     public void setWebScriptFiles(List<String> webScriptFiles) {
331         this.webScriptFiles = webScriptFiles;
332     }
333 
334     /**
335      * The headerNavigation element defines a set of additional
336      * tabs which will appear on the document.
337      */
338     public void setHeaderNavigationList(List<HeaderNavigation> headerNavigationList) {
339         this.headerNavigationList = headerNavigationList;
340     }
341 
342     public boolean isSessionDocument() {
343         return this.sessionDocument;
344     }
345 
346     public void setSessionDocument(boolean sessionDocument) {
347         this.sessionDocument = sessionDocument;
348     }
349 
350     /**
351      * @return the derivedValuesSetter
352      */
353     public Class<? extends DerivedValuesSetter> getDerivedValuesSetterClass() {
354         return this.derivedValuesSetterClass;
355     }
356 
357     /**
358      * @param derivedValuesSetter the derivedValuesSetter to set
359      */
360     public void setDerivedValuesSetterClass(Class<? extends DerivedValuesSetter> derivedValuesSetter) {
361         this.derivedValuesSetterClass = derivedValuesSetter;
362     }
363 
364     public void afterPropertiesSet() throws Exception {
365         if ( getBusinessRulesClass() == null || getBusinessRulesClass().equals(MaintenanceDocumentRuleBase.class) ) {
366             setBusinessRulesClass(org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase.class);
367         }
368         super.afterPropertiesSet();
369     }
370 }