List of usage examples for io.vertx.core.json JsonObject getBoolean
public Boolean getBoolean(String key)
From source file:org.entcore.auth.oauth.OAuthDataHandler.java
License:Open Source License
private void checkPassword(JsonArray result, String password, String username, Handler<String> handler) { JsonObject r = result.getJsonObject(0); String dbPassword;/*from w w w . j av a 2s . com*/ if (r != null && (dbPassword = r.getString("password")) != null && !getOrElse(r.getBoolean("blockedProfile"), false)) { boolean success = false; String hash = null; try { switch (dbPassword.length()) { case 32: // md5 hash = Md5.hash(password); break; case 64: // sha-256 hash = Sha256.hash(password); break; default: // BCrypt success = BCrypt.checkpw(password, dbPassword); } if (!success && hash != null) { success = !dbPassword.trim().isEmpty() && dbPassword.equalsIgnoreCase(hash); if (success) { upgradeOldPassword(username, password); } } } catch (NoSuchAlgorithmException e) { log.error(e.getMessage(), e); } if (success) { handler.handle(r.getString("userId")); } else { handler.handle(null); } } else { handler.handle(null); } }
From source file:org.entcore.common.share.impl.GenericShareService.java
License:Open Source License
private void shareValidationVisible(String userId, String resourceId, Handler<Either<String, JsonObject>> handler, HashMap<String, Set<String>> membersActions, Set<String> shareBookmarkIds) { // final String preFilter = "AND m.id IN {members} "; final Set<String> members = membersActions.keySet(); final JsonObject params = new JsonObject().put("members", new JsonArray(new ArrayList<>(members))); // final String customReturn = "RETURN DISTINCT visibles.id as id, has(visibles.login) as isUser"; // UserUtils.findVisibles(eb, userId, customReturn, params, true, true, false, null, preFilter, res -> { checkMembers(params, res -> {// www . ja v a 2 s.co m if (res != null) { final JsonArray users = new JsonArray(); final JsonArray groups = new JsonArray(); final JsonArray shared = new JsonArray(); final JsonArray notifyMembers = new JsonArray(); for (Object o : res) { JsonObject j = (JsonObject) o; final String attr = j.getString("id"); if (Boolean.TRUE.equals(j.getBoolean("isUser"))) { users.add(attr); notifyMembers.add(new JsonObject().put("userId", attr)); prepareSharedArray(resourceId, "userId", shared, attr, membersActions.get(attr)); } else { groups.add(attr); notifyMembers.add(new JsonObject().put("groupId", attr)); prepareSharedArray(resourceId, "groupId", shared, attr, membersActions.get(attr)); } } handler.handle(new Either.Right<>(params.put("shared", shared).put("groups", groups) .put("users", users).put("notify-members", notifyMembers))); if (shareBookmarkIds != null && res.size() < members.size()) { members.removeAll(groups.getList()); members.removeAll(users.getList()); resyncShareBookmark(userId, members, shareBookmarkIds); } } else { handler.handle(new Either.Left<>("Invalid members count.")); } }); }
From source file:org.entcore.conversation.controllers.ConversationController.java
License:Open Source License
@Post("toggleUnread") @SecuredAction(value = "", type = ActionType.RESOURCE) @ResourceFilter(MultipleMessageUserFilter.class) public void toggleUnread(final HttpServerRequest request) { bodyToJson(request, new Handler<JsonObject>() { @Override//from w w w .ja v a 2s.c o m public void handle(JsonObject body) { final JsonArray ids = body.getJsonArray("id"); final Boolean unread = body.getBoolean("unread"); if (ids == null || ids.isEmpty() || unread == null) { badRequest(request); return; } UserUtils.getUserInfos(eb, request, new Handler<UserInfos>() { @Override public void handle(final UserInfos user) { if (user != null) { conversationService.toggleUnread(ids.getList(), unread, user, defaultResponseHandler(request)); } else { unauthorized(request); } } }); } }); }
From source file:org.entcore.feeder.aaf.PersonnelImportProcessing.java
License:Open Source License
protected String detectProfile(JsonObject object) { Boolean isTeacher = object.getBoolean("isTeacher"); if (isTeacher != null) { return isTeacher ? TEACHER_PROFILE_EXTERNAL_ID : PERSONNEL_PROFILE_EXTERNAL_ID; } else {/*from w w w. j ava 2 s. co m*/ JsonArray functions = object.getJsonArray("functions"); if (object.getBoolean("teaches", false)) { return TEACHER_PROFILE_EXTERNAL_ID; } else if (functions != null && functions.size() > 0) { for (Object function : functions.getList()) { if (function != null && (function.toString().contains("$DOC$") || function.toString().contains("$ENS$"))) { return TEACHER_PROFILE_EXTERNAL_ID; } } } return PERSONNEL_PROFILE_EXTERNAL_ID; } }
From source file:org.entcore.feeder.aaf1d.PersonnelImportProcessing1d.java
License:Open Source License
@Override protected String detectProfile(JsonObject object) { Boolean isTeacher = object.getBoolean("isTeacher"); if (isTeacher != null) { return isTeacher ? TEACHER_PROFILE_EXTERNAL_ID : PERSONNEL_PROFILE_EXTERNAL_ID; } else {// w w w . ja v a 2 s .co m JsonArray functions = object.getJsonArray("functions"); if (functions != null && functions.size() > 0) { for (Object f : functions) { if (!(f instanceof String)) continue; String function = (String) f; if (function.contains("ENS") || function.contains("DOC")) { return TEACHER_PROFILE_EXTERNAL_ID; } } } return PERSONNEL_PROFILE_EXTERNAL_ID; } }
From source file:org.entcore.feeder.utils.AAFUtil.java
License:Open Source License
private static Object functionalGroupConverter(Object value) { final JsonArray res = new JsonArray(); if (value instanceof JsonArray) { for (Object o : ((JsonArray) value)) { if (o instanceof JsonObject) { final JsonObject j = (JsonObject) o; final String structureExternalId = j.getString("structureExternalId"); if (isNotEmpty(structureExternalId)) { final String idrgpmt = j.getString("idrgpmt"); final String name = j.getString("name"); if (isNotEmpty(idrgpmt)) { res.add(structureExternalId + "$" + name + "$" + idrgpmt); } else if (isNotEmpty(j.getString("idgpe"))) { if (!getOrElse(j.getBoolean("usedInCourses"), false)) continue; final String code = j.getString("code"); if (isNotEmpty(code) && isNotEmpty(j.getString("code_gep"))) { res.add(structureExternalId + "$" + j.getString("code_gep") + "_" + code + "$" + j.getString("idgpe")); } else if (isNotEmpty(code) && isNotEmpty(j.getString("code_div"))) { res.add(structureExternalId + "$" + j.getString("code_div") + "_" + code + "$" + j.getString("idgpe")); }/*ww w . ja v a 2 s . com*/ } else if (isEmpty(j.getString("externalId")) && isNotEmpty(name)) { res.add(structureExternalId + "$" + name + "$" + j.getString("id")); } else if (isNotEmpty(j.getString("externalId"))) { res.add(j.getString("externalId") + "$" + j.getString("id")); } } } } } return res; }
From source file:org.entcore.timeline.controllers.helper.NotificationHelper.java
License:Open Source License
public void sendImmediateNotifications(final HttpServerRequest request, final JsonObject json) { //Get notification properties (mixin : admin console configuration which overrides default properties) final String notificationName = json.getString("notificationName"); final JsonObject notification = json.getJsonObject("notification"); configService.getNotificationProperties(notificationName, new Handler<Either<String, JsonObject>>() { public void handle(final Either<String, JsonObject> properties) { if (properties.isLeft() || properties.right().getValue() == null) { log.error("[NotificationHelper] Issue while retrieving notification (" + notificationName + ") properties."); return; }/*from w ww . j ava 2 s . c o m*/ final JsonObject notificationProperties = properties.right().getValue(); //Get users preferences (overrides notification properties) NotificationUtils.getUsersPreferences(eb, json.getJsonArray("recipientsIds"), "language: uac.language, tokens: uac.fcmTokens ", new Handler<JsonArray>() { public void handle(final JsonArray userList) { if (userList == null) { log.error("[NotificationHelper] Issue while retrieving users preferences."); return; } mailerService.sendImmediateMails(request, notificationName, notification, json.getJsonObject("params"), userList, notificationProperties); if (pushNotifService != null && json.containsKey("pushNotif") && notificationProperties.getBoolean("push-notif") && !TimelineNotificationsLoader.Restrictions.INTERNAL.name() .equals(notificationProperties.getString("restriction")) && !TimelineNotificationsLoader.Restrictions.HIDDEN.name() .equals(notificationProperties.getString("restriction"))) pushNotifService.sendImmediateNotifs(notificationName, json, userList, notificationProperties); } }); } }); }
From source file:org.entcore.workspace.service.WorkspaceService.java
License:Open Source License
private void copyFile(JsonObject message, final GenericDao dao, final long emptySize, Handler<JsonObject> handler) { try {// www . ja va 2 s . c o m dao.findById(message.getString("documentId"), message.getString("ownerId"), new Handler<JsonObject>() { @Override public void handle(JsonObject src) { if ("ok".equals(src.getString("status")) && src.getJsonObject("result") != null) { JsonObject orig = src.getJsonObject("result"); if (orig.getJsonObject("metadata", new JsonObject()).getLong("size", 0l) > emptySize) { handler.handle(new JsonObject().put("status", "ko").put("error", "file.too.large")); return; } final JsonObject dest = orig.copy(); String now = MongoDb.formatDate(new Date()); dest.remove("_id"); dest.remove("protected"); if (message.getBoolean("protected") != null) dest.put("protected", message.getBoolean("protected")); dest.put("application", WORKSPACE_NAME); if (message.getJsonObject("user") != null) { dest.put("owner", message.getJsonObject("user").getString("userId")); dest.put("ownerName", message.getJsonObject("user").getString("userName")); dest.remove("to"); dest.remove("from"); dest.remove("toName"); dest.remove("fromName"); } dest.put("created", now); dest.put("modified", now); String folder = getOrElse(message.getString("folder"), ""); try { folder = URLDecoder.decode(folder, "UTF-8"); } catch (UnsupportedEncodingException e) { log.warn(e.getMessage(), e); } dest.put("folder", folder); String filePath = orig.getString("file"); if (filePath != null) { storage.copyFile(filePath, new Handler<JsonObject>() { @Override public void handle(JsonObject event) { if (event != null && "ok".equals(event.getString("status"))) { dest.put("file", event.getString("_id")); persist(dest); } } }); } else { persist(dest); } } else { handler.handle(new JsonObject().put("status", "ko").put("error", "not.found")); } } private void persist(final JsonObject dest) { documentDao.save(dest, new Handler<JsonObject>() { @Override public void handle(JsonObject res) { if ("ok".equals(res.getString("status"))) { incrementStorage(dest); handler.handle(res); } else { handler.handle(res); } } }); } }); } catch (Exception e) { log.error(e); } }
From source file:org.etourdot.vertx.marklogic.model.options.RangeAttributeIndex.java
License:Open Source License
public RangeAttributeIndex(JsonObject jsonObject) { requireNonNull(jsonObject);//from w w w . ja v a 2 s. c o m scalarType(jsonObject.getString("scalar-type")); ofNullable(jsonObject.getString("parent-namespace-uri")).ifPresent(this::namespaceUri); localname(jsonObject.getString("parent-localname")); ofNullable(jsonObject.getString("collation")).ifPresent(this::collation); ofNullable(jsonObject.getBoolean("range-value-positions")).ifPresent(this::rangeValuePositions); }
From source file:org.etourdot.vertx.marklogic.model.options.RangeElementIndex.java
License:Open Source License
public RangeElementIndex(JsonObject jsonObject) { requireNonNull(jsonObject);//from w w w. j a v a 2 s . c om scalarType(jsonObject.getString("scalar-type")); ofNullable(jsonObject.getString("namespace-uri")).ifPresent(this::namespaceUri); localname(jsonObject.getString("localname")); ofNullable(jsonObject.getString("collation")).ifPresent(this::collation); ofNullable(jsonObject.getBoolean("range-value-positions")).ifPresent(this::rangeValuePositions); }