| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.krad.web.form; |
| 17 | |
|
| 18 | |
import org.apache.commons.lang.StringUtils; |
| 19 | |
import org.kuali.rice.krad.lookup.LookupUtils; |
| 20 | |
import org.kuali.rice.krad.lookup.Lookupable; |
| 21 | |
import org.kuali.rice.krad.uif.UifConstants.ViewType; |
| 22 | |
import org.kuali.rice.krad.uif.view.LookupView; |
| 23 | |
import org.kuali.rice.krad.uif.service.ViewHelperService; |
| 24 | |
import org.kuali.rice.krad.util.KRADConstants; |
| 25 | |
import org.kuali.rice.krad.util.KRADUtils; |
| 26 | |
|
| 27 | |
import javax.servlet.http.HttpServletRequest; |
| 28 | |
import java.util.ArrayList; |
| 29 | |
import java.util.Collection; |
| 30 | |
import java.util.HashMap; |
| 31 | |
import java.util.List; |
| 32 | |
import java.util.Map; |
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
public class LookupForm extends UifFormBase { |
| 40 | |
private static final long serialVersionUID = -7323484966538685327L; |
| 41 | |
|
| 42 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LookupForm.class); |
| 43 | |
|
| 44 | |
private String dataObjectClassName; |
| 45 | |
private String docNum; |
| 46 | |
private String referencesToRefresh; |
| 47 | |
|
| 48 | |
private boolean multipleValuesSelect; |
| 49 | |
private String lookupCollectionName; |
| 50 | |
|
| 51 | |
private Map<String, String> criteriaFields; |
| 52 | |
private Map<String, String> fieldConversions; |
| 53 | |
|
| 54 | |
private boolean atLeastOneRowReturnable; |
| 55 | |
private boolean atLeastOneRowHasActions; |
| 56 | |
|
| 57 | |
private Collection<?> searchResults; |
| 58 | |
|
| 59 | |
public LookupForm() { |
| 60 | 0 | super(); |
| 61 | |
|
| 62 | 0 | setViewTypeName(ViewType.LOOKUP); |
| 63 | 0 | atLeastOneRowReturnable = false; |
| 64 | 0 | atLeastOneRowHasActions = false; |
| 65 | 0 | multipleValuesSelect = false; |
| 66 | |
|
| 67 | 0 | criteriaFields = new HashMap<String, String>(); |
| 68 | 0 | fieldConversions = new HashMap<String, String>(); |
| 69 | 0 | } |
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
@Override |
| 76 | |
public void postBind(HttpServletRequest request) { |
| 77 | 0 | super.postBind(request); |
| 78 | |
|
| 79 | |
try { |
| 80 | 0 | Lookupable lookupable = getLookupable(); |
| 81 | 0 | if (lookupable == null) { |
| 82 | 0 | LOG.error("Lookupable not found for view id " + getView().getId()); |
| 83 | 0 | throw new RuntimeException("Lookupable not found for view id " + getView().getId()); |
| 84 | |
} |
| 85 | |
|
| 86 | 0 | if (StringUtils.isBlank(getDataObjectClassName())) { |
| 87 | 0 | setDataObjectClassName(((LookupView) getView()).getDataObjectClassName().getName()); |
| 88 | |
} |
| 89 | |
|
| 90 | |
|
| 91 | 0 | Class<?> dataObjectClass = Class.forName(getDataObjectClassName()); |
| 92 | 0 | lookupable.setDataObjectClass(dataObjectClass); |
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | 0 | if (!((LookupView) getView()).isShowMaintenanceLinks()) { |
| 97 | |
|
| 98 | 0 | if (StringUtils.contains(getReturnLocation(), "/" + KRADConstants.PORTAL_ACTION) || |
| 99 | |
StringUtils.contains(getReturnLocation(), "/index.html")) { |
| 100 | 0 | ((LookupView) getView()).setShowMaintenanceLinks(true); |
| 101 | |
} |
| 102 | |
} |
| 103 | |
|
| 104 | |
|
| 105 | 0 | lookupable.setReadOnlyFieldsList(getReadOnlyFieldsList()); |
| 106 | |
|
| 107 | |
|
| 108 | 0 | if (request.getParameter(KRADConstants.CONVERSION_FIELDS_PARAMETER) != null) { |
| 109 | 0 | String conversionFields = request.getParameter(KRADConstants.CONVERSION_FIELDS_PARAMETER); |
| 110 | 0 | setFieldConversions(KRADUtils.convertStringParameterToMap(conversionFields)); |
| 111 | 0 | lookupable.setFieldConversions(getFieldConversions()); |
| 112 | |
} |
| 113 | |
|
| 114 | |
|
| 115 | 0 | Map<String, String> fieldValues = new HashMap<String, String>(); |
| 116 | 0 | Map<String, String> formFields = getCriteriaFields(); |
| 117 | |
|
| 118 | 0 | if (formFields != null) { |
| 119 | 0 | for (Map.Entry<String, String> entry : formFields.entrySet()) { |
| 120 | |
|
| 121 | 0 | fieldValues.put(entry.getKey(), |
| 122 | |
LookupUtils.forceUppercase(dataObjectClass, entry.getKey(), entry.getValue())); |
| 123 | |
} |
| 124 | |
} |
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | 0 | if (StringUtils.isNotBlank(getDocNum())) { |
| 129 | 0 | fieldValues.put(KRADConstants.DOC_NUM, getDocNum()); |
| 130 | |
} |
| 131 | |
|
| 132 | 0 | this.setCriteriaFields(fieldValues); |
| 133 | 0 | } catch (ClassNotFoundException e) { |
| 134 | 0 | LOG.error("Object class " + getDataObjectClassName() + " not found"); |
| 135 | 0 | throw new RuntimeException("Object class " + getDataObjectClassName() + " not found", e); |
| 136 | 0 | } |
| 137 | 0 | } |
| 138 | |
|
| 139 | |
public Lookupable getLookupable() { |
| 140 | 0 | ViewHelperService viewHelperService = getView().getViewHelperService(); |
| 141 | 0 | if (viewHelperService == null) { |
| 142 | 0 | LOG.error("ViewHelperService is null."); |
| 143 | 0 | throw new RuntimeException("ViewHelperService is null."); |
| 144 | |
} |
| 145 | |
|
| 146 | 0 | if (!Lookupable.class.isAssignableFrom(viewHelperService.getClass())) { |
| 147 | 0 | LOG.error("ViewHelperService class '" + viewHelperService.getClass().getName() + |
| 148 | |
"' is not assignable from '" + Lookupable.class + "'"); |
| 149 | 0 | throw new RuntimeException("ViewHelperService class '" + viewHelperService.getClass().getName() + |
| 150 | |
"' is not assignable from '" + Lookupable.class + "'"); |
| 151 | |
} |
| 152 | |
|
| 153 | 0 | return (Lookupable) viewHelperService; |
| 154 | |
} |
| 155 | |
|
| 156 | |
protected Boolean processBooleanParameter(String parameterValue) { |
| 157 | 0 | if (StringUtils.isNotBlank(parameterValue)) { |
| 158 | 0 | if ("YES".equals(parameterValue.toUpperCase())) { |
| 159 | 0 | return Boolean.TRUE; |
| 160 | |
} |
| 161 | 0 | return new Boolean(parameterValue); |
| 162 | |
} |
| 163 | 0 | return null; |
| 164 | |
} |
| 165 | |
|
| 166 | |
public String getDataObjectClassName() { |
| 167 | 0 | return this.dataObjectClassName; |
| 168 | |
} |
| 169 | |
|
| 170 | |
public void setDataObjectClassName(String dataObjectClassName) { |
| 171 | 0 | this.dataObjectClassName = dataObjectClassName; |
| 172 | 0 | } |
| 173 | |
|
| 174 | |
public String getDocNum() { |
| 175 | 0 | return this.docNum; |
| 176 | |
} |
| 177 | |
|
| 178 | |
public void setDocNum(String docNum) { |
| 179 | 0 | this.docNum = docNum; |
| 180 | 0 | } |
| 181 | |
|
| 182 | |
public String getReferencesToRefresh() { |
| 183 | 0 | return referencesToRefresh; |
| 184 | |
} |
| 185 | |
|
| 186 | |
public void setReferencesToRefresh(String referencesToRefresh) { |
| 187 | 0 | this.referencesToRefresh = referencesToRefresh; |
| 188 | 0 | } |
| 189 | |
|
| 190 | |
|
| 191 | |
|
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
|
| 199 | |
|
| 200 | |
public boolean isMultipleValuesSelect() { |
| 201 | 0 | return multipleValuesSelect; |
| 202 | |
} |
| 203 | |
|
| 204 | |
|
| 205 | |
|
| 206 | |
|
| 207 | |
|
| 208 | |
|
| 209 | |
public void setMultipleValuesSelect(boolean multipleValuesSelect) { |
| 210 | 0 | this.multipleValuesSelect = multipleValuesSelect; |
| 211 | 0 | } |
| 212 | |
|
| 213 | |
|
| 214 | |
|
| 215 | |
|
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | |
public String getLookupCollectionName() { |
| 220 | 0 | return lookupCollectionName; |
| 221 | |
} |
| 222 | |
|
| 223 | |
|
| 224 | |
|
| 225 | |
|
| 226 | |
|
| 227 | |
|
| 228 | |
public void setLookupCollectionName(String lookupCollectionName) { |
| 229 | 0 | this.lookupCollectionName = lookupCollectionName; |
| 230 | 0 | } |
| 231 | |
|
| 232 | |
public Map<String, String> getCriteriaFields() { |
| 233 | 0 | return this.criteriaFields; |
| 234 | |
} |
| 235 | |
|
| 236 | |
public void setCriteriaFields(Map<String, String> criteriaFields) { |
| 237 | 0 | this.criteriaFields = criteriaFields; |
| 238 | 0 | } |
| 239 | |
|
| 240 | |
public Map<String, String> getFieldConversions() { |
| 241 | 0 | return this.fieldConversions; |
| 242 | |
} |
| 243 | |
|
| 244 | |
public void setFieldConversions(Map<String, String> fieldConversions) { |
| 245 | 0 | this.fieldConversions = fieldConversions; |
| 246 | 0 | } |
| 247 | |
|
| 248 | |
public Collection<?> getSearchResults() { |
| 249 | 0 | return this.searchResults; |
| 250 | |
} |
| 251 | |
|
| 252 | |
public void setSearchResults(Collection<?> searchResults) { |
| 253 | 0 | this.searchResults = searchResults; |
| 254 | 0 | } |
| 255 | |
|
| 256 | |
public boolean isAtLeastOneRowReturnable() { |
| 257 | 0 | return atLeastOneRowReturnable; |
| 258 | |
} |
| 259 | |
|
| 260 | |
public void setAtLeastOneRowReturnable(boolean atLeastOneRowReturnable) { |
| 261 | 0 | this.atLeastOneRowReturnable = atLeastOneRowReturnable; |
| 262 | 0 | } |
| 263 | |
|
| 264 | |
public boolean isAtLeastOneRowHasActions() { |
| 265 | 0 | return atLeastOneRowHasActions; |
| 266 | |
} |
| 267 | |
|
| 268 | |
public void setAtLeastOneRowHasActions(boolean atLeastOneRowHasActions) { |
| 269 | 0 | this.atLeastOneRowHasActions = atLeastOneRowHasActions; |
| 270 | 0 | } |
| 271 | |
} |