001 /* 002 * Copyright 2011 The Kuali Foundation Licensed under the Educational Community 003 * License, Version 1.0 (the "License"); you may not use this file except in 004 * compliance with the License. You may obtain a copy of the License at 005 * http://www.opensource.org/licenses/ecl1.php Unless required by applicable law 006 * or agreed to in writing, software distributed under the License is 007 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 008 * KIND, either express or implied. See the License for the specific language 009 * governing permissions and limitations under the License. 010 */ 011 package org.kuali.rice.krad.uif.container; 012 013 import org.apache.commons.lang.StringUtils; 014 import org.kuali.rice.krad.datadictionary.MaintenanceDocumentEntry; 015 import org.kuali.rice.krad.service.DocumentDictionaryService; 016 import org.kuali.rice.krad.service.KRADServiceLocatorWeb; 017 import org.kuali.rice.krad.uif.UifConstants; 018 import org.kuali.rice.krad.uif.UifConstants.ViewType; 019 import org.kuali.rice.krad.uif.core.RequestParameter; 020 021 /** 022 * View type for Maintenance documents 023 * 024 * <p> 025 * Supports primary display for a new maintenance record, in which case the 026 * fields are display for populating the new record, and an edit maintenance 027 * record, which is a comparison view with the old record read-only on the left 028 * side and the new record (changed record) on the right side 029 * </p> 030 * 031 * <p> 032 * The <code>MaintenanceView</code> provides the interface for the maintenance 033 * framework. It works with the <code>Maintainable</code> service and 034 * maintenance controller. 035 * </p> 036 * 037 * <p> 038 * Maintenance views are primarily configured by the object class they are 039 * associated with. This provides the default dictionary information for the 040 * fields. If more than one maintenance view is needed for the same object 041 * class, the view name can be used to further identify an unique view 042 * </p> 043 * 044 * @author Kuali Rice Team (rice.collab@kuali.org) 045 */ 046 public class MaintenanceView extends DocumentView { 047 private static final long serialVersionUID = -3382802967703882341L; 048 049 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(MaintenanceView.class); 050 051 private Class<?> dataObjectClassName; 052 053 private String oldObjectBindingPath; 054 055 @RequestParameter 056 private String maintenanceAction; 057 058 public MaintenanceView() { 059 super(); 060 061 setViewTypeName(ViewType.MAINTENANCE); 062 } 063 064 /** 065 * The following initialization is performed: 066 * 067 * <ul> 068 * <li>Retrieve the maintenance document entry for defaults and context</li> 069 * <li>Set the abstractTypeClasses map for the maintenance object path</li> 070 * </ul> 071 * 072 * @see org.kuali.rice.krad.uif.container.ContainerBase#performInitialization(org.kuali.rice.krad.uif.container.View) 073 */ 074 @Override 075 public void performInitialization(View view) { 076 super.performInitialization(view); 077 078 // get maintenance document entry 079 MaintenanceDocumentEntry documentEntry = null; 080 String docTypeName = KRADServiceLocatorWeb.getDocumentDictionaryService() 081 .getMaintenanceDocumentTypeName(getDataObjectClassName()); 082 if (StringUtils.isNotBlank(docTypeName)) { 083 documentEntry = 084 KRADServiceLocatorWeb.getDocumentDictionaryService().getMaintenanceDocumentEntry(docTypeName); 085 } 086 087 if (documentEntry != null) { 088 pushObjectToContext(UifConstants.ContextVariableNames.DOCUMENT_ENTRY, documentEntry); 089 } else { 090 LOG.error("Unable to find maintenance document entry for data object class: " + 091 getDataObjectClassName().getName()); 092 throw new RuntimeException("Unable to find maintenance document entry for data object class: " + 093 getDataObjectClassName().getName()); 094 } 095 096 getAbstractTypeClasses().put(getDefaultBindingObjectPath(), getDataObjectClassName()); 097 getAbstractTypeClasses().put(getOldObjectBindingPath(), getDataObjectClassName()); 098 } 099 100 /** 101 * Class name for the object the maintenance document applies to 102 * 103 * <p> 104 * The object class name is used to pick up a dictionary entry which will 105 * feed the attribute field definitions and other configuration. In addition 106 * it is used to configure the <code>Maintainable</code> which will carry 107 * out the maintenance action 108 * </p> 109 * 110 * @return Class<?> maintenance object class 111 */ 112 public Class<?> getDataObjectClassName() { 113 return this.dataObjectClassName; 114 } 115 116 /** 117 * Setter for the object class name 118 * 119 * @param dataObjectClassName 120 */ 121 public void setDataObjectClassName(Class<?> dataObjectClassName) { 122 this.dataObjectClassName = dataObjectClassName; 123 } 124 125 /** 126 * Gives the binding path to the old object (record being edited) to display 127 * for comparison 128 * 129 * @return String old object binding path 130 */ 131 public String getOldObjectBindingPath() { 132 return this.oldObjectBindingPath; 133 } 134 135 /** 136 * Setter for the old object binding path 137 * 138 * @param oldObjectBindingPath 139 */ 140 public void setOldObjectBindingPath(String oldObjectBindingPath) { 141 this.oldObjectBindingPath = oldObjectBindingPath; 142 } 143 144 /** 145 * Indicates what maintenance action (new, edit, copy) was 146 * requested 147 * 148 * @return String maintenance action 149 */ 150 public String getMaintenanceAction() { 151 return maintenanceAction; 152 } 153 154 /** 155 * Setter for the maintenance action 156 * 157 * @param maintenanceAction 158 */ 159 public void setMaintenanceAction(String maintenanceAction) { 160 this.maintenanceAction = maintenanceAction; 161 } 162 163 }