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

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

Introduction

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

Prototype

public JsonArray getJsonArray(String key) 

Source Link

Document

Get the JsonArray value with the specified key

Usage

From source file:org.entcore.feeder.export.eliot.BaseExportProcessing.java

License:Open Source License

private void writeElement(XMLEventWriter writer, XMLEventFactory eventFactory, JsonObject element)
        throws XMLStreamException {
    if (element.getJsonArray("joinKey") == null && element.getString("externalId") != null) {
        element.put("joinKey",
                new fr.wseduc.webutils.collections.JsonArray().add(element.getString("externalId")));
    }/*from ww w.  jav a2  s . c o  m*/
    writer.add(eventFactory.createStartElement("", "", "addRequest"));
    writer.add(eventFactory.createDTD("\n"));
    writer.add(eventFactory.createStartElement("", "", "operationalAttributes"));
    writer.add(eventFactory.createStartElement("", "", "attr"));
    process(writer, eventFactory);
    writer.add(eventFactory.createEndElement("", "", "attr"));
    writer.add(eventFactory.createEndElement("", "", "operationalAttributes"));
    writer.add(eventFactory.createDTD("\n"));
    writer.add(eventFactory.createStartElement("", "", "identifier"));
    writer.add(eventFactory.createStartElement("", "", "id"));
    writer.add(eventFactory.createCharacters(element.getString("externalId")));
    writer.add(eventFactory.createEndElement("", "", "id"));
    writer.add(eventFactory.createEndElement("", "", "identifier"));
    writer.add(eventFactory.createDTD("\n"));
    writer.add(eventFactory.createStartElement("", "", "attributes"));
    writer.add(eventFactory.createDTD("\n"));
    for (String attr : exportMapping.fieldNames()) {
        Object mapping = exportMapping.getValue(attr);
        Object value = element.getValue(attr);
        if (mapping instanceof JsonObject) {
            addAttribute((JsonObject) mapping, value, writer, eventFactory);
        } else {
            for (Object o : ((JsonArray) mapping)) {
                if (!(o instanceof JsonObject))
                    continue;
                addAttribute((JsonObject) o, value, writer, eventFactory);
            }
        }
    }
    writer.add(eventFactory.createEndElement("", "", "attributes"));
    writer.add(eventFactory.createDTD("\n"));
    writer.add(eventFactory.createEndElement("", "", "addRequest"));
    writer.add(eventFactory.createDTD("\n\n"));
}

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

License:Open Source License

private void validateAndImport(final Message<JsonObject> message, final Feed feed, final boolean preDelete,
        final String structureExternalId, final String source) {
    launchImportValidation(message, new Handler<Report>() {
        @Override/*www.  j  ava  2  s.  co  m*/
        public void handle(final Report report) {
            if (report != null && !report.containsErrors()) {
                doImport(message, feed, new Handler<Report>() {
                    @Override
                    public void handle(final Report importReport) {
                        if (importReport == null) {
                            sendError(message, "import.error");
                            return;
                        }
                        final JsonObject ir = importReport.getResult();
                        final JsonArray existingUsers = ir.getJsonArray("usersExternalIds");
                        final JsonArray profiles = ir.getJsonArray(Report.PROFILES);
                        if (preDelete && structureExternalId != null && existingUsers != null
                                && existingUsers.size() > 0 && !importReport.containsErrors()) {
                            new User.PreDeleteTask(0).preDeleteMissingUsersInStructure(structureExternalId,
                                    source, existingUsers, profiles, new Handler<Message<JsonObject>>() {
                                        @Override
                                        public void handle(Message<JsonObject> event) {
                                            if (!"ok".equals(event.body().getString("status"))) {
                                                importReport.addError("preDelete.error");
                                            }
                                            sendOK(message,
                                                    new JsonObject().put("result", importReport.getResult()));
                                        }
                                    });
                        } else {
                            sendOK(message, new JsonObject().put("result", importReport.getResult()));
                        }
                    }
                });
            } else if (report != null) {
                sendOK(message, new JsonObject().put("result", report.getResult()));
            } else {
                sendError(message, "validation.error");
            }
        }
    });
}

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

License:Open Source License

public void createUser(final Message<JsonObject> message) {
    final JsonObject user = getMandatoryObject("data", message);
    if (user == null)
        return;//from   w  w  w  .  jav  a2 s  . com
    if (user.getString("externalId") == null) {
        user.put("externalId", UUID.randomUUID().toString());
    }
    final String profile = message.body().getString("profile", "");
    if (!profiles.containsKey(profile)) {
        sendError(message, "Invalid profile : " + profile);
        return;
    }
    JsonArray childrenIds = null;
    if ("Relative".equals(profile)) {
        childrenIds = user.getJsonArray("childrenIds");
    }
    final String error = profiles.get(profile).validate(user);
    if (error != null) {
        logger.error(error);
        sendError(message, error);
        return;
    }
    user.put("source", SOURCE);
    final String structureId = message.body().getString("structureId");
    if (structureId != null && !structureId.trim().isEmpty()) {
        createUserInStructure(message, user, profile, structureId, childrenIds);
        return;
    }
    final String classId = message.body().getString("classId");
    if (classId != null && !classId.trim().isEmpty()) {
        createUserInClass(message, user, profile, classId, childrenIds);
        return;
    }
    sendError(message, "structureId or classId must be specified");
}

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

License:Open Source License

private void persEducNatToClasses(JsonObject object) {
    final JsonArray classes = object.getJsonArray("classes");
    if (classes != null) {
        final JsonObject params = new JsonObject().put("structureExternalId", structureExternalId)
                .put("classes", classes).put("source", getSource())
                .put("outDate", DateTime.now().plusDays(1).getMillis()).put("now", importTimestamp);
        final JsonArray teacherIds = object.getJsonArray("teacherIds");
        if (teacherIds != null && teacherIds.size() > 0) {
            params.put("profile", "Teacher");
            for (Object id : teacherIds) {
                if (id != null) {
                    txXDT.add(PERSEDUCNAT_TO_CLASSES, params.copy().put("id", id.toString()));
                }/*from w w  w .  j  a v a2 s  .c o m*/
            }
        }
        final JsonArray personnelIds = object.getJsonArray("personnelIds");
        if (personnelIds != null && personnelIds.size() > 0) {
            params.put("profile", "Personnel");
            for (Object id : personnelIds) {
                if (id != null) {
                    txXDT.add(PERSEDUCNAT_TO_CLASSES, params.copy().put("id", id.toString()));
                }
            }
        }
    }
}

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

License:Open Source License

private void persEducNatToSubjects(JsonObject object) {
    final String subjectId = object.getString("subjectId");
    final JsonArray teacherIds = object.getJsonArray("teacherIds");
    if (isNotEmpty(subjectId) && teacherIds != null && teacherIds.size() > 0) {
        final JsonObject params = new JsonObject().put("subjectId", subjectId).put("teacherIds", teacherIds)
                .put("classes", object.getJsonArray("classes", new fr.wseduc.webutils.collections.JsonArray()))
                .put("groups", object.getJsonArray("groups", new fr.wseduc.webutils.collections.JsonArray()))
                .put("source", getSource()).put("now", importTimestamp);
        txXDT.add(LINK_SUBJECT, params);
    }/* ww w .ja  v a  2s  . co  m*/
}

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

License:Open Source License

private void persEducNatToGroups(JsonObject object) {
    final JsonArray groups = object.getJsonArray("groups");
    if (groups != null) {
        final JsonArray teacherIds = object.getJsonArray("teacherIds");
        final List<String> ids = new ArrayList<>();
        if (teacherIds != null) {
            ids.addAll(teacherIds.getList());
        }//from  w  ww  .  ja  v  a 2 s  .c  o  m
        final JsonArray personnelIds = object.getJsonArray("personnelIds");
        if (personnelIds != null) {
            ids.addAll(personnelIds.getList());
        }
        if (!ids.isEmpty()) {
            final JsonArray g = new fr.wseduc.webutils.collections.JsonArray();
            for (Object o : groups) {
                g.add(structureExternalId + "$" + o.toString());
            }
            for (String id : ids) {
                txXDT.add(PERSEDUCNAT_TO_GROUPS,
                        new JsonObject().put("groups", g).put("id", id).put("source", getSource())
                                .put("outDate", DateTime.now().plusDays(1).getMillis())
                                .put("now", importTimestamp));
            }
        }
    }
}

From source file:org.entcore.feeder.timetable.edt.EDTImporter.java

License:Open Source License

void initSchedule(JsonObject currentEntity) {
    slotDuration = Integer.parseInt(currentEntity.getString("DureePlace")) * 60;
    for (Object o : currentEntity.getJsonArray("Place")) {
        if (o instanceof JsonObject) {
            JsonObject s = (JsonObject) o;
            slots.put(s.getString("Numero"),
                    new Slot(s.getString("LibelleHeureDebut"), s.getString("LibelleHeureFin"), slotDuration));
        }//w ww.  j  a va2  s  .  c o  m
    }
}

From source file:org.entcore.feeder.timetable.edt.EDTImporter.java

License:Open Source License

void addGroup(JsonObject currentEntity) {
    final String id = currentEntity.getString(IDENT);
    groups.put(id, currentEntity);/*from w w  w  .j a v  a  2s.  c o m*/
    final JsonArray classes = currentEntity.getJsonArray("Classe");
    final JsonArray pcs = currentEntity.getJsonArray("PartieDeClasse");
    classInGroups(id, classes, this.classes);
    classInGroups(id, pcs, this.subClasses);

    final String name = currentEntity.getString("Nom");
    txXDT.add(CREATE_GROUPS,
            new JsonObject().put("structureExternalId", structureExternalId).put("name", name)
                    .put("displayNameSearchField", Validator.sanitize(name))
                    .put("externalId", structureExternalId + "$" + name).put("id", UUID.randomUUID().toString())
                    .put("source", getSource()));
}

From source file:org.entcore.feeder.timetable.edt.EDTImporter.java

License:Open Source License

private void classInGroups(String id, JsonArray classes, Map<String, JsonObject> ref) {
    if (classes != null) {
        for (Object o : classes) {
            if (o instanceof JsonObject) {
                final JsonObject j = ref.get(((JsonObject) o).getString(IDENT));
                if (j != null) {
                    JsonArray groups = j.getJsonArray("groups");
                    if (groups == null) {
                        groups = new fr.wseduc.webutils.collections.JsonArray();
                        j.put("groups", groups);
                    }/*from w  ww .j  a v a2s . c o  m*/
                    groups.add(id);
                }
            }
        }
    }
}

From source file:org.entcore.feeder.timetable.edt.EDTImporter.java

License:Open Source License

void addClasse(JsonObject currentEntity) {
    final String id = currentEntity.getString(IDENT);
    classes.put(id, currentEntity);/*from   ww  w  .j  a  v a 2s  .com*/
    final JsonArray pcs = currentEntity.getJsonArray("PartieDeClasse");
    final String ocn = currentEntity.getString("Nom");
    final String className = (classesMapping != null) ? getOrElse(classesMapping.getString(ocn), ocn, false)
            : ocn;
    currentEntity.put("className", className);
    if (pcs != null) {
        for (Object o : pcs) {
            if (o instanceof JsonObject) {
                final String pcIdent = ((JsonObject) o).getString(IDENT);
                subClasses.put(pcIdent, ((JsonObject) o).put("className", className));
            }
        }
    }
    if (className != null) {
        txXDT.add(UNKNOWN_CLASSES, new JsonObject().put("UAI", UAI).put("className", className));
    }
}