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());
}
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());
}
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");
}
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() + "'");
}
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() + "'");
}
Aggregations