Example usage for com.fasterxml.jackson.databind.node BooleanNode getFalse

List of usage examples for com.fasterxml.jackson.databind.node BooleanNode getFalse

Introduction

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

Prototype

public static BooleanNode getFalse() 

Source Link

Usage

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

private static JsonNode dropCollection(JsonNode command) throws CommandException {
    checkPreconditions(command, true);/*w  ww. j  a  v a2s  .c om*/
    String coll = extractCollectionName(command);
    try {
        CollectionService.drop(coll);
        return BooleanNode.getTrue();
    } catch (InvalidCollectionException e) {
        return BooleanNode.getFalse();
    } catch (Exception e) {
        throw new CommandExecutionException(command,
                "Error dropping collection: " + ExceptionUtils.getMessage(e));
    }
}

From source file:com.github.pjungermann.config.types.json.JsonConverterTest.java

@Test
public void from_hierarchicalJsonObject_convertToConfig() {
    ObjectNode level2 = new ObjectNode(JsonNodeFactory.instance);
    level2.set("an", new TextNode("entry"));

    ObjectNode level1 = new ObjectNode(JsonNodeFactory.instance);
    level1.set("level_2", level2);
    level1.set("another", new TextNode("value"));

    ArrayNode arrayNode = new ArrayNode(JsonNodeFactory.instance);
    arrayNode.add(1);//from  ww w .  ja  v  a 2 s . c om
    arrayNode.add(2);
    arrayNode.add(3);

    ObjectNode json = new ObjectNode(JsonNodeFactory.instance);
    json.set("level_1", level1);
    json.set("boolean_true", BooleanNode.getTrue());
    json.set("boolean_false", BooleanNode.getFalse());
    json.set("number", new IntNode(123456));
    json.set("string", new TextNode("string value"));
    json.set("list", arrayNode);

    Config config = converter.from(json);

    assertEquals(true, config.get("boolean_true"));
    assertEquals(false, config.get("boolean_false"));
    assertEquals(123456, config.get("number"));
    assertEquals("string value", config.get("string"));
    assertEquals("entry", config.get("level_1.level_2.an"));
    assertEquals("value", config.get("level_1.another"));
    List list = (List) config.get("list");
    assertEquals(1, list.get(0));
    assertEquals(2, list.get(1));
    assertEquals(3, list.get(2));
}

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

private static JsonNode existsCollection(JsonNode command) throws CommandException {
    //        checkPreconditions(command,false);
    String coll = extractCollectionName(command);
    try {//from   w  w w  . jav  a 2s.  c om
        boolean res = CollectionService.exists(coll);
        return res ? BooleanNode.getTrue() : BooleanNode.getFalse();
    } catch (SqlInjectionException e) {
        throw new CommandExecutionException(command, ExceptionUtils.getMessage(e));
    } catch (InvalidCollectionException e) {
        throw new CommandExecutionException(command,
                "Invalid collection '" + coll + "':" + ExceptionUtils.getMessage(e));
    }
}

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

private static JsonNode createCollection(JsonNode command) throws CommandException {
    checkPreconditions(command, true);//w w  w  .j  a  v  a  2 s .co m
    String coll = extractCollectionName(command);
    try {
        CollectionService.create(coll);
        return BooleanNode.getTrue();
    } catch (CollectionAlreadyExistsException e) {
        return BooleanNode.getFalse();
    } catch (InvalidCollectionException e) {
        throw new CommandExecutionException(command,
                "Invalid collection name: " + ExceptionUtils.getMessage(e));
    } catch (Throwable e) {
        throw new CommandExecutionException(command,
                "Error creating collection: " + ExceptionUtils.getMessage(e));
    }
}

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

protected JsonNode suspend(JsonNode command) throws CommandException {
    String username = getUsername(command);

    try {//from  ww  w. j av  a  2s.c  o m
        boolean inTransaction = DbHelper.isInTransaction();
        if (inTransaction) {
            return BooleanNode.getFalse();
        }
        UserService.disableUser(username);
    } catch (UserNotFoundException e) {
        throw new CommandExecutionException(command, "User " + username + " does not exists");
    } catch (OpenTransactionException e) {
        return BooleanNode.getFalse();
        //throw new CommandExecutionException(command,"Transaction still open during suspend");
    }
    return BooleanNode.getTrue();
}

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

protected JsonNode reactivate(JsonNode command) throws CommandException {
    String username = getUsername(command);
    try {/*from  w w  w  . j  a  v  a  2s . c om*/
        if (DbHelper.isInTransaction())
            return BooleanNode.getFalse();
        UserService.enableUser(username);

    } catch (UserNotFoundException e) {
        throw new CommandExecutionException(command, "user " + username + " does not exists");
    } catch (OpenTransactionException e) {
        return BooleanNode.getFalse();
        //throw new CommandExecutionException(command,"transaction still open while altering user status");
    }
    return BooleanNode.getTrue();
}