View Javadoc

1   /**
2    * Copyright 2005-2012 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.service.KRADServiceLocatorWeb;
21  import org.kuali.rice.krad.uif.UifConstants.ViewType;
22  import org.kuali.rice.krad.uif.component.RequestParameter;
23  
24  /**
25   * View type for Maintenance documents
26   *
27   * <p>
28   * Supports primary display for a new maintenance record, in which case the
29   * fields are display for populating the new record, and an edit maintenance
30   * record, which is a comparison view with the old record read-only on the left
31   * side and the new record (changed record) on the right side
32   * </p>
33   *
34   * <p>
35   * The <code>MaintenanceView</code> provides the interface for the maintenance
36   * framework. It works with the <code>Maintainable</code> service and
37   * maintenance controller.
38   * </p>
39   *
40   * <p>
41   * Maintenance views are primarily configured by the object class they are
42   * associated with. This provides the default dictionary information for the
43   * fields. If more than one maintenance view is needed for the same object
44   * class, the view name can be used to further identify an unique view
45   * </p>
46   *
47   * @author Kuali Rice Team (rice.collab@kuali.org)
48   */
49  public class MaintenanceView extends DocumentView {
50      private static final long serialVersionUID = -3382802967703882341L;
51  
52      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(MaintenanceView.class);
53  
54      private Class<?> dataObjectClassName;
55  
56      private String oldObjectBindingPath;
57  
58      @RequestParameter
59      private String maintenanceAction;
60  
61      public MaintenanceView() {
62          super();
63  
64          setViewTypeName(ViewType.MAINTENANCE);
65      }
66  
67      /**
68       * The following initialization is performed:
69       *
70       * <ul>
71       * <li>Set the abstractTypeClasses map for the maintenance object path</li>
72       * </ul>
73       *
74       * @see org.kuali.rice.krad.uif.container.ContainerBase#performInitialization(org.kuali.rice.krad.uif.view.View, java.lang.Object)
75       */
76      @Override
77      public void performInitialization(View view, Object model) {
78          super.performInitialization(view, model);
79  
80          getObjectPathToConcreteClassMapping().put(getDefaultBindingObjectPath(), getDataObjectClassName());
81          getObjectPathToConcreteClassMapping().put(getOldObjectBindingPath(), getDataObjectClassName());
82      }
83  
84      /**
85       * Overrides to retrieve the a {@link MaintenanceDocumentEntry} based on the configured data object class
86       *
87       * @return MaintenanceDocumentEntry document entry (exception thrown if not found)
88       */
89      @Override
90      protected MaintenanceDocumentEntry getDocumentEntryForView() {
91          MaintenanceDocumentEntry documentEntry = null;
92          String docTypeName = KRADServiceLocatorWeb.getDocumentDictionaryService().getMaintenanceDocumentTypeName(
93                  getDataObjectClassName());
94          if (StringUtils.isNotBlank(docTypeName)) {
95              documentEntry = KRADServiceLocatorWeb.getDocumentDictionaryService().getMaintenanceDocumentEntry(
96                      docTypeName);
97          }
98  
99          if (documentEntry == null) {
100             throw new RuntimeException(
101                     "Unable to find maintenance document entry for data object class: " + getDataObjectClassName()
102                             .getName());
103         }
104 
105         return documentEntry;
106     }
107 
108     /**
109      * Class name for the object the maintenance document applies to
110      *
111      * <p>
112      * The object class name is used to pick up a dictionary entry which will
113      * feed the attribute field definitions and other configuration. In addition
114      * it is used to configure the <code>Maintainable</code> which will carry
115      * out the maintenance action
116      * </p>
117      *
118      * @return Class<?> maintenance object class
119      */
120     public Class<?> getDataObjectClassName() {
121         return this.dataObjectClassName;
122     }
123 
124     /**
125      * Setter for the object class name
126      *
127      * @param dataObjectClassName
128      */
129     public void setDataObjectClassName(Class<?> dataObjectClassName) {
130         this.dataObjectClassName = dataObjectClassName;
131     }
132 
133     /**
134      * Gives the binding path to the old object (record being edited) to display
135      * for comparison
136      *
137      * @return String old object binding path
138      */
139     public String getOldObjectBindingPath() {
140         return this.oldObjectBindingPath;
141     }
142 
143     /**
144      * Setter for the old object binding path
145      *
146      * @param oldObjectBindingPath
147      */
148     public void setOldObjectBindingPath(String oldObjectBindingPath) {
149         this.oldObjectBindingPath = oldObjectBindingPath;
150     }
151 
152     /**
153      * Indicates what maintenance action (new, edit, copy) was
154      * requested
155      *
156      * @return String maintenance action
157      */
158     public String getMaintenanceAction() {
159         return maintenanceAction;
160     }
161 
162     /**
163      * Setter for the maintenance action
164      *
165      * @param maintenanceAction
166      */
167     public void setMaintenanceAction(String maintenanceAction) {
168         this.maintenanceAction = maintenanceAction;
169     }
170 
171 }