Example usage for io.vertx.core.eventbus Message body

List of usage examples for io.vertx.core.eventbus Message body

Introduction

In this page you can find the example usage for io.vertx.core.eventbus Message body.

Prototype

@CacheReturn
T body();

Source Link

Document

The body of the message.

Usage

From source file:org.entcore.feeder.ManualFeeder.java

License:Open Source License

public void addUserGroup(Message<JsonObject> message) {
    final String userId = getMandatoryString("userId", message);
    final String groupId = message.body().getString("groupId");
    if (userId == null || groupId == null)
        return;// w w w .  j a  va 2 s .  co  m
    executeTransaction(message, new VoidFunction<TransactionHelper>() {
        @Override
        public void apply(TransactionHelper tx) {
            User.addGroup(userId, groupId, tx);
        }
    });
}

From source file:org.entcore.feeder.ManualFeeder.java

License:Open Source License

public void removeUserGroup(Message<JsonObject> message) {
    final String userId = getMandatoryString("userId", message);
    final String groupId = message.body().getString("groupId");
    if (userId == null || groupId == null)
        return;//from   w w w . java  2 s . co m
    executeTransaction(message, new VoidFunction<TransactionHelper>() {
        @Override
        public void apply(TransactionHelper tx) {
            User.removeGroup(userId, groupId, tx);
        }
    });
}

From source file:org.entcore.feeder.ManualFeeder.java

License:Open Source License

public void createGroup(Message<JsonObject> message) {
    final JsonObject group = message.body().getJsonObject("group");
    if (group == null || group.size() == 0) {
        sendError(message, "missing.group");
        return;/*from  w w  w  .jav a2s. c o m*/
    }
    final String structureId = message.body().getString("structureId");
    final String classId = message.body().getString("classId");
    executeTransaction(message, new VoidFunction<TransactionHelper>() {
        @Override
        public void apply(TransactionHelper tx) throws ValidationException {
            Group.manualCreateOrUpdate(group, structureId, classId, tx);
        }
    });
}

From source file:org.entcore.feeder.ManualFeeder.java

License:Open Source License

public void addGroupUsers(Message<JsonObject> message) {
    final String groupId = getMandatoryString("groupId", message);
    final JsonArray userIds = message.body().getJsonArray("userIds");

    if (userIds == null || groupId == null)
        return;/*ww w.j a v a2 s. com*/

    executeTransaction(message, new VoidFunction<TransactionHelper>() {
        @Override
        public void apply(TransactionHelper tx) {
            Group.addUsers(groupId, userIds, tx);
        }
    });
}

From source file:org.entcore.feeder.ManualFeeder.java

License:Open Source License

public void removeGroupUsers(Message<JsonObject> message) {
    final String groupId = getMandatoryString("groupId", message);
    final JsonArray userIds = message.body().getJsonArray("userIds");

    if (userIds == null || groupId == null)
        return;//w w  w .  ja v  a2 s. c  o m

    executeTransaction(message, new VoidFunction<TransactionHelper>() {
        @Override
        public void apply(TransactionHelper tx) {
            Group.removeUsers(groupId, userIds, tx);
        }
    });
}

From source file:org.entcore.feeder.ManualFeeder.java

License:Open Source License

public void updateStructure(final Message<JsonObject> message) {
    JsonObject s = getMandatoryObject("data", message);
    if (s == null)
        return;/*w  w w .  j  ava2  s.  co  m*/
    String structureId = getMandatoryString("structureId", message);
    if (structureId == null)
        return;
    final String error = structureValidator.modifiableValidate(s);
    if (error != null) {
        logger.error(error);
        sendError(message, error);
    } else {
        String query;
        JsonObject params = s.copy().put("structureId", structureId);
        if (s.getString("name") != null) {
            query = "MATCH (s:`Structure` { id : {structureId}})<-[:DEPENDS]-(g:Group) "
                    + "WHERE last(split(g.name, '-')) IN ['Student','Teacher','Personnel','Relative','Guest','AdminLocal','HeadTeacher', 'SCOLARITE'] "
                    + "SET g.name = {name} + '-' + last(split(g.name, '-')), g.displayNameSearchField = {sanitizeName}, ";
            params.put("sanitizeName", Validator.sanitize(s.getString("name")));
        } else {
            query = "MATCH (s:`Structure` { id : {structureId}}) SET";

        }
        query = query + Neo4jUtils.nodeSetPropertiesFromJson("s", s) + "RETURN DISTINCT s.id as id ";

        neo4j.execute(query, params, new Handler<Message<JsonObject>>() {
            @Override
            public void handle(Message<JsonObject> m) {
                message.reply(m.body());
            }
        });
    }
}

From source file:org.entcore.feeder.timetable.AbstractTimetableImporter.java

License:Open Source License

protected void init(final Handler<AsyncResult<Void>> handler) throws TransactionException {
    importTimestamp = System.currentTimeMillis();
    final String externalIdFromUAI = "MATCH (s:Structure {UAI : {UAI}}) "
            + "return s.externalId as externalId, s.id as id, s.timetable as timetable ";
    final String tma = getTeacherMappingAttribute();
    final String getUsersByProfile = "MATCH (:Structure {UAI : {UAI}})<-[:DEPENDS]-(:ProfileGroup)<-[:IN]-(u:User) "
            + "WHERE head(u.profiles) = {profile} AND NOT(u." + tma + " IS NULL) "
            + "RETURN DISTINCT u.id as id, u." + tma
            + " as tma, head(u.profiles) as profile, u.source as source, "
            + "u.lastName as lastName, u.firstName as firstName";
    final String classesMappingQuery = "MATCH (s:Structure {UAI : {UAI}})<-[:MAPPING]-(cm:ClassesMapping) "
            + "return cm.mapping as mapping ";
    final String subjectsMappingQuery = "MATCH (s:Structure {UAI : {UAI}})<-[:SUBJECT]-(sub:Subject) return sub.code as code, sub.id as id";
    final TransactionHelper tx = TransactionManager.getTransaction();
    tx.add(getUsersByProfile, new JsonObject().put("UAI", UAI).put("profile", "Teacher"));
    tx.add(externalIdFromUAI, new JsonObject().put("UAI", UAI));
    tx.add(classesMappingQuery, new JsonObject().put("UAI", UAI));
    tx.add(subjectsMappingQuery, new JsonObject().put("UAI", UAI));
    tx.commit(new Handler<Message<JsonObject>>() {
        @Override//from w  ww .j  a  v  a2  s .c o  m
        public void handle(Message<JsonObject> event) {
            final JsonArray res = event.body().getJsonArray("results");
            if ("ok".equals(event.body().getString("status")) && res != null && res.size() == 4) {
                try {
                    for (Object o : res.getJsonArray(0)) {
                        if (o instanceof JsonObject) {
                            final JsonObject j = (JsonObject) o;
                            teachersMapping.put(j.getString("tma"),
                                    new String[] { j.getString("id"), j.getString("source") });
                            teachersCleanNameMapping.put(
                                    Validator.sanitize(j.getString("firstName") + j.getString("lastName")),
                                    new String[] { j.getString("id"), j.getString("source") });
                        }
                    }
                    JsonArray a = res.getJsonArray(1);
                    if (a != null && a.size() == 1) {
                        structureExternalId = a.getJsonObject(0).getString("externalId");
                        structure.add(structureExternalId);
                        structureId = a.getJsonObject(0).getString("id");
                        if (!getSource().equals(a.getJsonObject(0).getString("timetable"))) {
                            handler.handle(new DefaultAsyncResult<Void>(
                                    new TransactionException("different.timetable.type")));
                            return;
                        }
                    } else {
                        handler.handle(new DefaultAsyncResult<Void>(new ValidationException("invalid.uai")));
                        return;
                    }
                    JsonArray cm = res.getJsonArray(2);
                    if (cm != null && cm.size() == 1) {
                        try {
                            final JsonObject cmn = cm.getJsonObject(0);
                            log.info(cmn.encode());
                            if (isNotEmpty(cmn.getString("mapping"))) {
                                classesMapping = new JsonObject(cmn.getString("mapping"));
                                log.info("classMapping : " + classesMapping.encodePrettily());
                            } else {
                                classesMapping = new JsonObject();
                            }
                        } catch (Exception ecm) {
                            classesMapping = new JsonObject();
                            log.error(ecm.getMessage(), ecm);
                        }
                    }
                    JsonArray subjects = res.getJsonArray(3);
                    if (subjects != null && subjects.size() > 0) {
                        for (Object o : subjects) {
                            if (o instanceof JsonObject) {
                                final JsonObject s = (JsonObject) o;
                                subjectsMapping.put(s.getString("code"), s.getString("id"));
                            }
                        }
                    }
                    txXDT = TransactionManager.getTransaction();
                    persEducNat = new PersEducNat(txXDT, report, getSource());
                    persEducNat.setMapping(
                            "dictionary/mapping/" + getSource().toLowerCase() + "/PersEducNat.json");
                    handler.handle(new DefaultAsyncResult<>((Void) null));
                } catch (Exception e) {
                    handler.handle(new DefaultAsyncResult<Void>(e));
                }
            } else {
                handler.handle(new DefaultAsyncResult<Void>(
                        new TransactionException(event.body().getString("message"))));
            }
        }
    });
}

From source file:org.entcore.feeder.timetable.AbstractTimetableImporter.java

License:Open Source License

private void persistBulKCourses() {
    final JsonArray cf = coursesBuffer;
    coursesBuffer = new fr.wseduc.webutils.collections.JsonArray();
    final int countCoursesBuffer = cf.size();
    if (countCoursesBuffer > 0) {
        mongoDb.bulk(COURSES, cf, new Handler<Message<JsonObject>>() {
            @Override//from  ww  w  .ja va 2 s.  com
            public void handle(Message<JsonObject> event) {
                if (!"ok".equals(event.body().getString("status"))) {
                    if (event.body().getString("message") == null
                            || !event.body().getString("message").contains("duplicate key error")) {
                        report.addError("error.persist.course");
                    } else {
                        log.warn("Duplicate courses keys.");
                    }
                }
                if (countMongoQueries.addAndGet(-countCoursesBuffer) == 0) {
                    end();
                }
            }
        });
    }
}

From source file:org.entcore.feeder.timetable.AbstractTimetableImporter.java

License:Open Source License

private void end() {
    if (endHandler != null && countMongoQueries.get() == 0) {
        final JsonObject baseQuery = new JsonObject().put("structureId", structureId);
        if (txSuccess) {
            mongoDb.update(COURSES, baseQuery.copy().put("pending", importTimestamp),
                    new JsonObject().put("$rename", new JsonObject().put("pending", "modified")), false, true,
                    new Handler<Message<JsonObject>>() {
                        @Override
                        public void handle(Message<JsonObject> event) {
                            if ("ok".equals(event.body().getString("status"))) {
                                mongoDb.update(COURSES,
                                        baseQuery.copy().put("deleted", new JsonObject().put("$exists", false))
                                                .put("modified", new JsonObject().put("$ne", importTimestamp)),
                                        new JsonObject().put("$set",
                                                new JsonObject().put("deleted", importTimestamp)),
                                        false, true, new Handler<Message<JsonObject>>() {
                                            @Override
                                            public void handle(Message<JsonObject> event) {
                                                if (!"ok".equals(event.body().getString("status"))) {
                                                    report.addError("error.set.deleted.courses");
                                                }
                                                endHandler.handle(new DefaultAsyncResult<>(report));
                                            }
                                        });
                            } else {
                                report.addError("error.renaming.pending");
                                endHandler.handle(new DefaultAsyncResult<>(report));
                            }/*from   ww w . ja  v a2 s .c o  m*/
                        }
                    });
        } else {
            mongoDb.delete(COURSES, baseQuery.copy().put("pending", importTimestamp).put("modified",
                    new JsonObject().put("$exists", false)), new Handler<Message<JsonObject>>() {
                        @Override
                        public void handle(Message<JsonObject> event) {
                            if ("ok".equals(event.body().getString("status"))) {
                                mongoDb.update(COURSES, baseQuery.copy().put("pending", importTimestamp),
                                        new JsonObject().put("$unset", new JsonObject().put("pending", "")),
                                        false, true, new Handler<Message<JsonObject>>() {
                                            @Override
                                            public void handle(Message<JsonObject> event) {
                                                if (!"ok".equals(event.body().getString("status"))) {
                                                    report.addError("error.unset.pending");
                                                }
                                                endHandler.handle(new DefaultAsyncResult<>(report));
                                            }
                                        });
                            } else {
                                report.addError("error.removing.inconsistencies.courses");
                                endHandler.handle(new DefaultAsyncResult<>(report));
                            }
                        }
                    });
        }
    }
}

From source file:org.entcore.feeder.timetable.AbstractTimetableImporter.java

License:Open Source License

public static void transition(final String structureExternalId) {
    if (isNotEmpty(structureExternalId)) {
        final String query = "MATCH (s:Structure {externalId: {externalId}}) RETURN s.id as structureId";
        final JsonObject params = new JsonObject().put("externalId", structureExternalId);
        TransactionManager.getNeo4jHelper().execute(query, params, new Handler<Message<JsonObject>>() {
            @Override// w ww .ja  va2s  .  c o  m
            public void handle(Message<JsonObject> event) {
                final JsonArray res = event.body().getJsonArray("result");
                if ("ok".equals(event.body().getString("status")) && res != null && res.size() > 0) {
                    transitionDeleteCourses(res.getJsonObject(0));
                    transitionDeleteSubjectsAndMapping(structureExternalId);
                }
            }
        });
    } else {
        transitionDeleteCourses(new JsonObject());
        transitionDeleteSubjectsAndMapping(structureExternalId);
    }
}