List of usage examples for com.fasterxml.jackson.databind.node ObjectNode put
public ObjectNode put(String paramString1, String paramString2)
From source file:controllers.api.v1.Dataset.java
public static Result getDatasetAccess(Long datasetId) { ObjectNode result = Json.newObject(); result.put("status", "ok"); result.set("access", Json.toJson(DatasetsDAO.getDatasetAccessibilty(datasetId))); return ok(result); }
From source file:controllers.api.v1.Dataset.java
public static Result getDatasetOwnerTypes() { ObjectNode result = Json.newObject(); result.put("status", "ok"); result.set("ownerTypes", Json.toJson(DatasetsDAO.getDatasetOwnerTypes())); return ok(result); }
From source file:mobile.service.RNSService.java
/** * ?/* www. ja v a 2 s .c o m*/ * * @param serviceId ?Id??Idnull??? * @param file ??5 * @param pos ?1 - 5 * @return */ public static ServiceVOResult<CommonVO> uploadServicePic(Long serviceId, File file) { Service service = null; if (null != serviceId) { service = Service.queryServiceById(serviceId); if (null == service) { return ServiceVOResult.error("1008", "??"); } if (!service.getOwner().getId().equals(MobileUtil.getCurrentUser().getId())) { return ServiceVOResult.error("1004", "???"); } if (service.getCaseAttachs().size() >= 5) { return ServiceVOResult.error("1005", "???"); } } ServiceVOResult<CommonVO> uploadResult = FileService.uploadAttatch(file, "mobile.jpg", FileService.AttatchType.SERVICE); if (!uploadResult.isSuccess()) { return ServiceVOResult.error(uploadResult.getErrorCode(), uploadResult.getErrorContent()); } if (null != service) { synchronized (uploadServicePicLock) { JPA.em().refresh(service); Set<AttachOfService> caseAttachs = service.getCaseAttachs(); if (caseAttachs.size() >= 5) { return ServiceVOResult.error("1005", "???"); } // ?Json ArrayNode attachArray = Json.newObject().arrayNode(); for (AttachOfService attachOfService : caseAttachs) { ObjectNode attachNode = Json.newObject(); attachNode.put("attachId", attachOfService.id); attachArray.add(attachNode); } ObjectNode attachNode = Json.newObject(); attachNode.put("attachId", uploadResult.getVo().getLong("attachId")); attachArray.add(attachNode); ObjectNode data = Json.newObject(); data.put("id", serviceId); data.set("attachs", attachArray); ServiceResult updateResult = createOrUpdateService(data, null); if (!updateResult.isSuccess()) { return ServiceVOResult.create(updateResult); } } } CommonVO vo = CommonVO.create(); vo.set("url", uploadResult.getVo().getString("url")); vo.set("attachId", uploadResult.getVo().getLong("attachId")); return ServiceVOResult.success(vo); }
From source file:controllers.api.v1.Dataset.java
public static Result getDatasetOwnersByID(int id) { ObjectNode result = Json.newObject(); result.put("status", "ok"); result.set("owners", Json.toJson(DatasetsDAO.getDatasetOwnersByID(id))); return ok(result); }
From source file:dao.SearchDAO.java
public static ObjectNode getPagedJobByKeyword(String category, String keyword, int page, int size) { final List<FlowJob> pagedFlowJobs = 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 .ja v a 2s . co m result = txTemplate.execute(new TransactionCallback<ObjectNode>() { public ObjectNode doInTransaction(TransactionStatus status) { String query = SEARCH_JOB_WITH_PAGINATION.replace("$keyword", keyword); List<Map<String, Object>> rows = null; rows = jdbcTemplate.queryForList(query, (page - 1) * size, size); for (Map row : rows) { FlowJob flowJob = new FlowJob(); flowJob.flowId = (Long) row.get(FlowRowMapper.FLOW_ID_COLUMN); flowJob.jobId = (Long) row.get(FlowRowMapper.JOB_ID_COLUMN); flowJob.jobName = (String) row.get(FlowRowMapper.JOB_NAME_COLUMN); flowJob.jobPath = (String) row.get(FlowRowMapper.JOB_PATH_COLUMN); flowJob.jobType = (String) row.get(FlowRowMapper.JOB_TYPE_COLUMN); flowJob.flowName = (String) row.get(FlowRowMapper.FLOW_NAME_COLUMN); flowJob.flowPath = (String) row.get(FlowRowMapper.FLOW_PATH_COLUMN); flowJob.flowGroup = (String) row.get(FlowRowMapper.FLOW_GROUP_COLUMN); flowJob.appCode = (String) row.get(FlowRowMapper.APP_CODE_COLUMN); flowJob.appId = (Integer) row.get(FlowRowMapper.APP_ID_COLUMN); flowJob.displayName = flowJob.jobName; flowJob.link = "#/flows/name/" + flowJob.appCode + "/" + Long.toString(flowJob.flowId) + "/page/1?urn=" + flowJob.flowGroup; flowJob.path = flowJob.appCode + "/" + flowJob.jobPath; pagedFlowJobs.add(flowJob); } 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(pagedFlowJobs)); return resultNode; } }); return result; }
From source file:mobile.service.RNSService.java
/** * //from w w w . j av a 2s . c o m * * @param requireId Id * @param file * @param filename ?? * @return */ public static ServiceVOResult<CommonVO> updateRequireAttachment(Long requireId, File file, String filename) { if (StringUtils.isBlank(filename)) { throw new IllegalArgumentException("filename can not be blank."); } Require require = null; if (null != requireId) { require = Require.queryRequireById(requireId); if (null == require) { return ServiceVOResult.error("1007", "?"); } if (!require.getOwner().getId().equals(MobileUtil.getCurrentUser().getId())) { return ServiceVOResult.error("1003", "??"); } if (require.getCaseAttachs().size() >= 5) { return ServiceVOResult.error("1006", "??"); } } ServiceVOResult<CommonVO> uploadResult = FileService.uploadAttatch(file, filename, FileService.AttatchType.REQUIRE); if (!uploadResult.isSuccess()) { return ServiceVOResult.error(uploadResult.getErrorCode(), uploadResult.getErrorContent()); } if (null != require) { synchronized (updateRequireAttachmentLock) { JPA.em().refresh(require); Set<AttachOfRequire> caseAttachs = require.getCaseAttachs(); if (caseAttachs.size() >= 5) { return ServiceVOResult.error("1006", "??"); } // ?Json ArrayNode attachArray = Json.newObject().arrayNode(); for (AttachOfRequire attachOfRequire : caseAttachs) { ObjectNode attachNode = Json.newObject(); attachNode.put("attachId", attachOfRequire.id); attachArray.add(attachNode); } ObjectNode attachNode = Json.newObject(); attachNode.put("attachId", uploadResult.getVo().getLong("attachId")); attachArray.add(attachNode); ObjectNode data = Json.newObject(); data.put("id", requireId); data.set("attachs", attachArray); ServiceResult updateResult = createOrUpdateRequire(data, null); if (!updateResult.isSuccess()) { return ServiceVOResult.create(updateResult); } } } CommonVO vo = CommonVO.create(); vo.set("url", uploadResult.getVo().getString("url")); vo.set("attachId", uploadResult.getVo().getLong("attachId")); return ServiceVOResult.success(vo); }
From source file:utils.ReflectionService.java
public static JsonNode createJsonNode(Class clazz, int maxDeep) { if (maxDeep <= 0 || JsonNode.class.isAssignableFrom(clazz)) { return null; }// w ww. j ava2 s.c om ObjectMapper objectMapper = new ObjectMapper(); ObjectNode objectNode = objectMapper.createObjectNode(); for (Field field : clazz.getDeclaredFields()) { field.setAccessible(true); String key = field.getName(); try { // is array or collection if (field.getType().isArray() || Collection.class.isAssignableFrom(field.getType())) { ParameterizedType collectionType = (ParameterizedType) field.getGenericType(); Class<?> type = (Class<?>) collectionType.getActualTypeArguments()[0]; ArrayNode arrayNode = objectMapper.createArrayNode(); arrayNode.add(createJsonNode(type, maxDeep - 1)); objectNode.put(key, arrayNode); } else { Class<?> type = field.getType(); if (Modifier.isStatic(field.getModifiers())) { continue; } else if (type.isEnum()) { objectNode.put(key, Enum.class.getName()); } else if (!type.getName().startsWith("java") && !key.startsWith("_")) { objectNode.put(key, createJsonNode(type, maxDeep - 1)); } else { objectNode.put(key, type.getName()); } } } catch (Exception e) { e.printStackTrace(); } } return objectNode; }
From source file:dao.SearchDAO.java
public static ObjectNode getPagedMetricByKeyword(final String category, String keyword, int page, int size) { List<Metric> pagedMetrics = new ArrayList<Metric>(); 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. j av a 2 s.c om result = txTemplate.execute(new TransactionCallback<ObjectNode>() { public ObjectNode doInTransaction(TransactionStatus status) { String query = SEARCH_METRIC_WITH_PAGINATION.replace("$keyword", keyword); List<Map<String, Object>> rows = null; rows = jdbcTemplate.queryForList(query, (page - 1) * size, size); for (Map row : rows) { Metric metric = new Metric(); metric.id = (Integer) row.get(MetricRowMapper.METRIC_ID_COLUMN); metric.name = (String) row.get(MetricRowMapper.METRIC_NAME_COLUMN); metric.refID = (String) row.get(MetricRowMapper.METRIC_REF_ID_COLUMN); metric.refIDType = (String) row.get(MetricRowMapper.METRIC_REF_ID_TYPE_COLUMN); metric.description = (String) row.get(MetricRowMapper.METRIC_DESCRIPTION_COLUMN); metric.dashboardName = (String) row.get(MetricRowMapper.METRIC_DASHBOARD_NAME_COLUMN); metric.category = (String) row.get(MetricRowMapper.METRIC_CATEGORY_COLUMN); metric.group = (String) row.get(MetricRowMapper.METRIC_GROUP_COLUMN); metric.source = "metric"; metric.urn = ""; if (StringUtils.isNotBlank(metric.dashboardName)) { metric.urn += metric.dashboardName + "/"; } if (StringUtils.isNotBlank(metric.group)) { metric.urn += metric.group + "/"; } if (StringUtils.isNotBlank(metric.name)) { metric.urn += metric.name; } ObjectNode schema = Json.newObject(); schema.put(MetricRowMapper.METRIC_REF_ID_COLUMN, metric.refID); schema.put(MetricRowMapper.METRIC_REF_ID_TYPE_COLUMN, metric.refIDType); schema.put(MetricRowMapper.METRIC_DESCRIPTION_COLUMN, metric.description); schema.put(MetricRowMapper.METRIC_DASHBOARD_NAME_COLUMN, metric.dashboardName); schema.put(MetricRowMapper.METRIC_CATEGORY_COLUMN, metric.category); schema.put(MetricRowMapper.METRIC_GROUP_COLUMN, metric.group); metric.schema = schema.toString(); pagedMetrics.add(metric); } 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(pagedMetrics)); return resultNode; } }); return result; }
From source file:dao.SearchDAO.java
public static JsonNode elasticSearchMetricByKeyword(String category, String keywords, int page, int size) { ObjectNode queryNode = Json.newObject(); queryNode.put("from", (page - 1) * size); queryNode.put("size", size); JsonNode responseNode = null;/* w w w . j a v a 2 s.co m*/ ObjectNode keywordNode = null; try { keywordNode = utils.Search.generateElasticSearchQueryString(category, null, keywords); } catch (Exception e) { Logger.error("Elastic search metric input query is not JSON format. Error message :" + e.getMessage()); } if (keywordNode != null) { queryNode.set("query", keywordNode); Promise<WSResponse> responsePromise = WS .url(Play.application().configuration().getString(SearchDAO.ELASTICSEARCH_METRIC_URL_KEY)) .post(queryNode); responseNode = responsePromise.get(1000).asJson(); } ObjectNode resultNode = Json.newObject(); Long count = 0L; List<Metric> pagedMetrics = new ArrayList<>(); resultNode.put("page", page); resultNode.put("category", category); resultNode.put("isMetrics", true); resultNode.put("itemsPerPage", size); resultNode.put("keywords", keywords); if (responseNode != null && responseNode.isContainerNode() && responseNode.has("hits")) { JsonNode hitsNode = responseNode.get("hits"); if (hitsNode != null) { if (hitsNode.has("total")) { count = hitsNode.get("total").asLong(); } if (hitsNode.has("hits")) { JsonNode dataNode = hitsNode.get("hits"); if (dataNode != null && dataNode.isArray()) { Iterator<JsonNode> arrayIterator = dataNode.elements(); if (arrayIterator != null) { while (arrayIterator.hasNext()) { JsonNode node = arrayIterator.next(); if (node.isContainerNode() && node.has("_id")) { Metric metric = new Metric(); metric.id = node.get("_id").asInt(); if (node.has("_source")) { JsonNode sourceNode = node.get("_source"); if (sourceNode != null) { if (sourceNode.has("metric_name")) { metric.name = sourceNode.get("metric_name").asText(); } if (sourceNode.has("metric_description")) { metric.description = sourceNode.get("metric_description").asText(); } if (sourceNode.has("dashboard_name")) { metric.dashboardName = sourceNode.get("dashboard_name").asText(); } if (sourceNode.has("metric_group")) { metric.group = sourceNode.get("metric_group").asText(); } if (sourceNode.has("metric_category")) { metric.category = sourceNode.get("metric_category").asText(); } if (sourceNode.has("urn")) { metric.urn = sourceNode.get("urn").asText(); } if (sourceNode.has("metric_source")) { metric.source = sourceNode.get("metric_source").asText(); if (StringUtils.isBlank(metric.source)) { metric.source = null; } } metric.schema = sourceNode.toString(); } } pagedMetrics.add(metric); } } } } } } } resultNode.put("count", count); resultNode.put("totalPages", (int) Math.ceil(count / ((double) size))); resultNode.set("data", Json.toJson(pagedMetrics)); return resultNode; }
From source file:dao.SearchDAO.java
public static JsonNode elasticSearchFlowByKeyword(String category, String keywords, int page, int size) { ObjectNode queryNode = Json.newObject(); queryNode.put("from", (page - 1) * size); queryNode.put("size", size); JsonNode searchOpt = null;/*from w ww. j av a 2s. c om*/ JsonNode responseNode = null; ObjectNode keywordNode = null; try { keywordNode = utils.Search.generateElasticSearchQueryString(category, null, keywords); } catch (Exception e) { Logger.error("Elastic search flow input query is not JSON format. Error message :" + e.getMessage()); } if (keywordNode != null) { queryNode.set("query", keywordNode); Promise<WSResponse> responsePromise = WS .url(Play.application().configuration().getString(SearchDAO.ELASTICSEARCH_FLOW_URL_KEY)) .post(queryNode); responseNode = responsePromise.get(1000).asJson(); } ObjectNode resultNode = Json.newObject(); Long count = 0L; List<FlowJob> pagedFlowJobs = new ArrayList<>(); resultNode.put("page", page); resultNode.put("category", category); resultNode.put("isFlowJob", true); resultNode.put("itemsPerPage", size); resultNode.put("keywords", keywords); if (responseNode != null && responseNode.isContainerNode() && responseNode.has("hits")) { JsonNode hitsNode = responseNode.get("hits"); if (hitsNode != null) { if (hitsNode.has("total")) { count = hitsNode.get("total").asLong(); } if (hitsNode.has("hits")) { JsonNode dataNode = hitsNode.get("hits"); if (dataNode != null && dataNode.isArray()) { Iterator<JsonNode> arrayIterator = dataNode.elements(); if (arrayIterator != null) { while (arrayIterator.hasNext()) { JsonNode node = arrayIterator.next(); if (node.isContainerNode() && node.has("_id")) { FlowJob flowJob = new FlowJob(); if (node.has("_source")) { JsonNode sourceNode = node.get("_source"); if (sourceNode != null) { if (sourceNode.has("app_code")) { flowJob.appCode = sourceNode.get("app_code").asText(); } if (sourceNode.has("app_id")) { flowJob.appId = sourceNode.get("app_id").asInt(); } if (sourceNode.has("flow_id")) { flowJob.flowId = sourceNode.get("flow_id").asLong(); } if (sourceNode.has("flow_name")) { flowJob.flowName = sourceNode.get("flow_name").asText(); flowJob.displayName = flowJob.flowName; } if (sourceNode.has("flow_path")) { flowJob.flowPath = sourceNode.get("flow_path").asText(); } if (sourceNode.has("flow_group")) { flowJob.flowGroup = sourceNode.get("flow_group").asText(); } flowJob.link = "#/flows/name/" + flowJob.appCode + "/" + Long.toString(flowJob.flowId) + "/page/1?urn=" + flowJob.flowGroup; flowJob.path = flowJob.appCode + "/" + flowJob.flowPath; flowJob.schema = sourceNode.toString(); } } pagedFlowJobs.add(flowJob); } } } } } } } resultNode.put("count", count); resultNode.put("totalPages", (int) Math.ceil(count / ((double) size))); resultNode.set("data", Json.toJson(pagedFlowJobs)); return resultNode; }