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.wizards;
20  
21  import java.util.HashMap;
22  import java.util.List;
23  import java.util.Map;
24  import org.apache.commons.collections4.CollectionUtils;
25  import org.apache.syncope.client.console.panels.search.SearchClause;
26  import org.apache.syncope.client.console.panels.search.SearchUtils;
27  import org.apache.syncope.client.lib.SyncopeClient;
28  import org.apache.syncope.client.ui.commons.wizards.any.EntityWrapper;
29  import org.apache.syncope.common.lib.search.AbstractFiqlSearchConditionBuilder;
30  import org.apache.syncope.common.lib.to.DynRealmTO;
31  import org.apache.syncope.common.lib.types.AnyTypeKind;
32  
33  public class DynRealmWrapper extends EntityWrapper<DynRealmTO> {
34  
35      private static final long serialVersionUID = 7226128615964284614L;
36  
37      private Map<String, List<SearchClause>> dynClauses;
38  
39      public DynRealmWrapper(final DynRealmTO dynRealmTO) {
40          super(dynRealmTO);
41          getDynClauses();
42      }
43  
44      public final Map<String, List<SearchClause>> getDynClauses() {
45          if (this.dynClauses == null) {
46              this.dynClauses = SearchUtils.getSearchClauses(getInnerObject().getDynMembershipConds());
47          }
48          return this.dynClauses;
49      }
50  
51      public void setDynClauses(final Map<String, List<SearchClause>> dynClauses) {
52          this.dynClauses.clear();
53          this.dynClauses.putAll(dynClauses);
54      }
55  
56      public Map<String, String> getDynMembershipConds() {
57          final Map<String, String> res = new HashMap<>();
58          if (this.dynClauses != null && !this.dynClauses.isEmpty()) {
59              this.dynClauses.entrySet().stream().
60                      filter(entry -> (CollectionUtils.isNotEmpty(entry.getValue()))).
61                      forEachOrdered(entry -> {
62                          AbstractFiqlSearchConditionBuilder<?, ?, ?> builder =
63                                  AnyTypeKind.USER.name().equals(entry.getKey())
64                                  ? SyncopeClient.getUserSearchConditionBuilder()
65                                  : AnyTypeKind.GROUP.name().equals(entry.getKey())
66                                  ? SyncopeClient.getGroupSearchConditionBuilder()
67                                  : SyncopeClient.getAnyObjectSearchConditionBuilder(entry.getKey());
68                          String fiql = SearchUtils.buildFIQL(entry.getValue(), builder);
69                          if (fiql != null) {
70                              res.put(entry.getKey(), fiql);
71                          }
72                      });
73          }
74  
75          return res;
76      }
77  
78      public DynRealmTO fillDynamicConditions() {
79          getInnerObject().getDynMembershipConds().clear();
80          getInnerObject().getDynMembershipConds().putAll(this.getDynMembershipConds());
81          return getInnerObject();
82      }
83  }