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