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.List;
22  import org.apache.commons.lang3.StringUtils;
23  import org.apache.syncope.client.console.panels.search.AnyObjectSearchPanel;
24  import org.apache.syncope.client.console.panels.search.MapOfListModel;
25  import org.apache.syncope.client.console.rest.AnyTypeRestClient;
26  import org.apache.syncope.client.ui.commons.wicket.markup.html.bootstrap.tabs.Accordion;
27  import org.apache.syncope.common.lib.to.AnyTypeTO;
28  import org.apache.wicket.PageReference;
29  import org.apache.wicket.extensions.markup.html.tabs.AbstractTab;
30  import org.apache.wicket.extensions.wizard.WizardStep;
31  import org.apache.wicket.markup.html.list.ListItem;
32  import org.apache.wicket.markup.html.list.ListView;
33  import org.apache.wicket.markup.html.panel.Panel;
34  import org.apache.wicket.model.LoadableDetachableModel;
35  import org.apache.wicket.model.Model;
36  import org.apache.wicket.model.StringResourceModel;
37  import org.apache.wicket.spring.injection.annot.SpringBean;
38  
39  public class PushTaskFilters extends WizardStep {
40  
41      private static final long serialVersionUID = 855618618337931784L;
42  
43      @SpringBean
44      protected AnyTypeRestClient anyTypeRestClient;
45  
46      public PushTaskFilters(final PushTaskWrapper pushTaskWrapper, final PageReference pageRef) {
47          super();
48  
49          final LoadableDetachableModel<List<AnyTypeTO>> types = new LoadableDetachableModel<>() {
50  
51              private static final long serialVersionUID = 5275935387613157437L;
52  
53              @Override
54              protected List<AnyTypeTO> load() {
55                  return anyTypeRestClient.listAnyTypes();
56              }
57          };
58  
59          add(new ListView<>("filters", types) {
60  
61              private static final long serialVersionUID = 9101744072914090143L;
62  
63              @Override
64              protected void populateItem(final ListItem<AnyTypeTO> item) {
65                  final String key = item.getModelObject().getKey();
66                  item.add(new Accordion("filters", List.of(
67                          new AbstractTab(new StringResourceModel(
68                                  "filters", this, new Model<>(item.getModelObject()))) {
69  
70                      private static final long serialVersionUID = 1037272333056449378L;
71  
72                      @Override
73                      public Panel getPanel(final String panelId) {
74                          return new AnyObjectSearchPanel.Builder(
75                                  key, new MapOfListModel<>(pushTaskWrapper, "filterClauses", key), pageRef).
76                                  required(false).build(panelId);
77                      }
78                  }), Model.of(StringUtils.isBlank(pushTaskWrapper.getFilters().get(key)) ? -1 : 0))
79                          .setOutputMarkupId(true));
80              }
81          });
82      }
83  }