Search in sources :

Example 1 with WidgetDeletedEvent

use of com.epam.ta.reportportal.core.events.activity.WidgetDeletedEvent in project service-api by reportportal.

the class UpdateDashboardHandlerImpl method removeWidget.

@Override
public OperationCompletionRS removeWidget(Long widgetId, Long dashboardId, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user) {
    Dashboard dashboard = getShareableDashboardHandler.getPermitted(dashboardId, projectDetails);
    Widget widget = getShareableWidgetHandler.getPermitted(widgetId, projectDetails);
    /*
		 *	if user is an owner of the widget - remove it from all dashboards
		 *	should be replaced with copy
		 */
    if (user.getUsername().equalsIgnoreCase(widget.getOwner())) {
        OperationCompletionRS result = deleteWidget(widget);
        messageBus.publishActivity(new WidgetDeletedEvent(WidgetConverter.TO_ACTIVITY_RESOURCE.apply(widget), user.getUserId(), user.getUsername()));
        return result;
    }
    DashboardWidget toRemove = dashboard.getDashboardWidgets().stream().filter(dashboardWidget -> widget.getId().equals(dashboardWidget.getId().getWidgetId())).findFirst().orElseThrow(() -> new ReportPortalException(ErrorType.WIDGET_NOT_FOUND_IN_DASHBOARD, widgetId, dashboardId));
    dashboardWidgetRepository.delete(toRemove);
    return new OperationCompletionRS("Widget with ID = '" + widget.getId() + "' was successfully removed from the dashboard with ID = '" + dashboard.getId() + "'");
}
Also used : DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) Widget(com.epam.ta.reportportal.entity.widget.Widget) WidgetDeletedEvent(com.epam.ta.reportportal.core.events.activity.WidgetDeletedEvent) Dashboard(com.epam.ta.reportportal.entity.dashboard.Dashboard) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Aggregations

WidgetDeletedEvent (com.epam.ta.reportportal.core.events.activity.WidgetDeletedEvent)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 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)1 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)1