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.Collection;
22  import java.util.List;
23  import java.util.Set;
24  import org.apache.syncope.client.console.commons.IdRepoConstants;
25  import org.apache.syncope.client.console.panels.MultilevelPanel;
26  import org.apache.syncope.client.console.rest.TaskRestClient;
27  import org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal;
28  import org.apache.syncope.client.console.wicket.markup.html.form.ActionLink;
29  import org.apache.syncope.client.console.wicket.markup.html.form.ActionsPanel;
30  import org.apache.syncope.common.lib.to.LiveSyncTaskTO;
31  import org.apache.syncope.common.lib.types.IdRepoEntitlement;
32  import org.apache.syncope.common.lib.types.TaskType;
33  import org.apache.wicket.PageReference;
34  import org.apache.wicket.ajax.AjaxRequestTarget;
35  import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
36  import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
37  import org.apache.wicket.model.IModel;
38  
39  public abstract class LiveSyncTaskDirectoryPanel extends ProvisioningTaskDirectoryPanel<LiveSyncTaskTO> {
40  
41      private static final long serialVersionUID = 4984337552918213290L;
42  
43      protected LiveSyncTaskDirectoryPanel(
44              final TaskRestClient restClient,
45              final BaseModal<?> baseModal,
46              final MultilevelPanel multiLevelPanelRef,
47              final String resource,
48              final PageReference pageRef) {
49  
50          super(restClient, baseModal, multiLevelPanelRef, TaskType.LIVE_SYNC, new LiveSyncTaskTO(), resource, pageRef);
51      }
52  
53      @Override
54      protected List<IColumn<LiveSyncTaskTO, String>> getTrailingFieldColumns() {
55          List<IColumn<LiveSyncTaskTO, String>> columns = super.getTrailingFieldColumns();
56          columns.removeIf(column -> column instanceof PropertyColumn<?, ?> propertyColumn
57                  && propertyColumn.getPropertyExpression().contains("Exec"));
58          return columns;
59      }
60  
61      @Override
62      protected Collection<ActionLink.ActionType> getBatches() {
63          return Set.of();
64      }
65  
66      @Override
67      public ActionsPanel<LiveSyncTaskTO> getActions(final IModel<LiveSyncTaskTO> model) {
68          ActionsPanel<LiveSyncTaskTO> panel = super.getActions(model);
69          panel.getActions().removeIf(action -> action.getType() == ActionLink.ActionType.CLONE);
70          return panel;
71      }
72  
73      @Override
74      protected String paginatorRowsKey() {
75          return IdRepoConstants.PREF_PULL_TASKS_PAGINATOR_ROWS;
76      }
77  
78      @Override
79      protected void onDelete(final AjaxRequestTarget target) {
80          target.add(addAjaxLink);
81      }
82  
83      @Override
84      protected ProvisioningTasksProvider<LiveSyncTaskTO> dataProvider() {
85          return new ProvisioningTasksProvider<>(TaskType.LIVE_SYNC, rows) {
86  
87              private static final long serialVersionUID = -8658004154067744714L;
88  
89              @Override
90              public long size() {
91                  long size = super.size();
92                  addAjaxLink.setEnabled(size == 0);
93                  return size;
94              }
95          };
96      }
97  
98      @Override
99      protected void addFurtherActions(final ActionsPanel<LiveSyncTaskTO> panel, final IModel<LiveSyncTaskTO> model) {
100         panel.add(new ActionLink<>() {
101 
102             private static final long serialVersionUID = -3722207913631435501L;
103 
104             @Override
105             public void onClick(final AjaxRequestTarget target, final LiveSyncTaskTO ignore) {
106                 LiveSyncTaskDirectoryPanel.this.getTogglePanel().close(target);
107                 templates.setTargetObject(model.getObject());
108                 templates.toggle(target, true);
109             }
110         }, ActionLink.ActionType.TEMPLATE, IdRepoEntitlement.TASK_UPDATE).disableIndicator();
111     }
112 }