Example usage for io.vertx.core.json JsonObject getMap

List of usage examples for io.vertx.core.json JsonObject getMap

Introduction

In this page you can find the example usage for io.vertx.core.json JsonObject getMap.

Prototype

public Map<String, Object> getMap() 

Source Link

Document

Get the underlying Map as is.

Usage

From source file:io.knotx.util.JsonObjectUtil.java

License:Apache License

private static boolean isKeyAJsonObject(JsonObject object, String key) {
    return object.getMap().get(key) instanceof JsonObject;
}

From source file:io.mewbase.bson.BsonObject.java

License:Open Source License

/**
 * Create an instance from a JsonObject//from  ww w.  j a  va 2  s .co  m
 *
 * @param jsonObject the JsonObject to create the BsonObject from
 */
public BsonObject(JsonObject jsonObject) {
    this.map = jsonObject.getMap();
}

From source file:io.rhiot.kafka.bridge.JsonMessageConverter.java

License:Apache License

@Override
public Message toAmqpMessage(String amqpAddress, ConsumerRecord<String, byte[]> record) {

    Message message = Proton.message();//  www .j  ava 2s  .c  o  m
    message.setAddress(amqpAddress);

    // get the root JSON
    JsonObject json = new JsonObject(new String(record.value()));

    // get AMQP properties from the JSON
    JsonObject jsonProperties = json.getJsonObject(JsonMessageConverter.PROPERTIES);
    if (jsonProperties != null) {

        for (Entry<String, Object> entry : jsonProperties) {

            if (entry.getValue() != null) {

                if (entry.getKey().equals(JsonMessageConverter.MESSAGE_ID)) {
                    message.setMessageId(entry.getValue());
                } else if (entry.getKey().equals(JsonMessageConverter.TO)) {
                    message.setAddress(entry.getValue().toString());
                } else if (entry.getKey().equals(JsonMessageConverter.SUBJECT)) {
                    message.setSubject(entry.getValue().toString());
                } else if (entry.getKey().equals(JsonMessageConverter.REPLY_TO)) {
                    message.setReplyTo(entry.getValue().toString());
                } else if (entry.getKey().equals(JsonMessageConverter.CORRELATION_ID)) {
                    message.setCorrelationId(entry.getValue());
                }
            }
        }
    }

    // get AMQP application properties from the JSON
    JsonObject jsonApplicationProperties = json.getJsonObject(JsonMessageConverter.APPLICATION_PROPERTIES);
    if (jsonApplicationProperties != null) {

        Map<Symbol, Object> applicationPropertiesMap = new HashMap<>();

        for (Entry<String, Object> entry : jsonApplicationProperties) {
            applicationPropertiesMap.put(Symbol.valueOf(entry.getKey()), entry.getValue());
        }

        ApplicationProperties applicationProperties = new ApplicationProperties(applicationPropertiesMap);
        message.setApplicationProperties(applicationProperties);
    }

    // put message annotations about partition, offset and key (if not null)
    Map<Symbol, Object> messageAnnotationsMap = new HashMap<>();
    messageAnnotationsMap.put(Symbol.valueOf(Bridge.AMQP_PARTITION_ANNOTATION), record.partition());
    messageAnnotationsMap.put(Symbol.valueOf(Bridge.AMQP_OFFSET_ANNOTATION), record.offset());
    if (record.key() != null)
        messageAnnotationsMap.put(Symbol.valueOf(Bridge.AMQP_KEY_ANNOTATION), record.key());

    // get AMQP message annotations from the JSON
    JsonObject jsonMessageAnnotations = json.getJsonObject(JsonMessageConverter.MESSAGE_ANNOTATIONS);
    if (jsonMessageAnnotations != null) {

        for (Entry<String, Object> entry : jsonMessageAnnotations) {
            messageAnnotationsMap.put(Symbol.valueOf(entry.getKey()), entry.getValue());
        }
    }

    MessageAnnotations messageAnnotations = new MessageAnnotations(messageAnnotationsMap);
    message.setMessageAnnotations(messageAnnotations);

    // get the AMQP message body from the JSON
    JsonObject jsonBody = json.getJsonObject(JsonMessageConverter.BODY);

    if (jsonBody != null) {

        // type attribtute for following sectin : AMQP value or raw data/binary
        String type = jsonBody.getString(JsonMessageConverter.SECTION_TYPE);

        if (type.equals(JsonMessageConverter.SECTION_AMQP_VALUE_TYPE)) {

            // section is an AMQP value
            Object jsonSection = jsonBody.getValue(JsonMessageConverter.SECTION);

            // encoded as String
            if (jsonSection instanceof String) {
                message.setBody(new AmqpValue(jsonSection));
                // encoded as an array/List
            } else if (jsonSection instanceof JsonArray) {
                JsonArray jsonArray = (JsonArray) jsonSection;
                message.setBody(new AmqpValue(jsonArray.getList()));
                // encoded as a Map
            } else if (jsonSection instanceof JsonObject) {
                JsonObject jsonObject = (JsonObject) jsonSection;
                message.setBody(new AmqpValue(jsonObject.getMap()));
            }

        } else if (type.equals(JsonMessageConverter.SECTION_DATA_TYPE)) {

            // section is a raw binary data

            // get the section from the JSON (it's base64 encoded)
            byte[] value = jsonBody.getBinary(JsonMessageConverter.SECTION);

            message.setBody(new Data(new Binary(Base64.getDecoder().decode(value))));
        }
    }

    return message;
}

From source file:io.sqp.proxy.vertx.VertxBackendConnectionPool.java

License:Open Source License

private void loadConfigurations(JsonArray backendConfs) throws ConfigurationException {
    // first validate the configuration object
    if (backendConfs == null || backendConfs.isEmpty()) {
        throw new ConfigurationException("No backend was configured.");
    }/*  w  ww. j ava 2  s  .  com*/
    if (backendConfs.size() > 1) {
        logger.log(Level.WARNING,
                "Only one backend configuration is supported at the moment. The rest is ignored.");
    }
    JsonObject firstConf = backendConfs.getJsonObject(0);
    if (firstConf == null) {
        throwInvalidConfiguration("It's not a valid JSON object.");
    }

    // Every backend needs a specific 'config' configuration map
    JsonObject backendSpecificConf = firstConf.getJsonObject("config");
    if (backendSpecificConf == null) {
        throwInvalidConfiguration("Backend specific configuration is missing.");
    }
    _backendSpecificConfiguration = backendSpecificConf.getMap();

    // The 'type' defines the subclass of BackendConnection that is the heart of the backend
    String backendType = firstConf.getString("type");
    if (backendType == null) {
        throwInvalidConfiguration("No type specified.");
    }
    // Get the class from the class loader and verify it's a subclass of BackendConnection
    Class<?> uncastedBackendClass = null;
    try {
        uncastedBackendClass = Class.forName(backendType);
    } catch (ClassNotFoundException e) {
        throwInvalidConfiguration("Class '" + backendType + "' specified as 'type' was not found.");
    }
    try {
        _backendClass = uncastedBackendClass.asSubclass(Backend.class);
    } catch (ClassCastException e) {
        throwInvalidConfiguration("Class '" + backendType + "' is not a valid Backend implementation.");
    }
}

From source file:org.entcore.common.share.impl.GenericShareService.java

License:Open Source License

protected JsonArray getResoureActions(Map<String, SecuredAction> securedActions) {
    if (resourceActions != null) {
        return resourceActions;
    }/*www .j a v  a  2 s.c  om*/
    JsonObject resourceActions = new JsonObject();
    for (SecuredAction action : securedActions.values()) {
        if (ActionType.RESOURCE.name().equals(action.getType()) && !action.getDisplayName().isEmpty()) {
            JsonObject a = resourceActions.getJsonObject(action.getDisplayName());
            if (a == null) {
                a = new JsonObject()
                        .put("name",
                                new fr.wseduc.webutils.collections.JsonArray()
                                        .add(action.getName().replaceAll("\\.", "-")))
                        .put("displayName", action.getDisplayName()).put("type", action.getType());
                resourceActions.put(action.getDisplayName(), a);
            } else {
                a.getJsonArray("name").add(action.getName().replaceAll("\\.", "-"));
            }
        }
    }
    this.resourceActions = new fr.wseduc.webutils.collections.JsonArray(
            new ArrayList<>(resourceActions.getMap().values()));
    return this.resourceActions;
}

From source file:org.entcore.directory.controllers.DirectoryController.java

License:Open Source License

@Get("/api/personnes")
@SecuredAction("directory.authent")
public void people(HttpServerRequest request) {
    List<String> expectedTypes = request.params().getAll("type");
    JsonObject params = new JsonObject();
    params.put("classId", request.params().get("id"));
    String types = "";
    if (expectedTypes != null && !expectedTypes.isEmpty()) {
        types = "AND p.name IN {expectedTypes} ";
        params.put("expectedTypes", new fr.wseduc.webutils.collections.JsonArray(expectedTypes));
    }//from   w  ww . j av  a 2  s  . c  om
    neo.send(
            "MATCH (n:Class)<-[:DEPENDS]-(g:ProfileGroup)<-[:IN]-(m:User), "
                    + "g-[:DEPENDS]->(pg:ProfileGroup)-[:HAS_PROFILE]->(p:Profile) " + "WHERE n.id = {classId} "
                    + types + "RETURN distinct m.id as userId, p.name as type, "
                    + "m.activationCode as code, m.firstName as firstName,"
                    + "m.lastName as lastName, n.id as classId " + "ORDER BY type DESC ",
            params.getMap(), request.response());
}

From source file:org.entcore.feeder.csv.ColumnsMapper.java

License:Open Source License

public ColumnsMapper(JsonObject additionnalsMappings) {
    JsonObject mappings = new JsonObject().put("id", "externalId").put("externalid", "externalId")
            .put("idexterno", "externalId").put("nom", "lastName").put("apellido", "lastName")
            .put("lastname", "lastName").put("sobrenome", "lastName").put("nomeleve", "lastName")
            .put("nomresponsable", "lastName").put("nomdusageeleve", "username")
            .put("nomusageresponsable", "username").put("nomusage", "username").put("nomdusage", "username")
            .put("prenom", "firstName").put("nombre", "firstName").put("firstname", "firstName")
            .put("nome", "firstName").put("prenomeleve", "firstName").put("prenomresponsable", "firstName")
            .put("classe", "classes").put("clase", "classes").put("class", "classes").put("turma", "classes")
            .put("libelleclasse", "classes").put("classeouregroupement", "classes")
            .put("idenfant", "childExternalId").put("datedenaissance", "birthDate")
            .put("datenaissance", "birthDate").put("birthdate", "birthDate")
            .put("fechadenacimiento", "birthDate").put("datadenascimento", "birthDate")
            .put("neele", "birthDate").put("ne(e)le", "birthDate").put("childid", "childExternalId")
            .put("childexternalid", "childExternalId").put("idexternohijo", "childExternalId")
            .put("idexternofilho", "childExternalId").put("nomenfant", "childLastName")
            .put("prenomenfant", "childFirstName").put("classeenfant", "childClasses")
            .put("nomdusageenfant", "childUsername").put("nomdefamilleenfant", "childLastName")
            .put("nomdefamilleeleve", "childLastName").put("classesenfants", "childClasses")
            .put("classeseleves", "childClasses").put("presencedevanteleves", "teaches")
            .put("fonction", "functions").put("funcion", "functions").put("function", "functions")
            .put("funcao", "functions").put("niveau", "level").put("regime", "accommodation")
            .put("filiere", "sector").put("cycle", "sector").put("mef", "module")
            .put("libellemef", "moduleName").put("boursier", "scholarshipHolder").put("transport", "transport")
            .put("statut", "status").put("codematiere", "fieldOfStudy").put("matiere", "fieldOfStudyLabels")
            .put("persreleleve", "relative").put("civilite", "title").put("civiliteresponsable", "title")
            .put("telephone", "homePhone").put("telefono", "homePhone").put("phone", "homePhone")
            .put("telefone", "homePhone").put("telephonedomicile", "homePhone")
            .put("telephonetravail", "workPhone").put("telefonotrabajo", "workPhone")
            .put("phonework", "workPhone").put("telefonetrabalho", "workPhone")
            .put("telephoneportable", "mobile").put("adresse", "address").put("adresse1", "address")
            .put("adresseresponsable", "address").put("direccion", "address").put("address", "address")
            .put("endereco", "address").put("adresse2", "address2").put("cp", "zipCode")
            .put("cpresponsable", "zipCode").put("codigopostal", "zipCode").put("postcode", "zipCode")
            .put("cp1", "zipCode").put("cp2", "zipCode2").put("ville", "city").put("communeresponsable", "city")
            .put("commune", "city").put("commune1", "city").put("commune2", "city2").put("ciudad", "city")
            .put("city", "city").put("cidade", "city").put("pays", "country").put("pais", "country")
            .put("country", "country").put("pays1", "country").put("pays2", "country2")
            .put("discipline", "classCategories").put("materia", "classCategories")
            .put("matiereenseignee", "subjectTaught").put("email", "email").put("correoelectronico", "email")
            .put("courriel", "email").put("professeurprincipal", "headTeacher").put("sexe", "gender")
            .put("attestationfournie", "ignore").put("autorisationsassociations", "ignore")
            .put("autorisationassociations", "ignore").put("autorisationsphotos", "ignore")
            .put("autorisationphoto", "ignore").put("decisiondepassage", "ignore").put("directeur", "ignore")
            .put("ine", "ine").put("identifiantclasse", "ignore").put("dateinscription", "ignore")
            .put("deuxiemeprenom", "ignore").put("troisiemeprenom", "ignore").put("communenaissance", "ignore")
            .put("deptnaissance", "ignore").put("paysnaissance", "ignore").put("etat", "ignore")
            .put("intervenant", "ignore").put("regroupement(s)", "ignore").put("dispositif(s)", "ignore")
            .put("", "ignore");

    mappings.mergeIn(additionnalsMappings);
    namesMapping = mappings.getMap();
    relativeMapping = mappings.copy().put("prenomeleve", "childFirstName")
            .put("nomdusageeleve", "childUsername").getMap();
}

From source file:org.entcore.feeder.utils.Validator.java

License:Open Source License

private String required(JsonObject object, String acceptLanguage) {
    Map<String, Object> m = object.getMap();
    for (Object o : required) {
        if (!m.containsKey(o.toString())) {
            return i18n.translate("missing.attribute", I18n.DEFAULT_DOMAIN, acceptLanguage,
                    i18n.translate(o.toString(), I18n.DEFAULT_DOMAIN, acceptLanguage));
        }/* w  ww.  java 2 s.  c  o m*/
    }
    return null;
}

From source file:org.entcore.timeline.events.DefaultTimelineEventStore.java

License:Open Source License

@Override
public void get(final UserInfos user, List<String> types, int offset, int limit, JsonObject restrictionFilter,
        boolean mine, final Handler<JsonObject> result) {
    final String recipient = user.getUserId();
    final String externalId = user.getExternalId();
    if (recipient != null && !recipient.trim().isEmpty()) {
        final JsonObject query = new JsonObject().put("deleted", new JsonObject().put("$exists", false))
                .put("date", new JsonObject().put("$lt", MongoDb.now()));
        if (externalId == null || externalId.trim().isEmpty()) {
            query.put(mine ? "sender" : "recipients.userId", recipient);
        } else {/*from  w w w. j a v  a 2  s  .com*/
            query.put(mine ? "sender" : "recipients.userId", new JsonObject().put("$in",
                    new fr.wseduc.webutils.collections.JsonArray().add(recipient).add(externalId)));
        }
        query.put("reportAction.action", new JsonObject().put("$ne", "DELETE"));
        if (types != null && !types.isEmpty()) {
            if (types.size() == 1) {
                query.put("type", types.get(0));
            } else {
                JsonArray typesFilter = new fr.wseduc.webutils.collections.JsonArray();
                for (String t : types) {
                    typesFilter.add(new JsonObject().put("type", t));
                }
                query.put("$or", typesFilter);
            }
        }
        if (restrictionFilter != null && restrictionFilter.size() > 0) {
            JsonArray nor = new fr.wseduc.webutils.collections.JsonArray();
            for (String type : restrictionFilter.getMap().keySet()) {
                for (Object eventType : restrictionFilter.getJsonArray(type,
                        new fr.wseduc.webutils.collections.JsonArray())) {
                    nor.add(new JsonObject().put("type", type).put("event-type", eventType.toString()));
                }
                query.put("$nor", nor);
            }
        }
        JsonObject sort = new JsonObject().put("created", -1);
        JsonObject keys = new JsonObject().put("message", 1).put("params", 1).put("date", 1).put("sender", 1)
                .put("comments", 1).put("type", 1).put("event-type", 1).put("resource", 1)
                .put("sub-resource", 1).put("add-comment", 1);
        if (!mine) {
            keys.put("recipients",
                    new JsonObject().put("$elemMatch", new JsonObject().put("userId", user.getUserId())));
            keys.put("reporters",
                    new JsonObject().put("$elemMatch", new JsonObject().put("userId", user.getUserId())));
        }

        mongo.find(TIMELINE_COLLECTION, query, sort, keys, offset, limit, 100,
                new Handler<Message<JsonObject>>() {
                    @Override
                    public void handle(Message<JsonObject> message) {
                        result.handle(message.body());
                    }
                });
    } else {
        result.handle(invalidArguments());
    }
}

From source file:org.entcore.timeline.events.DefaultTimelineEventStore.java

License:Open Source License

private JsonObject validAndGet(JsonObject json) {
    if (json != null) {
        JsonObject e = json.copy();
        for (String attr : json.fieldNames()) {
            if (!FIELDS.contains(attr) || e.getValue(attr) == null) {
                e.remove(attr);//  w  w  w.  j ava 2  s  .co  m
            }
        }
        if (e.getMap().keySet().containsAll(REQUIRED_FIELDS)) {
            return e;
        }
    }
    return null;
}