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.ScriptFinder.java

public static Result getScriptRuntimeByJobID(int applicationID, int jobID) {
    ObjectNode result = Json.newObject();

    int attemptNumber = 0;
    String attemptStr = request().getQueryString("attempt_number");
    if (StringUtils.isBlank(attemptStr)) {
        attemptNumber = 0;//from w w  w.  ja v  a 2  s .  c om
    } else {
        try {
            attemptNumber = Integer.parseInt(attemptStr);
        } catch (NumberFormatException e) {
            Logger.error("ScriptFinder Controller getPagedScripts wrong page parameter. Error message: "
                    + e.getMessage());
            attemptNumber = 0;
        }
    }

    result.put("status", "ok");
    result.set("data", Json.toJson(ScriptFinderDAO.getPagedScriptRuntime(applicationID, jobID)));
    return ok(result);
}

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

public static Result getScriptLineageByJobID(int applicationID, int jobID) {
    ObjectNode result = Json.newObject();

    int attemptNumber = 0;
    String attemptStr = request().getQueryString("attempt_number");
    if (StringUtils.isBlank(attemptStr)) {
        attemptNumber = 0;/*  www .ja  v a  2 s  . c  om*/
    } else {
        try {
            attemptNumber = Integer.parseInt(attemptStr);
        } catch (NumberFormatException e) {
            Logger.error("ScriptFinder Controller getPagedScripts wrong page parameter. Error message: "
                    + e.getMessage());
            attemptNumber = 0;
        }
    }

    result.put("status", "ok");
    result.set("data", Json.toJson(ScriptFinderDAO.getScriptLineage(applicationID, jobID)));
    return ok(result);
}

From source file:me.tfeng.play.avro.AvroHelper.java

private static JsonNode convertToSimpleRecord(Schema schema, JsonNode json, JsonNodeFactory factory)
        throws IOException {
    if (json.isObject() && schema.getType() == Type.RECORD) {
        ObjectNode node = (ObjectNode) json;
        ObjectNode newNode = factory.objectNode();
        for (Field field : schema.getFields()) {
            String fieldName = field.name();
            if (node.has(fieldName)) {
                JsonNode value = convertToSimpleRecord(field.schema(), node.get(fieldName), factory);
                if (!value.isNull()) {
                    newNode.put(fieldName, value);
                }// w  w  w .ja  v  a  2  s.c o m
            }
        }
        return newNode;
    } else if (json.isObject() && schema.getType() == Type.MAP) {
        ObjectNode node = (ObjectNode) json;
        ObjectNode newNode = factory.objectNode();
        Schema valueType = schema.getValueType();
        Iterator<Entry<String, JsonNode>> entries = node.fields();
        while (entries.hasNext()) {
            Entry<String, JsonNode> entry = entries.next();
            JsonNode value = convertToSimpleRecord(valueType, entry.getValue(), factory);
            if (value.isNull()) {
                newNode.put(entry.getKey(), value);
            }
        }
        return newNode;
    } else if (schema.getType() == Type.UNION) {
        Schema type = AvroHelper.getSimpleUnionType(schema);
        if (type == null) {
            if (json.isNull()) {
                return json;
            } else {
                ObjectNode node = (ObjectNode) json;
                Entry<String, JsonNode> entry = node.fields().next();
                for (Schema unionType : schema.getTypes()) {
                    if (unionType.getFullName().equals(entry.getKey())) {
                        ObjectNode newNode = factory.objectNode();
                        newNode.put(entry.getKey(),
                                convertToSimpleRecord(unionType, entry.getValue(), factory));
                        return newNode;
                    }
                }
                throw new IOException("Unable to get schema for type " + entry.getKey() + " in union");
            }
        } else if (json.isNull()) {
            return json;
        } else {
            return convertToSimpleRecord(type, json.get(type.getFullName()), factory);
        }
    } else if (json.isArray() && schema.getType() == Type.ARRAY) {
        ArrayNode node = (ArrayNode) json;
        ArrayNode newNode = factory.arrayNode();
        Iterator<JsonNode> iterator = node.elements();
        while (iterator.hasNext()) {
            newNode.add(convertToSimpleRecord(schema.getElementType(), iterator.next(), factory));
        }
        return newNode;
    } else {
        return json;
    }
}

From source file:dao.DashboardDAO.java

public static ObjectNode getPagedConfidentialDatasetsByManagerId(String managerId, String platform, int page,
        int size) {

    DataSourceTransactionManager tm = new DataSourceTransactionManager(getJdbcTemplate().getDataSource());
    TransactionTemplate txTemplate = new TransactionTemplate(tm);

    return txTemplate.execute(new TransactionCallback<ObjectNode>() {

        public ObjectNode doInTransaction(TransactionStatus status) {
            List<Map<String, Object>> rows = new ArrayList<>(size);
            long count = getPagedDashboardDatasets(managerId, GET_CONFIDENTIAL_DATASETS_FILTER_PLATFORM,
                    platform, null, page, size, rows);

            List<DashboardDataset> datasets = new ArrayList<>();
            for (Map row : rows) {
                DashboardDataset dashboardDataset = new DashboardDataset();
                dashboardDataset.datasetId = (Long) row.get("dataset_id");
                dashboardDataset.datasetName = (String) row.get("name");
                dashboardDataset.ownerId = (String) row.get("owner_id");
                if (dashboardDataset.datasetId != null && dashboardDataset.datasetId > 0) {
                    dashboardDataset.fields = getJdbcTemplate().queryForList(
                            GET_CONFIDENTIAL_FIELDS_BY_DATASET_ID, String.class, dashboardDataset.datasetId);
                }//  w w w.  j a v  a 2s.  c  om
                datasets.add(dashboardDataset);
            }

            ObjectNode resultNode = Json.newObject();
            resultNode.put("status", "ok");
            resultNode.put("count", count);
            resultNode.put("page", page);
            resultNode.put("itemsPerPage", size);
            resultNode.put("totalPages", (int) Math.ceil(count / ((double) size)));
            resultNode.set("datasets", Json.toJson(datasets));
            return resultNode;
        }
    });
}

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

private static ObjectNode buildChoicesNode(final ObjectMapper objectMapper, final Type heapValueType,
        final SchemaLoader schemaLoader) {

    if (heapValueType == null || !(heapValueType instanceof Class<?>)) {
        return null;
    }//ww  w .  j  a  va  2s .co m

    final Class<?> choicesEnumClass = (Class<?>) heapValueType;

    if (!choicesEnumClass.isEnum()) {
        return null;
    }

    final URI choicesUri = schemaLoader.getTypeUri(choicesEnumClass);
    final String choicesName = choicesEnumClass.getSimpleName();
    final ObjectNode choicesNode = objectMapper.createObjectNode();

    choicesNode.put(PropertyName.title.name(), choicesName);
    choicesNode.put(PropertyName.uri.name(), choicesUri.toString());

    // TODO: Only embed the choices once per schema to lighten the download?
    final Object[] enumConstants = choicesEnumClass.getEnumConstants();
    if (enumConstants != null && enumConstants.length > 0) {
        final ArrayNode valuesNode = objectMapper.createArrayNode();

        choicesNode.put(PropertyName.values.name(), valuesNode);

        for (final Object enumConstant : enumConstants) {
            final String choice = String.valueOf(enumConstant);
            valuesNode.add(choice);
        }
    }

    return choicesNode;
}

From source file:dao.DashboardDAO.java

public static ObjectNode getPagedComplianceDatasetsByManagerId(String managerId, String platform, String option,
        int page, int size) {

    DataSourceTransactionManager tm = new DataSourceTransactionManager(getJdbcTemplate().getDataSource());
    TransactionTemplate txTemplate = new TransactionTemplate(tm);

    return txTemplate.execute(new TransactionCallback<ObjectNode>() {

        public ObjectNode doInTransaction(TransactionStatus status) {
            long count;
            List<Map<String, Object>> rows = new ArrayList<>(size);
            if (StringUtils.isNotBlank(option) && !(option.equalsIgnoreCase(ALL_DATASETS))) {
                count = getPagedDashboardDatasets(managerId, GET_DATASETS_WITH_COMPLIANCE_FILTER_PLATFORM,
                        platform, option, page, size, rows);
            } else {
                count = getPagedDashboardDatasets(managerId, GET_ALL_DATASETS_BY_ID_FILTER_PLATFORM, platform,
                        null, page, size, rows);
            }//from ww  w.  j  a v a 2  s .  c om

            List<DashboardDataset> datasets = new ArrayList<>();
            for (Map row : rows) {
                DashboardDataset dashboardDataset = new DashboardDataset();
                dashboardDataset.datasetId = (Long) row.get("dataset_id");
                dashboardDataset.datasetName = (String) row.get("name");
                dashboardDataset.ownerId = (String) row.get("owner_id");
                if (dashboardDataset.datasetId != null && dashboardDataset.datasetId > 0) {
                    dashboardDataset.fields = getJdbcTemplate().queryForList(
                            GET_COMPLIANCE_FIELDS_BY_DATASET_ID, String.class, dashboardDataset.datasetId);
                }
                datasets.add(dashboardDataset);
            }

            ObjectNode resultNode = Json.newObject();
            resultNode.put("status", "ok");
            resultNode.put("count", count);
            resultNode.put("page", page);
            resultNode.put("itemsPerPage", size);
            resultNode.put("totalPages", (int) Math.ceil(count / ((double) size)));
            resultNode.set("datasets", Json.toJson(datasets));
            return resultNode;
        }
    });
}

From source file:dao.DashboardDAO.java

public static ObjectNode getPagedOwnershipDatasetsByManagerId(String managerId, String platform, int option,
        int page, int size) {

    final DataSourceTransactionManager tm = new DataSourceTransactionManager(getJdbcTemplate().getDataSource());
    final TransactionTemplate txTemplate = new TransactionTemplate(tm);

    return txTemplate.execute(new TransactionCallback<ObjectNode>() {

        public ObjectNode doInTransaction(TransactionStatus status) {
            final String datasetQuery;
            switch (option) {
            case 1:
                datasetQuery = GET_OWNERSHIP_CONFIRMED_DATASETS_FILTER_PLATFORM;
                break;
            case 2:
                datasetQuery = GET_OWNERSHIP_UNCONFIRMED_DATASETS_FILTER_PLATFORM;
                break;
            case 3:
                datasetQuery = GET_OWNERSHIP_DATASETS_FILTER_PLATFORM;
                break;
            default:
                datasetQuery = GET_OWNERSHIP_DATASETS_FILTER_PLATFORM;
            }//from w ww . ja v a  2 s  .  co m

            List<Map<String, Object>> rows = new ArrayList<>(size);
            long count = getPagedDashboardDatasets(managerId, datasetQuery, platform, null, page, size, rows);

            List<DashboardDataset> datasets = new ArrayList<>();
            for (Map row : rows) {
                DashboardDataset dashboardDataset = new DashboardDataset();
                dashboardDataset.datasetId = (Long) row.get("dataset_id");
                dashboardDataset.datasetName = (String) row.get("name");
                dashboardDataset.ownerId = (String) row.get("owner_id");
                String confirmedOwnerId = (String) row.get("confirmed_owner_id");
                if (StringUtils.isBlank(confirmedOwnerId) && option == 1) {
                    confirmedOwnerId = "<other team>";
                }
                dashboardDataset.confirmedOwnerId = confirmedOwnerId;
                datasets.add(dashboardDataset);
            }

            ObjectNode resultNode = Json.newObject();
            resultNode.put("status", "ok");
            resultNode.put("count", count);
            resultNode.put("page", page);
            resultNode.put("itemsPerPage", size);
            resultNode.put("totalPages", (int) Math.ceil(count / ((double) size)));
            resultNode.set("datasets", Json.toJson(datasets));
            return resultNode;
        }
    });
}

From source file:com.ikanow.aleph2.example.flume_harvester.services.FlumeHarvesterSink.java

protected static ObjectNode addField(final ObjectNode mutable_obj, final String field_name, final String value,
        Map<String, String> type_map) {
    return Patterns.match((String) type_map.get(field_name)).<ObjectNode>andReturn()
            .when(t -> null == t, __ -> mutable_obj.put(field_name, value)) //(string)
            .when(t -> t.equalsIgnoreCase("long"), __ -> mutable_obj.put(field_name, Long.parseLong(value)))
            .when(t -> t.equalsIgnoreCase("int") || t.equalsIgnoreCase("integer"),
                    __ -> mutable_obj.put(field_name, Integer.parseInt(value)))
            .when(t -> t.equalsIgnoreCase("double") || t.equalsIgnoreCase("numeric"),
                    __ -> mutable_obj.put(field_name, Double.parseDouble(value)))
            .when(t -> t.equalsIgnoreCase("float"), __ -> mutable_obj.put(field_name, Float.parseFloat(value)))
            .when(t -> t.equalsIgnoreCase("boolean"),
                    __ -> mutable_obj.put(field_name, Boolean.parseBoolean(value)))
            .when(t -> t.equalsIgnoreCase("hex"), __ -> mutable_obj.put(field_name, Long.parseLong(value, 16)))
            .when(t -> t.equalsIgnoreCase("date"), __ -> {
                Validation<String, Date> res = TimeUtils.getSchedule(value, Optional.empty());
                return res.validation(left -> mutable_obj,
                        right -> mutable_obj.put(field_name, right.toString()));
            }).otherwise(__ -> mutable_obj.put(field_name, value)) // (string)
    ;//from  w  w w .ja  va 2 s  .c  o m
}

From source file:dao.DashboardDAO.java

public static ObjectNode getPagedDescriptionDatasetsByManagerId(String managerId, String platform, int option,
        int page, int size) {

    DataSourceTransactionManager tm = new DataSourceTransactionManager(getJdbcTemplate().getDataSource());
    TransactionTemplate txTemplate = new TransactionTemplate(tm);

    return txTemplate.execute(new TransactionCallback<ObjectNode>() {

        public ObjectNode doInTransaction(TransactionStatus status) {
            Boolean isDatasetLevel = true;
            String description;/* w w w . jav  a  2  s  .c  om*/

            final String datasetQuery;
            switch (option) {
            case 1:
                datasetQuery = GET_DATASETS_WITH_DESCRIPTION_FILTER_PLATFORM;
                description = "has dataset level description";
                break;
            case 2:
                datasetQuery = GET_DATASETS_WITHOUT_DESCRIPTION_FILTER_PLATFORM;
                description = "no dataset level description";
                break;
            case 3:
                datasetQuery = GET_DATASETS_WITH_FULL_FIELD_DESCRIPTION_FILTER_PLATFORM;
                description = "all fields have description";
                isDatasetLevel = false;
                break;
            case 4:
                datasetQuery = GET_DATASETS_WITH_ANY_FIELD_DESCRIPTION_FILTER_PLATFORM;
                description = "has field description";
                isDatasetLevel = false;
                break;
            case 5:
                datasetQuery = GET_DATASETS_WITH_NO_FIELD_DESCRIPTION_FILTER_PLATFORM;
                description = "no field description";
                isDatasetLevel = false;
                break;
            case 6:
                datasetQuery = GET_ALL_DATASETS_BY_ID_FILTER_PLATFORM;
                description = "";
                break;
            default:
                datasetQuery = GET_ALL_DATASETS_BY_ID_FILTER_PLATFORM;
                description = "";
            }

            List<Map<String, Object>> rows = new ArrayList<>(size);
            long count = getPagedDashboardDatasets(managerId, datasetQuery, platform, null, page, size, rows);

            List<DashboardDataset> datasets = new ArrayList<>();
            for (Map row : rows) {
                DashboardDataset dashboardDataset = new DashboardDataset();
                dashboardDataset.datasetId = (Long) row.get("dataset_id");
                dashboardDataset.datasetName = (String) row.get("name");
                dashboardDataset.ownerId = (String) row.get("owner_id");
                if (dashboardDataset.datasetId != null && dashboardDataset.datasetId > 0) {
                    if (isDatasetLevel) {
                        dashboardDataset.fields = getJdbcTemplate().queryForList(GET_DATASET_LEVEL_COMMENTS,
                                String.class, dashboardDataset.datasetId);
                    } else {
                        dashboardDataset.fields = getJdbcTemplate().queryForList(GET_FIELDS_WITH_DESCRIPTION,
                                String.class, dashboardDataset.datasetId);
                    }
                }
                datasets.add(dashboardDataset);
            }

            ObjectNode resultNode = Json.newObject();
            resultNode.put("status", "ok");
            resultNode.put("count", count);
            resultNode.put("page", page);
            resultNode.put("description", description);
            resultNode.put("itemsPerPage", size);
            resultNode.put("isDatasetLevel", isDatasetLevel);
            resultNode.put("totalPages", (int) Math.ceil(count / ((double) size)));
            resultNode.set("datasets", Json.toJson(datasets));
            return resultNode;
        }
    });
}

From source file:com.ning.metrics.serialization.event.SmileEnvelopeEvent.java

private static void addToTree(ObjectNode root, String name, Object value) {
    /* could wrap everything as POJONode, but that's bit inefficient;
     * so let's handle some known cases.
     * (in reality, I doubt there could ever be non-scalars, FWIW, since
     * downstream systems expect simple key/value data)
     *///from   w  ww. j  a  va 2s.  c  o m
    if (value instanceof String) {
        root.put(name, (String) value);
        return;
    }
    if (value instanceof Number) {
        Number num = (Number) value;
        if (value instanceof Integer) {
            root.put(name, num.intValue());
        } else if (value instanceof Long) {
            root.put(name, num.longValue());
        } else if (value instanceof Double) {
            root.put(name, num.doubleValue());
        } else {
            root.putPOJO(name, num);
        }
    } else if (value == Boolean.TRUE) {
        root.put(name, true);
    } else if (value == Boolean.FALSE) {
        root.put(name, false);
    } else { // most likely Date
        root.putPOJO(name, value);
    }
}