View Javadoc
1   /**
2    * Copyright 2005-2015 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.krad.uif.view;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.krad.datadictionary.MaintenanceDocumentEntry;
20  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
21  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
22  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
23  import org.kuali.rice.krad.uif.UifConstants.ViewType;
24  import org.kuali.rice.krad.uif.component.RequestParameter;
25  
26  /**
27   * View type for Maintenance documents
28   *
29   * <p>Supports primary display for a new maintenance record, in which case the
30   * fields are display for populating the new record, and an edit maintenance
31   * record, which is a comparison view with the old record read-only on the left
32   * side and the new record (changed record) on the right side</p>
33   *
34   * <p>The <code>MaintenanceDocumentView</code> provides the interface for the maintenance
35   * framework. It works with the <code>Maintainable</code> service and
36   * maintenance controller.</p>
37   *
38   * <p>Maintenance views are primarily configured by the object class they are
39   * associated with. This provides the default dictionary information for the
40   * fields. If more than one maintenance view is needed for the same object
41   * class, the view name can be used to further identify an unique view</p>
42   *
43   * @author Kuali Rice Team (rice.collab@kuali.org)
44   */
45  @BeanTag(name = "maintenanceView", parent="Uif-MaintenanceView")
46  public class MaintenanceDocumentView extends DocumentView {
47      private static final long serialVersionUID = -3382802967703882341L;
48  
49      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(MaintenanceDocumentView.class);
50  
51      private Class<?> dataObjectClassName;
52  
53      private String docTypeName;
54  
55      private String oldObjectBindingPath;
56  
57      @RequestParameter
58      private String maintenanceAction;
59  
60      public MaintenanceDocumentView() {
61          super();
62  
63          setViewTypeName(ViewType.MAINTENANCE);
64      }
65  
66      /**
67       * The following initialization is performed:
68       *
69       * <ul>
70       * <li>Set the abstractTypeClasses map for the maintenance object path</li>
71       * </ul>
72       *
73       * {@inheritDoc}
74       */
75      @Override
76      public void performInitialization(Object model) {
77          super.performInitialization(model);
78  
79          getObjectPathToConcreteClassMapping().put(getDefaultBindingObjectPath(), getDataObjectClassName());
80          getObjectPathToConcreteClassMapping().put(getOldObjectBindingPath(), getDataObjectClassName());
81      }
82  
83      /**
84       * Overrides to retrieve the a {@link MaintenanceDocumentEntry} based on the configured data object class
85       *
86       * @return MaintenanceDocumentEntry document entry (exception thrown if not found)
87       */
88      @Override
89      protected MaintenanceDocumentEntry getDocumentEntryForView() {
90          MaintenanceDocumentEntry documentEntry = null;
91          String docTypeName = KRADServiceLocatorWeb.getDocumentDictionaryService().getMaintenanceDocumentTypeName(
92                  getDataObjectClassName());
93          if (StringUtils.isNotBlank(docTypeName)) {
94              documentEntry = KRADServiceLocatorWeb.getDocumentDictionaryService().getMaintenanceDocumentEntry(
95                      docTypeName);
96          }
97  
98          if (documentEntry == null) {
99              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 }