1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.lookup;
17
18 import java.beans.PropertyDescriptor;
19 import java.util.ArrayList;
20 import java.util.Arrays;
21 import java.util.Collection;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.regex.Pattern;
26
27 import org.apache.commons.beanutils.PropertyUtils;
28 import org.kuali.rice.kns.authorization.BusinessObjectRestrictions;
29 import org.kuali.rice.kns.bo.BusinessObject;
30 import org.kuali.rice.kns.bo.BusinessObjectAttributeEntry;
31 import org.kuali.rice.kns.datadictionary.control.ControlDefinition;
32 import org.kuali.rice.kns.service.DataDictionaryService;
33 import org.kuali.rice.kns.service.KNSServiceLocator;
34 import org.kuali.rice.kns.util.BeanPropertyComparator;
35 import org.kuali.rice.kns.util.KNSConstants;
36 import org.kuali.rice.kns.web.struts.form.LookupForm;
37
38 public class DictionaryLookupableHelperServiceImpl extends AbstractLookupableHelperServiceImpl {
39 private static final long serialVersionUID = 970484069493741447L;
40 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DictionaryLookupableHelperServiceImpl.class);
41 private static final List IGNORED_FIELDS = Arrays.asList(new String[] { "class", "validationNumber" });
42
43
44
45 @Override
46 public List getSearchResults(Map<String, String> fieldValues) {
47 throw new UnsupportedOperationException("getSearchResults not supported for DictionaryLookupableHelperServiceImpl");
48 }
49
50
51
52
53
54
55 public List getSearchResults(Map fieldValues, Map fieldConversions) {
56 setBackLocation((String) fieldValues.get(KNSConstants.BACK_LOCATION));
57 setDocFormKey((String) fieldValues.get(KNSConstants.DOC_FORM_KEY));
58
59 List searchResults = new ArrayList();
60 DataDictionaryService dataDictionaryService = KNSServiceLocator.getDataDictionaryService();
61 try {
62 String boClassName = (String) fieldValues.get(KNSConstants.DICTIONARY_BO_NAME);
63
64
65 Class boClass = Class.forName(boClassName);
66
67
68
69 PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(boClass);
70 for (int i = 0; i < descriptors.length; ++i) {
71 PropertyDescriptor propertyDescriptor = descriptors[i];
72
73
74 if (IGNORED_FIELDS.contains(propertyDescriptor.getName())) {
75 continue;
76 }
77
78
79
80
81 if (!Collection.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
82 String propertyName = propertyDescriptor.getName();
83
84 BusinessObjectAttributeEntry attributeEntry = new BusinessObjectAttributeEntry();
85 attributeEntry.setAttributeName(propertyName);
86 attributeEntry.setAttributeLabel(dataDictionaryService.getAttributeLabel(boClass, propertyName));
87 attributeEntry.setAttributeSummary(dataDictionaryService.getAttributeSummary(boClass, propertyName));
88
89 Integer maxLength = dataDictionaryService.getAttributeMaxLength(boClass, propertyName);
90 if (maxLength != null) {
91 attributeEntry.setAttributeMaxLength(maxLength.toString());
92 }
93
94 Pattern validationExpression = dataDictionaryService.getAttributeValidatingExpression(boClass, propertyName);
95 if (validationExpression != null) {
96 attributeEntry.setAttributeValidatingExpression(validationExpression.pattern());
97 }
98 ControlDefinition controlDef = dataDictionaryService.getAttributeControlDefinition(boClass, propertyName);
99 if (controlDef != null) {
100 attributeEntry.setAttributeControlType(controlDef.toString());
101 }
102 Class formatterClass = dataDictionaryService.getAttributeFormatter(boClass, propertyName);
103 if (formatterClass != null) {
104 attributeEntry.setAttributeFormatterClassName(formatterClass.getName());
105 }
106
107
108 searchResults.add(attributeEntry);
109 }
110
111 }
112
113
114 List defaultSortColumns = getDefaultSortColumns();
115 if (defaultSortColumns.size() > 0) {
116 Collections.sort(searchResults, new BeanPropertyComparator(getDefaultSortColumns(), true));
117 }
118 }
119 catch (ClassNotFoundException e) {
120 LOG.error("Class not found for bo search name" + e.getMessage());
121 throw new RuntimeException("Class not found for bo search name" + e.getMessage());
122 }
123
124 return searchResults;
125 }
126
127
128
129
130
131 @Override
132 public HtmlData getReturnUrl(BusinessObject bo, LookupForm lookupForm, List returnKeys, BusinessObjectRestrictions businessObjectRestrictions) {
133 return getEmptyAnchorHtmlData();
134 }
135
136
137
138
139
140
141 @Override
142 protected String getActionUrlHref(BusinessObject businessObject, String methodToCall, List pkNames){
143 return KNSConstants.EMPTY_STRING;
144 }
145
146
147
148
149 public List getDefaultReturnType() {
150 return new ArrayList();
151 }
152
153
154
155
156 @Override
157 public List getReturnKeys() {
158 return new ArrayList();
159 }
160 }