1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.util; |
17 | |
|
18 | |
import org.apache.commons.beanutils.PropertyUtils; |
19 | |
import org.apache.commons.lang.StringUtils; |
20 | |
import org.kuali.rice.core.api.encryption.EncryptionService; |
21 | |
import org.kuali.rice.core.api.services.CoreApiServiceLocator; |
22 | |
import org.kuali.rice.core.util.ClassLoaderUtils; |
23 | |
import org.kuali.rice.core.web.format.FormatException; |
24 | |
import org.kuali.rice.kew.util.KEWConstants; |
25 | |
import org.kuali.rice.kim.bo.Person; |
26 | |
import org.kuali.rice.kns.authorization.FieldRestriction; |
27 | |
import org.kuali.rice.kns.bo.BusinessObject; |
28 | |
import org.kuali.rice.kns.bo.BusinessObjectRelationship; |
29 | |
import org.kuali.rice.kns.bo.Inactivateable; |
30 | |
import org.kuali.rice.kns.bo.KualiCode; |
31 | |
import org.kuali.rice.kns.bo.PersistableBusinessObject; |
32 | |
import org.kuali.rice.kns.datadictionary.BusinessObjectEntry; |
33 | |
import org.kuali.rice.kns.datadictionary.FieldDefinition; |
34 | |
import org.kuali.rice.kns.datadictionary.MaintainableCollectionDefinition; |
35 | |
import org.kuali.rice.kns.datadictionary.control.ButtonControlDefinition; |
36 | |
import org.kuali.rice.kns.datadictionary.control.ControlDefinition; |
37 | |
import org.kuali.rice.kns.datadictionary.control.CurrencyControlDefinition; |
38 | |
import org.kuali.rice.kns.datadictionary.control.KualiUserControlDefinition; |
39 | |
import org.kuali.rice.kns.datadictionary.control.LinkControlDefinition; |
40 | |
import org.kuali.rice.kns.datadictionary.exception.UnknownBusinessClassAttributeException; |
41 | |
import org.kuali.rice.kns.datadictionary.mask.MaskFormatter; |
42 | |
import org.kuali.rice.kns.document.authorization.MaintenanceDocumentRestrictions; |
43 | |
import org.kuali.rice.kns.inquiry.Inquirable; |
44 | |
import org.kuali.rice.kns.lookup.HtmlData; |
45 | |
import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData; |
46 | |
import org.kuali.rice.kns.lookup.LookupUtils; |
47 | |
import org.kuali.rice.kns.lookup.keyvalues.IndicatorValuesFinder; |
48 | |
import org.kuali.rice.kns.lookup.keyvalues.KeyValuesFinder; |
49 | |
import org.kuali.rice.kns.lookup.keyvalues.PersistableBusinessObjectValuesFinder; |
50 | |
import org.kuali.rice.kns.lookup.valuefinder.ValueFinder; |
51 | |
import org.kuali.rice.kns.service.BusinessObjectDictionaryService; |
52 | |
import org.kuali.rice.kns.service.BusinessObjectMetaDataService; |
53 | |
import org.kuali.rice.kns.service.DataDictionaryService; |
54 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
55 | |
import org.kuali.rice.kns.service.KualiModuleService; |
56 | |
import org.kuali.rice.kns.service.ModuleService; |
57 | |
import org.kuali.rice.kns.web.ui.Field; |
58 | |
import org.kuali.rice.kns.web.ui.PropertyRenderingConfigElement; |
59 | |
import org.kuali.rice.kns.web.ui.Row; |
60 | |
import org.kuali.rice.kns.web.ui.Section; |
61 | |
|
62 | |
import java.lang.reflect.InvocationTargetException; |
63 | |
import java.security.GeneralSecurityException; |
64 | |
import java.util.ArrayList; |
65 | |
import java.util.HashMap; |
66 | |
import java.util.Iterator; |
67 | |
import java.util.List; |
68 | |
import java.util.Map; |
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
public final class FieldUtils { |
75 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(FieldUtils.class); |
76 | 0 | private static DataDictionaryService dataDictionaryService = null; |
77 | 0 | private static BusinessObjectMetaDataService businessObjectMetaDataService = null; |
78 | 0 | private static BusinessObjectDictionaryService businessObjectDictionaryService = null; |
79 | 0 | private static KualiModuleService kualiModuleService = null; |
80 | |
|
81 | 0 | private FieldUtils() { |
82 | 0 | throw new UnsupportedOperationException("do not call"); |
83 | |
} |
84 | |
|
85 | |
public static void setInquiryURL(Field field, BusinessObject bo, String propertyName) { |
86 | 0 | HtmlData inquiryHref = new AnchorHtmlData(KNSConstants.EMPTY_STRING, KNSConstants.EMPTY_STRING); |
87 | |
|
88 | 0 | Boolean b = getBusinessObjectDictionaryService().noInquiryFieldInquiry(bo.getClass(), propertyName); |
89 | 0 | if (b == null || !b.booleanValue()) { |
90 | 0 | Class<Inquirable> inquirableClass = getBusinessObjectDictionaryService().getInquirableClass(bo.getClass()); |
91 | 0 | Boolean b2 = getBusinessObjectDictionaryService().forceLookupResultFieldInquiry(bo.getClass(), propertyName); |
92 | 0 | Inquirable inq = null; |
93 | |
try { |
94 | 0 | if ( inquirableClass != null ) { |
95 | 0 | inq = inquirableClass.newInstance(); |
96 | |
} else { |
97 | 0 | inq = KNSServiceLocatorWeb.getKualiInquirable(); |
98 | 0 | if ( LOG.isDebugEnabled() ) { |
99 | 0 | LOG.debug( "Default Inquirable Class: " + inq.getClass() ); |
100 | |
} |
101 | |
} |
102 | |
|
103 | 0 | inquiryHref = inq.getInquiryUrl(bo, propertyName, null == b2 ? false : b2.booleanValue() ); |
104 | |
|
105 | 0 | } catch ( Exception ex ) { |
106 | 0 | LOG.error("unable to create inquirable to get inquiry URL", ex ); |
107 | 0 | } |
108 | |
} |
109 | |
|
110 | 0 | field.setInquiryURL(inquiryHref); |
111 | 0 | } |
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
public static void setFieldControl(Class businessObjectClass, String attributeName, boolean convertForLookup, |
126 | |
Field field) { |
127 | 0 | ControlDefinition control = getDataDictionaryService().getAttributeControlDefinition(businessObjectClass, |
128 | |
attributeName); |
129 | 0 | String fieldType = Field.TEXT; |
130 | |
|
131 | 0 | if (control != null) { |
132 | 0 | if (control.isSelect()) { |
133 | 0 | if (control.getScript() != null && control.getScript().length() > 0) { |
134 | 0 | fieldType = Field.DROPDOWN_SCRIPT; |
135 | 0 | field.setScript(control.getScript()); |
136 | |
} else { |
137 | 0 | fieldType = Field.DROPDOWN; |
138 | |
} |
139 | |
} |
140 | |
|
141 | 0 | if (control.isMultiselect()) { |
142 | 0 | fieldType = Field.MULTISELECT; |
143 | |
} |
144 | |
|
145 | 0 | if (control.isCheckbox()) { |
146 | 0 | fieldType = Field.CHECKBOX; |
147 | |
} |
148 | |
|
149 | 0 | if (control.isRadio()) { |
150 | 0 | fieldType = Field.RADIO; |
151 | |
} |
152 | |
|
153 | 0 | if (control.isHidden()) { |
154 | 0 | fieldType = Field.HIDDEN; |
155 | |
} |
156 | |
|
157 | 0 | if (control.isKualiUser()) { |
158 | 0 | fieldType = Field.KUALIUSER; |
159 | 0 | KualiUserControlDefinition kualiUserControl = (KualiUserControlDefinition) control; |
160 | 0 | field.setUniversalIdAttributeName(kualiUserControl.getUniversalIdAttributeName()); |
161 | 0 | field.setUserIdAttributeName(kualiUserControl.getUserIdAttributeName()); |
162 | 0 | field.setPersonNameAttributeName(kualiUserControl.getPersonNameAttributeName()); |
163 | |
} |
164 | |
|
165 | 0 | if (control.isWorkflowWorkgroup()) { |
166 | 0 | fieldType = Field.WORKFLOW_WORKGROUP; |
167 | |
} |
168 | |
|
169 | 0 | if (control.isFile()) { |
170 | 0 | fieldType = Field.FILE; |
171 | |
} |
172 | |
|
173 | 0 | if (control.isTextarea() && !convertForLookup) { |
174 | 0 | fieldType = Field.TEXT_AREA; |
175 | |
} |
176 | |
|
177 | 0 | if (control.isLookupHidden()) { |
178 | 0 | fieldType = Field.LOOKUP_HIDDEN; |
179 | |
} |
180 | |
|
181 | 0 | if (control.isLookupReadonly()) { |
182 | 0 | fieldType = Field.LOOKUP_READONLY; |
183 | |
} |
184 | |
|
185 | 0 | if (control.isCurrency()) { |
186 | 0 | fieldType = Field.CURRENCY; |
187 | |
} |
188 | |
|
189 | 0 | if (control.isButton()) { |
190 | 0 | fieldType = Field.BUTTON; |
191 | |
} |
192 | |
|
193 | 0 | if (control.isLink()) { |
194 | 0 | fieldType = Field.LINK; |
195 | |
} |
196 | |
|
197 | 0 | if (Field.CURRENCY.equals(fieldType) && control instanceof CurrencyControlDefinition) { |
198 | 0 | CurrencyControlDefinition currencyControl = (CurrencyControlDefinition) control; |
199 | 0 | field.setStyleClass("amount"); |
200 | 0 | field.setSize(currencyControl.getSize()); |
201 | 0 | field.setFormattedMaxLength(currencyControl.getFormattedMaxLength()); |
202 | |
} |
203 | |
|
204 | |
|
205 | 0 | if (Field.TEXT.equals(fieldType)) { |
206 | 0 | Integer size = control.getSize(); |
207 | 0 | if (size != null) { |
208 | 0 | field.setSize(size.intValue()); |
209 | |
} else { |
210 | 0 | field.setSize(30); |
211 | |
} |
212 | 0 | field.setDatePicker(control.isDatePicker()); |
213 | 0 | field.setRanged(control.isRanged()); |
214 | |
} |
215 | |
|
216 | 0 | if (Field.WORKFLOW_WORKGROUP.equals(fieldType)) { |
217 | 0 | Integer size = control.getSize(); |
218 | 0 | if (size != null) { |
219 | 0 | field.setSize(size.intValue()); |
220 | |
} else { |
221 | 0 | field.setSize(30); |
222 | |
} |
223 | |
} |
224 | |
|
225 | |
|
226 | 0 | if (Field.TEXT_AREA.equals(fieldType)) { |
227 | 0 | Integer rows = control.getRows(); |
228 | 0 | if (rows != null) { |
229 | 0 | field.setRows(rows.intValue()); |
230 | |
} else { |
231 | 0 | field.setRows(3); |
232 | |
} |
233 | |
|
234 | 0 | Integer cols = control.getCols(); |
235 | 0 | if (cols != null) { |
236 | 0 | field.setCols(cols.intValue()); |
237 | |
} else { |
238 | 0 | field.setCols(40); |
239 | |
} |
240 | 0 | field.setExpandedTextArea(control.isExpandedTextArea()); |
241 | |
} |
242 | |
|
243 | |
|
244 | 0 | if (Field.DROPDOWN.equals(fieldType) || Field.RADIO.equals(fieldType) |
245 | |
|| Field.DROPDOWN_SCRIPT.equals(fieldType) |
246 | |
|| Field.MULTISELECT.equals(fieldType)) { |
247 | 0 | String keyFinderClassName = control.getValuesFinderClass(); |
248 | |
|
249 | 0 | if (StringUtils.isNotBlank(keyFinderClassName)) { |
250 | |
try { |
251 | 0 | Class keyFinderClass = ClassLoaderUtils.getClass(keyFinderClassName); |
252 | 0 | KeyValuesFinder finder = (KeyValuesFinder) keyFinderClass.newInstance(); |
253 | |
|
254 | 0 | if (finder != null) { |
255 | 0 | if (finder instanceof PersistableBusinessObjectValuesFinder) { |
256 | 0 | ((PersistableBusinessObjectValuesFinder) finder) |
257 | |
.setBusinessObjectClass(ClassLoaderUtils.getClass(control |
258 | |
.getBusinessObjectClass())); |
259 | 0 | ((PersistableBusinessObjectValuesFinder) finder).setKeyAttributeName(control |
260 | |
.getKeyAttribute()); |
261 | 0 | ((PersistableBusinessObjectValuesFinder) finder).setLabelAttributeName(control |
262 | |
.getLabelAttribute()); |
263 | 0 | if (control.getIncludeBlankRow() != null) { |
264 | 0 | ((PersistableBusinessObjectValuesFinder) finder).setIncludeBlankRow(control |
265 | |
.getIncludeBlankRow()); |
266 | |
} |
267 | 0 | ((PersistableBusinessObjectValuesFinder) finder).setIncludeKeyInDescription(control |
268 | |
.getIncludeKeyInLabel()); |
269 | |
} |
270 | 0 | field.setFieldValidValues(finder.getKeyValues()); |
271 | 0 | field.setFieldInactiveValidValues(finder.getKeyValues(false)); |
272 | |
} |
273 | 0 | } catch (InstantiationException e) { |
274 | 0 | LOG.error("Unable to get new instance of finder class: " + keyFinderClassName); |
275 | 0 | throw new RuntimeException("Unable to get new instance of finder class: " + keyFinderClassName); |
276 | 0 | } catch (IllegalAccessException e) { |
277 | 0 | LOG.error("Unable to get new instance of finder class: " + keyFinderClassName); |
278 | 0 | throw new RuntimeException("Unable to get new instance of finder class: " + keyFinderClassName); |
279 | 0 | } |
280 | |
} |
281 | |
} |
282 | |
|
283 | 0 | if (Field.CHECKBOX.equals(fieldType) && convertForLookup) { |
284 | 0 | fieldType = Field.RADIO; |
285 | 0 | field.setFieldValidValues(IndicatorValuesFinder.INSTANCE.getKeyValues()); |
286 | |
} |
287 | |
|
288 | |
|
289 | 0 | if (Field.BUTTON.equals(fieldType)) { |
290 | 0 | ButtonControlDefinition buttonControl = (ButtonControlDefinition) control; |
291 | 0 | field.setImageSrc(buttonControl.getImageSrc()); |
292 | 0 | field.setStyleClass(buttonControl.getStyleClass()); |
293 | |
} |
294 | |
|
295 | |
|
296 | 0 | if (Field.LINK.equals(fieldType)) { |
297 | 0 | LinkControlDefinition linkControl = (LinkControlDefinition) control; |
298 | 0 | field.setStyleClass(linkControl.getStyleClass()); |
299 | 0 | field.setTarget(linkControl.getTarget()); |
300 | 0 | field.setHrefText(linkControl.getHrefText()); |
301 | |
} |
302 | |
|
303 | |
} |
304 | |
|
305 | 0 | field.setFieldType(fieldType); |
306 | 0 | } |
307 | |
|
308 | |
|
309 | |
|
310 | |
|
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
|
316 | |
|
317 | |
public static Field getPropertyField(Class businessObjectClass, String attributeName, boolean convertForLookup) { |
318 | 0 | Field field = new Field(); |
319 | 0 | field.setPropertyName(attributeName); |
320 | 0 | field.setFieldLabel(getDataDictionaryService().getAttributeLabel(businessObjectClass, attributeName)); |
321 | |
|
322 | 0 | setFieldControl(businessObjectClass, attributeName, convertForLookup, field); |
323 | |
|
324 | 0 | Boolean fieldRequired = getBusinessObjectDictionaryService().getLookupAttributeRequired(businessObjectClass, attributeName); |
325 | 0 | if (fieldRequired != null) { |
326 | 0 | field.setFieldRequired(fieldRequired.booleanValue()); |
327 | |
} |
328 | |
|
329 | 0 | Integer maxLength = getDataDictionaryService().getAttributeMaxLength(businessObjectClass, attributeName); |
330 | 0 | if (maxLength != null) { |
331 | 0 | field.setMaxLength(maxLength.intValue()); |
332 | |
} |
333 | |
|
334 | 0 | Boolean upperCase = null; |
335 | |
try { |
336 | 0 | upperCase = getDataDictionaryService().getAttributeForceUppercase(businessObjectClass, attributeName); |
337 | |
} |
338 | 0 | catch (UnknownBusinessClassAttributeException t) { |
339 | |
|
340 | 0 | LOG.warn( "UnknownBusinessClassAttributeException in fieldUtils.getPropertyField() : " + t.getMessage() ); |
341 | 0 | } |
342 | 0 | if (upperCase != null) { |
343 | 0 | field.setUpperCase(upperCase.booleanValue()); |
344 | |
} |
345 | |
|
346 | 0 | if (!businessObjectClass.isInterface()) { |
347 | |
try { |
348 | 0 | field.setFormatter(ObjectUtils.getFormatterWithDataDictionary(businessObjectClass.newInstance(), |
349 | |
attributeName)); |
350 | 0 | } catch (InstantiationException e) { |
351 | 0 | LOG.info("Unable to get new instance of business object class: " + businessObjectClass.getName(), e); |
352 | |
|
353 | 0 | } catch (IllegalAccessException e) { |
354 | 0 | LOG.info("Unable to get new instance of business object class: " + businessObjectClass.getName(), e); |
355 | |
|
356 | 0 | } |
357 | |
} |
358 | |
|
359 | |
|
360 | 0 | field.setBusinessObjectClassName(businessObjectClass.getName()); |
361 | 0 | field.setFieldHelpName(attributeName); |
362 | 0 | field.setFieldHelpSummary(getDataDictionaryService().getAttributeSummary(businessObjectClass, attributeName)); |
363 | |
|
364 | 0 | return field; |
365 | |
} |
366 | |
|
367 | |
|
368 | |
|
369 | |
|
370 | |
|
371 | |
|
372 | |
|
373 | |
|
374 | |
|
375 | |
|
376 | |
|
377 | |
|
378 | |
|
379 | |
public static void setAdditionalDisplayPropertyForCodes(Class businessObjectClass, String attributeName, PropertyRenderingConfigElement field) { |
380 | |
try { |
381 | 0 | BusinessObjectRelationship relationship = getBusinessObjectMetaDataService().getBusinessObjectRelationship( |
382 | |
(BusinessObject) businessObjectClass.newInstance(), attributeName); |
383 | |
|
384 | 0 | if (relationship != null && attributeName.startsWith(relationship.getParentAttributeName()) |
385 | |
&& KualiCode.class.isAssignableFrom(relationship.getRelatedClass())) { |
386 | 0 | field.setAdditionalDisplayPropertyName(relationship.getParentAttributeName() + "." |
387 | |
+ KNSPropertyConstants.NAME); |
388 | |
} |
389 | 0 | } catch (Exception e) { |
390 | 0 | throw new RuntimeException("Cannot get new instance of class to check for KualiCode references: " |
391 | |
+ e.getMessage()); |
392 | 0 | } |
393 | 0 | } |
394 | |
|
395 | |
|
396 | |
|
397 | |
|
398 | |
|
399 | |
|
400 | |
|
401 | |
|
402 | |
public static List wrapFields(List fields) { |
403 | 0 | return wrapFields(fields, KNSConstants.DEFAULT_NUM_OF_COLUMNS); |
404 | |
} |
405 | |
|
406 | |
|
407 | |
|
408 | |
|
409 | |
|
410 | |
|
411 | |
|
412 | |
|
413 | |
public static List<Row> wrapFields(List<Field> fields, int numberOfColumns) { |
414 | |
|
415 | 0 | List<Row> rows = new ArrayList(); |
416 | 0 | List<Field> fieldOnlyList = new ArrayList(); |
417 | |
|
418 | 0 | List<Field> visableFields = getVisibleFields(fields); |
419 | 0 | List<Field> nonVisableFields = getNonVisibleFields(fields); |
420 | |
|
421 | 0 | int fieldsPosition = 0; |
422 | 0 | for (Field element : visableFields) { |
423 | 0 | if (Field.SUB_SECTION_SEPARATOR.equals(element.getFieldType()) || Field.CONTAINER.equals(element.getFieldType())) { |
424 | 0 | fieldsPosition = createBlankSpace(fieldOnlyList, rows, numberOfColumns, fieldsPosition); |
425 | 0 | List fieldList = new ArrayList(); |
426 | 0 | fieldList.add(element); |
427 | 0 | rows.add(new Row(fieldList)); |
428 | 0 | } |
429 | |
else { |
430 | 0 | if (fieldsPosition < numberOfColumns) { |
431 | 0 | fieldOnlyList.add(element); |
432 | 0 | fieldsPosition++; |
433 | |
} |
434 | |
else { |
435 | 0 | rows.add(new Row(new ArrayList(fieldOnlyList))); |
436 | 0 | fieldOnlyList.clear(); |
437 | 0 | fieldOnlyList.add(element); |
438 | 0 | fieldsPosition = 1; |
439 | |
} |
440 | |
} |
441 | |
} |
442 | 0 | createBlankSpace(fieldOnlyList, rows, numberOfColumns, fieldsPosition); |
443 | |
|
444 | |
|
445 | 0 | if(nonVisableFields != null && !nonVisableFields.isEmpty()){ |
446 | 0 | Row nonVisRow = new Row(); |
447 | 0 | nonVisRow.setFields(nonVisableFields); |
448 | 0 | rows.add(nonVisRow); |
449 | |
} |
450 | |
|
451 | |
|
452 | 0 | return rows; |
453 | |
} |
454 | |
|
455 | |
private static List<Field> getVisibleFields(List<Field> fields){ |
456 | 0 | List<Field> rList = new ArrayList<Field>(); |
457 | |
|
458 | 0 | for(Field f: fields){ |
459 | 0 | if(!Field.HIDDEN.equals(f.getFieldType()) && !Field.BLANK_SPACE.equals(f.getFieldType())){ |
460 | 0 | rList.add(f); |
461 | |
} |
462 | |
} |
463 | |
|
464 | 0 | return rList; |
465 | |
} |
466 | |
|
467 | |
private static List<Field> getNonVisibleFields(List<Field> fields){ |
468 | 0 | List<Field> rList = new ArrayList<Field>(); |
469 | |
|
470 | 0 | for(Field f: fields){ |
471 | 0 | if(Field.HIDDEN.equals(f.getFieldType()) || Field.BLANK_SPACE.equals(f.getFieldType())){ |
472 | 0 | rList.add(f); |
473 | |
} |
474 | |
} |
475 | |
|
476 | 0 | return rList; |
477 | |
} |
478 | |
|
479 | |
|
480 | |
|
481 | |
|
482 | |
|
483 | |
|
484 | |
|
485 | |
|
486 | |
|
487 | |
private static int createBlankSpace(List<Field> fieldOnlyList, List<Row> rows, int numberOfColumns, int fieldsPosition) { |
488 | 0 | int fieldOnlySize = fieldOnlyList.size(); |
489 | 0 | if (fieldOnlySize > 0) { |
490 | 0 | for (int i = 0; i < (numberOfColumns - fieldOnlySize); i++) { |
491 | 0 | Field empty = new Field(); |
492 | 0 | empty.setFieldType(Field.BLANK_SPACE); |
493 | |
|
494 | 0 | empty.setPropertyName(Field.BLANK_SPACE); |
495 | 0 | fieldOnlyList.add(empty); |
496 | |
} |
497 | 0 | rows.add(new Row(new ArrayList(fieldOnlyList))); |
498 | 0 | fieldOnlyList.clear(); |
499 | 0 | fieldsPosition = 0; |
500 | |
} |
501 | 0 | return fieldsPosition; |
502 | |
} |
503 | |
|
504 | |
|
505 | |
|
506 | |
|
507 | |
|
508 | |
|
509 | |
|
510 | |
|
511 | |
|
512 | |
public static Field constructContainerField(String name, String label, List fields) { |
513 | 0 | return constructContainerField(name, label, fields, KNSConstants.DEFAULT_NUM_OF_COLUMNS); |
514 | |
} |
515 | |
|
516 | |
|
517 | |
|
518 | |
|
519 | |
|
520 | |
|
521 | |
|
522 | |
|
523 | |
|
524 | |
|
525 | |
public static Field constructContainerField(String name, String label, List fields, int numberOfColumns) { |
526 | 0 | Field containerField = new Field(); |
527 | 0 | containerField.setPropertyName(name); |
528 | 0 | containerField.setFieldLabel(label); |
529 | 0 | containerField.setFieldType(Field.CONTAINER); |
530 | 0 | containerField.setNumberOfColumnsForCollection(numberOfColumns); |
531 | |
|
532 | 0 | List rows = wrapFields(fields, numberOfColumns); |
533 | 0 | containerField.setContainerRows(rows); |
534 | |
|
535 | 0 | return containerField; |
536 | |
} |
537 | |
|
538 | |
|
539 | |
|
540 | |
|
541 | |
|
542 | |
|
543 | |
|
544 | |
|
545 | |
|
546 | |
public static List<Field> populateFieldsFromBusinessObject(List<Field> fields, BusinessObject bo) { |
547 | 0 | List<Field> populatedFields = new ArrayList<Field>(); |
548 | |
|
549 | 0 | if (bo instanceof PersistableBusinessObject) { |
550 | 0 | ((PersistableBusinessObject) bo).refreshNonUpdateableReferences(); |
551 | |
} |
552 | |
|
553 | 0 | for (Iterator<Field> iter = fields.iterator(); iter.hasNext();) { |
554 | 0 | Field element = iter.next(); |
555 | 0 | if (element.containsBOData()) { |
556 | 0 | String propertyName = element.getPropertyName(); |
557 | |
|
558 | |
|
559 | |
|
560 | |
|
561 | 0 | if (isPropertyNested(propertyName) && !isObjectTreeNonNullAllTheWayDown(bo, propertyName) && ((!element.getFieldType().equals(Field.IMAGE_SUBMIT)) && !(element.getFieldType().equals(Field.CONTAINER)) && (!element.getFieldType().equals(Field.QUICKFINDER)))) { |
562 | 0 | element.setPropertyValue(null); |
563 | |
} |
564 | 0 | else if (PropertyUtils.isReadable(bo, propertyName)) { |
565 | 0 | populateReadableField(element, bo); |
566 | |
} |
567 | |
|
568 | 0 | if (StringUtils.isNotBlank(element.getAlternateDisplayPropertyName())) { |
569 | 0 | String alternatePropertyValue = ObjectUtils.getFormattedPropertyValueUsingDataDictionary(bo, element |
570 | |
.getAlternateDisplayPropertyName()); |
571 | 0 | element.setAlternateDisplayPropertyValue(alternatePropertyValue); |
572 | |
} |
573 | |
|
574 | 0 | if (StringUtils.isNotBlank(element.getAdditionalDisplayPropertyName())) { |
575 | 0 | String additionalPropertyValue = ObjectUtils.getFormattedPropertyValueUsingDataDictionary(bo, element |
576 | |
.getAdditionalDisplayPropertyName()); |
577 | 0 | element.setAdditionalDisplayPropertyValue(additionalPropertyValue); |
578 | |
} |
579 | |
} |
580 | 0 | populatedFields.add(element); |
581 | 0 | } |
582 | |
|
583 | 0 | return populatedFields; |
584 | |
} |
585 | |
|
586 | |
public static void populateReadableField(Field field, BusinessObject businessObject){ |
587 | 0 | Object obj = ObjectUtils.getNestedValue(businessObject, field.getPropertyName()); |
588 | 0 | if (obj != null) { |
589 | 0 | String formattedValue = ObjectUtils.getFormattedPropertyValueUsingDataDictionary(businessObject, field.getPropertyName()); |
590 | 0 | field.setPropertyValue(formattedValue); |
591 | |
|
592 | |
|
593 | 0 | if ( field.getFieldType().equals(Field.KUALIUSER) ) { |
594 | |
|
595 | |
try { |
596 | 0 | if ( StringUtils.isNotBlank(field.getUniversalIdAttributeName()) ) { |
597 | 0 | Object principalId = ObjectUtils.getNestedValue(businessObject, field.getUniversalIdAttributeName()); |
598 | 0 | if ( principalId != null ) { |
599 | 0 | field.setUniversalIdValue(principalId.toString()); |
600 | |
} |
601 | |
} |
602 | 0 | if ( StringUtils.isNotBlank(field.getPersonNameAttributeName()) ) { |
603 | 0 | Object personName = ObjectUtils.getNestedValue(businessObject, field.getPersonNameAttributeName()); |
604 | 0 | if ( personName != null ) { |
605 | 0 | field.setPersonNameValue( personName.toString() ); |
606 | |
} |
607 | |
} |
608 | 0 | } catch ( Exception ex ) { |
609 | 0 | LOG.warn( "Unable to get principal ID or person name property in FieldBridge.", ex ); |
610 | 0 | } |
611 | |
} |
612 | |
} |
613 | |
|
614 | 0 | populateSecureField(field, obj); |
615 | 0 | } |
616 | |
|
617 | |
public static void populateSecureField(Field field, Object fieldValue){ |
618 | |
|
619 | |
|
620 | 0 | if (field.isSecure()) { |
621 | |
try { |
622 | 0 | if (fieldValue != null && fieldValue.toString().endsWith(EncryptionService.HASH_POST_PREFIX)) { |
623 | 0 | field.setEncryptedValue(fieldValue.toString()); |
624 | |
} |
625 | |
else { |
626 | 0 | field.setEncryptedValue(CoreApiServiceLocator.getEncryptionService().encrypt(fieldValue) + EncryptionService.ENCRYPTION_POST_PREFIX); |
627 | |
} |
628 | |
} |
629 | 0 | catch (GeneralSecurityException e) { |
630 | 0 | throw new RuntimeException("Unable to encrypt secure field " + e.getMessage()); |
631 | 0 | } |
632 | |
|
633 | |
} |
634 | 0 | } |
635 | |
|
636 | |
|
637 | |
|
638 | |
|
639 | |
|
640 | |
|
641 | |
|
642 | |
static private boolean isPropertyNested(String propertyName) { |
643 | 0 | return -1 != propertyName.indexOf('.'); |
644 | |
} |
645 | |
|
646 | |
|
647 | |
|
648 | |
|
649 | |
|
650 | |
|
651 | |
|
652 | |
|
653 | |
|
654 | |
static private boolean isObjectTreeNonNullAllTheWayDown(BusinessObject bo, String propertyName) { |
655 | 0 | String[] propertyParts = propertyName.split("\\."); |
656 | |
|
657 | 0 | StringBuffer property = new StringBuffer(); |
658 | 0 | for (int i = 0; i < propertyParts.length - 1; i++) { |
659 | |
|
660 | 0 | property.append((0 == property.length()) ? "" : ".").append(propertyParts[i]); |
661 | |
try { |
662 | 0 | if (null == PropertyUtils.getNestedProperty(bo, property.toString())) { |
663 | 0 | return false; |
664 | |
} |
665 | |
} |
666 | 0 | catch (Throwable t) { |
667 | 0 | LOG.debug("Either getter or setter not specified for property \"" + property.toString() + "\"", t); |
668 | 0 | return false; |
669 | 0 | } |
670 | |
} |
671 | |
|
672 | 0 | return true; |
673 | |
|
674 | |
} |
675 | |
|
676 | |
|
677 | |
|
678 | |
|
679 | |
|
680 | |
|
681 | |
private static boolean containsIntermediateNull(Object bo, String propertyName) { |
682 | 0 | boolean containsNull = false; |
683 | |
|
684 | 0 | if (StringUtils.contains(propertyName, ".")) { |
685 | 0 | String prefix = StringUtils.substringBefore(propertyName, "."); |
686 | 0 | Object propertyValue = ObjectUtils.getPropertyValue(bo, prefix); |
687 | |
|
688 | 0 | if (propertyValue == null) { |
689 | 0 | containsNull = true; |
690 | |
} |
691 | |
else { |
692 | 0 | String suffix = StringUtils.substringAfter(propertyName, "."); |
693 | 0 | containsNull = containsIntermediateNull(propertyValue, suffix); |
694 | |
} |
695 | |
} |
696 | |
|
697 | 0 | return containsNull; |
698 | |
} |
699 | |
|
700 | |
|
701 | |
|
702 | |
|
703 | |
|
704 | |
|
705 | |
|
706 | |
|
707 | |
|
708 | |
public static Map populateBusinessObjectFromMap(BusinessObject bo, Map fieldValues) { |
709 | 0 | return populateBusinessObjectFromMap(bo, fieldValues, ""); |
710 | |
} |
711 | |
|
712 | |
|
713 | |
|
714 | |
|
715 | |
|
716 | |
|
717 | |
|
718 | |
|
719 | |
|
720 | |
|
721 | |
public static Map populateBusinessObjectFromMap(BusinessObject bo, Map<String, ?> fieldValues, String propertyNamePrefix) { |
722 | 0 | Map cachedValues = new HashMap(); |
723 | 0 | MessageMap errorMap = GlobalVariables.getMessageMap(); |
724 | |
|
725 | |
try { |
726 | 0 | for (Iterator<String> iter = fieldValues.keySet().iterator(); iter.hasNext();) { |
727 | 0 | String propertyName = iter.next(); |
728 | |
|
729 | 0 | if (propertyName.endsWith(KNSConstants.CHECKBOX_PRESENT_ON_FORM_ANNOTATION)) { |
730 | |
|
731 | |
|
732 | 0 | if (StringUtils.isNotBlank((String) fieldValues.get(propertyName))) { |
733 | 0 | String checkboxName = StringUtils.removeEnd(propertyName, KNSConstants.CHECKBOX_PRESENT_ON_FORM_ANNOTATION); |
734 | 0 | String checkboxValue = (String) fieldValues.get(checkboxName); |
735 | 0 | if (checkboxValue == null) { |
736 | |
|
737 | 0 | if (PropertyUtils.isWriteable(bo, checkboxName)) { |
738 | 0 | Class type = ObjectUtils.easyGetPropertyType(bo, checkboxName); |
739 | 0 | if (type == Boolean.TYPE || type == Boolean.class) { |
740 | |
|
741 | 0 | ObjectUtils.setObjectProperty(bo, checkboxName, type, "false"); |
742 | |
} |
743 | |
} |
744 | |
} |
745 | 0 | } |
746 | |
|
747 | |
|
748 | |
} |
749 | 0 | else if (PropertyUtils.isWriteable(bo, propertyName) && fieldValues.get(propertyName) != null ) { |
750 | |
|
751 | 0 | Class type = ObjectUtils.easyGetPropertyType(bo, propertyName); |
752 | |
try { |
753 | 0 | Object fieldValue = fieldValues.get(propertyName); |
754 | 0 | ObjectUtils.setObjectProperty(bo, propertyName, type, fieldValue); |
755 | |
} |
756 | 0 | catch (FormatException e) { |
757 | 0 | cachedValues.put(propertyNamePrefix + propertyName, fieldValues.get(propertyName)); |
758 | 0 | errorMap.putError(propertyNamePrefix + propertyName, e.getErrorKey(), e.getErrorArgs()); |
759 | 0 | } |
760 | |
} |
761 | 0 | } |
762 | |
} |
763 | 0 | catch (IllegalAccessException e) { |
764 | 0 | LOG.error("unable to populate business object" + e.getMessage()); |
765 | 0 | throw new RuntimeException(e.getMessage(), e); |
766 | |
} |
767 | 0 | catch (InvocationTargetException e) { |
768 | 0 | LOG.error("unable to populate business object" + e.getMessage()); |
769 | 0 | throw new RuntimeException(e.getMessage(), e); |
770 | |
} |
771 | 0 | catch (NoSuchMethodException e) { |
772 | 0 | LOG.error("unable to populate business object" + e.getMessage()); |
773 | 0 | throw new RuntimeException(e.getMessage(), e); |
774 | 0 | } |
775 | |
|
776 | 0 | return cachedValues; |
777 | |
} |
778 | |
|
779 | |
|
780 | |
|
781 | |
|
782 | |
|
783 | |
|
784 | |
|
785 | |
|
786 | |
|
787 | |
|
788 | |
|
789 | |
public static Field fixFieldForForm(Field field, List keyFieldNames, String namePrefix, String maintenanceAction, boolean readOnly, MaintenanceDocumentRestrictions auths, String documentStatus, String documentInitiatorPrincipalId) { |
790 | 0 | String propertyName = field.getPropertyName(); |
791 | |
|
792 | 0 | if (field.containsBOData()) { |
793 | |
|
794 | |
|
795 | 0 | if (!propertyName.startsWith(KNSConstants.DISPATCH_REQUEST_PARAMETER)) { |
796 | |
|
797 | 0 | if (field.getPropertyPrefix() == null || field.getPropertyPrefix().equals("")) { |
798 | 0 | field.setPropertyName(namePrefix + propertyName); |
799 | |
} |
800 | |
else { |
801 | 0 | field.setPropertyName(field.getPropertyPrefix() + "." + propertyName); |
802 | |
} |
803 | |
} |
804 | |
|
805 | 0 | if (readOnly) { |
806 | 0 | field.setReadOnly(true); |
807 | |
} |
808 | |
|
809 | |
|
810 | 0 | if ( KNSConstants.MAINTENANCE_EDIT_ACTION.equals(maintenanceAction) ) { |
811 | 0 | if (keyFieldNames.contains(propertyName) ) { |
812 | 0 | field.setReadOnly(true); |
813 | 0 | field.setKeyField(true); |
814 | 0 | } else if ( StringUtils.isNotBlank( field.getUniversalIdAttributeName() ) |
815 | |
&& keyFieldNames.contains(field.getUniversalIdAttributeName() ) ) { |
816 | |
|
817 | |
|
818 | 0 | field.setReadOnly(true); |
819 | 0 | field.setKeyField(true); |
820 | |
} |
821 | |
} |
822 | |
|
823 | |
|
824 | 0 | applyAuthorization(field, maintenanceAction, auths, documentStatus, documentInitiatorPrincipalId); |
825 | |
|
826 | |
|
827 | 0 | if (StringUtils.isNotBlank(field.getFieldConversions())) { |
828 | 0 | String fieldConversions = field.getFieldConversions(); |
829 | 0 | String newFieldConversions = KNSConstants.EMPTY_STRING; |
830 | 0 | String[] conversions = StringUtils.split(fieldConversions, KNSConstants.FIELD_CONVERSIONS_SEPARATOR); |
831 | |
|
832 | 0 | for (int l = 0; l < conversions.length; l++) { |
833 | 0 | String conversion = conversions[l]; |
834 | |
|
835 | 0 | String[] conversionPair = StringUtils.split(conversion, KNSConstants.FIELD_CONVERSION_PAIR_SEPARATOR, 2); |
836 | 0 | String conversionFrom = conversionPair[0]; |
837 | 0 | String conversionTo = conversionPair[1]; |
838 | 0 | conversionTo = KNSConstants.MAINTENANCE_NEW_MAINTAINABLE + conversionTo; |
839 | 0 | newFieldConversions += (conversionFrom + KNSConstants.FIELD_CONVERSION_PAIR_SEPARATOR + conversionTo); |
840 | |
|
841 | 0 | if (l < conversions.length) { |
842 | 0 | newFieldConversions += KNSConstants.FIELD_CONVERSIONS_SEPARATOR; |
843 | |
} |
844 | |
} |
845 | |
|
846 | 0 | field.setFieldConversions(newFieldConversions); |
847 | |
} |
848 | |
|
849 | |
|
850 | 0 | if (StringUtils.isNotBlank(field.getInquiryParameters())) { |
851 | 0 | String inquiryParameters = field.getInquiryParameters(); |
852 | 0 | StringBuilder newInquiryParameters = new StringBuilder(); |
853 | 0 | String[] parameters = StringUtils.split(inquiryParameters, KNSConstants.FIELD_CONVERSIONS_SEPARATOR); |
854 | |
|
855 | 0 | for (int l = 0; l < parameters.length; l++) { |
856 | 0 | String parameter = parameters[l]; |
857 | |
|
858 | 0 | String[] parameterPair = StringUtils.split(parameter, KNSConstants.FIELD_CONVERSION_PAIR_SEPARATOR, 2); |
859 | 0 | String conversionFrom = parameterPair[0]; |
860 | 0 | String conversionTo = parameterPair[1]; |
861 | |
|
862 | |
|
863 | 0 | newInquiryParameters.append(KNSConstants.MAINTENANCE_NEW_MAINTAINABLE).append(conversionFrom); |
864 | |
|
865 | 0 | newInquiryParameters.append(KNSConstants.FIELD_CONVERSION_PAIR_SEPARATOR).append(conversionTo); |
866 | |
|
867 | 0 | if (l < parameters.length - 1) { |
868 | 0 | newInquiryParameters.append(KNSConstants.FIELD_CONVERSIONS_SEPARATOR); |
869 | |
} |
870 | |
} |
871 | |
|
872 | 0 | field.setInquiryParameters(newInquiryParameters.toString()); |
873 | |
} |
874 | |
|
875 | 0 | if (Field.KUALIUSER.equals(field.getFieldType())) { |
876 | |
|
877 | 0 | int suffixIndex = field.getPropertyName().indexOf( field.getUserIdAttributeName() ); |
878 | 0 | if ( suffixIndex != -1 ) { |
879 | 0 | field.setPersonNameAttributeName( field.getPropertyName().substring( 0, suffixIndex ) + field.getPersonNameAttributeName() ); |
880 | 0 | field.setUniversalIdAttributeName( field.getPropertyName().substring( 0, suffixIndex ) + field.getUniversalIdAttributeName() ); |
881 | |
} else { |
882 | 0 | field.setPersonNameAttributeName(namePrefix + field.getPersonNameAttributeName()); |
883 | 0 | field.setUniversalIdAttributeName(namePrefix + field.getUniversalIdAttributeName()); |
884 | |
} |
885 | |
|
886 | |
|
887 | |
} |
888 | |
|
889 | |
|
890 | 0 | if (StringUtils.isNotBlank(field.getLookupParameters())) { |
891 | 0 | String lookupParameters = field.getLookupParameters(); |
892 | 0 | String newLookupParameters = KNSConstants.EMPTY_STRING; |
893 | 0 | String[] conversions = StringUtils.split(lookupParameters, KNSConstants.FIELD_CONVERSIONS_SEPARATOR); |
894 | |
|
895 | 0 | for (int m = 0; m < conversions.length; m++) { |
896 | 0 | String conversion = conversions[m]; |
897 | |
|
898 | 0 | String[] conversionPair = StringUtils.split(conversion, KNSConstants.FIELD_CONVERSION_PAIR_SEPARATOR, 2); |
899 | 0 | String conversionFrom = conversionPair[0]; |
900 | 0 | String conversionTo = conversionPair[1]; |
901 | 0 | conversionFrom = KNSConstants.MAINTENANCE_NEW_MAINTAINABLE + conversionFrom; |
902 | 0 | newLookupParameters += (conversionFrom + KNSConstants.FIELD_CONVERSION_PAIR_SEPARATOR + conversionTo); |
903 | |
|
904 | 0 | if (m < conversions.length) { |
905 | 0 | newLookupParameters += KNSConstants.FIELD_CONVERSIONS_SEPARATOR; |
906 | |
} |
907 | |
} |
908 | |
|
909 | 0 | field.setLookupParameters(newLookupParameters); |
910 | |
} |
911 | |
|
912 | |
|
913 | 0 | if (Field.CONTAINER.equals(field.getFieldType())) { |
914 | 0 | List containerRows = field.getContainerRows(); |
915 | 0 | List fixedRows = new ArrayList(); |
916 | |
|
917 | 0 | for (Iterator iter = containerRows.iterator(); iter.hasNext();) { |
918 | 0 | Row containerRow = (Row) iter.next(); |
919 | 0 | List containerFields = containerRow.getFields(); |
920 | 0 | List fixedFields = new ArrayList(); |
921 | |
|
922 | 0 | for (Iterator iterator = containerFields.iterator(); iterator.hasNext();) { |
923 | 0 | Field containerField = (Field) iterator.next(); |
924 | 0 | containerField = fixFieldForForm(containerField, keyFieldNames, namePrefix, maintenanceAction, readOnly, auths, documentStatus, documentInitiatorPrincipalId); |
925 | 0 | fixedFields.add(containerField); |
926 | 0 | } |
927 | |
|
928 | 0 | fixedRows.add(new Row(fixedFields)); |
929 | 0 | } |
930 | |
|
931 | 0 | field.setContainerRows(fixedRows); |
932 | |
} |
933 | |
} |
934 | 0 | return field; |
935 | |
} |
936 | |
|
937 | |
public static void applyAuthorization(Field field, String maintenanceAction, MaintenanceDocumentRestrictions auths, String documentStatus, String documentInitiatorPrincipalId) { |
938 | 0 | String fieldName = ""; |
939 | 0 | FieldRestriction fieldAuth = null; |
940 | 0 | Person user = GlobalVariables.getUserSession().getPerson(); |
941 | |
|
942 | 0 | if (field.getPropertyName().startsWith(KNSConstants.MAINTENANCE_NEW_MAINTAINABLE)) { |
943 | |
|
944 | 0 | fieldName = field.getPropertyName().substring(KNSConstants.MAINTENANCE_NEW_MAINTAINABLE.length()); |
945 | |
|
946 | |
|
947 | 0 | if (auths.hasRestriction(fieldName)) { |
948 | 0 | fieldAuth = auths.getFieldRestriction(fieldName); |
949 | 0 | if(KNSConstants.MAINTENANCE_NEW_ACTION.equals(maintenanceAction) || KNSConstants.MAINTENANCE_COPY_ACTION.equals(maintenanceAction)){ |
950 | 0 | if((KEWConstants.ROUTE_HEADER_SAVED_CD.equals(documentStatus) || KEWConstants.ROUTE_HEADER_INITIATED_CD.equals(documentStatus)) |
951 | |
&& user.getPrincipalId().equals(documentInitiatorPrincipalId)){ |
952 | |
|
953 | |
|
954 | |
}else{ |
955 | 0 | if(fieldAuth.isPartiallyMasked()){ |
956 | 0 | field.setSecure(true); |
957 | 0 | fieldAuth.setShouldBeEncrypted(true); |
958 | 0 | MaskFormatter maskFormatter = fieldAuth.getMaskFormatter(); |
959 | 0 | String displayMaskValue = maskFormatter.maskValue(field.getPropertyValue()); |
960 | 0 | field.setDisplayMaskValue(displayMaskValue); |
961 | 0 | populateSecureField(field, field.getPropertyValue()); |
962 | 0 | } |
963 | 0 | else if(fieldAuth.isMasked()){ |
964 | 0 | field.setSecure(true); |
965 | 0 | fieldAuth.setShouldBeEncrypted(true); |
966 | 0 | MaskFormatter maskFormatter = fieldAuth.getMaskFormatter(); |
967 | 0 | String displayMaskValue = maskFormatter.maskValue(field.getPropertyValue()); |
968 | 0 | field.setDisplayMaskValue(displayMaskValue); |
969 | 0 | populateSecureField(field, field.getPropertyValue()); |
970 | |
} |
971 | |
} |
972 | |
} |
973 | |
|
974 | 0 | if (KNSConstants.MAINTENANCE_EDIT_ACTION.equals(maintenanceAction) || KNSConstants.MAINTENANCE_NEWWITHEXISTING_ACTION.equals(maintenanceAction)) { |
975 | |
|
976 | 0 | if(fieldAuth.isPartiallyMasked()){ |
977 | 0 | field.setSecure(true); |
978 | 0 | fieldAuth.setShouldBeEncrypted(true); |
979 | 0 | MaskFormatter maskFormatter = fieldAuth.getMaskFormatter(); |
980 | 0 | String displayMaskValue = maskFormatter.maskValue(field.getPropertyValue()); |
981 | 0 | field.setDisplayMaskValue(displayMaskValue); |
982 | 0 | populateSecureField(field, field.getPropertyValue()); |
983 | 0 | } |
984 | 0 | else if(fieldAuth.isMasked()){ |
985 | 0 | field.setSecure(true); |
986 | 0 | fieldAuth.setShouldBeEncrypted(true); |
987 | 0 | MaskFormatter maskFormatter = fieldAuth.getMaskFormatter(); |
988 | 0 | String displayMaskValue = maskFormatter.maskValue(field.getPropertyValue()); |
989 | 0 | field.setDisplayMaskValue(displayMaskValue); |
990 | 0 | populateSecureField(field, field.getPropertyValue()); |
991 | |
} |
992 | |
} |
993 | |
|
994 | 0 | if (Field.isInputField(field.getFieldType()) || field.getFieldType().equalsIgnoreCase(Field.CHECKBOX)) { |
995 | |
|
996 | |
|
997 | 0 | if (fieldAuth.isReadOnly()) { |
998 | 0 | if (!field.isReadOnly() && !fieldAuth.isMasked() && !fieldAuth.isPartiallyMasked()) { |
999 | 0 | field.setReadOnly(true); |
1000 | |
} |
1001 | |
} |
1002 | 0 | else if (fieldAuth.isHidden()) { |
1003 | 0 | if (field.getFieldType() != Field.HIDDEN) { |
1004 | 0 | field.setFieldType(Field.HIDDEN); |
1005 | |
} |
1006 | |
} |
1007 | |
} |
1008 | |
|
1009 | 0 | if(Field.BUTTON.equalsIgnoreCase(field.getFieldType()) && fieldAuth.isHidden()){ |
1010 | 0 | field.setFieldType(Field.HIDDEN); |
1011 | |
} |
1012 | |
|
1013 | |
|
1014 | |
|
1015 | 0 | if (field.isReadOnly() && fieldAuth.isHidden()) { |
1016 | 0 | field.setFieldType(Field.HIDDEN); |
1017 | |
} |
1018 | |
|
1019 | |
} |
1020 | |
|
1021 | |
|
1022 | |
} |
1023 | 0 | else if (field.getPropertyName().startsWith(KNSConstants.MAINTENANCE_OLD_MAINTAINABLE)) { |
1024 | |
|
1025 | 0 | fieldName = field.getPropertyName().substring(KNSConstants.MAINTENANCE_OLD_MAINTAINABLE.length()); |
1026 | |
|
1027 | 0 | if (auths.hasRestriction(fieldName)) { |
1028 | 0 | fieldAuth = auths.getFieldRestriction(fieldName); |
1029 | 0 | if(fieldAuth.isPartiallyMasked()){ |
1030 | 0 | field.setSecure(true); |
1031 | 0 | MaskFormatter maskFormatter = fieldAuth.getMaskFormatter(); |
1032 | 0 | String displayMaskValue = maskFormatter.maskValue(field.getPropertyValue()); |
1033 | 0 | field.setDisplayMaskValue(displayMaskValue); |
1034 | 0 | field.setPropertyValue(displayMaskValue); |
1035 | 0 | populateSecureField(field, field.getPropertyValue()); |
1036 | |
|
1037 | |
} |
1038 | |
|
1039 | 0 | if(fieldAuth.isMasked()){ |
1040 | 0 | field.setSecure(true); |
1041 | 0 | MaskFormatter maskFormatter = fieldAuth.getMaskFormatter(); |
1042 | 0 | String displayMaskValue = maskFormatter.maskValue(field.getPropertyValue()); |
1043 | 0 | field.setDisplayMaskValue(displayMaskValue); |
1044 | 0 | field.setPropertyValue(displayMaskValue); |
1045 | 0 | populateSecureField(field, field.getPropertyValue()); |
1046 | |
} |
1047 | |
|
1048 | 0 | if (fieldAuth.isHidden()) { |
1049 | 0 | field.setFieldType(Field.HIDDEN); |
1050 | |
} |
1051 | |
} |
1052 | |
} |
1053 | 0 | } |
1054 | |
|
1055 | |
|
1056 | |
|
1057 | |
|
1058 | |
|
1059 | |
|
1060 | |
|
1061 | |
|
1062 | |
|
1063 | |
|
1064 | |
|
1065 | |
public static List meshSections(List oldSections, List newSections, List keyFieldNames, String maintenanceAction, boolean readOnly, MaintenanceDocumentRestrictions auths, String documentStatus, String documentInitiatorPrincipalId) { |
1066 | 0 | List meshedSections = new ArrayList(); |
1067 | |
|
1068 | 0 | for (int i = 0; i < newSections.size(); i++) { |
1069 | 0 | Section maintSection = (Section) newSections.get(i); |
1070 | 0 | List sectionRows = maintSection.getRows(); |
1071 | 0 | Section oldMaintSection = (Section) oldSections.get(i); |
1072 | 0 | List oldSectionRows = oldMaintSection.getRows(); |
1073 | 0 | List<Row> meshedRows = new ArrayList(); |
1074 | 0 | meshedRows = meshRows(oldSectionRows, sectionRows, keyFieldNames, maintenanceAction, readOnly, auths, documentStatus, documentInitiatorPrincipalId); |
1075 | 0 | maintSection.setRows(meshedRows); |
1076 | 0 | if (StringUtils.isBlank(maintSection.getErrorKey())) { |
1077 | 0 | maintSection.setErrorKey(MaintenanceUtils.generateErrorKeyForSection(maintSection)); |
1078 | |
} |
1079 | 0 | meshedSections.add(maintSection); |
1080 | |
} |
1081 | |
|
1082 | 0 | return meshedSections; |
1083 | |
} |
1084 | |
|
1085 | |
|
1086 | |
|
1087 | |
|
1088 | |
|
1089 | |
|
1090 | |
|
1091 | |
|
1092 | |
|
1093 | |
|
1094 | |
|
1095 | |
public static List meshRows(List oldRows, List newRows, List keyFieldNames, String maintenanceAction, boolean readOnly, MaintenanceDocumentRestrictions auths, String documentStatus, String documentInitiatorPrincipalId) { |
1096 | 0 | List<Row> meshedRows = new ArrayList<Row>(); |
1097 | |
|
1098 | 0 | for (int j = 0; j < newRows.size(); j++) { |
1099 | 0 | Row sectionRow = (Row) newRows.get(j); |
1100 | 0 | List rowFields = sectionRow.getFields(); |
1101 | 0 | Row oldSectionRow = null; |
1102 | 0 | List oldRowFields = new ArrayList(); |
1103 | |
|
1104 | 0 | if (null != oldRows && oldRows.size() > j) { |
1105 | 0 | oldSectionRow = (Row) oldRows.get(j); |
1106 | 0 | oldRowFields = oldSectionRow.getFields(); |
1107 | |
} |
1108 | |
|
1109 | 0 | List meshedFields = meshFields(oldRowFields, rowFields, keyFieldNames, maintenanceAction, readOnly, auths, documentStatus, documentInitiatorPrincipalId); |
1110 | 0 | if (meshedFields.size() > 0) { |
1111 | 0 | Row meshedRow = new Row(meshedFields); |
1112 | 0 | if (sectionRow.isHidden()) { |
1113 | 0 | meshedRow.setHidden(true); |
1114 | |
} |
1115 | |
|
1116 | 0 | meshedRows.add(meshedRow); |
1117 | |
} |
1118 | |
} |
1119 | |
|
1120 | 0 | return meshedRows; |
1121 | |
} |
1122 | |
|
1123 | |
|
1124 | |
|
1125 | |
|
1126 | |
|
1127 | |
|
1128 | |
|
1129 | |
|
1130 | |
|
1131 | |
|
1132 | |
|
1133 | |
|
1134 | |
public static List meshFields(List oldFields, List newFields, List keyFieldNames, String maintenanceAction, boolean readOnly, MaintenanceDocumentRestrictions auths, String documentStatus, String documentInitiatorPrincipalId) { |
1135 | 0 | List meshedFields = new ArrayList(); |
1136 | |
|
1137 | 0 | List newFieldsToMerge = new ArrayList(); |
1138 | 0 | List oldFieldsToMerge = new ArrayList(); |
1139 | |
|
1140 | 0 | for (int k = 0; k < newFields.size(); k++) { |
1141 | 0 | Field newMaintField = (Field) newFields.get(k); |
1142 | 0 | String propertyName = newMaintField.getPropertyName(); |
1143 | |
|
1144 | 0 | if (Field.IMAGE_SUBMIT.equals(newMaintField.getFieldType())) { |
1145 | 0 | meshedFields.add(newMaintField); |
1146 | |
} |
1147 | 0 | else if (Field.CONTAINER.equals(newMaintField.getFieldType())) { |
1148 | 0 | if (oldFields.size() > k) { |
1149 | 0 | Field oldMaintField = (Field) oldFields.get(k); |
1150 | 0 | newMaintField = meshContainerFields(oldMaintField, newMaintField, keyFieldNames, maintenanceAction, readOnly, auths, documentStatus, documentInitiatorPrincipalId); |
1151 | 0 | } |
1152 | |
else { |
1153 | 0 | newMaintField = meshContainerFields(newMaintField, newMaintField, keyFieldNames, maintenanceAction, readOnly, auths, documentStatus, documentInitiatorPrincipalId); |
1154 | |
} |
1155 | 0 | meshedFields.add(newMaintField); |
1156 | |
} |
1157 | |
else { |
1158 | 0 | newMaintField = FieldUtils.fixFieldForForm(newMaintField, keyFieldNames, KNSConstants.MAINTENANCE_NEW_MAINTAINABLE, maintenanceAction, readOnly, auths, documentStatus, documentInitiatorPrincipalId); |
1159 | |
|
1160 | 0 | if (KNSConstants.MAINTENANCE_EDIT_ACTION.equals(maintenanceAction) || KNSConstants.MAINTENANCE_COPY_ACTION.equals(maintenanceAction)) { |
1161 | 0 | Field oldMaintField = (Field) oldFields.get(k); |
1162 | |
|
1163 | |
|
1164 | |
|
1165 | 0 | if (!StringUtils.equalsIgnoreCase(newMaintField.getPropertyValue(), oldMaintField.getPropertyValue()) |
1166 | |
&& !Field.HIDDEN.equals(newMaintField.getFieldType())) { |
1167 | 0 | newMaintField.setHighlightField(true); |
1168 | |
} |
1169 | |
|
1170 | 0 | oldMaintField = FieldUtils.fixFieldForForm(oldMaintField, keyFieldNames, KNSConstants.MAINTENANCE_OLD_MAINTAINABLE, maintenanceAction, true, auths, documentStatus, documentInitiatorPrincipalId); |
1171 | 0 | oldFieldsToMerge.add(oldMaintField); |
1172 | |
} |
1173 | |
|
1174 | 0 | newFieldsToMerge.add(newMaintField); |
1175 | |
|
1176 | 0 | for (Iterator iter = oldFieldsToMerge.iterator(); iter.hasNext();) { |
1177 | 0 | Field element = (Field) iter.next(); |
1178 | 0 | meshedFields.add(element); |
1179 | 0 | } |
1180 | |
|
1181 | 0 | for (Iterator iter = newFieldsToMerge.iterator(); iter.hasNext();) { |
1182 | 0 | Field element = (Field) iter.next(); |
1183 | 0 | meshedFields.add(element); |
1184 | 0 | } |
1185 | |
} |
1186 | |
} |
1187 | 0 | return meshedFields; |
1188 | |
} |
1189 | |
|
1190 | |
|
1191 | |
|
1192 | |
|
1193 | |
|
1194 | |
|
1195 | |
|
1196 | |
|
1197 | |
|
1198 | |
|
1199 | |
|
1200 | |
|
1201 | |
|
1202 | |
protected static boolean isLookupFieldLevelHelpEnabled(Class businessObjectClass, String attributeName) { |
1203 | 0 | return false; |
1204 | |
} |
1205 | |
|
1206 | |
|
1207 | |
|
1208 | |
|
1209 | |
|
1210 | |
|
1211 | |
|
1212 | |
|
1213 | |
|
1214 | |
|
1215 | |
|
1216 | |
|
1217 | |
|
1218 | |
protected static boolean isLookupFieldLevelHelpDisabled(Class businessObjectClass, String attributeName) { |
1219 | 0 | return false; |
1220 | |
} |
1221 | |
|
1222 | |
public static List createAndPopulateFieldsForLookup(List<String> lookupFieldAttributeList, List<String> readOnlyFieldsList, Class businessObjectClass) throws InstantiationException, IllegalAccessException { |
1223 | 0 | List<Field> fields = new ArrayList<Field>(); |
1224 | 0 | BusinessObjectEntry boe = getDataDictionaryService().getDataDictionary().getBusinessObjectEntry(businessObjectClass.getName()); |
1225 | |
|
1226 | 0 | Map<String, Boolean> isHiddenMap = new HashMap<String, Boolean>(); |
1227 | 0 | Map<String, Boolean> isReadOnlyMap = new HashMap<String, Boolean>(); |
1228 | |
|
1229 | |
|
1230 | |
|
1231 | |
|
1232 | |
|
1233 | 0 | if(boe.hasLookupDefinition()){ |
1234 | 0 | List<FieldDefinition> fieldDefs = boe.getLookupDefinition().getLookupFields(); |
1235 | 0 | for(FieldDefinition field : fieldDefs){ |
1236 | 0 | isReadOnlyMap.put(field.getAttributeName(), Boolean.valueOf(field.isReadOnly())); |
1237 | 0 | isHiddenMap.put(field.getAttributeName(), Boolean.valueOf(field.isHidden())); |
1238 | |
} |
1239 | |
} |
1240 | |
|
1241 | 0 | for( String attributeName : lookupFieldAttributeList ) |
1242 | |
{ |
1243 | 0 | Field field = FieldUtils.getPropertyField(businessObjectClass, attributeName, true); |
1244 | |
|
1245 | 0 | if(field.isDatePicker() && field.isRanged()) { |
1246 | |
|
1247 | 0 | Field newDate = createRangeDateField(field); |
1248 | 0 | fields.add(newDate); |
1249 | |
} |
1250 | |
|
1251 | |
BusinessObject newBusinessObjectInstance; |
1252 | 0 | if (ExternalizableBusinessObjectUtils.isExternalizableBusinessObjectInterface(businessObjectClass)) { |
1253 | 0 | ModuleService moduleService = getKualiModuleService().getResponsibleModuleService(businessObjectClass); |
1254 | 0 | newBusinessObjectInstance = (BusinessObject) moduleService.createNewObjectFromExternalizableClass(businessObjectClass); |
1255 | 0 | } |
1256 | |
else { |
1257 | 0 | newBusinessObjectInstance = (BusinessObject) businessObjectClass.newInstance(); |
1258 | |
} |
1259 | |
|
1260 | 0 | field = LookupUtils.setFieldQuickfinder(newBusinessObjectInstance, attributeName, field, lookupFieldAttributeList); |
1261 | 0 | field = LookupUtils.setFieldDirectInquiry(newBusinessObjectInstance, attributeName, field); |
1262 | |
|
1263 | |
|
1264 | 0 | if (!Field.MULTISELECT.equals(field.getFieldType())) { |
1265 | 0 | field.setMaxLength(100); |
1266 | |
} |
1267 | |
|
1268 | |
|
1269 | 0 | if (attributeName.equals(KNSPropertyConstants.ACTIVE) && Inactivateable.class.isAssignableFrom(businessObjectClass)) { |
1270 | 0 | field.setPropertyValue(KNSConstants.YES_INDICATOR_VALUE); |
1271 | 0 | field.setDefaultValue(KNSConstants.YES_INDICATOR_VALUE); |
1272 | |
} |
1273 | |
|
1274 | 0 | String defaultValue = getBusinessObjectMetaDataService().getLookupFieldDefaultValue(businessObjectClass, attributeName); |
1275 | 0 | if (defaultValue != null) { |
1276 | 0 | field.setPropertyValue(defaultValue); |
1277 | 0 | field.setDefaultValue(defaultValue); |
1278 | |
} |
1279 | |
|
1280 | 0 | Class defaultValueFinderClass = getBusinessObjectMetaDataService().getLookupFieldDefaultValueFinderClass(businessObjectClass, attributeName); |
1281 | |
|
1282 | 0 | if (defaultValueFinderClass != null) { |
1283 | 0 | field.setPropertyValue(((ValueFinder) defaultValueFinderClass.newInstance()).getValue()); |
1284 | 0 | field.setDefaultValue(((ValueFinder) defaultValueFinderClass.newInstance()).getValue()); |
1285 | |
} |
1286 | 0 | if ( (readOnlyFieldsList != null && readOnlyFieldsList.contains(field.getPropertyName())) |
1287 | |
|| ( isReadOnlyMap.containsKey(field.getPropertyName()) && isReadOnlyMap.get(field.getPropertyName()).booleanValue()) |
1288 | |
) { |
1289 | 0 | field.setReadOnly(true); |
1290 | |
} |
1291 | |
|
1292 | 0 | populateQuickfinderDefaultsForLookup(businessObjectClass, attributeName, field); |
1293 | |
|
1294 | 0 | if ((isHiddenMap.containsKey(field.getPropertyName()) && isHiddenMap.get(field.getPropertyName()).booleanValue())) { |
1295 | 0 | field.setFieldType(Field.HIDDEN); |
1296 | |
} |
1297 | |
|
1298 | 0 | boolean triggerOnChange = getBusinessObjectDictionaryService().isLookupFieldTriggerOnChange(businessObjectClass, attributeName); |
1299 | 0 | field.setTriggerOnChange(triggerOnChange); |
1300 | |
|
1301 | 0 | field.setFieldLevelHelpEnabled(isLookupFieldLevelHelpEnabled(businessObjectClass, attributeName)); |
1302 | 0 | field.setFieldLevelHelpDisabled(isLookupFieldLevelHelpDisabled(businessObjectClass, attributeName)); |
1303 | |
|
1304 | 0 | fields.add(field); |
1305 | 0 | } |
1306 | 0 | return fields; |
1307 | |
} |
1308 | |
|
1309 | |
|
1310 | |
|
1311 | |
|
1312 | |
|
1313 | |
|
1314 | |
|
1315 | |
|
1316 | |
|
1317 | |
|
1318 | |
|
1319 | |
private static void populateQuickfinderDefaultsForLookup( |
1320 | |
Class businessObjectClass, String attributeName, Field field) |
1321 | |
throws InstantiationException, IllegalAccessException { |
1322 | |
|
1323 | 0 | String quickfinderParamString = getBusinessObjectMetaDataService().getLookupFieldQuickfinderParameterString(businessObjectClass, attributeName); |
1324 | 0 | Class<? extends ValueFinder> quickfinderParameterFinderClass = |
1325 | |
getBusinessObjectMetaDataService().getLookupFieldQuickfinderParameterStringBuilderClass(businessObjectClass, attributeName); |
1326 | 0 | if (quickfinderParameterFinderClass != null) { |
1327 | 0 | quickfinderParamString = quickfinderParameterFinderClass.newInstance().getValue(); |
1328 | |
} |
1329 | |
|
1330 | 0 | if (!StringUtils.isEmpty(quickfinderParamString)) { |
1331 | 0 | String [] params = quickfinderParamString.split(","); |
1332 | 0 | if (params != null) for (String param : params) { |
1333 | 0 | if (param.contains(KNSConstants.LOOKUP_PARAMETER_LITERAL_DELIMITER)) { |
1334 | 0 | String[] paramChunks = param.split(KNSConstants.LOOKUP_PARAMETER_LITERAL_DELIMITER, 2); |
1335 | 0 | field.appendLookupParameters( |
1336 | |
KNSConstants.LOOKUP_PARAMETER_LITERAL_PREFIX+KNSConstants.LOOKUP_PARAMETER_LITERAL_DELIMITER+ |
1337 | |
paramChunks[1]+":"+paramChunks[0]); |
1338 | |
} |
1339 | |
} |
1340 | |
} |
1341 | 0 | } |
1342 | |
|
1343 | |
|
1344 | |
|
1345 | |
|
1346 | |
|
1347 | |
|
1348 | |
|
1349 | |
public static Field createRangeDateField(Field field) { |
1350 | 0 | Field newDate = (Field)ObjectUtils.deepCopy(field); |
1351 | 0 | newDate.setFieldLabel(newDate.getFieldLabel()+" "+KNSConstants.LOOKUP_DEFAULT_RANGE_SEARCH_LOWER_BOUND_LABEL); |
1352 | 0 | field.setFieldLabel(field.getFieldLabel()+" "+KNSConstants.LOOKUP_DEFAULT_RANGE_SEARCH_UPPER_BOUND_LABEL); |
1353 | 0 | newDate.setPropertyName(KNSConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX+newDate.getPropertyName()); |
1354 | 0 | return newDate; |
1355 | |
} |
1356 | |
|
1357 | |
private static Field meshContainerFields(Field oldMaintField, Field newMaintField, List keyFieldNames, String maintenanceAction, boolean readOnly, MaintenanceDocumentRestrictions auths, String documentStatus, String documentInitiatorPrincipalId) { |
1358 | 0 | List resultingRows = new ArrayList(); |
1359 | 0 | resultingRows.addAll(meshRows(oldMaintField.getContainerRows(), newMaintField.getContainerRows(), keyFieldNames, maintenanceAction, readOnly, auths, documentStatus, documentInitiatorPrincipalId)); |
1360 | 0 | Field resultingField = newMaintField; |
1361 | 0 | resultingField.setFieldType(Field.CONTAINER); |
1362 | |
|
1363 | |
|
1364 | 0 | resultingField.setContainerElementName(newMaintField.getContainerElementName()); |
1365 | 0 | resultingField.setContainerDisplayFields(newMaintField.getContainerDisplayFields()); |
1366 | 0 | resultingField.setNumberOfColumnsForCollection(newMaintField.getNumberOfColumnsForCollection()); |
1367 | |
|
1368 | 0 | resultingField.setContainerRows(resultingRows); |
1369 | 0 | List resultingRowsList = newMaintField.getContainerRows(); |
1370 | 0 | if (resultingRowsList.size() > 0) { |
1371 | 0 | List resultingFieldsList = ((Row) resultingRowsList.get(0)).getFields(); |
1372 | 0 | if (resultingFieldsList.size() > 0) { |
1373 | |
|
1374 | |
|
1375 | 0 | String containedFieldName = ((Field) (resultingFieldsList.get(0))).getPropertyName(); |
1376 | 0 | resultingField.setPropertyName(containedFieldName.substring(0, containedFieldName.lastIndexOf('.'))); |
1377 | |
} |
1378 | 0 | } |
1379 | |
else { |
1380 | 0 | resultingField.setPropertyName(oldMaintField.getPropertyName()); |
1381 | |
} |
1382 | 0 | return resultingField; |
1383 | |
} |
1384 | |
|
1385 | |
|
1386 | |
|
1387 | |
|
1388 | |
|
1389 | |
|
1390 | |
|
1391 | |
|
1392 | |
static final public void modifyFieldToSupportMultipleValueLookups(Field field, String parents, MaintainableCollectionDefinition definition) { |
1393 | 0 | field.setMultipleValueLookedUpCollectionName(parents + definition.getName()); |
1394 | 0 | field.setMultipleValueLookupClassName(definition.getSourceClassName().getName()); |
1395 | 0 | field.setMultipleValueLookupClassLabel(getDataDictionaryService().getDataDictionary().getBusinessObjectEntry(definition.getSourceClassName().getName()).getObjectLabel()); |
1396 | 0 | } |
1397 | |
|
1398 | |
|
1399 | |
|
1400 | |
|
1401 | |
|
1402 | |
|
1403 | |
|
1404 | |
|
1405 | |
static final public boolean isCollectionMultipleLookupEnabled(MaintainableCollectionDefinition definition) { |
1406 | 0 | return definition.getSourceClassName() != null && definition.isIncludeMultipleLookupLine(); |
1407 | |
} |
1408 | |
|
1409 | |
|
1410 | |
|
1411 | |
|
1412 | |
|
1413 | |
|
1414 | |
|
1415 | |
|
1416 | |
public static String scrubWhitespace(String s) { |
1417 | 0 | return s.replaceAll("(\\s)(\\s+)", " "); |
1418 | |
} |
1419 | |
|
1420 | |
private static DataDictionaryService getDataDictionaryService() { |
1421 | 0 | if (dataDictionaryService == null) { |
1422 | 0 | dataDictionaryService = KNSServiceLocatorWeb.getDataDictionaryService(); |
1423 | |
} |
1424 | 0 | return dataDictionaryService; |
1425 | |
} |
1426 | |
|
1427 | |
private static BusinessObjectMetaDataService getBusinessObjectMetaDataService() { |
1428 | 0 | if (businessObjectMetaDataService == null) { |
1429 | 0 | businessObjectMetaDataService = KNSServiceLocatorWeb.getBusinessObjectMetaDataService(); |
1430 | |
} |
1431 | 0 | return businessObjectMetaDataService; |
1432 | |
} |
1433 | |
|
1434 | |
private static BusinessObjectDictionaryService getBusinessObjectDictionaryService() { |
1435 | 0 | if (businessObjectDictionaryService == null) { |
1436 | 0 | businessObjectDictionaryService = KNSServiceLocatorWeb.getBusinessObjectDictionaryService(); |
1437 | |
} |
1438 | 0 | return businessObjectDictionaryService; |
1439 | |
} |
1440 | |
|
1441 | |
private static KualiModuleService getKualiModuleService() { |
1442 | 0 | if (kualiModuleService == null) { |
1443 | 0 | kualiModuleService = KNSServiceLocatorWeb.getKualiModuleService(); |
1444 | |
} |
1445 | 0 | return kualiModuleService; |
1446 | |
} |
1447 | |
} |