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() + "'");
}
Aggregations