Search in sources :

Example 56 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project pinot by linkedin.

the class IngraphDashboardConfigResource method viewDashboardConfigs.

@GET
@Path("/list")
@Produces(MediaType.APPLICATION_JSON)
public String viewDashboardConfigs(@DefaultValue("0") @QueryParam("jtStartIndex") int jtStartIndex, @DefaultValue("100") @QueryParam("jtPageSize") int jtPageSize) {
    List<IngraphDashboardConfigDTO> ingraphDashboardConfigDTOs = ingraphDashboardConfigDAO.findAll();
    List<IngraphDashboardConfigDTO> subList = Utils.sublist(ingraphDashboardConfigDTOs, jtStartIndex, jtPageSize);
    ObjectNode rootNode = JsonResponseUtil.buildResponseJSON(subList);
    return rootNode.toString();
}
Also used : IngraphDashboardConfigDTO(com.linkedin.thirdeye.datalayer.dto.IngraphDashboardConfigDTO) ObjectNode(org.codehaus.jackson.node.ObjectNode) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 57 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project pinot by linkedin.

the class JsonResponseUtil method buildResponseJSON.

public static ObjectNode buildResponseJSON(Object obj) {
    ObjectNode rootNode = MAPPER.getNodeFactory().objectNode();
    rootNode.put("Result", "OK");
    JsonNode node = MAPPER.convertValue(obj, JsonNode.class);
    rootNode.put("Record", node);
    return rootNode;
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) JsonNode(org.codehaus.jackson.JsonNode)

Example 58 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project pinot by linkedin.

the class JsonResponseUtil method buildResponseJSON.

public static ObjectNode buildResponseJSON(List<? extends Object> list) {
    ObjectNode rootNode = MAPPER.getNodeFactory().objectNode();
    ArrayNode resultArrayNode = MAPPER.createArrayNode();
    rootNode.put("Result", "OK");
    for (Object obj : list) {
        JsonNode node = MAPPER.convertValue(obj, JsonNode.class);
        resultArrayNode.add(node);
    }
    rootNode.put("Records", resultArrayNode);
    return rootNode;
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) JsonNode(org.codehaus.jackson.JsonNode) ArrayNode(org.codehaus.jackson.node.ArrayNode)

Example 59 with ObjectNode

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

the class AbstractRESTInteraction method getValue.

private Object getValue(JsonNode valueNode) {
    Object value;
    if (valueNode instanceof TextNode) {
        value = valueNode.asText();
    } else if (valueNode instanceof ObjectNode) {
        value = mapValue(valueNode.getFieldNames(), valueNode);
    } else if (valueNode instanceof ArrayNode) {
        ArrayNode aNode = (ArrayNode) valueNode;
        ArrayList<String> listValue = new ArrayList<>(aNode.size());
        for (int j = 0; j < aNode.size(); j++) {
            listValue.add(aNode.get(j).asText());
        }
        value = listValue;
    } else if (valueNode instanceof IntNode) {
        value = valueNode.getIntValue();
    } else if (valueNode instanceof LongNode) {
        value = valueNode.getLongValue();
    } else if (valueNode.isNull()) {
        return null;
    } else {
        throw new RuntimeException(String.format("Unhandled REST value type '%s'. Need String (TextNode), List (ArrayNode), Object (ObjectNode), long (LongNode), or int (IntNode).", valueNode.getClass()));
    }
    return value;
}
Also used : IntNode(org.codehaus.jackson.node.IntNode) ObjectNode(org.codehaus.jackson.node.ObjectNode) ArrayList(java.util.ArrayList) TextNode(org.codehaus.jackson.node.TextNode) ArrayNode(org.codehaus.jackson.node.ArrayNode) Matchers.containsString(org.hamcrest.Matchers.containsString) LongNode(org.codehaus.jackson.node.LongNode)

Example 60 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project perun by CESNET.

the class OIDC method replaceAttrsInJsonTree.

private JsonNode replaceAttrsInJsonTree(PerunSession sess, User user, JsonNode node) throws InternalErrorException, WrongAttributeAssignmentException, PrivilegeException, UserNotExistsException {
    ObjectMapper mapper = new ObjectMapper();
    if (!node.isObject()) {
        if (node.isTextual()) {
            Matcher attrMatcher = attrRegex.matcher(node.getTextValue());
            if (attrMatcher.matches()) {
                try {
                    Object value = sess.getPerun().getAttributesManager().getAttribute(sess, user, node.getTextValue()).getValue();
                    if (value != null) {
                        return mapper.convertValue(value, JsonNode.class);
                    } else {
                        log.info("Attribute " + node.getTextValue() + " is not present for user " + user);
                        return NullNode.getInstance();
                    }
                } catch (AttributeNotExistsException e) {
                    log.warn("Attribute " + node.getTextValue() + " does not exists");
                    return null;
                }
            }
        }
        return node;
    } else {
        ObjectNode object = (ObjectNode) node;
        ObjectNode userinfo = mapper.createObjectNode();
        Iterator<Map.Entry<String, JsonNode>> fieldsIterator = object.getFields();
        while (fieldsIterator.hasNext()) {
            Map.Entry<String, JsonNode> child = fieldsIterator.next();
            JsonNode result = replaceAttrsInJsonTree(sess, user, child.getValue());
            if (result != null) {
                userinfo.put(child.getKey(), result);
            }
        }
        if (userinfo.size() == 0) {
            return null;
        } else {
            return userinfo;
        }
    }
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) Matcher(java.util.regex.Matcher) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) JsonNode(org.codehaus.jackson.JsonNode) Map(java.util.Map) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

ObjectNode (org.codehaus.jackson.node.ObjectNode)97 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)29 ArrayNode (org.codehaus.jackson.node.ArrayNode)29 JsonNode (org.codehaus.jackson.JsonNode)22 GET (javax.ws.rs.GET)21 Path (javax.ws.rs.Path)18 Test (org.junit.Test)16 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)8 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