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.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 w  w. ja v a 2 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

protected void addSubject(String id, JsonObject currentEntity) {
    String subjectId = subjectsMapping.get(currentEntity.getString("Code"));
    if (isEmpty(subjectId)) {
        final String externalId = structureExternalId + "$" + currentEntity.getString("Code");
        subjectId = UUID.randomUUID().toString();
        txXDT.add(CREATE_SUBJECT,/*w  w w.j a  v a2s.c o  m*/
                currentEntity.put("structureExternalId", structureExternalId).put("externalId", externalId)
                        .put("id", subjectId).put("source", getSource()).put("now", importTimestamp));
    }
    subjects.put(id, subjectId);
}

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

License:Open Source License

protected void persistCourse(JsonObject object) {
    if (object == null) {
        return;//from w  w  w  .  jav  a2 s  .  c  o  m
    }
    persEducNatToClasses(object);
    persEducNatToGroups(object);
    persEducNatToSubjects(object);
    object.put("pending", importTimestamp);
    final int currentCount = countMongoQueries.incrementAndGet();
    JsonObject m = new JsonObject().put("$set", object).put("$setOnInsert",
            new JsonObject().put("created", importTimestamp));
    coursesBuffer.add(new JsonObject().put("operation", "upsert").put("document", m).put("criteria",
            new JsonObject().put("_id", object.getString("_id"))));

    if (currentCount % 1000 == 0) {
        persistBulKCourses();
    }
}