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