List of usage examples for com.fasterxml.jackson.databind.node NullNode getInstance
public static NullNode getInstance()
From source file:com.digitalpebble.stormcrawler.protocol.selenium.NavigationFilters.java
@SuppressWarnings("rawtypes") @Override//from ww w .j a v a2s . c o m public void configure(Map stormConf, JsonNode filtersConf) { // initialises the filters List<NavigationFilter> filterLists = new ArrayList<>(); // get the filters part String name = getClass().getCanonicalName(); filtersConf = filtersConf.get(name); if (filtersConf == null) { LOG.info("No field {} in JSON config. Skipping", name); filters = new NavigationFilter[0]; return; } // conf node contains a list of objects Iterator<JsonNode> filterIter = filtersConf.elements(); while (filterIter.hasNext()) { JsonNode afilterConf = filterIter.next(); String filterName = "<unnamed>"; JsonNode nameNode = afilterConf.get("name"); if (nameNode != null) { filterName = nameNode.textValue(); } JsonNode classNode = afilterConf.get("class"); if (classNode == null) { LOG.error("Filter {} doesn't specified a 'class' attribute", filterName); continue; } String className = classNode.textValue().trim(); filterName += '[' + className + ']'; // check that it is available and implements the interface // NavigationFilter try { Class<?> filterClass = Class.forName(className); boolean subClassOK = NavigationFilter.class.isAssignableFrom(filterClass); if (!subClassOK) { LOG.error("Filter {} does not extend NavigationFilter", filterName); continue; } NavigationFilter filterInstance = (NavigationFilter) filterClass.newInstance(); JsonNode paramNode = afilterConf.get("params"); if (paramNode != null) { filterInstance.configure(stormConf, paramNode); } else { // Pass in a nullNode if missing filterInstance.configure(stormConf, NullNode.getInstance()); } filterLists.add(filterInstance); LOG.info("Setup {}", filterName); } catch (Exception e) { LOG.error("Can't setup {}: {}", filterName, e); throw new RuntimeException("Can't setup " + filterName, e); } } filters = filterLists.toArray(new NavigationFilter[filterLists.size()]); }
From source file:de.raion.xmppbot.hipchat.JiraLinkBeautifierInterceptor.java
private String createMessageText(Message xmppMessage, JsonNode issue, JiraIssuePlugin plugin) { String issueKey = issue.findValue("key").textValue(); String issueSummary = issue.findValue("summary").textValue(); String issueIconUrl = issue.path("fields").path("issuetype").get("iconUrl").asText(); String issueType = issue.path("fields").path("issuetype").get("name").asText(); String priorityUrl = issue.path("fields").path("priority").get("iconUrl").asText(); String priority = issue.path("fields").path("priority").get("name").asText(); String statusUrl = issue.path("fields").path("status").get("iconUrl").asText(); String status = issue.path("fields").path("status").get("name").asText(); String reporterAcnt = issue.path("fields").path("reporter").get("name").asText(); String reporterName = issue.path("fields").path("reporter").get("displayName").asText(); String reporterIcon = issue.path("fields").path("reporter").path("avatarUrls").get("16x16").asText(); String assigneeAcnt = null;/* ww w . j av a 2s . co m*/ String assigneeName = null; String assigneeIcon = null; JsonNode assignee = issue.path("fields").path("assignee"); //log.debug(assignee.toString()); //log.debug("Nullnode = {}", assignee.isNull()); if (!(assignee == NullNode.getInstance())) { if (!assignee.get("name").isMissingNode()) assigneeAcnt = assignee.get("name").asText(); if (!assignee.get("displayName").isMissingNode()) assigneeName = assignee.get("displayName").asText(); if (!assignee.get("avatarUrls").isMissingNode()) assigneeIcon = assignee.path("avatarUrls").get("16x16").asText(); } String line = xmppMessage.getBody(); int index = line.indexOf("http"); String issueUrl = line.substring(index).trim().replace("\n", ""); StringBuilder builder = new StringBuilder(); String issueText = createIssueText(issueKey, issueSummary); builder.append(createImageTag(issueIconUrl, issueType)); builder.append(" ").append(createAnchorTag(issueText, issueUrl)); // TODO do better ;) if (!status.toLowerCase().equals("closed")) builder.append(createImageTag(priorityUrl, priority)); builder.append(createImageTag(statusUrl, status)); builder.append(" Opened by "); builder.append( createAnchorTag(reporterName, createProfileUrl(plugin.getConfig().getJiraDomain(), reporterAcnt))); builder.append(" ").append(createImageTag(reporterIcon, reporterName)); if (assigneeAcnt != null) { builder.append(". Current assignee is "); builder.append(createAnchorTag(assigneeName, createProfileUrl(plugin.getConfig().getJiraDomain(), assigneeAcnt))); builder.append(" ").append(createImageTag(assigneeIcon, assigneeName)); } return builder.toString(); }
From source file:com.baasbox.commands.UsersResource.java
private JsonNode doFollow(JsonNode command, String from, String to) throws CommandExecutionException { try {/*from w ww. ja va 2 s . c o m*/ ODocument followed = FriendShipService.follow(from, to); String s = JSONFormats.prepareDocToJson(followed, JSONFormats.Formats.USER); return Json.mapper().readTree(s); } catch (UserNotFoundException e) { throw new CommandExecutionException(command, ExceptionUtils.getMessage(e), e); } catch (AlreadyFriendsException e) { return NullNode.getInstance(); } catch (SqlInjectionException e) { throw new CommandExecutionException(command, ExceptionUtils.getMessage(e), e); } catch (Exception e) { throw new CommandExecutionException(command, ExceptionUtils.getMessage(e), e); } }
From source file:com.almende.eve.state.mongo.MongoState.java
@Override public synchronized boolean locPutIfUnchanged(final String key, final JsonNode newVal, JsonNode oldVal) { boolean result = false; try {/* ww w . ja va 2 s . c o m*/ JsonNode cur = NullNode.getInstance(); if (properties.containsKey(key)) { cur = properties.get(key); } if (oldVal == null) { oldVal = NullNode.getInstance(); } // Poor man's equality as some Numbers are compared incorrectly: e.g. // IntNode versus LongNode if (oldVal.equals(cur) || oldVal.toString().equals(cur.toString())) { properties.put(key, newVal); result = updateProperties(false); // updateField(key, newVal); } } catch (final UpdateConflictException e) { LOG.log(Level.WARNING, e.getMessage()); reloadProperties(); // recur if update conflict occurs locPutIfUnchanged(key, newVal, oldVal); } catch (final Exception e) { LOG.log(Level.WARNING, "locPutIfUnchanged error", e); } return result; }
From source file:com.redhat.lightblue.crud.rdbms.RDBMSProcessor.java
private static void convertRecursion(RDBMSContext rdbmsContext, JsonDoc jd, String key, Object values, ArrayNode doc) {//from ww w .ja va2 s .c o m Collection c = values instanceof Collection ? ((Collection) values) : null; if (values == null || (c != null && c.isEmpty())) { if (doc == null) { jd.modify(new Path(key), NullNode.getInstance(), true); } else { doc.add(NullNode.getInstance()); } } else if (c != null && c.size() > 1) { if (doc == null) { doc = new ArrayNode(rdbmsContext.getJsonNodeFactory()); } for (Object value : c) { if (value instanceof Collection) { Collection cValue = (Collection) value; ArrayNode newDoc = new ArrayNode(rdbmsContext.getJsonNodeFactory()); for (Object o : cValue) { convertRecursion(rdbmsContext, jd, key, o, newDoc); } doc.add(newDoc); } else { doc.add(value.toString()); } } jd.modify(new Path(key), doc, true); } else { if (doc == null) { Object o = c.iterator().next(); jd.modify(new Path(key), new TextNode(o.toString()), true); } else { doc.add(new TextNode(values.toString())); } } }
From source file:org.wisdom.wamp.WampControllerRPCTest.java
@Test public void testValidInvocationWithNullArg() throws RegistryException { message = null;//from ww w.j ava2 s. c om Json json = new JsonService(); WampController controller = createWampControllerAndConnectClient(json); Howdy howdy = new Howdy(); controller.register(howdy, "http://example.com/howdy"); message = null; ArrayNode call = json.newArray(); call.add(MessageType.CALL.code()); call.add("7DK6TdN4wLiUJgNM"); call.add("http://example.com/howdy#complex"); call.add(NullNode.getInstance()); controller.onMessage("id", call); assertThat(message).isNotNull(); JsonNode node = json.parse(message); assertThat(node.isArray()); System.out.println(message); assertThat(node.get(0).asInt()).isEqualTo(MessageType.CALLRESULT.code()); assertThat(node.get(1).asText()).isEqualTo("7DK6TdN4wLiUJgNM"); assertThat(node.get(2).isNull()).isTrue(); }
From source file:com.almende.eve.state.ConcurrentJsonFileState.java
@Override public synchronized JsonNode get(final String key) { JsonNode result = NullNode.getInstance(); boolean open = false; try {/*from w w w .j a v a 2s . co m*/ if (properties == null) { open = true; openFile(); read(); } result = properties.get(key); } catch (final Exception e) { LOG.log(Level.WARNING, "", e); } if (open) { closeFile(); } return result; }
From source file:com.baasbox.commands.UsersResource.java
protected JsonNode changeUsername(JsonNode command, JsonCallback unused) throws CommandException { String username = getUsername(command); JsonNode newUsernameJson = getParamField(command, "newUsername"); if (newUsernameJson == null || !newUsernameJson.isTextual()) throw new CommandExecutionException(command, "invalid new username: " + newUsernameJson); String newUsername = newUsernameJson.asText(); try {/* w ww . j a v a2 s.c om*/ UserService.changeUsername(username, newUsername); } catch (UserNotFoundException | OpenTransactionException | SqlInjectionException e) { throw new CommandExecutionException(command, ExceptionUtils.getMessage(e), e); } return NullNode.getInstance(); }
From source file:io.macgyver.neorx.rest.NeoRxClientIntegrationTest.java
@Test public void testPrimitiveValues() throws JsonProcessingException, IOException { ObjectMapper m = new ObjectMapper(); JsonNode n = m.createObjectNode().set("xyz", NullNode.getInstance()); getClient().execCypher(// w ww.j a v a 2s .c om "create (a:JUnit) set a={p}, a.javaNull={javaNull},a.nullVal={nullVal}, a.intVal={intVal},a.stringVal={stringVal} return a", "p", n, "stringVal", m.readTree("\"foo\""), "intVal", m.readTree("3"), "nullVal", NullNode.getInstance(), "javaNull", null); }
From source file:org.apache.usergrid.java.client.model.UsergridEntity.java
public void removeProperty(@NotNull final String name) { putProperty(name, NullNode.getInstance()); }