use of com.epam.ta.reportportal.entity.dashboard.Dashboard in project service-api by reportportal.
the class CreateDashboardHandlerImpl method createDashboard.
@Override
public EntryCreatedRS createDashboard(ReportPortalUser.ProjectDetails projectDetails, CreateDashboardRQ rq, ReportPortalUser user) {
BusinessRule.expect(dashboardRepository.existsByNameAndOwnerAndProjectId(rq.getName(), user.getUsername(), projectDetails.getProjectId()), BooleanUtils::isFalse).verify(ErrorType.RESOURCE_ALREADY_EXISTS, rq.getName());
Dashboard dashboard = new DashboardBuilder().addDashboardRq(rq).addProject(projectDetails.getProjectId()).addOwner(user.getUsername()).get();
dashboardRepository.save(dashboard);
aclHandler.initAcl(dashboard, user.getUsername(), projectDetails.getProjectId(), BooleanUtils.isTrue(rq.getShare()));
messageBus.publishActivity(new DashboardCreatedEvent(TO_ACTIVITY_RESOURCE.apply(dashboard), user.getUserId(), user.getUsername()));
return new EntryCreatedRS(dashboard.getId());
}
use of com.epam.ta.reportportal.entity.dashboard.Dashboard 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.");
}
use of com.epam.ta.reportportal.entity.dashboard.Dashboard 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;
}
use of com.epam.ta.reportportal.entity.dashboard.Dashboard 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.Dashboard in project service-api by reportportal.
the class DashboardControllerTest method createDashboardPositive.
@Test
void createDashboardPositive() throws Exception {
CreateDashboardRQ createDashboardRQ = new CreateDashboardRQ();
createDashboardRQ.setName("dashboard");
createDashboardRQ.setDescription("description");
final MvcResult mvcResult = mockMvc.perform(post(DEFAULT_PROJECT_BASE_URL + "/dashboard").with(token(oAuthHelper.getDefaultToken())).content(objectMapper.writeValueAsBytes(createDashboardRQ)).contentType(APPLICATION_JSON)).andExpect(status().isCreated()).andReturn();
final EntryCreatedRS entryCreatedRS = objectMapper.readValue(mvcResult.getResponse().getContentAsString(), EntryCreatedRS.class);
final Optional<Dashboard> dashboardOptional = dashboardRepository.findById(entryCreatedRS.getId());
assertTrue(dashboardOptional.isPresent());
assertEquals("dashboard", dashboardOptional.get().getName());
assertEquals("description", dashboardOptional.get().getDescription());
}
Aggregations