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.DocumentEntry;
20 import org.kuali.rice.krad.datadictionary.MaintenanceDocumentEntry;
21 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
22 import org.kuali.rice.krad.uif.UifConstants;
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>MaintenanceView</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 public class MaintenanceView extends DocumentView {
52 private static final long serialVersionUID = -3382802967703882341L;
53
54 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(MaintenanceView.class);
55
56 private Class<?> dataObjectClassName;
57
58 private String oldObjectBindingPath;
59
60 @RequestParameter
61 private String maintenanceAction;
62
63 public MaintenanceView() {
64 super();
65
66 setViewTypeName(ViewType.MAINTENANCE);
67 }
68
69 /**
70 * The following initialization is performed:
71 *
72 * <ul>
73 * <li>Set the abstractTypeClasses map for the maintenance object path</li>
74 * </ul>
75 *
76 * @see org.kuali.rice.krad.uif.container.ContainerBase#performInitialization(org.kuali.rice.krad.uif.view.View, java.lang.Object)
77 */
78 @Override
79 public void performInitialization(View view, Object model) {
80 super.performInitialization(view, model);
81
82 getAbstractTypeClasses().put(getDefaultBindingObjectPath(), getDataObjectClassName());
83 getAbstractTypeClasses().put(getOldObjectBindingPath(), getDataObjectClassName());
84 }
85
86 /**
87 * Overrides to retrieve the a {@link MaintenanceDocumentEntry} based on the configured data object class
88 *
89 * @return MaintenanceDocumentEntry document entry (exception thrown if not found)
90 */
91 @Override
92 protected MaintenanceDocumentEntry getDocumentEntryForView() {
93 MaintenanceDocumentEntry documentEntry = null;
94 String docTypeName = KRADServiceLocatorWeb.getDocumentDictionaryService().getMaintenanceDocumentTypeName(
95 getDataObjectClassName());
96 if (StringUtils.isNotBlank(docTypeName)) {
97 documentEntry = KRADServiceLocatorWeb.getDocumentDictionaryService().getMaintenanceDocumentEntry(
98 docTypeName);
99 }
100
101 if (documentEntry == null) {
102 throw new RuntimeException(
103 "Unable to find maintenance document entry for data object class: " + getDataObjectClassName()
104 .getName());
105 }
106
107 return documentEntry;
108 }
109
110 /**
111 * Class name for the object the maintenance document applies to
112 *
113 * <p>
114 * The object class name is used to pick up a dictionary entry which will
115 * feed the attribute field definitions and other configuration. In addition
116 * it is used to configure the <code>Maintainable</code> which will carry
117 * out the maintenance action
118 * </p>
119 *
120 * @return Class<?> maintenance object class
121 */
122 public Class<?> getDataObjectClassName() {
123 return this.dataObjectClassName;
124 }
125
126 /**
127 * Setter for the object class name
128 *
129 * @param dataObjectClassName
130 */
131 public void setDataObjectClassName(Class<?> dataObjectClassName) {
132 this.dataObjectClassName = dataObjectClassName;
133 }
134
135 /**
136 * Gives the binding path to the old object (record being edited) to display
137 * for comparison
138 *
139 * @return String old object binding path
140 */
141 public String getOldObjectBindingPath() {
142 return this.oldObjectBindingPath;
143 }
144
145 /**
146 * Setter for the old object binding path
147 *
148 * @param oldObjectBindingPath
149 */
150 public void setOldObjectBindingPath(String oldObjectBindingPath) {
151 this.oldObjectBindingPath = oldObjectBindingPath;
152 }
153
154 /**
155 * Indicates what maintenance action (new, edit, copy) was
156 * requested
157 *
158 * @return String maintenance action
159 */
160 public String getMaintenanceAction() {
161 return maintenanceAction;
162 }
163
164 /**
165 * Setter for the maintenance action
166 *
167 * @param maintenanceAction
168 */
169 public void setMaintenanceAction(String maintenanceAction) {
170 this.maintenanceAction = maintenanceAction;
171 }
172
173 }