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