Search in sources :

Example 6 with Dashboard

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());
}
Also used : DashboardCreatedEvent(com.epam.ta.reportportal.core.events.activity.DashboardCreatedEvent) Dashboard(com.epam.ta.reportportal.entity.dashboard.Dashboard) EntryCreatedRS(com.epam.ta.reportportal.ws.model.EntryCreatedRS) DashboardBuilder(com.epam.ta.reportportal.ws.converter.builders.DashboardBuilder)

Example 7 with Dashboard

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.");
}
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 8 with Dashboard

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;
}
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)

Example 9 with Dashboard

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());
}
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) DashboardResource(com.epam.ta.reportportal.ws.model.dashboard.DashboardResource) Dashboard(com.epam.ta.reportportal.entity.dashboard.Dashboard) Test(org.junit.jupiter.api.Test)

Example 10 with Dashboard

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());
}
Also used : Dashboard(com.epam.ta.reportportal.entity.dashboard.Dashboard) CreateDashboardRQ(com.epam.ta.reportportal.ws.model.dashboard.CreateDashboardRQ) EntryCreatedRS(com.epam.ta.reportportal.ws.model.EntryCreatedRS) MvcResult(org.springframework.test.web.servlet.MvcResult) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test)

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