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