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