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

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

Introduction

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

Prototype

public boolean containsKey(String key) 

Source Link

Document

Does the JSON object contain the specified key?

Usage

From source file:org.entcore.cas.services.LabomepRegisteredService.java

License:Open Source License

@Override
protected void prepareUserCas20(User user, String userId, String service, JsonObject data, Document doc,
        List<Element> additionnalAttributes) {
    user.setUser(data.getString(principalAttributeName));

    try {//from  ww  w. j a v a 2s .c  o  m
        // Uid
        if (data.containsKey("externalId")) {
            additionnalAttributes.add(createTextElement("uid", data.getString("externalId"), doc));
        }

        // administratives Structures first
        final List<String> uaiList = new ArrayList<>();

        for (Object o : data.getJsonArray("administratives", new fr.wseduc.webutils.collections.JsonArray())) {
            JsonObject structure = (JsonObject) o;
            final String uai = structure.getString("UAI");
            if (!StringUtils.isEmpty(uai)) {
                uaiList.add(uai);
                additionnalAttributes.add(createTextElement("structures", uai, doc));
            }
        }

        for (Object o : data.getJsonArray("structures", new fr.wseduc.webutils.collections.JsonArray())) {
            JsonObject structure = (JsonObject) o;
            final String uai = structure.getString("UAI");
            if (!StringUtils.isEmpty(uai) && !uaiList.contains(uai)) {
                additionnalAttributes.add(createTextElement("structures", uai, doc));
            }
        }

        // classes
        for (Object o : data.getJsonArray("classes", new fr.wseduc.webutils.collections.JsonArray())) {
            JsonObject classe = (JsonObject) o;
            additionnalAttributes.add(createTextElement("classes", classe.getString("name"), doc));
        }

        // Profile
        switch (data.getString("type")) {
        case "Student":
            additionnalAttributes.add(createTextElement("profile", "National_1", doc));
            break;
        case "Teacher":
            additionnalAttributes.add(createTextElement("profile", "National_3", doc));
            break;
        case "Relative":
            additionnalAttributes.add(createTextElement("profile", "National_2", doc));
            break;
        case "Personnel":
            additionnalAttributes.add(createTextElement("profile", "National_4", doc));
            break;
        }

        // Lastname
        if (data.containsKey("lastName")) {
            additionnalAttributes.add(createTextElement("nom", data.getString("lastName"), doc));
        }

        // Firstname
        if (data.containsKey("firstName")) {
            additionnalAttributes.add(createTextElement("prenom", data.getString("firstName"), doc));
        }

        // Email
        if (data.containsKey("email")) {
            additionnalAttributes.add(createTextElement("email", data.getString("email"), doc));
        }

    } catch (Exception e) {
        log.error("Failed to extract user's attributes for Labomep", e);
    }
}

From source file:org.entcore.cas.services.LeSiteTvRegisteredService.java

License:Open Source License

@Override
protected void prepareUserCas20(User user, String userId, String service, JsonObject data, Document doc,
        List<Element> additionnalAttributes) {
    user.setUser(data.getString(principalAttributeName));

    try {//from w  w  w.j  a  v a2s  .c  o  m
        Element root = createElement(LSTV_ROOT, doc);

        // Uid
        if (data.containsKey("externalId")) {
            root.appendChild(createTextElement(LSTV_ID, data.getString("externalId"), doc));
        }

        // Structures
        for (Object o : data.getJsonArray("structures", new fr.wseduc.webutils.collections.JsonArray())
                .getList()) {
            if (o == null || !(o instanceof JsonObject))
                continue;
            JsonObject structure = (JsonObject) o;
            if (structure.containsKey("UAI")) {
                root.appendChild(createTextElement(LSTV_STRUCTURE_UAI, structure.getString("UAI"), doc));
            }
        }

        // Profile
        switch (data.getString("type")) {
        case "Student":
            root.appendChild(createTextElement(LSTV_PROFILES, "National_1", doc));
            break;
        case "Teacher":
            root.appendChild(createTextElement(LSTV_PROFILES, "National_3", doc));
            break;
        case "Relative":
            root.appendChild(createTextElement(LSTV_PROFILES, "National_2", doc));
            break;
        case "Personnel":
            root.appendChild(createTextElement(LSTV_PROFILES, "National_4", doc));
            break;
        }

        // Lastname
        if (data.containsKey("lastName")) {
            root.appendChild(createTextElement(LSTV_LASTNAME, data.getString("lastName"), doc));
        }

        // Firstname
        if (data.containsKey("firstName")) {
            root.appendChild(createTextElement(LSTV_FIRSTNAME, data.getString("firstName"), doc));
        }

        // Email
        if (data.containsKey("email")) {
            root.appendChild(createTextElement(LSTV_EMAIL, data.getString("email"), doc));
        }

        additionnalAttributes.add(root);

    } catch (Exception e) {
        log.error("Failed to transform User for LeSite.tv", e);
    }
}

From source file:org.entcore.cas.services.MSELRegisteredService.java

License:Open Source License

@Override
protected void prepareUserCas20(User user, String userId, String service, JsonObject data, Document doc,
        List<Element> additionnalAttributes) {
    // TODO Auto-generated method stub
    user.setUser(data.getString(principalAttributeName));
    try {//from  w  ww. j  a va 2 s.  com
        //uid
        if (data.containsKey("externalId")) {
            additionnalAttributes.add(createTextElement(MSEL_ID, data.getString("externalId"), doc));
        }
        // Structures
        for (Object o : data.getJsonArray("structures", new fr.wseduc.webutils.collections.JsonArray())
                .getList()) {
            if (o == null || !(o instanceof JsonObject))
                continue;
            JsonObject structure = (JsonObject) o;
            if (structure.containsKey("UAI")) {
                additionnalAttributes
                        .add(createTextElement(MSEL_STRUCTURE_UAI, structure.getString("UAI"), doc));
            }
        }

        // Profile
        switch (data.getString("type")) {
        case "Student":
            additionnalAttributes.add(createTextElement(MSEL_PROFILES, "National_1", doc));
            break;
        case "Teacher":
            additionnalAttributes.add(createTextElement(MSEL_PROFILES, "National_3", doc));
            break;
        case "Relative":
            additionnalAttributes.add(createTextElement(MSEL_PROFILES, "National_2", doc));
            break;
        case "Personnel":
            additionnalAttributes.add(createTextElement(MSEL_PROFILES, "National_4", doc));
            break;
        }
    } catch (Exception e) {
        log.error("Failed to transform User for Mon stage en ligne", e);
    }
}

From source file:org.entcore.cas.services.ProEPSRegisteredService.java

License:Open Source License

@Override
protected void prepareUserCas20(User user, String userId, String service, JsonObject data, Document doc,
        List<Element> additionnalAttributes) {
    user.setUser(data.getString(principalAttributeName));

    try {//from  www . jav  a 2  s.com
        // Uid
        if (data.containsKey("externalId")) {
            additionnalAttributes.add(createTextElement(UID, data.getString("externalId"), doc));
        }

        // Structures
        for (Object o : data.getJsonArray("structures", new fr.wseduc.webutils.collections.JsonArray())) {
            if (!(o instanceof JsonObject))
                continue;
            JsonObject structure = (JsonObject) o;
            if (structure.containsKey("UAI")) {
                additionnalAttributes.add(createTextElement(STRUCTURE_UAI, structure.getString("UAI"), doc));
            }
        }

        // Profile
        switch (data.getString("type")) {
        case "Student":
            additionnalAttributes.add(createTextElement(PROFILE, "National_1", doc));
            break;
        case "Teacher":
            additionnalAttributes.add(createTextElement(PROFILE, "National_3", doc));
            break;
        case "Relative":
            additionnalAttributes.add(createTextElement(PROFILE, "National_2", doc));
            break;
        case "Personnel":
            additionnalAttributes.add(createTextElement(PROFILE, "National_4", doc));
            break;
        }

    } catch (Exception e) {
        log.error("Failed to transform User for ProEPS", e);
    }
}

From source file:org.entcore.cas.services.UidRegisteredService.java

License:Open Source License

@Override
protected void prepareUserCas20(User user, String userId, String service, JsonObject data, Document doc,
        List<Element> additionnalAttributes) {
    user.setUser(data.getString(principalAttributeName));

    try {/*from  w  w w  .  j a va  2 s . c o  m*/
        // Uid
        if (data.containsKey("externalId")) {
            additionnalAttributes.add(createTextElement(UID, data.getString("externalId"), doc));
        }

    } catch (Exception e) {
        log.error("Failed to transform User for Uid service", e);
    }
}

From source file:org.entcore.cas.services.UniversalisRegisteredService.java

License:Open Source License

@Override
protected void prepareUserCas20(User user, String userId, String service, JsonObject data, Document doc,
        List<Element> additionnalAttributes) {
    user.setUser(data.getString(principalAttributeName));

    try {//w w  w  .  j a v  a2  s .  c om
        // Uid
        if (data.containsKey("externalId")) {
            additionnalAttributes.add(createTextElement(UNVS_ID, data.getString("externalId"), doc));
        }

        // Structures
        for (Object o : data.getJsonArray("structures", new fr.wseduc.webutils.collections.JsonArray())
                .getList()) {
            if (o == null || !(o instanceof JsonObject))
                continue;
            JsonObject structure = (JsonObject) o;
            if (structure.containsKey("UAI")) {
                additionnalAttributes
                        .add(createTextElement(UNVS_STRUCTURE_UAI, structure.getString("UAI"), doc));
            }
        }

        // Profile
        switch (data.getString("type")) {
        case "Student":
            additionnalAttributes.add(createTextElement(UNVS_PROFILES, "National_1", doc));
            break;
        case "Teacher":
            additionnalAttributes.add(createTextElement(UNVS_PROFILES, "National_3", doc));
            break;
        case "Relative":
            additionnalAttributes.add(createTextElement(UNVS_PROFILES, "National_2", doc));
            break;
        case "Personnel":
            additionnalAttributes.add(createTextElement(UNVS_PROFILES, "National_4", doc));
            break;
        }

        // Lastname
        if (data.containsKey("lastName")) {
            additionnalAttributes.add(createTextElement(UNVS_LASTNAME, data.getString("lastName"), doc));
        }

        // Firstname
        if (data.containsKey("firstName")) {
            additionnalAttributes.add(createTextElement(UNVS_FIRSTNAME, data.getString("firstName"), doc));
        }

    } catch (Exception e) {
        log.error("Failed to transform User for Universalis", e);
    }
}

From source file:org.entcore.cas.services.WebclasseursRegisteredService.java

License:Open Source License

@Override
protected void prepareUserCas20(User user, String userId, String service, JsonObject data, Document doc,
        List<Element> additionnalAttributes) {
    user.setUser(data.getString(principalAttributeName));

    try {//w  w w  . j  a v  a2  s  .  c o  m
        // Lastname
        if (data.containsKey("login")) {
            additionnalAttributes.add(createTextElement(WEBCLASSEURS_LOGIN, data.getString("login"), doc));
        }

        // Profile
        JsonArray profiles = data.getJsonArray("type");
        if (profiles.contains("Teacher") || profiles.contains("Personnel")) {
            // Teacher and Personnel seen alike for Webclasseurs
            additionnalAttributes.add(createTextElement(WEBCLASSEURS_PROFILE, "National_3", doc));
        } else if (profiles.contains("Student")) {
            additionnalAttributes.add(createTextElement(WEBCLASSEURS_PROFILE, "National_1", doc));
        } else if (profiles.contains("Relative")) {
            additionnalAttributes.add(createTextElement(WEBCLASSEURS_PROFILE, "National_2", doc));
        }

    } catch (Exception e) {
        log.error("Failed to transform User for Webclasseurs", e);
    }
}

From source file:org.entcore.common.service.impl.MongoDbCrudService.java

License:Open Source License

private void addPlainField(JsonObject data) {
    if (!this.mongoDbConf.getSearchTextFields().isEmpty()) {
        for (final String field : this.mongoDbConf.getSearchTextFields()) {
            final List<String> decomposition = StringUtils.split(field, "\\.");
            final String collection = decomposition.get(0);
            if (this.collection.equals(collection)) {
                if (decomposition.size() == 2) {
                    //not an object or array
                    final String label = decomposition.get(1);
                    if (data.containsKey(label)) {
                        data.put(label + plainSuffixField, StringUtils.stripHtmlTag(data.getString(label)));
                    }//from  w ww . j  a va 2 s  .c o  m
                } else if (decomposition.size() == 3) {
                    final String label = decomposition.get(1);
                    final String deepLabel = decomposition.get(2);
                    final Object element = data.getValue(label);
                    if (element instanceof JsonArray) {
                        //not processed yet
                        log.error("the plain duplication d'ont support Json Array");
                    } else if (element instanceof JsonObject) {
                        final JsonObject jo = (JsonObject) element;
                        if (jo.containsKey(deepLabel)) {
                            jo.put(deepLabel + plainSuffixField,
                                    StringUtils.stripHtmlTag(jo.getString(deepLabel)));
                        }
                    }
                } else {
                    //object too complex : not treaty
                    log.error(
                            "the plain duplication only works for a string field or top-level field of an object : collection.field | collection.object.field");
                }
            } else {
                break;
            }
        }
    }
}

From source file:org.entcore.communication.controllers.CommunicationController.java

License:Open Source License

@Post("/visible")
@SecuredAction(value = "", type = ActionType.AUTHENTICATED)
public void searchVisible(HttpServerRequest request) {
    RequestUtils.bodyToJson(request, filter -> UserUtils.getUserInfos(eb, request, user -> {
        if (user != null) {
            String preFilter = "";
            String match = "";
            String where = "";
            String nbUsers = "";
            String groupTypes = "";
            JsonObject params = new JsonObject();
            JsonArray expectedTypes = null;
            if (filter != null && filter.size() > 0) {
                for (String criteria : filter.fieldNames()) {
                    switch (criteria) {
                    case "structures":
                    case "classes":
                        JsonArray itemssc = filter.getJsonArray(criteria);
                        if (itemssc == null || itemssc.isEmpty()
                                || ("structures".equals(criteria) && filter.getJsonArray("classes") != null
                                        && !filter.getJsonArray("classes").isEmpty()))
                            continue;
                        if (!params.containsKey("nIds")) {
                            params.put("nIds", itemssc);
                        } else {
                            params.getJsonArray("nIds").addAll(itemssc);
                        }//from  ww w .j  a va  2 s  .  c  o  m
                        if (!match.contains("-[:DEPENDS")) {
                            if (!match.contains("MATCH ")) {
                                match = "MATCH ";
                                where = " WHERE ";
                            } else {
                                match += ", ";
                                where += "AND ";
                            }
                            match += "(visibles)-[:IN*0..1]->()-[:DEPENDS]->(n) ";
                            where += "n.id IN {nIds} ";
                        }
                        if ("structures".equals(criteria)) {
                            match = match.replaceFirst("\\[:DEPENDS]", "[:DEPENDS*1..2]");
                        }
                        break;
                    case "profiles":
                    case "functions":
                        JsonArray itemspf = filter.getJsonArray(criteria);
                        if (itemspf == null || itemspf.isEmpty())
                            continue;
                        if (!params.containsKey("filters")) {
                            params.put("filters", itemspf);
                        } else {
                            //params.getJsonArray("filters").addAll(itemspf);
                            params.put("filters2", itemspf);
                        }
                        if (!match.contains("MATCH ")) {
                            match = "MATCH ";
                            where = " WHERE ";
                        } else {
                            match += ", ";
                            where += "AND ";
                        }
                        if (!match.contains("(visibles)-[:IN*0..1]->(g)")) {
                            match += "(visibles)-[:IN*0..1]->(g)";
                            where += "g.filter IN {filters} ";
                        } else {
                            match += "(visibles)-[:IN*0..1]->(g2) ";
                            where += "g2.filter IN {filters2} ";
                        }
                        break;
                    case "search":
                        final String search = filter.getString(criteria);
                        if (isNotEmpty(search)) {
                            preFilter = "AND m.displayNameSearchField CONTAINS {search} ";
                            String sanitizedSearch = StringValidation.sanitize(search);
                            params.put("search", sanitizedSearch);
                        }
                        break;
                    case "types":
                        JsonArray types = filter.getJsonArray(criteria);
                        if (types != null && types.size() > 0
                                && CommunicationService.EXPECTED_TYPES.containsAll(types.getList())) {
                            expectedTypes = types;
                        }
                        break;
                    case "nbUsersInGroups":
                        if (filter.getBoolean("nbUsersInGroups", false)) {
                            nbUsers = ", visibles.nbUsers as nbUsers";
                        }
                        break;
                    case "groupType":
                        if (filter.getBoolean("groupType", false)) {
                            groupTypes = ", labels(visibles) as groupType, visibles.filter as groupProfile";
                        }
                        break;
                    }
                }
            }
            final boolean returnGroupType = !groupTypes.isEmpty();
            final String customReturn = match + where
                    + "RETURN DISTINCT visibles.id as id, visibles.name as name, "
                    + "visibles.displayName as displayName, visibles.groupDisplayName as groupDisplayName, "
                    + "HEAD(visibles.profiles) as profile" + nbUsers + groupTypes;
            communicationService.visibleUsers(user.getUserId(), null, expectedTypes, true, true, false,
                    preFilter, customReturn, params, user.getType(), visibles -> {
                        if (visibles.isRight()) {
                            renderJson(request, UserUtils.translateAndGroupVisible(visibles.right().getValue(),
                                    I18n.acceptLanguage(request), returnGroupType));
                        } else {
                            leftToResponse(request, visibles.left());
                        }
                    });
        } else {
            badRequest(request, "invalid.user");
        }
    }));
}

From source file:org.entcore.conversation.controllers.ConversationController.java

License:Open Source License

@Post("draft")
@SecuredAction("conversation.create.draft")
public void createDraft(final HttpServerRequest request) {
    getUserInfos(eb, request, new Handler<UserInfos>() {
        @Override/*from  w  ww.ja va  2 s  .c o  m*/
        public void handle(final UserInfos user) {
            if (user != null) {
                final String parentMessageId = request.params().get("In-Reply-To");
                bodyToJson(request, new Handler<JsonObject>() {
                    @Override
                    public void handle(final JsonObject message) {

                        if (!message.containsKey("from")) {
                            message.put("from", user.getUserId());
                        }

                        final Handler<JsonObject> parentHandler = new Handler<JsonObject>() {
                            @Override
                            public void handle(JsonObject parent) {
                                final String threadId;
                                if (parent != null) {
                                    threadId = parent.getString("thread_id");
                                } else {
                                    threadId = null;
                                }
                                neoConversationService.addDisplayNames(message, parent,
                                        new Handler<JsonObject>() {
                                            public void handle(JsonObject message) {
                                                conversationService.saveDraft(parentMessageId, threadId,
                                                        message, user, defaultResponseHandler(request, 201));
                                            }
                                        });
                            }
                        };

                        if (parentMessageId != null && !parentMessageId.trim().isEmpty()) {
                            conversationService.get(parentMessageId, user,
                                    new Handler<Either<String, JsonObject>>() {
                                        public void handle(Either<String, JsonObject> event) {
                                            if (event.isLeft()) {
                                                badRequest(request);
                                                return;
                                            }

                                            parentHandler.handle(event.right().getValue());
                                        }
                                    });
                        } else {
                            parentHandler.handle(null);
                        }

                    }
                });
            } else {
                unauthorized(request);
            }
        }
    });
}