Search in sources :

Example 6 with ObjectNode

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

the class JsonResponseUtil method buildErrorResponseJSON.

public static ObjectNode buildErrorResponseJSON(String message) {
    ObjectNode rootNode = MAPPER.getNodeFactory().objectNode();
    rootNode.put("Result", "ERROR");
    rootNode.put("Message", message);
    return rootNode;
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode)

Example 7 with ObjectNode

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

the class OIDC method getUserinfo.

private ObjectNode getUserinfo(final PerunSession sess, final User user, Collection<String> allowedScopes, Map<String, String> properties) throws InternalErrorException, PrivilegeException, UserNotExistsException, WrongAttributeAssignmentException {
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode userinfo = mapper.createObjectNode();
    for (final String scope : allowedScopes) {
        String property = properties.get(scope);
        if (property == null || property.isEmpty()) {
            log.info("No values are mapped to scope " + scope + ". Configure them in " + CONFIG_FILE);
            continue;
        }
        try {
            JsonNode claims = mapper.readTree(property);
            if (!claims.isObject()) {
                throw new InternalErrorException("Config file " + CONFIG_FILE + " is wrongly configured. Values have to be valid JSON objects.");
            }
            claims = replaceAttrsInJsonTree(sess, user, claims);
            if (claims != null && claims.isObject()) {
                userinfo.putAll((ObjectNode) claims);
            }
        } catch (IOException e) {
            throw new InternalErrorException("Config file " + CONFIG_FILE + " is wrongly configured. Values have to be valid JSON objects.", e);
        }
    }
    return userinfo;
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) JsonNode(org.codehaus.jackson.JsonNode) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) IOException(java.io.IOException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 8 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project YCSB by brianfrankcooper.

the class MemcachedClient method toJson.

protected static String toJson(Map<String, ByteIterator> values) throws IOException {
    ObjectNode node = MAPPER.createObjectNode();
    HashMap<String, String> stringMap = StringByteIterator.getStringMap(values);
    for (Map.Entry<String, String> pair : stringMap.entrySet()) {
        node.put(pair.getKey(), pair.getValue());
    }
    JsonFactory jsonFactory = new JsonFactory();
    Writer writer = new StringWriter();
    JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(writer);
    MAPPER.writeTree(jsonGenerator, node);
    return writer.toString();
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) StringWriter(java.io.StringWriter) JsonFactory(org.codehaus.jackson.JsonFactory) JsonGenerator(org.codehaus.jackson.JsonGenerator) HashMap(java.util.HashMap) Map(java.util.Map) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 9 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project sling-org-apache-sling-testing-clients by apache.

the class SlingClientImportContentTest method testImportJson.

@Test
public void testImportJson() throws Exception {
    ObjectNode node = JsonNodeFactory.instance.objectNode();
    ObjectNode props = JsonNodeFactory.instance.objectNode();
    props.put("prop1", "val1");
    node.put("something", props);
    client.importJson(IMPORT_PATH, node);
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) Test(org.junit.Test)

Example 10 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project oxTrust by GluuFederation.

the class SchemaTypeUserSerializer method serialize.

@Override
public void serialize(User user, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
    log.info(" serialize() ");
    try {
        ObjectMapper mapper = new ObjectMapper();
        mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
        JsonNode rootNode = mapper.convertValue(user, JsonNode.class);
        Iterator<Map.Entry<String, JsonNode>> iterator = rootNode.getFields();
        while (iterator.hasNext()) {
            Map.Entry<String, JsonNode> rootNodeEntry = iterator.next();
            if (!(SchemaTypeMapping.getSchemaTypeInstance(rootNodeEntry.getKey()) instanceof UserExtensionSchema)) {
                if (rootNodeEntry.getValue() instanceof ObjectNode) {
                    if (rootNodeEntry.getKey().equalsIgnoreCase("name")) {
                        AttributeHolder attributeHolder = new AttributeHolder();
                        attributeHolder.setName(rootNodeEntry.getKey());
                        attributeHolder.setType("string");
                        attributeHolder.setDescription("Name object");
                        attributeHolder.setRequired(Boolean.FALSE);
                        List<AttributeHolder> nameAttributeHolders = new ArrayList<AttributeHolder>();
                        Iterator<Map.Entry<String, JsonNode>> nameIterator = rootNodeEntry.getValue().getFields();
                        while (nameIterator.hasNext()) {
                            Map.Entry<String, JsonNode> nameRootNodeEntry = nameIterator.next();
                            AttributeHolder nameAttributeHolder = new AttributeHolder();
                            nameAttributeHolder.setName(nameRootNodeEntry.getKey());
                            nameAttributeHolder.setType("string");
                            if (nameRootNodeEntry.getKey().equalsIgnoreCase("formatted")) {
                                nameAttributeHolder.setDescription("Formatted name on-the-fly for display. Using this in a query filter is not supported.");
                                nameAttributeHolder.setMutability("readOnly");
                            } else {
                                nameAttributeHolder.setDescription(nameRootNodeEntry.getKey());
                            }
                            if (nameRootNodeEntry.getKey().equalsIgnoreCase("givenName") || nameRootNodeEntry.getKey().equalsIgnoreCase("familyName")) {
                                nameAttributeHolder.setRequired(true);
                            } else {
                                nameAttributeHolder.setRequired(false);
                            }
                            nameAttributeHolders.add(nameAttributeHolder);
                        }
                        attributeHolder.setSubAttributes(nameAttributeHolders);
                        attributeHolders.add(attributeHolder);
                    }
                } else if (rootNodeEntry.getValue() instanceof ArrayNode) {
                    AttributeHolder arrayNodeAttributeHolder = new AttributeHolder();
                    arrayNodeAttributeHolder.setName(rootNodeEntry.getKey());
                    if (rootNodeEntry.getKey().equalsIgnoreCase("groups")) {
                        arrayNodeAttributeHolder.setDescription(rootNodeEntry.getKey() + " list; using sub-attributes in a query filter is not supported (cross-querying)");
                        arrayNodeAttributeHolder.setCaseExact(Boolean.TRUE);
                        List<String> referenceTypes = new ArrayList<String>();
                        referenceTypes.add("Group");
                        arrayNodeAttributeHolder.setReferenceTypes(referenceTypes);
                    } else {
                        arrayNodeAttributeHolder.setDescription(rootNodeEntry.getKey() + " list");
                        arrayNodeAttributeHolder.setCaseExact(Boolean.FALSE);
                    }
                    arrayNodeAttributeHolder.setRequired(Boolean.FALSE);
                    arrayNodeAttributeHolder.setMultiValued(Boolean.TRUE);
                    if (rootNodeEntry.getKey().equalsIgnoreCase("schemas")) {
                        arrayNodeAttributeHolder.setUniqueness("server");
                        arrayNodeAttributeHolder.setType("string");
                        arrayNodeAttributeHolder.setCaseExact(Boolean.TRUE);
                        arrayNodeAttributeHolder.setReturned("always");
                    } else {
                        arrayNodeAttributeHolder.setType("complex");
                    }
                    if (rootNodeEntry.getKey().equalsIgnoreCase("photos")) {
                        arrayNodeAttributeHolder.setType("reference");
                        List<String> referenceTypes = new ArrayList<String>();
                        referenceTypes.add("uri");
                        arrayNodeAttributeHolder.setReferenceTypes(referenceTypes);
                    }
                    List<AttributeHolder> arrayNodeMapAttributeHolders = new ArrayList<AttributeHolder>();
                    Iterator<JsonNode> arrayNodeIterator = rootNodeEntry.getValue().getElements();
                    while (arrayNodeIterator.hasNext()) {
                        JsonNode jsonNode = arrayNodeIterator.next();
                        Iterator<Map.Entry<String, JsonNode>> arrayNodeMapIterator = jsonNode.getFields();
                        while (arrayNodeMapIterator.hasNext()) {
                            Map.Entry<String, JsonNode> arrayNodeMapRootNodeEntry = arrayNodeMapIterator.next();
                            AttributeHolder arrayNodeMapAttributeHolder = new AttributeHolder();
                            if (rootNodeEntry.getKey().equalsIgnoreCase("groups") && arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("reference")) {
                                arrayNodeMapAttributeHolder.setName("$ref");
                            } else {
                                arrayNodeMapAttributeHolder.setName(arrayNodeMapRootNodeEntry.getKey());
                            }
                            arrayNodeMapAttributeHolder.setType("string");
                            arrayNodeMapAttributeHolder.setDescription(arrayNodeMapRootNodeEntry.getKey());
                            if (arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("value") || arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("type")) {
                                arrayNodeMapAttributeHolder.setRequired(Boolean.TRUE);
                            } else {
                                arrayNodeMapAttributeHolder.setRequired(Boolean.FALSE);
                            }
                            if (arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("valueAsImageDataURI") || arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("valueAsURI")) {
                                arrayNodeMapAttributeHolder.setMutability("readOnly");
                                arrayNodeMapAttributeHolder.setType("reference");
                                List<String> referenceTypes = new ArrayList<String>();
                                referenceTypes.add("uri");
                                arrayNodeMapAttributeHolder.setReferenceTypes(referenceTypes);
                            }
                            arrayNodeMapAttributeHolders.add(arrayNodeMapAttributeHolder);
                        }
                        arrayNodeAttributeHolder.setSubAttributes(arrayNodeMapAttributeHolders);
                        attributeHolders.add(arrayNodeAttributeHolder);
                    }
                } else {
                    AttributeHolder attributeHolder = new AttributeHolder();
                    attributeHolder.setName(rootNodeEntry.getKey());
                    if (rootNodeEntry.getValue().isBoolean()) {
                        attributeHolder.setType("boolean");
                    } else {
                        attributeHolder.setType("string");
                    }
                    attributeHolder.setDescription(rootNodeEntry.getKey());
                    if (rootNodeEntry.getKey().equalsIgnoreCase("userName") || rootNodeEntry.getKey().equalsIgnoreCase("displayName")) {
                        attributeHolder.setRequired(Boolean.TRUE);
                    } else {
                        attributeHolder.setRequired(Boolean.FALSE);
                    }
                    if (rootNodeEntry.getKey().equalsIgnoreCase("id") || rootNodeEntry.getKey().equalsIgnoreCase("userName")) {
                        attributeHolder.setUniqueness("server");
                        attributeHolder.setReturned("always");
                    }
                    if (rootNodeEntry.getKey().equalsIgnoreCase("id") || rootNodeEntry.getKey().equalsIgnoreCase("externalId") || rootNodeEntry.getKey().equalsIgnoreCase("password")) {
                        attributeHolder.setCaseExact(Boolean.TRUE);
                    }
                    if (rootNodeEntry.getKey().equalsIgnoreCase("id")) {
                        attributeHolder.setMutability("readOnly");
                    }
                    attributeHolders.add(attributeHolder);
                }
            }
        }
        UserCoreSchema userCoreSchema = (UserCoreSchema) schemaType;
        userCoreSchema.setAttributeHolders(attributeHolders);
        schemaType = userCoreSchema;
    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException("Unexpected processing error; please check the User class structure.");
    }
}
Also used : AttributeHolder(org.gluu.oxtrust.model.scim2.schema.AttributeHolder) ObjectNode(org.codehaus.jackson.node.ObjectNode) ArrayList(java.util.ArrayList) JsonNode(org.codehaus.jackson.JsonNode) IOException(java.io.IOException) IOException(java.io.IOException) UserExtensionSchema(org.gluu.oxtrust.model.scim2.schema.extension.UserExtensionSchema) Iterator(java.util.Iterator) UserCoreSchema(org.gluu.oxtrust.model.scim2.schema.core.UserCoreSchema) ArrayList(java.util.ArrayList) List(java.util.List) ArrayNode(org.codehaus.jackson.node.ArrayNode) Map(java.util.Map) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

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