1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.lookup; |
17 | |
|
18 | |
import org.apache.commons.collections.CollectionUtils; |
19 | |
import org.apache.commons.lang.StringUtils; |
20 | |
import org.kuali.rice.core.api.criteria.Predicate; |
21 | |
import org.kuali.rice.core.api.criteria.QueryByCriteria; |
22 | |
import org.kuali.rice.core.util.ClassLoaderUtils; |
23 | |
import org.kuali.rice.core.util.ConcreteKeyValue; |
24 | |
import org.kuali.rice.core.util.KeyValue; |
25 | |
import org.kuali.rice.core.web.format.BooleanFormatter; |
26 | |
import org.kuali.rice.core.web.format.CollectionFormatter; |
27 | |
import org.kuali.rice.core.web.format.DateFormatter; |
28 | |
import org.kuali.rice.core.web.format.Formatter; |
29 | |
import org.kuali.rice.kew.util.KEWConstants; |
30 | |
import org.kuali.rice.kim.api.group.Group; |
31 | |
import org.kuali.rice.kim.api.group.GroupQueryResults; |
32 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
33 | |
import org.kuali.rice.kim.api.type.KimType; |
34 | |
import org.kuali.rice.kim.api.type.KimTypeService; |
35 | |
import org.kuali.rice.kim.bo.Person; |
36 | |
import org.kuali.rice.kim.bo.types.dto.AttributeDefinitionMap; |
37 | |
import org.kuali.rice.kim.impl.group.GroupBo; |
38 | |
import org.kuali.rice.kim.impl.type.KimTypeLookupableHelperServiceImpl; |
39 | |
import org.kuali.rice.kim.service.KIMServiceLocatorWeb; |
40 | |
import org.kuali.rice.kim.util.KIMPropertyConstants; |
41 | |
import org.kuali.rice.kim.util.KimCommonUtilsInternal; |
42 | |
import org.kuali.rice.kim.util.KimConstants; |
43 | |
import org.kuali.rice.kns.document.authorization.BusinessObjectRestrictions; |
44 | |
import org.kuali.rice.kns.lookup.HtmlData; |
45 | |
import org.kuali.rice.kns.web.comparator.CellComparatorHelper; |
46 | |
import org.kuali.rice.kns.web.struts.form.LookupForm; |
47 | |
import org.kuali.rice.kns.web.ui.Column; |
48 | |
import org.kuali.rice.kns.web.ui.Field; |
49 | |
import org.kuali.rice.kns.web.ui.ResultRow; |
50 | |
import org.kuali.rice.kns.web.ui.Row; |
51 | |
import org.kuali.rice.krad.bo.BusinessObject; |
52 | |
import org.kuali.rice.krad.bo.PersistableBusinessObject; |
53 | |
import org.kuali.rice.krad.datadictionary.AttributeDefinition; |
54 | |
import org.kuali.rice.krad.datadictionary.KimAttributeDefinition; |
55 | |
import org.kuali.rice.krad.keyvalues.IndicatorValuesFinder; |
56 | |
import org.kuali.rice.krad.keyvalues.KeyValuesFinder; |
57 | |
import org.kuali.rice.krad.keyvalues.KimAttributeValuesFinder; |
58 | |
import org.kuali.rice.krad.util.GlobalVariables; |
59 | |
import org.kuali.rice.krad.util.KRADConstants; |
60 | |
import org.kuali.rice.krad.util.ObjectUtils; |
61 | |
import org.kuali.rice.krad.util.UrlFactory; |
62 | |
|
63 | |
import java.sql.Date; |
64 | |
import java.sql.Timestamp; |
65 | |
import java.util.ArrayList; |
66 | |
import java.util.Calendar; |
67 | |
import java.util.Collection; |
68 | |
import java.util.Collections; |
69 | |
import java.util.Comparator; |
70 | |
import java.util.HashMap; |
71 | |
import java.util.Iterator; |
72 | |
import java.util.List; |
73 | |
import java.util.Map; |
74 | |
import java.util.Properties; |
75 | |
|
76 | |
import static org.kuali.rice.core.api.criteria.PredicateFactory.*; |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | 0 | public class GroupLookupableHelperServiceImpl extends KimLookupableHelperServiceImpl { |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | 0 | private static String KIM_TYPE_ID_PROPERTY_NAME = "kimTypeId"; |
90 | 0 | private List<Row> grpRows = new ArrayList<Row>(); |
91 | 0 | private List<Row> attrRows = new ArrayList<Row>(); |
92 | 0 | private String typeId = ""; |
93 | |
private AttributeDefinitionMap attrDefinitions; |
94 | 0 | private Map<String, String> groupTypeValuesCache = new HashMap<String, String>(); |
95 | |
|
96 | |
@Override |
97 | |
public List<HtmlData> getCustomActionUrls(BusinessObject bo, List pkNames) { |
98 | 0 | GroupBo groupImpl = (GroupBo) bo; |
99 | 0 | List<HtmlData> anchorHtmlDataList = new ArrayList<HtmlData>(); |
100 | 0 | if(allowsNewOrCopyAction(KimConstants.KimUIConstants.KIM_GROUP_DOCUMENT_TYPE_NAME)){ |
101 | 0 | anchorHtmlDataList.add(getEditGroupUrl(groupImpl)); |
102 | |
} |
103 | 0 | return anchorHtmlDataList; |
104 | |
} |
105 | |
|
106 | |
protected HtmlData getEditGroupUrl(GroupBo groupBo) { |
107 | 0 | String href = ""; |
108 | |
|
109 | 0 | Properties parameters = new Properties(); |
110 | 0 | parameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.DOC_HANDLER_METHOD); |
111 | 0 | parameters.put(KRADConstants.PARAMETER_COMMAND, KEWConstants.INITIATE_COMMAND); |
112 | 0 | parameters.put(KRADConstants.DOCUMENT_TYPE_NAME, KimConstants.KimUIConstants.KIM_GROUP_DOCUMENT_TYPE_NAME); |
113 | 0 | parameters.put(KimConstants.PrimaryKeyConstants.GROUP_ID, groupBo.getId()); |
114 | 0 | if (StringUtils.isNotBlank(getReturnLocation())) { |
115 | 0 | parameters.put(KRADConstants.RETURN_LOCATION_PARAMETER, getReturnLocation()); |
116 | |
} |
117 | 0 | href = UrlFactory.parameterizeUrl(KimCommonUtilsInternal.getKimBasePath()+KimConstants.KimUIConstants.KIM_GROUP_DOCUMENT_ACTION, parameters); |
118 | |
|
119 | 0 | HtmlData.AnchorHtmlData anchorHtmlData = new HtmlData.AnchorHtmlData(href, |
120 | |
KRADConstants.DOC_HANDLER_METHOD, KRADConstants.MAINTENANCE_EDIT_METHOD_TO_CALL); |
121 | 0 | return anchorHtmlData; |
122 | |
} |
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
@Override |
131 | |
public List<GroupBo> getSearchResults(java.util.Map<String,String> fieldValues) { |
132 | 0 | QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create(); |
133 | 0 | Map<String, String> criteriaMap = new HashMap<String, String>(fieldValues); |
134 | 0 | criteriaMap.remove(KRADConstants.BACK_LOCATION); |
135 | 0 | criteriaMap.remove(KRADConstants.DOC_FORM_KEY); |
136 | 0 | if (!criteriaMap.isEmpty()) { |
137 | 0 | List<Predicate> predicates = new ArrayList<Predicate>(); |
138 | 0 | for (String key : criteriaMap.keySet()) { |
139 | 0 | if (StringUtils.isNotEmpty(criteriaMap.get(key))) { |
140 | 0 | if (key.equals("principalName")) { |
141 | |
|
142 | 0 | Timestamp currentTime = new Timestamp(Calendar.getInstance().getTimeInMillis()); |
143 | 0 | String principalId = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(criteriaMap.get(key)).getPrincipalId(); |
144 | 0 | predicates.add( |
145 | |
and( |
146 | |
equal("members.memberId", principalId), |
147 | |
equal("members.typeCode", KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE), |
148 | |
and( |
149 | |
or(isNull(KIMPropertyConstants.KimMember.ACTIVE_FROM_DATE), greaterThanOrEqual(KIMPropertyConstants.KimMember.ACTIVE_FROM_DATE, currentTime)), |
150 | |
or(isNull(KIMPropertyConstants.KimMember.ACTIVE_TO_DATE), lessThan(KIMPropertyConstants.KimMember.ACTIVE_TO_DATE, currentTime)) |
151 | |
) |
152 | |
)); |
153 | 0 | } else { |
154 | 0 | predicates.add(like(key, criteriaMap.get(key))); |
155 | |
} |
156 | |
} |
157 | |
} |
158 | 0 | if (!predicates.isEmpty()) { |
159 | 0 | criteria.setPredicates(and(predicates.toArray(new Predicate[] {}))); |
160 | |
} |
161 | |
} |
162 | |
|
163 | 0 | GroupQueryResults groupResults = KimApiServiceLocator.getGroupService().findGroups(criteria.build()); |
164 | 0 | List<Group> groups = groupResults.getResults(); |
165 | |
|
166 | |
|
167 | 0 | List<GroupBo> groupBos = new ArrayList<GroupBo>(groups.size()); |
168 | 0 | for (Group group : groups) { |
169 | 0 | groupBos.add(GroupBo.from(group)); |
170 | |
} |
171 | |
|
172 | |
|
173 | 0 | return groupBos; |
174 | |
} |
175 | |
|
176 | |
@Override |
177 | |
public boolean checkForAdditionalFields(Map fieldValues) { |
178 | 0 | List<Row> attributeRows = setupAttributeRows(fieldValues); |
179 | 0 | if (attributeRows.isEmpty()) { |
180 | 0 | setAttrRows(attributeRows); |
181 | 0 | } else if (CollectionUtils.isEmpty(getAttrRows())) { |
182 | 0 | setAttrRows(attributeRows); |
183 | |
} |
184 | 0 | if (getAttrRows().size() > 0) { |
185 | 0 | return true; |
186 | |
} |
187 | 0 | return false; |
188 | |
} |
189 | |
|
190 | |
|
191 | |
@Override |
192 | |
public List<Row> getRows() { |
193 | 0 | if (getGrpRows().isEmpty()) { |
194 | 0 | List<Row> rows = super.getRows(); |
195 | 0 | List<Row> returnRows = new ArrayList<Row>(); |
196 | 0 | for (Row row : rows) { |
197 | 0 | for (int i = row.getFields().size() - 1; i >= 0; i--) { |
198 | 0 | Field field = row.getFields().get(i); |
199 | 0 | if (field.getPropertyName().equals(KIM_TYPE_ID_PROPERTY_NAME)) { |
200 | 0 | Field typeField = new Field(); |
201 | 0 | typeField.setFieldLabel("Type"); |
202 | 0 | typeField.setPropertyName(KIM_TYPE_ID_PROPERTY_NAME); |
203 | 0 | typeField.setFieldValidValues(getGroupTypeOptions()); |
204 | 0 | typeField.setFieldType(Field.DROPDOWN); |
205 | 0 | row.getFields().set(i, typeField); |
206 | |
} |
207 | |
} |
208 | 0 | returnRows.add(row); |
209 | |
} |
210 | |
|
211 | 0 | Field typeField = new Field(); |
212 | 0 | typeField.setFieldLabel("Principal Name"); |
213 | 0 | typeField.setPropertyName(KIMPropertyConstants.Person.PRINCIPAL_NAME); |
214 | 0 | typeField.setFieldType(Field.TEXT); |
215 | 0 | typeField.setMaxLength(40); |
216 | 0 | typeField.setSize(20); |
217 | 0 | typeField.setQuickFinderClassNameImpl("org.kuali.rice.kim.bo.Person"); |
218 | 0 | typeField.setFieldConversions( "principalName:principalName" ); |
219 | 0 | typeField.setLookupParameters( "principalName:principalName" ); |
220 | |
|
221 | |
|
222 | |
|
223 | 0 | List<Field> fields = (returnRows.isEmpty()) ? new ArrayList<Field>() : returnRows.get(returnRows.size() - 1).getFields(); |
224 | 0 | if (!fields.isEmpty() && fields.get(fields.size() - 1).getFieldType().equals(Field.BLANK_SPACE)) { |
225 | |
|
226 | 0 | int insertLoc = fields.size() - 1; |
227 | 0 | while (insertLoc >= 0 && fields.get(insertLoc).getFieldType().equals(Field.BLANK_SPACE)) { |
228 | 0 | insertLoc--; |
229 | |
} |
230 | 0 | fields.set(insertLoc + 1, typeField); |
231 | 0 | returnRows.get(returnRows.size() - 1).setFields(fields); |
232 | 0 | } else { |
233 | |
|
234 | 0 | int fieldLen = fields.size(); |
235 | 0 | fields = new ArrayList<Field>(); |
236 | 0 | fields.add(typeField); |
237 | 0 | for (int i = 1; i < fieldLen; i++) { |
238 | 0 | Field blankSpace = new Field(); |
239 | 0 | blankSpace.setFieldType(Field.BLANK_SPACE); |
240 | 0 | blankSpace.setPropertyName(Field.BLANK_SPACE); |
241 | 0 | fields.add(blankSpace); |
242 | |
} |
243 | 0 | returnRows.add(new Row(fields)); |
244 | |
} |
245 | |
|
246 | 0 | setGrpRows(returnRows); |
247 | |
} |
248 | 0 | if (getAttrRows().isEmpty()) { |
249 | 0 | setAttrDefinitions(new AttributeDefinitionMap()); |
250 | 0 | return getGrpRows(); |
251 | |
} |
252 | 0 | List<Row> fullRows = new ArrayList<Row>(); |
253 | 0 | fullRows.addAll(getGrpRows()); |
254 | 0 | fullRows.addAll(getAttrRows()); |
255 | 0 | return fullRows; |
256 | |
} |
257 | |
|
258 | |
|
259 | |
@Override |
260 | |
public List<Column> getColumns() { |
261 | 0 | List<Column> columns = super.getColumns(); |
262 | 0 | for (Row row : attrRows) { |
263 | 0 | for (Field field : row.getFields()) { |
264 | 0 | Column newColumn = new Column(); |
265 | 0 | newColumn.setColumnTitle(field.getFieldLabel()); |
266 | 0 | newColumn.setMaxLength(getColumnMaxLength(field.getPropertyName())); |
267 | 0 | newColumn.setPropertyName(field.getPropertyName()); |
268 | 0 | newColumn.setFormatter(field.getFormatter()); |
269 | 0 | columns.add(newColumn); |
270 | 0 | } |
271 | |
} |
272 | 0 | return columns; |
273 | |
} |
274 | |
|
275 | |
@Override |
276 | |
public Collection performLookup(LookupForm lookupForm, Collection resultTable, boolean bounded) { |
277 | 0 | setBackLocation((String) lookupForm.getFieldsForLookup().get(KRADConstants.BACK_LOCATION)); |
278 | 0 | setDocFormKey((String) lookupForm.getFieldsForLookup().get(KRADConstants.DOC_FORM_KEY)); |
279 | |
Collection displayList; |
280 | |
|
281 | |
|
282 | 0 | if (bounded) { |
283 | 0 | displayList = getSearchResults(lookupForm.getFieldsForLookup()); |
284 | |
} |
285 | |
else { |
286 | 0 | displayList = getSearchResultsUnbounded(lookupForm.getFieldsForLookup()); |
287 | |
} |
288 | |
|
289 | 0 | HashMap<String,Class> propertyTypes = new HashMap<String, Class>(); |
290 | |
|
291 | 0 | boolean hasReturnableRow = false; |
292 | |
|
293 | 0 | List returnKeys = getReturnKeys(); |
294 | 0 | List pkNames = getBusinessObjectMetaDataService().listPrimaryKeyFieldNames(getBusinessObjectClass()); |
295 | 0 | Person user = GlobalVariables.getUserSession().getPerson(); |
296 | |
|
297 | |
|
298 | 0 | for (Iterator iter = displayList.iterator(); iter.hasNext();) { |
299 | 0 | BusinessObject element = (BusinessObject) iter.next(); |
300 | 0 | if(element instanceof PersistableBusinessObject){ |
301 | 0 | lookupForm.setLookupObjectId(((PersistableBusinessObject)element).getObjectId()); |
302 | |
} |
303 | |
|
304 | 0 | BusinessObjectRestrictions businessObjectRestrictions = getBusinessObjectAuthorizationService().getLookupResultRestrictions(element, user); |
305 | |
|
306 | 0 | HtmlData returnUrl = getReturnUrl(element, lookupForm, returnKeys, businessObjectRestrictions); |
307 | |
|
308 | 0 | String actionUrls = getActionUrls(element, pkNames, businessObjectRestrictions); |
309 | |
|
310 | 0 | if("".equals(actionUrls)){ |
311 | 0 | actionUrls = ACTION_URLS_EMPTY; |
312 | |
} |
313 | |
|
314 | 0 | List<Column> columns = getColumns(); |
315 | 0 | for (Object element2 : columns) { |
316 | |
|
317 | 0 | Column col = (Column) element2; |
318 | 0 | Formatter formatter = col.getFormatter(); |
319 | |
|
320 | |
|
321 | 0 | String propValue = KRADConstants.EMPTY_STRING; |
322 | 0 | Object prop = null; |
323 | 0 | if (col.getPropertyName().matches("\\w+\\.\\d+$")) { |
324 | 0 | String id = col.getPropertyName().substring(col.getPropertyName().lastIndexOf('.') + 1); |
325 | 0 | prop = ((GroupBo)element).getGroupAttributeValueById(id); |
326 | |
} |
327 | 0 | if (prop == null) { |
328 | 0 | prop = ObjectUtils.getPropertyValue(element, col.getPropertyName()); |
329 | |
} else { |
330 | |
} |
331 | |
|
332 | |
|
333 | 0 | Class propClass = propertyTypes.get(col.getPropertyName()); |
334 | 0 | if ( propClass == null ) { |
335 | |
try { |
336 | 0 | propClass = ObjectUtils.getPropertyType( element, col.getPropertyName(), getPersistenceStructureService() ); |
337 | 0 | propertyTypes.put( col.getPropertyName(), propClass ); |
338 | 0 | } catch (Exception e) { |
339 | 0 | throw new RuntimeException("Cannot access PropertyType for property " + "'" + col.getPropertyName() + "' " + " on an instance of '" + element.getClass().getName() + "'.", e); |
340 | 0 | } |
341 | |
} |
342 | |
|
343 | |
|
344 | 0 | if (prop != null) { |
345 | |
|
346 | 0 | if (prop instanceof Boolean) { |
347 | 0 | formatter = new BooleanFormatter(); |
348 | |
} |
349 | |
|
350 | |
|
351 | 0 | if (prop instanceof Date) { |
352 | 0 | formatter = new DateFormatter(); |
353 | |
} |
354 | |
|
355 | |
|
356 | 0 | if (prop instanceof Collection && formatter == null) { |
357 | 0 | formatter = new CollectionFormatter(); |
358 | |
} |
359 | |
|
360 | 0 | if (formatter != null) { |
361 | 0 | propValue = (String) formatter.format(prop); |
362 | |
} |
363 | |
else { |
364 | 0 | propValue = prop.toString(); |
365 | 0 | if (col.getPropertyName().equals(KIM_TYPE_ID_PROPERTY_NAME)) { |
366 | 0 | propValue = groupTypeValuesCache.get(prop.toString()); |
367 | |
} |
368 | |
} |
369 | |
} |
370 | |
|
371 | |
|
372 | 0 | col.setComparator(CellComparatorHelper.getAppropriateComparatorForPropertyClass(propClass)); |
373 | 0 | col.setValueComparator(CellComparatorHelper.getAppropriateValueComparatorForPropertyClass(propClass)); |
374 | |
|
375 | 0 | propValue = maskValueIfNecessary(element.getClass(), col.getPropertyName(), propValue, businessObjectRestrictions); |
376 | |
|
377 | 0 | col.setPropertyValue(propValue); |
378 | |
|
379 | 0 | if (StringUtils.isNotBlank(propValue)) { |
380 | 0 | col.setColumnAnchor(getInquiryUrl(element, col.getPropertyName())); |
381 | |
|
382 | |
} |
383 | 0 | } |
384 | |
|
385 | 0 | ResultRow row = new ResultRow(columns, returnUrl.constructCompleteHtmlTag(), actionUrls); |
386 | 0 | row.setRowId(returnUrl.getName()); |
387 | 0 | row.setReturnUrlHtmlData(returnUrl); |
388 | |
|
389 | |
|
390 | 0 | if (getBusinessObjectDictionaryService().isExportable(getBusinessObjectClass())) { |
391 | 0 | row.setBusinessObject(element); |
392 | |
} |
393 | 0 | if(element instanceof PersistableBusinessObject){ |
394 | 0 | row.setObjectId((((PersistableBusinessObject)element).getObjectId())); |
395 | |
} |
396 | |
|
397 | |
|
398 | 0 | boolean rowReturnable = isResultReturnable(element); |
399 | 0 | row.setRowReturnable(rowReturnable); |
400 | 0 | if (rowReturnable) { |
401 | 0 | hasReturnableRow = true; |
402 | |
} |
403 | 0 | resultTable.add(row); |
404 | 0 | } |
405 | |
|
406 | 0 | lookupForm.setHasReturnableRow(hasReturnableRow); |
407 | |
|
408 | 0 | return displayList; |
409 | |
} |
410 | |
|
411 | |
private List<KeyValue> getGroupTypeOptions() { |
412 | 0 | List<KeyValue> options = new ArrayList<KeyValue>(); |
413 | 0 | options.add(new ConcreteKeyValue("", "")); |
414 | |
|
415 | 0 | Collection<KimType> kimGroupTypes = KimApiServiceLocator.getKimTypeInfoService().findAllKimTypes(); |
416 | |
|
417 | 0 | for (KimType kimType : kimGroupTypes) { |
418 | 0 | if (KimTypeLookupableHelperServiceImpl.hasGroupTypeService(kimType) && groupTypeValuesCache.get(kimType.getId()) == null) { |
419 | 0 | String value = kimType.getNamespaceCode().trim() + KRADConstants.FIELD_CONVERSION_PAIR_SEPARATOR + kimType.getName().trim(); |
420 | 0 | options.add(new ConcreteKeyValue(kimType.getId(), value)); |
421 | 0 | } |
422 | |
} |
423 | 0 | Collections.sort(options, new Comparator<KeyValue>() { |
424 | |
@Override |
425 | |
public int compare(KeyValue k1, KeyValue k2) { |
426 | 0 | return k1.getValue().compareTo(k2.getValue()); |
427 | |
} |
428 | |
}); |
429 | 0 | return options; |
430 | |
} |
431 | |
|
432 | |
private List<Row> setupAttributeRows(Map fieldValues) { |
433 | 0 | List<Row> returnRows = new ArrayList<Row>(); |
434 | 0 | for (Row row : getGrpRows()) { |
435 | 0 | Field field = row.getFields().get(0); |
436 | 0 | if (field.getPropertyName().equals(KIM_TYPE_ID_PROPERTY_NAME) && StringUtils.isNotBlank(field.getPropertyValue())) { |
437 | 0 | if (!StringUtils.isBlank(getTypeId()) || !getTypeId().equals(field.getPropertyValue())) { |
438 | 0 | setTypeId(field.getPropertyValue()); |
439 | 0 | setAttrRows(new ArrayList<Row>()); |
440 | 0 | KimType kimType = getTypeInfoService().getKimType( field.getPropertyValue() ); |
441 | 0 | KimTypeService kimTypeService = KIMServiceLocatorWeb.getKimTypeService(kimType); |
442 | 0 | AttributeDefinitionMap definitions = kimTypeService.getAttributeDefinitions(kimType.getId()); |
443 | 0 | setAttrDefinitions(definitions); |
444 | 0 | for (AttributeDefinition definition : definitions.values()) { |
445 | 0 | List<Field> fields = new ArrayList<Field>(); |
446 | 0 | Field typeField = new Field(); |
447 | |
|
448 | 0 | String attrDefnId = getAttrDefnId(definition); |
449 | 0 | typeField.setFieldLabel(definition.getLabel()); |
450 | 0 | typeField.setPropertyName(definition.getName()+"."+attrDefnId); |
451 | 0 | typeField.setPropertyValue(fieldValues.get(typeField.getPropertyName())); |
452 | 0 | if (definition.getControl().isSelect()) { |
453 | |
try { |
454 | 0 | KeyValuesFinder finder = (KeyValuesFinder) ClassLoaderUtils.getClass(definition.getControl().getValuesFinderClass()).newInstance(); |
455 | |
|
456 | 0 | if (finder instanceof KimAttributeValuesFinder) { |
457 | 0 | ((KimAttributeValuesFinder) finder).setKimTypeId(field.getPropertyValue()); |
458 | 0 | ((KimAttributeValuesFinder) finder).setKimAttributeName(definition.getName()); |
459 | |
} |
460 | 0 | typeField.setFieldValidValues(finder.getKeyValues()); |
461 | 0 | typeField.setFieldType(Field.DROPDOWN); |
462 | |
} |
463 | 0 | catch (InstantiationException e) { |
464 | 0 | throw new RuntimeException(e.getMessage()); |
465 | |
} |
466 | 0 | catch (IllegalAccessException e) { |
467 | 0 | throw new RuntimeException(e.getMessage()); |
468 | 0 | } |
469 | 0 | } else if (definition.getControl().isText()){ |
470 | 0 | typeField.setMaxLength(definition.getMaxLength()); |
471 | 0 | if (definition.getControl().getSize() != null) { |
472 | 0 | typeField.setSize(definition.getControl().getSize()); |
473 | |
} |
474 | 0 | typeField.setFieldType(Field.TEXT); |
475 | 0 | } else if (definition.getControl().isRadio()) { |
476 | |
try { |
477 | 0 | KeyValuesFinder finder = (KeyValuesFinder) ClassLoaderUtils.getClass(definition.getControl().getValuesFinderClass()).newInstance(); |
478 | 0 | typeField.setFieldValidValues(finder.getKeyValues()); |
479 | 0 | typeField.setFieldType(Field.RADIO); |
480 | |
} |
481 | 0 | catch (InstantiationException e) { |
482 | 0 | throw new RuntimeException(e.getMessage()); |
483 | |
} |
484 | 0 | catch (IllegalAccessException e) { |
485 | 0 | throw new RuntimeException(e.getMessage()); |
486 | 0 | } |
487 | 0 | } else if (definition.getControl().isCheckbox()) { |
488 | 0 | KeyValuesFinder finder = new IndicatorValuesFinder(); |
489 | 0 | typeField.setFieldValidValues(finder.getKeyValues()); |
490 | 0 | typeField.setFieldType(Field.RADIO); |
491 | |
|
492 | 0 | } else if (definition.getControl().isHidden()) { |
493 | 0 | typeField.setFieldType(Field.HIDDEN); |
494 | 0 | } else if (definition.getControl().isLookupReadonly()) { |
495 | 0 | typeField.setFieldType(Field.LOOKUP_READONLY); |
496 | 0 | } else if (definition.getControl().isTextarea()) { |
497 | 0 | typeField.setMaxLength(definition.getMaxLength()); |
498 | 0 | if (definition.getControl().getSize() != null) { |
499 | 0 | typeField.setSize(definition.getControl().getSize()); |
500 | |
} |
501 | 0 | typeField.setFieldType(Field.TEXT_AREA); |
502 | |
} |
503 | 0 | fields.add(typeField); |
504 | 0 | returnRows.add(new Row(fields)); |
505 | 0 | } |
506 | 0 | } else { |
507 | 0 | return getAttrRows(); |
508 | |
} |
509 | 0 | } else if (field.getPropertyName().equals(KIM_TYPE_ID_PROPERTY_NAME) && StringUtils.isBlank(field.getPropertyValue())) { |
510 | 0 | setTypeId(""); |
511 | |
} |
512 | 0 | } |
513 | 0 | return returnRows; |
514 | |
} |
515 | |
|
516 | |
private String getAttrDefnId(AttributeDefinition definition) { |
517 | 0 | return ((KimAttributeDefinition)definition).getKimAttrDefnId(); |
518 | |
} |
519 | |
|
520 | |
public List<Row> getGrpRows() { |
521 | 0 | return this.grpRows; |
522 | |
} |
523 | |
|
524 | |
public void setGrpRows(List<Row> grpRows) { |
525 | 0 | this.grpRows = grpRows; |
526 | 0 | } |
527 | |
|
528 | |
public AttributeDefinitionMap getAttrDefinitions() { |
529 | 0 | return this.attrDefinitions; |
530 | |
} |
531 | |
|
532 | |
public void setAttrDefinitions(AttributeDefinitionMap attrDefinitions) { |
533 | 0 | this.attrDefinitions = attrDefinitions; |
534 | 0 | } |
535 | |
|
536 | |
public List<Row> getAttrRows() { |
537 | 0 | return this.attrRows; |
538 | |
} |
539 | |
|
540 | |
public void setAttrRows(List<Row> attrRows) { |
541 | 0 | this.attrRows = attrRows; |
542 | 0 | } |
543 | |
|
544 | |
public String getTypeId() { |
545 | 0 | return this.typeId; |
546 | |
} |
547 | |
|
548 | |
public void setTypeId(String typeId) { |
549 | 0 | this.typeId = typeId; |
550 | 0 | } |
551 | |
|
552 | |
@Override |
553 | |
public void performClear(LookupForm lookupForm) { |
554 | 0 | super.performClear(lookupForm); |
555 | 0 | this.attrRows = new ArrayList<Row>(); |
556 | 0 | } |
557 | |
|
558 | |
} |