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