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.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   * Modal window with report executions.
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 }