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