use of com.epam.ta.reportportal.core.events.activity.WidgetUpdatedEvent in project service-api by reportportal.
the class UpdateWidgetHandlerImpl method updateWidget.
@Override
public OperationCompletionRS updateWidget(Long widgetId, WidgetRQ updateRQ, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user) {
Widget widget = getShareableEntityHandler.getAdministrated(widgetId, projectDetails);
widgetContentFieldsValidator.validate(widget);
if (!widget.getName().equals(updateRQ.getName())) {
BusinessRule.expect(widgetRepository.existsByNameAndOwnerAndProjectId(updateRQ.getName(), user.getUsername(), projectDetails.getProjectId()), BooleanUtils::isFalse).verify(ErrorType.RESOURCE_ALREADY_EXISTS, updateRQ.getName());
}
WidgetActivityResource before = TO_ACTIVITY_RESOURCE.apply(widget);
List<UserFilter> userFilter = getUserFilters(updateRQ.getFilterIds(), projectDetails.getProjectId(), user.getUsername());
String widgetOptionsBefore = parseWidgetOptions(widget);
updateSharing(widget, projectDetails.getProjectId(), updateRQ.getShare());
widget = new WidgetBuilder(widget).addWidgetRq(updateRQ).addFilters(userFilter).get();
widgetRepository.save(widget);
messageBus.publishActivity(new WidgetUpdatedEvent(before, TO_ACTIVITY_RESOURCE.apply(widget), widgetOptionsBefore, parseWidgetOptions(widget), user.getUserId(), user.getUsername()));
return new OperationCompletionRS("Widget with ID = '" + widget.getId() + "' successfully updated.");
}
Aggregations