Package org.sonar.api.utils.text

Examples of org.sonar.api.utils.text.JsonWriter


      "{\"transitions\": []}");
  }

  private void testActions(Issue issue, String expected) throws JSONException {
    StringWriter output = new StringWriter();
    JsonWriter jsonWriter = JsonWriter.of(output);
    jsonWriter.beginObject();
    writer.writeActions(issue, jsonWriter);
    jsonWriter.endObject();
    JSONAssert.assertEquals(output.toString(), expected, true);
  }
View Full Code Here


    JSONAssert.assertEquals(output.toString(), expected, true);
  }

  private void testTransitions(Issue issue, String expected) throws JSONException {
    StringWriter output = new StringWriter();
    JsonWriter jsonWriter = JsonWriter.of(output);
    jsonWriter.beginObject();
    writer.writeTransitions(issue, jsonWriter);
    jsonWriter.endObject();
    JSONAssert.assertEquals(output.toString(), expected, true);
  }
View Full Code Here

    return result;
  }

  public String toJson() {
    StringWriter json = new StringWriter();
    JsonWriter writer = JsonWriter.of(json);
    writer.beginArray();
    for (QProfile profile : profiles) {
      writer
        .beginObject()
        .prop("key", profile.getKey())
        .prop("language", profile.getLanguage())
        .prop("name", profile.getName())
        .prop("rulesUpdatedAt", UtcDateUtils.formatDateTime(profile.getRulesUpdatedAt()))
        .endObject();
    }
    writer.endArray();
    writer.close();
    return json.toString();
  }
View Full Code Here

    test(Collections.<DuplicationsParser.Block>emptyList(), "{\"duplications\": [], \"files\": {}}");
  }

  private void test(List<DuplicationsParser.Block> blocks, String expected) throws JSONException {
    StringWriter output = new StringWriter();
    JsonWriter jsonWriter = JsonWriter.of(output);
    jsonWriter.beginObject();
    writer.write(blocks, jsonWriter, session);
    jsonWriter.endObject();
    JSONAssert.assertEquals(output.toString(), expected, true);
  }
View Full Code Here

        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());
        json.prop("desc", widget.getDescription());
        json.prop("col", widget.getColumnIndex());
        json.prop("row", widget.getRowIndex());
        json.prop("configured", widget.getConfigured());
        json.prop("componentId", widget.getResourceId());
        json.name("props").beginArray();
        for (WidgetPropertyDto prop : propertiesByWidget.get(widget.getKey())) {
          json.beginObject();
          json.prop("key", prop.getPropertyKey());
          json.prop("val", prop.getTextValue());
          json.endObject();
        }
        json.endArray().endObject();
      }

      json.endArray();
      json.endObject();
      json.close();
    } finally {
      dbSession.close();
    }
  }
View Full Code Here

  @Override
  public void handle(Request request, Response response) {
    String fileKey = request.mandatoryParam(PARAM_KEY);
    UserSession userSession = UserSession.get();

    JsonWriter json = response.newJsonWriter();
    json.beginObject();

    DbSession session = dbClient.openSession(false);
    try {
      ComponentDto component = dbClient.componentDao().getNullableByKey(session, fileKey);
      if (component == null) {
        throw new NotFoundException(String.format("Component '%s' does not exist", fileKey));
      }
      userSession.checkComponentPermission(UserRole.USER, fileKey);

      List<Period> periodList = periods(component.projectUuid(), session);
      Integer periodIndex = request.paramAsInt(PARAM_PERIOD);
      Date periodDate = periodDate(periodIndex, periodList);

      RulesAggregation rulesAggregation = issueService.findRulesByComponent(component.key(), periodDate, session);
      Multiset<String> severitiesAggregation = issueService.findSeveritiesByComponent(component.key(), periodDate, session);
      Map<String, MeasureDto> measuresByMetricKey = measuresByMetricKey(component, session);

      appendComponent(json, component, userSession, session);
      appendPermissions(json, component, userSession);
      appendPeriods(json, periodList);
      appendIssuesAggregation(json, rulesAggregation, severitiesAggregation);
      appendMeasures(json, measuresByMetricKey, severitiesAggregation, periodIndex);
      appendTabs(json, measuresByMetricKey);
      appendExtensions(json, component, userSession);
      appendManualRules(json);
    } finally {
      MyBatis.closeQuietly(session);
    }

    json.endObject();
    json.close();
  }
View Full Code Here

      request.mandatoryParam(PROFILE_KEY));
    writeResponse(result, response);
  }

  private void writeResponse(BulkChangeResult result, Response response) {
    JsonWriter json = response.newJsonWriter().beginObject();
    json.prop("succeeded", result.countSucceeded());
    json.prop("failed", result.countFailed());
    result.getErrors().writeJsonAsWarnings(json, i18n, UserSession.get().locale());
    json.endObject().close();
  }
View Full Code Here

  private void sendErrors(ServletResponse response, int status, Errors errors) {
    ServletResponse.ServletStream stream = response.stream();
    stream.reset();
    stream.setStatus(status);
    stream.setMediaType(MimeTypes.JSON);
    JsonWriter json = JsonWriter.of(new OutputStreamWriter(stream.output()));

    try {
      json.beginObject();
      errors.writeJson(json, i18n, UserSession.get().locale());
      json.endObject();
    } finally {
      // TODO if close() fails, the runtime exception should not hide the
      // potential exception raised in the try block.
      json.close();
    }
  }
View Full Code Here

    int from = Math.max(request.mandatoryParamAsInt(FROM), 1);
    int to = (Integer) ObjectUtils.defaultIfNull(request.paramAsInt(TO), Integer.MAX_VALUE);
    CoverageService.TYPE type = CoverageService.TYPE.valueOf(request.mandatoryParam(TYPE));

    JsonWriter json = response.newJsonWriter().beginObject();

    Map<Integer, Integer> hits = coverageService.getHits(fileKey, type);
    if (!hits.isEmpty()) {
      Map<Integer, Integer> testCases = coverageService.getTestCases(fileKey, type);
      Map<Integer, Integer> conditions = coverageService.getConditions(fileKey, type);
      Map<Integer, Integer> coveredConditions = coverageService.getCoveredConditions(fileKey, type);
      writeCoverage(hits, testCases, conditions, coveredConditions, from, to, json);
    }

    json.endObject().close();
  }
View Full Code Here

    }
  }

  void handleList(List<Controller> controllers, Request request, Response response) {
    boolean includeInternals = request.mandatoryParamAsBoolean("include_internals");
    JsonWriter writer = response.newJsonWriter();
    writer.beginObject();
    writer.name("webServices").beginArray();

    // sort controllers by path
    Ordering<Controller> ordering = Ordering.natural().onResultOf(new Function<Controller, String>() {
      @Override
      public String apply(Controller controller) {
        return controller.path();
      }
    });
    for (Controller controller : ordering.sortedCopy(controllers)) {
      writeController(writer, controller, includeInternals);
    }
    writer.endArray();
    writer.endObject();
    writer.close();
  }
View Full Code Here

TOP

Related Classes of org.sonar.api.utils.text.JsonWriter

Copyright © 2018 www.massapicom. 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.