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