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