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.any;
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.AnyWrapper;
29  import org.apache.syncope.common.lib.to.GroupTO;
30  
31  public class GroupWrapper extends AnyWrapper<GroupTO> {
32  
33      private static final long serialVersionUID = 8058288034211558376L;
34  
35      private GroupTO previousGroupTO;
36  
37      private List<SearchClause> uDynClauses;
38  
39      private Map<String, List<SearchClause>> aDynClauses;
40  
41      public GroupWrapper(final GroupTO groupTO) {
42          this(null, groupTO);
43      }
44  
45      public GroupWrapper(final GroupTO previousGroupTO, final GroupTO groupTO) {
46          super(groupTO);
47          this.previousGroupTO = previousGroupTO;
48          getUDynClauses();
49          getADynClauses();
50      }
51  
52      public GroupTO getPreviousGroupTO() {
53          return previousGroupTO;
54      }
55  
56      public final List<SearchClause> getUDynClauses() {
57          if (this.uDynClauses == null) {
58              this.uDynClauses = SearchUtils.getSearchClauses(this.anyTO.getUDynMembershipCond());
59          }
60          return this.uDynClauses;
61      }
62  
63      public void setUDynClauses(final List<SearchClause> uDynClauses) {
64          this.uDynClauses = uDynClauses;
65      }
66  
67      public final Map<String, List<SearchClause>> getADynClauses() {
68          if (this.aDynClauses == null) {
69              this.aDynClauses = SearchUtils.getSearchClauses(this.anyTO.getADynMembershipConds());
70          }
71          return this.aDynClauses;
72      }
73  
74      public void setADynClauses(final Map<String, List<SearchClause>> aDynClauses) {
75          this.aDynClauses = aDynClauses;
76      }
77  
78      public String getUDynMembershipCond() {
79          return CollectionUtils.isEmpty(this.uDynClauses)
80                  ? null
81                  : SearchUtils.buildFIQL(this.uDynClauses, SyncopeClient.getUserSearchConditionBuilder());
82      }
83  
84      public Map<String, String> getADynMembershipConds() {
85          Map<String, String> res = new HashMap<>();
86          if (this.aDynClauses != null && !this.aDynClauses.isEmpty()) {
87              this.aDynClauses.entrySet().stream().
88                      filter(entry -> CollectionUtils.isNotEmpty(entry.getValue())).
89                      forEach(entry -> {
90                          String fiql = SearchUtils.buildFIQL(entry.getValue(),
91                                  SyncopeClient.getAnyObjectSearchConditionBuilder(entry.getKey()));
92                          if (fiql != null) {
93                              res.put(entry.getKey(), fiql);
94                          }
95                      });
96          }
97  
98          return res;
99      }
100 
101     public GroupTO fillDynamicConditions() {
102         this.anyTO.setUDynMembershipCond(this.getUDynMembershipCond());
103         this.anyTO.getADynMembershipConds().clear();
104         this.anyTO.getADynMembershipConds().putAll(this.getADynMembershipConds());
105         return this.anyTO;
106     }
107 }