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:controllers.api.v1.Dataset.java

public static Result getDependViews(Long datasetId) {
    ObjectNode result = Json.newObject();
    List<DatasetDependency> depends = new ArrayList<>();
    DatasetsDAO.getDependencies(datasetId, depends);
    result.put("status", "ok");
    result.set("depends", Json.toJson(depends));
    return ok(result);
}

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

public static Result getReferenceViews(Long datasetId) {
    ObjectNode result = Json.newObject();
    List<DatasetDependency> references = new ArrayList<>();
    DatasetsDAO.getReferences(datasetId, references);
    result.put("status", "ok");
    result.set("references", Json.toJson(references));
    return ok(result);
}

From source file:org.waarp.gateway.kernel.rest.RestArgument.java

public static ObjectNode fillDetailedAllow(METHOD method, String path, String command, ObjectNode body,
        JsonNode result) {//from  w w  w  .  j  ava2 s  .  c o m
    ObjectNode node = JsonHandler.createObjectNode();
    ObjectNode node2 = node.putObject(method.name());
    node2.put(REST_FIELD.JSON_PATH.field, "/" + path);
    node2.put(REST_ROOT_FIELD.JSON_COMMAND.field, command);
    if (body != null) {
        node2.set(RestArgument.REST_FIELD.JSON_JSON.field, body);
    }
    if (result != null) {
        node2.set(RestArgument.REST_GROUP.ARGS_ANSWER.group, result);
    }
    return node;
}

From source file:models.daos.DatasetDao.java

public static ObjectNode getDatasetUrnForPropertiesLike(String properties) {
    ObjectNode result = Json.newObject();
    List<String> datasetUrns = new ArrayList<String>();
    if (StringUtils.isNotBlank(properties)) {
        Map<String, Object> params = new HashMap<>();
        params.put("properties", properties);
        List<Map<String, Object>> rows = null;
        rows = JdbcUtil.wherehowsNamedJdbcTemplate.queryForList(GET_DATASET_URN_PROPERTIES_LIKE_EXPR, params);
        for (Map row : rows) {
            String datasetUrn = (String) row.get("urn");
            datasetUrns.add(datasetUrn);
        }// w  w w  .j a v a2 s.c  o  m
        result.put("count", datasetUrns.size());
        result.set("urns", Json.toJson(datasetUrns));
    }
    return result;
}

From source file:org.waarp.openr66.protocol.http.rest.test.HttpTestRestR66Client.java

protected static AbstractDbData getItem(RESTHANDLERS data) throws HttpInvalidAuthenticationException {
    switch (data) {
    case DbConfiguration:
        return new DbConfiguration(null, hostid, limit, limit, limit, limit, delaylimit);
    case DbHostAuth:
        return new DbHostAuth(null, hostid, address, HttpTestR66PseudoMain.config.REST_PORT, false,
                hostkey.getBytes(), false, false);
    case DbHostConfiguration:
        return new DbHostConfiguration(null, hostid, business, roles, aliases, others);
    case DbRule:/*w  ww. j a  va2  s .  c  o m*/
        return new DbRule(null, idRule, ids, 2, "/recv", "/send", "/arch", "/work", tasks, tasks, tasks, tasks,
                tasks, tasks);
    case DbTaskRunner:
        ObjectNode source = JsonHandler.createObjectNode();
        source.put(Columns.IDRULE.name(), idRule);
        source.put(Columns.RANK.name(), 0);
        source.put(Columns.BLOCKSZ.name(), 65536);
        source.put(Columns.FILEINFO.name(), "file info");
        source.put(Columns.FILENAME.name(), "filename");
        source.put(Columns.GLOBALLASTSTEP.name(), TASKSTEP.NOTASK.ordinal());
        source.put(Columns.GLOBALSTEP.name(), TASKSTEP.NOTASK.ordinal());
        source.put(Columns.INFOSTATUS.name(), ErrorCode.Unknown.ordinal());
        source.put(Columns.ISMOVED.name(), false);
        source.put(Columns.MODETRANS.name(), 2);
        source.put(Columns.ORIGINALNAME.name(), "original filename");
        source.put(Columns.OWNERREQ.name(), Configuration.configuration.HOST_ID);
        source.put(Columns.SPECIALID.name(), DbConstant.ILLEGALVALUE);
        source.put(Columns.REQUESTED.name(), hostid);
        source.put(Columns.REQUESTER.name(), hostid);
        source.put(Columns.RETRIEVEMODE.name(), true);
        source.put(Columns.STARTTRANS.name(), System.currentTimeMillis());
        source.put(Columns.STOPTRANS.name(), System.currentTimeMillis());
        source.put(Columns.STEP.name(), -1);
        source.put(Columns.STEPSTATUS.name(), ErrorCode.Unknown.ordinal());
        source.put(Columns.TRANSFERINFO.name(), "transfer info");
        source.put(DbTaskRunner.JSON_RESCHEDULE, false);
        source.put(DbTaskRunner.JSON_THROUGHMODE, false);
        source.put(DbTaskRunner.JSON_ORIGINALSIZE, 123L);
        try {
            return new DbTaskRunner(null, source);
        } catch (WaarpDatabaseException e) {
            throw new HttpInvalidAuthenticationException(e);
        }
    default:
        break;
    }
    return null;
}

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

public static Result favoriteDataset(int id) {
    ObjectNode result = Json.newObject();
    String username = session("user");
    if (StringUtils.isNotBlank(username)) {
        if (DatasetsDAO.favorite(id, username)) {
            result.put("status", "success");
        } else {/*www .  j  a  v a  2s. c o  m*/
            result.put("status", "failed");
        }
    } else {
        result.put("status", "failed");
    }

    return ok(result);
}

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

public static Result unfavoriteDataset(int id) {
    ObjectNode result = Json.newObject();
    String username = session("user");
    if (StringUtils.isNotBlank(username)) {
        if (DatasetsDAO.unfavorite(id, username)) {
            result.put("status", "success");
        } else {/*from  w w  w.  j a va  2s. c  o  m*/
            result.put("status", "failed");
        }
    } else {
        result.put("status", "failed");
    }

    return ok(result);
}

From source file:com.redhat.jenkins.plugins.ci.messaging.ActiveMqMessagingWorker.java

public static String formatMessage(Message message) {
    StringBuilder sb = new StringBuilder();

    try {/*from  www.j  a v  a2s.  co m*/
        String headers = formatHeaders(message);
        if (headers.length() > 0) {
            sb.append("Message Headers:\n");
            sb.append(headers);
        }

        sb.append("Message Properties:\n");
        @SuppressWarnings("unchecked")
        Enumeration<String> propNames = message.getPropertyNames();
        while (propNames.hasMoreElements()) {
            String propertyName = propNames.nextElement();
            sb.append("  ");
            sb.append(propertyName);
            sb.append(": ");
            if (message.getObjectProperty(propertyName) != null) {
                sb.append(message.getObjectProperty(propertyName).toString());
            }
            sb.append("\n");
        }

        sb.append("Message Content:\n");
        if (message instanceof TextMessage) {
            sb.append(((TextMessage) message).getText());
        } else if (message instanceof MapMessage) {
            MapMessage mm = (MapMessage) message;
            ObjectMapper mapper = new ObjectMapper();
            ObjectNode root = mapper.createObjectNode();

            @SuppressWarnings("unchecked")
            Enumeration<String> e = mm.getMapNames();
            while (e.hasMoreElements()) {
                String field = e.nextElement();
                root.put(field, mapper.convertValue(mm.getObject(field), JsonNode.class));
            }
            sb.append(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(root));
        } else if (message instanceof BytesMessage) {
            BytesMessage bm = (BytesMessage) message;
            bm.reset();
            byte[] bytes = new byte[(int) bm.getBodyLength()];
            if (bm.readBytes(bytes) == bm.getBodyLength()) {
                sb.append(new String(bytes));
            }
        } else {
            sb.append("  Unhandled message type: " + message.getJMSType());
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, "Unable to format message:", e);
    }

    return sb.toString();
}

From source file:com.github.fge.jsonschema.servlets.SyntaxValidateServlet.java

private static JsonNode buildParsingError(final JsonProcessingException e, final boolean crlf) {
    final JsonLocation location = e.getLocation();
    final ObjectNode ret = JsonNodeFactory.instance.objectNode();

    /*//from  w ww  .ja v  a  2  s.c  o  m
     * Unfortunately, for some reason, Jackson botches the column number in
     * its JsonPosition -- I cannot figure out why exactly. However, it does
     * have a correct offset into the buffer.
     *
     * The problem is that if the input has CR/LF line terminators, its
     * offset will be "off" by the number of lines minus 1 with regards to
     * what JavaScript sees as positions in text areas. Make the necessary
     * adjustments so that the caret jumps at the correct position in this
     * case.
     */
    final int lineNr = location.getLineNr();
    int offset = (int) location.getCharOffset();
    if (crlf)
        offset = offset - lineNr + 1;
    ret.put(ParseError.LINE, lineNr);
    ret.put(ParseError.OFFSET, offset);

    // Finally, put the message
    ret.put(ParseError.MESSAGE, e.getOriginalMessage());
    return ret;
}

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

public static Result ownDataset(int id) {
    ObjectNode result = Json.newObject();
    String username = session("user");
    if (StringUtils.isNotBlank(username)) {
        result = DatasetsDAO.ownDataset(id, username);
    } else {/* w  ww. j a v a  2s. com*/
        result.put("status", "failed");
    }

    return ok(result);
}