Search in sources :

Example 16 with JsonArray

use of javax.json.JsonArray in project goci by EBISPOT.

the class JsonBuilder method buildJson.

public String buildJson(String pvalue, String efoTrait, String rsId, String pubmedId, int sampleSize, long gwasPanelResolution, String ensemblId) {
    String dbVersion = getDate();
    String gwasDbId = "http://identifiers.org/gwascatalog";
    String jsonSchemaVersion = "1.2.2";
    String soTerm = "http://purl.obolibrary.org/obo/SO_0001627";
    JsonObject target = Json.createObjectBuilder().add("activity", "http://identifiers.org/cttv.activity/predicted_damaging").add("id", Json.createArrayBuilder().add("http://identifiers.org/ensembl/" + ensemblId)).add("target_type", "http://identifiers.org/cttv.target/gene_evidence").build();
    JsonObject variant = Json.createObjectBuilder().add("type", "snp single").add("id", Json.createArrayBuilder().add("http://identifiers.org/dbsnp/" + rsId)).build();
    JsonObject disease = Json.createObjectBuilder().add("id", Json.createArrayBuilder().add(efoTrait)).build();
    JsonObject uniqueAssociationFields = Json.createObjectBuilder().add("sample_size", Integer.toString(sampleSize)).add("gwas_panel_resolution", Long.toString(gwasPanelResolution)).add("pubmed_refs", "http://europepmc.org/abstract/MED/" + pubmedId).add("target", "http://identifiers.org/ensembl/" + ensemblId).add("object", efoTrait).add("variant", "http://identifiers.org/dbsnp/" + rsId).add("study_name", "cttv009_gwas_catalog").add("pvalue", pvalue).build();
    JsonObject litId = Json.createObjectBuilder().add("lit_id", "http://europepmc.org/abstract/MED/" + pubmedId).build();
    JsonArray references = Json.createArrayBuilder().add(litId).build();
    JsonObject literature = Json.createObjectBuilder().add("references", references).build();
    JsonArray litIdArray = Json.createArrayBuilder().add(litId).build();
    JsonObject literatureHigher = Json.createObjectBuilder().add("references", litIdArray).build();
    JsonObject expert = Json.createObjectBuilder().add("status", true).add("statement", "Primary submitter of data").build();
    JsonObject dbXref = Json.createObjectBuilder().add("version", dbVersion).add("id", gwasDbId).build();
    JsonObject database = Json.createObjectBuilder().add("version", dbVersion).add("id", "GWAS Catalog").add("dbxref", dbXref).build();
    JsonObject variant2diseaseProvenanceType = Json.createObjectBuilder().add("literature", literature).add("expert", expert).add("database", database).build();
    JsonObject method = Json.createObjectBuilder().add("description", "pvalue for the snp to disease association.").build();
    JsonObject resourceScore = Json.createObjectBuilder().add("type", "pvalue").add("method", method).add("value", pvalue).build();
    JsonArray evidenceCodes = Json.createArrayBuilder().add("http://identifiers.org/eco/GWAS").add("http://purl.obolibrary.org/obo/ECO_0000205").build();
    JsonObject variant2disease = Json.createObjectBuilder().add("gwas_sample_size", sampleSize).add("unique_experiment_reference", "http://europepmc.org/abstract/MED/" + pubmedId).add("gwas_panel_resolution", gwasPanelResolution).add("provenance_type", variant2diseaseProvenanceType).add("is_associated", true).add("resource_score", resourceScore).add("evidence_codes", evidenceCodes).add("date_asserted", dbVersion).build();
    JsonObject gene2Variantexpert = Json.createObjectBuilder().add("status", true).add("statement", "Primary submitter of data").build();
    JsonObject gene2variantProvenanceType = Json.createObjectBuilder().add("expert", gene2Variantexpert).add("database", database).build();
    JsonArray gene2VariantEvidenceCodes = Json.createArrayBuilder().add("http://purl.obolibrary.org/obo/ECO_0000205").add("http://identifiers.org/eco/cttv_mapping_pipeline").build();
    JsonObject gene2variant = Json.createObjectBuilder().add("provenance_type", gene2variantProvenanceType).add("is_associated", true).add("date_asserted", dbVersion).add("evidence_codes", gene2VariantEvidenceCodes).add("functional_consequence", soTerm).build();
    JsonObject evidence = Json.createObjectBuilder().add("variant2disease", variant2disease).add("gene2variant", gene2variant).build();
    JsonObject json = Json.createObjectBuilder().add("target", target).add("access_level", "public").add("sourceID", "gwascatalog").add("variant", variant).add("disease", disease).add("unique_association_fields", uniqueAssociationFields).add("evidence", evidence).add("validated_against_schema_version", jsonSchemaVersion).add("type", "genetic_association").add("literature", literatureHigher).build();
    String jsonToReturn = json.toString();
    //        Pattern pattern = Pattern.compile(",\"value\":(\".E.\")");
    //        Matcher matcher = pattern.matcher(jsonToReturn);
    //
    //        boolean found = false;
    //        while (matcher.find()) {
    //            System.out.println("I found the text" +
    //                            matcher.group() + " starting at " +
    //                            "index " + matcher.start() + " and ending at index " +  matcher.end() );
    //            found = true;
    //        }
    jsonToReturn = removeQuoteAroundPvalue(jsonToReturn);
    System.out.println("\n" + jsonToReturn);
    return jsonToReturn;
}
Also used : JsonArray(javax.json.JsonArray) JsonObject(javax.json.JsonObject)

Example 17 with JsonArray

use of javax.json.JsonArray in project drill by apache.

the class ProfileParser method parseFragProfiles.

private void parseFragProfiles() {
    JsonArray frags = getFragmentProfile();
    for (JsonObject fragProfile : frags.getValuesAs(JsonObject.class)) {
        int mId = fragProfile.getInt("majorFragmentId");
        FragInfo major = fragments.get(mId);
        major.parse(fragProfile);
    }
}
Also used : JsonArray(javax.json.JsonArray) JsonObject(javax.json.JsonObject)

Example 18 with JsonArray

use of javax.json.JsonArray in project drill by apache.

the class ProfileParser method getOpInfo.

/**
   * We often run test queries single threaded to make analysis of the profile
   * easier. For a single-threaded (single slice) query, get a map from
   * operator ID to operator information as preparation for additional
   * analysis.
   *
   * @return
   */
public Map<Integer, OperatorProfile> getOpInfo() {
    Map<Integer, String> ops = getOperators();
    Map<Integer, OperatorProfile> info = new HashMap<>();
    JsonArray frags = getFragmentProfile();
    JsonObject fragProfile = frags.getJsonObject(0).getJsonArray("minorFragmentProfile").getJsonObject(0);
    JsonArray opList = fragProfile.getJsonArray("operatorProfile");
    for (JsonObject opProfile : opList.getValuesAs(JsonObject.class)) {
        parseOpProfile(ops, info, opProfile);
    }
    return info;
}
Also used : JsonArray(javax.json.JsonArray) HashMap(java.util.HashMap) JsonObject(javax.json.JsonObject)

Example 19 with JsonArray

use of javax.json.JsonArray in project sling by apache.

the class Announcement method asClusterView.

/** create a clusterview from json **/
private static ClusterView asClusterView(final String localClusterViewJSON) {
    JsonObject obj = jsonReaderFactory.createReader(new StringReader(localClusterViewJSON)).readObject();
    DefaultClusterView clusterView = new DefaultClusterView(obj.getString("id"));
    JsonArray instancesObj = obj.getJsonArray("instances");
    for (int i = 0; i < instancesObj.size(); i++) {
        JsonObject anInstance = instancesObj.getJsonObject(i);
        clusterView.addInstanceDescription(asInstance(anInstance));
    }
    return clusterView;
}
Also used : JsonArray(javax.json.JsonArray) DefaultClusterView(org.apache.sling.discovery.commons.providers.DefaultClusterView) StringReader(java.io.StringReader) JsonObject(javax.json.JsonObject)

Example 20 with JsonArray

use of javax.json.JsonArray in project sling by apache.

the class Announcement method fromJSON.

/** Create an announcement form json **/
public static Announcement fromJSON(final String topologyAnnouncementJSON) {
    JsonObject announcement = jsonReaderFactory.createReader(new StringReader(topologyAnnouncementJSON)).readObject();
    final String ownerId = announcement.getString("ownerId");
    final int protocolVersion;
    if (!announcement.containsKey("protocolVersion")) {
        protocolVersion = -1;
    } else {
        protocolVersion = announcement.getInt("protocolVersion");
    }
    final Announcement result = new Announcement(ownerId, protocolVersion);
    if (announcement.containsKey("created")) {
        result.originallyCreatedAt = announcement.getJsonNumber("created").longValue();
    }
    if (announcement.containsKey("backoffInterval")) {
        long backoffInterval = announcement.getJsonNumber("backoffInterval").longValue();
        result.backoffInterval = backoffInterval;
    }
    if (announcement.containsKey("resetBackoff")) {
        boolean resetBackoff = announcement.getBoolean("resetBackoff");
        result.resetBackoff = resetBackoff;
    }
    if (announcement.containsKey("loop") && announcement.getBoolean("loop")) {
        result.setLoop(true);
        return result;
    }
    if (announcement.containsKey("localClusterView")) {
        final String localClusterViewJSON = asJSON(announcement.getJsonObject("localClusterView"));
        final ClusterView localClusterView = asClusterView(localClusterViewJSON);
        result.setLocalCluster(localClusterView);
    }
    if (announcement.containsKey("inherited")) {
        final Boolean inherited = announcement.getBoolean("inherited");
        result.inherited = inherited;
    }
    if (announcement.containsKey("serverInfo")) {
        String serverInfo = announcement.getString("serverInfo");
        result.serverInfo = serverInfo;
    }
    final JsonArray subAnnouncements = announcement.getJsonArray("topologyAnnouncements");
    for (int i = 0; i < subAnnouncements.size(); i++) {
        String subAnnouncementJSON = subAnnouncements.getString(i);
        result.addIncomingTopologyAnnouncement(fromJSON(subAnnouncementJSON));
    }
    return result;
}
Also used : ClusterView(org.apache.sling.discovery.ClusterView) DefaultClusterView(org.apache.sling.discovery.commons.providers.DefaultClusterView) JsonArray(javax.json.JsonArray) StringReader(java.io.StringReader) JsonObject(javax.json.JsonObject)

Aggregations

JsonArray (javax.json.JsonArray)80 JsonObject (javax.json.JsonObject)58 Test (org.junit.Test)38 ArrayList (java.util.ArrayList)24 NameValuePair (org.apache.commons.httpclient.NameValuePair)20 Credentials (org.apache.commons.httpclient.Credentials)19 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)19 HttpTest (org.apache.sling.commons.testing.integration.HttpTest)17 StringReader (java.io.StringReader)15 HashSet (java.util.HashSet)15 JsonReader (javax.json.JsonReader)14 HashMap (java.util.HashMap)12 JsonString (javax.json.JsonString)12 JsonValue (javax.json.JsonValue)7 JerseyTest (org.glassfish.jersey.test.JerseyTest)7 JsonException (javax.json.JsonException)6 Map (java.util.Map)5 Response (javax.ws.rs.core.Response)5 File (java.io.File)4 JsonArrayBuilder (javax.json.JsonArrayBuilder)4