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.Rules.java

@Security.Authenticated(Secured.class)
@BodyParser.Of(BodyParser.Json.class)
public static Promise<Result> updateFeatureValue(String name) {
    JsonNode json = request().body().asJson();
    ObjectNode avm = (ObjectNode) json.deepCopy();
    avm.retain("ruleUUID", "uuid");
    ObjectNode feature = Json.newObject();
    feature.put("name", json.findValue("name").asText());
    ObjectNode value = Json.newObject();
    value.put("name", json.findValue("value").asText());
    ObjectNode newValue = Json.newObject();
    newValue.put("name", json.findValue("newValue"));
    Promise<Boolean> updated = Substructure.nodes.setValue(avm, feature, value, newValue);
    return updated.map(new Function<Boolean, Result>() {
        ObjectNode result = Json.newObject();

        public Result apply(Boolean updated) {
            if (updated) {
                result.put("message", "Feature successfully updated.");
                return ok(result);
            }//ww  w .  j  a va 2s .c o  m
            result.put("message", "Feature not updated.");
            return badRequest(result);
        }
    });
}

From source file:controllers.Rules.java

@Security.Authenticated(Secured.class)
@BodyParser.Of(BodyParser.Json.class)
public static Promise<Result> rhs(String name) {
    ObjectNode properties = Json.newObject();
    properties.put("name", name);
    Promise<Rule> rule = Rule.nodes.get(properties);
    Promise<JsonNode> rhsJSON = rule.flatMap(new Function<Rule, Promise<JsonNode>>() {
        public Promise<JsonNode> apply(Rule rule) {
            ObjectNode properties = Json.newObject();
            String uuid = UUIDGenerator.from(rule.uuid);
            properties.put("uuid", uuid);
            Promise<RHS> rhs = RHS.nodes.get(properties);
            return rhs.map(new Function<RHS, JsonNode>() {
                public JsonNode apply(RHS rhs) {
                    return rhs.json;
                }//from w ww .  j  a  va  2 s . c  om
            });
        }
    });
    return rhsJSON.map(new Function<JsonNode, Result>() {
        public Result apply(JsonNode rhsJSON) {
            ObjectNode result = Json.newObject();
            result.put("json", rhsJSON);
            return ok(result);
        }
    });
}

From source file:controllers.Rules.java

@Security.Authenticated(Secured.class)
public static Promise<Result> input(final String name) {
    Promise<List<Feature>> globalFeatureList = Feature.nodes.all();
    ObjectNode properties = Json.newObject();
    properties.put("name", name);
    Promise<Rule> rule = Rule.nodes.get(properties);
    rule = rule.flatMap(new Function<Rule, Promise<Rule>>() {
        public Promise<Rule> apply(final Rule rule) {
            ObjectNode properties = Json.newObject();
            String uuid = UUIDGenerator.from(rule.uuid);
            properties.put("uuid", uuid);
            properties.put("ruleUUID", rule.uuid);
            Promise<LHS> lhs = LHS.nodes.get(properties);
            return lhs.map(new Function<LHS, Rule>() {
                public Rule apply(LHS lhs) {
                    rule.lhs = lhs;//ww  w .  j  ava2 s  .com
                    return rule;
                }
            });
        }
    });
    Promise<Tuple<List<Feature>, Rule>> results = globalFeatureList.zip(rule);
    return results.map(new Function<Tuple<List<Feature>, Rule>, Result>() {
        public Result apply(Tuple<List<Feature>, Rule> results) {
            return ok(input.render(results._1, results._2));
        }
    });
}

From source file:controllers.Rules.java

@Security.Authenticated(Secured.class)
@BodyParser.Of(BodyParser.Json.class)
public static Promise<Result> lhs(String name) {
    ObjectNode properties = Json.newObject();
    properties.put("name", name);
    Promise<Rule> rule = Rule.nodes.get(properties);
    Promise<JsonNode> lhsJSON = rule.flatMap(new Function<Rule, Promise<JsonNode>>() {
        public Promise<JsonNode> apply(Rule rule) {
            ObjectNode properties = Json.newObject();
            String uuid = UUIDGenerator.from(rule.uuid);
            properties.put("uuid", uuid);
            properties.put("ruleUUID", rule.uuid);
            Promise<LHS> lhs = LHS.nodes.get(properties);
            return lhs.map(new Function<LHS, JsonNode>() {
                public JsonNode apply(LHS lhs) {
                    return lhs.json;
                }/* w w w  . jav a 2 s  . c om*/
            });
        }
    });
    return lhsJSON.map(new Function<JsonNode, Result>() {
        public Result apply(JsonNode lhsJSON) {
            ObjectNode result = Json.newObject();
            result.put("json", lhsJSON);
            return ok(result);
        }
    });
}

From source file:controllers.Rules.java

@Security.Authenticated(Secured.class)
@BodyParser.Of(BodyParser.Json.class)
public static Promise<Result> delete(final String name) {
    final ObjectNode rule = Json.newObject();
    rule.put("name", name);
    // 1. Check if rule is orphaned
    Promise<Boolean> orphaned = Rule.nodes.orphaned(rule);
    // 2. If it is, delete it
    Promise<Boolean> deleted = orphaned.flatMap(new Function<Boolean, Promise<Boolean>>() {
        public Promise<Boolean> apply(Boolean orphaned) {
            if (orphaned) {
                Promise<Rule> r = Rule.nodes.get(rule);
                Promise<Boolean> deleted = r.flatMap(new Function<Rule, Promise<Boolean>>() {
                    public Promise<Boolean> apply(Rule r) {
                        rule.put("uuid", r.uuid);
                        return Rule.nodes.delete(rule);
                    }//from   w w  w .  ja  v  a 2 s .c  o  m
                });
                return deleted;
            }
            return Promise.pure(false);
        }
    });
    return deleted.map(new Function<Boolean, Result>() {
        ObjectNode result = Json.newObject();

        public Result apply(Boolean deleted) {
            if (deleted) {
                return ok(result);
            }
            return badRequest(result);
        }
    });
}

From source file:controllers.Rules.java

@Security.Authenticated(Secured.class)
@BodyParser.Of(BodyParser.Json.class)
public static Promise<Result> updateName(final String name) {
    final ObjectNode newProps = (ObjectNode) request().body().asJson();
    newProps.retain("uuid", "name", "description");
    Promise<Boolean> nameTaken = Rule.nodes.exists(newProps);
    Promise<Boolean> updated = nameTaken.flatMap(new Function<Boolean, Promise<Boolean>>() {
        public Promise<Boolean> apply(Boolean nameTaken) {
            if (nameTaken) {
                return Promise.pure(false);
            }// w ww .  j  a  v  a2s.  c  o m
            ObjectNode oldProps = Json.newObject();
            oldProps.put("name", name);
            return Rule.nodes.update(oldProps, newProps);
        }
    });
    return updated.map(new Function<Boolean, Result>() {
        ObjectNode result = Json.newObject();

        public Result apply(Boolean updated) {
            if (updated) {
                result.put("id", newProps.get("name").asText());
                result.put("message", "Name successfully updated.");
                return ok(result);
            }
            result.put("message", "Name not updated.");
            return badRequest(result);
        }
    });
}

From source file:dao.DashboardDAO.java

public static ObjectNode getOwnershipBarChartData(String managerId) {

    List<DashboardBarData> barDataList = getDashboardBarData(managerId, GET_CONFIRMED_DATASET_BAR_CHART_DATA);

    ObjectNode resultNode = Json.newObject();
    resultNode.put("status", "ok");
    resultNode.set("barData", Json.toJson(barDataList));
    return resultNode;
}

From source file:controllers.Rules.java

@Security.Authenticated(Secured.class)
@BodyParser.Of(BodyParser.Json.class)
public static Promise<Result> addFeature(String name) {
    JsonNode json = request().body().asJson();
    final ObjectNode avm = (ObjectNode) json.deepCopy();
    avm.retain("ruleUUID", "uuid");
    final ObjectNode feature = Json.newObject();
    feature.put("name", json.findValue("name").asText());
    feature.put("type", json.findValue("type").asText());
    Promise<Boolean> added = Substructure.nodes.connect(avm, feature);
    Promise<Feature> feat = Feature.nodes.get(feature);
    return added.zip(feat).map(new Function<Tuple<Boolean, Feature>, Result>() {
        ObjectNode result = Json.newObject();

        public Result apply(Tuple<Boolean, Feature> t) {
            Boolean added = t._1;
            if (added) {
                Feature feat = t._2;//from w  ww .  j  a  v a 2 s . c om
                if (feat.isComplex()) {
                    String parentUUID = avm.get("uuid").asText();
                    String featureUUID = feat.getUUID();
                    String uuid = UUIDGenerator.from(parentUUID + featureUUID);
                    ObjectNode value = Json.newObject();
                    value.put("uuid", uuid);
                    value.putArray("pairs");
                    result.put("value", value);
                } else {
                    result.put("value", new TextNode("underspecified"));
                }
                result.put("message", "Feature successfully added.");
                return ok(result);
            }
            result.put("message", "Feature not added.");
            return badRequest(result);
        }
    });
}

From source file:dao.DashboardDAO.java

public static ObjectNode getDescriptionBarChartData(String managerId, int option) {
    String query;//from   www  . j av  a2s . c  om
    switch (option) {
    case 1:
        query = GET_COMMENTS_DESCRIPTION_BAR_CHART_DATA;
        break;
    case 2:
        query = GET_FIELD_COMMENTS_DESCRIPTION_BAR_CHART_DATA;
        break;
    default:
        query = GET_COMMENTS_DESCRIPTION_BAR_CHART_DATA;
    }

    List<DashboardBarData> barDataList = getDashboardBarData(managerId, query);

    ObjectNode resultNode = Json.newObject();
    resultNode.put("status", "ok");
    resultNode.set("barData", Json.toJson(barDataList));
    return resultNode;
}

From source file:org.wrml.runtime.format.application.vnd.wrml.design.schema.SchemaDesignFormatter.java

private static ObjectNode buildSyntaxNode(final ObjectMapper objectMapper, final Type heapValueType,
        final SyntaxLoader syntaxLoader) {

    if (!String.class.equals(heapValueType) && heapValueType instanceof Class<?>) {

        // TODO: Make it easy/possible to get the Syntax Document's title and uri

        final Class<?> heapValueClass = (Class<?>) heapValueType;
        final URI syntaxUri = syntaxLoader.getSyntaxUri(heapValueClass);
        final String syntaxName = heapValueClass.getSimpleName();
        final ObjectNode syntaxNode = objectMapper.createObjectNode();

        syntaxNode.put(PropertyName.title.name(), syntaxName);
        syntaxNode.put(PropertyName.uri.name(), syntaxUri.toString());
        return syntaxNode;
    }/*from   w  w  w  . j a  va2  s.  co  m*/
    return null;
}