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.krad.uif.view; 017 018import org.apache.commons.lang.StringUtils; 019import org.kuali.rice.krad.datadictionary.MaintenanceDocumentEntry; 020import org.kuali.rice.krad.datadictionary.parse.BeanTag; 021import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute; 022import org.kuali.rice.krad.service.KRADServiceLocatorWeb; 023import org.kuali.rice.krad.uif.UifConstants.ViewType; 024import org.kuali.rice.krad.uif.component.RequestParameter; 025 026/** 027 * View type for Maintenance documents 028 * 029 * <p>Supports primary display for a new maintenance record, in which case the 030 * fields are display for populating the new record, and an edit maintenance 031 * record, which is a comparison view with the old record read-only on the left 032 * side and the new record (changed record) on the right side</p> 033 * 034 * <p>The <code>MaintenanceDocumentView</code> provides the interface for the maintenance 035 * framework. It works with the <code>Maintainable</code> service and 036 * maintenance controller.</p> 037 * 038 * <p>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</p> 042 * 043 * @author Kuali Rice Team (rice.collab@kuali.org) 044 */ 045@BeanTag(name = "maintenanceView", parent="Uif-MaintenanceView") 046public class MaintenanceDocumentView extends DocumentView { 047 private static final long serialVersionUID = -3382802967703882341L; 048 049 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(MaintenanceDocumentView.class); 050 051 private Class<?> dataObjectClassName; 052 053 private String docTypeName; 054 055 private String oldObjectBindingPath; 056 057 @RequestParameter 058 private String maintenanceAction; 059 060 public MaintenanceDocumentView() { 061 super(); 062 063 setViewTypeName(ViewType.MAINTENANCE); 064 } 065 066 /** 067 * The following initialization is performed: 068 * 069 * <ul> 070 * <li>Set the abstractTypeClasses map for the maintenance object path</li> 071 * </ul> 072 * 073 * {@inheritDoc} 074 */ 075 @Override 076 public void performInitialization(Object model) { 077 super.performInitialization(model); 078 079 getObjectPathToConcreteClassMapping().put(getDefaultBindingObjectPath(), getDataObjectClassName()); 080 getObjectPathToConcreteClassMapping().put(getOldObjectBindingPath(), getDataObjectClassName()); 081 } 082 083 /** 084 * Overrides to retrieve the a {@link MaintenanceDocumentEntry} based on the configured data object class 085 * 086 * @return MaintenanceDocumentEntry document entry (exception thrown if not found) 087 */ 088 @Override 089 protected MaintenanceDocumentEntry getDocumentEntryForView() { 090 MaintenanceDocumentEntry documentEntry = null; 091 String docTypeName = KRADServiceLocatorWeb.getDocumentDictionaryService().getMaintenanceDocumentTypeName( 092 getDataObjectClassName()); 093 if (StringUtils.isNotBlank(docTypeName)) { 094 documentEntry = KRADServiceLocatorWeb.getDocumentDictionaryService().getMaintenanceDocumentEntry( 095 docTypeName); 096 } 097 098 if (documentEntry == null) { 099 throw new RuntimeException( 100 "Unable to find maintenance document entry for data object class: " + getDataObjectClassName() 101 .getName()); 102 } 103 104 return documentEntry; 105 } 106 107 /** 108 * Class name for the object the maintenance document applies to 109 * 110 * <p>The object class name is used to pick up a dictionary entry which will 111 * feed the attribute field definitions and other configuration. In addition 112 * it is used to configure the <code>Maintainable</code> which will carry 113 * out the maintenance action</p> 114 * 115 * @return maintenance object class 116 */ 117 @BeanTagAttribute 118 public Class<?> getDataObjectClassName() { 119 return this.dataObjectClassName; 120 } 121 122 /** 123 * @see #getDataObjectClassName() 124 */ 125 public void setDataObjectClassName(Class<?> dataObjectClassName) { 126 this.dataObjectClassName = dataObjectClassName; 127 } 128 129 /** 130 * Name for the document type the maintenance document applies to 131 * 132 * <p>The document type name is used to pick up a dictionary entry which will 133 * feed the attribute field definitions and other configuration. In addition 134 * it is used to configure the <code>Maintainable</code> which will carry 135 * out the maintenance action</p> 136 * 137 * @return document type name 138 */ 139 @BeanTagAttribute(name="docTypeName") 140 public String getDocTypeName() { 141 return this.docTypeName; 142 } 143 144 /** 145 * @see #getDocTypeName() 146 */ 147 public void setDocTypeName(String docTypeName) { 148 this.docTypeName = docTypeName; 149 } 150 151 /** 152 * Gives the binding path to the old object (record being edited) to display 153 * for comparison. 154 * 155 * @return old object binding path 156 */ 157 @BeanTagAttribute 158 public String getOldObjectBindingPath() { 159 return this.oldObjectBindingPath; 160 } 161 162 /** 163 * @see #getOldObjectBindingPath() 164 */ 165 public void setOldObjectBindingPath(String oldObjectBindingPath) { 166 this.oldObjectBindingPath = oldObjectBindingPath; 167 } 168 169 /** 170 * Indicates what maintenance action (new, edit, copy) was requested. 171 * 172 * @return maintenance action 173 */ 174 @BeanTagAttribute 175 public String getMaintenanceAction() { 176 return maintenanceAction; 177 } 178 179 /** 180 * @see #getMaintenanceAction() 181 */ 182 public void setMaintenanceAction(String maintenanceAction) { 183 this.maintenanceAction = maintenanceAction; 184 } 185}