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.util.ObjectUtils;
34 import org.kuali.rice.krad.web.form.LookupForm;
35 import org.springframework.beans.PropertyValues;
36
37
38
39
40
41
42
43
44
45
46
47 public class ViewDictionaryServiceImpl implements ViewDictionaryService {
48 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(
49 ViewDictionaryServiceImpl.class);
50
51 private DataDictionaryService dataDictionaryService;
52
53
54
55
56
57 public Inquirable getInquirable(Class<?> dataObjectClass, String viewName) {
58 Inquirable inquirable = null;
59
60 if (StringUtils.isBlank(viewName)) {
61 viewName = UifConstants.DEFAULT_VIEW_NAME;
62 }
63
64 Map<String, String> indexKey = new HashMap<String, String>();
65 indexKey.put(UifParameters.VIEW_NAME, viewName);
66 indexKey.put(UifParameters.DATA_OBJECT_CLASS_NAME, dataObjectClass.getName());
67
68
69 PropertyValues propertyValues = getDataDictionary().getViewPropertiesByType(ViewType.INQUIRY, indexKey);
70
71 String viewHelperServiceClassName = ViewModelUtils.getStringValFromPVs(propertyValues,
72 UifPropertyPaths.VIEW_HELPER_SERVICE_CLASS);
73 if (StringUtils.isNotBlank(viewHelperServiceClassName)) {
74 try {
75 inquirable = (Inquirable) ObjectUtils.newInstance(Class.forName(viewHelperServiceClassName));
76 } catch (ClassNotFoundException e) {
77 throw new RiceRuntimeException(
78 "Unable to find class for inquirable classname: " + viewHelperServiceClassName, e);
79 }
80 }
81
82 return inquirable;
83 }
84
85
86
87
88 public boolean isInquirable(Class<?> dataObjectClass) {
89 Map<String, String> indexKey = new HashMap<String, String>();
90 indexKey.put(UifParameters.VIEW_NAME, UifConstants.DEFAULT_VIEW_NAME);
91 indexKey.put(UifParameters.DATA_OBJECT_CLASS_NAME, dataObjectClass.getName());
92
93 boolean isInquirable = getDataDictionary().viewByTypeExist(ViewType.INQUIRY, indexKey);
94
95 return isInquirable;
96 }
97
98
99
100
101 public boolean isLookupable(Class<?> dataObjectClass) {
102 Map<String, String> indexKey = new HashMap<String, String>();
103 indexKey.put(UifParameters.VIEW_NAME, UifConstants.DEFAULT_VIEW_NAME);
104 indexKey.put(UifParameters.DATA_OBJECT_CLASS_NAME, dataObjectClass.getName());
105
106 boolean isLookupable = getDataDictionary().viewByTypeExist(ViewType.LOOKUP, indexKey);
107
108 return isLookupable;
109 }
110
111
112
113
114 public boolean isMaintainable(Class<?> dataObjectClass) {
115 Map<String, String> indexKey = new HashMap<String, String>();
116 indexKey.put(UifParameters.VIEW_NAME, UifConstants.DEFAULT_VIEW_NAME);
117 indexKey.put(UifParameters.DATA_OBJECT_CLASS_NAME, dataObjectClass.getName());
118
119 boolean isMaintainable = getDataDictionary().viewByTypeExist(ViewType.MAINTENANCE, indexKey);
120
121 return isMaintainable;
122 }
123
124
125
126
127
128
129
130
131 @Override
132 public Integer getResultSetLimitForLookup(Class<?> dataObjectClass, LookupForm lookupForm) {
133 LookupView lookupView = null;
134 boolean multipleValueSelectSpecifiedOnURL = false;
135
136 if (ObjectUtils.isNotNull(lookupForm)) {
137 if (lookupForm.isMultipleValuesSelect()) {
138 multipleValueSelectSpecifiedOnURL = true;
139 }
140
141 if (!multipleValueSelectSpecifiedOnURL && lookupForm.getViewRequestParameters().containsKey(UifParameters.MULTIPLE_VALUES_SELECT)) {
142 String multiValueSelect = lookupForm.getViewRequestParameters().get(
143 UifParameters.MULTIPLE_VALUES_SELECT);
144 if (multiValueSelect.equalsIgnoreCase("true")) {
145 multipleValueSelectSpecifiedOnURL = true;
146 }
147 }
148 lookupView = (LookupView)lookupForm.getView();
149 } else {
150 Map<String, String> indexKey = new HashMap<String, String>();
151 indexKey.put(UifParameters.VIEW_NAME, UifConstants.DEFAULT_VIEW_NAME);
152 indexKey.put(UifParameters.DATA_OBJECT_CLASS_NAME, dataObjectClass.getName());
153 lookupView = (LookupView)getDataDictionary().getViewByTypeIndex(ViewType.LOOKUP, indexKey);
154 }
155
156 if (lookupView != null) {
157 if (lookupView.isMultipleValuesSelect() || multipleValueSelectSpecifiedOnURL) {
158 return lookupView.getMultipleValuesSelectResultSetLimit();
159 } else {
160 return lookupView.getResultSetLimit();
161 }
162 }
163 return null;
164 }
165
166 protected DataDictionary getDataDictionary() {
167 return getDataDictionaryService().getDataDictionary();
168 }
169
170 protected DataDictionaryService getDataDictionaryService() {
171 return this.dataDictionaryService;
172 }
173
174 public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
175 this.dataDictionaryService = dataDictionaryService;
176 }
177 }