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.Map;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.kuali.rice.core.api.exception.RiceRuntimeException;
23 import org.kuali.rice.krad.datadictionary.DataDictionary;
24 import org.kuali.rice.krad.inquiry.Inquirable;
25 import org.kuali.rice.krad.service.DataDictionaryService;
26 import org.kuali.rice.krad.uif.UifConstants;
27 import org.kuali.rice.krad.uif.UifParameters;
28 import org.kuali.rice.krad.uif.UifPropertyPaths;
29 import org.kuali.rice.krad.uif.util.ViewModelUtils;
30 import org.kuali.rice.krad.uif.view.LookupView;
31 import org.kuali.rice.krad.uif.service.ViewDictionaryService;
32 import org.kuali.rice.krad.uif.UifConstants.ViewType;
33 import org.kuali.rice.krad.uif.view.View;
34 import org.kuali.rice.krad.uif.view.ViewSessionPolicy;
35 import org.kuali.rice.krad.util.ObjectUtils;
36 import org.kuali.rice.krad.web.form.LookupForm;
37 import org.springframework.beans.PropertyValues;
38 import org.springframework.util.Assert;
39
40
41
42
43
44
45
46
47
48
49
50 public class ViewDictionaryServiceImpl implements ViewDictionaryService {
51 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(
52 ViewDictionaryServiceImpl.class);
53
54 private DataDictionaryService dataDictionaryService;
55
56
57
58
59
60 public Inquirable getInquirable(Class<?> dataObjectClass, String viewName) {
61 Inquirable inquirable = null;
62
63 if (StringUtils.isBlank(viewName)) {
64 viewName = UifConstants.DEFAULT_VIEW_NAME;
65 }
66
67 Map<String, String> indexKey = new HashMap<String, String>();
68 indexKey.put(UifParameters.VIEW_NAME, viewName);
69 indexKey.put(UifParameters.DATA_OBJECT_CLASS_NAME, dataObjectClass.getName());
70
71
72 PropertyValues propertyValues = getDataDictionary().getViewPropertiesByType(ViewType.INQUIRY, indexKey);
73
74 String viewHelperServiceClassName = ViewModelUtils.getStringValFromPVs(propertyValues,
75 UifPropertyPaths.VIEW_HELPER_SERVICE_CLASS);
76 if (StringUtils.isNotBlank(viewHelperServiceClassName)) {
77 try {
78 inquirable = (Inquirable) ObjectUtils.newInstance(Class.forName(viewHelperServiceClassName));
79 } catch (ClassNotFoundException e) {
80 throw new RiceRuntimeException(
81 "Unable to find class for inquirable classname: " + viewHelperServiceClassName, e);
82 }
83 }
84
85 return inquirable;
86 }
87
88
89
90
91 public boolean isInquirable(Class<?> dataObjectClass) {
92 Map<String, String> indexKey = new HashMap<String, String>();
93 indexKey.put(UifParameters.VIEW_NAME, UifConstants.DEFAULT_VIEW_NAME);
94 indexKey.put(UifParameters.DATA_OBJECT_CLASS_NAME, dataObjectClass.getName());
95
96 boolean isInquirable = getDataDictionary().viewByTypeExist(ViewType.INQUIRY, indexKey);
97
98 return isInquirable;
99 }
100
101
102
103
104 public boolean isLookupable(Class<?> dataObjectClass) {
105 Map<String, String> indexKey = new HashMap<String, String>();
106 indexKey.put(UifParameters.VIEW_NAME, UifConstants.DEFAULT_VIEW_NAME);
107 indexKey.put(UifParameters.DATA_OBJECT_CLASS_NAME, dataObjectClass.getName());
108
109 boolean isLookupable = getDataDictionary().viewByTypeExist(ViewType.LOOKUP, indexKey);
110
111 return isLookupable;
112 }
113
114
115
116
117 public boolean isMaintainable(Class<?> dataObjectClass) {
118 Map<String, String> indexKey = new HashMap<String, String>();
119 indexKey.put(UifParameters.VIEW_NAME, UifConstants.DEFAULT_VIEW_NAME);
120 indexKey.put(UifParameters.DATA_OBJECT_CLASS_NAME, dataObjectClass.getName());
121
122 boolean isMaintainable = getDataDictionary().viewByTypeExist(ViewType.MAINTENANCE, indexKey);
123
124 return isMaintainable;
125 }
126
127
128
129
130
131
132
133
134 @Override
135 public Integer getResultSetLimitForLookup(Class<?> dataObjectClass, LookupForm lookupForm) {
136 LookupView lookupView = null;
137 boolean multipleValueSelectSpecifiedOnURL = false;
138
139 if (ObjectUtils.isNotNull(lookupForm)) {
140 if (lookupForm.isMultipleValuesSelect()) {
141 multipleValueSelectSpecifiedOnURL = true;
142 }
143
144 if (!multipleValueSelectSpecifiedOnURL && lookupForm.getViewRequestParameters().containsKey(
145 UifParameters.MULTIPLE_VALUES_SELECT)) {
146 String multiValueSelect = lookupForm.getViewRequestParameters().get(
147 UifParameters.MULTIPLE_VALUES_SELECT);
148 if (multiValueSelect.equalsIgnoreCase("true")) {
149 multipleValueSelectSpecifiedOnURL = true;
150 }
151 }
152 lookupView = (LookupView) lookupForm.getView();
153 } else {
154 Map<String, String> indexKey = new HashMap<String, String>();
155 indexKey.put(UifParameters.VIEW_NAME, UifConstants.DEFAULT_VIEW_NAME);
156 indexKey.put(UifParameters.DATA_OBJECT_CLASS_NAME, dataObjectClass.getName());
157 lookupView = (LookupView) getDataDictionary().getViewByTypeIndex(ViewType.LOOKUP, indexKey);
158 }
159
160 if (lookupView != null) {
161 if (lookupView.isMultipleValuesSelect() || multipleValueSelectSpecifiedOnURL) {
162 return lookupView.getMultipleValuesSelectResultSetLimit();
163 } else {
164 return lookupView.getResultSetLimit();
165 }
166 }
167 return null;
168 }
169
170
171
172
173 public ViewSessionPolicy getViewSessionPolicy(String viewId) {
174 Assert.hasLength(viewId, "view id is required for retrieving the view session policy");
175
176 ViewSessionPolicy viewSessionPolicy = null;
177
178 View view = getDataDictionary().getImmutableViewById(viewId);
179 if (view != null) {
180 viewSessionPolicy = view.getSessionPolicy();
181 }
182
183 return viewSessionPolicy;
184 }
185
186
187
188
189 public boolean isSessionStorageEnabled(String viewId) {
190 Assert.hasLength(viewId, "view id is required for retrieving session indicator");
191
192 boolean sessionStorageEnabled = false;
193
194 View view = getDataDictionary().getImmutableViewById(viewId);
195 if (view != null) {
196 sessionStorageEnabled = view.isPersistFormToSession();
197 }
198
199 return sessionStorageEnabled;
200 }
201
202 protected DataDictionary getDataDictionary() {
203 return getDataDictionaryService().getDataDictionary();
204 }
205
206 protected DataDictionaryService getDataDictionaryService() {
207 return this.dataDictionaryService;
208 }
209
210 public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
211 this.dataDictionaryService = dataDictionaryService;
212 }
213 }