List of usage examples for com.google.gson JsonElement getAsString
public String getAsString()
From source file:cl.niclabs.tscrypto.common.datatypes.BigIntegerBase64TypeAdapter.java
License:Open Source License
@Override public BigInteger deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return new BigInteger(Base64.decodeBase64(json.getAsString())); }
From source file:classes.analysis.Analysis.java
License:Open Source License
private String generateXMLContent(JsonElement jsonCode, int level) { String content = ""; if (jsonCode.isJsonPrimitive()) { content += jsonCode.getAsString(); } else if (jsonCode.isJsonArray()) { content += "\n"; for (JsonElement subelement : jsonCode.getAsJsonArray()) { content += this.generateXMLContent(subelement, level + 1); }/* w ww .j a va 2 s .co m*/ content += "\n"; content += String.join("", Collections.nCopies(level - 1, "\t")); } else if (jsonCode.isJsonObject()) { for (Map.Entry<String, JsonElement> entry : jsonCode.getAsJsonObject().entrySet()) { content += String.join("", Collections.nCopies(level, "\t")) + "<" + entry.getKey() + ">" + this.generateXMLContent(entry.getValue(), level + 1) + "</" + entry.getKey() + ">\n"; } } return content; }
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 ww. j a va 2 s .com 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) {/*from w w w . j a va2 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"; }/*from www .j a v a2s.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: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(); }// www. j a v a2s .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: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() : ""; }
From source file:cloud.google.oauth2.MyWayAuthentication.java
License:Apache License
/** * Just return access token//from w w w . j a v a2 s . c om * */ @Override public String getAccessToken() { try { long iat = (System.currentTimeMillis() / 1000) - 60; long exp = iat + 3600; String urlParameters = "grant_type=" + GCDStatic.getGrant() + "&assertion=" + getAssertion(exp, iat); String result = ConnectionService.connect(GCDStatic.getAud()).body(urlParameters) .header("Content-Type", "application/x-www-form-urlencoded").post(); JsonElement jelement = new JsonParser().parse(result); JsonObject jobject = jelement.getAsJsonObject(); jelement = jobject.get("access_token"); return jelement != null ? jelement.getAsString() : ""; } catch (Exception e) { e.printStackTrace(); } return ""; }
From source file:cmput301.f13t01.elasticsearch.InterfaceAdapter.java
License:GNU General Public License
private Type typeForName(final JsonElement typeElem) { try {/*from ww w. ja va 2s . c om*/ return Class.forName(typeElem.getAsString()); } catch (ClassNotFoundException e) { throw new JsonParseException(e); } }
From source file:cn.edu.zjnu.acm.judge.util.excel.ExcelUtil.java
License:Apache License
private static <T> List<T> parse(Workbook workbook, FormulaEvaluator evaluator, Class<T> type, Locale locale) { MetaInfo metaInfo = MetaInfo.forType(type, locale); Sheet sheet = workbook.getSheetAt(workbook.getActiveSheetIndex()); Iterator<Row> rows = sheet.rowIterator(); if (!rows.hasNext()) { return Collections.emptyList(); }/*from w ww.j ava2 s . c o m*/ Row firstRow = rows.next(); Map<Integer, String> columnIndexToFieldName = Maps.newHashMapWithExpectedSize(metaInfo.size()); for (Iterator<Cell> it = firstRow.cellIterator(); it.hasNext();) { Cell cell = it.next(); JsonElement jsonElement = parseAsJsonElement(cell, evaluator); if (jsonElement != null) { Field field = metaInfo.getField(jsonElement.getAsString()); if (field != null) { String name = field.getName(); int index = cell.getColumnIndex(); columnIndexToFieldName.put(index, name); } } } if (columnIndexToFieldName.isEmpty()) { return Collections.emptyList(); } List<T> result = new ArrayList<>(sheet.getLastRowNum() - sheet.getFirstRowNum()); while (rows.hasNext()) { result.add(parseRow(evaluator, rows.next(), columnIndexToFieldName, type)); } return result; }