Search in sources :

Example 1 with DashboardDeletedEvent

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.");
}
Also used : ShareableObjectsHandler(com.epam.ta.reportportal.auth.acl.ShareableObjectsHandler) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS) WidgetContentRemover(com.epam.ta.reportportal.core.widget.content.remover.WidgetContentRemover) DashboardRepository(com.epam.ta.reportportal.dao.DashboardRepository) DeleteDashboardHandler(com.epam.ta.reportportal.core.dashboard.DeleteDashboardHandler) DashboardWidgetRepository(com.epam.ta.reportportal.dao.DashboardWidgetRepository) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) DashboardDeletedEvent(com.epam.ta.reportportal.core.events.activity.DashboardDeletedEvent) MessageBus(com.epam.ta.reportportal.core.events.MessageBus) Collectors(java.util.stream.Collectors) GetShareableEntityHandler(com.epam.ta.reportportal.core.shareable.GetShareableEntityHandler) WidgetRepository(com.epam.ta.reportportal.dao.WidgetRepository) Dashboard(com.epam.ta.reportportal.entity.dashboard.Dashboard) List(java.util.List) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) TO_ACTIVITY_RESOURCE(com.epam.ta.reportportal.ws.converter.converters.DashboardConverter.TO_ACTIVITY_RESOURCE) Service(org.springframework.stereotype.Service) Widget(com.epam.ta.reportportal.entity.widget.Widget) Collectors.toSet(java.util.stream.Collectors.toSet) DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) Widget(com.epam.ta.reportportal.entity.widget.Widget) DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) Dashboard(com.epam.ta.reportportal.entity.dashboard.Dashboard) DashboardDeletedEvent(com.epam.ta.reportportal.core.events.activity.DashboardDeletedEvent) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Aggregations

ShareableObjectsHandler (com.epam.ta.reportportal.auth.acl.ShareableObjectsHandler)1 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)1 DeleteDashboardHandler (com.epam.ta.reportportal.core.dashboard.DeleteDashboardHandler)1 MessageBus (com.epam.ta.reportportal.core.events.MessageBus)1 DashboardDeletedEvent (com.epam.ta.reportportal.core.events.activity.DashboardDeletedEvent)1 GetShareableEntityHandler (com.epam.ta.reportportal.core.shareable.GetShareableEntityHandler)1 WidgetContentRemover (com.epam.ta.reportportal.core.widget.content.remover.WidgetContentRemover)1 DashboardRepository (com.epam.ta.reportportal.dao.DashboardRepository)1 DashboardWidgetRepository (com.epam.ta.reportportal.dao.DashboardWidgetRepository)1 WidgetRepository (com.epam.ta.reportportal.dao.WidgetRepository)1 Dashboard (com.epam.ta.reportportal.entity.dashboard.Dashboard)1 DashboardWidget (com.epam.ta.reportportal.entity.dashboard.DashboardWidget)1 Widget (com.epam.ta.reportportal.entity.widget.Widget)1 TO_ACTIVITY_RESOURCE (com.epam.ta.reportportal.ws.converter.converters.DashboardConverter.TO_ACTIVITY_RESOURCE)1 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1