001/** 002 * Copyright 2005-2016 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 org.kuali.rice.kns.document.authorization.DocumentAuthorizer; 019import org.kuali.rice.kns.document.authorization.DocumentPresentationController; 020import org.kuali.rice.kns.document.authorization.MaintenanceDocumentAuthorizerBase; 021import org.kuali.rice.kns.document.authorization.MaintenanceDocumentPresentationControllerBase; 022import org.kuali.rice.kns.rule.PromptBeforeValidation; 023import org.kuali.rice.kns.web.derivedvaluesetter.DerivedValuesSetter; 024import org.kuali.rice.krad.bo.BusinessObject; 025import org.kuali.rice.krad.datadictionary.DataDictionaryException; 026import org.kuali.rice.krad.datadictionary.exception.DuplicateEntryException; 027import org.kuali.rice.krad.document.Document; 028import org.kuali.rice.kns.document.MaintenanceDocumentBase; 029import org.kuali.rice.kns.maintenance.Maintainable; 030import org.kuali.rice.kns.rules.MaintenanceDocumentRule; 031import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase; 032 033import java.util.ArrayList; 034import java.util.LinkedHashMap; 035import java.util.List; 036import java.util.Map; 037 038/** 039 * @author Kuali Rice Team (rice.collab@kuali.org) 040 */ 041@Deprecated 042public class MaintenanceDocumentEntry extends org.kuali.rice.krad.datadictionary.MaintenanceDocumentEntry implements KNSDocumentEntry { 043 protected List<MaintainableSectionDefinition> maintainableSections = new ArrayList<MaintainableSectionDefinition>(); 044 protected List<String> lockingKeys = new ArrayList<String>(); 045 046 protected Map<String, MaintainableSectionDefinition> maintainableSectionMap = 047 new LinkedHashMap<String, MaintainableSectionDefinition>(); 048 049 protected boolean allowsNewOrCopy = true; 050 protected String additionalSectionsFile; 051 052 //for issue KULRice3072, to enable PK field copy 053 protected boolean preserveLockingKeysOnCopy = false; 054 055 // for issue KULRice3070, to enable deleting a db record using maintenance doc 056 protected boolean allowsRecordDeletion = false; 057 058 protected boolean translateCodes = false; 059 060 protected Class<? extends PromptBeforeValidation> promptBeforeValidationClass; 061 protected Class<? extends DerivedValuesSetter> derivedValuesSetterClass; 062 protected List<String> webScriptFiles = new ArrayList<String>(3); 063 protected List<HeaderNavigation> headerNavigationList = new ArrayList<HeaderNavigation>(); 064 065 protected boolean sessionDocument = false; 066 067 public MaintenanceDocumentEntry() { 068 super(); 069 070 documentAuthorizerClass = MaintenanceDocumentAuthorizerBase.class; 071 documentPresentationControllerClass = MaintenanceDocumentPresentationControllerBase.class; 072 } 073 074 /** 075 * @return Returns the preRulesCheckClass. 076 */ 077 public Class<? extends PromptBeforeValidation> getPromptBeforeValidationClass() { 078 return promptBeforeValidationClass; 079 } 080 081 /** 082 * The promptBeforeValidationClass element is the full class name of the java 083 * class which determines whether the user should be asked any questions prior to running validation. 084 * 085 * @see KualiDocumentActionBase#promptBeforeValidation(org.apache.struts.action.ActionMapping, 086 * org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, 087 * javax.servlet.http.HttpServletResponse, String) 088 */ 089 public void setPromptBeforeValidationClass(Class<? extends PromptBeforeValidation> preRulesCheckClass) { 090 this.promptBeforeValidationClass = preRulesCheckClass; 091 } 092 093 @Override 094 public Class<? extends Document> getStandardDocumentBaseClass() { 095 return MaintenanceDocumentBase.class; 096 } 097 098 /* 099 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}