1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.client.console.wicket.extensions.markup.html.repeater.data.table;
20
21 import java.lang.reflect.InvocationTargetException;
22 import java.util.Map;
23 import java.util.Objects;
24 import org.apache.commons.lang3.ArrayUtils;
25 import org.apache.syncope.common.lib.types.ExecStatus;
26 import org.apache.wicket.Component;
27 import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
28 import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
29 import org.apache.wicket.markup.html.basic.Label;
30 import org.apache.wicket.markup.repeater.Item;
31 import org.apache.wicket.model.IModel;
32 import org.apache.wicket.model.Model;
33 import org.apache.wicket.model.StringResourceModel;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36 import org.springframework.beans.BeanUtils;
37 import org.springframework.beans.BeansException;
38
39 public class BatchResponseColumn<T, S> extends AbstractColumn<T, S> {
40
41 private static final long serialVersionUID = 7955560320949560716L;
42
43 private static final Logger LOG = LoggerFactory.getLogger(BatchResponseColumn.class);
44
45 private final Map<String, String> results;
46
47 private final String keyFieldName;
48
49 public BatchResponseColumn(final Map<String, String> results, final String keyFieldName) {
50 super(new Model<>());
51 this.results = results;
52 this.keyFieldName = keyFieldName;
53 }
54
55 @Override
56 public Component getHeader(final String componentId) {
57 Label label = new Label(componentId, new Model<>());
58 label.setDefaultModel(new StringResourceModel("batch.result.header", label, new Model<>("Result")));
59 return label;
60 }
61
62 @Override
63 public void populateItem(final Item<ICellPopulator<T>> item, final String componentId, final IModel<T> rowModel) {
64 try {
65 Object key = Objects.requireNonNull(
66 BeanUtils.getPropertyDescriptor(rowModel.getObject().getClass(), keyFieldName))
67 .getReadMethod().invoke(rowModel.getObject(), ArrayUtils.EMPTY_OBJECT_ARRAY);
68 String status = results.containsKey(key.toString())
69 ? results.get(key.toString())
70 : ExecStatus.NOT_ATTEMPTED.name();
71
72 item.add(new Label(componentId, new StringResourceModel(status, item, new Model<>(status))));
73 } catch (BeansException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
74 LOG.error("Error retrieving target key value", e);
75 }
76 }
77 }