| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.krad.uif.widget; |
| 17 | |
|
| 18 | |
import java.security.GeneralSecurityException; |
| 19 | |
import java.util.HashMap; |
| 20 | |
import java.util.List; |
| 21 | |
import java.util.Map; |
| 22 | |
import java.util.Map.Entry; |
| 23 | |
import java.util.Properties; |
| 24 | |
|
| 25 | |
import org.apache.commons.lang.StringUtils; |
| 26 | |
import org.kuali.rice.core.api.CoreApiServiceLocator; |
| 27 | |
import org.kuali.rice.core.web.format.Formatter; |
| 28 | |
import org.kuali.rice.krad.service.KRADServiceLocator; |
| 29 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb; |
| 30 | |
import org.kuali.rice.krad.uif.UifConstants; |
| 31 | |
import org.kuali.rice.krad.uif.UifParameters; |
| 32 | |
import org.kuali.rice.krad.uif.container.View; |
| 33 | |
import org.kuali.rice.krad.uif.core.Component; |
| 34 | |
import org.kuali.rice.krad.uif.field.AttributeField; |
| 35 | |
import org.kuali.rice.krad.uif.field.LinkField; |
| 36 | |
import org.kuali.rice.krad.uif.util.LookupInquiryUtils; |
| 37 | |
import org.kuali.rice.krad.uif.util.ObjectPropertyUtils; |
| 38 | |
import org.kuali.rice.krad.uif.util.ViewModelUtils; |
| 39 | |
import org.kuali.rice.krad.util.UrlFactory; |
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
public class Inquiry extends WidgetBase { |
| 47 | |
private static final long serialVersionUID = -2154388007867302901L; |
| 48 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(Inquiry.class); |
| 49 | |
|
| 50 | |
public static final String INQUIRY_TITLE_PREFIX = "title.inquiry.url.value.prependtext"; |
| 51 | |
|
| 52 | |
private String baseInquiryUrl; |
| 53 | |
|
| 54 | |
private String dataObjectClassName; |
| 55 | |
private String viewName; |
| 56 | |
|
| 57 | |
private Map<String, String> inquiryParameters; |
| 58 | |
|
| 59 | |
private boolean forceInquiry; |
| 60 | |
|
| 61 | |
private LinkField inquiryLinkField; |
| 62 | |
|
| 63 | |
public Inquiry() { |
| 64 | 0 | super(); |
| 65 | |
|
| 66 | 0 | forceInquiry = false; |
| 67 | 0 | inquiryParameters = new HashMap<String, String>(); |
| 68 | 0 | } |
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
@Override |
| 75 | |
public void performFinalize(View view, Object model, Component parent) { |
| 76 | 0 | super.performFinalize(view, model, parent); |
| 77 | |
|
| 78 | |
|
| 79 | 0 | if (!isRender() || !isReadOnly()) { |
| 80 | 0 | return; |
| 81 | |
} |
| 82 | |
|
| 83 | |
|
| 84 | 0 | setRender(false); |
| 85 | |
|
| 86 | 0 | AttributeField field = (AttributeField) parent; |
| 87 | |
|
| 88 | |
|
| 89 | 0 | Object propertyValue = ObjectPropertyUtils.getPropertyValue(model, field.getBindingInfo().getBindingPath()); |
| 90 | 0 | if ((propertyValue == null) || StringUtils.isBlank(propertyValue.toString())) { |
| 91 | 0 | return; |
| 92 | |
} |
| 93 | |
|
| 94 | 0 | setupLink(view, model, field); |
| 95 | 0 | } |
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
public void setupLink(View view, Object model, AttributeField field) { |
| 110 | |
|
| 111 | 0 | Object parentObject = ViewModelUtils.getParentObjectForMetadata(view, model, field); |
| 112 | 0 | String propertyName = field.getBindingInfo().getBindingName(); |
| 113 | |
|
| 114 | |
|
| 115 | 0 | if (StringUtils.isNotBlank(getDataObjectClassName()) && (getInquiryParameters() != null) && !getInquiryParameters().isEmpty()) { |
| 116 | 0 | Class<?> inquiryObjectClass = null; |
| 117 | |
try { |
| 118 | 0 | inquiryObjectClass = Class.forName(getDataObjectClassName()); |
| 119 | |
} |
| 120 | 0 | catch (ClassNotFoundException e) { |
| 121 | 0 | LOG.error("Unable to get class for: " + getDataObjectClassName()); |
| 122 | 0 | throw new RuntimeException(e); |
| 123 | 0 | } |
| 124 | |
|
| 125 | 0 | buildInquiryLink(parentObject, propertyName, inquiryObjectClass, getInquiryParameters()); |
| 126 | 0 | } |
| 127 | |
|
| 128 | |
else { |
| 129 | 0 | view.getViewHelperService().buildInquiryLink(parentObject, propertyName, this); |
| 130 | |
} |
| 131 | 0 | } |
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
public void buildInquiryLink(Object dataObject, String propertyName, Class<?> inquiryObjectClass, |
| 147 | |
Map<String, String> inquiryParms) { |
| 148 | 0 | Properties urlParameters = new Properties(); |
| 149 | |
|
| 150 | 0 | urlParameters.put(UifParameters.DATA_OBJECT_CLASS_NAME, inquiryObjectClass.getName()); |
| 151 | 0 | urlParameters.put(UifParameters.METHOD_TO_CALL, UifConstants.MethodToCallNames.START); |
| 152 | |
|
| 153 | 0 | for (Entry<String, String> inquiryParameter : inquiryParms.entrySet()) { |
| 154 | 0 | String parameterName = inquiryParameter.getKey(); |
| 155 | |
|
| 156 | 0 | Object parameterValue = ObjectPropertyUtils.getPropertyValue(dataObject, parameterName); |
| 157 | |
|
| 158 | |
|
| 159 | 0 | if (parameterValue == null) { |
| 160 | 0 | parameterValue = ""; |
| 161 | |
} |
| 162 | 0 | else if (parameterValue instanceof java.sql.Date) { |
| 163 | 0 | if (Formatter.findFormatter(parameterValue.getClass()) != null) { |
| 164 | 0 | Formatter formatter = Formatter.getFormatter(parameterValue.getClass()); |
| 165 | 0 | parameterValue = formatter.format(parameterValue); |
| 166 | 0 | } |
| 167 | |
} |
| 168 | |
else { |
| 169 | 0 | parameterValue = parameterValue.toString(); |
| 170 | |
} |
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
|
| 175 | |
|
| 176 | 0 | if (KRADServiceLocatorWeb.getBusinessObjectAuthorizationService() |
| 177 | |
.attributeValueNeedsToBeEncryptedOnFormsAndLinks(inquiryObjectClass, inquiryParameter.getValue())) { |
| 178 | |
try { |
| 179 | 0 | parameterValue = CoreApiServiceLocator.getEncryptionService().encrypt(parameterValue); |
| 180 | |
} |
| 181 | 0 | catch (GeneralSecurityException e) { |
| 182 | 0 | LOG.error("Exception while trying to encrypted value for inquiry framework.", e); |
| 183 | 0 | throw new RuntimeException(e); |
| 184 | 0 | } |
| 185 | |
} |
| 186 | |
|
| 187 | |
|
| 188 | 0 | urlParameters.put(inquiryParameter.getValue(), parameterValue); |
| 189 | 0 | } |
| 190 | |
|
| 191 | 0 | String inquiryUrl = UrlFactory.parameterizeUrl(getBaseInquiryUrl(), urlParameters); |
| 192 | 0 | getInquiryLinkField().setHrefText(inquiryUrl); |
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | 0 | Object fieldValue = ObjectPropertyUtils.getPropertyValue(dataObject, propertyName); |
| 198 | 0 | if (fieldValue != null) { |
| 199 | 0 | getInquiryLinkField().setLinkLabel(fieldValue.toString()); |
| 200 | |
} |
| 201 | |
|
| 202 | |
|
| 203 | 0 | String linkTitle = createTitleText(inquiryObjectClass); |
| 204 | 0 | linkTitle = LookupInquiryUtils.getTitleText(linkTitle, inquiryObjectClass, getInquiryParameters()); |
| 205 | 0 | getInquiryLinkField().setTitle(linkTitle); |
| 206 | |
|
| 207 | 0 | setRender(true); |
| 208 | 0 | } |
| 209 | |
|
| 210 | |
|
| 211 | |
|
| 212 | |
|
| 213 | |
|
| 214 | |
|
| 215 | |
|
| 216 | |
|
| 217 | |
public String createTitleText(Class<?> dataObjectClass) { |
| 218 | 0 | String titleText = ""; |
| 219 | |
|
| 220 | 0 | String titlePrefixProp = KRADServiceLocator.getKualiConfigurationService().getPropertyString( |
| 221 | |
INQUIRY_TITLE_PREFIX); |
| 222 | 0 | if (StringUtils.isNotBlank(titlePrefixProp)) { |
| 223 | 0 | titleText += titlePrefixProp + " "; |
| 224 | |
} |
| 225 | |
|
| 226 | 0 | String objectLabel = KRADServiceLocatorWeb.getDataDictionaryService().getDataDictionary() |
| 227 | |
.getDataObjectEntry(dataObjectClass.getName()).getObjectLabel(); |
| 228 | 0 | if (StringUtils.isNotBlank(objectLabel)) { |
| 229 | 0 | titleText += objectLabel + " "; |
| 230 | |
} |
| 231 | |
|
| 232 | 0 | return titleText; |
| 233 | |
} |
| 234 | |
|
| 235 | |
|
| 236 | |
|
| 237 | |
|
| 238 | |
@Override |
| 239 | |
public List<Component> getNestedComponents() { |
| 240 | 0 | List<Component> components = super.getNestedComponents(); |
| 241 | |
|
| 242 | 0 | components.add(getInquiryLinkField()); |
| 243 | |
|
| 244 | 0 | return components; |
| 245 | |
} |
| 246 | |
|
| 247 | |
public String getBaseInquiryUrl() { |
| 248 | 0 | return this.baseInquiryUrl; |
| 249 | |
} |
| 250 | |
|
| 251 | |
public void setBaseInquiryUrl(String baseInquiryUrl) { |
| 252 | 0 | this.baseInquiryUrl = baseInquiryUrl; |
| 253 | 0 | } |
| 254 | |
|
| 255 | |
public String getDataObjectClassName() { |
| 256 | 0 | return this.dataObjectClassName; |
| 257 | |
} |
| 258 | |
|
| 259 | |
public void setDataObjectClassName(String dataObjectClassName) { |
| 260 | 0 | this.dataObjectClassName = dataObjectClassName; |
| 261 | 0 | } |
| 262 | |
|
| 263 | |
public String getViewName() { |
| 264 | 0 | return this.viewName; |
| 265 | |
} |
| 266 | |
|
| 267 | |
public void setViewName(String viewName) { |
| 268 | 0 | this.viewName = viewName; |
| 269 | 0 | } |
| 270 | |
|
| 271 | |
public boolean isForceInquiry() { |
| 272 | 0 | return this.forceInquiry; |
| 273 | |
} |
| 274 | |
|
| 275 | |
public void setForceInquiry(boolean forceInquiry) { |
| 276 | 0 | this.forceInquiry = forceInquiry; |
| 277 | 0 | } |
| 278 | |
|
| 279 | |
public Map<String, String> getInquiryParameters() { |
| 280 | 0 | return this.inquiryParameters; |
| 281 | |
} |
| 282 | |
|
| 283 | |
public void setInquiryParameters(Map<String, String> inquiryParameters) { |
| 284 | 0 | this.inquiryParameters = inquiryParameters; |
| 285 | 0 | } |
| 286 | |
|
| 287 | |
public LinkField getInquiryLinkField() { |
| 288 | 0 | return this.inquiryLinkField; |
| 289 | |
} |
| 290 | |
|
| 291 | |
public void setInquiryLinkField(LinkField inquiryLinkField) { |
| 292 | 0 | this.inquiryLinkField = inquiryLinkField; |
| 293 | 0 | } |
| 294 | |
|
| 295 | |
} |