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