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

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

Introduction

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

Prototype

public String toString() 

Source Link

Usage

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

@Override
public InputStream replaceProperty(final InputStream src, final InputStream replacement,
        final List<String> path, final boolean justValue) throws IOException {

    final ObjectNode srcNode = (ObjectNode) mapper.readTree(src);
    IOUtils.closeQuietly(src);/*from  ww w  . ja  v  a  2s .c  om*/

    JsonNode replacementNode;
    if (justValue) {
        replacementNode = new TextNode(IOUtils.toString(replacement));
    } else {
        replacementNode = mapper.readTree(replacement);
        if (replacementNode.has("value")) {
            replacementNode = replacementNode.get("value");
        }
    }
    IOUtils.closeQuietly(replacement);

    JsonNode node = srcNode;
    for (int i = 0; i < path.size() - 1; i++) {
        node = node.get(path.get(i));
        if (node == null) {
            throw new NotFoundException();
        }
    }

    ((ObjectNode) node).set(path.get(path.size() - 1), replacementNode);

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

From source file:org.apache.syncope.core.workflow.flowable.FlowableUserWorkflowAdapter.java

protected void exportProcessModel(final String key, final OutputStream os) {
    Model model = getModel(getProcessDefinitionByKey(key));

    try {/*from   w w w .  j  a v a  2  s. c  om*/
        ObjectNode modelNode = (ObjectNode) OBJECT_MAPPER.readTree(model.getMetaInfo());
        modelNode.put(ModelDataJsonConstants.MODEL_ID, model.getId());
        modelNode.replace(MODEL_DATA_JSON_MODEL,
                OBJECT_MAPPER.readTree(engine.getRepositoryService().getModelEditorSource(model.getId())));

        os.write(modelNode.toString().getBytes());
    } catch (IOException e) {
        LOG.error("While exporting workflow definition {}", model.getId(), e);
    }
}

From source file:org.thingsboard.server.dao.audit.sink.ElasticsearchAuditLogSink.java

private String createElasticJsonRecord(AuditLog auditLog) {
    ObjectNode auditLogNode = mapper.createObjectNode();
    auditLogNode.put("postDate", LocalDateTime.now().toString());
    auditLogNode.put("id", auditLog.getId().getId().toString());
    auditLogNode.put("entityName", auditLog.getEntityName());
    auditLogNode.put("tenantId", auditLog.getTenantId().getId().toString());
    if (auditLog.getCustomerId() != null) {
        auditLogNode.put("customerId", auditLog.getCustomerId().getId().toString());
    }//from  w ww .  jav a  2s. co  m
    auditLogNode.put("entityId", auditLog.getEntityId().getId().toString());
    auditLogNode.put("entityType", auditLog.getEntityId().getEntityType().name());
    auditLogNode.put("userId", auditLog.getUserId().getId().toString());
    auditLogNode.put("userName", auditLog.getUserName());
    auditLogNode.put("actionType", auditLog.getActionType().name());
    if (auditLog.getActionData() != null) {
        auditLogNode.put("actionData", auditLog.getActionData().toString());
    }
    auditLogNode.put("actionStatus", auditLog.getActionStatus().name());
    auditLogNode.put("actionFailureDetails", auditLog.getActionFailureDetails());
    return auditLogNode.toString();
}

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

@Override
public InputStream selectEntity(final InputStream src, final String[] propertyNames) throws IOException {

    final ObjectNode srcNode = (ObjectNode) mapper.readTree(src);

    final Set<String> retain = new HashSet<String>();
    retain.add(Constants.get(ConstantKey.JSON_ID_NAME));
    retain.add(Constants.get(ConstantKey.JSON_TYPE_NAME));
    retain.add(Constants.get(ConstantKey.JSON_EDITLINK_NAME));
    retain.add(Constants.get(ConstantKey.JSON_NEXTLINK_NAME));
    retain.add(Constants.get(ConstantKey.JSON_ODATAMETADATA_NAME));
    retain.add(Constants.get(ConstantKey.JSON_VALUE_NAME));

    for (String name : propertyNames) {
        retain.add(name);//from w w w. j  a v a2s .  c  om
        retain.add(name + Constants.get(ConstantKey.JSON_NAVIGATION_SUFFIX));
        retain.add(name + Constants.get(ConstantKey.JSON_MEDIA_SUFFIX));
        retain.add(name + Constants.get(ConstantKey.JSON_TYPE_SUFFIX));
    }

    srcNode.retain(retain);

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

From source file:controllers.AnyplaceMapping.java

/**
 * Retrieve all the pois of a building/floor combination.
 *
 * @return// w w w  . j a v a  2 s .c o  m
 */
public static Result poisByBuid() {
    OAuth2Request anyReq = new OAuth2Request(request(), response());
    if (!anyReq.assertJsonBody()) {
        return AnyResponseHelper.bad_request(AnyResponseHelper.CANNOT_PARSE_BODY_AS_JSON);
    }
    JsonNode json = anyReq.getJsonBody();
    LPLogger.info("AnyplaceMapping::poisByBuid(): " + json.toString());

    List<String> requiredMissing = JsonUtils.requirePropertiesInJson(json, "buid");
    if (!requiredMissing.isEmpty()) {
        return AnyResponseHelper.requiredFieldsMissing(requiredMissing);
    }

    String buid = json.findPath("buid").textValue();
    try {
        List<JsonNode> pois = ProxyDataSource.getIDatasource().poisByBuildingAsJson(buid);
        ObjectNode res = JsonUtils.createObjectNode();
        res.put("pois", JsonUtils.getJsonFromList(pois));
        try {
            //                if (request().getHeader("Accept-Encoding") != null && request().getHeader("Accept-Encoding").contains("gzip")) {
            return gzippedJSONOk(res.toString());
            //                }
            //                return AnyResponseHelper.ok(res.toString());
        } catch (IOException ioe) {
            return AnyResponseHelper.ok(res, "Successfully retrieved all pois from building.");
        }
    } catch (DatasourceException e) {
        return AnyResponseHelper.internal_server_error("Server Internal Error [" + e.getMessage() + "]");
    }
}

From source file:controllers.AnyplaceMapping.java

/**
 * Retrieve all the pois of a building/floor combination.
 *
 * @return//  ww w . jav a  2 s. c om
 */
public static Result poisByFloor() {
    OAuth2Request anyReq = new OAuth2Request(request(), response());
    if (!anyReq.assertJsonBody()) {
        return AnyResponseHelper.bad_request(AnyResponseHelper.CANNOT_PARSE_BODY_AS_JSON);
    }
    JsonNode json = anyReq.getJsonBody();
    LPLogger.info("AnyplaceMapping::poisByFloor(): " + json.toString());

    List<String> requiredMissing = JsonUtils.requirePropertiesInJson(json, "buid", "floor_number");
    if (!requiredMissing.isEmpty()) {
        return AnyResponseHelper.requiredFieldsMissing(requiredMissing);
    }

    String buid = json.findPath("buid").textValue();
    String floor_number = json.findPath("floor_number").textValue();
    try {
        List<JsonNode> pois = ProxyDataSource.getIDatasource().poisByBuildingFloorAsJson(buid, floor_number);
        ObjectNode res = JsonUtils.createObjectNode();
        res.put("pois", JsonUtils.getJsonFromList(pois));
        try {
            //                if (request().getHeader("Accept-Encoding") != null && request().getHeader("Accept-Encoding").contains("gzip")) {
            return gzippedJSONOk(res.toString());
            //                }
            //                return AnyResponseHelper.ok(res.toString());
        } catch (IOException ioe) {
            return AnyResponseHelper.ok(res,
                    "Successfully retrieved all pois from floor " + floor_number + "!");
        }
    } catch (DatasourceException e) {
        return AnyResponseHelper.internal_server_error("Server Internal Error [" + e.getMessage() + "]");
    }
}

From source file:controllers.AnyplaceMapping.java

/**
 * Retrieve all the buildings.//from  www.ja va 2 s. c  o m
 *
 * @return
 */
public static Result buildingAll() {
    OAuth2Request anyReq = new OAuth2Request(request(), response());
    if (!anyReq.assertJsonBody()) {
        return AnyResponseHelper.bad_request(AnyResponseHelper.CANNOT_PARSE_BODY_AS_JSON);
    }
    JsonNode json = anyReq.getJsonBody();
    LPLogger.info("AnyplaceMapping::buildingAll(): " + json.toString());

    try {
        List<JsonNode> buildings = ProxyDataSource.getIDatasource().getAllBuildings();
        ObjectNode res = JsonUtils.createObjectNode();
        res.put("buildings", JsonUtils.getJsonFromList(buildings));
        try {
            //                if (request().getHeader("Accept-Encoding") != null && request().getHeader("Accept-Encoding").contains("gzip")) {
            return gzippedJSONOk(res.toString());
            //                }
            //                return AnyResponseHelper.ok(res.toString());
        } catch (IOException ioe) {
            return AnyResponseHelper.ok(res, "Successfully retrieved all buildings!");
        }
    } catch (DatasourceException e) {
        return AnyResponseHelper.internal_server_error("Server Internal Error [" + e.getMessage() + "]");
    }
}

From source file:controllers.AnyplaceMapping.java

/**
 * Retrieve all the floors of a building.
 *
 * @return//  w w w . ja v  a2  s  .co m
 */
public static Result floorAll() {
    OAuth2Request anyReq = new OAuth2Request(request(), response());
    if (!anyReq.assertJsonBody()) {
        return AnyResponseHelper.bad_request(AnyResponseHelper.CANNOT_PARSE_BODY_AS_JSON);
    }
    JsonNode json = anyReq.getJsonBody();
    LPLogger.info("AnyplaceMapping::floorAll(): " + json.toString());

    List<String> requiredMissing = JsonUtils.requirePropertiesInJson(json, "buid");
    if (!requiredMissing.isEmpty()) {
        return AnyResponseHelper.requiredFieldsMissing(requiredMissing);
    }

    String buid = json.findPath("buid").textValue();

    try {
        List<JsonNode> buildings = ProxyDataSource.getIDatasource().floorsByBuildingAsJson(buid);
        ObjectNode res = JsonUtils.createObjectNode();
        res.put("floors", JsonUtils.getJsonFromList(buildings));
        try {
            //                if (request().getHeader("Accept-Encoding") != null && request().getHeader("Accept-Encoding").contains("gzip")) {
            return gzippedJSONOk(res.toString());
            //                }
            //                return AnyResponseHelper.ok(res.toString());
        } catch (IOException ioe) {
            return AnyResponseHelper.ok(res, "Successfully retrieved all floors!");
        }
    } catch (DatasourceException e) {
        return AnyResponseHelper.internal_server_error("Server Internal Error [" + e.getMessage() + "]");
    }
}

From source file:controllers.AnyplaceMapping.java

/**
 * Retrieve all the pois of a building/floor combination.
 *
 * @return/* w w w  .j  av a2  s.  c om*/
 */
public static Result connectionsByFloor() {
    OAuth2Request anyReq = new OAuth2Request(request(), response());
    if (!anyReq.assertJsonBody()) {
        return AnyResponseHelper.bad_request(AnyResponseHelper.CANNOT_PARSE_BODY_AS_JSON);
    }
    JsonNode json = anyReq.getJsonBody();
    LPLogger.info("AnyplaceMapping::poisByFloor(): " + json.toString());

    List<String> requiredMissing = JsonUtils.requirePropertiesInJson(json, "buid", "floor_number");
    if (!requiredMissing.isEmpty()) {
        return AnyResponseHelper.requiredFieldsMissing(requiredMissing);
    }

    String buid = json.findPath("buid").textValue();
    String floor_number = json.findPath("floor_number").textValue();
    try {
        List<JsonNode> pois = ProxyDataSource.getIDatasource().connectionsByBuildingFloorAsJson(buid,
                floor_number);
        ObjectNode res = JsonUtils.createObjectNode();
        res.put("connections", JsonUtils.getJsonFromList(pois));
        try {
            //                if (request().getHeader("Accept-Encoding") != null && request().getHeader("Accept-Encoding").contains("gzip")) {
            return gzippedJSONOk(res.toString());
            //                }
            //                return AnyResponseHelper.ok(res.toString());
        } catch (IOException ioe) {
            return AnyResponseHelper.ok(res,
                    "Successfully retrieved all pois from floor " + floor_number + "!");
        }
    } catch (DatasourceException e) {
        return AnyResponseHelper.internal_server_error("Server Internal Error [" + e.getMessage() + "]");
    }
}

From source file:controllers.AnyplaceMapping.java

public static Result buildingByBucode() {
    OAuth2Request anyReq = new OAuth2Request(request(), response());
    if (!anyReq.assertJsonBody()) {
        return AnyResponseHelper.bad_request(AnyResponseHelper.CANNOT_PARSE_BODY_AS_JSON);
    }//from w ww .  j a  v a2  s  .co m
    JsonNode json = anyReq.getJsonBody();
    LPLogger.info("AnyplaceMapping::buildingAll(): " + json.toString());

    List<String> requiredMissing = JsonUtils.requirePropertiesInJson(json, "bucode");
    if (!requiredMissing.isEmpty()) {
        return AnyResponseHelper.requiredFieldsMissing(requiredMissing);
    }

    String bucode = json.findValue("bucode").textValue();

    try {
        List<JsonNode> buildings = ProxyDataSource.getIDatasource().getAllBuildingsByBucode(bucode);
        ObjectNode res = JsonUtils.createObjectNode();
        res.put("buildings", JsonUtils.getJsonFromList(buildings));

        try {
            //                if (request().getHeader("Accept-Encoding") != null && request().getHeader("Accept-Encoding").contains("gzip")) {
            return gzippedJSONOk(res.toString());
            //                }
            //                return AnyResponseHelper.ok(res.toString());
        } catch (IOException ioe) {
            return AnyResponseHelper.ok(res, "Successfully retrieved all buildings!");
        }
    } catch (DatasourceException e) {
        return AnyResponseHelper.internal_server_error("Server Internal Error [" + e.getMessage() + "]");
    }
}