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.tasks;
20  
21  import java.util.HashMap;
22  import java.util.List;
23  import java.util.Map;
24  import org.apache.syncope.client.console.panels.search.SearchClause;
25  import org.apache.syncope.client.console.panels.search.SearchUtils;
26  import org.apache.syncope.client.lib.SyncopeClient;
27  import org.apache.syncope.client.ui.commons.wizards.any.EntityWrapper;
28  import org.apache.syncope.common.lib.search.AbstractFiqlSearchConditionBuilder;
29  import org.apache.syncope.common.lib.to.PushTaskTO;
30  
31  public class PushTaskWrapper extends EntityWrapper<PushTaskTO> {
32  
33      private static final long serialVersionUID = 8058288034211558377L;
34  
35      private Map<String, List<SearchClause>> filterClauses;
36  
37      public PushTaskWrapper(final PushTaskTO pushTaskTO) {
38          super(pushTaskTO);
39          getFilterClauses();
40      }
41  
42      public final Map<String, List<SearchClause>> getFilterClauses() {
43          if (this.filterClauses == null) {
44              this.filterClauses = SearchUtils.getSearchClauses(getInnerObject().getFilters());
45          }
46          return this.filterClauses;
47      }
48  
49      public void setFilterClauses(final Map<String, List<SearchClause>> aDynClauses) {
50          this.filterClauses = aDynClauses;
51      }
52  
53      public Map<String, String> getFilters() {
54          Map<String, String> filters = new HashMap<>();
55  
56          for (Map.Entry<String, List<SearchClause>> entry : getFilterClauses().entrySet()) {
57              if (!entry.getValue().isEmpty()) {
58                  AbstractFiqlSearchConditionBuilder<?, ?, ?> bld;
59                  switch (entry.getKey()) {
60                      case "USER":
61                          bld = SyncopeClient.getUserSearchConditionBuilder();
62                          break;
63  
64                      case "GROUP":
65                          bld = SyncopeClient.getGroupSearchConditionBuilder();
66                          break;
67  
68                      default:
69                          bld = SyncopeClient.getAnyObjectSearchConditionBuilder(entry.getKey());
70                  }
71  
72                  filters.put(entry.getKey(), SearchUtils.buildFIQL(entry.getValue(), bld));
73              }
74          }
75  
76          return filters;
77      }
78  
79      public PushTaskTO fillFilterConditions() {
80          getInnerObject().getFilters().clear();
81          getInnerObject().getFilters().putAll(this.getFilters());
82          return getInnerObject();
83      }
84  }