use of com.epam.ta.reportportal.core.events.activity.DashboardDeletedEvent in project service-api by reportportal.
the class DeleteDashboardHandlerImpl method deleteDashboard.
@Override
public OperationCompletionRS deleteDashboard(Long dashboardId, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user) {
Dashboard dashboard = getShareableEntityHandler.getAdministrated(dashboardId, projectDetails);
Set<DashboardWidget> dashboardWidgets = dashboard.getDashboardWidgets();
List<Widget> widgets = dashboardWidgets.stream().filter(DashboardWidget::isCreatedOn).map(DashboardWidget::getWidget).peek(aclHandler::deleteAclForObject).peek(widget -> widgetContentRemovers.forEach(remover -> remover.removeContent(widget))).collect(Collectors.toList());
dashboardWidgets.addAll(widgets.stream().flatMap(w -> w.getDashboardWidgets().stream()).collect(toSet()));
aclHandler.deleteAclForObject(dashboard);
dashboardWidgetRepository.deleteAll(dashboardWidgets);
dashboardRepository.delete(dashboard);
widgetRepository.deleteAll(widgets);
messageBus.publishActivity(new DashboardDeletedEvent(TO_ACTIVITY_RESOURCE.apply(dashboard), user.getUserId(), user.getUsername()));
return new OperationCompletionRS("Dashboard with ID = '" + dashboardId + "' successfully deleted.");
}
Aggregations