List of usage examples for com.google.gson JsonObject has
public boolean has(String memberName)
From source file:citysdk.tourism.client.parser.POIDeserializer.java
License:Open Source License
private void getLocation(POI poi, JsonObject jObject) { JsonObject json = jObject.getAsJsonObject(LOCATION); JsonArray array;/*from ww w .ja v a 2s.c o m*/ Location location = new Location(); if (json.has(POINT)) { array = json.getAsJsonArray(POINT); getPoints(location, array); } if (json.has(LINE)) { array = json.getAsJsonArray(LINE); getLine(location, array); } if (json.has(POLYGON)) { array = json.getAsJsonArray(POLYGON); getSimplePolygon(location, array); } if (json.has(ADDRESS)) location.setAddress(getPOIBaseType(json.getAsJsonObject(ADDRESS))); if (json.has(RELATIONSHIP)) { array = json.getAsJsonArray(RELATIONSHIP); getRelationships(location, array); } poi.setLocation(location); }
From source file:citysdk.tourism.client.parser.POIDeserializer.java
License:Open Source License
private void getTime(POI poi, JsonObject jObject) { JsonArray jArray = jObject.getAsJsonArray(TIME); for (int i = 0; i < jArray.size(); i++) { JsonObject ob = jArray.get(i).getAsJsonObject(); POITermType term = getPOITermType(ob); if (ob.has(SCHEME)) term.setScheme(ob.get(SCHEME).getAsString()); poi.addTime(term);/*w w w .ja v a 2 s . co m*/ } }
From source file:citysdk.tourism.client.parser.POIDeserializer.java
License:Open Source License
private void getSinglePOI(POI poi, JsonObject jObject) { copyTo(poi, getPOIBaseType(jObject)); if (jObject.has(LABEL)) getLabels(poi, jObject);//from w ww.j a v a2 s . c o m if (jObject.has(DESCRIPTION)) getDescription(poi, jObject); if (jObject.has(CATEGORY)) getCategories(poi, jObject); if (jObject.has(LOCATION)) getLocation(poi, jObject); if (jObject.has(TIME)) getTime(poi, jObject); if (jObject.has(LINK)) getLinks(poi, jObject); }
From source file:citysdk.tourism.client.parser.POIDeserializer.java
License:Open Source License
private void deserializePoiBased(Deserializable poi, JsonObject json) { getSinglePOI((POI) poi, json);//from w w w . ja v a 2 s.c om // for routes if (json.has(POIS)) { JsonArray jArray = json.get(POIS).getAsJsonArray(); ListPointOfInterest list = ((Route) poi).getListPoi(); for (int i = 0; i < jArray.size(); i++) { PointOfInterest rPoi = new PointOfInterest(); getSinglePOI(rPoi, jArray.get(i).getAsJsonObject()); list.addPoi(rPoi); } } }
From source file:citysdk.tourism.client.parser.POIDeserializer.java
License:Open Source License
private POI deserializeCategories(Category list, JsonElement elem) { JsonObject json = null; JsonArray array;// www .java 2 s. c o m if (elem.isJsonObject() && elem.getAsJsonObject().has(CATEGORIES)) { array = elem.getAsJsonObject().get(CATEGORIES).getAsJsonArray(); for (int i = 0; i < array.size(); i++) { Category cat = new Category(); json = array.get(i).getAsJsonObject(); getSinglePOI(cat, json); if (json.has(CATEGORIES)) { Category subs = (Category) deserializeCategories(new Category(), json); for (int j = 0; j < subs.getNumCategories(); j++) cat.addCategory(subs.getCategory(j)); } list.addCategory(cat); } } return list; }
From source file:citysdk.tourism.client.parser.POIDeserializer.java
License:Open Source License
private void deserializeListOfList(ListPOIS list, JsonObject jObject) { if (jObject.has(POI)) { ListPointOfInterest pois = new ListPointOfInterest(); deserializeListPois(pois, jObject); list.setListPoi(pois);//from w w w .j a va 2 s . co m } if (jObject.has(EVENT)) { ListEvent events = new ListEvent(); deserializeListEvents(events, jObject); list.setListEvent(events); } if (jObject.has(ROUTES)) { ListRoute routes = new ListRoute(); deserializeListRoutes(routes, jObject); list.setListRoute(routes); } }
From source file:citysdk.tourism.client.parser.POIDeserializer.java
License:Open Source License
/** * Gson deserializer for the CitySDK Tourism POI Classes */// www . ja va2s. c om @Override public Deserializable deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jObject = json.getAsJsonObject(); Deserializable deserializable = (Deserializable) inferType(typeOfT); if (deserializable.getClass().equals(ListPOIS.class)) { deserializeListOfList((ListPOIS) deserializable, jObject); } else if (jObject.has(POI)) { deserializeListPois((ListPointOfInterest) deserializable, jObject); } else if (jObject.has(EVENT)) { deserializeListEvents((ListEvent) deserializable, jObject); } else if (jObject.has(ROUTES)) { deserializeListRoutes((ListRoute) deserializable, jObject); } else if (jObject.has(TOURISM)) { deserializeResources((Resources) deserializable, jObject); } else if (jObject.has(CATEGORIES)) { deserializeCategories((Category) deserializable, jObject); } else if (jObject.has(TAGS)) { deserializeTags((ListTag) deserializable, jObject); } else if (deserializable != null) { deserializePoiBased(deserializable, jObject); } return deserializable; }
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; for (JsonElement step_json : provenance) { stepJSONobject = step_json.getAsJsonObject(); for (JsonElement output : stepJSONobject.getAsJsonArray("outputs")) { outputs.put(output.getAsJsonObject().get("id").getAsString(), step_json); }/* w ww . j a v a2s. co m*/ 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.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 v a 2s . c om*/ 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 .ja v a 2s . 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; }