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.panels.search;
20
21 import java.util.List;
22 import java.util.Map;
23 import java.util.function.Function;
24 import java.util.stream.Collectors;
25 import org.apache.syncope.client.console.rest.ConnectorRestClient;
26 import org.apache.syncope.client.lib.SyncopeClient;
27 import org.apache.syncope.common.lib.search.AbstractFiqlSearchConditionBuilder;
28 import org.apache.syncope.common.lib.to.ConnIdObjectClass;
29 import org.apache.syncope.common.lib.to.PlainSchemaTO;
30 import org.apache.syncope.common.lib.to.ResourceTO;
31 import org.apache.syncope.common.lib.types.AnyTypeKind;
32 import org.apache.wicket.PageReference;
33 import org.apache.wicket.model.IModel;
34 import org.apache.wicket.model.LoadableDetachableModel;
35 import org.apache.wicket.spring.injection.annot.SpringBean;
36
37 public class ConnObjectSearchPanel extends AbstractSearchPanel {
38
39 private static final long serialVersionUID = 21020550706646L;
40
41 protected final ResourceTO resource;
42
43 public static class Builder extends AbstractSearchPanel.Builder<ConnObjectSearchPanel> {
44
45 private static final long serialVersionUID = 6308997285778809578L;
46
47 private final ResourceTO resource;
48
49 private final AnyTypeKind anyType;
50
51 private final String typeName;
52
53 public Builder(
54 final ResourceTO resource,
55 final AnyTypeKind anyType,
56 final String type,
57 final IModel<List<SearchClause>> model,
58 final PageReference pageRef) {
59
60 super(model, pageRef);
61 this.resource = resource;
62 this.anyType = anyType;
63 this.typeName = type;
64 }
65
66 @Override
67 public ConnObjectSearchPanel build(final String id) {
68 return new ConnObjectSearchPanel(id, anyType, typeName, this);
69 }
70 }
71
72 @SpringBean
73 protected ConnectorRestClient connectorRestClient;
74
75 protected ConnObjectSearchPanel(final String id, final AnyTypeKind kind, final Builder builder) {
76 super(id, kind, builder);
77 this.resource = builder.resource;
78 }
79
80 protected ConnObjectSearchPanel(final String id, final AnyTypeKind kind, final String type, final Builder builder) {
81 super(id, kind, type, builder);
82 this.resource = builder.resource;
83 }
84
85 @Override
86 protected AbstractFiqlSearchConditionBuilder<?, ?, ?> getSearchConditionBuilder() {
87 return SyncopeClient.getConnObjectTOFiqlSearchConditionBuilder();
88 }
89
90 @Override
91 protected String getFIQLQueryTarget() {
92 return "CONN_OBJ";
93 }
94
95 @Override
96 protected void populate() {
97 this.types = new LoadableDetachableModel<>() {
98
99 private static final long serialVersionUID = 22668815812716L;
100
101 @Override
102 protected List<SearchClause.Type> load() {
103 return List.of(SearchClause.Type.ATTRIBUTE);
104 }
105 };
106
107 this.dnames = new LoadableDetachableModel<>() {
108
109 private static final long serialVersionUID = 2989042618372L;
110
111 @Override
112 protected Map<String, PlainSchemaTO> load() {
113 return Map.of();
114 }
115 };
116
117 this.anames = new LoadableDetachableModel<>() {
118
119 private static final long serialVersionUID = 3002350300761L;
120
121 @Override
122 protected Map<String, PlainSchemaTO> load() {
123 return connectorRestClient.buildObjectClassInfo(
124 connectorRestClient.read(resource.getConnector()), false).stream().
125 map(ConnIdObjectClass::getAttributes).
126 flatMap(List::stream).
127 collect(Collectors.toMap(
128 PlainSchemaTO::getKey, Function.identity(),
129 (schema1, schema2) -> schema1));
130 }
131 };
132 }
133 }