Example usage for com.google.gson JsonObject get

List of usage examples for com.google.gson JsonObject get

Introduction

In this page you can find the example usage for com.google.gson JsonObject get.

Prototype

public JsonElement get(String memberName) 

Source Link

Document

Returns the member with the specified name.

Usage

From source file:cl.niclabs.tscrypto.common.messages.TSMessageParser.java

License:Open Source License

@Override
public TSMessage deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {

    JsonObject jobject = (JsonObject) json;
    String type = jobject.get("type").getAsString();
    String version = jobject.get("version").getAsString();

    // TODO check version

    if (type.equals("encrypted-data")) {
        return context.deserialize(json, EncryptedData.class);
    } else if (type.matches(".*-query")) {
        return parseQuery(type, version, json, context);
    } else if (type.matches(".*-answer")) {
        return parseAnswer(type, version, json, context);
    }//  w w w .j  av  a 2s. c  om

    throw new JsonParseException("Illegal TSMessage type/version:" + type + "/" + version);
}

From source file:classes.analysis.Analysis.java

License:Open Source License

private static Analysis parseAnalysisGalaxyData(String origin, String emsuser, JsonObject analysisData) {
    JsonParser parser = new JsonParser();
    JsonArray provenance = (JsonArray) parser.parse(analysisData.get("provenance").getAsString());

    //STEP 1. Find the associations between the steps (inputs and outputs)
    HashMap<String, JsonElement> outputs = new HashMap<String, JsonElement>();
    JsonObject stepJSONobject;/*from   ww  w. j  a va 2  s  .co  m*/
    for (JsonElement step_json : provenance) {
        stepJSONobject = step_json.getAsJsonObject();
        for (JsonElement output : stepJSONobject.getAsJsonArray("outputs")) {
            outputs.put(output.getAsJsonObject().get("id").getAsString(), step_json);
        }

        if ("upload1".equalsIgnoreCase(stepJSONobject.get("tool_id").getAsString())) {
            stepJSONobject.remove("step_type");
            stepJSONobject.add("step_type", new JsonPrimitive("external_source"));
        } else {
            stepJSONobject.add("step_type", new JsonPrimitive("processed_data"));
        }
    }
    for (JsonElement step_json : provenance) {
        stepJSONobject = step_json.getAsJsonObject();
        for (JsonElement input : stepJSONobject.getAsJsonArray("inputs")) {
            String id = input.getAsJsonObject().get("id").getAsString();
            if (outputs.containsKey(id)) {
                if (!"external_source"
                        .equalsIgnoreCase(outputs.get(id).getAsJsonObject().get("step_type").getAsString())) {
                    outputs.get(id).getAsJsonObject().remove("step_type");
                    outputs.get(id).getAsJsonObject().add("step_type", new JsonPrimitive("intermediate_data"));
                }

                if (!stepJSONobject.has("used_data")) {
                    stepJSONobject.add("used_data", new JsonArray());
                }
                ((JsonArray) stepJSONobject.get("used_data")).add(new JsonPrimitive(
                        "STxxxx." + outputs.get(id).getAsJsonObject().get("id").getAsString()));
            }
        }
    }

    //STEP 2. Create the instances for the steps
    ArrayList<NonProcessedData> nonProcessedDataList = new ArrayList<NonProcessedData>();
    ArrayList<ProcessedData> processedDataList = new ArrayList<ProcessedData>();
    for (JsonElement step_json : provenance) {
        stepJSONobject = step_json.getAsJsonObject();
        if ("external_source".equalsIgnoreCase(stepJSONobject.get("step_type").getAsString())) {
            nonProcessedDataList.add(ExternalData.parseStepGalaxyData(stepJSONobject, analysisData, emsuser));
        } else if ("intermediate_data".equalsIgnoreCase(stepJSONobject.get("step_type").getAsString())) {
            nonProcessedDataList
                    .add(IntermediateData.parseStepGalaxyData(stepJSONobject, analysisData, emsuser));
        } else if ("processed_data".equalsIgnoreCase(stepJSONobject.get("step_type").getAsString())) {
            processedDataList.add(ProcessedData.parseStepGalaxyData(stepJSONobject, analysisData, emsuser));
        } else {
            throw new InstantiationError("Unknown step type");
        }
    }

    Collections.sort(nonProcessedDataList);
    Collections.sort(processedDataList);

    //STEP 3. Create the instance of analysis
    Analysis analysis = new Analysis();
    analysis.setAnalysisName(analysisData.get("ems_analysis_name").getAsString());
    analysis.setAnalysisType("Galaxy workflow");
    analysis.setNonProcessedData(nonProcessedDataList.toArray(new NonProcessedData[] {}));
    analysis.setProcessedData(processedDataList.toArray(new ProcessedData[] {}));
    analysis.setTags(new String[] { "imported" });
    analysis.setStatus("pending");

    return analysis;
}

From source file:classes.analysis.Analysis.java

License:Open Source License

private ArrayList<Pair> processElementContent(String templatesDir, String jsonObject)
        throws FileNotFoundException {
    ArrayList<Pair> elements = new ArrayList<Pair>();
    ArrayList<Pair> fields = processTemplateFile(templatesDir + File.separator + "analysis-form.json");
    JsonObject analysis = new JsonParser().parse(jsonObject).getAsJsonObject();

    elements.add(new Pair("Analysis details", "", 0, "title"));
    elements.add(new Pair("", "", 1, "section"));
    for (Pair field : fields) {
        elements.add(new Pair(field.value, this.getJsonElementAsString(analysis.get(field.label)), 2, "field"));
    }/*from w ww. j  a v a  2 s. com*/

    elements.add(new Pair("Steps in the analysis", "", 0, "title"));
    elements.add(new Pair("", "", 0, "section"));
    JsonArray steps = analysis.get("non_processed_data").getAsJsonArray();
    JsonObject step;
    for (JsonElement _step : steps) {
        step = _step.getAsJsonObject();
        String type = this.getJsonElementAsString(step.get("type"));
        if ("rawdata".equalsIgnoreCase(type)) {
            type = "Raw data step";
        } else {
            type = type.substring(0, 1).toUpperCase() + type.substring(1);
            type = type.replaceAll("_", " ");
        }
        elements.add(new Pair(type, "", 1, "title"));
        elements.add(new Pair("", "", 1, "section"));
        fields = processTemplateFile(
                templatesDir + File.separator + step.get("type").getAsString() + "-form.json");
        for (Pair field : fields) {
            elements.add(new Pair(field.value, this.getJsonElementAsString(step.get(field.label)), 2, "field"));
        }
    }

    steps = analysis.get("processed_data").getAsJsonArray();
    for (JsonElement _step : steps) {
        step = _step.getAsJsonObject();
        String type = this.getJsonElementAsString(step.get("type"));
        type = type.substring(0, 1).toUpperCase() + type.substring(1);
        type = type.replaceAll("_", " ");
        elements.add(new Pair(type, "", 1, "title"));
        elements.add(new Pair("", "", 1, "section"));
        fields = processTemplateFile(
                templatesDir + File.separator + step.get("type").getAsString() + "-form.json");
        for (Pair field : fields) {
            elements.add(new Pair(field.value, this.getJsonElementAsString(step.get(field.label)), 2, "field"));
        }
    }

    return elements;
}

From source file:classes.analysis.non_processed_data.ExternalData.java

License:Open Source License

public static ExternalData parseStepGalaxyData(JsonObject step_json_object, JsonObject analysisData,
        String emsuser) {/*from www.j  a va 2  s. co m*/
    ExternalData step = new ExternalData("STxxxx." + step_json_object.get("id").getAsString());

    String prefix = analysisData.get("experiment_id").getAsString() + "/"
            + analysisData.get("analysis_id").getAsString() + "/";
    ArrayList<String> outputs = new ArrayList<String>();
    for (JsonElement output : step_json_object.get("outputs").getAsJsonArray()) {
        outputs.add(prefix + output.getAsJsonObject().get("file").getAsString().replaceAll(" ", "_") + "."
                + output.getAsJsonObject().get("extension").getAsString());
    }
    step.setFilesLocation(outputs.toArray(new String[] {}));

    Date dateNow = new Date();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
    step.setSubmissionDate(dateFormat.format(dateNow));
    step.setLastEditionDate(dateFormat.format(dateNow));
    step.addOwner(new User(emsuser, ""));
    step.setStepName(step_json_object.get("tool_id").getAsString());
    step.setStepNumber(step_json_object.get("id").getAsInt());

    return step;
}

From source file:classes.analysis.non_processed_data.IntermediateData.java

License:Open Source License

public static IntermediateData parseStepGalaxyData(JsonObject step_json_object, JsonObject analysisData,
        String emsuser) {//w w  w  .  j  a va 2 s  .co m
    IntermediateData step = new IntermediateData("STxxxx." + step_json_object.get("id").getAsString());
    step.setIntermediateDataType("preprocessing_step");
    step.setSoftware(step_json_object.get("tool_id").getAsString());
    step.setSoftwareVersion(step_json_object.get("tool_version").getAsString());
    HashSet<String> used_data = new HashSet<String>();
    if (step_json_object.has("used_data")) {
        for (JsonElement data : step_json_object.get("used_data").getAsJsonArray()) {
            used_data.add(data.getAsString());
        }
    }
    step.setUsedData(used_data.toArray(new String[] {}));

    String prefix = analysisData.get("experiment_id").getAsString() + "/"
            + analysisData.get("analysis_id").getAsString() + "/";
    ArrayList<String> outputs = new ArrayList<String>();
    for (JsonElement output : step_json_object.get("outputs").getAsJsonArray()) {
        outputs.add(prefix + output.getAsJsonObject().get("file").getAsString().replaceAll(" ", "_") + "."
                + output.getAsJsonObject().get("extension").getAsString());
    }
    step.setFilesLocation(outputs.toArray(new String[] {}));

    String description = "Step " + step_json_object.get("id").getAsString() + " in Galaxy history "
            + analysisData.get("history_id").getAsString() + ".\n";
    description += "The tool exited with code " + step_json_object.get("exit_code").getAsString() + "\n";
    description += "Outputs:\n";
    for (JsonElement output : step_json_object.get("outputs").getAsJsonArray()) {
        description += "  - " + output.getAsJsonObject().get("file").getAsString() + " (id:"
                + output.getAsJsonObject().get("id").getAsString() + ")\n";
    }
    step.setResults(description);

    description = "Step inputs:\n";
    for (JsonElement input : step_json_object.get("inputs").getAsJsonArray()) {
        description += "  - " + input.getAsJsonObject().get("file").getAsString() + " (id:"
                + input.getAsJsonObject().get("id").getAsString() + ")\n";
    }
    description += "\n";
    description += "Parameters:\n";
    for (JsonElement input : step_json_object.get("parameters").getAsJsonArray()) {
        description += Step.getParameterDescription(input.getAsJsonObject(), 1);
    }

    step.setSoftwareConfiguration(description);

    Date dateNow = new Date();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
    step.setSubmissionDate(dateFormat.format(dateNow));
    step.setLastEditionDate(dateFormat.format(dateNow));
    step.addOwner(new User(emsuser, ""));
    if (step_json_object.has("step_name")) {
        step.setStepName(step_json_object.get("step_name").getAsString());
    } else {
        step.setStepName(step_json_object.get("tool_id").getAsString());
    }
    step.setStepNumber(step_json_object.get("id").getAsInt());

    return step;
}

From source file:classes.analysis.ProcessedData.java

License:Open Source License

public static ProcessedData parseStepGalaxyData(JsonObject step_json_object, JsonObject analysisData,
        String emsuser) {//  ww  w  .  j a v a  2 s .  c  om
    ProcessedData step = new ProcessedData("STxxxx." + step_json_object.get("id").getAsString());
    step.setProcessedDataType("quantification_step");
    step.setSoftware(step_json_object.get("tool_id").getAsString());
    step.setSoftwareVersion(step_json_object.get("tool_version").getAsString());
    HashSet<String> used_data = new HashSet<String>();
    if (step_json_object.has("used_data")) {
        for (JsonElement data : step_json_object.get("used_data").getAsJsonArray()) {
            used_data.add(data.getAsString());
        }
    }
    step.setUsedData(used_data.toArray(new String[] {}));

    String prefix = analysisData.get("experiment_id").getAsString() + "/"
            + analysisData.get("analysis_id").getAsString() + "/";
    ArrayList<String> outputs = new ArrayList<String>();
    for (JsonElement output : step_json_object.get("outputs").getAsJsonArray()) {
        outputs.add(prefix + output.getAsJsonObject().get("file").getAsString().replaceAll(" ", "_") + "."
                + output.getAsJsonObject().get("extension").getAsString());
    }
    step.setFilesLocation(outputs.toArray(new String[] {}));

    String description = "Step " + step_json_object.get("id").getAsString() + " in Galaxy history "
            + analysisData.get("history_id").getAsString() + ".\n";
    description += "The tool exited with code " + step_json_object.get("exit_code").getAsString() + "\n";
    description += "Outputs:\n";
    for (JsonElement output : step_json_object.get("outputs").getAsJsonArray()) {
        description += "  - " + output.getAsJsonObject().get("file").getAsString() + " (id:"
                + output.getAsJsonObject().get("id").getAsString() + ")\n";
    }
    step.setResults(description);

    description = "Step inputs:\n";
    for (JsonElement input : step_json_object.get("inputs").getAsJsonArray()) {
        description += "  - " + input.getAsJsonObject().get("file").getAsString() + " (id:"
                + input.getAsJsonObject().get("id").getAsString() + ")\n";
    }
    description += "\n";
    description += "Parameters:\n";
    for (JsonElement input : step_json_object.get("parameters").getAsJsonArray()) {
        description += Step.getParameterDescription(input.getAsJsonObject(), 1);
    }

    step.setSoftwareConfiguration(description);

    Date dateNow = new Date();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
    step.setSubmissionDate(dateFormat.format(dateNow));
    step.setLastEditionDate(dateFormat.format(dateNow));
    step.addOwner(new User(emsuser, ""));
    step.setStepName(step_json_object.get("tool_id").getAsString());
    step.setStepNumber(step_json_object.get("id").getAsInt());

    return step;
}

From source file:classes.Experiment.java

License:Open Source License

private ArrayList<Pair> processElementContent(String templatesDir, String jsonObject)
        throws FileNotFoundException {
    ArrayList<Pair> elements = new ArrayList<Pair>();
    ArrayList<Pair> fields = processTemplateFile(templatesDir + File.separator + "experiment-form.json");
    JsonObject analysis = new JsonParser().parse(jsonObject).getAsJsonObject();

    elements.add(new Pair("Study details", "", 0, "title"));
    elements.add(new Pair("", "", 1, "section"));
    for (Pair field : fields) {
        elements.add(new Pair(field.value, this.getJsonElementAsString(analysis.get(field.label)), 2, "field"));
    }/*  w  ww .ja v  a 2  s  . c om*/

    return elements;
}

From source file:classes.samples.BioCondition.java

License:Open Source License

private ArrayList<Pair> processElementContent(String templatesDir, String jsonObject)
        throws FileNotFoundException {
    ArrayList<Pair> elements = new ArrayList<Pair>();
    ArrayList<Pair> fields = processTemplateFile(templatesDir + File.separator + "biocondition-form.json");
    JsonObject analysis = new JsonParser().parse(jsonObject).getAsJsonObject();

    elements.add(new Pair("Biological conditions details", "", 0, "title"));
    elements.add(new Pair("", "", 1, "section"));
    for (Pair field : fields) {
        elements.add(new Pair(field.value, this.getJsonElementAsString(analysis.get(field.label)), 2, "field"));
    }/*  w ww .  jav a2s .c  o m*/

    elements.add(new Pair("Samples in the analysis", "", 0, "title"));
    elements.add(new Pair("", "", 0, "section"));
    JsonArray samples = analysis.get("associatedBioreplicates").getAsJsonArray();
    JsonObject sample;
    for (JsonElement _step : samples) {
        sample = _step.getAsJsonObject();
        elements.add(new Pair("Sample", "", 1, "title"));
        elements.add(new Pair("", "", 1, "section"));
        fields = processTemplateFile(templatesDir + File.separator + "bioreplicate-form.json");
        for (Pair field : fields) {
            elements.add(
                    new Pair(field.value, this.getJsonElementAsString(sample.get(field.label)), 2, "field"));
        }

        elements.add(new Pair("Aliquouts", "", 2, "title"));
        elements.add(new Pair("", "", 2, "section"));
        JsonArray aliquots = sample.get("associatedAnalyticalReplicates").getAsJsonArray();
        for (JsonElement aliquot : aliquots) {
            sample = aliquot.getAsJsonObject();
            fields = processTemplateFile(templatesDir + File.separator + "analytical_replicate-form.json");
            for (Pair field : fields) {
                elements.add(new Pair(field.value, this.getJsonElementAsString(sample.get(field.label)), 3,
                        "field"));
            }
        }
    }

    return elements;
}

From source file:client.apis.TwitchAPI.java

License:Apache License

public boolean isLive(String channel) {
    JsonObject js = this.GET("https://api.twitch.tv/kraken/streams/" + channel);
    return js.get("stream") != null;
}

From source file:client.commands.AutoPoints.java

License:Apache License

private void process(String chan, TwitchAPI api) {
    JsonObject js = api.GET("http://tmi.twitch.tv/group/user/" + chan + "/chatters").get("chatters")
            .getAsJsonObject();/*from w w  w . ja  va 2s  .co m*/
    this.addPoints(js.get("moderators").getAsJsonArray(), ptsToAdd, chan);
    this.addPoints(js.get("staff").getAsJsonArray(), ptsToAdd, chan);
    this.addPoints(js.get("admins").getAsJsonArray(), ptsToAdd, chan);
    this.addPoints(js.get("global_mods").getAsJsonArray(), ptsToAdd, chan);
    this.addPoints(js.get("viewers").getAsJsonArray(), ptsToAdd, chan);
}