1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.client.console.tasks;
20
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.Iterator;
24 import java.util.List;
25 import org.apache.syncope.client.console.SyncopeConsoleSession;
26 import org.apache.syncope.client.console.commons.IdRepoConstants;
27 import org.apache.syncope.client.console.commons.TaskDataProvider;
28 import org.apache.syncope.client.console.pages.BasePage;
29 import org.apache.syncope.client.console.panels.MultilevelPanel;
30 import org.apache.syncope.client.console.rest.TaskRestClient;
31 import org.apache.syncope.client.console.wicket.extensions.markup.html.repeater.data.table.DatePropertyColumn;
32 import org.apache.syncope.client.console.wicket.extensions.markup.html.repeater.data.table.KeyPropertyColumn;
33 import org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal;
34 import org.apache.syncope.client.console.wicket.markup.html.form.ActionLink;
35 import org.apache.syncope.client.console.wicket.markup.html.form.ActionLink.ActionType;
36 import org.apache.syncope.client.console.wicket.markup.html.form.ActionsPanel;
37 import org.apache.syncope.client.ui.commons.Constants;
38 import org.apache.syncope.client.ui.commons.panels.ModalPanel;
39 import org.apache.syncope.common.lib.SyncopeClientException;
40 import org.apache.syncope.common.lib.SyncopeConstants;
41 import org.apache.syncope.common.lib.to.PropagationTaskTO;
42 import org.apache.syncope.common.lib.types.IdRepoEntitlement;
43 import org.apache.syncope.common.lib.types.TaskType;
44 import org.apache.wicket.PageReference;
45 import org.apache.wicket.ajax.AjaxRequestTarget;
46 import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
47 import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
48 import org.apache.wicket.model.IModel;
49 import org.apache.wicket.model.Model;
50 import org.apache.wicket.model.StringResourceModel;
51
52 public abstract class PropagationTaskDirectoryPanel
53 extends TaskDirectoryPanel<PropagationTaskTO> implements ModalPanel {
54
55 private static final long serialVersionUID = 4984337552918213290L;
56
57 private final String resource;
58
59 protected PropagationTaskDirectoryPanel(
60 final TaskRestClient restClient,
61 final BaseModal<?> baseModal,
62 final MultilevelPanel multiLevelPanelRef,
63 final String resource,
64 final PageReference pageRef) {
65
66 super(restClient, baseModal, multiLevelPanelRef, pageRef, false);
67 this.resource = resource;
68 initResultTable();
69 }
70
71 @Override
72 protected List<IColumn<PropagationTaskTO, String>> getColumns() {
73 List<IColumn<PropagationTaskTO, String>> columns = new ArrayList<>();
74
75 columns.add(new KeyPropertyColumn<>(
76 new StringResourceModel(Constants.KEY_FIELD_NAME, this), Constants.KEY_FIELD_NAME));
77
78 columns.add(new PropertyColumn<>(
79 new StringResourceModel("operation", this), "operation", "operation"));
80
81 if (resource == null) {
82 columns.add(new PropertyColumn<>(
83 new StringResourceModel("resource", this), "resource", "resource"));
84 } else {
85 columns.add(new PropertyColumn<>(
86 new StringResourceModel("anyTypeKind", this), "anyTypeKind", "anyTypeKind") {
87
88 private static final long serialVersionUID = 3344577098912281394L;
89
90 @Override
91 public IModel<?> getDataModel(final IModel<PropagationTaskTO> rowModel) {
92 if (rowModel.getObject().getAnyTypeKind() == null) {
93 return Model.of(SyncopeConstants.REALM_ANYTYPE);
94 } else {
95 return super.getDataModel(rowModel);
96 }
97 }
98 });
99 }
100
101 columns.add(new PropertyColumn<>(
102 new StringResourceModel("entityKey", this), "entityKey", "entityKey"));
103
104 columns.add(new PropertyColumn<>(
105 new StringResourceModel("connObjectKey", this), "connObjectKey", "connObjectKey"));
106
107 columns.add(new DatePropertyColumn<>(
108 new StringResourceModel("start", this), "start", "start"));
109
110 columns.add(new DatePropertyColumn<>(
111 new StringResourceModel("end", this), "end", "end"));
112
113 columns.add(new PropertyColumn<>(
114 new StringResourceModel("latestExecStatus", this), "latestExecStatus", "latestExecStatus"));
115
116 return columns;
117 }
118
119 @Override
120 public ActionsPanel<PropagationTaskTO> getActions(final IModel<PropagationTaskTO> model) {
121 final ActionsPanel<PropagationTaskTO> panel = super.getActions(model);
122 final PropagationTaskTO taskTO = model.getObject();
123
124 panel.add(new ActionLink<>() {
125
126 private static final long serialVersionUID = -3722207913631435501L;
127
128 @Override
129 public void onClick(final AjaxRequestTarget target, final PropagationTaskTO modelObject) {
130 PropagationTaskDirectoryPanel.this.getTogglePanel().close(target);
131 viewTaskExecs(taskTO, target);
132 }
133 }, ActionLink.ActionType.VIEW_EXECUTIONS, IdRepoEntitlement.TASK_READ);
134
135
136 panel.add(new ActionLink<>() {
137
138 private static final long serialVersionUID = 9206257220553949594L;
139
140 @Override
141 public void onClick(final AjaxRequestTarget target, final PropagationTaskTO modelObject) {
142 PropagationTaskDirectoryPanel.this.getTogglePanel().close(target);
143 viewTaskDetails(modelObject, target);
144 }
145 }, ActionLink.ActionType.VIEW_DETAILS, IdRepoEntitlement.TASK_READ);
146
147 panel.add(new ActionLink<>() {
148
149 private static final long serialVersionUID = -3722207913631435501L;
150
151 @Override
152 public void onClick(final AjaxRequestTarget target, final PropagationTaskTO modelObject) {
153 try {
154 restClient.startExecution(taskTO.getKey(), null);
155
156 SyncopeConsoleSession.get().success(getString(Constants.OPERATION_SUCCEEDED));
157 target.add(container);
158 } catch (SyncopeClientException e) {
159 LOG.error("While running {}", taskTO.getKey(), e);
160 SyncopeConsoleSession.get().onException(e);
161 }
162 ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
163 }
164 }, ActionLink.ActionType.EXECUTE, IdRepoEntitlement.TASK_EXECUTE);
165
166 panel.add(new ActionLink<>() {
167
168 private static final long serialVersionUID = -3722207913631435501L;
169
170 @Override
171 public void onClick(final AjaxRequestTarget target, final PropagationTaskTO modelObject) {
172 try {
173 restClient.delete(TaskType.PROPAGATION, taskTO.getKey());
174
175 SyncopeConsoleSession.get().success(getString(Constants.OPERATION_SUCCEEDED));
176 target.add(container);
177 PropagationTaskDirectoryPanel.this.getTogglePanel().close(target);
178 } catch (SyncopeClientException e) {
179 LOG.error("While deleting {}", taskTO.getKey(), e);
180 SyncopeConsoleSession.get().onException(e);
181 }
182 ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
183 }
184 }, ActionLink.ActionType.DELETE, IdRepoEntitlement.TASK_DELETE, true);
185
186 return panel;
187 }
188
189 @Override
190 protected Collection<ActionType> getBatches() {
191 List<ActionType> batches = new ArrayList<>();
192 batches.add(ActionType.DELETE);
193 batches.add(ActionType.EXECUTE);
194 return batches;
195 }
196
197 @Override
198 protected PropagationTasksProvider dataProvider() {
199 return new PropagationTasksProvider(rows);
200 }
201
202 @Override
203 protected String paginatorRowsKey() {
204 return IdRepoConstants.PREF_PROPAGATION_TASKS_PAGINATOR_ROWS;
205 }
206
207 protected class PropagationTasksProvider extends TaskDataProvider<PropagationTaskTO> {
208
209 private static final long serialVersionUID = 4725679400450513556L;
210
211 public PropagationTasksProvider(final int paginatorRows) {
212 super(paginatorRows, TaskType.PROPAGATION);
213 }
214
215 @Override
216 public long size() {
217 return restClient.count(resource, TaskType.PROPAGATION);
218 }
219
220 @Override
221 public Iterator<PropagationTaskTO> iterator(final long first, final long count) {
222 int page = ((int) first / paginatorRows);
223 return restClient.listPropagationTasks(
224 resource, (page < 0 ? 0 : page) + 1, paginatorRows, getSort()).
225 iterator();
226 }
227 }
228
229 protected abstract void viewTaskDetails(PropagationTaskTO taskTO, AjaxRequestTarget target);
230 }