List of usage examples for io.vertx.core.json JsonArray size
public int size()
From source file:org.entcore.feeder.aaf.StudentImportProcessing.java
License:Open Source License
protected String[][] createClasses(JsonArray classes) { String[][] linkStructureClasses = null; if (classes != null && classes.size() > 0) { linkStructureClasses = new String[classes.size()][2]; int i = 0; for (Object o : classes) { if (!(o instanceof String)) continue; String[] c = ((String) o).split("\\$"); if (c.length == 2) { Structure s = importer.getStructure(c[0]); if (s != null) { String classExternalId = s.getExternalId() + "$" + c[1]; s.createClassIfAbsent(classExternalId, c[1]); linkStructureClasses[i][0] = s.getExternalId(); linkStructureClasses[i++][1] = classExternalId; }//from w ww . j a va 2 s. c o m } } } return linkStructureClasses; }
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 {//from w w w.ja va 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.aaf1d.StudentImportProcessing1d.java
License:Open Source License
static JsonArray parseRelativeField1d(JsonArray relative) { JsonArray res = null;/* www . j ava 2 s. c om*/ if (relative != null && relative.size() > 0) { res = new fr.wseduc.webutils.collections.JsonArray(); for (Object o : relative) { if (!(o instanceof String)) continue; String[] r = ((String) o).split("\\$"); res.add(r[0]); } } return res; }
From source file:org.entcore.feeder.aaf1d.StudentImportProcessing1d.java
License:Open Source License
static String[][] createGroups(JsonArray groups, Importer importer, String academyPrefix) { String[][] linkStructureGroups = null; if (groups != null && groups.size() > 0) { linkStructureGroups = new String[groups.size()][2]; int i = 0; for (Object o : groups) { if (!(o instanceof String)) continue; String[] g = ((String) o).split("\\$"); if (g.length == 5) { Structure s = importer.getStructure(g[0]); if (s != null) { String groupExternalId = academyPrefix + g[3]; s.createFunctionalGroupIfAbsent(groupExternalId, g[4]); linkStructureGroups[i][0] = s.getExternalId(); linkStructureGroups[i++][1] = groupExternalId; }// w w w . j a v a 2 s . c o m } } } return linkStructureGroups; }
From source file:org.entcore.feeder.aaf1d.StudentImportProcessing1d.java
License:Open Source License
@Override protected String[][] createClasses(JsonArray classes) { String[][] linkStructureClasses = null; if (classes != null && classes.size() > 0) { linkStructureClasses = new String[classes.size()][2]; int i = 0; for (Object o : classes) { if (!(o instanceof String)) continue; String[] c = ((String) o).split("\\$"); if (c.length == 5) { Structure s = importer.getStructure(c[0]); if (s != null) { String classExternalId = getAcademyPrefix() + c[3]; s.createClassIfAbsent(classExternalId, c[4]); linkStructureClasses[i][0] = s.getExternalId(); linkStructureClasses[i++][1] = classExternalId; }// ww w .j a v a2 s . c o m } } } return linkStructureClasses; }
From source file:org.entcore.feeder.aaf1d.StudentImportProcessing1d2.java
License:Open Source License
@Override protected String[][] createClasses(JsonArray classes) { String[][] linkStructureClasses = null; if (classes != null && classes.size() > 0) { linkStructureClasses = new String[classes.size()][2]; int i = 0; for (Object o : classes) { if (!(o instanceof String)) continue; String[] c = ((String) o).split("\\$"); if (c.length == 5) { Structure s = importer.getStructure(c[0]); if (s != null) { String classExternalId = c[3]; s.createClassIfAbsent(classExternalId, c[4]); linkStructureClasses[i][0] = s.getExternalId(); linkStructureClasses[i++][1] = classExternalId; }// ww w . java2s .co m } } } return linkStructureClasses; }
From source file:org.entcore.feeder.csv.CsvFeeder.java
License:Open Source License
private void queryNotModifiableIds(final Handler<Message<JsonObject>> handler, JsonArray externalIds) { if (externalIds.size() > 0) { String query = "MATCH (u:User) where u.externalId IN {ids} AND u.source IN ['AAF', 'AAF1D'] " + "AND NOT(HAS(u.deleteDate)) AND NOT(HAS(u.disappearanceDate)) " + "RETURN COLLECT(u.externalId) as ids"; TransactionManager.getNeo4jHelper().execute(query, new JsonObject().put("ids", externalIds), new Handler<Message<JsonObject>>() { @Override/*from w w w . j a v a 2s. co m*/ public void handle(Message<JsonObject> event) { if ("ok".equals(event.body().getString("status"))) { JsonArray res = event.body().getJsonArray("result"); JsonArray ids; if (res != null && res.size() > 0 && res.getJsonObject(0) != null && (ids = res.getJsonObject(0).getJsonArray("ids")) != null && ids.size() > 0) { handler.handle( new ResultMessage().error("unmodifiable.externalId-" + ids.encode())); } else { handler.handle(new ResultMessage()); } } else { handler.handle(event); } } }); } else { handler.handle(new ResultMessage()); } }
From source file:org.entcore.feeder.csv.CsvFeeder.java
License:Open Source License
public void start(final String profile, final Structure structure, String file, String charset, final Importer importer, final Handler<Message<JsonObject>> handler) { importer.getReport().addProfile(profile); importer.createOrUpdateProfile(STUDENT_PROFILE); importer.createOrUpdateProfile(RELATIVE_PROFILE); importer.createOrUpdateProfile(PERSONNEL_PROFILE); importer.createOrUpdateProfile(TEACHER_PROFILE); importer.createOrUpdateProfile(GUEST_PROFILE); DefaultFunctions.createOrUpdateFunctions(importer); final Validator validator = ManualFeeder.profiles.get(profile); // final Structure structure = importer.getStructure(structureExternalId); // if (structure == null) { // handler.handle(new ResultMessage().error("invalid.structure")); // return; // }/*from w w w.j a v a2s . co m*/ try { CSVReader csvParser = getCsvReader(file, charset); final List<String> columns = new ArrayList<>(); int nbColumns = 0; String[] strings; int i = 0; csvParserWhile: while ((strings = csvParser.readNext()) != null) { if (i == 0) { columnsMapper.getColumsNames(strings, columns, profile, handler); nbColumns = columns.size(); } else if (!columns.isEmpty()) { if (emptyLine(strings)) { i++; continue; } if (strings.length > nbColumns) { strings = Arrays.asList(strings).subList(0, nbColumns).toArray(new String[nbColumns]); } JsonObject user = new JsonObject(); user.put("structures", new fr.wseduc.webutils.collections.JsonArray().add(structure.getExternalId())); user.put("profiles", new fr.wseduc.webutils.collections.JsonArray().add(profile)); List<String[]> classes = new ArrayList<>(); // Class Admin if (isNotEmpty(structure.getOverrideClass())) { String eId = structure.getOverrideClass(); // structure.getExternalId() + '$' + structure.getOverrideClass(); //structure.createClassIfAbsent(eId, structure.getOverrideClass()); final String[] classId = new String[3]; classId[0] = structure.getExternalId(); classId[1] = eId; classId[2] = ""; classes.add(classId); } for (int j = 0; j < strings.length; j++) { final String c = columns.get(j); final String v = strings[j].trim(); if ((v.isEmpty() && !c.startsWith("child")) || ("classes".equals(c) && isNotEmpty(structure.getOverrideClass()))) continue; switch (validator.getType(c)) { case "string": if ("birthDate".equals(c)) { Matcher m = frenchDatePatter.matcher(v); if (m.find()) { user.put(c, m.group(3) + "-" + m.group(2) + "-" + m.group(1)); } else { user.put(c, v); } } else { user.put(c, v); } break; case "array-string": JsonArray a = user.getJsonArray(c); if (a == null) { a = new fr.wseduc.webutils.collections.JsonArray(); user.put(c, a); } if (("classes".equals(c) || "subjectTaught".equals(c) || "functions".equals(c)) && !v.startsWith(structure.getExternalId() + "$")) { a.add(structure.getExternalId() + "$" + v); } else { a.add(v); } break; case "boolean": user.put(c, "true".equals(v.toLowerCase())); break; default: Object o = user.getValue(c); final String v2; if ("childClasses".equals(c) && !v.startsWith(structure.getExternalId() + "$")) { v2 = structure.getExternalId() + "$" + v; } else { v2 = v; } if (o != null) { if (o instanceof JsonArray) { ((JsonArray) o).add(v2); } else { JsonArray array = new fr.wseduc.webutils.collections.JsonArray(); array.add(o).add(v2); user.put(c, array); } } else { user.put(c, v2); } } if ("classes".equals(c)) { String[] cc = v.split("\\$"); if (cc.length == 2 && !cc[1].matches("[0-9]+")) { final String fosEId = importer.getFieldOfStudy().get(cc[1]); if (fosEId != null) { cc[1] = fosEId; } } String eId = structure.getExternalId() + '$' + cc[0]; structure.createClassIfAbsent(eId, cc[0]); final String[] classId = new String[3]; classId[0] = structure.getExternalId(); classId[1] = eId; classId[2] = (cc.length == 2) ? cc[1] : ""; classes.add(classId); } } String ca; long seed; JsonArray classesA; Object co = user.getValue("classes"); if (co != null && co instanceof JsonArray) { classesA = (JsonArray) co; } else if (co instanceof String) { classesA = new fr.wseduc.webutils.collections.JsonArray().add(co); } else { classesA = null; } if ("Student".equals(profile) && classesA != null && classesA.size() == 1) { seed = defaultStudentSeed; ca = classesA.getString(0); } else { ca = String.valueOf(i); seed = System.currentTimeMillis(); } generateUserExternalId(user, ca, structure, seed); if ("Student".equals(profile)) { studentExternalIdMapping.put(getHashMapping(user, ca, structure, seed), user.getString("externalId")); } switch (profile) { case "Teacher": importer.createOrUpdatePersonnel(user, TEACHER_PROFILE_EXTERNAL_ID, user.getJsonArray("structures"), classes.toArray(new String[classes.size()][2]), null, true, true); break; case "Personnel": importer.createOrUpdatePersonnel(user, PERSONNEL_PROFILE_EXTERNAL_ID, user.getJsonArray("structures"), classes.toArray(new String[classes.size()][2]), null, true, true); break; case "Student": importer.createOrUpdateStudent(user, STUDENT_PROFILE_EXTERNAL_ID, null, null, classes.toArray(new String[classes.size()][2]), null, null, true, true); break; case "Relative": if (("Intitul".equals(strings[0]) && "Adresse Organisme".equals(strings[1])) || ("".equals(strings[0]) && "Intitul".equals(strings[1]) && "Adresse Organisme".equals(strings[2]))) { break csvParserWhile; } JsonArray linkStudents = new fr.wseduc.webutils.collections.JsonArray(); for (String attr : user.fieldNames()) { if ("childExternalId".equals(attr)) { Object o = user.getValue(attr); if (o instanceof JsonArray) { for (Object c : (JsonArray) o) { if (c instanceof String && !((String) c).trim().isEmpty()) { linkStudents.add(c); } } } else if (o instanceof String && !((String) o).trim().isEmpty()) { linkStudents.add(o); } } else if ("childUsername".equals(attr)) { Object childUsername = user.getValue(attr); Object childLastName = user.getValue("childLastName"); Object childFirstName = user.getValue("childFirstName"); Object childClasses; if (isNotEmpty(structure.getOverrideClass())) { childClasses = structure.getOverrideClass(); } else { childClasses = user.getValue("childClasses"); } if (childUsername instanceof JsonArray && childLastName instanceof JsonArray && childFirstName instanceof JsonArray && childClasses instanceof JsonArray && ((JsonArray) childClasses).size() == ((JsonArray) childLastName).size() && ((JsonArray) childFirstName).size() == ((JsonArray) childLastName) .size()) { for (int j = 0; j < ((JsonArray) childUsername).size(); j++) { String mapping = structure.getExternalId() + ((JsonArray) childUsername).getString(j).trim() + ((JsonArray) childLastName).getString(j).trim() + ((JsonArray) childFirstName).getString(j).trim() + ((JsonArray) childClasses).getString(j).trim() + defaultStudentSeed; relativeStudentMapping(linkStudents, mapping); } } else if (childUsername instanceof String && childLastName instanceof String && childFirstName instanceof String && childClasses instanceof String) { String mapping = structure.getExternalId() + childLastName.toString().trim() + childFirstName.toString().trim() + childClasses.toString().trim() + defaultStudentSeed; relativeStudentMapping(linkStudents, mapping); } else { handler.handle(new ResultMessage().error("invalid.child.mapping")); return; } } else if ("childLastName".equals(attr) && !user.fieldNames().contains("childUsername")) { Object childLastName = user.getValue(attr); Object childFirstName = user.getValue("childFirstName"); Object childClasses; if (isNotEmpty(structure.getOverrideClass())) { childClasses = structure.getOverrideClass(); } else { childClasses = user.getValue("childClasses"); } if (childLastName instanceof JsonArray && childFirstName instanceof JsonArray && childClasses instanceof JsonArray && ((JsonArray) childClasses).size() == ((JsonArray) childLastName).size() && ((JsonArray) childFirstName).size() == ((JsonArray) childLastName) .size()) { for (int j = 0; j < ((JsonArray) childLastName).size(); j++) { String mapping = structure.getExternalId() + ((JsonArray) childLastName).getString(j).trim() + ((JsonArray) childFirstName).getString(j).trim() + ((JsonArray) childClasses).getString(j).trim() + defaultStudentSeed; relativeStudentMapping(linkStudents, mapping); } } else if (childLastName instanceof String && childFirstName instanceof String && childClasses instanceof String) { String mapping = structure.getExternalId() + childLastName.toString().trim() + childFirstName.toString().trim() + childClasses.toString().trim() + defaultStudentSeed; relativeStudentMapping(linkStudents, mapping); } else { handler.handle(new ResultMessage().error("invalid.child.mapping")); return; } } } importer.createOrUpdateUser(user, linkStudents, true); break; case "Guest": importer.createOrUpdateGuest(user, classes.toArray(new String[classes.size()][2])); break; } } i++; } switch (profile) { case "Teacher": importer.getPersEducNat().createAndLinkSubjects(structure.getExternalId()); break; case "Relative": importer.linkRelativeToClass(RELATIVE_PROFILE_EXTERNAL_ID, null, structure.getExternalId()); importer.linkRelativeToStructure(RELATIVE_PROFILE_EXTERNAL_ID, null, structure.getExternalId()); importer.addRelativeProperties(getSource()); break; } } catch (Exception e) { handler.handle(new ResultMessage().error("csv.exception")); log.error("csv.exception", e); } // importer.markMissingUsers(structure.getExternalId(), new Handler<Void>() { // @Override // public void handle(Void event) { // importer.persist(handler); // } // }); // importer.persist(handler); }
From source file:org.entcore.feeder.csv.CsvImportsLauncher.java
License:Open Source License
@Override public void handle(Long event) { final FileSystem fs = vertx.fileSystem(); fs.readDir(path, ".*.zip", new Handler<AsyncResult<List<String>>>() { @Override// ww w. j av a 2s . c om public void handle(final AsyncResult<List<String>> event) { if (event.succeeded()) { Collections.sort(event.result()); final Handler[] handlers = new Handler[event.result().size() + 1]; handlers[handlers.length - 1] = new Handler<Void>() { @Override public void handle(Void v) { postImport.execute(); } }; for (int i = event.result().size() - 1; i >= 0; i--) { final int j = i; handlers[i] = new Handler<Void>() { @Override public void handle(Void v) { final String file = event.result().get(j); log.info("Importing file : " + file); Matcher matcher; Matcher nameMatcher; if (file != null && (matcher = UAI_PATTERN.matcher(file)).find() && (nameMatcher = namePattern.matcher(file)).find()) { final String uai = matcher.group(1); final String structureName = nameMatcher.group(1); TransactionManager.getNeo4jHelper().execute( "MATCH (s:Structure {UAI:{uai}}) return s.externalId as externalId", new JsonObject().put("uai", uai), new Handler<Message<JsonObject>>() { @Override public void handle(Message<JsonObject> event) { final String structureExternalId; JsonArray res = event.body().getJsonArray("result"); if ("ok".equals(event.body().getString("status")) && res.size() > 0) { structureExternalId = res.getJsonObject(0) .getString("externalId"); } else { structureExternalId = null; } final String parentDir = path + File.separator + UUID.randomUUID().toString(); final String dirName = parentDir + File.separator + structureName + (structureExternalId != null ? "@" + structureExternalId : "") + "_" + uai; fs.mkdirs(dirName, new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> event) { try { FileUtils.unzip(file.replaceAll("\\s", "%20"), dirName); moveCsvFiles(structureExternalId, fs, dirName, parentDir, handlers, j); } catch (IOException e) { fs.deleteRecursive(parentDir, true, null); log.error("Error unzip : " + file, e); handlers[j + 1].handle(null); } } }); } }); } else { log.error("UAI not found in filename : " + file); handlers[j + 1].handle(null); } } }; } handlers[0].handle(null); } else { log.error("Error reading directory."); } } }); }
From source file:org.entcore.feeder.csv.CsvValidator.java
License:Open Source License
private void checkFile(final String path, final String profile, final String charset, final Handler<JsonObject> handler) { final List<String> columns = new ArrayList<>(); final AtomicInteger filterExternalId = new AtomicInteger(-1); final JsonArray externalIds = new fr.wseduc.webutils.collections.JsonArray(); try {//from w w w . j a v a2s .c o m CSVReader csvParser = getCsvReader(path, charset); String[] strings; int i = 0; while ((strings = csvParser.readNext()) != null) { if (i == 0) { JsonArray invalidColumns = columnsMapper.getColumsNames(strings, columns, profile); if (invalidColumns.size() > 0) { parseErrors("invalid.column", invalidColumns, profile, handler); } else if (columns.contains("externalId")) { int j = 0; for (String c : columns) { if ("externalId".equals(c)) { filterExternalId.set(j); } j++; } } else if (structureId != null && !structureId.trim().isEmpty()) { findUsersEnabled = false; findUsers(path, profile, columns, charset, handler); } else { validateFile(path, profile, columns, null, charset, handler); } } else if (filterExternalId.get() >= 0 && !emptyLine(strings)) { if (strings[filterExternalId.get()] != null && !strings[filterExternalId.get()].isEmpty()) { externalIds.add(strings[filterExternalId.get()]); } else if (findUsersEnabled) { // TODO add check to empty lines findUsersEnabled = false; final int eii = filterExternalId.get(); filterExternalId.set(-1); findUsers(path, profile, columns, eii, charset, handler); } } i++; } } catch (Exception e) { addError(profile, "csv.exception"); log.error("csv.exception", e); handler.handle(result); return; } if (filterExternalId.get() >= 0) { filterExternalIdExists(externalIds, new Handler<JsonArray>() { @Override public void handle(JsonArray externalIdsExists) { if (externalIdsExists != null) { validateFile(path, profile, columns, externalIdsExists, charset, handler); } else { addError(profile, "error.find.externalIds"); handler.handle(result); } } }); } }