Search in sources :

Example 1 with WidgetUpdatedEvent

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.");
}
Also used : WidgetActivityResource(com.epam.ta.reportportal.ws.model.activity.WidgetActivityResource) WidgetUpdatedEvent(com.epam.ta.reportportal.core.events.activity.WidgetUpdatedEvent) Widget(com.epam.ta.reportportal.entity.widget.Widget) UserFilter(com.epam.ta.reportportal.entity.filter.UserFilter) WidgetBuilder(com.epam.ta.reportportal.ws.converter.builders.WidgetBuilder) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Aggregations

WidgetUpdatedEvent (com.epam.ta.reportportal.core.events.activity.WidgetUpdatedEvent)1 UserFilter (com.epam.ta.reportportal.entity.filter.UserFilter)1 Widget (com.epam.ta.reportportal.entity.widget.Widget)1 WidgetBuilder (com.epam.ta.reportportal.ws.converter.builders.WidgetBuilder)1 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)1 WidgetActivityResource (com.epam.ta.reportportal.ws.model.activity.WidgetActivityResource)1