Example usage for com.fasterxml.jackson.databind.node IntNode valueOf

List of usage examples for com.fasterxml.jackson.databind.node IntNode valueOf

Introduction

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

Prototype

public static IntNode valueOf(int paramInt) 

Source Link

Usage

From source file:com.baasbox.commands.ScriptsResource.java

private static JsonNode log(JsonNode command, JsonCallback callback) throws CommandException {
    JsonNode idOfTheModule = command.get(ScriptCommand.MAIN);
    JsonNode par = command.get(ScriptCommand.PARAMS);
    if (idOfTheModule == null) {
        idOfTheModule = command.get(ScriptCommand.ID);
    }/*from w w  w  .  ja  va  2 s .c o m*/
    ObjectNode message = Json.mapper().createObjectNode();
    message.put("message", par.get("message"));
    message.put("args", par.get("args"));
    message.put("script", idOfTheModule);
    message.put("date", SDF.format(new Date()));
    int publish = EventsService.publish(EventsService.StatType.SCRIPT, message);
    return IntNode.valueOf(publish);
}

From source file:com.baasbox.commands.PushResource.java

private JsonNode sendMessage(JsonNode command, JsonCallback callback) throws CommandException {
    JsonNode params = command.get(ScriptCommand.PARAMS);
    if (params == null || !params.isObject()) {
        throw new CommandParsingException(command, "missing parameters");
    }//from  w ww  .j  av a 2 s .  c  o  m

    JsonNode body = params.get("body");
    if (body == null || !body.isObject()) {
        throw new CommandParsingException(command, "missing body object parameter");
    }
    JsonNode messageNode = body.get("message");
    if (messageNode == null || !messageNode.isTextual()) {
        throw new CommandParsingException(command, "missing message text parameter");
    }
    String message = messageNode.asText();

    List<String> users = new ArrayList<>();
    JsonNode usersNode = params.get("to");
    if (usersNode == null || !usersNode.isArray()) {
        throw new CommandParsingException(command, "missing required to parameter");
    }
    ArrayNode usrAry = (ArrayNode) usersNode;
    usrAry.forEach(j -> {
        if (j == null || !j.isTextual())
            return;
        users.add(j.asText());
    });

    JsonNode profilesNode = params.get("profiles");
    List<Integer> profiles;
    if (profilesNode == null) {
        profiles = Collections.singletonList(1);
    } else if (profilesNode.isArray()) {
        ArrayNode pAry = (ArrayNode) profilesNode;
        profiles = new ArrayList<>();
        pAry.forEach((j) -> {
            if (j == null || !j.isIntegralNumber())
                return;
            profiles.add(j.asInt());
        });
    } else {
        throw new CommandParsingException(command, "wrong profiles parameter");
    }

    boolean[] errors = new boolean[users.size()];
    PushService ps = new PushService();

    try {
        ps.send(message, users, profiles, body, errors);
        Json.ObjectMapperExt mapper = Json.mapper();
        boolean someOk = false;
        boolean someFail = false;
        for (boolean error : errors) {
            if (error)
                someFail = true;
            else
                someOk = true;
        }
        if (someFail && someOk) {
            return IntNode.valueOf(1);
        } else if (someFail) {
            return IntNode.valueOf(2);
        } else {
            return IntNode.valueOf(0);
        }
    } catch (Exception e) {
        throw new CommandExecutionException(command, ExceptionUtils.getMessage(e), e);
    }
}

From source file:com.unboundid.scim2.common.messages.PatchOperation.java

/**
 * Create a new replace patch operation.
 *
 * @param path The path targeted by this patch operation.  The path
 *             must not be {@code null}.
 *             Path string examples:/* w  w  w .  java 2  s.  c om*/
 *               "{@code userName eq 'bjensen'}"
 *               "{@code userName}"
 * @param value The value(s) to replace.  The value(s) must not be {@code null}.
 *
 * @return The new replace patch operation.
 * @throws ScimException If the path is invalid.
 */
public static PatchOperation replace(final String path, final Integer value) throws ScimException {
    return replace(path, IntNode.valueOf(value));
}

From source file:com.unboundid.scim2.common.messages.PatchOperation.java

/**
 * Create a new replace patch operation.
 *
 * @param path The path targeted by this patch operation.  The path
 *             must not be {@code null}.
 * @param value The value(s) to replace.  The value(s) must not be {@code null}.
 *
 * @return The new replace patch operation.
 *///from w  w  w  .j  a  v  a 2  s  .  co m
public static PatchOperation replace(final Path path, final Integer value) {
    return replace(path, IntNode.valueOf(value));
}

From source file:com.unboundid.scim2.common.GenericScimResource.java

/**
 * Adds or replaces an Integer value in a generic SCIM resource.
 *   <p>//  w w w. ja v  a2s .c  o  m
 * For example:
 * In a GenericScimResource (gsr) representing the following resource:
 * <pre><code>
 * {
 *   "path1":7
 * }
 * </code></pre>
 *   <p>
 *   gsr.replaceValue(Path.fromString("path1"), path1value)
 *   where path1value is an Integer
 *   would change the "path1" field to the value of the path1value
 *   variable
 *   <p>
 *
 *   gsr.replaceValue(Path.fromString("path2"), path2value)
 *   where path2value is an Integer
 *   would add a field called "path2" with the value of the path2value
 *   variable
 *   <p>
 *
 *   Note that in a case where multiple paths match (for example
 *   a path with a filter), all paths that match will be affected.
 *
 * @param path the path to replace the value for.
 * @param value the new value.
 * @return returns the new generic SCIM resource (this).
 * @throws ScimException thrown if an error occurs (for example
 * if the path or value is "{@code null}" or invalid).
 */
public GenericScimResource replaceValue(final Path path, final Integer value) throws ScimException {
    return replaceValue(path, IntNode.valueOf(value));
}