Search in sources :

Example 1 with DashboardWidget

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

the class DashboardBuilder method addUpdateRq.

public DashboardBuilder addUpdateRq(UpdateDashboardRQ rq) {
    Optional.ofNullable(rq.getName()).ifPresent(name -> dashboard.setName(name));
    Optional.ofNullable(rq.getDescription()).ifPresent(description -> dashboard.setDescription(description));
    Optional.ofNullable(rq.getShare()).ifPresent(share -> dashboard.setShared(share));
    Optional.ofNullable(rq.getWidgets()).ifPresent(widgets -> {
        for (DashboardWidget dashboardWidget : dashboard.getDashboardWidgets()) {
            widgets.stream().filter(updWidget -> Objects.equals(dashboardWidget.getId().getWidgetId(), updWidget.getWidgetId())).forEach(updWidget -> {
                ofNullable(updWidget.getWidgetPosition()).ifPresent(position -> {
                    dashboardWidget.setPositionX(position.getX());
                    dashboardWidget.setPositionY(position.getY());
                });
                ofNullable(updWidget.getWidgetSize()).ifPresent(size -> {
                    dashboardWidget.setWidth(size.getWidth());
                    dashboardWidget.setHeight(size.getHeight());
                });
            });
        }
    });
    return this;
}
Also used : Dashboard(com.epam.ta.reportportal.entity.dashboard.Dashboard) Objects(java.util.Objects) Project(com.epam.ta.reportportal.entity.project.Project) UpdateDashboardRQ(com.epam.ta.reportportal.ws.model.dashboard.UpdateDashboardRQ) Optional.ofNullable(java.util.Optional.ofNullable) Optional(java.util.Optional) Supplier(java.util.function.Supplier) DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) CreateDashboardRQ(com.epam.ta.reportportal.ws.model.dashboard.CreateDashboardRQ) DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget)

Example 2 with DashboardWidget

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

the class WidgetConverter method toDashboardWidget.

/**
 * Creates many-to-many object representation of dashboards and widgets
 *
 * @param model     Widget model object
 * @param dashboard Dashboard
 * @param widget    Widget
 * @return many-to-many object representation
 */
public static DashboardWidget toDashboardWidget(DashboardResource.WidgetObjectModel model, Dashboard dashboard, Widget widget, boolean isCreatedOn) {
    DashboardWidgetId id = new DashboardWidgetId();
    id.setDashboardId(dashboard.getId());
    id.setWidgetId(model.getWidgetId());
    DashboardWidget dashboardWidget = new DashboardWidget();
    dashboardWidget.setId(id);
    dashboardWidget.setWidgetType(widget.getWidgetType());
    dashboardWidget.setWidgetName(widget.getName());
    dashboardWidget.setPositionX(model.getWidgetPosition().getX());
    dashboardWidget.setPositionY(model.getWidgetPosition().getY());
    dashboardWidget.setWidth(model.getWidgetSize().getWidth());
    dashboardWidget.setHeight(model.getWidgetSize().getHeight());
    dashboardWidget.setDashboard(dashboard);
    dashboardWidget.setShare(widget.isShared());
    dashboardWidget.setWidget(widget);
    dashboardWidget.setCreatedOn(isCreatedOn);
    dashboardWidget.setWidgetOwner(widget.getOwner());
    return dashboardWidget;
}
Also used : DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) DashboardWidgetId(com.epam.ta.reportportal.entity.dashboard.DashboardWidgetId)

Example 3 with DashboardWidget

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

the class DashboardConverterTest method getDashboard.

private static Dashboard getDashboard() {
    Dashboard dashboard = new Dashboard();
    dashboard.setId(1L);
    dashboard.setName("name");
    dashboard.setDescription("description");
    dashboard.setCreationDate(LocalDateTime.now());
    dashboard.setOwner("owner");
    final Project project = new Project();
    project.setId(2L);
    dashboard.setProject(project);
    dashboard.setShared(true);
    final DashboardWidget dashboardWidget = new DashboardWidget();
    dashboardWidget.setId(new DashboardWidgetId(1L, 3L));
    dashboardWidget.setPositionY(2);
    dashboardWidget.setPositionX(3);
    dashboardWidget.setWidth(5);
    dashboardWidget.setHeight(6);
    dashboardWidget.setWidgetName("widgetName");
    dashboardWidget.setDashboard(dashboard);
    final Widget widget = new Widget();
    dashboardWidget.setWidget(widget);
    dashboard.addWidget(dashboardWidget);
    return dashboard;
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) Widget(com.epam.ta.reportportal.entity.widget.Widget) DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) Dashboard(com.epam.ta.reportportal.entity.dashboard.Dashboard) DashboardWidgetId(com.epam.ta.reportportal.entity.dashboard.DashboardWidgetId)

Example 4 with DashboardWidget

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

the class DeleteDashboardHandlerImpl method deleteDashboard.

@Override
public OperationCompletionRS deleteDashboard(Long dashboardId, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user) {
    Dashboard dashboard = getShareableEntityHandler.getAdministrated(dashboardId, projectDetails);
    Set<DashboardWidget> dashboardWidgets = dashboard.getDashboardWidgets();
    List<Widget> widgets = dashboardWidgets.stream().filter(DashboardWidget::isCreatedOn).map(DashboardWidget::getWidget).peek(aclHandler::deleteAclForObject).peek(widget -> widgetContentRemovers.forEach(remover -> remover.removeContent(widget))).collect(Collectors.toList());
    dashboardWidgets.addAll(widgets.stream().flatMap(w -> w.getDashboardWidgets().stream()).collect(toSet()));
    aclHandler.deleteAclForObject(dashboard);
    dashboardWidgetRepository.deleteAll(dashboardWidgets);
    dashboardRepository.delete(dashboard);
    widgetRepository.deleteAll(widgets);
    messageBus.publishActivity(new DashboardDeletedEvent(TO_ACTIVITY_RESOURCE.apply(dashboard), user.getUserId(), user.getUsername()));
    return new OperationCompletionRS("Dashboard with ID = '" + dashboardId + "' successfully deleted.");
}
Also used : ShareableObjectsHandler(com.epam.ta.reportportal.auth.acl.ShareableObjectsHandler) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS) WidgetContentRemover(com.epam.ta.reportportal.core.widget.content.remover.WidgetContentRemover) DashboardRepository(com.epam.ta.reportportal.dao.DashboardRepository) DeleteDashboardHandler(com.epam.ta.reportportal.core.dashboard.DeleteDashboardHandler) DashboardWidgetRepository(com.epam.ta.reportportal.dao.DashboardWidgetRepository) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) DashboardDeletedEvent(com.epam.ta.reportportal.core.events.activity.DashboardDeletedEvent) MessageBus(com.epam.ta.reportportal.core.events.MessageBus) Collectors(java.util.stream.Collectors) GetShareableEntityHandler(com.epam.ta.reportportal.core.shareable.GetShareableEntityHandler) WidgetRepository(com.epam.ta.reportportal.dao.WidgetRepository) Dashboard(com.epam.ta.reportportal.entity.dashboard.Dashboard) List(java.util.List) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) TO_ACTIVITY_RESOURCE(com.epam.ta.reportportal.ws.converter.converters.DashboardConverter.TO_ACTIVITY_RESOURCE) Service(org.springframework.stereotype.Service) Widget(com.epam.ta.reportportal.entity.widget.Widget) Collectors.toSet(java.util.stream.Collectors.toSet) DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) Widget(com.epam.ta.reportportal.entity.widget.Widget) DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) Dashboard(com.epam.ta.reportportal.entity.dashboard.Dashboard) DashboardDeletedEvent(com.epam.ta.reportportal.core.events.activity.DashboardDeletedEvent) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Example 5 with DashboardWidget

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

the class WidgetConverterTest method getDashboardWIdget.

private static DashboardWidget getDashboardWIdget() {
    final DashboardWidget dashboardWidget = new DashboardWidget();
    final Widget widget = new Widget();
    widget.setId(1L);
    dashboardWidget.setWidget(widget);
    final Dashboard dashboard = new Dashboard();
    dashboard.setId(2L);
    dashboardWidget.setId(new DashboardWidgetId(dashboard.getId(), widget.getId()));
    dashboardWidget.setDashboard(dashboard);
    dashboardWidget.setPositionX(2);
    dashboardWidget.setPositionY(4);
    dashboardWidget.setHeight(5);
    dashboardWidget.setWidth(6);
    return dashboardWidget;
}
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) Dashboard(com.epam.ta.reportportal.entity.dashboard.Dashboard) DashboardWidgetId(com.epam.ta.reportportal.entity.dashboard.DashboardWidgetId)

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