<commit_before>package com.xing.qa.selenium.grid.hub;

import com.google.gson.JsonObject;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.openqa.grid.common.SeleniumProtocol;
import org.openqa.grid.internal.RemoteProxy;
import org.openqa.grid.internal.TestSession;
import org.openqa.grid.internal.TestSlot;
import org.openqa.grid.web.servlet.beta.MiniCapability;
import org.openqa.grid.web.servlet.beta.SlotsLines;
import org.openqa.selenium.remote.CapabilityType;

/**
 * Renderer that presents data on a WebProxy as JSON object.
 *
 * @author <NAME> (<EMAIL>)
 */
public class WebProxyJsonRenderer implements JSONRenderer {

    private final RemoteProxy proxy;

    public WebProxyJsonRenderer(RemoteProxy proxy) {
        this.proxy = proxy;
    }

    @Override
    public JSONObject render() throws JSONException {
        JSONObject json = new JSONObject();
        JsonObject status = proxy.getStatus();
        json.put("class", proxy.getClass().getSimpleName());

        try {
            json.put("version",
                    status.getAsJsonObject("value").getAsJsonObject("build").getAsJsonPrimitive("version").getAsString());
        } catch (JSONException e) {
            json.put("version", "unknown");
            json.put("error", e.getMessage());
            json.put("trace", e.getStackTrace());
            e.printStackTrace();
        }

        json.put("os", status.getAsJsonObject("value").getAsJsonPrimitive("os").getAsString());
        json.put("java", status.getAsJsonObject("value").getAsJsonObject("java").getAsJsonPrimitive("version").getAsString());
        json.put("configuration", proxy.getConfig());

        SlotsLines rcLines = new SlotsLines();
        SlotsLines wdLines = new SlotsLines();

        for (TestSlot slot : proxy.getTestSlots()) {
            if (slot.getProtocol() == SeleniumProtocol.Selenium) {
                rcLines.add(slot);
            } else {<commit_msg>Fix WebProxyJsonRenderer to serialize os-property of node successfully<commit_after>package com.xing.qa.selenium.grid.hub;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.openqa.grid.common.SeleniumProtocol;
import org.openqa.grid.internal.RemoteProxy;
import org.openqa.grid.internal.TestSession;
import org.openqa.grid.internal.TestSlot;
import org.openqa.grid.web.servlet.beta.MiniCapability;
import org.openqa.grid.web.servlet.beta.SlotsLines;
import org.openqa.selenium.remote.CapabilityType;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * Renderer that presents data on a WebProxy as JSON object.
 *
 * @author <NAME> (<EMAIL>)
 */
public class WebProxyJsonRenderer implements JSONRenderer {

    private final RemoteProxy proxy;

    public WebProxyJsonRenderer(RemoteProxy proxy) {
        this.proxy = proxy;
    }

    @Override
    public JSONObject render() throws JSONException {
        JSONObject json = new JSONObject();
        JsonObject status = proxy.getStatus();
        json.put("class", proxy.getClass().getSimpleName());

        try {
            json.put("version",
                    status.getAsJsonObject("value").getAsJsonObject("build").getAsJsonPrimitive("version").getAsString());
        } catch (JSONException e) {
            json.put("version", "unknown");
            json.put("error", e.getMessage());
            json.put("trace", e.getStackTrace());
            e.printStackTrace();
        }

        Set<Map.Entry<String, JsonElement>> os = status.getAsJsonObject("value").getAsJsonObject("os").entrySet();
        Map<String, String> osProperties = new HashMap<>();
        for(Map.Entry<String, JsonElement> entry : os) {
            osProperties.put(entry.getKey(), entry.getValue().getAsString());
        }
        json.put("os", osProperties);
        json.put("java", status.getAsJsonObject("value").getAsJsonObject("java").getAsJsonPrimitive("version").getAsString());
        json.put("configuration", proxy.getConfig());

        SlotsLines rcLines = new SlotsLines();
        SlotsLines wdLines = new SlotsLines();

        for (TestSlot slot : proxy.getTestSlots()) {
            if (slot.getProtocol() == SeleniumProtocol.Selenium) {
                rcLines.add(slot);
            } else {
{'fraction_non_alphanumeric': 0.13174748398902103, 'fraction_numerical': 0.0, 'mean_word_length': 3.2830558276199806, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6273243', 'n_tokens_mistral': 1252, 'n_tokens_neox': 1236, 'n_words': 234}