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