Search in sources :

Example 1 with UpdateDashboardRQ

use of com.epam.ta.reportportal.ws.model.dashboard.UpdateDashboardRQ in project service-api by reportportal.

the class DashboardBuilder method addUpdateRq.

public DashboardBuilder addUpdateRq(UpdateDashboardRQ rq) {
    Optional.ofNullable(rq.getName()).ifPresent(name -> dashboard.setName(name));
    Optional.ofNullable(rq.getDescription()).ifPresent(description -> dashboard.setDescription(description));
    Optional.ofNullable(rq.getShare()).ifPresent(share -> dashboard.setShared(share));
    Optional.ofNullable(rq.getWidgets()).ifPresent(widgets -> {
        for (DashboardWidget dashboardWidget : dashboard.getDashboardWidgets()) {
            widgets.stream().filter(updWidget -> Objects.equals(dashboardWidget.getId().getWidgetId(), updWidget.getWidgetId())).forEach(updWidget -> {
                ofNullable(updWidget.getWidgetPosition()).ifPresent(position -> {
                    dashboardWidget.setPositionX(position.getX());
                    dashboardWidget.setPositionY(position.getY());
                });
                ofNullable(updWidget.getWidgetSize()).ifPresent(size -> {
                    dashboardWidget.setWidth(size.getWidth());
                    dashboardWidget.setHeight(size.getHeight());
                });
            });
        }
    });
    return this;
}
Also used : Dashboard(com.epam.ta.reportportal.entity.dashboard.Dashboard) Objects(java.util.Objects) Project(com.epam.ta.reportportal.entity.project.Project) UpdateDashboardRQ(com.epam.ta.reportportal.ws.model.dashboard.UpdateDashboardRQ) Optional.ofNullable(java.util.Optional.ofNullable) Optional(java.util.Optional) Supplier(java.util.function.Supplier) DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget) CreateDashboardRQ(com.epam.ta.reportportal.ws.model.dashboard.CreateDashboardRQ) DashboardWidget(com.epam.ta.reportportal.entity.dashboard.DashboardWidget)

Example 2 with UpdateDashboardRQ

use of com.epam.ta.reportportal.ws.model.dashboard.UpdateDashboardRQ in project service-api by reportportal.

the class DashboardControllerTest method updateDashboardPositive.

@Test
void updateDashboardPositive() throws Exception {
    final UpdateDashboardRQ rq = new UpdateDashboardRQ();
    rq.setName("updated");
    rq.setDescription("updated");
    rq.setShare(false);
    mockMvc.perform(put(DEFAULT_PROJECT_BASE_URL + "/dashboard/17").with(token(oAuthHelper.getDefaultToken())).content(objectMapper.writeValueAsBytes(rq)).contentType(APPLICATION_JSON)).andExpect(status().isOk());
    final Optional<Dashboard> optionalDashboard = dashboardRepository.findById(17L);
    assertTrue(optionalDashboard.isPresent());
    assertEquals("updated", optionalDashboard.get().getName());
    assertEquals("updated", optionalDashboard.get().getDescription());
    assertFalse(optionalDashboard.get().isShared());
}
Also used : Dashboard(com.epam.ta.reportportal.entity.dashboard.Dashboard) UpdateDashboardRQ(com.epam.ta.reportportal.ws.model.dashboard.UpdateDashboardRQ) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test)

Example 3 with UpdateDashboardRQ

use of com.epam.ta.reportportal.ws.model.dashboard.UpdateDashboardRQ 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)

Aggregations

Dashboard (com.epam.ta.reportportal.entity.dashboard.Dashboard)3 UpdateDashboardRQ (com.epam.ta.reportportal.ws.model.dashboard.UpdateDashboardRQ)3 DashboardWidget (com.epam.ta.reportportal.entity.dashboard.DashboardWidget)2 Test (org.junit.jupiter.api.Test)2 DashboardWidgetId (com.epam.ta.reportportal.entity.dashboard.DashboardWidgetId)1 Project (com.epam.ta.reportportal.entity.project.Project)1 BaseMvcTest (com.epam.ta.reportportal.ws.BaseMvcTest)1 Position (com.epam.ta.reportportal.ws.model.Position)1 Size (com.epam.ta.reportportal.ws.model.Size)1 CreateDashboardRQ (com.epam.ta.reportportal.ws.model.dashboard.CreateDashboardRQ)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Optional.ofNullable (java.util.Optional.ofNullable)1 Supplier (java.util.function.Supplier)1