Search in sources :

Example 96 with ObjectNode

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;
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) HashMap(java.util.HashMap) JsonNode(org.codehaus.jackson.JsonNode) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) Entry(java.util.Map.Entry) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 97 with ObjectNode

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;
    }
}
Also used : UserAtom(won.owner.model.UserAtom) ObjectNode(org.codehaus.jackson.node.ObjectNode) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

ObjectNode (org.codehaus.jackson.node.ObjectNode)97 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)29 ArrayNode (org.codehaus.jackson.node.ArrayNode)29 JsonNode (org.codehaus.jackson.JsonNode)22 GET (javax.ws.rs.GET)21 Path (javax.ws.rs.Path)18 Test (org.junit.Test)16 Produces (javax.ws.rs.Produces)12 Map (java.util.Map)11 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)9 IOException (java.io.IOException)8 StringWriter (java.io.StringWriter)5 JsonFactory (org.codehaus.jackson.JsonFactory)5 HelixDataAccessor (org.apache.helix.HelixDataAccessor)4 Span (org.apache.stanbol.enhancer.nlp.model.Span)4 DatasetImpl (org.eol.globi.service.DatasetImpl)4 Date (java.util.Date)3 TaskDriver (org.apache.helix.task.TaskDriver)3 WorkflowConfig (org.apache.helix.task.WorkflowConfig)3