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

@BodyParser.Of(BodyParser.Json.class)
private static Promise<Result> addTarget(String name, JsonNode json) {
    ObjectNode feature = Json.newObject();
    feature.put("name", name);
    feature.put("type", json.get("type").asText());
    ObjectNode target = Json.newObject();
    target.put("name", json.get("target").asText());
    Promise<Boolean> connected = Feature.nodes.connect(feature, target);
    return connected.map(new Function<Boolean, Result>() {
        ObjectNode result = Json.newObject();

        public Result apply(Boolean connected) {
            if (connected) {
                result.put("message", "Target successfully added.");
                return ok(result);
            }/*from  w w w .  j a  v a  2s  . co m*/
            result.put("message", "Target not added.");
            return badRequest(result);
        }
    });
}

From source file:com.nirmata.workflow.details.JsonSerializer.java

public static JsonNode newStartedTask(StartedTask startedTask) {
    ObjectNode node = newNode();
    node.put("instanceName", startedTask.getInstanceName());
    node.put("startDateUtc", startedTask.getStartDateUtc().format(DateTimeFormatter.ISO_DATE_TIME));
    return node;/*from  w  ww  .  ja  v  a2s  .co  m*/
}

From source file:com.nirmata.workflow.details.JsonSerializer.java

public static JsonNode newTaskType(TaskType taskType) {
    ObjectNode node = newNode();
    node.put("type", taskType.getType());
    node.put("version", taskType.getVersion());
    node.put("isIdempotent", taskType.isIdempotent());
    return node;/*  w  w  w  .jav  a2 s. c  o m*/
}

From source file:com.nirmata.workflow.details.JsonSerializer.java

public static JsonNode newExecutableTask(ExecutableTask executableTask) {
    ObjectNode node = newNode();
    node.put("runId", executableTask.getRunId().getId());
    node.put("taskId", executableTask.getTaskId().getId());
    node.set("taskType", newTaskType(executableTask.getTaskType()));
    node.putPOJO("metaData", executableTask.getMetaData());
    node.put("isExecutable", executableTask.isExecutable());
    return node;//  w w w  .  ja va  2  s .c  om
}

From source file:com.nirmata.workflow.details.JsonSerializer.java

public static JsonNode newRunnableTaskDag(RunnableTaskDag runnableTaskDag) {
    ArrayNode tab = newArrayNode();//  w  w  w  . j  a  v a2 s  .  c o  m
    runnableTaskDag.getDependencies().forEach(taskId -> tab.add(taskId.getId()));

    ObjectNode node = newNode();
    node.put("taskId", runnableTaskDag.getTaskId().getId());
    node.set("dependencies", tab);

    return node;
}

From source file:com.nirmata.workflow.details.JsonSerializer.java

public static JsonNode newTaskExecutionResult(TaskExecutionResult taskExecutionResult) {
    ObjectNode node = newNode();
    node.put("status", taskExecutionResult.getStatus().name().toLowerCase());
    node.put("message", taskExecutionResult.getMessage());
    node.putPOJO("resultData", taskExecutionResult.getResultData());
    node.put("subTaskRunId",
            taskExecutionResult.getSubTaskRunId().isPresent()
                    ? taskExecutionResult.getSubTaskRunId().get().getId()
                    : null);/*from  w w w  .j  a v  a2 s.  c  om*/
    node.put("completionTimeUtc",
            taskExecutionResult.getCompletionTimeUtc().format(DateTimeFormatter.ISO_DATE_TIME));
    return node;
}

From source file:controllers.Features.java

@Security.Authenticated(Secured.class)
@BodyParser.Of(BodyParser.Json.class)
public static Promise<Result> delete(final String name) {
    final ObjectNode props = Json.newObject();
    props.put("name", name);
    // 1. Check if feature is orphaned
    Promise<Boolean> orphaned = Feature.nodes.orphaned(props);
    Promise<Boolean> deleted = orphaned.flatMap(new Function<Boolean, Promise<Boolean>>() {
        public Promise<Boolean> apply(Boolean orphaned) {
            // 2. If it is, delete it
            if (orphaned) {
                return Feature.nodes.delete(props);
            }//  ww w . j  a v a  2  s. co m
            return Promise.pure(false);
        }
    });
    return deleted.map(new Function<Boolean, Result>() {
        ObjectNode result = Json.newObject();

        public Result apply(Boolean deleted) {
            if (deleted) {
                result.put("message", "Feature successfully deleted.");
                return ok(result);
            }
            result.put("message", "Feature not deleted.");
            return badRequest(result);
        }
    });
}

From source file:com.github.fge.jsonschema.servlets.SyntaxValidateServlet.java

private static boolean fillWithData(final ObjectNode node, final String onSuccess, final String onFailure,
        final String raw) throws IOException {
    try {//  w  ww.j  a v  a2  s .  c o m
        node.put(onSuccess, JsonLoader.fromString(raw));
        return false;
    } catch (JsonProcessingException e) {
        node.put(onFailure, buildParsingError(e, raw.contains("\r\n")));
        return true;
    }
}

From source file:controllers.Features.java

@BodyParser.Of(BodyParser.Json.class)
private static Promise<Result> removeTarget(String name, JsonNode json) {
    final ObjectNode feature = Json.newObject();
    feature.put("name", name);
    feature.put("type", json.get("type").asText());
    final ObjectNode target = Json.newObject();
    target.put("name", json.get("target").asText());
    // 1. Check if feature :HAS this target in some rule
    Promise<Boolean> hasValue = Feature.nodes.has(feature, target);
    // 2. If it doesn't, disconnect it from the target
    Promise<Boolean> disconnected = hasValue.flatMap(new Function<Boolean, Promise<Boolean>>() {
        public Promise<Boolean> apply(Boolean hasValue) {
            if (hasValue) {
                return Promise.pure(false);
            }/*  w w  w. j a v a  2s. c  o  m*/
            return Feature.nodes.disconnect(feature, target);
        }
    });
    return disconnected.map(new Function<Boolean, Result>() {
        ObjectNode result = Json.newObject();

        public Result apply(Boolean disconnected) {
            if (disconnected) {
                result.put("message", "Target successfully removed.");
                return ok(result);
            }
            result.put("message", "Target not removed.");
            return badRequest(result);
        }
    });
}

From source file:controllers.Features.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("name", "description", "type");
    Promise<Boolean> nameTaken = Feature.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 w  w  .ja va2  s . c  o m
            ObjectNode oldProps = Json.newObject();
            oldProps.put("name", name);
            return Feature.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);
        }
    });
}