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.wizards.resources;
20
21 import java.util.ArrayList;
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.Map;
25 import org.apache.syncope.client.console.rest.ConnectorRestClient;
26 import org.apache.syncope.common.lib.to.ResourceTO;
27 import org.apache.syncope.common.lib.types.ConnConfProperty;
28 import org.apache.wicket.ajax.markup.html.form.AjaxButton;
29 import org.apache.wicket.model.LoadableDetachableModel;
30 import org.apache.wicket.model.PropertyModel;
31 import org.apache.wicket.spring.injection.annot.SpringBean;
32
33 public abstract class ResourceConnConfPanel extends AbstractConnConfPanel<ResourceTO> {
34
35 private static final long serialVersionUID = -7982691107029848579L;
36
37 @SpringBean
38 protected ConnectorRestClient connectorRestClient;
39
40 public ResourceConnConfPanel(final ResourceTO resourceTO) {
41 super(resourceTO);
42
43 model = new LoadableDetachableModel<>() {
44
45 private static final long serialVersionUID = -2965284931860212687L;
46
47 @Override
48 protected List<ConnConfProperty> load() {
49 List<ConnConfProperty> confOverride = getConnProperties(resourceTO);
50 resourceTO.getConfOverride().clear();
51 resourceTO.getConfOverride().addAll(confOverride);
52
53 return new PropertyModel<List<ConnConfProperty>>(modelObject, "confOverride") {
54
55 private static final long serialVersionUID = -7809699384012595307L;
56
57 @Override
58 public List<ConnConfProperty> getObject() {
59 List<ConnConfProperty> res = new ArrayList<>(super.getObject());
60
61
62 res.sort((left, right) -> {
63 if (left == null) {
64 return -1;
65 } else {
66 return left.compareTo(right);
67 }
68 });
69
70 return res;
71 }
72 }.getObject();
73 }
74 };
75
76 setConfPropertyListView(model, true);
77
78 check.setEnabled(!model.getObject().isEmpty());
79 check.setVisible(!model.getObject().isEmpty());
80 }
81
82
83
84
85
86
87
88 @Override
89 protected final List<ConnConfProperty> getConnProperties(final ResourceTO resourceTO) {
90 List<ConnConfProperty> props = new ArrayList<>();
91
92 if (resourceTO.getConnector() != null) {
93 connectorRestClient.read(resourceTO.getConnector()).getConf().stream().
94 filter(ConnConfProperty::isOverridable).
95 forEachOrdered(props::add);
96 }
97 if (resourceTO.getConfOverride().isEmpty()) {
98 resourceTO.getConfOverride().clear();
99 } else {
100 Map<String, ConnConfProperty> valuedProps = new HashMap<>();
101 resourceTO.getConfOverride().forEach(prop -> valuedProps.put(prop.getSchema().getName(), prop));
102
103 for (int i = 0; i < props.size(); i++) {
104 if (valuedProps.containsKey(props.get(i).getSchema().getName())) {
105 props.set(i, valuedProps.get(props.get(i).getSchema().getName()));
106 }
107 }
108 }
109
110 return props;
111 }
112
113 public LoadableDetachableModel<List<ConnConfProperty>> getModel() {
114 return model;
115 }
116
117 public AjaxButton getCheck() {
118 return check;
119 }
120 }