Search in sources :

Example 6 with DashboardWidget

use of com.epam.ta.reportportal.entity.dashboard.DashboardWidget in project service-api by reportportal.

the class WidgetConverterTest method toDashboardWidget.

@Test
void toDashboardWidget() {
    final DashboardResource.WidgetObjectModel widgetObjectModel = getWidgetObjectModel();
    final Dashboard dashboard = new Dashboard();
    dashboard.setId(2L);
    dashboard.setName("name");
    final Widget widget = new Widget();
    widget.setName("name");
    widget.setShared(true);
    widget.setOwner("default");
    final DashboardWidget dashboardWidget = WidgetConverter.toDashboardWidget(widgetObjectModel, dashboard, widget, true);
    assertThat(dashboardWidget.getDashboard()).isEqualToComparingFieldByField(dashboard);
    assertThat(dashboardWidget.getWidget()).isEqualToComparingFieldByField(widget);
    assertEquals(dashboardWidget.getHeight(), widgetObjectModel.getWidgetSize().getHeight());
    assertEquals(dashboardWidget.getWidth(), widgetObjectModel.getWidgetSize().getWidth());
    assertEquals(dashboardWidget.getPositionX(), widgetObjectModel.getWidgetPosition().getX());
    assertEquals(dashboardWidget.getPositionY(), widgetObjectModel.getWidgetPosition().getY());
    assertEquals(dashboardWidget.getWidgetName(), widget.getName());
    assertEquals(dashboardWidget.isShare(), widget.isShared());
    assertEquals("default", dashboardWidget.getWidgetOwner());
    assertTrue(dashboardWidget.isCreatedOn());
}
Also used : DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) Widget(com.epam.ta.reportportal.entity.widget.Widget) DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) DashboardResource(com.epam.ta.reportportal.ws.model.dashboard.DashboardResource) Dashboard(com.epam.ta.reportportal.entity.dashboard.Dashboard) Test(org.junit.jupiter.api.Test)

Example 7 with DashboardWidget

use of com.epam.ta.reportportal.entity.dashboard.DashboardWidget in project service-api by reportportal.

the class DashboardBuilderTest method updateDashboard.

@Test
void updateDashboard() {
    final String name = "name";
    final String description = "description";
    final boolean share = true;
    UpdateDashboardRQ updateDashboardRQ = new UpdateDashboardRQ();
    updateDashboardRQ.setName(name);
    updateDashboardRQ.setDescription(description);
    updateDashboardRQ.setShare(share);
    updateDashboardRQ.setWidgets(Collections.singletonList(new DashboardResource.WidgetObjectModel("kek", 1L, new Size(10, 20), new Position(30, 40))));
    DashboardWidget dashboardWidget = new DashboardWidget();
    dashboardWidget.setHeight(5);
    dashboardWidget.setWidth(10);
    dashboardWidget.setPositionX(1);
    dashboardWidget.setPositionY(2);
    dashboardWidget.setId(new DashboardWidgetId(1L, 1L));
    final Dashboard existDashboard = new Dashboard();
    existDashboard.addWidget(dashboardWidget);
    final Dashboard dashboard = new DashboardBuilder(existDashboard).addUpdateRq(updateDashboardRQ).get();
    assertEquals(name, dashboard.getName());
    assertEquals(description, dashboard.getDescription());
    assertEquals(share, dashboard.isShared());
}
Also used : DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) Position(com.epam.ta.reportportal.ws.model.Position) Size(com.epam.ta.reportportal.ws.model.Size) Dashboard(com.epam.ta.reportportal.entity.dashboard.Dashboard) UpdateDashboardRQ(com.epam.ta.reportportal.ws.model.dashboard.UpdateDashboardRQ) DashboardWidgetId(com.epam.ta.reportportal.entity.dashboard.DashboardWidgetId) Test(org.junit.jupiter.api.Test)

Example 8 with DashboardWidget

use of com.epam.ta.reportportal.entity.dashboard.DashboardWidget in project service-api by reportportal.

the class WidgetConverterTest method toObjectModel.

@Test
void toObjectModel() {
    final DashboardWidget dashboardWidget = getDashboardWIdget();
    final DashboardResource.WidgetObjectModel widgetObjectModel = WidgetConverter.TO_OBJECT_MODEL.apply(dashboardWidget);
    assertEquals(widgetObjectModel.getWidgetId(), dashboardWidget.getId().getWidgetId());
    assertEquals(widgetObjectModel.getWidgetPosition().getX(), dashboardWidget.getPositionX());
    assertEquals(widgetObjectModel.getWidgetPosition().getY(), dashboardWidget.getPositionY());
    assertEquals(widgetObjectModel.getWidgetSize().getHeight(), dashboardWidget.getHeight());
    assertEquals(widgetObjectModel.getWidgetSize().getWidth(), dashboardWidget.getWidth());
    assertEquals(dashboardWidget.isShare(), widgetObjectModel.isShare());
}
Also used : DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) DashboardResource(com.epam.ta.reportportal.ws.model.dashboard.DashboardResource) Test(org.junit.jupiter.api.Test)

Example 9 with DashboardWidget

use of com.epam.ta.reportportal.entity.dashboard.DashboardWidget in project service-api by reportportal.

the class UpdateDashboardHandlerImpl method updateDashboard.

@Override
public OperationCompletionRS updateDashboard(ReportPortalUser.ProjectDetails projectDetails, UpdateDashboardRQ rq, Long dashboardId, ReportPortalUser user) {
    Dashboard dashboard = getShareableDashboardHandler.getAdministrated(dashboardId, projectDetails);
    DashboardActivityResource before = TO_ACTIVITY_RESOURCE.apply(dashboard);
    if (!dashboard.getName().equals(rq.getName())) {
        BusinessRule.expect(dashboardRepository.existsByNameAndOwnerAndProjectId(rq.getName(), user.getUsername(), projectDetails.getProjectId()), BooleanUtils::isFalse).verify(ErrorType.RESOURCE_ALREADY_EXISTS, rq.getName());
    }
    dashboard = new DashboardBuilder(dashboard).addUpdateRq(rq).get();
    dashboardRepository.save(dashboard);
    if (before.isShared() != dashboard.isShared()) {
        aclHandler.updateAcl(dashboard, projectDetails.getProjectId(), dashboard.isShared());
        updateWidgetHandler.updateSharing(dashboard.getDashboardWidgets().stream().map(DashboardWidget::getWidget).collect(Collectors.toList()), projectDetails.getProjectId(), dashboard.isShared());
    }
    messageBus.publishActivity(new DashboardUpdatedEvent(before, TO_ACTIVITY_RESOURCE.apply(dashboard), user.getUserId(), user.getUsername()));
    return new OperationCompletionRS("Dashboard with ID = '" + dashboard.getId() + "' successfully updated");
}
Also used : DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) DashboardActivityResource(com.epam.ta.reportportal.ws.model.activity.DashboardActivityResource) DashboardUpdatedEvent(com.epam.ta.reportportal.core.events.activity.DashboardUpdatedEvent) Dashboard(com.epam.ta.reportportal.entity.dashboard.Dashboard) DashboardBuilder(com.epam.ta.reportportal.ws.converter.builders.DashboardBuilder) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Example 10 with DashboardWidget

use of com.epam.ta.reportportal.entity.dashboard.DashboardWidget 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

DashboardWidget (com.epam.ta.reportportal.entity.dashboard.DashboardWidget)12 Dashboard (com.epam.ta.reportportal.entity.dashboard.Dashboard)9 Widget (com.epam.ta.reportportal.entity.widget.Widget)6 DashboardWidgetId (com.epam.ta.reportportal.entity.dashboard.DashboardWidgetId)5 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)4 UpdateDashboardRQ (com.epam.ta.reportportal.ws.model.dashboard.UpdateDashboardRQ)3 Test (org.junit.jupiter.api.Test)3 ShareableObjectsHandler (com.epam.ta.reportportal.auth.acl.ShareableObjectsHandler)2 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)2 MessageBus (com.epam.ta.reportportal.core.events.MessageBus)2 DashboardUpdatedEvent (com.epam.ta.reportportal.core.events.activity.DashboardUpdatedEvent)2 WidgetDeletedEvent (com.epam.ta.reportportal.core.events.activity.WidgetDeletedEvent)2 GetShareableEntityHandler (com.epam.ta.reportportal.core.shareable.GetShareableEntityHandler)2 WidgetContentRemover (com.epam.ta.reportportal.core.widget.content.remover.WidgetContentRemover)2 DashboardRepository (com.epam.ta.reportportal.dao.DashboardRepository)2 DashboardWidgetRepository (com.epam.ta.reportportal.dao.DashboardWidgetRepository)2 WidgetRepository (com.epam.ta.reportportal.dao.WidgetRepository)2 Project (com.epam.ta.reportportal.entity.project.Project)2 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)2 DashboardBuilder (com.epam.ta.reportportal.ws.converter.builders.DashboardBuilder)2