Example usage for com.fasterxml.jackson.databind JsonNode asText

List of usage examples for com.fasterxml.jackson.databind JsonNode asText

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind JsonNode asText.

Prototype

public abstract String asText();

Source Link

Usage

From source file:com.tda.sitefilm.allocine.JSONAllocineAPIHelper.java

private static int getValueAsInt(JsonNode node) {
    if (node == null) {
        return -1;
    } else if (node.isNull()) {
        return -1;
    }//  w  w w. j av  a 2s  .  com
    try {
        return Integer.parseInt(node.asText());
    } catch (Exception ignore) {
        return -1;
    }
}

From source file:com.tda.sitefilm.allocine.JSONAllocineAPIHelper.java

private static float getValueAsFloat(JsonNode node) {
    if (node == null) {
        return 0f;
    } else if (node.isNull()) {
        return 0f;
    }//w  w w  .  j  a  v  a 2 s.  c  o m
    try {
        return Float.parseFloat(node.asText());
    } catch (Exception ignore) {
        return 0f;
    }
}

From source file:com.pros.jsontransform.constraint.ConstraintRange.java

public static void validate(final JsonNode constraintNode, final JsonNode resultNode,
        final ObjectTransformer transformer) throws ObjectTransformerException {
    boolean ltRangeValid = true;
    boolean gtRangeValid = true;
    JsonNode rangeNode = constraintNode.get(Constraint.$RANGE.toString());
    if (rangeNode.isObject()) {
        JsonNode ltNode = rangeNode.path("less-than");
        if (!ltNode.isMissingNode()) {
            if (resultNode.isNumber() && ltNode.isNumber()) {
                ltRangeValid = resultNode.asDouble() < ltNode.asDouble();
            } else if (resultNode.isTextual() && ltNode.isTextual()) {
                ltRangeValid = resultNode.asText().compareTo(ltNode.asText()) < 0;
            }//from   w w w.  j  a v a2s  .co  m
        }

        JsonNode gtNode = rangeNode.path("greater-than");
        if (!gtNode.isMissingNode()) {
            if (resultNode.isNumber() && gtNode.isNumber()) {
                gtRangeValid = resultNode.asDouble() > gtNode.asDouble();
            } else if (resultNode.isTextual() && gtNode.isTextual()) {
                gtRangeValid = resultNode.asText().compareTo(gtNode.asText()) > 0;
            }
        }
    }

    if (ltRangeValid == false || gtRangeValid == false) {
        throw new ObjectTransformerException("Constraint violation [" + Constraint.$RANGE.toString() + "]"
                + " on transform node " + transformer.getTransformNodeFieldName());
    }
}

From source file:com.dnw.json.J.java

/**
 * Resolves a JsonNode, returns the corresponding Java object.
 * /*from   w  ww .  j  a  v a  2s.  c om*/
 * @author manbaum
 * @since Oct 22, 2014
 * @param node the given <code>JsonNode</code>.
 * @return the corresponding Java object.
 */
public final static Object resolve(JsonNode node) {
    if (node.isNull()) {
        return null;
    } else if (node.isTextual()) {
        return node.asText();
    } else if (node.isIntegralNumber()) {
        return node.asLong();
    } else if (node.isDouble()) {
        return node.asDouble();
    } else if (node.isBoolean()) {
        return node.asBoolean();
    } else if (node.isObject()) {
        return resolveObject(node);
    } else if (node.isArray()) {
        return resolveArray(node);
    }
    return null;
}

From source file:com.helger.wsdlgen.exchange.InterfaceReader.java

@Nullable
public static WGInterface readInterface(@Nonnull final IReadableResource aRes) {
    final ObjectNode aInterfaceNode = _readAsJSON(aRes);
    if (aInterfaceNode == null)
        return null;

    final String sInterfaceName = _getChildAsText(aInterfaceNode, "$name");
    final String sInterfaceNamespace = _getChildAsText(aInterfaceNode, "$namespace");
    final String sInterfaceEndpoint = _getChildAsText(aInterfaceNode, "$endpoint");

    final WGInterface aInterface = new WGInterface(sInterfaceName, sInterfaceNamespace, sInterfaceEndpoint);
    // Dont't format global interface comment
    aInterface.setDocumentation(_getChildAsText(aInterfaceNode, "$doc"));

    // Add all types
    final ObjectNode aTypesNode = (ObjectNode) aInterfaceNode.get("$types");
    if (aTypesNode != null) {
        // Read all contained types
        for (final Map.Entry<String, JsonNode> aTypeEntry : _getAllChildren(aTypesNode).entrySet()) {
            final String sTypeName = aTypeEntry.getKey();
            final JsonNode aTypeNode = aTypeEntry.getValue();

            if (!sTypeName.startsWith("$")) {
                final boolean bIsSimpleType = sTypeName.startsWith("#");
                if (bIsSimpleType) {
                    // Simple type
                    final WGSimpleType aSimpleType = new WGSimpleType(sInterfaceNamespace,
                            sTypeName.substring(1));
                    final WGTypeDef aSimpleTypeDef = new WGTypeDef(aSimpleType);
                    for (final Map.Entry<String, JsonNode> aChildTypeEntry : _getAllChildren(aTypeNode)
                            .entrySet()) {
                        final String sTypeChildName = aChildTypeEntry.getKey();
                        final JsonNode aTypeChildNode = aChildTypeEntry.getValue();

                        if (sTypeChildName.equals("$doc"))
                            aSimpleTypeDef.setDocumentation(_getDocumentation(aTypeChildNode.asText()));
                        else if (sTypeChildName.equals("$extension")) {
                            final String sExtension = aTypeChildNode.asText();
                            final IWGType aExtensionType = aInterface.getTypeOfName(sExtension);
                            if (aExtensionType == null)
                                throw new IllegalArgumentException("Simple type '" + aSimpleType.getName()
                                        + "' has invalid extension type '" + sExtension + "'");
                            aSimpleType.setExtension(aExtensionType);
                        } else if (sTypeChildName.equals("$restriction")) {
                            final String sRestriction = aTypeChildNode.asText();
                            final IWGType aRestrictionType = aInterface.getTypeOfName(sRestriction);
                            if (aRestrictionType == null)
                                throw new IllegalArgumentException("Simple type '" + aSimpleType.getName()
                                        + "' has invalid restriction type '" + sRestriction + "'");
                            aSimpleType.setRestriction(aRestrictionType);
                        } else if (sTypeChildName.equals("$enum")) {
                            final ArrayNode aEntries = (ArrayNode) aTypeChildNode;
                            if (aEntries == null)
                                throw new IllegalArgumentException(
                                        "Simple type '" + aSimpleType.getName() + "' has invalid enum entries");

                            // Convert all to string
                            final List<WGEnumEntry> aEnumEntries = new ArrayList<WGEnumEntry>();
                            for (final JsonNode aPropValue : aEntries) {
                                if (aPropValue instanceof ArrayNode) {
                                    // [key, documentation]
                                    final ArrayNode aProvValueList = (ArrayNode) aPropValue;
                                    aEnumEntries.add(new WGEnumEntry(aProvValueList.get(0).asText(),
                                            aProvValueList.get(1).asText()));
                                } else {
                                    // Just the key, without documentation
                                    aEnumEntries.add(new WGEnumEntry(aPropValue.asText()));
                                }/* ww  w .ja  v a2 s. c  o  m*/
                            }
                            aSimpleType.setEnumEntries(aEnumEntries);
                        } else if (sTypeChildName.equals("$maxlength")) {
                            final int nMaxLength = aTypeChildNode.asInt(-1);
                            if (nMaxLength <= 0)
                                throw new IllegalArgumentException("Simple type '" + aSimpleType.getName()
                                        + "' has invalid maxLength definition '" + aTypeChildNode.asText()
                                        + "'");

                            aSimpleType.setMaxLength(nMaxLength);
                        } else if (!sTypeChildName.startsWith("$")) {
                            // Only attributes allowed!
                            if (!sTypeChildName.startsWith("@"))
                                throw new IllegalArgumentException("Simple type '" + aSimpleType.getName()
                                        + "' may only have attributes and not '" + sTypeChildName + "'");

                            final WGTypeDef aTypeDef = _readTypeDef(aInterface, sTypeChildName, aTypeChildNode);
                            aSimpleType.addChildAttribute(sTypeChildName.substring(1), aTypeDef);
                        } else
                            throw new IllegalStateException("Unhandled simple type child: " + sTypeChildName);
                    }
                    aInterface.addType(aSimpleTypeDef);
                } else {
                    // Complex type
                    final WGComplexType aComplexType = new WGComplexType(sInterfaceNamespace, sTypeName);
                    final WGTypeDef aComplexTypeDef = new WGTypeDef(aComplexType);
                    for (final Map.Entry<String, JsonNode> aChildTypeEntry : _getAllChildren(aTypeNode)
                            .entrySet()) {
                        final String sTypeChildName = aChildTypeEntry.getKey();
                        final JsonNode aTypeChildNode = aChildTypeEntry.getValue();

                        if (sTypeChildName.equals("$doc"))
                            aComplexTypeDef.setDocumentation(_getDocumentation(aTypeChildNode.asText()));
                        else if (sTypeChildName.equals("$type"))
                            aComplexType.setType(EComplexType.getFromTagNameOrThrow(aTypeChildNode.asText()));
                        else if (!sTypeChildName.startsWith("$")) {
                            final WGTypeDef aChildTypeDef = _readTypeDef(aInterface, sTypeChildName,
                                    aTypeChildNode);

                            // Attribute or element?
                            if (sTypeChildName.startsWith("@"))
                                aComplexType.addChildAttribute(sTypeChildName.substring(1), aChildTypeDef);
                            else
                                aComplexType.addChildElement(sTypeChildName, aChildTypeDef);
                        } else
                            throw new IllegalStateException("Unhandled complex type child: " + sTypeChildName);
                    }
                    aInterface.addType(aComplexTypeDef);
                }
            } else
                throw new IllegalStateException("Unhandled special type: " + sTypeName);
        }
    }

    // Add all methods
    for (final Map.Entry<String, JsonNode> aMethodEntry : _getAllChildren(aInterfaceNode).entrySet()) {
        final String sMethodName = aMethodEntry.getKey();

        if (!sMethodName.startsWith("$")) {
            final ObjectNode aMethodNode = (ObjectNode) aMethodEntry.getValue();
            final WGMethod aMethod = new WGMethod(sMethodName);

            // Input
            final JsonNode aInputNode = aMethodNode.get("$input");
            if (aInputNode != null && aInputNode.isObject()) {
                aMethod.markHavingInput();
                for (final Map.Entry<String, JsonNode> aEntry : _getAllChildren(aInputNode).entrySet()) {
                    final String sParamName = aEntry.getKey();
                    final String sParamType = aEntry.getValue().asText();
                    final IWGType aParamType = aInterface.getTypeOfName(sParamType);
                    if (aParamType == null)
                        throw new IllegalArgumentException("Input type '" + sParamType + "' of method '"
                                + sMethodName + "' for element '" + sParamName + "' not found");
                    aMethod.addInputParam(sParamName, aParamType);
                }
            }

            // Output
            final JsonNode aOutputNode = aMethodNode.get("$output");
            if (aOutputNode != null && aOutputNode.isObject()) {
                aMethod.markHavingOutput();
                for (final Map.Entry<String, JsonNode> aEntry : _getAllChildren(aOutputNode).entrySet()) {
                    final String sParamName = aEntry.getKey();
                    final String sParamType = aEntry.getValue().asText();
                    final IWGType aParamType = aInterface.getTypeOfName(sParamType);
                    if (aParamType == null)
                        throw new IllegalArgumentException("Output type '" + sParamType + "' of method '"
                                + sMethodName + "' for element '" + sParamName + "' not found");
                    aMethod.addOutputParam(sParamName, aParamType);
                }
            }

            // Fault
            final JsonNode aFaultNode = aMethodNode.get("$fault");
            if (aFaultNode != null && aFaultNode.isObject()) {
                aMethod.markHavingFault();
                for (final Map.Entry<String, JsonNode> aEntry : _getAllChildren(aFaultNode).entrySet()) {
                    final String sParamName = aEntry.getKey();
                    final String sParamType = aEntry.getValue().asText();
                    final IWGType aParamType = aInterface.getTypeOfName(sParamType);
                    if (aParamType == null)
                        throw new IllegalArgumentException("Fault type '" + sParamType + "' of method '"
                                + sMethodName + "' for element '" + sParamName + "' not found");
                    aMethod.addFaultParam(sParamName, aParamType);
                }
            }

            aInterface.addMethod(aMethod);
        }
    }

    return aInterface;
}

From source file:org.jboss.pnc.auth.keycloakutil.util.HttpUtil.java

public static String getAttrForType(String rootUrl, String realm, String auth, String resourceEndpoint,
        String attrName, String attrValue, String returnAttrName) {

    String resourceUrl = composeResourceUrl(rootUrl, realm, resourceEndpoint);
    resourceUrl = HttpUtil.addQueryParamsToUri(resourceUrl, attrName, attrValue, "first", "0", "max", "2");

    List<ObjectNode> users = doGetJSON(RoleOperations.LIST_OF_NODES.class, resourceUrl, auth);

    ObjectNode user;//from  w  ww .j  av a2 s . c  o  m
    try {
        user = new LocalSearch(users).exactMatchOne(attrValue, attrName);
    } catch (Exception e) {
        throw new RuntimeException("Multiple " + resourceEndpoint + " found for " + attrName + ": " + attrValue,
                e);
    }

    String typeName = singularize(resourceEndpoint);
    if (user == null) {
        throw new RuntimeException(capitalize(typeName) + " not found for " + attrName + ": " + attrValue);
    }

    JsonNode attr = user.get(returnAttrName);
    if (attr == null) {
        throw new RuntimeException("Returned " + typeName + " info has no '" + returnAttrName + "' attribute");
    }
    return attr.asText();
}

From source file:org.kiji.rest.representations.KijiRestEntityId.java

/**
 * Converts a JSON string, integer, or wildcard (empty array)
 * node into a Java object (String, Integer, Long, WILDCARD, or null).
 *
 * @param node JSON string, integer numeric, or wildcard (empty array) node.
 * @return the JSON value, as a String, an Integer, a Long, a WILDCARD, or null.
 * @throws JsonParseException if the JSON node is not String, Integer, Long, WILDCARD, or null.
 *//*from w  w w .  j a v  a 2 s  .c o m*/
private static Object getNodeValue(JsonNode node) throws JsonParseException {
    // TODO: Write tests to distinguish integer and long components.
    if (node.isInt()) {
        return node.asInt();
    } else if (node.isLong()) {
        return node.asLong();
    } else if (node.isTextual()) {
        return node.asText();
    } else if (node.isArray() && node.size() == 0) {
        // An empty array token indicates a wildcard.
        return WildcardSingleton.INSTANCE;
    } else if (node.isNull()) {
        return null;
    } else {
        throw new JsonParseException(String.format(
                "Invalid JSON value: '%s', expecting string, int, long, null, or wildcard [].", node), null);
    }
}

From source file:com.baasbox.controllers.Push.java

public static Result sendUsers() throws Exception {
    boolean verbose = false;
    try {//from   w  w w  . ja  v a  2 s  .c  o  m

        if (BaasBoxLogger.isTraceEnabled())
            BaasBoxLogger.trace("Method Start");
        PushLogger pushLogger = PushLogger.getInstance().init();
        if (UserService.isAnAdmin(DbHelper.currentUsername())) {
            pushLogger.enable();
        } else {
            pushLogger.disable();
        }
        if (request().getQueryString("verbose") != null
                && request().getQueryString("verbose").equalsIgnoreCase("true"))
            verbose = true;

        Http.RequestBody body = request().body();
        JsonNode bodyJson = body.asJson(); //{"message":"Text"}
        if (BaasBoxLogger.isTraceEnabled())
            BaasBoxLogger.trace("send bodyJson: " + bodyJson);
        if (bodyJson == null)
            return status(CustomHttpCode.JSON_PAYLOAD_NULL.getBbCode(),
                    CustomHttpCode.JSON_PAYLOAD_NULL.getDescription());
        pushLogger.addMessage("Payload received: %s", bodyJson.toString());
        JsonNode messageNode = bodyJson.findValue("message");
        pushLogger.addMessage("Payload message received: %s",
                messageNode == null ? "null" : messageNode.asText());
        if (messageNode == null)
            return status(CustomHttpCode.PUSH_MESSAGE_INVALID.getBbCode(),
                    CustomHttpCode.PUSH_MESSAGE_INVALID.getDescription());
        if (!messageNode.isTextual())
            return status(CustomHttpCode.PUSH_MESSAGE_INVALID.getBbCode(),
                    CustomHttpCode.PUSH_MESSAGE_INVALID.getDescription());

        String message = messageNode.asText();

        JsonNode usernamesNodes = bodyJson.get("users");
        pushLogger.addMessage("users: %s", usernamesNodes == null ? "null" : usernamesNodes.toString());

        List<String> usernames = new ArrayList<String>();

        if (!(usernamesNodes == null)) {

            if (!(usernamesNodes.isArray()))
                return status(CustomHttpCode.PUSH_USERS_FORMAT_INVALID.getBbCode(),
                        CustomHttpCode.PUSH_USERS_FORMAT_INVALID.getDescription());

            for (JsonNode usernamesNode : usernamesNodes) {
                usernames.add(usernamesNode.asText());
            }

            HashSet<String> hs = new HashSet<String>();
            hs.addAll(usernames);
            usernames.clear();
            usernames.addAll(hs);
            pushLogger.addMessage("Users extracted: %s", Joiner.on(",").join(usernames));
        } else {
            return status(CustomHttpCode.PUSH_NOTFOUND_KEY_USERS.getBbCode(),
                    CustomHttpCode.PUSH_NOTFOUND_KEY_USERS.getDescription());
        }

        JsonNode pushProfilesNodes = bodyJson.get("profiles");
        pushLogger.addMessage("profiles: %s",
                pushProfilesNodes == null ? "null" : pushProfilesNodes.toString());

        List<Integer> pushProfiles = new ArrayList<Integer>();
        if (!(pushProfilesNodes == null)) {
            if (!(pushProfilesNodes.isArray()))
                return status(CustomHttpCode.PUSH_PROFILE_FORMAT_INVALID.getBbCode(),
                        CustomHttpCode.PUSH_PROFILE_FORMAT_INVALID.getDescription());
            for (JsonNode pushProfileNode : pushProfilesNodes) {
                if (pushProfileNode.isTextual())
                    return status(CustomHttpCode.PUSH_PROFILE_FORMAT_INVALID.getBbCode(),
                            CustomHttpCode.PUSH_PROFILE_FORMAT_INVALID.getDescription());
                pushProfiles.add(pushProfileNode.asInt());
            }

            HashSet<Integer> hs = new HashSet<Integer>();
            hs.addAll(pushProfiles);
            pushProfiles.clear();
            pushProfiles.addAll(hs);
        } else {
            pushProfiles.add(1);
        }
        pushLogger.addMessage("Profiles computed: %s", Joiner.on(",").join(pushProfiles));

        boolean[] withError = new boolean[6];
        PushService ps = new PushService();
        Result toRet = null;
        try {
            boolean isValid = (ps.validate(pushProfiles));
            pushLogger.addMessage("Profiles validation: %s", isValid);
            if (isValid)
                withError = ps.send(message, usernames, pushProfiles, bodyJson, withError);
            pushLogger.addMessage("Service result: %s", Booleans.join(", ", withError));
        } catch (UserNotFoundException e) {
            return notFound("Username not found");
        } catch (SqlInjectionException e) {
            return badRequest("The supplied name appears invalid (Sql Injection Attack detected)");
        } catch (PushNotInitializedException e) {
            BaasBoxLogger.error(ExceptionUtils.getMessage(e));
            return status(CustomHttpCode.PUSH_CONFIG_INVALID.getBbCode(),
                    CustomHttpCode.PUSH_CONFIG_INVALID.getDescription());
        } catch (PushProfileDisabledException e) {
            BaasBoxLogger.error(ExceptionUtils.getMessage(e));
            return status(CustomHttpCode.PUSH_PROFILE_DISABLED.getBbCode(),
                    CustomHttpCode.PUSH_PROFILE_DISABLED.getDescription());
        } catch (PushProfileInvalidException e) {
            BaasBoxLogger.error(ExceptionUtils.getMessage(e));
            return status(CustomHttpCode.PUSH_PROFILE_FORMAT_INVALID.getBbCode(),
                    CustomHttpCode.PUSH_PROFILE_FORMAT_INVALID.getDescription());
        } catch (PushInvalidApiKeyException e) {
            BaasBoxLogger.error(ExceptionUtils.getMessage(e));
            return status(CustomHttpCode.PUSH_INVALID_APIKEY.getBbCode(),
                    CustomHttpCode.PUSH_INVALID_APIKEY.getDescription());
        } catch (UnknownHostException e) {
            BaasBoxLogger.error(ExceptionUtils.getMessage(e));
            return status(CustomHttpCode.PUSH_HOST_UNREACHABLE.getBbCode(),
                    CustomHttpCode.PUSH_HOST_UNREACHABLE.getDescription());
        } catch (InvalidRequestException e) {
            BaasBoxLogger.error(ExceptionUtils.getMessage(e));
            return status(CustomHttpCode.PUSH_INVALID_REQUEST.getBbCode(),
                    CustomHttpCode.PUSH_INVALID_REQUEST.getDescription());
        } catch (IOException e) {
            BaasBoxLogger.error(ExceptionUtils.getMessage(e));
            return badRequest(ExceptionUtils.getMessage(e));
        } catch (PushSoundKeyFormatException e) {
            BaasBoxLogger.error(ExceptionUtils.getMessage(e));
            return status(CustomHttpCode.PUSH_SOUND_FORMAT_INVALID.getBbCode(),
                    CustomHttpCode.PUSH_SOUND_FORMAT_INVALID.getDescription());
        } catch (PushBadgeFormatException e) {
            BaasBoxLogger.error(ExceptionUtils.getMessage(e));
            return status(CustomHttpCode.PUSH_BADGE_FORMAT_INVALID.getBbCode(),
                    CustomHttpCode.PUSH_BADGE_FORMAT_INVALID.getDescription());
        } catch (PushActionLocalizedKeyFormatException e) {
            BaasBoxLogger.error(ExceptionUtils.getMessage(e));
            return status(CustomHttpCode.PUSH_ACTION_LOCALIZED_KEY_FORMAT_INVALID.getBbCode(),
                    CustomHttpCode.PUSH_ACTION_LOCALIZED_KEY_FORMAT_INVALID.getDescription());
        } catch (PushLocalizedKeyFormatException e) {
            BaasBoxLogger.error(ExceptionUtils.getMessage(e));
            return status(CustomHttpCode.PUSH_LOCALIZED_KEY_FORMAT_INVALID.getBbCode(),
                    CustomHttpCode.PUSH_LOCALIZED_ARGUMENTS_FORMAT_INVALID.getDescription());
        } catch (PushLocalizedArgumentsFormatException e) {
            BaasBoxLogger.error(ExceptionUtils.getMessage(e));
            return status(CustomHttpCode.PUSH_LOCALIZED_ARGUMENTS_FORMAT_INVALID.getBbCode(),
                    CustomHttpCode.PUSH_LOCALIZED_ARGUMENTS_FORMAT_INVALID.getDescription());
        } catch (PushCollapseKeyFormatException e) {
            BaasBoxLogger.error(ExceptionUtils.getMessage(e));
            return status(CustomHttpCode.PUSH_COLLAPSE_KEY_FORMAT_INVALID.getBbCode(),
                    CustomHttpCode.PUSH_COLLAPSE_KEY_FORMAT_INVALID.getDescription());
        } catch (PushTimeToLiveFormatException e) {
            BaasBoxLogger.error(ExceptionUtils.getMessage(e));
            return status(CustomHttpCode.PUSH_TIME_TO_LIVE_FORMAT_INVALID.getBbCode(),
                    CustomHttpCode.PUSH_TIME_TO_LIVE_FORMAT_INVALID.getDescription());
        } catch (PushContentAvailableFormatException e) {
            BaasBoxLogger.error(ExceptionUtils.getMessage(e));
            return status(CustomHttpCode.PUSH_CONTENT_AVAILABLE_FORMAT_INVALID.getBbCode(),
                    CustomHttpCode.PUSH_CONTENT_AVAILABLE_FORMAT_INVALID.getDescription());
        } catch (PushCategoryFormatException e) {
            BaasBoxLogger.error(ExceptionUtils.getMessage(e));
            return status(CustomHttpCode.PUSH_CATEGORY_FORMAT_INVALID.getBbCode(),
                    CustomHttpCode.PUSH_CATEGORY_FORMAT_INVALID.getDescription());
        }
        if (BaasBoxLogger.isTraceEnabled())
            BaasBoxLogger.trace("Method End");

        for (int i = 0; i < withError.length; i++) {
            if (withError[i] == true)
                return status(CustomHttpCode.PUSH_SENT_WITH_ERROR.getBbCode(),
                        CustomHttpCode.PUSH_SENT_WITH_ERROR.getDescription());
        }
        PushLogger.getInstance().messages();
        if (UserService.isAnAdmin(DbHelper.currentUsername()) && verbose) {
            return ok(toJson(PushLogger.getInstance().messages()));
        } else {
            return ok("Push Notification(s) has been sent");
        }
    } finally {
        if (UserService.isAnAdmin(DbHelper.currentUsername()) && verbose) {
            return ok(toJson(PushLogger.getInstance().messages()));
        }
        BaasBoxLogger.debug("Push execution flow:\n{}", PushLogger.getInstance().toString());
    }
}

From source file:org.opendaylight.ovsdb.lib.schema.BaseType.java

public static BaseType fromJson(JsonNode json, String keyorval) {
    BaseType baseType = null;//from w w  w . jav  a  2s. c om
    if (json.isValueNode()) {
        for (BaseType baseTypeFactory : types) {
            String type = json.asText().trim();
            baseType = baseTypeFactory.fromString(type);
            if (baseType != null) {
                break;
            }
        }
    } else {
        if (!json.has(keyorval)) {
            throw new TyperException("Not a type");
        }

        for (BaseType baseTypeFactory : types) {
            baseType = baseTypeFactory.fromJsonNode(json.get(keyorval), keyorval);
            if (baseType != null) {
                break;
            }
        }
    }
    return baseType;
}

From source file:com.baasbox.service.push.providers.APNServer.java

public static boolean validatePushPayload(JsonNode bodyJson) throws BaasBoxPushException {
    JsonNode soundNode = bodyJson.findValue("sound");

    JsonNode contentAvailableNode = bodyJson.findValue("content-available");
    Integer contentAvailable = null;
    if (!(contentAvailableNode == null)) {
        if (!(contentAvailableNode.isInt()))
            throw new PushContentAvailableFormatException(
                    "Content-available MUST be an Integer (1 for silent notification)");
        contentAvailable = contentAvailableNode.asInt();
    }//from   w  w  w.  j  a  v a  2s . com

    if (contentAvailable != null && contentAvailable != 1) {

        JsonNode categoryNode = bodyJson.findValue("category");
        String category = null;
        if (!(categoryNode == null)) {
            if (!(categoryNode.isTextual()))
                throw new PushCategoryFormatException("Category MUST be a String");
            category = categoryNode.asText();
        }

        String sound = null;
        if (!(soundNode == null)) {
            if (!(soundNode.isTextual()))
                throw new PushSoundKeyFormatException("Sound value MUST be a String");
            sound = soundNode.asText();
        }

        JsonNode actionLocKeyNode = bodyJson.findValue("actionLocalizedKey");
        String actionLocKey = null;

        if (!(actionLocKeyNode == null)) {
            if (!(actionLocKeyNode.isTextual()))
                throw new PushActionLocalizedKeyFormatException("ActionLocalizedKey MUST be a String");
            actionLocKey = actionLocKeyNode.asText();
        }

        JsonNode locKeyNode = bodyJson.findValue("localizedKey");
        String locKey = null;

        if (!(locKeyNode == null)) {
            if (!(locKeyNode.isTextual()))
                throw new PushLocalizedKeyFormatException("LocalizedKey MUST be a String");
            locKey = locKeyNode.asText();
        }

        JsonNode locArgsNode = bodyJson.get("localizedArguments");

        List<String> locArgs = new ArrayList<String>();
        if (!(locArgsNode == null)) {
            if (!(locArgsNode.isArray()))
                throw new PushLocalizedArgumentsFormatException(
                        "LocalizedArguments MUST be an Array of String");
            for (JsonNode locArgNode : locArgsNode) {
                if (!locArgNode.isTextual())
                    throw new PushLocalizedArgumentsFormatException(
                            "LocalizedArguments MUST be an Array of String");
                locArgs.add(locArgNode.toString());
            }
        }

        JsonNode customDataNodes = bodyJson.get("custom");

        Map<String, JsonNode> customData = new HashMap<String, JsonNode>();

        if (!(customDataNodes == null)) {
            if (customDataNodes.isTextual()) {
                customData.put("custom", customDataNodes);
            } else {
                for (JsonNode customDataNode : customDataNodes) {
                    customData.put("custom", customDataNodes);
                }
            }
        }

        JsonNode badgeNode = bodyJson.findValue("badge");
        int badge = 0;
        if (!(badgeNode == null)) {
            if (!(badgeNode.isNumber()))
                throw new PushBadgeFormatException("Badge value MUST be a number");
            else
                badge = badgeNode.asInt();
        }
    }
    return true;
}