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.reports;
20
21 import org.apache.syncope.client.console.SyncopeConsoleSession;
22 import org.apache.syncope.client.console.pages.BasePage;
23 import org.apache.syncope.client.console.panels.MultilevelPanel;
24 import org.apache.syncope.client.console.rest.ExecutionRestClient;
25 import org.apache.syncope.client.console.rest.ReportRestClient;
26 import org.apache.syncope.client.console.tasks.ExecutionsDirectoryPanel;
27 import org.apache.syncope.client.console.wicket.ajax.form.AjaxDownloadBehavior;
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.client.ui.commons.Constants;
31 import org.apache.syncope.client.ui.commons.rest.ResponseHolder;
32 import org.apache.syncope.common.lib.to.ExecTO;
33 import org.apache.syncope.common.lib.to.ReportTO;
34 import org.apache.syncope.common.lib.types.IdRepoEntitlement;
35 import org.apache.wicket.PageReference;
36 import org.apache.wicket.ajax.AjaxRequestTarget;
37 import org.apache.wicket.model.IModel;
38 import org.apache.wicket.spring.injection.annot.SpringBean;
39
40
41
42
43 public class ReportExecutionDetails extends MultilevelPanel.SecondLevel {
44
45 private static final long serialVersionUID = -4110576026663173545L;
46
47 @SpringBean
48 protected ReportRestClient reportRestClient;
49
50 public ReportExecutionDetails(final ReportTO reportTO, final PageReference pageRef) {
51 super();
52
53 MultilevelPanel mlp = new MultilevelPanel("executions");
54 add(mlp);
55
56 mlp.setFirstLevel(new ReportExecutionDirectoryPanel(mlp, reportTO.getKey(), reportRestClient, pageRef));
57 }
58
59 protected static class ReportExecutionDirectoryPanel extends ExecutionsDirectoryPanel {
60
61 private static final long serialVersionUID = 5691719817252887541L;
62
63 private final AjaxDownloadBehavior downloadBehavior;
64
65 ReportExecutionDirectoryPanel(
66 final MultilevelPanel multiLevelPanelRef,
67 final String key,
68 final ExecutionRestClient executionRestClient,
69 final PageReference pageRef) {
70
71 super(multiLevelPanelRef, key, executionRestClient, pageRef);
72
73 this.downloadBehavior = new AjaxDownloadBehavior();
74 this.add(downloadBehavior);
75 }
76
77 @Override
78 protected void next(
79 final String title,
80 final MultilevelPanel.SecondLevel slevel,
81 final AjaxRequestTarget target) {
82
83 multiLevelPanelRef.next(title, slevel, target);
84 }
85
86 @Override
87 protected void addFurtherActions(final ActionsPanel<ExecTO> panel, final IModel<ExecTO> model) {
88 panel.add(new ActionLink<>() {
89
90 private static final long serialVersionUID = -3722207913631435501L;
91
92 @Override
93 public void onClick(final AjaxRequestTarget target, final ExecTO ignore) {
94 ((ReportRestClient) restClient).exportExecutionResult(model.getObject().getKey()).ifPresentOrElse(
95 response -> {
96 downloadBehavior.setResponse(new ResponseHolder(response));
97 downloadBehavior.initiate(target);
98 },
99 () -> {
100 SyncopeConsoleSession.get().error(getString(Constants.OPERATION_ERROR));
101 ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
102 });
103 }
104 }, ActionLink.ActionType.EXPORT, IdRepoEntitlement.REPORT_READ);
105 }
106 }
107 }