View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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.common.lib.search.AbstractFiqlSearchConditionBuilder;
30  import org.apache.syncope.common.lib.to.PlainSchemaTO;
31  import org.apache.syncope.common.lib.to.SchemaTO;
32  import org.apache.syncope.common.lib.types.AnyTypeKind;
33  import org.apache.syncope.common.lib.types.SchemaType;
34  import org.apache.wicket.PageReference;
35  import org.apache.wicket.model.IModel;
36  import org.apache.wicket.model.LoadableDetachableModel;
37  import org.apache.wicket.spring.injection.annot.SpringBean;
38  
39  public class GroupSearchPanel extends AbstractSearchPanel {
40  
41      private static final long serialVersionUID = 5757183539269316263L;
42  
43      public static class Builder extends AbstractSearchPanel.Builder<GroupSearchPanel> {
44  
45          private static final long serialVersionUID = 6308997285778809578L;
46  
47          public Builder(final IModel<List<SearchClause>> model, final PageReference pageRef) {
48              super(model, pageRef);
49          }
50  
51          @Override
52          public GroupSearchPanel build(final String id) {
53              return new GroupSearchPanel(id, this);
54          }
55      }
56  
57      @SpringBean
58      protected SchemaRestClient schemaRestClient;
59  
60      @SpringBean
61      protected AnyTypeRestClient anyTypeRestClient;
62  
63      protected GroupSearchPanel(final String id, final GroupSearchPanel.Builder builder) {
64          super(id, AnyTypeKind.GROUP, builder);
65      }
66  
67      @Override
68      protected AbstractFiqlSearchConditionBuilder<?, ?, ?> getSearchConditionBuilder() {
69          return SyncopeClient.getGroupSearchConditionBuilder();
70      }
71  
72      @Override
73      protected String getFIQLQueryTarget() {
74          return AnyTypeKind.GROUP.name();
75      }
76  
77      @Override
78      protected void populate() {
79          super.populate();
80  
81          this.types = new LoadableDetachableModel<>() {
82  
83              private static final long serialVersionUID = 5275935387613157437L;
84  
85              @Override
86              protected List<SearchClause.Type> load() {
87                  List<SearchClause.Type> result = new ArrayList<>();
88                  result.add(SearchClause.Type.ATTRIBUTE);
89                  result.add(SearchClause.Type.AUX_CLASS);
90                  result.add(SearchClause.Type.RESOURCE);
91                  result.add(SearchClause.Type.GROUP_MEMBER);
92                  return result;
93              }
94          };
95  
96          this.groupNames = new LoadableDetachableModel<>() {
97  
98              private static final long serialVersionUID = 5275935387613157437L;
99  
100             @Override
101             protected List<String> load() {
102                 return List.of();
103             }
104         };
105 
106         this.anames = new LoadableDetachableModel<>() {
107 
108             private static final long serialVersionUID = 5275935387613157437L;
109 
110             @Override
111             protected Map<String, PlainSchemaTO> load() {
112                 return schemaRestClient.<PlainSchemaTO>getSchemas(
113                         SchemaType.PLAIN, null, anyTypeRestClient.read(type).getClasses().toArray(String[]::new)).
114                         stream().collect(Collectors.toMap(SchemaTO::getKey, Function.identity()));
115             }
116         };
117     }
118 }