Example usage for com.fasterxml.jackson.databind.node ObjectNode put

List of usage examples for com.fasterxml.jackson.databind.node ObjectNode put

Introduction

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

Prototype

public ObjectNode put(String paramString1, String paramString2) 

Source Link

Usage

From source file:controllers.acentera.Auth.java

public static Result authenticate() {
    HibernateSessionFactory.getSession();
    try {//from  ww w.j  a va2s.  com

        Form<Login> loginForm = Form.form(Login.class).bindFromRequest();

        if (loginForm.hasErrors()) {
            ObjectNode authTokenJson = Json.newObject();
            authTokenJson.put("success", false);
            authTokenJson.put("message", "Invalid Username / Password");
            return ok(authTokenJson);
        }

        String uuid = java.util.UUID.randomUUID().toString();

        Login login = loginForm.get();

        WebUser wu = new WebUser(login.email, login.password,
                new UsernamePasswordToken(login.email, login.password));

        if (wu.authenticate()) {

            Random rand = new Random();

            // nextInt is normally exclusive of the top value,
            // so add 1 to make it inclusive
            Integer randomNum = rand.nextInt((1990300 - 10) + 1) + 10;

            Logger.debug("AUTH : " + wu);
            Logger.debug("AUTH : " + wu.getUser());
            Logger.debug("AUTH : " + wu.getUser().getEmail());
            String k = Crypto.sign(
                    wu.getUser().getEmail() + "-" + wu.getUser().getSalt() + "-" + wu.getUser().getPassword());

            //Cache.set(uuid + ".webuser", wu);
            Cache.set(uuid + ".token", wu.email());

            Logger.trace("User email is : " + wu.email());

            ObjectNode authTokenJson = Json.newObject();
            authTokenJson.put("success", true);
            authTokenJson.put("url", "/user/");

            response().setCookie(SecurityController.AUTH_TOKEN, uuid);
            response().setCookie("email", wu.email());
            response().setCookie("tokensecret", k);

            session(SecurityController.AUTH_TOKEN, uuid);
            session("email", wu.email());
            session("tokensecret", k);
            return ok(authTokenJson);
        }

        HibernateSessionFactory.rollback();

        ObjectNode authTokenJson = Json.newObject();
        authTokenJson.put("success", false);
        authTokenJson.put("message", Messages.get("INVALID_PASSWORD"));
        return ok(authTokenJson);
    } catch (Exception ew) {
        ew.printStackTrace();
        HibernateSessionFactory.rollback();

        ObjectNode authTokenJson = Json.newObject();
        authTokenJson.put("success", false);
        authTokenJson.put("message", Messages.get("INVALID_PASSWORD"));
        return ok(authTokenJson);

    } finally {
        HibernateSessionFactory.closeSession();
    }
}

From source file:controllers.Rules.java

@Security.Authenticated(Secured.class)
@BodyParser.Of(BodyParser.Json.class)
public static Promise<Result> removePart(String name, String groupID, String slotID, String partID) {
    ObjectNode slot = Json.newObject();
    slot.put("uuid", slotID);
    final ObjectNode part = Json.newObject();
    part.put("uuid", partID);
    Promise<Boolean> removed = Slot.nodes.disconnect(slot, part);
    return removed.map(new ResultFunction("Part successfully removed.", "Part not removed."));
}

From source file:controllers.Rules.java

@Security.Authenticated(Secured.class)
@BodyParser.Of(BodyParser.Json.class)
public static Promise<Result> removeRef(String name, String groupID, String slotID, String refID) {
    ObjectNode slot = Json.newObject();
    slot.put("uuid", slotID);
    ObjectNode rule = Json.newObject();/* ww  w  .j a  v  a  2 s  .co  m*/
    rule.put("name", refID);
    Promise<Boolean> removed = Slot.nodes.disconnect(slot, rule);
    return removed.map(new ResultFunction("Part successfully removed.", "Part not removed."));
}

From source file:controllers.Rules.java

@Security.Authenticated(Secured.class)
@BodyParser.Of(BodyParser.Json.class)
public static Promise<Result> removeString(String name, String groupID, String stringID) {
    ObjectNode group = Json.newObject();
    group.put("uuid", groupID);
    final ObjectNode string = Json.newObject();
    string.put("uuid", stringID);
    string.put("nodeType", "string");
    Promise<Boolean> removed = CombinationGroup.nodes.disconnect(group, string);
    return removed.map(new ResultFunction("String successfully removed.", "String not removed."));
}

From source file:controllers.Rules.java

@Security.Authenticated(Secured.class)
@BodyParser.Of(BodyParser.Json.class)
public static Promise<Result> removeSlot(String name, String groupID, String slotID) {
    ObjectNode group = Json.newObject();
    group.put("uuid", groupID);
    ObjectNode slot = Json.newObject();/* ww w .  j a va2  s.  c om*/
    slot.put("uuid", slotID);
    slot.put("nodeType", "slot");
    Promise<Boolean> removed = CombinationGroup.nodes.disconnect(group, slot);
    return removed.map(new ResultFunction("Slot successfully removed.", "Slot not removed."));
}

From source file:controllers.Rules.java

@Security.Authenticated(Secured.class)
@BodyParser.Of(BodyParser.Json.class)
public static Promise<Result> addGroup(String name) {
    final JsonNode json = request().body().asJson();
    ObjectNode rhs = Json.newObject();
    rhs.put("uuid", json.findValue("rhsID").asText());
    final ObjectNode group = Json.newObject();
    final String uuid = UUIDGenerator.random();
    group.put("uuid", uuid);
    group.put("position", json.findValue("position").asInt());
    final ObjectNode result = Json.newObject();
    result.put("id", uuid);
    Promise<Boolean> added = RHS.nodes.connect(rhs, group);
    return added.map(new ResultFunction("Group successfully added.", "Group not added.", result));
}

From source file:controllers.Rules.java

@Security.Authenticated(Secured.class)
@BodyParser.Of(BodyParser.Json.class)
public static Promise<Result> updateGroup(String name, String groupID) {
    JsonNode json = request().body().asJson();
    ObjectNode oldProps = Json.newObject();
    oldProps.put("uuid", groupID);
    ObjectNode newProps = oldProps.deepCopy();
    newProps.put("position", json.findValue("position").asInt());
    Promise<Boolean> updated = CombinationGroup.nodes.update(oldProps, newProps);
    return updated.map(new ResultFunction("Group successfully updated.", "Group not updated."));
}

From source file:controllers.Rules.java

@Security.Authenticated(Secured.class)
@BodyParser.Of(BodyParser.Json.class)
public static Promise<Result> updateSlot(String name, String groupID, String slotID) {
    JsonNode json = request().body().asJson();
    ObjectNode oldProps = Json.newObject();
    oldProps.put("uuid", slotID);
    ObjectNode newProps = oldProps.deepCopy();
    newProps.put("position", json.findValue("position").asInt());
    Promise<Boolean> updated = Slot.nodes.update(oldProps, newProps);
    return updated.map(new ResultFunction("Slot successfully updated.", "Slot not updated."));
}

From source file:controllers.Rules.java

@Security.Authenticated(Secured.class)
@BodyParser.Of(BodyParser.Json.class)
public static Promise<Result> addSlot(String name, final String groupID) {
    JsonNode json = request().body().asJson();
    ObjectNode group = Json.newObject();
    group.put("uuid", groupID);
    final ObjectNode slot = Json.newObject();
    final String uuid = UUIDGenerator.random();
    slot.put("uuid", uuid);
    slot.put("position", json.findValue("position").asInt());
    final ObjectNode result = Json.newObject();
    result.put("id", uuid);
    Promise<Boolean> added = CombinationGroup.nodes.connect(group, slot);
    return added.map(new ResultFunction("Slot successfully added.", "Slot not added", result));
}

From source file:controllers.Rules.java

@Security.Authenticated(Secured.class)
@BodyParser.Of(BodyParser.Json.class)
public static Promise<Result> addPart(String name, String groupID, String slotID) {
    JsonNode json = request().body().asJson();
    ObjectNode slot = Json.newObject();
    slot.put("uuid", slotID);
    ObjectNode part = Json.newObject();//  www.jav  a 2  s .c  om
    String content = json.findValue("content").asText();
    String uuid = UUIDGenerator.from(content);
    part.put("uuid", uuid);
    part.put("content", content);
    Promise<Boolean> connected = Slot.nodes.connect(slot, part);
    ObjectNode result = Json.newObject();
    result.put("id", uuid);
    return connected.map(new ResultFunction("Part successfully added.", "Part not added.", result));
}