List of usage examples for io.vertx.core.json JsonObject getLong
public Long getLong(String key)
From source file:org.entcore.feeder.dictionary.structures.DuplicateUsers.java
License:Open Source License
private void mergeDuplicate(final JsonObject r, final Message<JsonObject> message, final TransactionHelper tx) { final String source1 = r.getString("source1"); final String source2 = r.getString("source2"); final boolean activatedU1 = r.getBoolean("activatedU1", false); final boolean activatedU2 = r.getBoolean("activatedU2", false); final String userId1 = r.getString("userId1"); final String userId2 = r.getString("userId2"); final boolean missing1 = r.getLong("disappearanceDate1") != null || r.getLong("deleteDate1") != null; final boolean missing2 = r.getLong("disappearanceDate2") != null || r.getLong("deleteDate2") != null; final JsonObject error = new JsonObject().put("status", "error"); if (source1 != null && source1.equals(source2) && notDeduplicateSource.contains(source1) && !missing1 && !missing2) {/*from w w w . j av a 2 s . c o m*/ message.reply(error.put("message", "two.users.in.same.source")); return; } String query; JsonObject params = new JsonObject(); if ((activatedU1 && prioritySource(source1) >= prioritySource(source2)) || (activatedU2 && prioritySource(source1) <= prioritySource(source2)) || (!activatedU1 && !activatedU2)) { query = SIMPLE_MERGE_QUERY; if (prioritySource(source1) == prioritySource(source2) && notDeduplicateSource.contains(source1)) { if (!missing1 && activatedU1) { params.put("userId1", userId1).put("userId2", userId2); } else if (!missing2 && activatedU2) { params.put("userId1", userId2).put("userId2", userId1); } else { query = SWITCH_MERGE_QUERY; if (activatedU1) { params.put("userId1", userId1).put("userId2", userId2); } else { params.put("userId1", userId2).put("userId2", userId1); } } } else { if (activatedU1) { params.put("userId1", userId1).put("userId2", userId2); } else if (activatedU2) { params.put("userId1", userId2).put("userId2", userId1); } else { if (prioritySource(source1) > prioritySource(source2)) { params.put("userId1", userId1).put("userId2", userId2); } else { params.put("userId1", userId2).put("userId2", userId1); } } } } else if ((activatedU1 && prioritySource(source1) < prioritySource(source2)) || (activatedU2 && prioritySource(source1) > prioritySource(source2))) { query = SWITCH_MERGE_QUERY; if (activatedU1) { params.put("userId1", userId1).put("userId2", userId2); } else { params.put("userId1", userId2).put("userId2", userId1); } } else { message.reply(error.put("message", "invalid.merge.case")); return; } if (tx != null) { tx.add(INCREMENT_RELATIVE_SCORE, params); tx.add(query, params); sendMergedEvent(params.getString("userId1"), params.getString("userId2")); message.reply(new JsonObject().put("status", "ok")); } else { try { TransactionHelper txl = TransactionManager.getTransaction(); txl.add(INCREMENT_RELATIVE_SCORE, params); txl.add(query, params); txl.commit(new Handler<Message<JsonObject>>() { @Override public void handle(Message<JsonObject> event) { if ("ok".equals(event.body().getString("status"))) { log.info("Merge duplicates : " + r.encode()); if (updateCourses) { AbstractTimetableImporter.updateMergedUsers(event.body().getJsonArray("results")); } sendMergedEvent(params.getString("userId1"), params.getString("userId2")); } message.reply(event.body()); } }); } catch (TransactionException e) { message.reply(error.put("message", "invalid.transaction")); } } }
From source file:org.entcore.feeder.dictionary.structures.DuplicateUsers.java
License:Open Source License
private void calculateAndStoreScore(JsonObject searchUser, JsonArray findUsers, TransactionHelper tx) { String query = "MATCH (u:User {id : {sId}}), (d:User {id : {dId}}) " + "WHERE NOT({dId} IN coalesce(u.ignoreDuplicates, [])) AND NOT({sId} IN coalesce(d.ignoreDuplicates, [])) " + "AND (has(u.activationCode) OR has(d.activationCode)) " + "MERGE u-[:DUPLICATE {score:{score}}]-d "; JsonObject params = new JsonObject().put("sId", searchUser.getString("id")); final String lastName = cleanAttribute(searchUser.getString("lastName")); final String firstName = cleanAttribute(searchUser.getString("firstName")); final String birthDate = cleanAttribute(searchUser.getString("birthDate")); final String email = cleanAttribute(searchUser.getString("email")); final String source = searchUser.getString("source"); final Long disappearanceDate = searchUser.getLong("disappearanceDate"); for (int i = 0; i < findUsers.size(); i++) { int score = 2; JsonObject fu = findUsers.getJsonObject(i); score += exactMatch(lastName, cleanAttribute(fu.getString("lastName"))); score += exactMatch(firstName, cleanAttribute(fu.getString("firstName"))); score += exactMatch(birthDate, cleanAttribute(fu.getString("birthDate"))); score += exactMatch(email, cleanAttribute(fu.getString("email"))); if (score > 3 && ((!source.equals(fu.getString("source")) && (notDeduplicateSource.contains(source) ^ notDeduplicateSource.contains(fu.getString("source")))) || disappearanceDate != null || fu.getLong("disappearanceDate") != null)) { tx.add(query, params.copy().put("dId", fu.getString("id")).put("score", score)); }//w w w.j a va 2s . c o m } }
From source file:org.entcore.feeder.Feeder.java
License:Open Source License
@Override public void start() { super.start(); String node = (String) vertx.sharedData().getLocalMap("server").get("node"); if (node == null) { node = ""; }//from w w w.j a va 2 s . c o m String neo4jConfig = (String) vertx.sharedData().getLocalMap("server").get("neo4jConfig"); if (neo4jConfig != null) { neo4j = Neo4j.getInstance(); neo4j.init(vertx, new JsonObject(neo4jConfig)); } MongoDb.getInstance().init(vertx.eventBus(), node + "wse.mongodb.persistor"); TransactionManager.getInstance().setNeo4j(neo4j); EventStoreFactory.getFactory().setVertx(vertx); defaultFeed = config.getString("feeder", "AAF"); feeds.put("AAF", new AafFeeder(vertx, getFilesDirectory("AAF"))); feeds.put("AAF1D", new Aaf1dFeeder(vertx, getFilesDirectory("AAF1D"))); feeds.put("CSV", new CsvFeeder(vertx, config.getJsonObject("csvMappings", new JsonObject()))); final long deleteUserDelay = config.getLong("delete-user-delay", 90 * 24 * 3600 * 1000l); final long preDeleteUserDelay = config.getLong("pre-delete-user-delay", 90 * 24 * 3600 * 1000l); final String deleteCron = config.getString("delete-cron", "0 0 2 * * ? *"); final String preDeleteCron = config.getString("pre-delete-cron", "0 0 3 * * ? *"); final String importCron = config.getString("import-cron"); final JsonObject imports = config.getJsonObject("imports"); final JsonObject preDelete = config.getJsonObject("pre-delete"); final TimelineHelper timeline = new TimelineHelper(vertx, eb, config); try { new CronTrigger(vertx, deleteCron).schedule(new User.DeleteTask(deleteUserDelay, eb, vertx)); if (preDelete != null) { if (preDelete.size() == ManualFeeder.profiles.size() && ManualFeeder.profiles.keySet().containsAll(preDelete.fieldNames())) { for (String profile : preDelete.fieldNames()) { final JsonObject profilePreDelete = preDelete.getJsonObject(profile); if (profilePreDelete == null || profilePreDelete.getString("cron") == null || profilePreDelete.getLong("delay") == null) continue; new CronTrigger(vertx, profilePreDelete.getString("cron")).schedule( new User.PreDeleteTask(profilePreDelete.getLong("delay"), profile, timeline)); } } } else { new CronTrigger(vertx, preDeleteCron) .schedule(new User.PreDeleteTask(preDeleteUserDelay, timeline)); } if (imports != null) { if (feeds.keySet().containsAll(imports.fieldNames())) { for (String f : imports.fieldNames()) { final JsonObject i = imports.getJsonObject(f); if (i != null && i.getString("cron") != null) { new CronTrigger(vertx, i.getString("cron")) .schedule(new ImporterTask(vertx, f, i.getBoolean("auto-export", false), config.getLong("auto-export-delay", 1800000l))); } } } else { logger.error("Invalid imports configuration."); } } else if (importCron != null && !importCron.trim().isEmpty()) { new CronTrigger(vertx, importCron).schedule(new ImporterTask(vertx, defaultFeed, config.getBoolean("auto-export", false), config.getLong("auto-export-delay", 1800000l))); } } catch (ParseException e) { logger.fatal(e.getMessage(), e); vertx.close(); return; } Validator.initLogin(neo4j, vertx); manual = new ManualFeeder(neo4j); duplicateUsers = new DuplicateUsers(config.getBoolean("timetable", true), config.getBoolean("autoMergeOnlyInSameStructure", true), vertx.eventBus()); postImport = new PostImport(vertx, duplicateUsers, config); vertx.eventBus().localConsumer(config.getString("address", FEEDER_ADDRESS), this); switch (config.getString("exporter", "")) { case "ELIOT": exporter = new EliotExporter(config.getString("export-path", "/tmp"), config.getString("export-destination"), config.getBoolean("concat-export", false), config.getBoolean("delete-export", true), vertx); break; } final JsonObject edt = config.getJsonObject("edt"); if (edt != null) { final String pronotePrivateKey = edt.getString("pronote-private-key"); if (isNotEmpty(pronotePrivateKey)) { edtUtils = new EDTUtils(vertx, pronotePrivateKey, config.getString("pronote-partner-name", "NEO-Open")); final String edtPath = edt.getString("path"); final String edtCron = edt.getString("cron"); if (isNotEmpty(edtPath) && isNotEmpty(edtCron)) { try { new CronTrigger(vertx, edtCron).schedule(new ImportsLauncher(vertx, edtPath, postImport, edtUtils, config.getBoolean("udt-user-creation", true))); } catch (ParseException e) { logger.error("Error in cron edt", e); } } } } final JsonObject udt = config.getJsonObject("udt"); if (udt != null) { final String udtPath = udt.getString("path"); final String udtCron = udt.getString("cron"); if (isNotEmpty(udtPath) && isNotEmpty(udtCron)) { try { new CronTrigger(vertx, udtCron).schedule(new ImportsLauncher(vertx, udtPath, postImport, edtUtils, config.getBoolean("udt-user-creation", true))); } catch (ParseException e) { logger.error("Error in cron udt", e); } } } final JsonObject csv = config.getJsonObject("csv"); if (csv != null) { final String csvPath = csv.getString("path"); final String csvCron = csv.getString("cron"); final JsonObject csvConfig = csv.getJsonObject("config"); if (isNotEmpty(csvPath) && isNotEmpty(csvCron) && csvConfig != null) { try { new CronTrigger(vertx, csvCron) .schedule(new CsvImportsLauncher(vertx, csvPath, csvConfig, postImport)); } catch (ParseException e) { logger.error("Error in cron csv", e); } } } I18n.getInstance().init(vertx); }
From source file:org.entcore.workspace.controllers.QuotaController.java
License:Open Source License
@Put("/quota") @SecuredAction(value = "", type = ActionType.RESOURCE) public void update(final HttpServerRequest request) { RequestUtils.bodyToJson(request, pathPrefix + "updateQuota", new Handler<JsonObject>() { @Override//from w ww . ja va2 s. c o m public void handle(JsonObject object) { quotaService.update(object.getJsonArray("users"), object.getLong("quota"), arrayResponseHandler(request)); } }); }
From source file:org.entcore.workspace.controllers.QuotaController.java
License:Open Source License
@Put("/quota/default/:profile") @SecuredAction(value = "", type = ActionType.RESOURCE) public void updateDefault(final HttpServerRequest request) { RequestUtils.bodyToJson(request, pathPrefix + "updateDefaultQuota", new Handler<JsonObject>() { @Override/* w w w . java 2s . c o m*/ public void handle(JsonObject object) { String profile = request.params().get("profile"); quotaService.updateQuotaDefaultMax(profile, object.getLong("defaultQuota"), object.getLong("maxQuota"), notEmptyResponseHandler(request)); } }); }
From source file:org.entcore.workspace.service.WorkspaceService.java
License:Open Source License
@Get("/workspace") @SecuredAction("workspace.view") public void view(final HttpServerRequest request) { UserUtils.getUserInfos(eb, request, new Handler<UserInfos>() { @Override/*from w w w. j a v a 2 s.c o m*/ public void handle(final UserInfos user) { if (user != null) { if (user.getAttribute("storage") != null && user.getAttribute("quota") != null) { renderView(request); eventStore.createAndStoreEvent(WokspaceEvent.ACCESS.name(), request); return; } quotaService.quotaAndUsage(user.getUserId(), new Handler<Either<String, JsonObject>>() { @Override public void handle(Either<String, JsonObject> r) { if (r.isRight()) { JsonObject j = r.right().getValue(); for (String attr : j.fieldNames()) { UserUtils.addSessionAttribute(eb, user.getUserId(), attr, j.getLong(attr), null); } } renderView(request); eventStore.createAndStoreEvent(WokspaceEvent.ACCESS.name(), request); } }); } else { unauthorized(request); } } }); }
From source file:org.entcore.workspace.service.WorkspaceService.java
License:Open Source License
private void updateStorage(JsonArray addeds, JsonArray removeds, final Handler<Either<String, JsonObject>> handler) { Map<String, Long> sizes = new HashMap<>(); if (addeds != null) { for (Object o : addeds) { if (!(o instanceof JsonObject)) continue; JsonObject added = (JsonObject) o; Long size = added.getJsonObject("metadata", new JsonObject()).getLong("size", 0l); String userId = (added.containsKey("to")) ? added.getString("to") : added.getString("owner"); if (userId == null) { log.info("UserId is null when update storage size"); log.info(added.encode()); continue; }/*from w ww .jav a 2s . c om*/ Long old = sizes.get(userId); if (old != null) { size += old; } sizes.put(userId, size); } } if (removeds != null) { for (Object o : removeds) { if (!(o instanceof JsonObject)) continue; JsonObject removed = (JsonObject) o; Long size = removed.getJsonObject("metadata", new JsonObject()).getLong("size", 0l); String userId = (removed.containsKey("to")) ? removed.getString("to") : removed.getString("owner"); if (userId == null) { log.info("UserId is null when update storage size"); log.info(removed.encode()); continue; } Long old = sizes.get(userId); if (old != null) { old -= size; } else { old = -1l * size; } sizes.put(userId, old); } } for (final Map.Entry<String, Long> e : sizes.entrySet()) { quotaService.incrementStorage(e.getKey(), e.getValue(), threshold, new Handler<Either<String, JsonObject>>() { @Override public void handle(Either<String, JsonObject> r) { if (r.isRight()) { JsonObject j = r.right().getValue(); UserUtils.addSessionAttribute(eb, e.getKey(), "storage", j.getLong("storage"), null); if (j.getBoolean("notify", false)) { notifyEmptySpaceIsSmall(e.getKey()); } } else { log.error(r.left().getValue()); } if (handler != null) { handler.handle(r); } } }); } }
From source file:org.etourdot.vertx.marklogic.model.client.impl.DocumentImpl.java
License:Open Source License
public DocumentImpl(JsonObject jsonObject) { this();/*from ww w. j a v a2 s .c o m*/ requireNonNull(jsonObject); ofNullable(jsonObject.getString(URI)).ifPresent(this::uri); ofNullable(jsonObject.getValue(CONTENT)).ifPresent(this::contentObject); ofNullable(jsonObject.getJsonArray(COLLECTIONS)).ifPresent(this::collections); ofNullable(jsonObject.getJsonArray(PERMISSIONS)).ifPresent(this::permissions); ofNullable(jsonObject.getInteger(QUALITY)).ifPresent(this::quality); ofNullable(jsonObject.getJsonObject(PROPERTIES)).ifPresent(this::properties); ofNullable(jsonObject.getString(EXTENSION)).ifPresent(this::extension); ofNullable(jsonObject.getString(DIRECTORY)).ifPresent(this::directory); ofNullable(jsonObject.getLong(VERSION)).ifPresent(this::version); ofNullable(jsonObject.getString(EXTRACT)).ifPresent(this::extract); ofNullable(jsonObject.getString(LANG)).ifPresent(this::lang); ofNullable(jsonObject.getString(REPAIR)).ifPresent(this::repair); ofNullable(jsonObject.getString(FORMAT)).ifPresent(this::format); ofNullable(jsonObject.getString(MIME_TYPE)).ifPresent(this::contentType); if (!hasContentType()) { contentType(jsonObject.getString(CONTENT_TYPE)); } forceFormatOrContentType(); }
From source file:org.etourdot.vertx.marklogic.model.options.SearchOptions.java
License:Open Source License
public SearchOptions(JsonObject jsonObject) { this();/*from w ww . j a v a 2s . c om*/ requireNonNull(jsonObject); ofNullable(jsonObject.getJsonArray(CATEGORIES)).ifPresent(this::categories); ofNullable(jsonObject.getJsonArray(COLLECTIONS)).ifPresent(this::collections); ofNullable(jsonObject.getString(DIRECTORY)).ifPresent(this::directory); ofNullable(jsonObject.getLong(START)).ifPresent(this::start); ofNullable(jsonObject.getLong(PAGELEN)).ifPresent(this::pageLen); ofNullable(jsonObject.getString(VIEW)).ifPresent(this::view); ofNullable(jsonObject.getString(EXPRESSION)).ifPresent(this::expression); ofNullable(jsonObject.getJsonObject(QBE)).ifPresent(this::qbe); ofNullable(jsonObject.getJsonObject(STRUCT_QUERY)).ifPresent(this::structuredQuery); }
From source file:org.sfs.filesystem.volume.HeaderBlob.java
License:Apache License
public HeaderBlob(JsonObject jsonObject) { this.volume = jsonObject.getString(X_CONTENT_VOLUME); this.position = jsonObject.getLong(X_CONTENT_POSITION); this.length = jsonObject.getLong(X_CONTENT_LENGTH); }