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.time.temporal.ChronoUnit;
22  import java.util.ArrayList;
23  import java.util.Iterator;
24  import java.util.List;
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.ajax.IndicatorAjaxTimerBehavior;
28  import org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal;
29  import org.apache.syncope.client.console.widgets.JobActionPanel;
30  import org.apache.syncope.common.lib.to.ProvisioningTaskTO;
31  import org.apache.syncope.common.lib.to.PullTaskTO;
32  import org.apache.syncope.common.lib.to.PushTaskTO;
33  import org.apache.syncope.common.lib.types.TaskType;
34  import org.apache.wicket.PageReference;
35  import org.apache.wicket.ajax.AjaxRequestTarget;
36  import org.apache.wicket.event.IEvent;
37  import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
38  import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
39  import org.apache.wicket.model.StringResourceModel;
40  
41  /**
42   * Tasks page.
43   *
44   * @param <T> Sched task type.
45   */
46  public abstract class ProvisioningTaskDirectoryPanel<T extends ProvisioningTaskTO>
47          extends SchedTaskDirectoryPanel<T> {
48  
49      private static final long serialVersionUID = 4984337552918213290L;
50  
51      private final String resource;
52  
53      protected ProvisioningTaskDirectoryPanel(
54              final TaskRestClient restClient,
55              final BaseModal<?> baseModal,
56              final MultilevelPanel multiLevelPanelRef,
57              final TaskType taskType,
58              final T newTaskTO,
59              final String resource,
60              final PageReference pageRef) {
61  
62          super(
63                  MultilevelPanel.FIRST_LEVEL_ID,
64                  restClient,
65                  baseModal,
66                  multiLevelPanelRef,
67                  taskType,
68                  newTaskTO,
69                  pageRef,
70                  false);
71          this.resource = resource;
72  
73          this.schedTaskTO.setResource(resource);
74  
75          // super in order to call the parent implementation
76          enableUtilityButton();
77          super.initResultTable();
78  
79          container.add(new IndicatorAjaxTimerBehavior(java.time.Duration.of(10, ChronoUnit.SECONDS)) {
80  
81              private static final long serialVersionUID = -4661303265651934868L;
82  
83              @Override
84              protected void onTimer(final AjaxRequestTarget target) {
85                  container.modelChanged();
86                  target.add(container);
87              }
88          });
89      }
90  
91      @Override
92      protected void initResultTable() {
93          // Do nothing in order to disable the call performed by the parent
94      }
95  
96      @Override
97      protected List<IColumn<T, String>> getFieldColumns() {
98          List<IColumn<T, String>> columns = new ArrayList<>();
99  
100         columns.addAll(getHeadingFieldColumns());
101 
102         if (schedTaskTO instanceof PullTaskTO) {
103             columns.add(new PropertyColumn<>(
104                     new StringResourceModel("destinationRealm", this), "destinationRealm", "destinationRealm"));
105         } else if (schedTaskTO instanceof PushTaskTO) {
106             columns.add(new PropertyColumn<>(
107                     new StringResourceModel("sourceRealm", this), "sourceRealm", "sourceRealm"));
108         }
109 
110         columns.addAll(getTrailingFieldColumns());
111 
112         return columns;
113     }
114 
115     @Override
116     public void onEvent(final IEvent<?> event) {
117         if (event.getPayload() instanceof JobActionPanel.JobActionPayload) {
118             container.modelChanged();
119             JobActionPanel.JobActionPayload.class.cast(event.getPayload()).getTarget().add(container);
120         } else {
121             super.onEvent(event);
122         }
123     }
124 
125     protected class ProvisioningTasksProvider<T extends ProvisioningTaskTO> extends SchedTasksProvider<T> {
126 
127         private static final long serialVersionUID = 4725679400450513556L;
128 
129         public ProvisioningTasksProvider(final TaskType taskType, final int paginatorRows) {
130             super(taskType, paginatorRows);
131         }
132 
133         @Override
134         public long size() {
135             return restClient.count(resource, taskType);
136         }
137 
138         @Override
139         public Iterator<T> iterator(final long first, final long count) {
140             int page = ((int) first / paginatorRows);
141             return restClient.<T>list(
142                     resource, taskType, (page < 0 ? 0 : page) + 1, paginatorRows, getSort()).
143                     iterator();
144         }
145     }
146 }