Example usage for com.fasterxml.jackson.databind.node JsonNodeFactory instance

List of usage examples for com.fasterxml.jackson.databind.node JsonNodeFactory instance

Introduction

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

Prototype

JsonNodeFactory instance

To view the source code for com.fasterxml.jackson.databind.node JsonNodeFactory instance.

Click Source Link

Usage

From source file:controllers.impl.StandardApi.java

@Override
public F.Promise<Result> updateStagePackageVersions(final String envName, final String stageName) {
    final models.Stage stage = models.Stage.getByEnvironmentNameAndName(envName, stageName);
    if (stage == null) {
        return F.Promise.pure(notFound());
    }//from   www  . j av  a2 s .  co  m

    final List<models.PackageVersion> versions = Lists.newArrayList();
    final JsonNode requestJson = request().body().asJson();
    if (requestJson == null) {
        return F.Promise.pure(badRequest());
    }
    final ArrayNode packages = (ArrayNode) requestJson.get("packages");
    for (final JsonNode node : packages) {
        final ObjectNode packageNode = (ObjectNode) node;
        final String packageName = packageNode.get("name").asText();
        final String version = packageNode.get("version").asText();
        final PackageVersion pkgVersion = getPackageVersion(packageName, version);
        versions.add(pkgVersion);
    }

    final ManifestHistory currentHistory = ManifestHistory.getCurrentForStage(stage);
    final Manifest currentManifest = currentHistory.getManifest();

    final LinkedHashMap<String, PackageVersion> newPackages = Maps
            .newLinkedHashMap(currentManifest.asPackageMap());
    versions.forEach(pv -> newPackages.put(pv.getPkg().getName(), pv));
    final Manifest newManifest = new Manifest();
    newManifest.getPackages().addAll(newPackages.values());
    newManifest.save();

    final Future<Object> ask = Patterns.ask(_deploymentManager,
            new FleetDeploymentCommands.DeployStage(stage, newManifest, "api"),
            Timeout.apply(30L, TimeUnit.SECONDS));

    return F.Promise.wrap(ask).map(o -> {
        if (o instanceof Deployment) {
            final Deployment deployment = (Deployment) o;
            return ok(JsonNodeFactory.instance.objectNode().put("deployId", deployment.getId()));
        }
        Logger.error("Expected Deployment response from deployment manager, got " + o);
        return internalServerError();
    });
}

From source file:net.hamnaberg.json.Property.java

private static ObjectNode toObject(Map<String, Value> object) {
    ObjectNode objectNode = JsonNodeFactory.instance.objectNode();
    for (Map.Entry<String, Value> entry : object.entrySet()) {
        objectNode.set(entry.getKey(), entry.getValue().asJson());
    }//from   ww w  . ja  va  2 s  . c  om
    return objectNode;
}

From source file:org.jetbrains.webdemo.sessions.MyHttpSession.java

private void sendFileExistenceResult() {
    try {//  ww  w  . j a  v  a 2 s  .c o  m
        ObjectNode response = new ObjectNode(JsonNodeFactory.instance);
        if (MySqlConnector.getInstance().getFile(request.getParameter("publicId")) != null) {
            response.put("exists", true);
        } else {
            response.put("exists", false);
        }
        writeResponse(response.toString(), HttpServletResponse.SC_OK);
    } catch (NullPointerException e) {
        writeResponse("Can't get parameters", HttpServletResponse.SC_BAD_REQUEST);
    } catch (DatabaseOperationException e) {
        writeResponse(e.getMessage(), HttpServletResponse.SC_BAD_REQUEST);
    }
}

From source file:io.fabric8.collector.elasticsearch.ElasticsearchClient.java

public ObjectNode createIndexIfMissing(final String index, final String type,
        Function<ObjectNode, Boolean> updater) {
    ObjectNode metadata = WebClients.handle404ByReturningNull(new Callable<ObjectNode>() {
        @Override//  w  ww . ja  v  a2  s  .co m
        public ObjectNode call() throws Exception {
            return getIndex(index);
        }
    });
    boolean create = false;
    JsonNodeFactory nodeFactory = JsonNodeFactory.instance;
    if (metadata == null) {
        create = true;
        metadata = nodeFactory.objectNode();
        /*
                    ObjectNode properties = JsonNodes.setObjects(metadata, index, "mappings", type, "properties");
                    if (properties == null) {
        LOG.warn("Failed to create object path!");
                    }
        */
    }
    if (!updater.apply(metadata)) {
        return null;
    }
    if (create) {
        return getElasticsearchAPI().createIndex(index, metadata);
    } else {
        return null;
    }
}

From source file:org.apache.olingo.fit.utils.Commons.java

public static InputStream getLinksAsJSON(final String entitySetName,
        final Map.Entry<String, Collection<String>> link) throws IOException {

    final ObjectNode links = new ObjectNode(JsonNodeFactory.instance);
    links.put(Constants.get(ConstantKey.JSON_ODATAMETADATA_NAME),
            Constants.get(ConstantKey.ODATA_METADATA_PREFIX) + entitySetName + "/$links/" + link.getKey());

    final ArrayNode uris = new ArrayNode(JsonNodeFactory.instance);

    for (String uri : link.getValue()) {
        final String absoluteURI;
        if (URI.create(uri).isAbsolute()) {
            absoluteURI = uri;//from  w  ww.j  a  v  a  2 s  . c  o  m
        } else {
            absoluteURI = Constants.get(ConstantKey.DEFAULT_SERVICE_URL) + uri;
        }
        uris.add(new ObjectNode(JsonNodeFactory.instance).put("url", absoluteURI));
    }

    if (uris.size() == 1) {
        links.setAll((ObjectNode) uris.get(0));
    } else {
        links.set("value", uris);
    }

    return IOUtils.toInputStream(links.toString(), Constants.ENCODING);
}

From source file:models.protocol.v2.MetricMessagesProcessor.java

private void processMetricsList(final MetricsList metricsList) {
    //TODO(barp): Map with a POJO mapper [MAI-184]
    final ObjectNode dataNode = JsonNodeFactory.instance.objectNode();
    final ArrayNode services = JsonNodeFactory.instance.arrayNode();
    for (final Map.Entry<String, Map<String, Set<String>>> service : metricsList.getMetrics().entrySet()) {
        final ObjectNode serviceObject = JsonNodeFactory.instance.objectNode();
        serviceObject.put("name", service.getKey());
        final ArrayNode metrics = JsonNodeFactory.instance.arrayNode();
        for (final Map.Entry<String, Set<String>> metric : service.getValue().entrySet()) {
            final ObjectNode metricObject = JsonNodeFactory.instance.objectNode();
            metricObject.put("name", metric.getKey());
            final ArrayNode stats = JsonNodeFactory.instance.arrayNode();
            for (final String statistic : metric.getValue()) {
                final ObjectNode statsObject = JsonNodeFactory.instance.objectNode();
                statsObject.put("name", statistic);
                statsObject.set("children", JsonNodeFactory.instance.arrayNode());
                stats.add(statsObject);//ww  w  . j  a  v a 2  s  .com
            }
            metricObject.set("children", stats);
            metrics.add(metricObject);
        }
        serviceObject.set("children", metrics);
        services.add(serviceObject);
    }
    dataNode.set("metrics", services);
    _connectionContext.sendCommand(COMMAND_METRICS_LIST, dataNode);
}

From source file:io.gs2.timer.Gs2TimerClient.java

/**
 * ???<br>//from   w w w  .  jav  a2 s. co  m
 * <br>
 *
 * @param request 
        
 * @return ?
        
 */

public UpdateTimerPoolResult updateTimerPool(UpdateTimerPoolRequest request) {

    ObjectNode body = JsonNodeFactory.instance.objectNode();
    if (request.getDescription() != null)
        body.put("description", request.getDescription());
    HttpPut put = createHttpPut(
            Gs2Constant.ENDPOINT_HOST + "/timerPool/"
                    + (request.getTimerPoolName() == null || request.getTimerPoolName().equals("") ? "null"
                            : request.getTimerPoolName())
                    + "",
            credential, ENDPOINT, UpdateTimerPoolRequest.Constant.MODULE,
            UpdateTimerPoolRequest.Constant.FUNCTION, body.toString());
    if (request.getRequestId() != null) {
        put.setHeader("X-GS2-REQUEST-ID", request.getRequestId());
    }

    return doRequest(put, UpdateTimerPoolResult.class);

}

From source file:com.msopentech.odatajclient.testservice.utils.JSONUtilities.java

public static InputStream getJsonProperty(final InputStream src, final String[] path, final String edmType)
        throws Exception {

    final ObjectMapper mapper = new ObjectMapper();
    final JsonNode srcNode = mapper.readTree(src);

    final ObjectNode property = new ObjectNode(JsonNodeFactory.instance);

    if (StringUtils.isNotBlank(edmType)) {
        property.put(JSON_ODATAMETADATA_NAME, ODATA_METADATA_PREFIX + edmType);
    }//  w ww.  ja va  2  s .  c o m

    JsonNode jsonNode = getJsonProperty(srcNode, path, 0);
    if (jsonNode.isObject()) {
        property.putAll((ObjectNode) jsonNode);
    } else {
        property.put("value", jsonNode.asText());
    }

    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    mapper.writeValue(bos, property);

    final InputStream res = new ByteArrayInputStream(bos.toByteArray());
    IOUtils.closeQuietly(bos);

    return res;
}

From source file:io.gs2.notification.Gs2NotificationClient.java

/**
 * ???<br>//from  ww  w.j av a2 s.  c o m
 * <br>
 *
 * @param request 
        
 * @return ?
        
 */

public UpdateNotificationResult updateNotification(UpdateNotificationRequest request) {

    ObjectNode body = JsonNodeFactory.instance.objectNode();
    if (request.getDescription() != null)
        body.put("description", request.getDescription());
    HttpPut put = createHttpPut(Gs2Constant.ENDPOINT_HOST + "/notification/"
            + (request.getNotificationName() == null || request.getNotificationName().equals("") ? "null"
                    : request.getNotificationName())
            + "", credential, ENDPOINT, UpdateNotificationRequest.Constant.MODULE,
            UpdateNotificationRequest.Constant.FUNCTION, body.toString());
    if (request.getRequestId() != null) {
        put.setHeader("X-GS2-REQUEST-ID", request.getRequestId());
    }

    return doRequest(put, UpdateNotificationResult.class);

}

From source file:org.apache.streams.lucene.LuceneSimpleTaggingProcessor.java

@Override
public List<StreamsDatum> process(StreamsDatum entry) {

    LOGGER.debug("{} processing {}", STREAMS_ID, entry.getDocument().getClass());

    List<StreamsDatum> result = Lists.newArrayList();

    List<String> jsons = Lists.newLinkedList();
    ObjectNode node;/*ww  w.  j av a  2s.com*/
    // first check for valid json
    if (this.metaDataKey == null)
        jsons.add(getJson(entry.getDocument()));
    else
        getMetaDataJsons(entry, jsons);

    for (String json : jsons) {
        try {
            node = (ObjectNode) mapper.readTree(json);
        } catch (IOException e) {
            e.printStackTrace();
            return result;
        }

        List<SimpleVerbatim> verbatimList = convertEntryToWorkUnit(json);
        Map<SimpleVerbatim, List<LanguageTag>> objectTags = taggingEngine.findMatches(verbatimList);
        Set<String> tagSet = Sets.newHashSet();
        for (List<LanguageTag> fieldtags : objectTags.values()) {
            for (LanguageTag tag : fieldtags) {
                tagSet.add(tag.getTag());
            }
        }

        ArrayNode tagArray = JsonNodeFactory.instance.arrayNode();
        Set<String> tags = Sets.newHashSet();
        for (String tag : tagSet) {
            if (tags.add(tag)) {
                tagArray.add(tag);
            }
        }

        // need utility methods for get / create specific node
        ObjectNode extensions = (ObjectNode) node.get("extensions");
        if (extensions == null) {
            extensions = JsonNodeFactory.instance.objectNode();
            node.put("extensions", extensions);
        }
        ObjectNode w2o = (ObjectNode) extensions.get("w2o");
        if (w2o == null) {
            w2o = JsonNodeFactory.instance.objectNode();
            extensions.put("w2o", w2o);
        }
        w2o.put("tags", tagArray);
        w2o.put("contentTags", tagArray);
        if (entry.getDocument() instanceof W2OActivity) {
            entry.setDocument(mapper.convertValue(node, W2OActivity.class));
        } else if (entry.getDocument() instanceof Activity) {
            entry.setDocument(mapper.convertValue(node, Activity.class));
        } else if (entry.getDocument() instanceof String) {
            try {
                entry.setDocument(mapper.writeValueAsString(node));
            } catch (JsonProcessingException jpe) {
                LOGGER.error("Exception while converting ObjectNode to string. Outputing as ObjectNode. {}",
                        jpe);
                entry.setDocument(node);
            }
        } else {
            entry.setDocument(node);
        }
        result.add(entry);
    }
    return result;
}