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

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

Introduction

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

Prototype

public String getString(String key) 

Source Link

Document

Get the string value with the specified key, special cases are addressed for extended JSON types Instant , byte[] and Enum which can be converted to String.

Usage

From source file:org.entcore.directory.services.impl.DefaultGroupService.java

License:Open Source License

@Override
public void createOrUpdateManual(JsonObject group, String structureId, String classId,
        Handler<Either<String, JsonObject>> result) {
    group.put("groupDisplayName", group.getString("name"));
    JsonObject action = new JsonObject().put("action", "manual-create-group").put("structureId", structureId)
            .put("classId", classId).put("group", group);
    eventBus.send(Directory.FEEDER, action, handlerToAsyncHandler(validUniqueResultHandler(0, result)));
}

From source file:org.entcore.directory.services.impl.DefaultShareBookmarkService.java

License:Open Source License

@Override
public void update(String userId, String id, JsonObject bookmark, Handler<Either<String, JsonObject>> handler) {
    final String query = "MATCH (u:User {id:{userId}}) " + "MERGE u-[:HAS_SB]->(sb:ShareBookmark) " + "SET sb."
            + cleanId(id) + " = {bookmark} ";
    JsonObject params = new JsonObject();
    params.put("userId", userId);
    params.put("bookmark", new JsonArray().add(bookmark.getString("name"))
            .addAll(getOrElse(bookmark.getJsonArray("members"), new JsonArray())));
    neo4j.execute(query, params, validEmptyHandler(handler));
}

From source file:org.entcore.directory.services.impl.DefaultUserBookService.java

License:Open Source License

private Optional<String> getPictureIdForUserbook(JsonObject userBook) {
    String picturePath = userBook.getString("picture");
    if (StringUtils.isEmpty(picturePath)) {
        return Optional.empty();
    }//from  ww w  . j a  v a  2s  .c o  m
    //it is not picture id but user id
    if (picturePath.startsWith("/userbook/avatar/")) {
        return Optional.empty();
    }
    String[] picturePaths = picturePath.split("/");
    String pictureId = picturePaths[picturePaths.length - 1];
    return Optional.ofNullable(pictureId);
}

From source file:org.entcore.directory.services.impl.DefaultUserBookService.java

License:Open Source License

private Future<Boolean> cacheAvatarFromUserBook(String userId, Optional<String> pictureId, Boolean remove) {
    // clean avatar when changing or when removing
    Future<Boolean> futureClean = (pictureId.isPresent() || remove) ? cleanAvatarCache(userId)
            : Future.succeededFuture();
    return futureClean.compose(res -> {
        if (!pictureId.isPresent()) {
            return Future.succeededFuture();
        }//from   w w  w.j  a  va2 s  . c  om
        Future<Boolean> futureCopy = Future.future();
        this.wsHelper.getDocument(pictureId.get(), resDoc -> {
            if (resDoc.succeeded() && "ok".equals(resDoc.result().body().getString("status"))) {
                JsonObject document = resDoc.result().body().getJsonObject("result");
                String fileId = document.getString("file");
                // Extensions are not used by storage
                String defaultFilename = avatarFileNameFromUserId(userId, Optional.empty());
                //
                JsonObject thumbnails = document.getJsonObject("thumbnails", new JsonObject());
                Map<String, String> filenamesByIds = new HashMap<>();
                filenamesByIds.put(fileId, defaultFilename);

                for (String size : thumbnails.fieldNames()) {
                    filenamesByIds.put(thumbnails.getString(size),
                            avatarFileNameFromUserId(userId, Optional.of(size)));
                }
                // TODO avoid buffer to improve performances and avoid cache every time
                List<Future> futures = new ArrayList<>();
                for (Entry<String, String> entry : filenamesByIds.entrySet()) {
                    String cFileId = entry.getKey();
                    String cFilename = entry.getValue();
                    Future<JsonObject> future = Future.future();
                    futures.add(future);
                    this.wsHelper.readFile(cFileId, buffer -> {
                        if (buffer != null) {
                            this.avatarStorage.writeBuffer(FileUtils.stripExtension(cFilename), buffer, "",
                                    cFilename, wRes -> {
                                        future.complete(wRes);
                                    });
                        } else {
                            future.fail("Cannot read file from workspace storage. ID =: " + cFileId);
                        }
                    });
                }
                //
                CompositeFuture.all(futures)
                        .setHandler(finishRes -> futureCopy.complete(finishRes.succeeded()));
            }
        });
        return futureCopy;
    });

}

From source file:org.entcore.directory.services.impl.DefaultUserService.java

License:Open Source License

@Override
public void createInStructure(String structureId, JsonObject user, Handler<Either<String, JsonObject>> result) {
    user.put("profiles", new fr.wseduc.webutils.collections.JsonArray().add(user.getString("type")));
    JsonObject action = new JsonObject().put("action", "manual-create-user").put("structureId", structureId)
            .put("profile", user.getString("type")).put("data", user);
    eb.send(Directory.FEEDER, action, handlerToAsyncHandler(validUniqueResultHandler(result)));
}

From source file:org.entcore.directory.services.impl.DefaultUserService.java

License:Open Source License

@Override
public void createInClass(String classId, JsonObject user, Handler<Either<String, JsonObject>> result) {
    user.put("profiles", new fr.wseduc.webutils.collections.JsonArray().add(user.getString("type")));
    JsonObject action = new JsonObject().put("action", "manual-create-user").put("classId", classId)
            .put("profile", user.getString("type")).put("data", user);
    eb.send(Directory.FEEDER, action, handlerToAsyncHandler(validUniqueResultHandler(result)));
}

From source file:org.entcore.directory.services.impl.DefaultUserService.java

License:Open Source License

@Override
public void sendUserCreatedEmail(final HttpServerRequest request, String userId,
        final Handler<Either<String, Boolean>> result) {
    String query = "MATCH (u:`User` { id : {id}}) WHERE NOT(u.email IS NULL) AND NOT(u.activationCode IS NULL) "
            + "RETURN u.login as login, u.email as email, u.activationCode as activationCode ";
    JsonObject params = new JsonObject().put("id", userId);
    neo.execute(query, params, new Handler<Message<JsonObject>>() {
        @Override/* w w w .ja  va 2  s .  c  o m*/
        public void handle(Message<JsonObject> m) {
            Either<String, JsonObject> r = validUniqueResult(m);
            if (r.isRight()) {
                JsonObject j = r.right().getValue();
                String email = j.getString("email");
                String login = j.getString("login");
                String activationCode = j.getString("activationCode");
                if (email == null || login == null || activationCode == null || email.trim().isEmpty()
                        || login.trim().isEmpty() || activationCode.trim().isEmpty()) {
                    result.handle(new Either.Left<String, Boolean>("user.invalid.values"));
                    return;
                }
                JsonObject json = new JsonObject()
                        .put("activationUri",
                                notification.getHost(request) + "/auth/activation?login=" + login
                                        + "&activationCode=" + activationCode)
                        .put("host", notification.getHost(request)).put("login", login);
                logger.debug(json.encode());
                notification.sendEmail(request, email, null, null, "email.user.created.info",
                        "email/userCreated.html", json, true, new Handler<AsyncResult<Message<JsonObject>>>() {

                            @Override
                            public void handle(AsyncResult<Message<JsonObject>> ar) {
                                if (ar.succeeded()) {
                                    result.handle(new Either.Right<String, Boolean>(true));
                                } else {
                                    result.handle(new Either.Left<String, Boolean>(ar.cause().getMessage()));
                                }
                            }
                        });
            } else {
                result.handle(new Either.Left<String, Boolean>(r.left().getValue()));
            }
        }
    });
}

From source file:org.entcore.feeder.aaf.AAFHandler.java

License:Open Source License

private void addValueInAttribute(String s) throws SAXException {
    if (s == null || (s.isEmpty() && !"ENTAuxEnsClassesPrincipal".equals(currentAttribute)
            && !"mobile".equals(currentAttribute) && !"ENTPersonMobileSMS".equals(currentAttribute))) {
        return;/* w  w  w.  ja  v a 2s  .co m*/
    }
    JsonObject j = mapping.getJsonObject(currentAttribute);
    if (j == null) {
        throw new SAXException("Unknown attribute " + currentAttribute);
    }
    if (currentStructure == null) {
        throw new SAXException("Value is found but structure isn't defined.");
    }
    String type = j.getString("type");
    String attribute = j.getString("attribute");
    final boolean prefix = j.getBoolean("prefix", false);
    if ("birthDate".equals(attribute) && !s.isEmpty()) {
        s = convertDate(s);
    }
    if (type != null && type.contains("array")) {
        JsonArray a = currentStructure.getJsonArray(attribute);
        if (a == null) {
            a = new fr.wseduc.webutils.collections.JsonArray();
            currentStructure.put(attribute, a);
        }
        if (!s.isEmpty()) {
            a.add(JsonUtil.convert(s, type, (prefix ? processing.getAcademyPrefix() : null)));
        }
    } else {
        Object v = JsonUtil.convert(s, type, (prefix ? processing.getAcademyPrefix() : null));
        if (!(v instanceof JsonUtil.None)) {
            currentStructure.put(attribute, v);
        }
    }
}

From source file:org.entcore.feeder.aaf.PersonnelImportProcessing.java

License:Open Source License

@Override
public void process(JsonObject object) {
    List<String> c = object.getJsonArray("classes") != null ? object.getJsonArray("classes").getList()
            : new LinkedList<>();
    createGroups(object.getJsonArray("groups"), c, null);
    createClasses(new fr.wseduc.webutils.collections.JsonArray(c));
    createFunctionGroups(object.getJsonArray("functions"), null);
    createHeadTeacherGroups(object.getJsonArray("headTeacher"), null);
    linkMef(object.getJsonArray("modules"));
    String profile = detectProfile(object);
    object.put("profiles", new fr.wseduc.webutils.collections.JsonArray()
            .add((TEACHER_PROFILE_EXTERNAL_ID.equals(profile) ? "Teacher" : "Personnel")));
    String email = object.getString("email");
    if (email != null && !email.trim().isEmpty()) {
        object.put("emailAcademy", email);
    }//from   ww w . j  a  v a2  s .  c  o m
    importer.createOrUpdatePersonnel(object, profile, null, null, null, true, false);
}

From source file:org.entcore.feeder.aaf.UserImportProcessing.java

License:Open Source License

@Override
public void process(JsonObject object) {
    if (resp.contains(object.getString("externalId"))) {
        object.put("profiles", new fr.wseduc.webutils.collections.JsonArray().add("Relative"));
        importer.createOrUpdateUser(object);
    }//from  ww w .j  a v  a2s  .  c o m
}