Search in sources :

Example 16 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project motech by motech.

the class SendEmailControllerTest method convertMailToJson.

private byte[] convertMailToJson() {
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode json = mapper.createObjectNode();
    json.put(FROM_ADDRESS, mail.getFromAddress());
    json.put(TO_ADDRESS, mail.getToAddress());
    json.put(SUBJECT, mail.getSubject());
    json.put(MESSAGE, mail.getMessage());
    return json.toString().getBytes();
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 17 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project motech by motech.

the class TaskServiceImpl method removeIgnoredFields.

private void removeIgnoredFields(JsonNode node) {
    if (null == node || node.isValueNode()) {
        return;
    }
    if (node.isObject()) {
        ObjectNode obj = (ObjectNode) node;
        obj.remove(IGNORED_FIELDS);
    }
    if (node.isArray()) {
        ArrayNode array = (ArrayNode) node;
        for (JsonNode item : array) {
            removeIgnoredFields(item);
        }
    }
    Iterator<Map.Entry<String, JsonNode>> elements = node.getFields();
    while (elements.hasNext()) {
        Map.Entry<String, JsonNode> entry = elements.next();
        if (!"values".equals(entry.getKey())) {
            removeIgnoredFields(entry.getValue());
        }
    }
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) JsonNode(org.codehaus.jackson.JsonNode) ArrayNode(org.codehaus.jackson.node.ArrayNode) Map(java.util.Map) HashMap(java.util.HashMap)

Example 18 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project helix by apache.

the class WorkflowAccessor method getWorkflowContext.

@GET
@Path("{workflowId}/context")
public Response getWorkflowContext(@PathParam("clusterId") String clusterId, @PathParam("workflowId") String workflowId) {
    TaskDriver taskDriver = getTaskDriver(clusterId);
    WorkflowContext workflowContext = taskDriver.getWorkflowContext(workflowId);
    ObjectNode workflowContextNode = JsonNodeFactory.instance.objectNode();
    if (workflowContext != null) {
        getWorkflowContextNode(workflowContextNode, workflowContext.getRecord());
    }
    return JSONRepresentation(workflowContextNode);
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) TaskDriver(org.apache.helix.task.TaskDriver) WorkflowContext(org.apache.helix.task.WorkflowContext) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 19 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project helix by apache.

the class InstanceAccessor method getHealthReportsOnInstance.

@GET
@Path("{instanceName}/healthreports")
public Response getHealthReportsOnInstance(@PathParam("clusterId") String clusterId, @PathParam("instanceName") String instanceName) throws IOException {
    HelixDataAccessor accessor = getDataAccssor(clusterId);
    ObjectNode root = JsonNodeFactory.instance.objectNode();
    root.put(Properties.id.name(), instanceName);
    ArrayNode healthReportsNode = root.putArray(InstanceProperties.healthreports.name());
    List<String> healthReports = accessor.getChildNames(accessor.keyBuilder().healthReports(instanceName));
    if (healthReports != null && healthReports.size() > 0) {
        healthReportsNode.addAll((ArrayNode) OBJECT_MAPPER.valueToTree(healthReports));
    }
    return JSONRepresentation(root);
}
Also used : HelixDataAccessor(org.apache.helix.HelixDataAccessor) ObjectNode(org.codehaus.jackson.node.ObjectNode) ArrayNode(org.codehaus.jackson.node.ArrayNode) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 20 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project helix by apache.

the class InstanceAccessor method getResourcesOnInstance.

@GET
@Path("{instanceName}/resources")
public Response getResourcesOnInstance(@PathParam("clusterId") String clusterId, @PathParam("instanceName") String instanceName) throws IOException {
    HelixDataAccessor accessor = getDataAccssor(clusterId);
    ObjectNode root = JsonNodeFactory.instance.objectNode();
    root.put(Properties.id.name(), instanceName);
    ArrayNode resourcesNode = root.putArray(InstanceProperties.resources.name());
    List<String> sessionIds = accessor.getChildNames(accessor.keyBuilder().sessions(instanceName));
    if (sessionIds == null || sessionIds.size() == 0) {
        return null;
    }
    // Only get resource list from current session id
    String currentSessionId = sessionIds.get(0);
    List<String> resources = accessor.getChildNames(accessor.keyBuilder().currentStates(instanceName, currentSessionId));
    if (resources != null && resources.size() > 0) {
        resourcesNode.addAll((ArrayNode) OBJECT_MAPPER.valueToTree(resources));
    }
    return JSONRepresentation(root);
}
Also used : HelixDataAccessor(org.apache.helix.HelixDataAccessor) ObjectNode(org.codehaus.jackson.node.ObjectNode) ArrayNode(org.codehaus.jackson.node.ArrayNode) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

ObjectNode (org.codehaus.jackson.node.ObjectNode)97 ArrayNode (org.codehaus.jackson.node.ArrayNode)29 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)28 JsonNode (org.codehaus.jackson.JsonNode)22 GET (javax.ws.rs.GET)21 Path (javax.ws.rs.Path)18 Test (org.junit.Test)17 Produces (javax.ws.rs.Produces)12 Map (java.util.Map)11 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)9 IOException (java.io.IOException)7 StringWriter (java.io.StringWriter)5 JsonFactory (org.codehaus.jackson.JsonFactory)5 HelixDataAccessor (org.apache.helix.HelixDataAccessor)4 Span (org.apache.stanbol.enhancer.nlp.model.Span)4 DatasetImpl (org.eol.globi.service.DatasetImpl)4 Date (java.util.Date)3 TaskDriver (org.apache.helix.task.TaskDriver)3 WorkflowConfig (org.apache.helix.task.WorkflowConfig)3