| 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 | 0 | public class DictionaryLookupableHelperServiceImpl extends AbstractLookupableHelperServiceImpl { |
| 39 | |
private static final long serialVersionUID = 970484069493741447L; |
| 40 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DictionaryLookupableHelperServiceImpl.class); |
| 41 | 0 | 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 | 0 | throw new UnsupportedOperationException("getSearchResults not supported for DictionaryLookupableHelperServiceImpl"); |
| 48 | |
} |
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
public List getSearchResults(Map fieldValues, Map fieldConversions) { |
| 56 | 0 | setBackLocation((String) fieldValues.get(KNSConstants.BACK_LOCATION)); |
| 57 | 0 | setDocFormKey((String) fieldValues.get(KNSConstants.DOC_FORM_KEY)); |
| 58 | |
|
| 59 | 0 | List searchResults = new ArrayList(); |
| 60 | 0 | DataDictionaryService dataDictionaryService = KNSServiceLocator.getDataDictionaryService(); |
| 61 | |
try { |
| 62 | 0 | String boClassName = (String) fieldValues.get(KNSConstants.DICTIONARY_BO_NAME); |
| 63 | |
|
| 64 | |
|
| 65 | 0 | Class boClass = Class.forName(boClassName); |
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | 0 | PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(boClass); |
| 70 | 0 | for (int i = 0; i < descriptors.length; ++i) { |
| 71 | 0 | PropertyDescriptor propertyDescriptor = descriptors[i]; |
| 72 | |
|
| 73 | |
|
| 74 | 0 | if (IGNORED_FIELDS.contains(propertyDescriptor.getName())) { |
| 75 | 0 | continue; |
| 76 | |
} |
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | 0 | if (!Collection.class.isAssignableFrom(propertyDescriptor.getPropertyType())) { |
| 82 | 0 | String propertyName = propertyDescriptor.getName(); |
| 83 | |
|
| 84 | 0 | BusinessObjectAttributeEntry attributeEntry = new BusinessObjectAttributeEntry(); |
| 85 | 0 | attributeEntry.setAttributeName(propertyName); |
| 86 | 0 | attributeEntry.setAttributeLabel(dataDictionaryService.getAttributeLabel(boClass, propertyName)); |
| 87 | 0 | attributeEntry.setAttributeSummary(dataDictionaryService.getAttributeSummary(boClass, propertyName)); |
| 88 | |
|
| 89 | 0 | Integer maxLength = dataDictionaryService.getAttributeMaxLength(boClass, propertyName); |
| 90 | 0 | if (maxLength != null) { |
| 91 | 0 | attributeEntry.setAttributeMaxLength(maxLength.toString()); |
| 92 | |
} |
| 93 | |
|
| 94 | 0 | Pattern validationExpression = dataDictionaryService.getAttributeValidatingExpression(boClass, propertyName); |
| 95 | 0 | if (validationExpression != null) { |
| 96 | 0 | attributeEntry.setAttributeValidatingExpression(validationExpression.pattern()); |
| 97 | |
} |
| 98 | 0 | ControlDefinition controlDef = dataDictionaryService.getAttributeControlDefinition(boClass, propertyName); |
| 99 | 0 | if (controlDef != null) { |
| 100 | 0 | attributeEntry.setAttributeControlType(controlDef.toString()); |
| 101 | |
} |
| 102 | 0 | Class formatterClass = dataDictionaryService.getAttributeFormatter(boClass, propertyName); |
| 103 | 0 | if (formatterClass != null) { |
| 104 | 0 | attributeEntry.setAttributeFormatterClassName(formatterClass.getName()); |
| 105 | |
} |
| 106 | |
|
| 107 | |
|
| 108 | 0 | searchResults.add(attributeEntry); |
| 109 | |
} |
| 110 | |
|
| 111 | |
} |
| 112 | |
|
| 113 | |
|
| 114 | 0 | List defaultSortColumns = getDefaultSortColumns(); |
| 115 | 0 | if (defaultSortColumns.size() > 0) { |
| 116 | 0 | Collections.sort(searchResults, new BeanPropertyComparator(getDefaultSortColumns(), true)); |
| 117 | |
} |
| 118 | |
} |
| 119 | 0 | catch (ClassNotFoundException e) { |
| 120 | 0 | LOG.error("Class not found for bo search name" + e.getMessage()); |
| 121 | 0 | throw new RuntimeException("Class not found for bo search name" + e.getMessage()); |
| 122 | 0 | } |
| 123 | |
|
| 124 | 0 | return searchResults; |
| 125 | |
} |
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
@Override |
| 132 | |
public HtmlData getReturnUrl(BusinessObject bo, LookupForm lookupForm, List returnKeys, BusinessObjectRestrictions businessObjectRestrictions) { |
| 133 | 0 | return getEmptyAnchorHtmlData(); |
| 134 | |
} |
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
@Override |
| 142 | |
protected String getActionUrlHref(BusinessObject businessObject, String methodToCall, List pkNames){ |
| 143 | 0 | return KNSConstants.EMPTY_STRING; |
| 144 | |
} |
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
public List getDefaultReturnType() { |
| 150 | 0 | return new ArrayList(); |
| 151 | |
} |
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
@Override |
| 157 | |
public List getReturnKeys() { |
| 158 | 0 | return new ArrayList(); |
| 159 | |
} |
| 160 | |
} |