Example usage for com.fasterxml.jackson.databind.node ArrayNode get

List of usage examples for com.fasterxml.jackson.databind.node ArrayNode get

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node ArrayNode get.

Prototype

public JsonNode get(String paramString) 

Source Link

Usage

From source file:org.gitana.platform.client.node.NodeImpl.java

@Override
public List<Locale> getTranslationLocales(String edition) {
    Response response = getRemote().get(getResourceUri() + "/i18n/locales?edition=" + edition);

    ArrayNode array = (ArrayNode) response.getObjectNode().get("locales");

    List<Locale> locales = new ArrayList<Locale>();
    for (int i = 0; i < array.size(); i++) {
        String localeString = array.get(i).textValue();
        Locale locale = org.gitana.util.I18NUtil.parseLocale(localeString);

        locales.add(locale);//from   w  ww  . j  a v a 2  s. c om

    }

    return locales;
}

From source file:org.wisdom.wamp.WampController.java

private void handleSubscription(String id, Map.Entry<String, WampClient> entry, ArrayNode message) {
    if (entry == null) {
        LOGGER.error("Invalid SUBSCRIBE message, cannot identify the client {}", id);
        return;//from ww  w . j a va2 s  .c  o  m
    }
    if (message.get(1) == null || message.get(1).asText().isEmpty()) {
        // The subscription does not allow error reporting, just ignore.
        LOGGER.error("Invalid SUBSCRIBE message, missing topic in {}", message);
        return;
    }
    String uri = message.get(1).asText();
    entry.getValue().subscribe(uri);
}

From source file:org.wisdom.wamp.WampController.java

private void handlePrefixMessage(String id, Map.Entry<String, WampClient> entry, ArrayNode message) {
    if (entry == null) {
        LOGGER.error("Invalid PREFIX message, cannot identify the client {}", id);
        return;/*www  . jav a  2s . c om*/
    }
    String pref = message.get(1).asText();
    String uri = message.get(2).asText();
    entry.getValue().registerPrefix(pref, uri);
}

From source file:org.wisdom.wamp.WampController.java

private void handleUnsubscription(String id, Map.Entry<String, WampClient> entry, ArrayNode message) {
    if (entry == null) {
        LOGGER.error("Invalid UNSUBSCRIBE message, cannot identify the client {}", id);
        return;/*from ww w . j  a v a  2s.  co m*/
    }
    if (message.get(1) == null || message.get(1).asText().isEmpty()) {
        // The un-subscription does not allow error reporting, just ignore.
        LOGGER.error("Invalid UNSUBSCRIBE message, missing topic in {}", message);
        return;
    }
    String uri = message.get(1).asText();
    entry.getValue().unsubscribe(uri);

    entry.getValue().unsubscribe(uri);
}

From source file:org.activiti.designer.eclipse.navigator.cloudrepo.ProcessModelContentProvider.java

public Object[] getChildren(Object parentElement) {
    if (parentElement instanceof ActivitiCloudEditorRoot) {
        if (modelsNode == null) {
            try {
                initializeRootElements();
            } catch (final ActivitiCloudEditorException e) {
                String detailMessage = null;
                if (e.getExceptionNode() != null) {
                    detailMessage = e.getExceptionNode().get("message").asText();
                } else {
                    detailMessage = e.getMessage();
                }/*from  w ww  .ja  v  a  2  s  .c o  m*/
                // creating fake entry
                ObjectMapper objectMapper = new ObjectMapper();
                modelsNode = objectMapper.createObjectNode();
                ArrayNode modelArrayNode = objectMapper.createArrayNode();
                ((ObjectNode) modelsNode).put("data", modelArrayNode);
                ObjectNode errorNode = objectMapper.createObjectNode();
                modelArrayNode.add(errorNode);
                errorNode.put("name", "Process models could not be retrieved: " + detailMessage);
            }
        }

        if (modelsNode != null) {
            ArrayNode modelArrayNode = (ArrayNode) modelsNode.get("data");
            Object[] objectArray = new Object[modelArrayNode.size()];
            for (int i = 0; i < modelArrayNode.size(); i++) {
                JsonNode modelNode = modelArrayNode.get(i);
                objectArray[i] = modelNode;
            }
            return objectArray;
        } else {
            return EMPTY_ARRAY;
        }

    } else {
        return EMPTY_ARRAY;
    }
}

From source file:org.wisdom.wamp.WampController.java

private void handleCallMessage(String id, Map.Entry<String, WampClient> entry, ArrayNode message) {
    if (entry == null) {
        LOGGER.error("Invalid CALL message, cannot identify the client {}", id);
        return;/*from   w  ww  .ja  v  a 2s.  c om*/
    }
    if (message.get(1) == null || message.get(1).asText() == null) {
        LOGGER.error("Invalid CALL message, callId not defined in the CALL message {}", message.toString());
        sendOnWebSocket(new RPCError("0", new IllegalArgumentException("callId not defined in CALL message"),
                errorPrefix).toJson(json), entry.getValue());
        return;
    }
    String callId = message.get(1).asText();

    if (message.get(2) == null || message.get(2).asText() == null) {
        LOGGER.error("Invalid CALL message, procId not defined in the CALL message {}", message.toString());
        sendOnWebSocket(new RPCError(callId, new IllegalArgumentException("procId not defined in CALL message"),
                errorPrefix).toJson(json), entry.getValue());
        return;
    }
    String procId = message.get(2).asText();

    List<JsonNode> args = new ArrayList<>();
    for (int i = 3; i < message.size(); i++) {
        args.add(message.get(i));
    }

    // Get full url from the potential compacted url (prefixed)
    String url = entry.getValue().getUri(procId);
    // Extract the service object identifier
    int index = url.indexOf("#");
    if (index == -1) {
        LOGGER.error("Invalid CALL message, malformed procId in the CALL message {}", message.toString());
        sendOnWebSocket(
                new RPCError(callId, new IllegalArgumentException("Malformed procId " + procId), errorPrefix)
                        .toJson(json),
                entry.getValue());
        return;
    }
    String regId = url.substring(0, index);
    String method = url.substring(index + 1);

    ExportedService service;
    synchronized (this) {
        service = registry.get(regId);
    }
    if (service == null) {
        LOGGER.error("Invalid CALL message, cannot find service {} from message {}", regId, message.toString());
        sendOnWebSocket(
                new RPCError(callId, new IllegalArgumentException("Service object " + regId + " not found"),
                        errorPrefix).toJson(json),
                entry.getValue());
        return;
    }
    if (method.isEmpty()) {
        LOGGER.error("Invalid CALL message, broken method name in message {}", message.toString());
        sendOnWebSocket(new RPCError(callId, new IllegalArgumentException("Malformed method name in " + procId),
                errorPrefix).toJson(json), entry.getValue());
        return;
    }

    // invocation
    handleRPCInvocation(entry.getValue(), callId, service, method, args);

}

From source file:org.modeshape.web.jcr.rest.handler.ItemHandlerImpl.java

private Object convertToJcrValues(Node node, Object value, boolean encoded) throws RepositoryException {
    if (value == NullNode.getInstance() || (value instanceof ArrayNode && ((ArrayNode) value).size() == 0)) {
        // for any null value of empty json array, return an empty array which will mean the property will be removed
        return null;
    }/*  w w  w  .jav a 2s . c  om*/
    org.modeshape.jcr.api.ValueFactory valueFactory = (org.modeshape.jcr.api.ValueFactory) node.getSession()
            .getValueFactory();
    if (value instanceof ArrayNode) {
        ArrayNode jsonValues = (ArrayNode) value;
        Value[] values = new Value[jsonValues.size()];

        for (int i = 0; i < jsonValues.size(); i++) {
            if (encoded) {
                values[i] = createBinaryValue(jsonValues.get(i).asText(), valueFactory);
            } else {
                values[i] = RestHelper.jsonValueToJCRValue(jsonValues.get(i), valueFactory);
            }
        }
        return values;
    }

    return encoded ? createBinaryValue(value.toString(), valueFactory)
            : RestHelper.jsonValueToJCRValue(value, valueFactory);
}

From source file:fr.gouv.vitam.mdbes.QueryBench.java

/**
  * { expression, $depth : exactdepth, $relativedepth : /- depth, vary : [] }, 
  * $depth and $relativedepth being optional (mutual exclusive),
  * vary being optional/*w  w w.  j  a  va2s.c  om*/
  *
  * @param command
  * @param level
  * @throws InvalidParseOperationException
  */
private void analyzeVary(final JsonNode command, int level) throws InvalidParseOperationException {
    if (command == null) {
        throw new InvalidParseOperationException("Not correctly parsed");
    }
    // check vary
    List<TypeField> fields = new ArrayList<>();
    if (command.has(VARY)) {
        final ArrayNode jvary = (ArrayNode) ((ObjectNode) command).remove(VARY);
        for (int i = 0; i < jvary.size(); i++) {
            JsonNode node = jvary.get(i);
            TypeField tf = getField(node, level);
            if (tf != null) {
                fields.add(tf);
            }
        }
    }
    levelFields.add(fields);
    levelRequests.add(command);
}

From source file:com.redhat.lightblue.metadata.parser.JSONMetadataParserTest.java

License:asdf

@Test
public void addStringToArray() {
    String value = "bar";
    ArrayNode array = new ArrayNode(factory);

    Assert.assertEquals(0, array.size());

    parser.addStringToArray(array, value);

    Assert.assertEquals(1, array.size());
    Assert.assertEquals(value, array.get(0).textValue());
}

From source file:com.redhat.lightblue.metadata.parser.JSONMetadataParserTest.java

License:asdf

@Test
public void addObjectToArray() {
    JsonNode value = new TextNode("asdf");
    ArrayNode array = new ArrayNode(factory);

    Assert.assertEquals(0, array.size());

    parser.addObjectToArray(array, value);

    Assert.assertEquals(1, array.size());
    Assert.assertEquals(value, array.get(0));
}