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

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

Introduction

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

Prototype

public static BooleanNode getTrue() 

Source Link

Usage

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

private static JsonNode dropCollection(JsonNode command) throws CommandException {
    checkPreconditions(command, true);//from ww w  .  j  a v a2 s . 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);// w  w w .  ja  v  a 2s  .  c  o m
    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 {/* ww  w  .j  a va 2  s .  c  o  m*/
        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);//from ww w  . j a  v a 2 s  . c  o  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.DocumentsResource.java

private JsonNode grant(JsonNode command, boolean grant) throws CommandException {
    validateHasParams(command);//from   w  w  w  . j a v  a 2 s.  co m
    String coll = getCollectionName(command);
    String id = getDocumentId(command);

    try {
        try {
            String rid = DocumentService.getRidByString(id, true);
            alterGrants(command, coll, rid, true, grant);
            alterGrants(command, coll, rid, false, grant);
        } catch (Exception e) {
            BaasBoxLogger.error("error", e);
            throw e;
        }
    } catch (UserNotFoundException e) {

        throw new CommandExecutionException(command, "user not found exception");
    } catch (DocumentNotFoundException e) {
        throw new CommandExecutionException(command, "document not found exception");
    } catch (InvalidCollectionException e) {
        throw new CommandExecutionException(command, "invalid colleciton exception");
    } catch (InvalidModelException e) {
        throw new CommandExecutionException(command, "invalid model exception");
    } catch (RoleNotFoundException e) {
        throw new CommandExecutionException(command, "role not found exception");
    } catch (RidNotFoundException e) {
        throw new CommandExecutionException(command, "document " + id + " not found");
    }
    return BooleanNode.getTrue();
}

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

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

    try {//from w w  w . j  a v a2 s .  co 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 ww  w  .  j  ava 2 s .c  o  m*/
        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();
}