use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project sonarqube by SonarSource.
the class ScannerWsClient method tryParseAsJsonError.
public static String tryParseAsJsonError(String responseContent) {
try {
JsonParser parser = new JsonParser();
JsonObject obj = parser.parse(responseContent).getAsJsonObject();
JsonArray errors = obj.getAsJsonArray("errors");
List<String> errorMessages = new ArrayList<>();
for (JsonElement e : errors) {
errorMessages.add(e.getAsJsonObject().get("msg").getAsString());
}
return Joiner.on(", ").join(errorMessages);
} catch (Exception e) {
return responseContent;
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project sonarqube by SonarSource.
the class QualityGateDetailsData method toJson.
private static JsonObject toJson(EvaluatedCondition evaluatedCondition) {
Condition condition = evaluatedCondition.getCondition();
JsonObject result = new JsonObject();
result.addProperty("metric", condition.getMetric().getKey());
result.addProperty("op", condition.getOperator().getDbValue());
if (condition.hasPeriod()) {
result.addProperty("period", 1);
}
if (condition.getWarningThreshold() != null) {
result.addProperty("warning", condition.getWarningThreshold());
}
if (condition.getErrorThreshold() != null) {
result.addProperty("error", condition.getErrorThreshold());
}
result.addProperty("actual", evaluatedCondition.getActualValue());
result.addProperty(FIELD_LEVEL, evaluatedCondition.getLevel().name());
return result;
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project sonarqube by SonarSource.
the class QualityGateDetailsData method toJson.
public String toJson() {
JsonObject details = new JsonObject();
details.addProperty(FIELD_LEVEL, level.toString());
JsonArray conditionResults = new JsonArray();
for (EvaluatedCondition condition : this.conditions) {
conditionResults.add(toJson(condition));
}
details.add("conditions", conditionResults);
return details.toString();
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project che by eclipse.
the class JsonRpcEntityQualifier method qualify.
public JsonRpcEntityType qualify(String message) {
checkNotNull(message, "Message must not be null");
checkArgument(!message.isEmpty(), "Message must not be empty");
LOG.debug("Qualifying message: " + message);
JsonObject jsonObject = jsonParser.parse(message).getAsJsonObject();
LOG.debug("Json keys: " + jsonObject.entrySet().stream().map(Map.Entry::getKey).collect(Collectors.toSet()));
if (jsonObject.has("method")) {
LOG.debug("Qualified to request");
return JsonRpcEntityType.REQUEST;
} else if (jsonObject.has("error") != jsonObject.has("result")) {
LOG.debug("Qualified to response");
return JsonRpcEntityType.RESPONSE;
} else {
LOG.debug("Qualified to undefined");
return JsonRpcEntityType.UNDEFINED;
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project che by eclipse.
the class JsonRpcError method toJsonObject.
public JsonObject toJsonObject() {
JsonObject error = new JsonObject();
error.addProperty("code", code);
error.addProperty("message", message);
return error;
}
Aggregations