private void writeResponse(Response response, List<CustomMeasureDto> customMeasures, int nbCustomMeasures, ComponentDto project, Map<Integer, MetricDto> metricsById, Map<String, UserDto> usersByUuid, @Nullable Long lastAnalysisDate, SearchOptions searchOptions, @Nullable List<String> fieldsToReturn) { JsonWriter json = response.newJsonWriter(); json.beginObject(); writeUsers(json, customMeasures, project, metricsById, usersByUuid, lastAnalysisDate, fieldsToReturn); searchOptions.writeJson(json, nbCustomMeasures); json.endObject(); json.close(); }
@Test public void writeJson() { SearchOptions options = new SearchOptions().setPage(3, 10); StringWriter json = new StringWriter(); JsonWriter jsonWriter = JsonWriter.of(json).beginObject(); options.writeJson(jsonWriter, 42L); jsonWriter.endObject().close(); JsonAssert.assertJson(json.toString()).isSimilarTo("{\"total\": 42, \"p\": 3, \"ps\": 10}"); }
@Override public void handle(Request request, Response response) throws Exception { SearchOptions searchOptions = new SearchOptions() .setPage(request.mandatoryParamAsInt(Param.PAGE), request.mandatoryParamAsInt(Param.PAGE_SIZE)); Boolean isCustom = request.paramAsBoolean(PARAM_IS_CUSTOM); try (DbSession dbSession = dbClient.openSession(false)) { List<MetricDto> metrics = dbClient.metricDao().selectEnabled(dbSession, isCustom, searchOptions.getOffset(), searchOptions.getLimit()); int nbMetrics = dbClient.metricDao().countEnabled(dbSession, isCustom); JsonWriter json = response.newJsonWriter(); json.beginObject(); Set<String> desiredFields = desiredFields(request.paramAsStrings(Param.FIELDS)); writeMetrics(json, metrics, desiredFields); searchOptions.writeJson(json, nbMetrics); json.endObject(); json.close(); } }
@Override public void handle(Request request, Response response) throws Exception { userSession.checkLoggedIn(); SearchOptions searchOptions = new SearchOptions() .setPage(request.mandatoryParamAsInt(Param.PAGE), request.mandatoryParamAsInt(Param.PAGE_SIZE)); Set<String> desiredFields = fieldsToReturn(request.paramAsStrings(Param.FIELDS)); String query = request.param(Param.TEXT_QUERY); try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = getOrganization(dbSession, request); userSession.checkPermission(ADMINISTER, organization); long nbOfProjects = dbClient.componentDao().countGhostProjects(dbSession, organization.getUuid(), query); List<ComponentDto> projects = dbClient.componentDao().selectGhostProjects(dbSession, organization.getUuid(), query, searchOptions.getOffset(), searchOptions.getLimit()); try (JsonWriter json = response.newJsonWriter()) { json.beginObject(); writeProjects(json, projects, desiredFields); searchOptions.writeJson(json, nbOfProjects); json.endObject(); } } }
private void writeResponse(Response response, List<CustomMeasureDto> customMeasures, int nbCustomMeasures, ComponentDto project, Map<Integer, MetricDto> metricsById, Map<String, UserDto> usersByUuid, @Nullable Long lastAnalysisDate, SearchOptions searchOptions, @Nullable List<String> fieldsToReturn) { JsonWriter json = response.newJsonWriter(); json.beginObject(); writeUsers(json, customMeasures, project, metricsById, usersByUuid, lastAnalysisDate, fieldsToReturn); searchOptions.writeJson(json, nbCustomMeasures); json.endObject(); json.close(); }
@Override public void handle(Request request, Response response) throws Exception { SearchOptions searchOptions = new SearchOptions() .setPage(request.mandatoryParamAsInt(Param.PAGE), request.mandatoryParamAsInt(Param.PAGE_SIZE)); Boolean isCustom = request.paramAsBoolean(PARAM_IS_CUSTOM); try (DbSession dbSession = dbClient.openSession(false)) { List<MetricDto> metrics = dbClient.metricDao().selectEnabled(dbSession, isCustom, searchOptions.getOffset(), searchOptions.getLimit()); int nbMetrics = dbClient.metricDao().countEnabled(dbSession, isCustom); JsonWriter json = response.newJsonWriter(); json.beginObject(); Set<String> desiredFields = desiredFields(request.paramAsStrings(Param.FIELDS)); writeMetrics(json, metrics, desiredFields); searchOptions.writeJson(json, nbMetrics); json.endObject(); json.close(); } }
@Override public void handle(Request request, Response response) throws Exception { userSession.checkLoggedIn(); SearchOptions searchOptions = new SearchOptions() .setPage(request.mandatoryParamAsInt(Param.PAGE), request.mandatoryParamAsInt(Param.PAGE_SIZE)); Set<String> desiredFields = fieldsToReturn(request.paramAsStrings(Param.FIELDS)); String query = request.param(Param.TEXT_QUERY); try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = getOrganization(dbSession, request); userSession.checkPermission(ADMINISTER, organization); long nbOfProjects = dbClient.componentDao().countGhostProjects(dbSession, organization.getUuid(), query); List<ComponentDto> projects = dbClient.componentDao().selectGhostProjects(dbSession, organization.getUuid(), query, searchOptions.getOffset(), searchOptions.getLimit()); try (JsonWriter json = response.newJsonWriter()) { json.beginObject(); writeProjects(json, projects, desiredFields); searchOptions.writeJson(json, nbOfProjects); json.endObject(); } } }