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