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.pages;
20
21 import de.agilecoders.wicket.core.markup.html.bootstrap.tabs.AjaxBootstrapTabbedPanel;
22 import java.util.ArrayList;
23 import java.util.List;
24 import org.apache.syncope.client.console.BookmarkablePageLinkBuilder;
25 import org.apache.syncope.client.console.SyncopeConsoleSession;
26 import org.apache.syncope.client.console.annotations.AMPage;
27 import org.apache.syncope.client.console.panels.AMSessionPanel;
28 import org.apache.syncope.client.console.panels.SRARouteDirectoryPanel;
29 import org.apache.syncope.client.console.panels.SRAStatisticsPanel;
30 import org.apache.syncope.client.console.rest.SRARouteRestClient;
31 import org.apache.syncope.client.console.rest.SRASessionRestClient;
32 import org.apache.syncope.client.ui.commons.Constants;
33 import org.apache.syncope.common.keymaster.client.api.ServiceOps;
34 import org.apache.syncope.common.keymaster.client.api.model.NetworkService;
35 import org.apache.syncope.common.lib.types.AMEntitlement;
36 import org.apache.wicket.ajax.AjaxRequestTarget;
37 import org.apache.wicket.ajax.markup.html.AjaxLink;
38 import org.apache.wicket.extensions.markup.html.tabs.AbstractTab;
39 import org.apache.wicket.extensions.markup.html.tabs.ITab;
40 import org.apache.wicket.markup.html.WebMarkupContainer;
41 import org.apache.wicket.markup.html.panel.Panel;
42 import org.apache.wicket.model.ResourceModel;
43 import org.apache.wicket.request.mapper.parameter.PageParameters;
44 import org.apache.wicket.spring.injection.annot.SpringBean;
45
46 @AMPage(label = "SRA", icon = "fas fa-share-alt", listEntitlement = "", priority = 100)
47 public class SRA extends BasePage {
48
49 private static final long serialVersionUID = 9200112197134882164L;
50
51 @SpringBean
52 private SRARouteRestClient sraRouteRestClient;
53
54 @SpringBean
55 private ServiceOps serviceOps;
56
57 public SRA(final PageParameters parameters) {
58 super(parameters);
59
60 body.add(BookmarkablePageLinkBuilder.build("dashboard", "dashboardBr", Dashboard.class));
61 body.setOutputMarkupId(true);
62
63 List<NetworkService> instances = serviceOps.list(NetworkService.Type.SRA);
64
65 AjaxLink<?> push = new AjaxLink<>("push") {
66
67 private static final long serialVersionUID = -817438685948164787L;
68
69 @Override
70 public void onClick(final AjaxRequestTarget target) {
71 try {
72 sraRouteRestClient.push();
73 SyncopeConsoleSession.get().success(getString(Constants.OPERATION_SUCCEEDED));
74 } catch (Exception e) {
75 LOG.error("While pushing to SRA", e);
76 SyncopeConsoleSession.get().onException(e);
77 }
78 ((BasePage) getPageReference().getPage()).getNotificationPanel().refresh(target);
79 }
80 };
81 push.setEnabled(!instances.isEmpty() && SyncopeConsoleSession.get().owns(AMEntitlement.SRA_ROUTE_PUSH));
82 body.add(push);
83
84 WebMarkupContainer content = new WebMarkupContainer("content");
85 content.setOutputMarkupId(true);
86 AjaxBootstrapTabbedPanel<ITab> tabbedPanel =
87 new AjaxBootstrapTabbedPanel<>("tabbedPanel", buildTabList(instances));
88 content.add(tabbedPanel);
89
90 body.add(content);
91 }
92
93 private List<ITab> buildTabList(final List<NetworkService> instances) {
94 List<ITab> tabs = new ArrayList<>();
95
96 tabs.add(new AbstractTab(new ResourceModel("routes")) {
97
98 private static final long serialVersionUID = 5211692813425391144L;
99
100 @Override
101 public Panel getPanel(final String panelId) {
102 return new SRARouteDirectoryPanel(panelId, sraRouteRestClient, getPageReference());
103 }
104 });
105
106 if (!instances.isEmpty()) {
107 tabs.add(new AbstractTab(new ResourceModel("metrics")) {
108
109 private static final long serialVersionUID = 5211692813425391144L;
110
111 @Override
112 public Panel getPanel(final String panelId) {
113 return new SRAStatisticsPanel(panelId, instances);
114 }
115 });
116 }
117
118 if (!instances.isEmpty() && SyncopeConsoleSession.get().owns(AMEntitlement.SRA_SESSION_LIST)) {
119 tabs.add(new AbstractTab(new ResourceModel("sessions")) {
120
121 private static final long serialVersionUID = 5211692813425391144L;
122
123 @Override
124 public Panel getPanel(final String panelId) {
125 return new AMSessionPanel(panelId, new SRASessionRestClient(instances),
126 AMEntitlement.SRA_SESSION_LIST, AMEntitlement.SRA_SESSION_DELETE, getPageReference());
127 }
128 });
129 }
130
131 return tabs;
132 }
133 }