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.ArrayList;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.function.Function;
25 import java.util.stream.Collectors;
26 import org.apache.syncope.client.console.rest.AnyTypeRestClient;
27 import org.apache.syncope.client.console.rest.SchemaRestClient;
28 import org.apache.syncope.client.lib.SyncopeClient;
29 import org.apache.syncope.client.ui.commons.Constants;
30 import org.apache.syncope.common.lib.SyncopeConstants;
31 import org.apache.syncope.common.lib.search.AbstractFiqlSearchConditionBuilder;
32 import org.apache.syncope.common.lib.to.GroupTO;
33 import org.apache.syncope.common.lib.to.PlainSchemaTO;
34 import org.apache.syncope.common.lib.to.SchemaTO;
35 import org.apache.syncope.common.lib.types.AnyTypeKind;
36 import org.apache.syncope.common.lib.types.SchemaType;
37 import org.apache.wicket.PageReference;
38 import org.apache.wicket.extensions.markup.html.repeater.util.SortParam;
39 import org.apache.wicket.model.IModel;
40 import org.apache.wicket.model.LoadableDetachableModel;
41 import org.apache.wicket.spring.injection.annot.SpringBean;
42
43 public class AnyObjectSearchPanel extends AbstractSearchPanel {
44
45 private static final long serialVersionUID = -1769527800450203738L;
46
47 public static class Builder extends AbstractSearchPanel.Builder<AnyObjectSearchPanel> {
48
49 private static final long serialVersionUID = 6308997285778809578L;
50
51 private final String type;
52
53 public Builder(final String type, final IModel<List<SearchClause>> model, final PageReference pageRef) {
54 super(model, pageRef);
55 this.type = type;
56 }
57
58 @Override
59 public AnyObjectSearchPanel build(final String id) {
60 return new AnyObjectSearchPanel(id, AnyTypeKind.ANY_OBJECT, type, this);
61 }
62 }
63
64 @SpringBean
65 protected SchemaRestClient schemaRestClient;
66
67 @SpringBean
68 protected AnyTypeRestClient anyTypeRestClient;
69
70 protected AnyObjectSearchPanel(final String id, final AnyTypeKind kind, final Builder builder) {
71 super(id, kind, builder);
72 }
73
74 protected AnyObjectSearchPanel(final String id, final AnyTypeKind kind, final String type, final Builder builder) {
75 super(id, kind, type, builder);
76 }
77
78 @Override
79 protected AbstractFiqlSearchConditionBuilder<?, ?, ?> getSearchConditionBuilder() {
80 return SyncopeClient.getAnyObjectSearchConditionBuilder(type);
81 }
82
83 @Override
84 protected String getFIQLQueryTarget() {
85 return type;
86 }
87
88 @Override
89 protected void populate() {
90 super.populate();
91
92 this.types = new LoadableDetachableModel<>() {
93
94 private static final long serialVersionUID = 5275935387613157437L;
95
96 @Override
97 protected List<SearchClause.Type> load() {
98 return getAvailableTypes();
99 }
100 };
101
102 this.groupNames = new LoadableDetachableModel<>() {
103
104 private static final long serialVersionUID = 5275935387613157437L;
105
106 @Override
107 protected List<String> load() {
108 return groupRestClient.search(
109 SyncopeConstants.ROOT_REALM,
110 null,
111 1,
112 Constants.MAX_GROUP_LIST_SIZE,
113 new SortParam<>(Constants.NAME_FIELD_NAME, true),
114 null).stream().map(GroupTO::getName).collect(Collectors.toList());
115 }
116 };
117
118 this.anames = new LoadableDetachableModel<>() {
119
120 private static final long serialVersionUID = 5275935387613157437L;
121
122 @Override
123 protected Map<String, PlainSchemaTO> load() {
124 return schemaRestClient.<PlainSchemaTO>getSchemas(SchemaType.PLAIN, null, anyTypeRestClient.read(type).
125 getClasses().toArray(String[]::new)).
126 stream().collect(Collectors.toMap(SchemaTO::getKey, Function.identity()));
127 }
128 };
129 }
130
131 protected List<SearchClause.Type> getAvailableTypes() {
132 List<SearchClause.Type> result = new ArrayList<>();
133 result.add(SearchClause.Type.ATTRIBUTE);
134 result.add(SearchClause.Type.GROUP_MEMBERSHIP);
135 result.add(SearchClause.Type.AUX_CLASS);
136 result.add(SearchClause.Type.RESOURCE);
137 result.add(SearchClause.Type.RELATIONSHIP);
138 return result;
139 }
140 }