Search in sources :

Example 11 with Dashboard

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

the class DashboardConverterTest method toSharedEntity.

@Test
void toSharedEntity() {
    final Dashboard dashboard = getDashboard();
    final SharedEntity sharedEntity = DashboardConverter.TO_SHARED_ENTITY.apply(dashboard);
    assertEquals(sharedEntity.getId(), String.valueOf(dashboard.getId()));
    assertEquals(sharedEntity.getName(), dashboard.getName());
    assertEquals(sharedEntity.getDescription(), dashboard.getDescription());
    assertEquals(sharedEntity.getOwner(), dashboard.getOwner());
}
Also used : Dashboard(com.epam.ta.reportportal.entity.dashboard.Dashboard) SharedEntity(com.epam.ta.reportportal.ws.model.SharedEntity) Test(org.junit.jupiter.api.Test)

Example 12 with Dashboard

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

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

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

Example 15 with Dashboard

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

the class UpdateDashboardHandlerImpl method removeWidget.

@Override
public OperationCompletionRS removeWidget(Long widgetId, Long dashboardId, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user) {
    Dashboard dashboard = getShareableDashboardHandler.getPermitted(dashboardId, projectDetails);
    Widget widget = getShareableWidgetHandler.getPermitted(widgetId, projectDetails);
    /*
		 *	if user is an owner of the widget - remove it from all dashboards
		 *	should be replaced with copy
		 */
    if (user.getUsername().equalsIgnoreCase(widget.getOwner())) {
        OperationCompletionRS result = deleteWidget(widget);
        messageBus.publishActivity(new WidgetDeletedEvent(WidgetConverter.TO_ACTIVITY_RESOURCE.apply(widget), user.getUserId(), user.getUsername()));
        return result;
    }
    DashboardWidget toRemove = dashboard.getDashboardWidgets().stream().filter(dashboardWidget -> widget.getId().equals(dashboardWidget.getId().getWidgetId())).findFirst().orElseThrow(() -> new ReportPortalException(ErrorType.WIDGET_NOT_FOUND_IN_DASHBOARD, widgetId, dashboardId));
    dashboardWidgetRepository.delete(toRemove);
    return new OperationCompletionRS("Widget with ID = '" + widget.getId() + "' was successfully removed from the dashboard with ID = '" + dashboard.getId() + "'");
}
Also used : DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) Widget(com.epam.ta.reportportal.entity.widget.Widget) WidgetDeletedEvent(com.epam.ta.reportportal.core.events.activity.WidgetDeletedEvent) Dashboard(com.epam.ta.reportportal.entity.dashboard.Dashboard) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Aggregations

Dashboard (com.epam.ta.reportportal.entity.dashboard.Dashboard)16 DashboardWidget (com.epam.ta.reportportal.entity.dashboard.DashboardWidget)8 Test (org.junit.jupiter.api.Test)8 Widget (com.epam.ta.reportportal.entity.widget.Widget)6 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)4 DashboardWidgetId (com.epam.ta.reportportal.entity.dashboard.DashboardWidgetId)3 DashboardBuilder (com.epam.ta.reportportal.ws.converter.builders.DashboardBuilder)3 DashboardActivityResource (com.epam.ta.reportportal.ws.model.activity.DashboardActivityResource)3 UpdateDashboardRQ (com.epam.ta.reportportal.ws.model.dashboard.UpdateDashboardRQ)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 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)2