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.widgets;
20  
21  import de.agilecoders.wicket.core.markup.html.bootstrap.image.Icon;
22  import de.agilecoders.wicket.extensions.markup.html.bootstrap.icon.FontAwesome5IconType;
23  import java.util.ArrayList;
24  import java.util.List;
25  import org.apache.commons.lang3.StringUtils;
26  import org.apache.syncope.client.console.wizards.mapping.JEXLTransformersTogglePanel;
27  import org.apache.syncope.common.lib.to.Item;
28  import org.apache.wicket.ajax.AjaxRequestTarget;
29  import org.apache.wicket.ajax.markup.html.AjaxLink;
30  import org.apache.wicket.markup.html.link.AbstractLink;
31  import org.apache.wicket.model.IModel;
32  import org.apache.wicket.model.util.ListModel;
33  
34  public class JEXLTransformerWidget extends AlertWidget<String> {
35  
36      private static final long serialVersionUID = 7667120094526529934L;
37  
38      private final Item item;
39  
40      private final JEXLTransformersTogglePanel transformers;
41  
42      public JEXLTransformerWidget(
43              final String id,
44              final Item item,
45              final JEXLTransformersTogglePanel transformers) {
46  
47          super(id);
48          setOutputMarkupId(true);
49  
50          this.item = item;
51          this.transformers = transformers;
52  
53          this.latestAlertsList.setVisible(false);
54      }
55  
56      @Override
57      protected IModel<List<String>> getLatestAlerts() {
58          return new ListModel<>() {
59  
60              private static final long serialVersionUID = -2583290457773357445L;
61  
62              @Override
63              public List<String> getObject() {
64                  List<String> result = new ArrayList<>();
65                  if (StringUtils.isNotBlank(item.getPropagationJEXLTransformer())) {
66                      result.add(item.getPropagationJEXLTransformer());
67                  }
68                  if (StringUtils.isNotBlank(item.getPullJEXLTransformer())) {
69                      result.add(item.getPullJEXLTransformer());
70                  }
71                  return result;
72              }
73          };
74      }
75  
76      @Override
77      protected AbstractLink getEventsLink(final String linkid) {
78          return new AjaxLink<String>(linkid) {
79  
80              private static final long serialVersionUID = -7978723352517770644L;
81  
82              @Override
83              public void onClick(final AjaxRequestTarget target) {
84                  transformers.setItem(target, JEXLTransformerWidget.this.item);
85                  transformers.toggle(target, true);
86              }
87          };
88      }
89  
90      @Override
91      protected Icon getIcon(final String iconid) {
92          return new Icon(iconid, FontAwesome5IconType.redo_s);
93      }
94  }