1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.service.impl;
17
18 import org.apache.commons.logging.Log;
19 import org.apache.commons.logging.LogFactory;
20 import org.apache.log4j.Logger;
21 import org.apache.log4j.Priority;
22 import org.kuali.rice.core.api.CoreApiServiceLocator;
23 import org.kuali.rice.krad.datadictionary.validator.ValidationController;
24 import org.kuali.rice.krad.service.DataDictionaryService;
25 import org.kuali.rice.krad.uif.UifConstants;
26 import org.kuali.rice.krad.uif.UifConstants.ViewStatus;
27 import org.kuali.rice.krad.uif.UifConstants.ViewType;
28 import org.kuali.rice.krad.uif.service.ViewHelperService;
29 import org.kuali.rice.krad.uif.service.ViewService;
30 import org.kuali.rice.krad.uif.service.ViewTypeService;
31 import org.kuali.rice.krad.uif.view.View;
32 import org.kuali.rice.krad.web.form.UifFormBase;
33
34 import java.util.List;
35 import java.util.Map;
36
37
38
39
40
41
42
43
44
45
46
47
48 public class ViewServiceImpl implements ViewService {
49 private static final Logger LOG = Logger.getLogger(ViewServiceImpl.class);
50
51 private DataDictionaryService dataDictionaryService;
52
53
54 private List<ViewTypeService> viewTypeServices;
55
56
57
58
59 public View getViewById(String viewId) {
60 if (LOG.isDebugEnabled()) {
61 LOG.debug("retrieving view instance for id: " + viewId);
62 }
63
64 View view = dataDictionaryService.getViewById(viewId);
65 if (view == null) {
66 LOG.warn("View not found for id: " + viewId);
67 } else {
68 if (LOG.isDebugEnabled()) {
69 LOG.debug("Updating view status to CREATED for view: " + view.getId());
70 }
71 view.setViewStatus(ViewStatus.CREATED);
72 }
73
74 return view;
75 }
76
77
78
79
80
81
82
83
84
85 public View getViewByType(ViewType viewType, Map<String, String> parameters) {
86 ViewTypeService typeService = getViewTypeService(viewType);
87 if (typeService == null) {
88 throw new RuntimeException("Unable to find view type service for view type name: " + viewType);
89 }
90
91 Map<String, String> typeParameters = typeService.getParametersFromRequest(parameters);
92
93 View view = dataDictionaryService.getViewByTypeIndex(viewType, typeParameters);
94 if (view == null) {
95 LOG.warn("View not found for type: " + viewType);
96 } else {
97 LOG.debug("Updating view status to CREATED for view: " + view.getId());
98 view.setViewStatus(ViewStatus.CREATED);
99 }
100
101 return view;
102 }
103
104
105
106
107
108 public String getViewIdForViewType(ViewType viewType, Map<String, String> parameters) {
109 ViewTypeService typeService = getViewTypeService(viewType);
110 if (typeService == null) {
111 throw new RuntimeException("Unable to find view type service for view type name: " + viewType);
112 }
113
114 Map<String, String> typeParameters = typeService.getParametersFromRequest(parameters);
115
116 return dataDictionaryService.getViewIdByTypeIndex(viewType, typeParameters);
117 }
118
119
120
121
122
123 public void buildView(View view, Object model, Map<String, String> parameters) {
124
125 ViewHelperService helperService = view.getViewHelperService();
126
127
128 helperService.populateViewFromRequestParameters(view, parameters);
129
130
131 ((UifFormBase) model).setViewRequestParameters(view.getViewRequestParameters());
132
133
134 performViewLifecycle(view, model, parameters);
135
136
137 if (CoreApiServiceLocator.getKualiConfigurationService().getPropertyValueAsBoolean(
138 UifConstants.VALIDATE_VIEWS_ONBUILD)) {
139 ValidationController validator = new ValidationController(true, true, true, true, false);
140 Log tempLogger = LogFactory.getLog(ViewServiceImpl.class);
141 validator.validate(view, tempLogger, false);
142 }
143 }
144
145
146
147
148
149
150
151
152
153
154
155
156 protected void performViewLifecycle(View view, Object model, Map<String, String> parameters) {
157
158 ViewHelperService helperService = view.getViewHelperService();
159
160
161 if (LOG.isEnabledFor(Priority.INFO)) {
162 LOG.info("performing initialize phase for view: " + view.getId());
163 }
164 helperService.performInitialization(view, model);
165
166
167 if (LOG.isDebugEnabled()) {
168 LOG.debug("processing indexing for view: " + view.getId());
169 }
170 view.index();
171
172
173 if (LOG.isDebugEnabled()) {
174 LOG.debug("Updating view status to INITIALIZED for view: " + view.getId());
175 }
176 view.setViewStatus(ViewStatus.INITIALIZED);
177
178
179 if (LOG.isEnabledFor(Priority.INFO)) {
180 LOG.info("performing apply model phase for view: " + view.getId());
181 }
182 helperService.performApplyModel(view, model);
183
184
185 if (LOG.isEnabledFor(Priority.INFO)) {
186 LOG.info("reindexing after apply model for view: " + view.getId());
187 }
188 view.index();
189
190
191 if (LOG.isEnabledFor(Priority.INFO)) {
192 LOG.info("performing finalize phase for view: " + view.getId());
193 }
194 helperService.performFinalize(view, model);
195
196
197 if (LOG.isEnabledFor(Priority.INFO)) {
198 LOG.info("processing final indexing for view: " + view.getId());
199 }
200 view.index();
201
202
203 if (LOG.isDebugEnabled()) {
204 LOG.debug("Updating view status to FINAL for view: " + view.getId());
205 }
206 view.setViewStatus(ViewStatus.FINAL);
207 }
208
209 public ViewTypeService getViewTypeService(UifConstants.ViewType viewType) {
210 if (viewTypeServices != null) {
211 for (ViewTypeService typeService : viewTypeServices) {
212 if (viewType.equals(typeService.getViewTypeName())) {
213 return typeService;
214 }
215 }
216 }
217
218 return null;
219 }
220
221 public List<ViewTypeService> getViewTypeServices() {
222 return this.viewTypeServices;
223 }
224
225 public void setViewTypeServices(List<ViewTypeService> viewTypeServices) {
226 this.viewTypeServices = viewTypeServices;
227 }
228
229 protected DataDictionaryService getDataDictionaryService() {
230 return this.dataDictionaryService;
231 }
232
233 public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
234 this.dataDictionaryService = dataDictionaryService;
235 }
236
237 }