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:mobile.service.RNSService.java

/**
 * // ww w. j  a v a  2s  .  co m
 *
 * @param requireId  Id
 * @param title      ?
 * @param industryId Id?
 * @param info       ??
 * @param budget     ?
 * @param skillsTags ?
 * @return
 */
public static ServiceResult updateRequire(Long requireId, String title, Long industryId, String info,
        String budget, List<String> skillsTags, List<Long> attachs) {
    if (null == requireId) {
        throw new IllegalArgumentException("requireId can not be null");
    }

    ObjectNode data = Json.newObject();
    data.put("id", requireId);

    if (null != title) {
        if (StringUtils.isBlank(title)) {
            return ServiceResult.error("100005", "?");
        } else {
            data.put("title", title);
        }
    }
    if (null != industryId) {
        SkillTag tag = SkillTag.getTagById(industryId);
        if (null == tag || tag.getTagType() != SkillTag.TagType.CATEGORY) {
            return ServiceResult.error("100005", "Id" + industryId);
        } else {
            data.put("industry", industryId);
        }
    }
    if (null != info) {
        data.put("info", info);
    }
    if (null != budget) {
        if (!Pattern.matches("^\\d{0,8}(\\.\\d)?$", budget) && !"-1".equals(budget)) {
            return ServiceResult.error("100005", "??8?1??");
        } else {
            data.put("budget", budget);
        }
    }
    if (null != skillsTags) {
        data.set("tags", Json.toJson(skillsTags));
    }
    if (null != attachs) {
        if (attachs.size() > 5) {
            return ServiceResult.error("1006", "??");
        }
        ArrayNode attachsNode = Json.newObject().arrayNode();
        for (Long attachId : attachs) {
            ObjectNode attachNode = Json.newObject();
            attachNode.put("attachId", attachId);
            attachsNode.add(attachNode);
        }
        data.set("attachs", attachsNode);
    }

    ServiceResult updateResult = createOrUpdateRequire(data, null);
    if (!updateResult.isSuccess()) {
        return updateResult;
    }

    return ServiceResult.success();
}

From source file:mobile.service.RNSService.java

/**
 * //  w w  w .  j ava 2 s.  c om
 *
 * @param serviceId  Id
 * @param title      
 * @param industryId Id
 * @param info       ??
 * @param budget     
 * @param skillsTags 
 * @return
 */
public static ServiceResult updateService(Long serviceId, String title, Long industryId, String info,
        String price, List<String> skillsTags, List<Long> attachs) {
    if (null == serviceId) {
        throw new IllegalArgumentException("serviceId can not be null");
    }

    ObjectNode data = Json.newObject();
    data.put("id", serviceId);

    if (null != title) {
        if (StringUtils.isBlank(title)) {
            return ServiceResult.error("100005", "?");
        } else {
            data.put("title", title);
        }
    }
    if (null != industryId) {
        SkillTag tag = SkillTag.getTagById(industryId);
        if (null == tag || tag.getTagType() != SkillTag.TagType.CATEGORY) {
            return ServiceResult.error("100005", "Id" + industryId);
        } else {
            data.put("industry", industryId);
        }
    }
    if (null != info) {
        data.put("info", info);
    }
    if (null != price) {
        if (!Pattern.matches("^\\d{0,8}(\\.\\d)?$", price) && !"-1".equals(price)) {
            return ServiceResult.error("100005", "??8?1??");
        } else {
            data.put("price", price);
        }
    }
    if (null != skillsTags) {
        data.set("tags", Json.toJson(skillsTags));
    }
    if (null != attachs) {
        if (attachs.size() > 5) {
            return ServiceResult.error("1005", "???");
        }
        ArrayNode attachsNode = Json.newObject().arrayNode();
        for (Long attachId : attachs) {
            ObjectNode attachNode = Json.newObject();
            attachNode.put("attachId", attachId);
            attachsNode.add(attachNode);
        }
        data.set("attachs", attachsNode);
    }

    ServiceResult updateResult = createOrUpdateService(data, null);
    if (!updateResult.isSuccess()) {
        return updateResult;
    }

    return ServiceResult.success();
}

From source file:dao.SearchDAO.java

public static ObjectNode getPagedCommentsByKeyword(String category, String keyword, int page, int size) {
    List<Dataset> pagedDatasets = new ArrayList<Dataset>();
    final JdbcTemplate jdbcTemplate = getJdbcTemplate();
    javax.sql.DataSource ds = jdbcTemplate.getDataSource();
    DataSourceTransactionManager tm = new DataSourceTransactionManager(ds);

    TransactionTemplate txTemplate = new TransactionTemplate(tm);

    ObjectNode result;/*from  w ww  .ja  v  a  2  s  .  co m*/
    result = txTemplate.execute(new TransactionCallback<ObjectNode>() {
        public ObjectNode doInTransaction(TransactionStatus status) {
            List<Map<String, Object>> rows = null;
            String query = SEARCH_DATASET_BY_COMMENTS_WITH_PAGINATION.replace("$keyword", keyword);
            rows = jdbcTemplate.queryForList(query, (page - 1) * size, size);

            for (Map row : rows) {

                Dataset ds = new Dataset();
                ds.id = (long) row.get(DatasetRowMapper.DATASET_ID_COLUMN);
                ds.name = (String) row.get(DatasetRowMapper.DATASET_NAME_COLUMN);
                ds.source = (String) row.get(DatasetRowMapper.DATASET_SOURCE_COLUMN);
                ds.urn = (String) row.get(DatasetRowMapper.DATASET_URN_COLUMN);
                ds.schema = (String) row.get(DatasetRowMapper.DATASET_SCHEMA_COLUMN);
                pagedDatasets.add(ds);
            }
            long count = 0;
            try {
                count = jdbcTemplate.queryForObject("SELECT FOUND_ROWS()", Long.class);
            } catch (EmptyResultDataAccessException e) {
                Logger.error("Exception = " + e.getMessage());
            }

            ObjectNode resultNode = Json.newObject();
            resultNode.put("count", count);
            resultNode.put("page", page);
            resultNode.put("category", category);
            resultNode.put("itemsPerPage", size);
            resultNode.put("totalPages", (int) Math.ceil(count / ((double) size)));
            resultNode.set("data", Json.toJson(pagedDatasets));

            return resultNode;
        }
    });

    return result;
}

From source file:dao.FlowsDAO.java

public static ObjectNode getPagedJobsByFlow(String applicationName, Long flowId, int page, int size) {
    ObjectNode result;
    List<Job> pagedJobs = new ArrayList<Job>();

    if (StringUtils.isBlank(applicationName) || (flowId <= 0)) {
        result = Json.newObject();/*from w  w w .  ja  v a  2 s.c o  m*/
        result.put("count", 0);
        result.put("page", page);
        result.put("itemsPerPage", size);
        result.put("totalPages", 0);
        result.set("jobs", Json.toJson(""));
        return result;
    }

    String application = applicationName.replace(".", " ");

    Integer appID = getApplicationIDByName(application);
    if (appID != 0) {
        javax.sql.DataSource ds = getJdbcTemplate().getDataSource();
        DataSourceTransactionManager tm = new DataSourceTransactionManager(ds);
        TransactionTemplate txTemplate = new TransactionTemplate(tm);
        final long azkabanFlowId = flowId;
        result = txTemplate.execute(new TransactionCallback<ObjectNode>() {
            public ObjectNode doInTransaction(TransactionStatus status) {
                List<Map<String, Object>> rows = null;
                rows = getJdbcTemplate().queryForList(GET_PAGED_JOBS_BY_APP_ID_AND_FLOW_ID, appID,
                        azkabanFlowId, (page - 1) * size, size);
                long count = 0;
                String flowName = "";
                try {
                    count = getJdbcTemplate().queryForObject("SELECT FOUND_ROWS()", Long.class);
                } catch (EmptyResultDataAccessException e) {
                    Logger.error("Exception = " + e.getMessage());
                }
                for (Map row : rows) {
                    Job job = new Job();
                    job.id = (Long) row.get("job_id");
                    job.name = (String) row.get("job_name");
                    job.path = (String) row.get("job_path");
                    job.path = (String) row.get("job_path");
                    job.refFlowGroup = (String) row.get("flow_group");
                    if (StringUtils.isNotBlank(job.path)) {
                        int index = job.path.indexOf("/");
                        if (index != -1) {
                            job.path = job.path.substring(0, index);
                        }
                    }
                    job.type = (String) row.get("job_type");
                    Object created = row.get("created_time");
                    job.refFlowId = (Long) row.get("ref_flow_id");
                    if (created != null) {
                        job.created = DateFormat.format(created.toString());
                    }
                    Object modified = row.get("modified_time");
                    if (modified != null) {
                        job.modified = DateFormat.format(modified.toString());
                    }

                    if (StringUtils.isBlank(flowName)) {
                        flowName = (String) row.get("flow_name");
                    }
                    pagedJobs.add(job);
                }
                ObjectNode resultNode = Json.newObject();
                resultNode.put("count", count);
                resultNode.put("flow", flowName);
                resultNode.put("page", page);
                resultNode.put("itemsPerPage", size);
                resultNode.put("totalPages", (int) Math.ceil(count / ((double) size)));
                resultNode.set("jobs", Json.toJson(pagedJobs));
                return resultNode;
            }
        });
        return result;
    }

    result = Json.newObject();
    result.put("count", 0);
    result.put("page", page);
    result.put("itemsPerPage", size);
    result.put("totalPages", 0);
    result.set("jobs", Json.toJson(""));
    return result;
}

From source file:dao.SearchDAO.java

public static ObjectNode getPagedFlowByKeyword(String category, String keyword, int page, int size) {
    final List<FlowJob> pagedFlows = new ArrayList<FlowJob>();
    final JdbcTemplate jdbcTemplate = getJdbcTemplate();
    javax.sql.DataSource ds = jdbcTemplate.getDataSource();
    DataSourceTransactionManager tm = new DataSourceTransactionManager(ds);

    TransactionTemplate txTemplate = new TransactionTemplate(tm);

    ObjectNode result;/*from  w  w w .j  ava 2  s .  co  m*/
    result = txTemplate.execute(new TransactionCallback<ObjectNode>() {
        public ObjectNode doInTransaction(TransactionStatus status) {
            String query = SEARCH_FLOW_WITH_PAGINATION.replace("$keyword", keyword);
            List<Map<String, Object>> rows = null;

            rows = jdbcTemplate.queryForList(query, (page - 1) * size, size);
            for (Map row : rows) {

                FlowJob flow = new FlowJob();
                flow.flowId = (Long) row.get(FlowRowMapper.FLOW_ID_COLUMN);
                flow.flowName = (String) row.get(FlowRowMapper.FLOW_NAME_COLUMN);
                flow.flowPath = (String) row.get(FlowRowMapper.FLOW_PATH_COLUMN);
                flow.flowGroup = (String) row.get(FlowRowMapper.FLOW_GROUP_COLUMN);
                flow.appCode = (String) row.get(FlowRowMapper.APP_CODE_COLUMN);
                flow.appId = (Integer) row.get(FlowRowMapper.APP_ID_COLUMN);
                flow.displayName = flow.flowName;
                flow.link = "#/flows/name/" + flow.appCode + "/" + Long.toString(flow.flowId) + "/page/1?urn="
                        + flow.flowGroup;
                flow.path = flow.appCode + "/" + flow.flowPath;
                pagedFlows.add(flow);
            }
            long count = 0;
            try {
                count = jdbcTemplate.queryForObject("SELECT FOUND_ROWS()", Long.class);
            } catch (EmptyResultDataAccessException e) {
                Logger.error("Exception = " + e.getMessage());
            }

            ObjectNode resultNode = Json.newObject();
            resultNode.put("count", count);
            resultNode.put("isFlowJob", true);
            resultNode.put("page", page);
            resultNode.put("category", category);
            resultNode.put("itemsPerPage", size);
            resultNode.put("totalPages", (int) Math.ceil(count / ((double) size)));
            resultNode.set("data", Json.toJson(pagedFlows));

            return resultNode;
        }
    });

    return result;
}

From source file:dao.SearchDAO.java

public static ObjectNode getPagedDatasetByKeyword(String category, String keyword, String source, int page,
        int size) {
    List<Dataset> pagedDatasets = new ArrayList<Dataset>();
    final JdbcTemplate jdbcTemplate = getJdbcTemplate();
    javax.sql.DataSource ds = jdbcTemplate.getDataSource();
    DataSourceTransactionManager tm = new DataSourceTransactionManager(ds);

    TransactionTemplate txTemplate = new TransactionTemplate(tm);

    ObjectNode result;/*from   www  . j  a v a2s . c o m*/
    result = txTemplate.execute(new TransactionCallback<ObjectNode>() {
        public ObjectNode doInTransaction(TransactionStatus status) {
            List<Map<String, Object>> rows = null;
            if (StringUtils.isBlank(source) || source.toLowerCase().equalsIgnoreCase("all")) {
                String query = SEARCH_DATASET_WITH_PAGINATION.replace("$keyword", keyword);
                rows = jdbcTemplate.queryForList(query, (page - 1) * size, size);
            } else {
                String query = SEARCH_DATASET_BY_SOURCE_WITH_PAGINATION.replace("$keyword", keyword);
                rows = jdbcTemplate.queryForList(query, source, (page - 1) * size, size);
            }

            for (Map row : rows) {

                Dataset ds = new Dataset();
                ds.id = (Long) row.get(DatasetRowMapper.DATASET_ID_COLUMN);
                ds.name = (String) row.get(DatasetRowMapper.DATASET_NAME_COLUMN);
                ds.source = (String) row.get(DatasetRowMapper.DATASET_SOURCE_COLUMN);
                ds.urn = (String) row.get(DatasetRowMapper.DATASET_URN_COLUMN);
                ds.schema = (String) row.get(DatasetRowMapper.DATASET_SCHEMA_COLUMN);
                pagedDatasets.add(ds);
            }
            long count = 0;
            try {
                count = jdbcTemplate.queryForObject("SELECT FOUND_ROWS()", Long.class);
            } catch (EmptyResultDataAccessException e) {
                Logger.error("Exception = " + e.getMessage());
            }

            ObjectNode resultNode = Json.newObject();
            resultNode.put("count", count);
            resultNode.put("page", page);
            resultNode.put("category", category);
            resultNode.put("source", source);
            resultNode.put("itemsPerPage", size);
            resultNode.put("totalPages", (int) Math.ceil(count / ((double) size)));
            resultNode.set("data", Json.toJson(pagedDatasets));

            return resultNode;
        }
    });

    return result;
}

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

public static Result getDatasetVersions(Long datasetId, Integer dbId) {
    ObjectNode result = Json.newObject();
    result.put("status", "ok");
    result.set("versions", Json.toJson(DatasetsDAO.getDatasetVersions(datasetId, dbId)));
    return ok(result);
}

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

public static Result getDatasetSchemaTextByVersion(Long datasetId, String version) {
    ObjectNode result = Json.newObject();
    result.put("status", "ok");
    result.set("schema_text", Json.toJson(DatasetsDAO.getDatasetSchemaTextByVersion(datasetId, version)));
    return ok(result);
}

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

public static Result getDatasetInstances(Long datasetId) {
    ObjectNode result = Json.newObject();
    result.put("status", "ok");
    result.set("instances", Json.toJson(DatasetsDAO.getDatasetInstances(datasetId)));
    return ok(result);
}

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

public static Result getDatasetPartitions(Long datasetId) {
    ObjectNode result = Json.newObject();
    result.put("status", "ok");
    result.set("partitions", Json.toJson(DatasetsDAO.getDatasetPartitionGains(datasetId)));
    return ok(result);
}