001/**
002 * Copyright 2005-2018 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.kns.datadictionary;
017
018import java.util.ArrayList;
019import java.util.LinkedHashMap;
020import java.util.List;
021import java.util.Map;
022
023import org.kuali.rice.kew.api.doctype.DocumentTypeService;
024import org.kuali.rice.kns.document.MaintenanceDocumentBase;
025import org.kuali.rice.kns.document.authorization.DocumentAuthorizer;
026import org.kuali.rice.kns.document.authorization.DocumentPresentationController;
027import org.kuali.rice.kns.document.authorization.MaintenanceDocumentAuthorizerBase;
028import org.kuali.rice.kns.document.authorization.MaintenanceDocumentPresentationControllerBase;
029import org.kuali.rice.kns.maintenance.Maintainable;
030import org.kuali.rice.kns.rule.PromptBeforeValidation;
031import org.kuali.rice.kns.rules.MaintenanceDocumentRule;
032import org.kuali.rice.kns.web.derivedvaluesetter.DerivedValuesSetter;
033import org.kuali.rice.kns.web.struts.action.KualiDocumentActionBase;
034import org.kuali.rice.krad.bo.BusinessObject;
035import org.kuali.rice.krad.datadictionary.DataDictionaryException;
036import org.kuali.rice.krad.datadictionary.exception.DuplicateEntryException;
037import org.kuali.rice.krad.document.Document;
038import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
039
040/**
041 * @author Kuali Rice Team (rice.collab@kuali.org)
042 *
043 * @deprecated Use {@link org.kuali.rice.krad.datadictionary.MaintenanceDocumentEntry}.
044 */
045@Deprecated
046public class MaintenanceDocumentEntry extends org.kuali.rice.krad.datadictionary.MaintenanceDocumentEntry implements KNSDocumentEntry {
047    protected List<MaintainableSectionDefinition> maintainableSections = new ArrayList<MaintainableSectionDefinition>();
048    protected List<String> lockingKeys = new ArrayList<String>();
049
050    protected Map<String, MaintainableSectionDefinition> maintainableSectionMap =
051            new LinkedHashMap<String, MaintainableSectionDefinition>();
052
053    protected boolean allowsNewOrCopy = true;
054    protected String additionalSectionsFile;
055
056    //for issue KULRice3072, to enable PK field copy
057    protected boolean preserveLockingKeysOnCopy = false;
058
059    // for issue KULRice3070, to enable deleting a db record using maintenance doc
060    protected boolean allowsRecordDeletion = false;
061
062    protected boolean translateCodes = false;
063
064    protected Class<? extends PromptBeforeValidation> promptBeforeValidationClass;
065    protected Class<? extends DerivedValuesSetter> derivedValuesSetterClass;
066    protected List<String> webScriptFiles = new ArrayList<String>(3);
067    protected List<HeaderNavigation> headerNavigationList = new ArrayList<HeaderNavigation>();
068
069    protected boolean sessionDocument = false;
070
071    public MaintenanceDocumentEntry() {
072        super();
073
074        documentAuthorizerClass = MaintenanceDocumentAuthorizerBase.class;
075        documentPresentationControllerClass = MaintenanceDocumentPresentationControllerBase.class;
076    }
077
078     /**
079     * @return Returns the preRulesCheckClass.
080     */
081    @Override
082        public Class<? extends PromptBeforeValidation> getPromptBeforeValidationClass() {
083        return promptBeforeValidationClass;
084    }
085
086    /**
087     * The promptBeforeValidationClass element is the full class name of the java
088     * class which determines whether the user should be asked any questions prior to running validation.
089     *
090     * @see KualiDocumentActionBase#promptBeforeValidation(org.apache.struts.action.ActionMapping,
091     *      org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest,
092     *      javax.servlet.http.HttpServletResponse, String)
093     */
094    @Override
095        public void setPromptBeforeValidationClass(Class<? extends PromptBeforeValidation> preRulesCheckClass) {
096        this.promptBeforeValidationClass = preRulesCheckClass;
097    }
098
099    @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}