Search in sources :

Example 1 with WidgetActivityResource

use of com.epam.ta.reportportal.ws.model.activity.WidgetActivityResource in project service-api by reportportal.

the class WidgetEventsTest method getWidget.

private static WidgetActivityResource getWidget(String name, boolean shared, String description, int itemsCount, Set<String> contentFields) {
    WidgetActivityResource widget = new WidgetActivityResource();
    widget.setName(name);
    widget.setId(2L);
    widget.setDescription(description);
    widget.setShared(shared);
    widget.setProjectId(3L);
    widget.setItemsCount(itemsCount);
    widget.setContentFields(contentFields);
    return widget;
}
Also used : WidgetActivityResource(com.epam.ta.reportportal.ws.model.activity.WidgetActivityResource)

Example 2 with WidgetActivityResource

use of com.epam.ta.reportportal.ws.model.activity.WidgetActivityResource in project service-api by reportportal.

the class WidgetConverterTest method toActivityResource.

@Test
void toActivityResource() {
    final Widget widget = getWidget();
    final WidgetActivityResource resource = WidgetConverter.TO_ACTIVITY_RESOURCE.apply(widget);
    assertEquals(resource.getId(), widget.getId());
    assertEquals(resource.getName(), widget.getName());
    assertEquals(resource.getProjectId(), widget.getProject().getId());
    assertEquals(resource.getDescription(), widget.getDescription());
    assertEquals(resource.getItemsCount(), widget.getItemsCount());
    assertEquals(resource.getContentFields(), widget.getContentFields());
    assertThat(resource.getWidgetOptions()).containsAllEntriesOf(widget.getWidgetOptions().getOptions());
}
Also used : WidgetActivityResource(com.epam.ta.reportportal.ws.model.activity.WidgetActivityResource) Widget(com.epam.ta.reportportal.entity.widget.Widget) DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) Test(org.junit.jupiter.api.Test)

Example 3 with WidgetActivityResource

use of com.epam.ta.reportportal.ws.model.activity.WidgetActivityResource 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

WidgetActivityResource (com.epam.ta.reportportal.ws.model.activity.WidgetActivityResource)3 Widget (com.epam.ta.reportportal.entity.widget.Widget)2 WidgetUpdatedEvent (com.epam.ta.reportportal.core.events.activity.WidgetUpdatedEvent)1 DashboardWidget (com.epam.ta.reportportal.entity.dashboard.DashboardWidget)1 UserFilter (com.epam.ta.reportportal.entity.filter.UserFilter)1 WidgetBuilder (com.epam.ta.reportportal.ws.converter.builders.WidgetBuilder)1 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)1 Test (org.junit.jupiter.api.Test)1