use of org.codehaus.jackson.node.ObjectNode in project gravel by gravel-st.
the class StringExtensions method parseAsJSONValue.
public static Map<String, Object> parseAsJSONValue(String src) {
ObjectMapper mapper = new ObjectMapper();
ObjectNode rootNode;
try {
rootNode = (ObjectNode) mapper.readValue(src, JsonNode.class);
} catch (JsonParseException e) {
throw new RuntimeException(e);
} catch (JsonMappingException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
HashMap<String, Object> map = new HashMap<String, Object>();
for (Iterator<Entry<String, JsonNode>> iter = rootNode.getFields(); iter.hasNext(); ) {
Entry<String, JsonNode> field = iter.next();
JsonNode value = field.getValue();
Object o = jsonNodeAsSimpleObject(value);
map.put(field.getKey(), o);
}
return map;
}
use of org.codehaus.jackson.node.ObjectNode in project webofneeds by researchstudio-sat.
the class WonWebSocketHandler method notifyPerPush.
private void notifyPerPush(final User user, final URI atomUri, final WonMessage wonMessage, URI connectionUri) {
if (wonMessage.getFocalMessage().getMessageType().isResponseMessage()) {
// we assume that this message, coming from the server here, can only be an
// echoed message. don't send by email.
logger.debug("not sending notification to user: message {} looks like an echo from the server", wonMessage.getMessageURI());
return;
}
if (user == null) {
logger.info("not sending notification to user: user not specified");
return;
}
UserAtom userAtom = getAtomOfUser(user, atomUri);
if (userAtom == null) {
logger.debug("not sending notification to user: atom uri not specified");
return;
}
String textMsg = WonRdfUtils.MessageUtils.getTextMessage(wonMessage);
String iconUrl = uriService.getOwnerProtocolOwnerURI().toString() + "/skin/current/images/logo.png";
switch(wonMessage.getMessageType()) {
case CONNECTION_MESSAGE:
if (userAtom.isConversations()) {
ObjectMapper mapper = new ObjectMapper();
ObjectNode rootNode = mapper.createObjectNode();
rootNode.put("type", "MESSAGE");
rootNode.put("atomUri", userAtom.getUri().toString());
rootNode.put("connectionUri", connectionUri.toString());
rootNode.put("icon", iconUrl);
if (textMsg != null) {
rootNode.put("message", StringUtils.abbreviate(textMsg, 50));
}
String stringifiedJson;
try {
stringifiedJson = mapper.writer().writeValueAsString(rootNode);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
pushSender.sendNotification(user, stringifiedJson);
}
return;
case SOCKET_HINT_MESSAGE:
if (userAtom.isMatches()) {
if (!isConnectionInSuggestedState(connectionUri)) {
// found the connection previously and we don't want to notify them
return;
}
ObjectMapper mapper = new ObjectMapper();
ObjectNode rootNode = mapper.createObjectNode();
rootNode.put("type", "HINT");
rootNode.put("atomUri", userAtom.getUri().toString());
rootNode.put("connectionUri", connectionUri.toString());
rootNode.put("icon", iconUrl);
String stringifiedJson;
try {
stringifiedJson = mapper.writer().writeValueAsString(rootNode);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
pushSender.sendNotification(user, stringifiedJson);
}
return;
case CONNECT:
if (userAtom.isRequests()) {
ObjectMapper mapper = new ObjectMapper();
ObjectNode rootNode = mapper.createObjectNode();
rootNode.put("type", "CONNECT");
rootNode.put("atomUri", userAtom.getUri().toString());
rootNode.put("connectionUri", connectionUri.toString());
rootNode.put("icon", iconUrl);
if (textMsg != null) {
rootNode.put("message", StringUtils.abbreviate(textMsg, 50));
}
String stringifiedJson;
try {
stringifiedJson = mapper.writer().writeValueAsString(rootNode);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
pushSender.sendNotification(user, stringifiedJson);
}
return;
default:
return;
}
}
Aggregations