Examples of DashboardDto


Examples of org.sonar.core.dashboard.DashboardDto

  @Override
  public void handle(Request request, Response response) throws Exception {
    DbSession dbSession = dbClient.openSession(false);
    try {
      Integer userId = UserSession.get().userId();
      DashboardDto dashboard = dbClient.dashboardDao().getAllowedByKey(dbSession, request.mandatoryParamAsLong(PARAM_KEY),
        userId != null ? userId.longValue() : null);
      if (dashboard == null) {
        throw new NotFoundException();
      }

      JsonWriter json = response.newJsonWriter();
      json.beginObject();
      json.prop("key", dashboard.getKey());
      json.prop("name", dashboard.getName());
      json.prop("layout", dashboard.getColumnLayout());
      json.prop("desc", dashboard.getDescription());
      json.prop("global", dashboard.getGlobal());
      json.prop("shared", dashboard.getShared());
      if (dashboard.getUserId() != null) {
        UserDto user = dbClient.userDao().getUser(dashboard.getUserId());
        if (user != null) {
          json.name("owner").beginObject();
          // TODO to be shared and extracted from here
          json.prop("login", user.getLogin());
          json.prop("name", user.getName());
          json.endObject();
        }
      }
      // load widgets and related properties
      json.name("widgets").beginArray();
      Collection<WidgetDto> widgets = dbClient.widgetDao().findByDashboard(dbSession, dashboard.getKey());
      ListMultimap<Long, WidgetPropertyDto> propertiesByWidget = WidgetPropertyDto.groupByWidgetId(
        dbClient.widgetPropertyDao().findByDashboard(dbSession, dashboard.getKey()));
      for (WidgetDto widget : widgets) {
        json.beginObject();
        json.prop("id", widget.getId());
        json.prop("key", widget.getWidgetKey());
        json.prop("name", widget.getName());
View Full Code Here

Examples of org.sonar.core.dashboard.DashboardDto

    List<DashboardDto> registeredDashboards = Lists.newArrayList();
    for (DashboardTemplate template : dashboardTemplates) {
      if (shouldRegister(template.getName())) {
        Dashboard dashboard = template.createDashboard();
        DashboardDto dto = register(template.getName(), dashboard);
        if ((dto != null) && (dashboard.isActivated())) {
          registeredDashboards.add(dto);
        }
      }
    }
View Full Code Here

Examples of org.sonar.core.dashboard.DashboardDto

      .setOrderIndex(index);
    activeDashboardDao.insert(activeDashboardDto);
  }

  protected DashboardDto register(String name, Dashboard dashboard) {
    DashboardDto dto = null;
    if (dashboardDao.selectGlobalDashboard(name) == null) {
      dto = createDtoFromExtension(name, dashboard);
      dashboardDao.insert(dto);
    }
    // and save the fact that is has now already been loaded
View Full Code Here

Examples of org.sonar.core.dashboard.DashboardDto

  }

  protected DashboardDto createDtoFromExtension(String name, Dashboard dashboard) {
    Date now = new Date();

    DashboardDto dashboardDto = new DashboardDto()
      .setName(name)
      .setDescription(dashboard.getDescription())
      .setColumnLayout(dashboard.getLayout().getCode())
      .setShared(true)
      .setGlobal(dashboard.isGlobal());
    dashboardDto.setCreatedAt(now).setUpdatedAt(now);

    for (int columnIndex = 1; columnIndex <= dashboard.getLayout().getColumns(); columnIndex++) {
      List<Dashboard.Widget> widgets = dashboard.getWidgetsOfColumn(columnIndex);
      for (int rowIndex = 1; rowIndex <= widgets.size(); rowIndex++) {
        Dashboard.Widget widget = widgets.get(rowIndex - 1);
        WidgetDto widgetDto = new WidgetDto()
          .setWidgetKey(widget.getId())
          .setColumnIndex(columnIndex)
          .setRowIndex(rowIndex)
          .setConfigured(true);
        widgetDto.setCreatedAt(now).setUpdatedAt(now);
        dashboardDto.addWidget(widgetDto);

        for (Entry<String, String> property : widget.getProperties().entrySet()) {
          WidgetPropertyDto propDto = new WidgetPropertyDto()
            .setPropertyKey(property.getKey())
            .setTextValue(property.getValue());
View Full Code Here

Examples of org.sonar.core.dashboard.DashboardDto

  @Test
  public void should_register_and_activate_dashboard() {
    when(fakeDashboardTemplate.createDashboard()).thenReturn(Dashboard.create());

    DashboardDto dashboardDto = task.register("Fake", fakeDashboardTemplate.createDashboard());

    verify(dashboardDao).insert(dashboardDto);
    verify(loadedTemplateDao).insert(eq(new LoadedTemplateDto("Fake", LoadedTemplateDto.DASHBOARD_TYPE)));
  }
View Full Code Here

Examples of org.sonar.core.dashboard.DashboardDto

      .setLayout(DashboardLayout.TWO_COLUMNS_30_70);
    Dashboard.Widget widget = dashboard.addWidget("fake-widget", 1);
    widget.setProperty("fake-property", "fake_metric");
    when(fakeDashboardTemplate.createDashboard()).thenReturn(dashboard);

    DashboardDto dto = task.createDtoFromExtension("Fake", fakeDashboardTemplate.createDashboard());
    assertThat(dto.getUserId()).isNull();
    assertThat(dto.getName()).isEqualTo("Fake");
    assertThat(dto.getDescription()).isNull();
    assertThat(dto.getColumnLayout()).isEqualTo("30%-70%");
    assertThat(dto.getShared()).isTrue();
    assertThat(dto.getGlobal()).isTrue();
    assertThat(dto.getCreatedAt()).isNotNull();
    assertThat(dto.getUpdatedAt()).isNotNull();

    WidgetDto widgetDto = Iterables.getOnlyElement(dto.getWidgets());
    assertThat(widgetDto.getWidgetKey()).isEqualTo("fake-widget");
    assertThat(widgetDto.getDescription()).isNull();
    assertThat(widgetDto.getColumnIndex()).isEqualTo(1);
    assertThat(widgetDto.getRowIndex()).isEqualTo(1);
    assertThat(widgetDto.getConfigured()).isTrue();
View Full Code Here

Examples of org.sonar.core.dashboard.DashboardDto

    assertThat(prop.getTextValue()).isEqualTo("fake_metric");
  }

  @Test
  public void defaultDashboardShouldBeTheFirstActivatedDashboard() {
    DashboardDto defaultDashboard = new DashboardDto().setId(10L).setName(RegisterDashboards.DEFAULT_DASHBOARD_NAME);
    DashboardDto second = new DashboardDto().setId(11L).setName("Bar");
    DashboardDto third = new DashboardDto().setId(12L).setName("Foo");
    List<DashboardDto> dashboards = Arrays.asList(third, defaultDashboard, second);

    task.activate(dashboards);

    verify(activeDashboardDao).insert(argThat(matchActiveDashboardDto(10L, 1)));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.