List of usage examples for com.fasterxml.jackson.databind JsonNode get
public JsonNode get(String paramString)
From source file:com.baasbox.service.scripting.ScriptingService.java
public static ScriptStatus update(String name, JsonNode code) throws ScriptException { if (code == null) throw new ScriptException("missing code"); JsonNode codeNode = code.get(ScriptsDao.CODE); if (codeNode == null || !codeNode.isTextual()) { throw new ScriptException("missing code"); }/* w w w . j a v a 2 s .co m*/ String source = codeNode.asText(); return update(name, source); }
From source file:com.cyphermessenger.client.SyncRequest.java
public static Captcha requestCaptcha() throws IOException, APIErrorException { HttpURLConnection conn = doRequest("captcha"); if (conn.getResponseCode() != 200) { throw new IOException("Server error"); }/* w ww. j a va 2 s . c o m*/ InputStream in = conn.getInputStream(); JsonNode node = MAPPER.readTree(in); conn.disconnect(); int statusCode = node.get("status").asInt(); String captchaTokenString = node.get("captchaToken").asText(); String captchaHashString = node.get("captchaHash").asText(); String captchaImageString = node.get("captchaBytes").asText(); byte[] captchaHash = Utils.BASE64_URL.decode(captchaHashString); byte[] captchaImage = Utils.BASE64_URL.decode(captchaImageString); if (statusCode == StatusCode.OK) { return new Captcha(captchaTokenString, captchaHash, captchaImage); } else { throw new APIErrorException(statusCode); } }
From source file:com.tda.sitefilm.allocine.JSONAllocineAPIHelper.java
private static void parseMedia(List<Media> mediaList, JsonNode rootNode) { JsonNode node = rootNode.get("media"); if (node != null && (node.size() > 0)) { for (int i = 0; i < node.size(); i++) { JsonNode mediaNode = node.get(i); Media media = new Media(); JsonNode innerNode = mediaNode.get("type"); if (innerNode != null) { TypeType typeType = new TypeType(); typeType.setCode(getValueAsInt(innerNode.get("code"))); media.setType(typeType); }//from www . ja va 2 s .c om innerNode = mediaNode.get("thumbnail"); if (innerNode != null) { ThumbnailType thumbnailType = new ThumbnailType(); thumbnailType.setHref(getValueAsString(innerNode.get("href"))); media.setThumbnail(thumbnailType); } mediaList.add(media); } } }
From source file:com.tda.sitefilm.allocine.JSONAllocineAPIHelper.java
private static void parseCasting(List<CastMember> members, JsonNode rootNode) { JsonNode node = rootNode.get("castMember"); if (node != null && (node.size() > 0)) { for (int i = 0; i < node.size(); i++) { JsonNode memberNode = node.get(i); CastMember member = new CastMember(); member.setRole(getValueAsString(memberNode.get("role"))); JsonNode personNode = memberNode.get("person"); if (personNode != null) { Person person = new Person(); person.setCode(getValueAsInt(personNode.get("code"))); person.setName(getValueAsString(personNode.get("name"))); member.setPerson(person); }/*www.j a v a2s .c o m*/ JsonNode activityNode = memberNode.get("activity"); if (activityNode != null) { ActivityType activityType = new ActivityType(); activityType.setCode(Integer.valueOf(getValueAsInt(activityNode.get("code")))); member.setActivity(activityType); } members.add(member); } } }
From source file:com.bbva.kltt.apirest.core.util.parser.ParserUtil.java
/** * @param nodeName with the node name//from w ww . j a va2s .co m * @param node with the node to search the field * @param fieldName with the field name to be searched * @param isRequired true if the field is required * @return the json node of the child * @throws APIRestGeneratorException with an occurred exception */ public static JsonNode getNodeValueJson(final String nodeName, final JsonNode node, final String fieldName, final boolean isRequired) throws APIRestGeneratorException { JsonNode outcome = null; final boolean hasField = node.has(fieldName); if (hasField) { outcome = node.get(fieldName); if (outcome.isNull() && isRequired) { ParserUtil.generateExceptionRequiredNodeContent(nodeName, fieldName); } } else if (!hasField && isRequired) { ParserUtil.generateExceptionRequiredField(nodeName, fieldName); } return outcome; }
From source file:controllers.ClaController.java
public static Result authCallback(String uuid, String code) { SignedCla cla = null;// w w w .j a v a2s. co m try { cla = getSignedCla(uuid); } catch (ResultException e) { return e.getResult(); } WSRequestHolder holder = WS.url("https://github.com/login/oauth/access_token"); holder = holder.setQueryParameter("client_id", Play.application().configuration().getString("app.github.clientid")); holder = holder.setQueryParameter("client_secret", Play.application().configuration().getString("app.github.clientsecret")); holder = holder.setQueryParameter("code", code); holder = holder.setHeader("Accept", "application/json"); Promise<WSResponse> response = holder.post(""); JsonNode json = response.get(30000).asJson(); String token = json.get("access_token").asText(); String header = GitHubApiUtils.getAuthHeader(token); response = WS.url("https://api.github.com/user").setHeader("Authorization", header).get(); json = response.get(30000).asJson(); String uid = json.get("id").asText(); if (!uid.equals(cla.getGitHubUid())) { return unauthorized( message.render("This contributor license agreement request does not belong to you")); } List<String> emails = new ArrayList<String>(); response = WS.url("https://api.github.com/user/emails").setHeader("Authorization", header).get(); json = response.get(30000).asJson(); if (json.isArray()) { ArrayNode array = (ArrayNode) json; Iterator<JsonNode> iterator = array.iterator(); while (iterator.hasNext()) { JsonNode node = iterator.next(); emails.add(node.get("email").asText()); } } if (emails.isEmpty()) { return badRequest( message.render("Unable to get e-mail address from GitHub for " + cla.getGitHubLogin())); } boolean employerCheck = cla.getLegalContactEmail() != null; Map<Long, String> responses = new HashMap<Long, String>(); for (SignedClaInputField field : cla.getInputFields()) { responses.put(field.getInputField().getId(), field.getResponse()); } session().clear(); session("login", cla.getGitHubUid()); String expiration = Play.application().configuration().getString("app.ccla.expiration"); return ok(views.html.cla.render(emails, cla, employerCheck, responses, expiration)); }
From source file:com.cyphermessenger.client.SyncRequest.java
private static JsonNode pullUpdate(CypherSession session, CypherUser contact, String action, Boolean since, Long time) throws IOException, APIErrorException { String timeBoundary = "since"; if (since != null && since == UNTIL) { timeBoundary = "until"; }/*from w w w . j a va 2s. c om*/ HashMap<String, String> pairs = new HashMap<>(3); pairs.put("action", action); if (contact != null) { pairs.put("contactID", contact.getUserID().toString()); } if (time != null) { pairs.put(timeBoundary, time.toString()); } HttpURLConnection conn = doRequest("pull", session, pairs); if (conn.getResponseCode() != 200) { throw new IOException("Server error"); } InputStream in = conn.getInputStream(); JsonNode node = MAPPER.readTree(in); conn.disconnect(); int statusCode = node.get("status").asInt(); if (statusCode == StatusCode.OK) { return node; } else { throw new APIErrorException(statusCode); } }
From source file:com.spoiledmilk.cykelsuperstier.break_rote.LocalTrainData.java
private static void getTimesForWeekdays(int hour, int minute, ArrayList<ITransportationInfo> times, JsonNode timeTableNode, int index1, int index2, int numOfStations) { ArrayList<TimeData> allTimes = new ArrayList<TimeData>(); for (int i = 0; i < timeTableNode.size(); i++) { JsonNode intervalNode = timeTableNode.get(i); try {/* w w w. j av a 2 s.c o m*/ double currentTime = ((double) hour) + ((double) minute) / 100d; double startInterval = intervalNode.get("start-time").asDouble(); double endInterval = intervalNode.get("end-time").asDouble(); if (endInterval < 1.0) endInterval += 24.0; if (currentTime >= startInterval && currentTime <= endInterval) { JsonNode dataNode = intervalNode.get("data"); int[] minutesArray = new int[dataNode.size()]; for (int j = 0; j < minutesArray.length; j++) { minutesArray[j] = dataNode.get(j).asInt(); } int currentHour = hour; int currentIndex = 0; int count = 0; while (currentHour <= endInterval && count < 3 && currentIndex < minutesArray.length) { double time1 = minutesArray[currentIndex + index1]; double time2 = minutesArray[currentIndex + index2]; if (time1 < 0 || time2 < 0) continue; time1 /= 100d; time1 += currentHour; time2 /= 100d; time2 += currentHour; if (time2 < time1) time2 += 1.0; allTimes.add(new TimeData(time1, time2)); currentHour++; count++; currentIndex += numOfStations; } } } catch (Exception e) { LOG.e(e.getLocalizedMessage()); } } // sort the list for (int i = 0; i < allTimes.size() - 1; i++) { for (int j = i + 1; j < allTimes.size(); j++) { TimeData td1 = allTimes.get(i); TimeData td2 = allTimes.get(j); if (td1.stationAtime > td2.stationAtime) { allTimes.set(i, td2); allTimes.set(j, td1); } } } LOG.d("sorted times = " + allTimes.toString()); // return the 3 results for (int i = 0; i < 3 && i < allTimes.size(); i++) { TimeData temp = allTimes.get(i); int time = 0; int minutes1 = (int) ((temp.stationAtime - (double) ((int) temp.stationAtime)) * 100); int minutes2 = (int) ((temp.stationBtime - (double) ((int) temp.stationBtime)) * 100); time = (((int) temp.stationBtime) - ((int) temp.stationAtime)) * 60; if (minutes2 >= minutes1) time = minutes2 - minutes1; else { time += 60 - minutes1 + minutes2; time -= 60; } String formattedTime1 = (((int) temp.stationAtime) < 10 ? "0" + ((int) temp.stationAtime) : "" + ((int) temp.stationAtime)) + ":" + (minutes1 < 10 ? "0" + minutes1 : "" + minutes1); String formattedTime2 = (((int) temp.stationBtime) < 10 ? "0" + ((int) temp.stationBtime) : "" + ((int) temp.stationBtime)) + ":" + (minutes2 < 10 ? "0" + minutes2 : "" + minutes2); times.add(new LocalTrainData(formattedTime1, formattedTime2, time)); } }
From source file:com.squarespace.template.plugins.platform.CommerceUtils.java
public static boolean isSoldOut(JsonNode item) { ProductType type = getProductType(item); JsonNode structuredContent = item.path("structuredContent"); switch (type) { case PHYSICAL: case SERVICE: JsonNode variants = structuredContent.path("variants"); int size = variants.size(); for (int i = 0; i < size; i++) { JsonNode variant = variants.get(i); if (isTruthy(variant.path("unlimited")) || variant.path("qtyInStock").asInt() > 0) { return false; }//w w w .j ava 2 s . c o m } return true; case DIGITAL: case GIFT_CARD: return false; default: return true; } }
From source file:com.squarespace.template.plugins.platform.CommerceUtils.java
public static boolean isOnSale(JsonNode item) { ProductType type = getProductType(item); JsonNode structuredContent = item.path("structuredContent"); switch (type) { case PHYSICAL: case SERVICE: JsonNode variants = structuredContent.path("variants"); int size = variants.size(); for (int i = 0; i < size; i++) { JsonNode variant = variants.get(i); if (isTruthy(variant.path("onSale"))) { return true; }/*from w w w.j a v a2 s.c o m*/ } break; case DIGITAL: return isTruthy(structuredContent.path("onSale")); case GIFT_CARD: default: break; } return false; }