List of usage examples for com.fasterxml.jackson.databind JsonNode get
public JsonNode get(String paramString)
From source file:com.flipkart.zjsonpatch.JsonDiff.java
private static void compareObjects(List<Diff> diffs, List<Object> path, JsonNode source, JsonNode target) { Iterator<String> keysFromSrc = source.fieldNames(); while (keysFromSrc.hasNext()) { String key = keysFromSrc.next(); if (!target.has(key)) { //remove case List<Object> currPath = getPath(path, key); diffs.add(Diff.generateDiff(Operation.REMOVE, currPath, source.get(key))); continue; }/* www . j a v a 2 s .co m*/ List<Object> currPath = getPath(path, key); generateDiffs(diffs, currPath, source.get(key), target.get(key)); } Iterator<String> keysFromTarget = target.fieldNames(); while (keysFromTarget.hasNext()) { String key = keysFromTarget.next(); if (!source.has(key)) { //add case List<Object> currPath = getPath(path, key); diffs.add(Diff.generateDiff(Operation.ADD, currPath, target.get(key))); } } }
From source file:com.ibm.watson.catalyst.corpus.CorpusBuilder.java
/** * Gets the documents node from the corpus JSON. * @param aJson//from w ww . ja v a 2s . c o m * @return */ private static JsonNode getDocumentsNode(File aJson) { JsonNode root; try { System.out.println("Reading tree."); root = MAPPER.readTree(aJson); System.out.println("Tree read."); } catch (FileNotFoundException e) { throw new IllegalStateException("Corpus not found: " + aJson, e); } catch (JsonProcessingException e) { e.printStackTrace(); throw new IllegalStateException(); } catch (IOException e) { throw new IllegalStateException(); } JsonNode documentsNode = root.get("documents"); return documentsNode; }
From source file:com.meetingninja.csse.database.UserDatabaseAdapter.java
public static List<Meeting> getMeetings(String userID) throws JsonParseException, JsonMappingException, IOException { // Server URL setup String _url = getBaseUri().appendPath("Meetings").appendPath(userID).build().toString(); // establish connection URL url = new URL(_url); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); // add request header conn.setRequestMethod("GET"); addRequestHeader(conn, false);/*from w w w.ja va 2s . co m*/ // Get server response int responseCode = conn.getResponseCode(); String response = getServerResponse(conn); // Initialize ObjectMapper List<Meeting> meetingsList = new ArrayList<Meeting>(); List<String> meetingIDList = new ArrayList<String>(); JsonNode responseNode = MAPPER.readTree(response); final JsonNode meetingsArray = responseNode.get(Keys.Meeting.LIST); if (meetingsArray != null && meetingsArray.isArray()) { for (final JsonNode meetingNode : meetingsArray) { String _id = meetingNode.get(Keys._ID).asText(); if (!meetingNode.get("type").asText().equals("MADE_MEETING")) { meetingIDList.add(_id); } } } else { logError(TAG, responseNode); } conn.disconnect(); for (String id : meetingIDList) { meetingsList.add(MeetingDatabaseAdapter.getMeetingInfo(id)); } return meetingsList; }
From source file:de.unikonstanz.winter.crossref.node.doi.CrossrefDoiNodeModel.java
/** * Creates a cell array containing all retrieved information for the given * DOI./*from w ww . j ava2 s. c o m*/ * * @param doiCell * Cell containing the DOI * @return Cells containing the retrieved information or missing cells if * the doiCell is invalid */ private static DataCell[] informationForDoi(final DataCell doiCell) { if (doiCell.isMissing() || !doiCell.getType().isCompatible(StringValue.class)) { return CrossrefUtil.createMissingCells(37, null); } String doi = ((StringValue) doiCell).getStringValue(); String url = CrossrefUtil.API_BASE_URL + "/works/" + doi; JsonNode root = null; try { root = CrossrefUtil.getJsonForUrl(url); } catch (IOException e) { LOGGER.error(e.getMessage(), e); return CrossrefUtil.createMissingCells(37, e.getMessage()); } DataCell[] cells = new DataCell[37]; JsonNode message = root.get("message"); cells[0] = CrossrefUtil.nodeToStringCell(message.get("publisher")); cells[1] = CrossrefUtil.nodeToStringListCell(message.get("title")); cells[2] = CrossrefUtil.nodeToIntCell(message.get("reference-count")); cells[3] = CrossrefUtil.nodeToStringCell(message.get("source")); cells[4] = CrossrefUtil.nodeToStringCell(message.get("prefix")); cells[5] = CrossrefUtil.nodeToStringCell(message.get("member")); cells[6] = CrossrefUtil.nodeToStringCell(message.get("type")); cells[7] = nodeToDateCell(message.get("created")); cells[8] = nodeToDateCell(message.get("deposited")); cells[9] = nodeToDateCell(message.get("indexed")); cells[10] = partialDateNodeToIntListCell(message.get("issued")); cells[11] = CrossrefUtil.nodeToStringListCell(message.get("subtitle")); cells[12] = CrossrefUtil.nodeToStringListCell(message.get("container-title")); cells[13] = CrossrefUtil.nodeToStringCell(message.get("issue")); cells[14] = CrossrefUtil.nodeToStringCell(message.get("volume")); cells[15] = CrossrefUtil.nodeToStringCell(message.get("page")); cells[16] = CrossrefUtil.nodeToStringCell(message.get("article-number")); cells[17] = partialDateNodeToIntListCell(message.get("published-print")); cells[18] = partialDateNodeToIntListCell(message.get("published-online")); cells[19] = CrossrefUtil.nodeToStringListCell(message.get("subject")); cells[20] = CrossrefUtil.nodeToStringListCell(message.get("ISSN")); cells[21] = CrossrefUtil.nodeToStringListCell(message.get("ISBN")); cells[22] = CrossrefUtil.nodeToStringListCell(message.get("archive")); cells[23] = toStringListCell(message, "license"); // TODO cells[24] = toStringListCell(message, "funder"); // TODO cells[25] = toStringListCell(message, "assertion"); // TODO cells[26] = toStringListCell(message, "author"); // TODO cells[27] = toStringListCell(message, "editor"); // TODO cells[28] = toStringListCell(message, "chair"); // TODO cells[29] = toStringListCell(message, "translator"); // TODO cells[30] = toStringListCell(message, "update-to"); // TODO cells[31] = CrossrefUtil.nodeToStringCell(message.get("update-policy")); cells[32] = toStringListCell(message, "link"); // TODO cells[33] = toStringListCell(message, "clinical-trail-number"); // TODO cells[34] = CrossrefUtil.nodeToStringCell(message.get("alternative-id")); cells[35] = CrossrefUtil.nodeToDoubleCell(message.get("score")); cells[36] = CrossrefUtil.nodeToStringCell(message.get("URL")); return cells; }
From source file:com.gsma.mobileconnect.utils.AndroidJsonUtils.java
/** * Extract the requested URL from the Operator Not Identified Discovery response. * * @param jsonDoc The json object to check. * @param relToFind The URL to find./* w w w .j a v a 2 s . c o m*/ * @return The requested URL if present, null otherwise. */ public static String extractUrl(JsonNode jsonDoc, String relToFind) { if (null == jsonDoc) { throw new IllegalArgumentException("Missing argument jsonDoc"); } if (null == relToFind) { throw new IllegalArgumentException("Missing argument relToFind"); } JsonNode linksNode = jsonDoc.get(Constants.LINKS_FIELD_NAME); if (null == linksNode) { return null; } Iterator<JsonNode> i = linksNode.elements(); while (i.hasNext()) { JsonNode node = i.next(); String rel = getOptionalStringValue(node, Constants.REL_FIELD_NAME); if (relToFind.equals(rel)) { return getOptionalStringValue(node, Constants.HREF_FIELD_NAME); } } return null; }
From source file:com.baasbox.service.scripting.ScriptingService.java
private static Map<String, List<String>> mapJson(JsonNode node) { if (node == null || node instanceof NullNode) { return null; }/* w w w. j av a2 s . c o m*/ if (node.isObject()) { Map<String, List<String>> ret = new LinkedHashMap<>(); node.fieldNames().forEachRemaining((field) -> { JsonNode jsonNode = node.get(field); List<String> cur = ret.get(field); if (cur == null) { cur = new LinkedList<>(); ret.put(field, cur); } append(cur, jsonNode); }); return ret; } return null; }
From source file:controllers.ClaController.java
@Transactional public static Result pullRequestHookCallback() { JsonNode json = request().body().asJson(); if (json == null) { return ok(); }/*from w ww.jav a 2 s.c om*/ if (!json.has("action")) { return ok(); } String action = json.get("action").asText(); if (action.equals("opened")) { JsonNode pullRequestNode = json.get("pull_request"); JsonNode userNode = pullRequestNode.get("user"); JsonNode repositoryNode = json.get("repository"); JsonNode ownerNode = repositoryNode.get("owner"); String uid = userNode.get("id").asText(); String login = userNode.get("login").asText(); String pullRequestUrl = pullRequestNode.get("url").asText(); String statusUrl = pullRequestNode.get("statuses_url").asText(); String issueUrl = pullRequestNode.get("issue_url").asText(); String repo = repositoryNode.get("name").asText(); String repoUrl = repositoryNode.get("url").asText(); String owner = ownerNode.get("login").asText(); Logger.info("Pull request " + pullRequestUrl + " opened"); /* Reject hook callbacks from other organizations */ boolean foundOrg = false; List<Organization> orgs = Organization.find.findList(); for (Organization org : orgs) { if (org.getName().equals(owner)) { foundOrg = true; break; } } if (!foundOrg) { return ok(); } /* Org members do not need to sign the CLA */ if (GitHubApiUtils.isOrgMember(owner, login)) { GitHubApiUtils.addIssueLabel(repoUrl, CLA_NOT_REQUIRED_LABEL, "159818"); GitHubApiUtils.attachIssueLabel(issueUrl + "/labels", CLA_NOT_REQUIRED_LABEL); return ok(); } SignedCla cla = null; ProjectCla projectCla = ProjectCla.find.where().eq("project", owner + "/" + repo).findUnique(); if (projectCla == null) { Cla defaultCla = Cla.find.where().eq("isDefault", true).findUnique(); projectCla = new ProjectCla(); projectCla.setMinCla(defaultCla); projectCla.setMaxCla(defaultCla); projectCla.setProject(owner + "/" + repo); cla = SignedCla.find.setForUpdate(true).where().eq("claId", defaultCla.getId()).eq("gitHubUid", uid) .ne("state", SignedCla.STATE_REVOKED).findUnique(); } else { List<Cla> clas = Cla.find.where().eq("name", projectCla.getMinCla().getName()).findList(); for (Cla c : clas) { cla = SignedCla.find.setForUpdate(true).where().eq("claId", c.getId()).eq("gitHubUid", uid) .ne("state", SignedCla.STATE_REVOKED).findUnique(); if (cla != null) { if (isInRange(cla, projectCla)) { break; } else { cla = null; } } } } handlePullRequest(cla, projectCla, uid, login, pullRequestUrl, statusUrl, issueUrl, repoUrl); } return ok(); }
From source file:mobile.service.SelfInfoService.java
/** * ???/*from ww w . ja v a 2 s.c om*/ * * @param newJobExp ?? */ public static ServiceResult addJobExp(JsonNode newJobExp) { User user = User.getFromSession(Context.current().session()); Expert expert = Expert.findByUserId(user.id); ArrayNode jobExpArrayNode = null; if (null == expert || StringUtils.isBlank(expert.jobExp)) { jobExpArrayNode = Json.newObject().arrayNode(); } else { jobExpArrayNode = (ArrayNode) Json.parse(expert.jobExp); } if (newJobExp.hasNonNull("endYear") && newJobExp.get("endYear").asText().equals("-1")) { ((ObjectNode) newJobExp).put("endYear", ""); } jobExpArrayNode.add(newJobExp); ObjectNode jobExpNode = Json.newObject(); jobExpNode.set("jobExp", jobExpArrayNode); ObjectNodeResult objectNodeResult = Expert.saveExpertByJson(Context.current().session(), jobExpNode); return ServiceResult.create(objectNodeResult); }
From source file:com.meetingninja.csse.database.UserDatabaseAdapter.java
public static List<Project> getProject(String userID) throws IOException { // Server URL setup String _url = getBaseUri().appendPath("Projects").appendPath(userID).build().toString(); URL url = new URL(_url); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); // add request header conn.setRequestMethod(IRequest.GET); addRequestHeader(conn, false);/* ww w.ja va2 s . co m*/ // Get server response int responseCode = conn.getResponseCode(); String response = getServerResponse(conn); // Initialize ObjectMapper List<Project> projectList = new ArrayList<Project>(); final JsonNode projectArray = MAPPER.readTree(response).get(Keys.Project.LIST); if (projectArray.isArray()) { for (final JsonNode projectNode : projectArray) { Project p = new Project(); p.setProjectID(projectNode.get(Keys.Project.ID).asText()); ProjectDatabaseAdapter.getProject(p); if (p.getProjectID() != null && !p.getProjectID().isEmpty()) { projectList.add(p); } } } else { Log.e(TAG, "Error parsing user's project list"); } conn.disconnect(); return projectList; }
From source file:org.openmhealth.shim.healthvault.HealthvaultShim.java
/** * Utility for parsing a dateTime from 'when' xml node from * health vault.//from w w w . jav a2s. c o m * * @param whenNode - The 'when' node of a 'thing' document. * @return - Joda DateTime corresponding to when node. */ private static DateTime parseDateTimeFromWhenNode(JsonNode whenNode) { if (whenNode == null) { return null; } JsonNode dateNode = whenNode.get("date"); JsonNode timeNode = whenNode.get("time"); String dateString = dateNode.get("y").asText() + "-" + dateNode.get("m").asText() + "-" + dateNode.get("d").asText(); if (timeNode != null) { String timeString = timeNode.get("h").asText() + ":" + timeNode.get("m").asText(); return formatterMins.parseDateTime(dateString + " " + timeString); } else { return formatterDate.parseDateTime(dateString); } }