Example usage for com.google.gson JsonObject add

List of usage examples for com.google.gson JsonObject add

Introduction

In this page you can find the example usage for com.google.gson JsonObject add.

Prototype

public void add(String property, JsonElement value) 

Source Link

Document

Adds a member, which is a name-value pair, to self.

Usage

From source file:at.gv.egovernment.moa.id.protocols.oauth20.attributes.OAuth20AttributeBuilder.java

License:EUPL

private static void addAttibutes(final List<IAttributeBuilder> builders, final JsonObject jsonObject,
        final OAAuthParameter oaParam, final IAuthData authData) {
    for (IAttributeBuilder b : builders) {
        try {/*from   w  w  w .ja  v a 2s  .  co m*/
            Pair<String, JsonPrimitive> attribute = b.build(oaParam, authData, generator);
            if (attribute != null && !StringUtils.isEmpty(attribute.getSecond().getAsString())) {
                jsonObject.add(attribute.getFirst(), attribute.getSecond());
            }
        } catch (AttributeException e) {
            Logger.info("Cannot add attribute " + b.getName());
        }
    }
}

From source file:at.quelltextlich.phabricator.conduit.raw.ConduitModule.java

License:Apache License

/**
 * Runs the API's 'conduit.ping' method//  ww  w  . ja  v a2  s.c  o  m
 */
public PingResult ping() throws ConduitException {
    final JsonElement callResult = connection.call("conduit.ping");
    final JsonObject callResultWrapper = new JsonObject();
    callResultWrapper.add("hostname", callResult);
    final PingResult result = gson.fromJson(callResultWrapper, PingResult.class);
    return result;
}

From source file:at.storm.bolt.JsonBolt.java

License:Apache License

public void execute(Tuple tuple, BasicOutputCollector collector) {
    String jsonString = tuple.getStringByField("jsonString");
    TupleStatistic tupleStatistic = (TupleStatistic) tuple.getValueByField("tupleStatistic");

    JsonObject jsonObject = (JsonObject) jsonParser.parse(jsonString);

    if (m_logging) {
        LOG.info("JSON: " + jsonObject.toString());
    }//from   w  ww . j  ava2s . co m

    tupleStatistic.setRealStart(jsonObject.get("timestamp").getAsLong());

    String message = jsonObject.get("msg").getAsString();

    if (!LanguageDetection.isEnglish(message)) {
        JsonObject score = new JsonObject();
        score.addProperty("score", 0);

        jsonObject.add("sentiment", score);

        collector.emit(TO_REDIS_PUBLISH_STREAM, new JsonBoltData(jsonObject, tupleStatistic));
    } else {
        collector.emit(PIPELINE_STREAM, new JsonBoltData(jsonObject, tupleStatistic));
    }

}

From source file:at.storm.bolt.SVMBolt.java

License:Apache License

public void execute(Tuple tuple) {
    FeatureGenerationBoltData featureGenerationValue = FeatureGenerationBoltData.getFromTuple(tuple);
    JsonObject jsonObject = featureGenerationValue.getJsonObject();
    TupleStatistic tupleStatistic = featureGenerationValue.getTupleStatistic();
    Map<Integer, Double> featureVector = featureGenerationValue.getFeatureVector();

    // Create feature nodes
    svm_node[] testNodes = new svm_node[featureVector.size()];
    int i = 0;//from w ww . j a v  a2  s.  c o m
    for (Map.Entry<Integer, Double> feature : featureVector.entrySet()) {
        svm_node node = new svm_node();
        node.index = feature.getKey();
        node.value = feature.getValue();
        testNodes[i] = node;
        i++;
    }

    double predictedClass = svm.svm_predict(m_model, testNodes);

    JsonObject score = new JsonObject();
    score.addProperty("score", convertRating(predictedClass));

    jsonObject.add("sentiment", score);

    if (m_logging) {
        LOG.info("SVM all done log: " + jsonObject.toString());
    }

    collector.emit(tuple, new SVMBoltData(jsonObject, tupleStatistic));
    collector.ack(tuple);
}

From source file:at.tugraz.kmi.medokyservice.fca.util.ImportExport.java

License:Open Source License

private JsonElement users2JSON() {

    BlockingDeque<User> users = Database.getInstance().getAll(User.class);
    JsonObject block = new JsonObject();
    for (User u : users) {
        JsonObject jso = prepare(u);/*from   www .  j ava  2s  .  c om*/
        jso.addProperty(E_UID, u.getExternalUid());
        block.add(Long.toString(u.getId()), jso);
    }
    return block;
}

From source file:at.tugraz.kmi.medokyservice.fca.util.ImportExport.java

License:Open Source License

private JsonElement learningObjects2JSON() {
    BlockingDeque<LearningObject> lobjects = Database.getInstance().getAll(LearningObject.class);
    JsonObject block = new JsonObject();
    for (LearningObject o : lobjects) {
        JsonObject jso = prepare(o);/*  ww  w.jav a2  s .c  o  m*/
        jso.addProperty(DATA, o.getData());
        jso.addProperty(OWNER, o.getOwner().getId());
        block.add(Long.toString(o.getId()), jso);
    }
    return block;
}

From source file:at.tugraz.kmi.medokyservice.fca.util.ImportExport.java

License:Open Source License

private <E extends FCAAbstract> JsonElement abstracts2JSon(Class<E> type) {
    BlockingDeque<E> objects = Database.getInstance().getAll(type);
    JsonObject block = new JsonObject();
    for (E o : objects) {
        JsonObject jso = prepare(o);
        jso.addProperty(CID, o.getCreationId());
        LinkedList<Long> loIds = new LinkedList<Long>();
        LinkedList<Long> loByLearnerIds = new LinkedList<Long>();
        for (LearningObject lo : o.getLearningObjects()) {
            loIds.add(lo.getId());//from  ww  w  .  jav a2 s  .  c  o m
        }
        for (LearningObject lo : o.getLearningObjectsByLearners()) {
            loByLearnerIds.add(lo.getId());
        }
        jso.add(SECTION_LO, gson.toJsonTree(loIds, new TypeToken<List<Long>>() {
        }.getType()));
        jso.add(SECTION_LO_L, gson.toJsonTree(loByLearnerIds, new TypeToken<List<Long>>() {
        }.getType()));
        block.add(Long.toString(o.getId()), jso);
    }
    return block;
}

From source file:at.tugraz.kmi.medokyservice.fca.util.ImportExport.java

License:Open Source License

private JsonElement metadata2JSON() {
    BlockingDeque<FCAItemMetadata> lobjects = Database.getInstance().getAll(FCAItemMetadata.class);
    JsonObject block = new JsonObject();
    for (FCAItemMetadata o : lobjects) {
        JsonObject jso = prepare(o);
        jso.addProperty(O_ID, o.getItemID());
        LinkedList<Long> loIds = new LinkedList<Long>();
        for (LearningObject lo : o.getLearningObjects()) {
            if (lo != null)
                loIds.add(lo.getId());/*from w  w w.j  a  v  a  2s  .c  o m*/
        }
        LinkedList<Long> loByLernerIds = new LinkedList<Long>();
        for (LearningObject lo : o.getLearningObjectByLearner()) {
            if (lo != null)
                loByLernerIds.add(lo.getId());
        }
        jso.add(SECTION_LO, gson.toJsonTree(loIds, new TypeToken<List<Long>>() {
        }.getType()));
        jso.add(SECTION_LO_L, gson.toJsonTree(loByLernerIds, new TypeToken<List<Long>>() {
        }.getType()));
        block.add(Long.toString(o.getId()), jso);
    }
    return block;
}

From source file:at.tugraz.kmi.medokyservice.fca.util.ImportExport.java

License:Open Source License

private JsonElement domains2JSON() {
    BlockingDeque<Domain> domains = Database.getInstance().getAll(Domain.class);
    JsonArray jsD = new JsonArray();
    for (Domain d : domains) {
        IncidenceMatrix mat = d.getMapping();
        Map<FCAObject, Set<FCAAttribute>> mapping = mat.getObjects();
        JsonObject jso = prepare(d);
        JsonObject jsM = new JsonObject();
        for (long mId : mat.getItemMetadata().keySet()) {
            jsM.addProperty(Long.toString(mId), mat.getItemMetadata().get(mId).getId());
        }/*from   www . j  a v a 2s  . com*/
        jso.add(SECTION_M, jsM);
        List<Long> ownerIDs = new LinkedList<Long>();
        for (User o : d.getOwners()) {
            ownerIDs.add(o.getId());
        }
        jso.add(OWNER, gson.toJsonTree(ownerIDs, new TypeToken<List<Long>>() {
        }.getType()));
        jso.addProperty(GLOBAL, d.isGlobal());
        jso.addProperty(APPROVED, d.isApproved());
        JsonObject jsMapping = new JsonObject();
        for (FCAObject o : mapping.keySet()) {
            LinkedList<Long> aIds = new LinkedList<Long>();
            for (FCAAttribute a : mapping.get(o)) {
                aIds.add(a.getId());
            }
            jsMapping.add(Long.toString(o.getId()), gson.toJsonTree(aIds, new TypeToken<List<Long>>() {
            }.getType()));
        }
        jso.add(MAPPING, jsMapping);
        jsD.add(jso);
    }
    return jsD;
}

From source file:at.tugraz.kmi.medokyservice.fca.util.ImportExport.java

License:Open Source License

private JsonElement courses2JSON() {
    BlockingDeque<Course> courses = Database.getInstance().getAll(Course.class);
    JsonArray jsC = new JsonArray();
    for (Course o : courses) {
        JsonObject jso = prepare(o);
        Set<Domain> domains = o.getDomains();
        LinkedList<Long> dIds = new LinkedList<Long>();
        for (Domain d : domains)
            dIds.add(d.getId());/*from  w w w .jav a 2  s.  c o  m*/

        jso.add(SECTION_D, gson.toJsonTree(dIds, new TypeToken<List<Long>>() {
        }.getType()));
        jso.addProperty(E_CID, o.getExternalCourseID());
        List<Long> participants = new LinkedList<Long>();
        for (User u : o.getParticipants())
            participants.add(u.getId());

        jso.add(PARTICIPANTS, gson.toJsonTree(participants, new TypeToken<List<Long>>() {
        }.getType()));

        jsC.add(jso);
    }
    return jsC;
}