Example usage for com.google.gson JsonElement getAsJsonObject

List of usage examples for com.google.gson JsonElement getAsJsonObject

Introduction

In this page you can find the example usage for com.google.gson JsonElement getAsJsonObject.

Prototype

public JsonObject getAsJsonObject() 

Source Link

Document

convenience method to get this element as a JsonObject .

Usage

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) {/*from   ww w.  j a  va2 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. ja  v a 2 s.c  o  m*/
    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.analysis.Step.java

License:Open Source License

protected static String getParameterDescription(JsonElement parameter, int level) {
    if (parameter.isJsonPrimitive()) {
        return parameter.getAsString() + "\n";
    }/*  w  ww.ja  va 2 s.  c  o  m*/

    if (parameter.isJsonArray()) {
        String description = "";
        String prefix = "";
        for (int i = 0; i < level; i++) {
            prefix += "  ";
        }

        for (JsonElement element : parameter.getAsJsonArray()) {
            description += prefix + Step.getParameterDescription(element, level + 1);
        }

        return description;
    }

    if (parameter.isJsonObject()) {
        String description = "";
        String prefix = "";
        for (int i = 0; i < level; i++) {
            prefix += "  ";
        }

        for (Map.Entry<String, JsonElement> member : parameter.getAsJsonObject().entrySet()) {
            description += prefix + "- " + member.getKey() + ": "
                    + Step.getParameterDescription(member.getValue(), level + 1);
        }
        return description;
    }

    return "";
}

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"));
    }//from w  w w.  j a  va  2 s  . 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.utils.CommandsSettings.java

License:Apache License

private void parseJson() throws IOException {
    JsonParser parser = new JsonParser();
    if (!this.fo.exists() || !this.fo.exists() || !(this.fi.length() > 0)) {
        this.writeDefault();
    }//  w  w w. j  a  va2 s .c o  m
    JsonElement obj = parser.parse(new FileReader("settings/commands.json"));
    this.commandsObj = obj.getAsJsonObject();
    if (this.commandsObj.toString().contains("null")) {
        System.out.println("Please set up your command settings first");
        System.exit(0);
    }
}

From source file:client.utils.Settings.java

License:Apache License

private void getSettingsFromJson() throws IOException {
    JsonParser parser = new JsonParser();
    if (!this.fo.exists() || !this.fo.exists() || !(this.fi.length() > 0)) {
        this.writeDefault();
    }/*  w  w w.jav  a 2 s. c  o  m*/
    JsonElement obj = parser.parse(new FileReader("settings/config.json"));
    this.settings = obj.getAsJsonObject();
    if (this.settings.toString().contains("null")) {
        System.out.println("Please set up your settings first");
        System.exit(0);
    } else {
        this.user = this.settings.get("username").getAsString();
        this.token = this.settings.get("token").getAsString();
        this.clientid = this.settings.get("clientid").getAsString();
        this.oauth = this.settings.get("oauth").getAsString();
        this.pointsToAdd = this.settings.get("point_increment").getAsInt();
        this.interval = this.settings.get("point_interval").getAsInt();
        JsonArray arr = this.settings.get("channels").getAsJsonArray();
        for (JsonElement chan : arr) {
            channels.add(chan.getAsString());
        }
    }
}

From source file:clientcommunicator.operations.LoginCredentials.java

@Override
public void deserialize(String JSON) throws JSONException {
    JsonElement obj = new JsonParser().parse(JSON);
    this.username = obj.getAsJsonObject().get("username").getAsString();
    this.password = obj.getAsJsonObject().get("password").getAsString();
}

From source file:clientcommunicator.Server.Cookie.java

private JsonObject getUserJsonObject(JsonElement element, boolean setNew) throws MalformedCookieException {
    JsonObject jobject = element.getAsJsonObject();
    if (!jobject.has("playerID")) {
        throw new MalformedCookieException();
    }/* w w w.  j ava  2s. co m*/
    JsonObject resultingCookie = new JsonObject();
    resultingCookie.add("name", jobject.get("name"));
    resultingCookie.add("password", jobject.get("password"));
    resultingCookie.add("playerID", jobject.get("playerID"));
    if (setNew) {
        try {
            String realCookie = resultingCookie.toString();
            realCookie = java.net.URLEncoder.encode(realCookie, "UTF-8");
            this.userInformationString = realCookie;
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(Cookie.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    return jobject;
}

From source file:clocker.mesos.entity.framework.marathon.MarathonFrameworkImpl.java

License:Apache License

@Override
public String startApplication(String id, Map<String, Object> flags) {
    Map<String, Object> substitutions = MutableMap.copyOf(flags);
    substitutions.put("id", id);

    Optional<String> result = MesosUtils.httpPost(this, "v2/apps",
            "classpath:///clocker/mesos/entity/framework/marathon/create-app.json", substitutions);
    if (!result.isPresent()) {
        JsonElement json = JsonFunctions.asJson().apply(result.get());
        String message = json.getAsJsonObject().get("message").getAsString();
        LOG.warn("Failed to start task {}: {}", id, message);
        throw new IllegalStateException("Failed to start Marathon task: " + message);
    } else {//from w  w  w  . ja  va  2s. c om
        LOG.debug("Success creating Marathon task");
        JsonElement json = JsonFunctions.asJson().apply(result.get());
        String version = json.getAsJsonObject().get("version").getAsString();
        return version;
    }
}

From source file:cloud.google.datastore.entity.commit.Commit.java

License:Apache License

private String getTransaction() {
    String result = ConnectionService
            .connect(GCDStatic.getDatastoreApiUrl() + config.getProjectName() + "/beginTransaction").body("")
            .accessToken(AuthenticationFactory.getInstance(config).getAccessToken()).post();
    JsonElement jelement = new JsonParser().parse(result);
    JsonObject jobject = jelement.getAsJsonObject();
    jelement = jobject.get("transaction");
    return jelement != null ? jelement.getAsString() : "";
}