List of usage examples for com.fasterxml.jackson.databind JsonNode iterator
public final Iterator<JsonNode> iterator()
From source file:org.walkmod.conf.providers.yml.SetReaderYMLAction.java
@Override public void doAction(JsonNode node) throws Exception { if (node.has("chains") && (chain == null || "".equals(chain.trim()))) { chain = "default"; }// www. j ava 2s . c o m ObjectNode reader = null; ObjectMapper mapper = provider.getObjectMapper(); if (chain != null && !"".equals(chain.trim())) { if (node.has("chains")) { JsonNode chainsListNode = node.get("chains"); if (chainsListNode.isArray()) { Iterator<JsonNode> it = chainsListNode.iterator(); boolean found = false; while (it.hasNext() && !found) { JsonNode current = it.next(); if (current.has("name")) { String name = current.get("name").asText(); found = name.equals(chain); if (found) { if (current.has("reader")) { reader = (ObjectNode) current.get("reader"); } else { reader = new ObjectNode(mapper.getNodeFactory()); } if (type != null && !"".equals(type.trim())) { reader.set("type", new TextNode(type)); } if (path != null && !"".equals(path.trim())) { reader.set("path", new TextNode(path)); } if (params != null && !params.isEmpty()) { ObjectNode paramsObject = null; if (reader.has("params")) { paramsObject = (ObjectNode) reader.get("params"); } else { paramsObject = new ObjectNode(mapper.getNodeFactory()); reader.set("params", paramsObject); } Set<String> keys = params.keySet(); for (String key : keys) { paramsObject.put(key, params.get(key).toString()); } } } } } } } if (reader != null) { provider.write(node); } } else { if (!node.has("chains")) { ArrayNode chains = new ArrayNode(mapper.getNodeFactory()); ObjectNode defaultChain = new ObjectNode(mapper.getNodeFactory()); defaultChain.set("name", new TextNode("default")); ObjectNode readerNode = new ObjectNode(mapper.getNodeFactory()); if (type != null && !"".equals(type.trim())) { readerNode.set("type", new TextNode(type)); } if (path != null && !"".equals(path.trim())) { readerNode.set("path", new TextNode(path)); } if (params != null && !params.isEmpty()) { ObjectNode paramsObject = new ObjectNode(mapper.getNodeFactory()); Set<String> keys = params.keySet(); for (String key : keys) { paramsObject.put(key, params.get(key).toString()); } readerNode.set("params", paramsObject); } defaultChain.set("reader", readerNode); if (node.has("transformations")) { defaultChain.set("transformations", node.get("transformations")); } chains.add(defaultChain); provider.write(chains); } } }
From source file:com.enitalk.configs.DateCache.java
@Bean(name = "skipCache") public LoadingCache<String, ConcurrentSkipListSet<DateTime>> datesMap() { CacheBuilder<Object, Object> ccc = CacheBuilder.newBuilder(); ccc.expireAfterWrite(2, TimeUnit.MINUTES); LoadingCache<String, ConcurrentSkipListSet<DateTime>> cache = ccc .build(new CacheLoader<String, ConcurrentSkipListSet<DateTime>>() { @Override/*from w w w .j a v a 2 s.co m*/ public ConcurrentSkipListSet<DateTime> load(String key) throws Exception { try { HashMap teachers = mongo.findOne(Query.query(Criteria.where("i").is(key)), HashMap.class, "teachers"); ObjectNode teacherJson = jackson.convertValue(teachers, ObjectNode.class); String timeZone = teacherJson.at("/calendar/timeZone").asText(); NavigableSet<DateTime> set = days(teacherJson.path("schedule"), timeZone, teacherJson); DateTimeZone dzz = DateTimeZone.forID(timeZone); DateTimeFormatter df = ISODateTimeFormat.dateTimeNoMillis().withZone(dzz); byte[] events = calendar.busyEvents(jackson.createObjectNode().put("id", key)); JsonNode evs = jackson.readTree(events); Iterator<JsonNode> its = evs.iterator(); TreeSet<DateTime> dates = new TreeSet<>(); while (its.hasNext()) { String date = its.next().asText(); DateTime av = df.parseDateTime(date).toDateTime(DateTimeZone.UTC); dates.add(av); } set.removeAll(dates); logger.info("Dates for i {} {}", key, set); return new ConcurrentSkipListSet<>(set); } catch (Exception e) { logger.error(ExceptionUtils.getFullStackTrace(e)); } return null; } }); return cache; }
From source file:org.walkmod.conf.providers.yml.SetWriterYMLAction.java
@Override public void doAction(JsonNode node) throws Exception { ObjectNode writer = null;// w w w .j a va 2s.c om ObjectMapper mapper = provider.getObjectMapper(); if (node.has("chains") && (chain == null || "".equals(chain.trim()))) { chain = "default"; } if (chain != null && !"".equals(chain.trim())) { if (node.has("chains")) { JsonNode chainsListNode = node.get("chains"); if (chainsListNode.isArray()) { Iterator<JsonNode> it = chainsListNode.iterator(); boolean found = false; while (it.hasNext() && !found) { JsonNode current = it.next(); if (current.has("name")) { String name = current.get("name").asText(); found = name.equals(chain); if (found) { if (current.has("writer")) { writer = (ObjectNode) current.get("writer"); } else { writer = new ObjectNode(mapper.getNodeFactory()); } if (type != null && !"".equals(type.trim())) { writer.set("type", new TextNode(type)); } if (path != null && !"".equals(path.trim())) { writer.set("path", new TextNode(path)); } if (params != null && !params.isEmpty()) { ObjectNode paramsObject = null; if (writer.has("params")) { paramsObject = (ObjectNode) writer.get("params"); } else { paramsObject = new ObjectNode(mapper.getNodeFactory()); writer.set("params", paramsObject); } Set<String> keys = params.keySet(); for (String key : keys) { paramsObject.put(key, params.get(key).toString()); } } } } } } } if (writer != null) { provider.write(node); } } else { if (!node.has("chains")) { ArrayNode chains = new ArrayNode(mapper.getNodeFactory()); ObjectNode defaultChain = new ObjectNode(mapper.getNodeFactory()); defaultChain.set("name", new TextNode("default")); ObjectNode writerNode = new ObjectNode(mapper.getNodeFactory()); if (type != null && !"".equals(type.trim())) { writerNode.set("type", new TextNode(type)); } if (path != null && !"".equals(path.trim())) { writerNode.set("path", new TextNode(path)); } if (params != null && !params.isEmpty()) { ObjectNode paramsObject = new ObjectNode(mapper.getNodeFactory()); Set<String> keys = params.keySet(); for (String key : keys) { paramsObject.put(key, params.get(key).toString()); } writerNode.set("params", paramsObject); } if (node.has("transformations")) { defaultChain.set("transformations", node.get("transformations")); } defaultChain.set("writer", writerNode); chains.add(defaultChain); ObjectNode root = new ObjectNode(mapper.getNodeFactory()); root.set("chains", chains); provider.write(root); } } }
From source file:org.jasig.cas.support.oauth.provider.impl.CasWrapperProvider20.java
@Override protected UserProfile extractUserProfile(final String body) { final CasWrapperProfile userProfile = new CasWrapperProfile(); JsonNode json = JsonHelper.getFirstNode(body); if (json != null) { userProfile.setId(JsonHelper.get(json, CasWrapperProfile.ID)); json = json.get(CasWrapperProfile.ATTRIBUTES); if (json != null) { final Iterator<JsonNode> nodes = json.iterator(); while (nodes.hasNext()) { json = nodes.next();//from w ww . ja v a 2s . co m final String attribute = json.fieldNames().next(); userProfile.addAttribute(attribute, JsonHelper.get(json, attribute)); } } } return userProfile; }
From source file:org.pac4j.oauth.client.CasOAuthWrapperClient.java
@Override protected CasOAuthWrapperProfile extractUserProfile(final String body) { final CasOAuthWrapperProfile userProfile = new CasOAuthWrapperProfile(); JsonNode json = JsonHelper.getFirstNode(body); if (json != null) { userProfile.setId(JsonHelper.get(json, "id")); json = json.get("attributes"); if (json != null) { final Iterator<JsonNode> nodes = json.iterator(); while (nodes.hasNext()) { json = nodes.next();/*from ww w . jav a 2 s . c om*/ final String attribute = json.fieldNames().next(); userProfile.addAttribute(attribute, JsonHelper.get(json, attribute)); } } } return userProfile; }
From source file:org.jboss.aerogear.sync.diffmatchpatch.JsonMapperTest.java
@Test public void serializeEdits() { final String documentId = "1234"; final String clientId = "client1"; final PatchMessage<DiffMatchPatchEdit> patchMessage = patchMessage(documentId, clientId, DiffMatchPatchEdit.withChecksum("bogus") .diff(new DiffMatchPatchDiff(Operation.UNCHANGED, "version")) .diff(new DiffMatchPatchDiff(Operation.DELETE, "1")) .diff(new DiffMatchPatchDiff(Operation.ADD, "2")).build()); final String json = JsonMapper.toJson(patchMessage); final JsonNode jsonNode = JsonMapper.asJsonNode(json); assertThat(jsonNode.get("msgType").asText(), equalTo("patch")); assertThat(jsonNode.get("id").asText(), equalTo(documentId)); assertThat(jsonNode.get("clientId").asText(), equalTo(clientId)); final JsonNode editsNode = jsonNode.get("edits"); assertThat(editsNode.isArray(), is(true)); assertThat(editsNode.size(), is(1)); final JsonNode edit = editsNode.iterator().next(); assertThat(edit.get("serverVersion").asText(), equalTo("0")); assertThat(edit.get("clientVersion").asText(), equalTo("0")); final JsonNode diffs = edit.get("diffs"); assertThat(diffs.isArray(), is(true)); assertThat(diffs.size(), is(3));/*from w ww . ja v a2 s. c o m*/ }
From source file:com.mapr.data.sputnik.log.Log4JLogger.java
public void printAll(String name, JsonNode node) { if (!node.isValueNode()) { Iterator<String> fieldNames = node.fieldNames(); System.out.print("{ "); while (fieldNames.hasNext()) { String fieldName = fieldNames.next(); JsonNode fieldValue = node.get(fieldName); if (fieldValue.isArray()) { System.out.print(fieldName + " [ "); List<String> a = new ArrayList<>(1); Iterator<JsonNode> itr = fieldValue.iterator(); while (itr.hasNext()) { JsonNode n = itr.next(); printAll(fieldName, n); System.out.print(", "); }/* w w w .j a va 2 s .c o m*/ System.out.print(" ] "); } else { printAll(fieldName, fieldValue); System.out.print(", "); } } System.out.print(" } "); } else { Iterator<Entry<String, JsonNode>> itParams = node.fields(); while (itParams.hasNext()) { Entry<String, JsonNode> elt = itParams.next(); System.out.println(elt.getKey()); } if (node.isInt()) { System.out.print(name + " : " + node.intValue()); } else if (node.isDouble()) { System.out.print(name + " : " + node.doubleValue()); } else if (node.isTextual()) { System.out.print(name + " : " + node.textValue()); } else if (node.isLong()) { System.out.print(name + " : " + node.longValue()); } else System.out.print(name + " : " + node.textValue()); } }
From source file:org.jboss.aerogear.sync.diffmatchpatch.JsonMapperTest.java
@Test public void serializeEditsWithArray() { final String documentId = "1234"; final String clientId = "client1"; final PatchMessage<DiffMatchPatchEdit> patchMessage = patchMessage(documentId, clientId, DiffMatchPatchEdit.withChecksum("bogus") .diff(new DiffMatchPatchDiff(Operation.UNCHANGED, "{\"content\": [\"one\", \"")) .diff(new DiffMatchPatchDiff(Operation.ADD, "tw")) .diff(new DiffMatchPatchDiff(Operation.UNCHANGED, "o")) .diff(new DiffMatchPatchDiff(Operation.DELETE, "ne")) .diff(new DiffMatchPatchDiff(Operation.UNCHANGED, "\"]}")).build()); final String json = JsonMapper.toJson(patchMessage); final JsonNode jsonNode = JsonMapper.asJsonNode(json); assertThat(jsonNode.get("msgType").asText(), equalTo("patch")); assertThat(jsonNode.get("id").asText(), equalTo(documentId)); assertThat(jsonNode.get("clientId").asText(), equalTo(clientId)); final JsonNode editsNode = jsonNode.get("edits"); assertThat(editsNode.isArray(), is(true)); assertThat(editsNode.size(), is(1)); final JsonNode edit = editsNode.iterator().next(); assertThat(edit.get("serverVersion").asText(), equalTo("0")); assertThat(edit.get("clientVersion").asText(), equalTo("0")); final JsonNode diffs = edit.get("diffs"); assertThat(diffs.isArray(), is(true)); assertThat(diffs.size(), is(5));/* ww w .j a v a 2 s .c o m*/ assertThat(diffs.get(0).get("operation").asText(), equalTo("UNCHANGED")); assertThat(diffs.get(0).get("text").asText(), equalTo("{\"content\": [\"one\", \"")); assertThat(diffs.get(1).get("operation").asText(), equalTo("ADD")); assertThat(diffs.get(1).get("text").asText(), equalTo("tw")); assertThat(diffs.get(2).get("operation").asText(), equalTo("UNCHANGED")); assertThat(diffs.get(2).get("text").asText(), equalTo("o")); assertThat(diffs.get(3).get("operation").asText(), equalTo("DELETE")); assertThat(diffs.get(3).get("text").asText(), equalTo("ne")); assertThat(diffs.get(4).get("operation").asText(), equalTo("UNCHANGED")); assertThat(diffs.get(4).get("text").asText(), equalTo("\"]}")); }
From source file:org.jboss.aerogear.sync.diffmatchpatch.JsonMapperTest.java
@Test public void serializeEditsWithArrayToJsonAndBack() { final String documentId = "1234"; final String clientId = "client1"; final PatchMessage<DiffMatchPatchEdit> patchMessage = patchMessage(documentId, clientId, DiffMatchPatchEdit.withChecksum("bogus") .diff(new DiffMatchPatchDiff(Operation.UNCHANGED, "{\"content\": [\"one\", \"")) .diff(new DiffMatchPatchDiff(Operation.ADD, "tw")) .diff(new DiffMatchPatchDiff(Operation.UNCHANGED, "o")) .diff(new DiffMatchPatchDiff(Operation.DELETE, "ne")) .diff(new DiffMatchPatchDiff(Operation.UNCHANGED, "\"]}")).build()); final String json = JsonMapper.toJson(patchMessage); final JsonNode jsonNode = JsonMapper.asJsonNode(json); assertThat(jsonNode.get("msgType").asText(), equalTo("patch")); assertThat(jsonNode.get("id").asText(), equalTo(documentId)); assertThat(jsonNode.get("clientId").asText(), equalTo(clientId)); final JsonNode editsNode = jsonNode.get("edits"); assertThat(editsNode.isArray(), is(true)); assertThat(editsNode.size(), is(1)); final JsonNode edit = editsNode.iterator().next(); assertThat(edit.get("serverVersion").asText(), equalTo("0")); assertThat(edit.get("clientVersion").asText(), equalTo("0")); final JsonNode diffs = edit.get("diffs"); assertThat(diffs.isArray(), is(true)); assertThat(diffs.size(), is(5));/*from w ww.jav a 2 s .com*/ assertThat(diffs.get(0).get("operation").asText(), equalTo("UNCHANGED")); assertThat(diffs.get(0).get("text").asText(), equalTo("{\"content\": [\"one\", \"")); assertThat(diffs.get(1).get("operation").asText(), equalTo("ADD")); assertThat(diffs.get(1).get("text").asText(), equalTo("tw")); assertThat(diffs.get(2).get("operation").asText(), equalTo("UNCHANGED")); assertThat(diffs.get(2).get("text").asText(), equalTo("o")); assertThat(diffs.get(3).get("operation").asText(), equalTo("DELETE")); assertThat(diffs.get(3).get("text").asText(), equalTo("ne")); assertThat(diffs.get(4).get("operation").asText(), equalTo("UNCHANGED")); assertThat(diffs.get(4).get("text").asText(), equalTo("\"]}")); }
From source file:com.ikanow.aleph2.security.service.IkanowV1DataGroupRoleProvider.java
private String determineCommunityAction(JsonNode members, String principalName) { String action = "NONE"; if (members != null) { for (Iterator<JsonNode> it = members.iterator(); it.hasNext();) { JsonNode member = it.next(); String id = member.get("_id").asText(); if (principalName.equals(id)) { String userType = member.get("userType").asText(); action = "member".equals(userType) ? ISecurityService.ACTION_READ : ISecurityService.ACTION_READ_WRITE; break; }/*from ww w. j a v a 2s . co m*/ } } return action; }