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 unownDataset(int id) {
    ObjectNode result = Json.newObject();
    String username = session("user");
    if (StringUtils.isNotBlank(username)) {
        result = DatasetsDAO.unownDataset(id, username);
    } else {/* ww w .  j  a v a  2  s  .  co  m*/
        result.put("status", "failed");
    }

    return ok(result);
}

From source file:controllers.ExpertApp.java

@SuppressWarnings("deprecation")
@Transactional(readOnly = true)//from  ww  w.  j  av  a2s  .  co m
public static Result getExpertInfo(Long expertUserId) {
    Expert expert = Expert.getExpertByUserId(expertUserId);
    ObjectNode node = Json.newObject();
    String countSql = "select count(m) from Comment m where toCommentUser.id = :id and level >= :commentLevel ";
    Long total = (Long) JPA.em().createQuery(countSql).setParameter("id", expert.userId)
            .setParameter("commentLevel", 3).getSingleResult();
    String headUrl = "";
    if (StringUtils.isBlank(expert.headUrl)) {
        headUrl = Assets.getDefaultAvatar();
    } else {
        headUrl = Assets.at(expert.headUrl);
    }
    JsonNode skillNode = null;
    if (StringUtils.isNotBlank(expert.skillsTags))
        skillNode = Json.parse(expert.skillsTags);
    else
        skillNode = Json.parse("[]");
    node.put("skillTagsArray", skillNode);
    node.put("status", "200");
    node.put("sex", expert.user.getGenderWithDefault().toString());
    node.put("userName", expert.userName);
    node.put("skillTags", expert.skillsTags);
    node.put("country", expert.country);
    node.put("countryImgUrl", Constants.countryPicKV.get(expert.country));
    node.put("headImgUrl", headUrl);
    node.put("linkUrl", routes.ExpertApp.detail(expertUserId).url());
    node.put("job", expert.job);
    node.put("personalInfo", expert.personalInfo);
    node.put("goodCommentNum", total);
    return ok(node);
}

From source file:json_cmp.Comparer.java

private static void changeStreamsPath(ObjectNode streamsObj) {
    String pathStr = streamsObj.path("path").toString();
    //System.out.println(pathStr);
    String[] temp;//from  w ww.j  a v a  2s.c  o m
    pathStr = pathStr.replace(".mp4", "");
    pathStr = pathStr.replace("\"", "");
    pathStr = pathStr.replace("/", "");
    pathStr = pathStr.replaceAll("&devtype[^&$]*", "");
    pathStr = pathStr.replaceAll("&plrs[^&$]*", "");
    pathStr = pathStr.replaceAll("&x=[^&$]*", "");
    pathStr = pathStr.replaceAll("&s=[^&$]*", "");

    temp = pathStr.split("\\?");
    pathStr = temp[0];
    if (temp.length < 2) {
        streamsObj.put("path", pathStr);
        return;
    }
    temp = temp[1].split("&");
    String regionStr = "";
    String siteStr = "";
    for (int i = 0; i < temp.length; i++) {
        if (temp[i].startsWith("region")) {
            regionStr = temp[i];
            temp[i] = "";
        } else if (temp[i].startsWith("site")) {
            siteStr = temp[i];
            temp[i] = "";
        }
    }
    for (int i = 0; i < temp.length; i++)
        pathStr += temp[i];
    pathStr += regionStr;
    pathStr += siteStr;
    streamsObj.put("path", pathStr);
    //System.out.println(pathStr);
}

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

protected static RestFuture realAllData(Channel channel, RESTHANDLERS data)
        throws HttpInvalidAuthenticationException {
    logger.debug("Send query");
    String key = null, value = null;
    if (HttpTestR66PseudoMain.config.REST_AUTHENTICATED) {
        key = userAuthent;/* w  w w  . j a  v  a2s. co  m*/
        value = keyAuthent;
    }
    ObjectNode answer = JsonHandler.createObjectNode();
    switch (data) {
    case DbConfiguration:
        answer.put(DbConfigurationR66RestMethodHandler.FILTER_ARGS.BANDWIDTH.name(), -1);
        break;
    case DbHostAuth:
        answer.put(DbHostAuthR66RestMethodHandler.FILTER_ARGS.ISSSL.name(), true);
        answer.put(DbHostAuthR66RestMethodHandler.FILTER_ARGS.ISACTIVE.name(), true);
        break;
    case DbHostConfiguration:
        answer.put(DbHostConfigurationR66RestMethodHandler.FILTER_ARGS.BUSINESS.name(), "hosta");
        break;
    case DbRule:
        answer.put(DbRuleR66RestMethodHandler.FILTER_ARGS.MODETRANS.name(), 2);
        break;
    case DbTaskRunner:
        answer.put(DbTaskRunnerR66RestMethodHandler.FILTER_ARGS.STOPTRANS.name(), new DateTime().toString());
        answer.put(Columns.OWNERREQ.name(), Configuration.configuration.HOST_ID);
        break;
    default:
        RestFuture restFuture = channel.attr(HttpRestClientSimpleResponseHandler.RESTARGUMENT).get();
        restFuture.cancel();
        WaarpSslUtility.closingSslChannel(channel);
        return restFuture;
    }
    RestFuture future = clientHelper.sendQuery(HttpTestR66PseudoMain.config, channel, HttpMethod.GET, host,
            data.uri, key, value, null, JsonHandler.writeAsString(answer));
    logger.debug("Query sent");
    return future;
}

From source file:org.wrml.runtime.format.application.vnd.wrml.design.schema.SchemaDesignFormatter.java

public static ObjectNode createSchemaDesignObjectNode(final ObjectMapper objectMapper, final Schema schema) {

    final Context context = schema.getContext();
    final SyntaxLoader syntaxLoader = context.getSyntaxLoader();
    final SchemaLoader schemaLoader = context.getSchemaLoader();
    final ObjectNode rootNode = objectMapper.createObjectNode();

    final URI schemaUri = schema.getUri();
    final Prototype prototype = schemaLoader.getPrototype(schemaUri);

    rootNode.put(PropertyName.uri.name(), syntaxLoader.formatSyntaxValue(schemaUri));
    rootNode.put(PropertyName.title.name(), schema.getTitle());
    rootNode.put(PropertyName.description.name(), schema.getDescription());
    rootNode.put(PropertyName.version.name(), schema.getVersion());

    final String titleSlotName = getTitleSlotName(schemaUri, schemaLoader);
    if (titleSlotName != null) {
        rootNode.put(PropertyName.titleSlotName.name(), titleSlotName);
    }//from  ww  w. j av a 2  s . c  om

    final UniqueName uniqueName = schema.getUniqueName();
    final ObjectNode uniqueNameNode = objectMapper.createObjectNode();
    uniqueNameNode.put(PropertyName.fullName.name(), uniqueName.getFullName());
    uniqueNameNode.put(PropertyName.namespace.name(), uniqueName.getNamespace());
    uniqueNameNode.put(PropertyName.localName.name(), uniqueName.getLocalName());
    rootNode.put(PropertyName.uniqueName.name(), uniqueNameNode);

    final Set<URI> declaredBaseSchemaUris = prototype.getDeclaredBaseSchemaUris();
    if (declaredBaseSchemaUris != null && !declaredBaseSchemaUris.isEmpty()) {
        final Set<URI> addedBaseSchemaUris = new LinkedHashSet<>();
        final ArrayNode baseSchemasNode = objectMapper.createArrayNode();
        rootNode.put(PropertyName.baseSchemas.name(), baseSchemasNode);

        for (final URI baseSchemaUri : declaredBaseSchemaUris) {
            if (!addedBaseSchemaUris.contains(baseSchemaUri)) {
                final ObjectNode baseSchemaNode = buildSchemaNode(objectMapper, baseSchemaUri, schemaLoader,
                        addedBaseSchemaUris);
                baseSchemasNode.add(baseSchemaNode);
                addedBaseSchemaUris.add(baseSchemaUri);
            }
        }
    }

    final Set<String> keySlotNames = prototype.getDeclaredKeySlotNames();
    if (keySlotNames != null && !keySlotNames.isEmpty()) {
        final ArrayNode keyPropertyNamesNode = objectMapper.createArrayNode();

        for (final String keySlotName : keySlotNames) {
            keyPropertyNamesNode.add(keySlotName);
        }

        if (keyPropertyNamesNode.size() > 0) {
            rootNode.put(PropertyName.keyPropertyNames.name(), keyPropertyNamesNode);
        }
    }

    final Set<String> allKeySlotNames = prototype.getAllKeySlotNames();
    final ArrayNode allKeySlotNamesNode = objectMapper.createArrayNode();
    rootNode.put(PropertyName.allKeySlotNames.name(), allKeySlotNamesNode);

    final ObjectNode keySlotMap = objectMapper.createObjectNode();
    rootNode.put(PropertyName.keys.name(), keySlotMap);

    final String uriSlotName = PropertyName.uri.name();
    if (allKeySlotNames.contains(uriSlotName)) {
        allKeySlotNamesNode.add(uriSlotName);

        final ObjectNode slot = createSlot(objectMapper, prototype, uriSlotName);
        keySlotMap.put(uriSlotName, slot);
    }

    for (final String keySlotName : allKeySlotNames) {
        if (!Document.SLOT_NAME_URI.equals(keySlotName)) {
            allKeySlotNamesNode.add(keySlotName);

            final ObjectNode slot = createSlot(objectMapper, prototype, keySlotName);
            keySlotMap.put(keySlotName, slot);
        }
    }

    rootNode.put(PropertyName.keyCount.name(), keySlotMap.size());

    final SortedSet<String> allSlotNames = prototype.getAllSlotNames();

    if (allSlotNames != null && !allSlotNames.isEmpty()) {

        final ObjectNode slotMapNode = objectMapper.createObjectNode();
        rootNode.put(PropertyName.slots.name(), slotMapNode);

        final ArrayNode propertyNamesNode = objectMapper.createArrayNode();

        for (final String slotName : allSlotNames) {
            final ProtoSlot protoSlot = prototype.getProtoSlot(slotName);
            if (protoSlot instanceof LinkProtoSlot) {
                continue;
            }

            if (allKeySlotNames.contains(slotName)) {
                // Skip key slots (handled separately)
                continue;
            }

            if (protoSlot.getDeclaringSchemaUri().equals(schemaUri)) {
                propertyNamesNode.add(slotName);
            }

            final ObjectNode slotNode = createSlot(objectMapper, prototype, slotName);

            if (slotNode != null) {
                slotMapNode.put(slotName, slotNode);
            }

        }
        if (propertyNamesNode.size() > 0) {
            rootNode.put(PropertyName.propertyNames.name(), propertyNamesNode);
        }

        rootNode.put(PropertyName.slotCount.name(), slotMapNode.size());
    }

    final Set<String> comparablePropertyNames = prototype.getComparableSlotNames();
    if (comparablePropertyNames != null && !comparablePropertyNames.isEmpty()) {
        final ArrayNode comparablePropertyNamesNode = objectMapper.createArrayNode();

        for (final String comparablePropertyName : comparablePropertyNames) {
            comparablePropertyNamesNode.add(comparablePropertyName);
        }

        if (comparablePropertyNamesNode.size() > 0) {
            rootNode.put(PropertyName.comparablePropertyNames.name(), comparablePropertyNamesNode);
        }
    }

    final Collection<LinkProtoSlot> linkProtoSlots = prototype.getLinkProtoSlots().values();
    if (linkProtoSlots != null && !linkProtoSlots.isEmpty()) {
        final ArrayNode linkNamesNode = objectMapper.createArrayNode();
        final ObjectNode linksMapNode = objectMapper.createObjectNode();
        rootNode.put(PropertyName.links.name(), linksMapNode);

        for (final LinkProtoSlot linkProtoSlot : linkProtoSlots) {

            if (linkProtoSlot.getDeclaringSchemaUri().equals(schemaUri)) {
                linkNamesNode.add(linkProtoSlot.getName());
            }

            final ObjectNode linkNode = objectMapper.createObjectNode();

            String linkTitle = linkProtoSlot.getTitle();
            if (linkTitle == null) {
                linkTitle = linkProtoSlot.getName();
            }

            linkNode.put(PropertyName.name.name(), linkProtoSlot.getName());
            linkNode.put(PropertyName.title.name(), linkTitle);

            final Method method = linkProtoSlot.getMethod();
            final URI linkRelationUri = linkProtoSlot.getLinkRelationUri();
            final URI declaringSchemaUri = linkProtoSlot.getDeclaringSchemaUri();

            linkNode.put(PropertyName.rel.name(), syntaxLoader.formatSyntaxValue(linkRelationUri));

            final Keys linkRelationKeys = context.getApiLoader().buildDocumentKeys(linkRelationUri,
                    schemaLoader.getLinkRelationSchemaUri());
            final LinkRelation linkRelation = context.getModel(linkRelationKeys,
                    schemaLoader.getLinkRelationDimensions());

            linkNode.put(PropertyName.relationTitle.name(), linkRelation.getTitle());
            linkNode.put(PropertyName.description.name(), linkProtoSlot.getDescription());
            linkNode.put(PropertyName.method.name(), method.getProtocolGivenName());
            linkNode.put(PropertyName.declaringSchemaUri.name(),
                    syntaxLoader.formatSyntaxValue(declaringSchemaUri));

            URI requestSchemaUri = linkProtoSlot.getRequestSchemaUri();
            if (schemaLoader.getDocumentSchemaUri().equals(requestSchemaUri)) {
                if (SystemLinkRelation.self.getUri().equals(linkRelationUri)
                        || SystemLinkRelation.save.getUri().equals(linkRelationUri)) {
                    requestSchemaUri = schemaUri;
                }
            }

            if (requestSchemaUri == null && method == Method.Save) {
                requestSchemaUri = schemaUri;
            }

            if (requestSchemaUri != null) {
                linkNode.put(PropertyName.requestSchemaUri.name(),
                        syntaxLoader.formatSyntaxValue(requestSchemaUri));

                final Schema requestSchema = schemaLoader.load(requestSchemaUri);
                if (requestSchema != null) {
                    linkNode.put(PropertyName.requestSchemaTitle.name(), requestSchema.getTitle());
                }
            }

            URI responseSchemaUri = linkProtoSlot.getResponseSchemaUri();
            if (schemaLoader.getDocumentSchemaUri().equals(responseSchemaUri)) {
                if (SystemLinkRelation.self.getUri().equals(linkRelationUri)
                        || SystemLinkRelation.save.getUri().equals(linkRelationUri)) {
                    responseSchemaUri = schemaUri;
                }
            }

            if (responseSchemaUri != null) {
                linkNode.put(PropertyName.responseSchemaUri.name(),
                        syntaxLoader.formatSyntaxValue(responseSchemaUri));

                final Schema responseSchema = schemaLoader.load(responseSchemaUri);
                if (responseSchema != null) {
                    linkNode.put(PropertyName.responseSchemaTitle.name(), responseSchema.getTitle());
                }
            }

            linksMapNode.put(linkTitle, linkNode);

        }

        if (linkNamesNode.size() > 0) {
            rootNode.put(PropertyName.linkNames.name(), linkNamesNode);
        }

        rootNode.put(PropertyName.linkCount.name(), linksMapNode.size());

    }

    return rootNode;
}

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

public static Result watchURN() {
    Map<String, String[]> params = request().body().asFormUrlEncoded();
    ObjectNode result = Json.newObject();

    String username = session("user");
    if (StringUtils.isNotBlank(username)) {
        String message = DatasetsDAO.watchURN(params, username);
        if (StringUtils.isBlank(message)) {
            result.put("status", "success");
        } else {//  w w w. j  ava2s. c  o  m
            result.put("status", "failed");
            result.put("message", message);
        }
    } else {
        result.put("status", "failed");
        result.put("message", "User is not authenticated");
    }
    return ok(result);
}

From source file:com.almende.eve.agent.example.MyFirstAgent.java

/**
 * Through this method the agent calls itself and prints the result to the
 * console.//  www .  ja va  2s  .  c  om
 *
 * @throws IOException Signals that an I/O exception has occurred.
 * @throws JSONRPCException the jSONRPC exception
 */
public void callMyself() throws IOException, JSONRPCException {
    final ObjectNode params = JOM.createObjectNode();
    params.put("name", getId());
    final String result = send(getFirstUrl(), "helloWorld", params, String.class);
    System.out.println("Got reply:" + result);
}

From source file:com.zero_x_baadf00d.partialize.converter.DefaultConverter.java

@Override
public void convert(final String fieldName, final Object data, final ObjectNode node) {
    node.put(fieldName, data.toString());
}

From source file:org.isaacphysics.labs.chemistry.checker.RunParser.java

public String toJSON(String input, String result) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode node1 = mapper.createObjectNode();
    node1.put("result", result);
    node1.put("input", input);
    return mapper.writeValueAsString(node1);
}

From source file:com.almende.eve.demo.MyFirstAgent.java

/**
 * Async echo, this method answers the echo request through a separate, asynchronous call.
 *
 * @param message/*w ww .  j a  va  2s  .  c om*/
 *            the message
 * @param senderUrl
 *            the sender url
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public void asyncEcho(@Name("message") String message, @Sender URI senderUrl) throws IOException {

    String returnMessage = "You said:" + message;
    ObjectNode params = JOM.createObjectNode();
    params.put("returnMessage", returnMessage);

    call(senderUrl, "result", params);

}