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();
}
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());
}
}
}
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);
}
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);
}
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);
}
Aggregations