Example usage for com.fasterxml.jackson.databind.node ObjectNode put

List of usage examples for com.fasterxml.jackson.databind.node ObjectNode put

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node ObjectNode put.

Prototype

public ObjectNode put(String paramString1, String paramString2) 

Source Link

Usage

From source file:org.gitana.platform.client.util.DriverUtil.java

public static ObjectNode toDependencyObject(TypedID typedID) {
    ObjectNode obj = JsonUtil.createObject();
    obj.put("typeId", typedID.getTypeId());
    obj.put("id", typedID.getId());

    return obj;//from www  . j a  v a  2 s  . c om
}

From source file:com.wegas.log.neo4j.Neo4jPlayerReply.java

/**
 * Creates a new Question node, with all the necessary properties.
 *
 * @param player             the player data
 * @param reply              the player's answer data
 * @param choiceDescriptor   the selected choice description
 * @param questionDescriptor the selected question description
 * @return a node object/* w  w w  .  j  a  va  2s .co m*/
 */
private static ObjectNode createJsonNode(Player player, Reply reply, ChoiceDescriptor choiceDescriptor,
        QuestionDescriptor questionDescriptor) {
    ObjectNode jsonObject = objectMapper.createObjectNode();

    jsonObject.put("playerId", player.getId());
    jsonObject.put("type", TYPE.QUESTION.toString());
    jsonObject.put("teamId", player.getTeamId());
    jsonObject.put("gameId", player.getGameId());
    jsonObject.put("name", player.getName());
    jsonObject.put("starttime", (new Date()).getTime());
    jsonObject.put("choice", choiceDescriptor.getName());
    jsonObject.put("question", questionDescriptor.getName());
    jsonObject.put("result", reply.getResult().getName());
    jsonObject.put("times", reply.getQuestionInstance().getReplies().size());
    if (reply.getResult().getImpact() != null) {
        jsonObject.put("impact",
                StringEscapeUtils.escapeEcmaScript(reply.getResult().getImpact().getContent()));
    } else {
        jsonObject.put("impact", "");
    }
    jsonObject.put("logID", player.getGameModel().getProperties().getLogID());
    return jsonObject;
}

From source file:controllers.chqbll.AjaxService.java

public static Result investigation(Integer id) {
    if (!CacheUtils.isLoggedIn()) {
        return badRequest(Messages.get("not.authorized.or.disconnect"));
    }/*from   w w  w .j  a va 2  s.co m*/

    ChqbllPayrollDetail detail = ChqbllPayrollDetail.getDetailedById(id);

    List<ChqbllHistory> historyList = new ArrayList<ChqbllHistory>();
    for (ChqbllDetailHistory hist : detail.histories) {
        ChqbllHistory history = new ChqbllHistory();
        history.date = DateUtils.formatDateStandart(hist.stepDate);
        history.bank = (hist.bank != null ? hist.bank.name : "");
        history.safe = (hist.safe != null ? hist.safe.name : "");
        history.step = Messages.get(hist.step.key);
        history.user = hist.insertBy;

        historyList.add(history);
    }

    List<Pair> properties = new ArrayList<Pair>();
    properties.add(new Pair(Messages.get("portfolio.no") + " / " + Messages.get("serial.no"),
            detail.portfolioNo.toString() + " / " + detail.serialNo));
    properties.add(new Pair(Messages.get("maturity"), DateUtils.formatDateStandart(detail.dueDate)));
    properties.add(new Pair(Messages.get("amount"), Format.asMoney(detail.amount) + " " + detail.excCode));
    properties.add(new Pair(Messages.get("type"), (detail.cbtype != null ? detail.cbtype.name : "")));
    if (detail.sort.equals(ChqbllSort.Cheque)) {
        properties.add(new Pair(Messages.get("bank.name"), detail.bankName));
    } else if (detail.isCustomer) {
        properties.add(new Pair(Messages.get("surety"), detail.surety));
    }
    if (detail.isCustomer) {
        properties.add(new Pair(Messages.get("owner"), detail.owner));
        properties.add(new Pair(Messages.get("payment_place"), detail.paymentPlace));
    }
    ObjectNode result = Json.newObject();

    result.put("title", detail.lastContactName);
    result.put("body",
            investigation_form.render(StringUtils.getChqbllTitle(detail), historyList, properties).body());

    return ok(result);
}

From source file:models.Friend.java

public static String addFriend(String id) {
    ObjectNode jsonData = Json.newObject();
    jsonData.put("email", session().get("email"));
    JsonNode response = UserService.getUserByEmail(jsonData);
    Application.sessionMsg(response);/*from   w w  w . j a va  2  s. co m*/

    String userID = response.path("userId").asText();

    JsonNode allfriends = UserService.addFriend(userID, id);
    return "success";
}

From source file:models.Friend.java

public static String deleteFriend(String id) {
    ObjectNode jsonData = Json.newObject();
    jsonData.put("email", session().get("email"));
    JsonNode response = UserService.getUserByEmail(jsonData);
    Application.sessionMsg(response);//from  w w  w  . ja  va 2s .  c  om

    String userID = response.path("userId").asText();

    JsonNode allfriends = UserService.deleteFriend(userID, id);
    return "success";
}

From source file:models.Friend.java

public static String addSubscribe(String id) {
    ObjectNode jsonData = Json.newObject();
    jsonData.put("email", session().get("email"));
    JsonNode response = UserService.getUserByEmail(jsonData);
    Application.sessionMsg(response);/*  w w w.  ja  va 2  s  .  c  om*/

    String userID = response.path("userId").asText();

    JsonNode allfriends = UserService.addSubscribe(userID, id);
    return "success";
}

From source file:models.Friend.java

public static String deleteSubscribe(String id) {
    ObjectNode jsonData = Json.newObject();
    jsonData.put("email", session().get("email"));
    JsonNode response = UserService.getUserByEmail(jsonData);
    Application.sessionMsg(response);/*from   w ww. j a  v a 2 s . com*/

    String userID = response.path("userId").asText();

    JsonNode allfriends = UserService.deleteSubscribe(userID, id);
    return "success";
}

From source file:controllers.api.v1.Lineage.java

public static Result getDatasetLineageGraphData(int id) {
    ObjectNode result = Json.newObject();
    String username = session("user");
    if (id < 1) {
        result.put("status", "error");
        result.put("message", "wrong dataset id");
        return ok(result);
    }/*ww w .  j  a v a 2  s . co m*/

    models.Dataset dataset = DatasetsDAO.getDatasetByID(id, username);
    if (dataset == null || StringUtils.isBlank(dataset.urn)) {
        result.put("status", "error");
        result.put("message", "wrong dataset id");
        return ok(result);
    }

    int upLevel = 1;
    String upLevelStr = request().getQueryString("upLevel");
    if (StringUtils.isBlank(upLevelStr)) {
        upLevel = 1;
    } else {
        try {
            upLevel = Integer.parseInt(upLevelStr);
        } catch (NumberFormatException e) {
            Logger.error(
                    "Lineage Controller getDatasetLineageGraphData wrong upLevel parameter. Error message: "
                            + e.getMessage());
            upLevel = 1;
        }
    }
    if (upLevel < 1)
        upLevel = 1;

    int downLevel = 1;
    String downLevelStr = request().getQueryString("downLevel");
    if (StringUtils.isBlank(downLevelStr)) {
        downLevel = 1;
    } else {
        try {
            downLevel = Integer.parseInt(downLevelStr);
        } catch (NumberFormatException e) {
            Logger.error(
                    "Lineage Controller getDatasetLineageGraphData wrong downLevel parameter. Error message: "
                            + e.getMessage());
            downLevel = 1;
        }
    }
    if (downLevel < 1)
        downLevel = 1;

    int lookBackTimeDefault = Integer
            .valueOf(Play.application().configuration().getString(LINEAGE_LOOK_BACK_TIME_KEY, "30"));
    int lookBackTime = lookBackTimeDefault;
    String lookBackTimeStr = request().getQueryString("period");
    if (!StringUtils.isBlank(lookBackTimeStr)) {
        try {
            lookBackTime = Integer.parseInt(lookBackTimeStr);
        } catch (NumberFormatException e) {
            Logger.error("Lineage Controller getDatasetLineageGraphData wrong period parameter. Error message: "
                    + e.getMessage());
            lookBackTime = lookBackTimeDefault;
        }
    }

    result.put("status", "ok");
    result.set("data",
            Json.toJson(LineageDAO.getObjectAdjacnet(dataset.urn, upLevel, downLevel, lookBackTime)));
    System.out
            .println(Json.toJson(LineageDAO.getObjectAdjacnet(dataset.urn, upLevel, downLevel, lookBackTime)));
    System.out.println(ok(result));
    return ok(result);
}

From source file:com.msopentech.odatajclient.engine.data.Serializer.java

private static void jsonLink(final ODataLink link, final Writer writer) {
    final ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
    final ObjectNode uri = mapper.createObjectNode();
    uri.put(ODataConstants.JSON_URL, link.getLink().toASCIIString());

    try {/*from   w  ww .  j  av a2s  .co m*/
        mapper.writeValue(writer, uri);
    } catch (Exception e) {
        throw new IllegalArgumentException("While serializing JSON link", e);
    }
}

From source file:org.gitana.platform.client.util.DriverUtil.java

/**
 * Generic helper method to copy the source object into the target container.
 *
 * @param source/*from  w  ww .jav a 2 s .c om*/
 * @param target
 */
public static CopyJob copy(Cluster cluster, Remote remote, TypedID source, TypedID target,
        TransferSchedule schedule) {
    boolean synchronous = TransferSchedule.SYNCHRONOUS.equals(schedule);

    ArrayNode sourceDependencies = toCopyDependencyChain(source);
    ArrayNode targetDependencies = toCopyDependencyChain(target);

    // execute
    ObjectNode payload = JsonUtil.createObject();
    payload.put("sources", sourceDependencies);
    payload.put("targets", targetDependencies);
    Response response1 = remote.post("/tools/copy?schedule=" + TransferSchedule.ASYNCHRONOUS.toString(),
            payload);
    String jobId = response1.getId();

    Job job = DriverUtil.retrieveOrPollJob(cluster, jobId, synchronous);
    return new CopyJob(cluster, job.getObject(), job.isSaved());
}