Search in sources :

Example 1 with AddWidgetRq

use of com.epam.ta.reportportal.ws.model.dashboard.AddWidgetRq in project service-api by reportportal.

the class DashboardControllerTest method addWidget.

@Test
void addWidget() throws Exception {
    AddWidgetRq rq = new AddWidgetRq();
    rq.setAddWidget(new DashboardResource.WidgetObjectModel("kek", 10L, new Size(5, 5), new Position(0, 0)));
    mockMvc.perform(put(DEFAULT_PROJECT_BASE_URL + "/dashboard/17/add").with(token(oAuthHelper.getDefaultToken())).contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(rq))).andExpect(status().isOk());
}
Also used : AddWidgetRq(com.epam.ta.reportportal.ws.model.dashboard.AddWidgetRq) Position(com.epam.ta.reportportal.ws.model.Position) Size(com.epam.ta.reportportal.ws.model.Size) DashboardResource(com.epam.ta.reportportal.ws.model.dashboard.DashboardResource) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test)

Example 2 with AddWidgetRq

use of com.epam.ta.reportportal.ws.model.dashboard.AddWidgetRq in project service-api by reportportal.

the class UpdateDashboardHandlerImpl method addWidget.

@Override
public OperationCompletionRS addWidget(Long dashboardId, ReportPortalUser.ProjectDetails projectDetails, AddWidgetRq rq, ReportPortalUser user) {
    Dashboard dashboard = getShareableDashboardHandler.getAdministrated(dashboardId, projectDetails);
    BusinessRule.expect(dashboard.getDashboardWidgets().stream().map(dw -> dw.getId().getWidgetId()).anyMatch(widgetId -> widgetId.equals(rq.getAddWidget().getWidgetId())), BooleanUtils::isFalse).verify(ErrorType.DASHBOARD_UPDATE_ERROR, Suppliers.formattedSupplier("Widget with ID = '{}' is already added to the dashboard with ID = '{}'", rq.getAddWidget().getWidgetId(), dashboard.getId()));
    Widget widget = getShareableWidgetHandler.getPermitted(rq.getAddWidget().getWidgetId(), projectDetails);
    boolean isCreatedOnDashboard = CollectionUtils.isEmpty(widget.getDashboardWidgets());
    DashboardWidget dashboardWidget = WidgetConverter.toDashboardWidget(rq.getAddWidget(), dashboard, widget, isCreatedOnDashboard);
    dashboardWidgetRepository.save(dashboardWidget);
    return new OperationCompletionRS("Widget with ID = '" + widget.getId() + "' was successfully added to the dashboard with ID = '" + dashboard.getId() + "'");
}
Also used : WidgetConverter(com.epam.ta.reportportal.ws.converter.converters.WidgetConverter) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS) UpdateDashboardRQ(com.epam.ta.reportportal.ws.model.dashboard.UpdateDashboardRQ) DashboardRepository(com.epam.ta.reportportal.dao.DashboardRepository) AddWidgetRq(com.epam.ta.reportportal.ws.model.dashboard.AddWidgetRq) Autowired(org.springframework.beans.factory.annotation.Autowired) BooleanUtils(org.apache.commons.lang3.BooleanUtils) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) MessageBus(com.epam.ta.reportportal.core.events.MessageBus) GetShareableEntityHandler(com.epam.ta.reportportal.core.shareable.GetShareableEntityHandler) Dashboard(com.epam.ta.reportportal.entity.dashboard.Dashboard) DashboardActivityResource(com.epam.ta.reportportal.ws.model.activity.DashboardActivityResource) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) TO_ACTIVITY_RESOURCE(com.epam.ta.reportportal.ws.converter.converters.DashboardConverter.TO_ACTIVITY_RESOURCE) CollectionUtils(org.apache.commons.collections.CollectionUtils) UpdateWidgetHandler(com.epam.ta.reportportal.core.widget.UpdateWidgetHandler) Service(org.springframework.stereotype.Service) DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) BusinessRule(com.epam.ta.reportportal.commons.validation.BusinessRule) UpdateDashboardHandler(com.epam.ta.reportportal.core.dashboard.UpdateDashboardHandler) ShareableObjectsHandler(com.epam.ta.reportportal.auth.acl.ShareableObjectsHandler) WidgetContentRemover(com.epam.ta.reportportal.core.widget.content.remover.WidgetContentRemover) DashboardWidgetRepository(com.epam.ta.reportportal.dao.DashboardWidgetRepository) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) DashboardUpdatedEvent(com.epam.ta.reportportal.core.events.activity.DashboardUpdatedEvent) Collectors(java.util.stream.Collectors) WidgetRepository(com.epam.ta.reportportal.dao.WidgetRepository) List(java.util.List) DashboardBuilder(com.epam.ta.reportportal.ws.converter.builders.DashboardBuilder) Widget(com.epam.ta.reportportal.entity.widget.Widget) Suppliers(com.epam.ta.reportportal.commons.validation.Suppliers) WidgetDeletedEvent(com.epam.ta.reportportal.core.events.activity.WidgetDeletedEvent) DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) Widget(com.epam.ta.reportportal.entity.widget.Widget) Dashboard(com.epam.ta.reportportal.entity.dashboard.Dashboard) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Aggregations

AddWidgetRq (com.epam.ta.reportportal.ws.model.dashboard.AddWidgetRq)2 ShareableObjectsHandler (com.epam.ta.reportportal.auth.acl.ShareableObjectsHandler)1 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)1 BusinessRule (com.epam.ta.reportportal.commons.validation.BusinessRule)1 Suppliers (com.epam.ta.reportportal.commons.validation.Suppliers)1 UpdateDashboardHandler (com.epam.ta.reportportal.core.dashboard.UpdateDashboardHandler)1 MessageBus (com.epam.ta.reportportal.core.events.MessageBus)1 DashboardUpdatedEvent (com.epam.ta.reportportal.core.events.activity.DashboardUpdatedEvent)1 WidgetDeletedEvent (com.epam.ta.reportportal.core.events.activity.WidgetDeletedEvent)1 GetShareableEntityHandler (com.epam.ta.reportportal.core.shareable.GetShareableEntityHandler)1 UpdateWidgetHandler (com.epam.ta.reportportal.core.widget.UpdateWidgetHandler)1 WidgetContentRemover (com.epam.ta.reportportal.core.widget.content.remover.WidgetContentRemover)1 DashboardRepository (com.epam.ta.reportportal.dao.DashboardRepository)1 DashboardWidgetRepository (com.epam.ta.reportportal.dao.DashboardWidgetRepository)1 WidgetRepository (com.epam.ta.reportportal.dao.WidgetRepository)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 BaseMvcTest (com.epam.ta.reportportal.ws.BaseMvcTest)1