List of usage examples for javax.json JsonArray getValuesAs
default <T, K extends JsonValue> List<T> getValuesAs(Function<K, T> func)
From source file:uk.ac.ebi.ep.adapter.bioportal.BioPortalService.java
@Override public Disease getDiseaseByName(String term, String diseaseId) throws BioportalAdapterException { String definition = ""; // Reader reader = new StringReader(get(REST_URL + "/search?q=" + term+"&ontology={EFO,MeSH,OMIM}&exact_match=true")); Reader reader = new StringReader(get(REST_URL + "/search?q=" + term)); JsonReader jsonReader = Json.createReader(reader); JsonObject jo = jsonReader.readObject(); JsonArray jsonArray = jo.getJsonArray("collection"); Disease disease = null;//from w ww. j a v a2 s . c o m for (JsonObject obj : jsonArray.getValuesAs(JsonObject.class)) { disease = new Disease(); disease.setId(diseaseId); for (Map.Entry<String, JsonValue> entry : obj.entrySet()) { switch (entry.getKey()) { case LABEL: if (entry.getKey().equalsIgnoreCase(LABEL)) { String name = entry.getValue().toString(); name = name.replaceAll("^\"|\"$", ""); if (name.equalsIgnoreCase(term)) { disease.setName(name); } } break; case DEFINITION: if (entry.getKey().equalsIgnoreCase(DEFINITION)) { definition = entry.getValue().toString().replace("\"", "").replaceAll("\\[", "") .replaceAll("\\]", ""); disease.setDescription(definition); return disease; } break; } } } return disease; }
From source file:de.pangaea.fixo3.CreateEsonetYellowPages.java
private void run() throws OWLOntologyCreationException, OWLOntologyStorageException, FileNotFoundException { m = new OntologyManager(ns); m.addTitle("ESONET Yellow Pages Ontology"); m.addVersion("1.0"); m.addDate("2016-11-23"); m.addCreator("Markus Stocker"); m.addSeeAlso("http://www.esonetyellowpages.com/"); m.addImport(SSN.ns);//from ww w.j a va 2 s . co m m.addSubClass(Frequency, MeasurementProperty); m.addLabel(Frequency, "Frequency"); m.addSubClass(ProfilingRange, MeasurementProperty); m.addLabel(ProfilingRange, "Profiling Range"); m.addSubClass(CellSize, MeasurementProperty); m.addLabel(CellSize, "Cell Size"); m.addSubClass(OperatingDepth, MeasurementProperty); m.addLabel(OperatingDepth, "Operating Depth"); m.addSubClass(TemperatureRange, MeasurementProperty); m.addLabel(TemperatureRange, "Temperature Range"); m.addSubClass(MeasuringRange, MeasurementProperty); m.addLabel(MeasuringRange, "Measuring Range"); m.addClass(WaterCurrent); m.addLabel(WaterCurrent, "Water Current"); m.addSubClass(WaterCurrent, FeatureOfInterest); m.addClass(CarbonDioxide); m.addLabel(CarbonDioxide, "Carbon Dioxide"); m.addSubClass(CarbonDioxide, FeatureOfInterest); m.addClass(Speed); m.addLabel(Speed, "Speed"); m.addSubClass(Speed, Property); m.addObjectSome(Speed, isPropertyOf, WaterCurrent); m.addClass(PartialPressure); m.addLabel(PartialPressure, "Partial Pressure"); m.addSubClass(PartialPressure, Property); m.addObjectSome(PartialPressure, isPropertyOf, CarbonDioxide); m.addClass(DopplerEffect); m.addSubClass(DopplerEffect, Stimulus); m.addLabel(DopplerEffect, "Doppler Effect"); m.addComment(DopplerEffect, "The Doppler effect (or the Doppler shift) is the change in frequency of a wave (or other periodic event) for an observer moving relative to its source."); m.addSource(DopplerEffect, IRI.create("https://en.wikipedia.org/wiki/Doppler_effect")); m.addObjectAll(DopplerEffect, isProxyFor, Speed); m.addClass(Infrared); m.addSubClass(Infrared, Stimulus); m.addLabel(Infrared, "Infrared"); m.addComment(Infrared, "Infrared (IR) is an invisible radiant energy."); m.addSource(Infrared, IRI.create("https://en.wikipedia.org/wiki/Infrared")); m.addObjectAll(Infrared, isProxyFor, PartialPressure); m.addClass(AcousticDopplerCurrentProfiler); m.addLabel(AcousticDopplerCurrentProfiler, "Acoustic Doppler Current Profiler"); m.addSource(AcousticDopplerCurrentProfiler, IRI.create("https://en.wikipedia.org/wiki/Acoustic_Doppler_current_profiler")); m.addComment(AcousticDopplerCurrentProfiler, "An acoustic Doppler current profiler (ADCP) is a hydroacoustic current meter similar to a sonar, attempting to measure water current velocities over a depth range using the Doppler effect of sound waves scattered back from particles within the water column."); m.addObjectAll(AcousticDopplerCurrentProfiler, detects, DopplerEffect); m.addObjectAll(AcousticDopplerCurrentProfiler, observes, Speed); m.addSubClass(AcousticDopplerCurrentProfiler, HydroacousticCurrentMeter); m.addClass(PartialPressureOfCO2Analyzer); m.addLabel(PartialPressureOfCO2Analyzer, "Partial Pressure of CO2 Analyzer"); m.addObjectAll(PartialPressureOfCO2Analyzer, detects, Infrared); m.addObjectAll(PartialPressureOfCO2Analyzer, observes, PartialPressure); m.addSubClass(PartialPressureOfCO2Analyzer, SensingDevice); m.addClass(HydroacousticCurrentMeter); m.addLabel(HydroacousticCurrentMeter, "Hydroacoustic Current Meter"); m.addSubClass(HydroacousticCurrentMeter, SensingDevice); JsonReader jr = Json.createReader(new FileReader(new File(eypDevicesFile))); JsonArray ja = jr.readArray(); for (JsonObject jo : ja.getValuesAs(JsonObject.class)) { String name = jo.getString("name"); String label = jo.getString("label"); String comment = jo.getString("comment"); String seeAlso = jo.getString("seeAlso"); JsonArray equivalentClasses = jo.getJsonArray("equivalentClasses"); JsonArray subClasses = jo.getJsonArray("subClasses"); addDeviceType(name, label, comment, seeAlso, equivalentClasses, subClasses); } m.save(eypFile); m.saveInferred(eypInferredFile); }
From source file:joachimeichborn.geotag.geocode.GoogleGeocoder.java
private String getMatchingContentFromAddressComponent(final String aAttribute, final JsonArray aResults, final LocationType... aLocationTypes) { for (final LocationType locationType : aLocationTypes) { for (final JsonObject result : aResults.getValuesAs(JsonObject.class)) { final JsonArray addressComponents = result.getJsonArray(ADDRESS_COMPONENTS_KEY); final String content = getMatchingContent(aAttribute, addressComponents, locationType); if (!StringUtils.isEmpty(content)) { return content; }// w w w . j a va 2 s . c o m } } return null; }
From source file:joachimeichborn.geotag.geocode.GoogleGeocoder.java
private String getMatchingContent(final String aAttribute, final JsonArray aResults, final LocationType... aLocationTypes) { for (final LocationType locationType : aLocationTypes) { for (final JsonObject component : aResults.getValuesAs(JsonObject.class)) { final JsonArray types = component.getJsonArray(TYPES_KEY); if (types.containsAll(locationType.getIdentifiers()) && component.containsKey(aAttribute)) { return component.getString(aAttribute); }//from w w w .j a v a 2 s .com } } return null; }
From source file:DesignGUI.java
private void parseStackExchange(String jsonStr) { JsonReader reader = null;/*from w ww.j av a 2s . c o m*/ StringBuilder content = new StringBuilder(); this.jEditorPane_areaShow.setContentType("text/html"); content.append("<html></body>"); try { reader = Json.createReader(new StringReader(jsonStr)); JsonObject jsonObject = reader.readObject(); reader.close(); JsonArray array = jsonObject.getJsonArray("items"); for (JsonObject result : array.getValuesAs(JsonObject.class)) { JsonObject ownerObject = result.getJsonObject("owner"); // int ownerReputation = ownerObject.getInt("reputation"); // System.out.println("Reputation:"+ownerReputation); int viewCount = result.getInt("view_count"); content.append("<br>View Count :" + viewCount + "<br>"); int answerCount = result.getInt("answer_count"); content.append("Answer Count :" + answerCount + "<br>"); String title = result.getString("title"); content.append("Title: <FONT COLOR=green>" + title + "</FONT>.<br>"); String link = result.getString("link"); content.append("URL :<a href="); content.append("'link'>" + link); content.append("</a>.<br>"); // String body = result.getString("body"); // content.append("Body:"+body); /* JsonArray tagsArray = result.getJsonArray("tags"); StringBuilder tagBuilder = new StringBuilder(); int i = 1; for(JsonValue tag : tagsArray){ tagBuilder.append(tag.toString()); if(i < tagsArray.size()) tagBuilder.append(","); i++; } content.append("Tags: "+tagBuilder.toString());*/ } content.append("</body></html>"); this.jEditorPane_areaShow.setText(content.toString()); System.out.println(content.toString()); } catch (Exception e) { e.printStackTrace(); } }
From source file:ch.bfh.abcvote.util.controllers.CommunicationController.java
/** * gets the all registered voters from the bulletin board and returns them as a List of Voter objects * @return returns a list of all voters//from ww w . java 2s . c o m */ public List<Voter> getAllARegisteredVoters() { List<Voter> voterlist = new ArrayList<Voter>(); try { URL url = new URL(bulletinBoardUrl + "/voters"); InputStream urlInputStream = url.openStream(); JsonReader jsonReader = Json.createReader(urlInputStream); JsonArray obj = jsonReader.readArray(); //For each Voter-Json in the Json Array for (JsonObject result : obj.getValuesAs(JsonObject.class)) { //JsonData converted into Voter Object and added to the list String email = result.getString("email"); String publicCredential = result.getString("publicCredential"); String appVersion = result.getString("appVersion"); Voter voter = new Voter(email, publicCredential, appVersion); voterlist.add(voter); } } catch (IOException x) { System.err.println(x); } return voterlist; }
From source file:de.pangaea.fixo3.CreateEsonetYellowPages.java
private void addDeviceType(String name, String label, String comment, String seeAlso, JsonArray equivalentClasses, JsonArray subClasses) { IRI deviceTypeIRI = IRI.create(name); m.addClass(deviceTypeIRI);/*from ww w . j av a 2 s. co m*/ m.addLabel(deviceTypeIRI, label); m.addComment(deviceTypeIRI, comment); m.addSeeAlso(deviceTypeIRI, seeAlso); // Default sub class, though implicit with curated sensing device type // hierarchy // m.addSubClass(deviceTypeIRI, SSN.SensingDevice); for (JsonObject equivalentClass : equivalentClasses.getValuesAs(JsonObject.class)) { if (equivalentClass.containsKey("type")) { m.addEquivalentClass(deviceTypeIRI, IRI.create(equivalentClass.getString("type"))); } } for (JsonObject subClass : subClasses.getValuesAs(JsonObject.class)) { if (subClass.containsKey("type")) { m.addSubClass(deviceTypeIRI, IRI.create(subClass.getString("type"))); } else if (subClass.containsKey("observes")) { JsonObject observesJson = subClass.getJsonObject("observes"); String propertyLabel = observesJson.getString("label"); String propertyType = observesJson.getString("type"); JsonObject featureJson = observesJson.getJsonObject("isPropertyOf"); String featureLabel = featureJson.getString("label"); String featureType = featureJson.getString("type"); IRI propertyIRI = IRI.create(EYP.ns.toString() + md5Hex(propertyLabel)); IRI propertyTypeIRI = IRI.create(propertyType); IRI featureIRI = IRI.create(EYP.ns.toString() + md5Hex(featureLabel)); IRI featureTypeIRI = IRI.create(featureType); m.addObjectValue(deviceTypeIRI, observes, propertyIRI); m.addIndividual(propertyIRI); m.addType(propertyIRI, propertyTypeIRI); m.addLabel(propertyIRI, propertyLabel); m.addIndividual(featureIRI); m.addType(featureIRI, featureTypeIRI); m.addLabel(featureIRI, featureLabel); m.addObjectAssertion(propertyIRI, isPropertyOf, featureIRI); } else if (subClass.containsKey("detects")) { JsonObject detectsJson = subClass.getJsonObject("detects"); String stimulusLabel = detectsJson.getString("label"); String stimulusType = detectsJson.getString("type"); IRI stimulusIRI = IRI.create(EYP.ns.toString() + md5Hex(stimulusLabel)); IRI stimulusTypeIRI = IRI.create(stimulusType); m.addObjectValue(deviceTypeIRI, detects, stimulusIRI); m.addIndividual(stimulusIRI); m.addType(stimulusIRI, stimulusTypeIRI); m.addLabel(stimulusIRI, stimulusLabel); } else if (subClass.containsKey("capability")) { JsonObject capabilityJson = subClass.getJsonObject("capability"); String capabilityLabel = capabilityJson.getString("label"); JsonObject propertyJson = capabilityJson.getJsonObject("property"); String propertyLabel = propertyJson.getString("label"); String propertyType = propertyJson.getString("type"); JsonObject valueJson = propertyJson.getJsonObject("value"); String valueLabel = valueJson.getString("label"); IRI capabilityIRI = IRI.create(EYP.ns.toString() + md5Hex(capabilityLabel)); IRI propertyIRI = IRI.create(EYP.ns.toString() + md5Hex(propertyLabel)); IRI propertyTypeIRI = IRI.create(propertyType); IRI valueIRI = IRI.create(EYP.ns.toString() + md5Hex(valueLabel)); m.addObjectValue(deviceTypeIRI, hasMeasurementCapability, capabilityIRI); m.addIndividual(capabilityIRI); m.addType(capabilityIRI, MeasurementCapability); m.addLabel(capabilityIRI, capabilityLabel); m.addObjectAssertion(capabilityIRI, hasMeasurementProperty, propertyIRI); m.addIndividual(propertyIRI); m.addType(propertyIRI, SSN.MeasurementProperty); m.addType(propertyIRI, propertyTypeIRI); m.addLabel(propertyIRI, propertyLabel); m.addObjectAssertion(propertyIRI, hasValue, valueIRI); m.addIndividual(valueIRI); m.addType(valueIRI, SSN.ObservationValue); m.addLabel(valueIRI, valueLabel); if (valueJson.containsKey("value")) { m.addType(valueIRI, QuantitativeValue); m.addDataAssertion(valueIRI, value, Float.valueOf(valueJson.getString("value"))); } else if (valueJson.containsKey("minValue") && valueJson.containsKey("maxValue")) { m.addType(valueIRI, QuantitativeValue); m.addDataAssertion(valueIRI, minValue, Float.valueOf(valueJson.getString("minValue"))); m.addDataAssertion(valueIRI, maxValue, Float.valueOf(valueJson.getString("maxValue"))); } else { throw new RuntimeException("Expected value or min/max value [valueJson = " + valueJson + "]"); } m.addObjectAssertion(valueIRI, unitCode, IRI.create(valueJson.getString("unitCode"))); } } }
From source file:ch.bfh.abcvote.util.controllers.CommunicationController.java
/** * Gets a List of ElectionHeaders from the Bulletin Board and returns it. Fetched list depends on the given ElectionFilterTyp * @param filter/*from w w w . j a v a 2 s . c o m*/ * The filter can be set to All, Open or Closed * @return returns a list of election headers */ public List<ElectionHeader> getElectionHeaders(ElectionFilterTyp filter) { List<ElectionHeader> electionHeaderlist = new ArrayList<ElectionHeader>(); DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); LocalDateTime actualDateTime = LocalDateTime.now(); String dateTimeString = actualDateTime.format(format); URL url = null; //depending on the filter a different request is sent to the bulletin board switch (filter) { // if the filter is set to ALL, all the electionheaders on the bulletin board are requested case ALL: { try { url = new URL(bulletinBoardUrl + "/elections"); } catch (MalformedURLException ex) { Logger.getLogger(CommunicationController.class.getName()).log(Level.SEVERE, null, ex); } } break; // if the filter is set to OPEN only ElectionHeaders where the VotingPeriod is still going are requested from the bulletin board case OPEN: { try { url = new URL(bulletinBoardUrl + "/elections/open?date=" + URLEncoder.encode(dateTimeString, "UTF-8").replace("+", "%20")); } catch (UnsupportedEncodingException | MalformedURLException ex) { System.err.println(ex); } } break; // if the filter is set to CLOSED only ElectionHeaders where the VotingPeriod is already over are requested from the bulletin board case CLOSED: { try { url = new URL(bulletinBoardUrl + "/elections/closed?date=" + URLEncoder.encode(dateTimeString, "UTF-8").replace("+", "%20")); } catch (UnsupportedEncodingException | MalformedURLException ex) { System.err.println(ex); } } break; } try { InputStream urlInputStream = url.openStream(); JsonReader jsonReader = Json.createReader(urlInputStream); JsonArray obj = jsonReader.readArray(); //Recieved Json String is transformed into a list of ElectionHeader objects for (JsonObject result : obj.getValuesAs(JsonObject.class)) { int id = Integer.parseInt(result.getString("id")); String title = result.getString("electionTitle"); LocalDateTime beginDate = LocalDateTime.parse(result.getString("beginDate"), format); LocalDateTime endDate = LocalDateTime.parse(result.getString("endDate"), format); ElectionHeader electionHeader = new ElectionHeader(id, title, beginDate, endDate); electionHeaderlist.add(electionHeader); } } catch (IOException x) { System.err.println(x); } return electionHeaderlist; }
From source file:ch.bfh.abcvote.util.controllers.CommunicationController.java
/** * Gets a list of all the posted ballots of the given election form the bulletin board and returns it * @param election//from w w w . j a v a2 s.com * Election for which the list of ballots should be retrieved * @return * the list of all posted ballots to the given election */ public List<Ballot> getBallotsByElection(Election election) { List<Ballot> ballots = new ArrayList<Ballot>(); try { URL url = new URL(bulletinBoardUrl + "/elections/" + election.getId() + "/ballots"); InputStream urlInputStream = url.openStream(); JsonReader jsonReader = Json.createReader(urlInputStream); JsonArray obj = jsonReader.readArray(); DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); //transforms the recieved json string into a list of ballot objects for (JsonObject result : obj.getValuesAs(JsonObject.class)) { int id = Integer.parseInt(result.getString("id")); LocalDateTime timeStamp = LocalDateTime.parse(result.getString("timestamp"), format); JsonObject jsonData = result.getJsonObject("jsonData"); List<String> selectedOptions = new ArrayList<String>(); JsonArray optionsArray = jsonData.getJsonArray("e"); for (int i = 0; i < optionsArray.size(); i++) { selectedOptions.add(optionsArray.getString(i)); } String u_HatString = jsonData.getString("u_Hat"); String cString = jsonData.getString("c"); String dString = jsonData.getString("d"); String pi1String = jsonData.getString("pi1"); String pi2String = jsonData.getString("pi2"); String pi3String = jsonData.getString("pi3"); //create ballot object and add it to the list Ballot ballot = new Ballot(id, election, selectedOptions, u_HatString, cString, dString, pi1String, pi2String, pi3String, timeStamp); System.out.println(ballot.isValid()); ballots.add(ballot); } } catch (IOException x) { System.err.println(x); } return ballots; }
From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java
public BtcLastBlock jsonLastBlock(JsonValue value) throws BtcException { JsonObject object = jsonObject(value); if (object == null) { return null; }//from w ww . jav a 2s. co m BtcLastBlock lastBlock = new BtcLastBlock(); lastBlock.setLastBlock(object.getString(BTCOBJ_LAST_BLOCK_LAST_BLOCK, "")); List<BtcTransaction> transactions = new ArrayList<BtcTransaction>(); JsonValue txs = object.get(BTCOBJ_LAST_BLOCK_TRANSACTIONS); if ((txs != null) && (txs.getValueType() == JsonValue.ValueType.ARRAY) && (txs instanceof JsonArray)) { JsonArray txsArray = (JsonArray) txs; for (JsonValue tx : txsArray.getValuesAs(JsonValue.class)) { transactions.add(jsonTransaction(tx)); } } lastBlock.setTransactions(transactions); return lastBlock; }