List of usage examples for io.vertx.core.json JsonArray add
public JsonArray add(Object value)
From source file:org.entcore.conversation.service.impl.SqlConversationService.java
License:Open Source License
private String addCompleteFolderCondition(JsonArray values, String restrain, Boolean unread, String folder, UserInfos user) {//from w w w.java2 s .co m String additionalWhere = ""; if (unread != null && unread) { additionalWhere += "AND unread = ? "; values.add(unread); } if (restrain != null) { additionalWhere += "AND um.folder_id = ? AND um.trashed = false"; values.add(folder); } else { additionalWhere += addFolderCondition(folder, values, user.getUserId()); } return additionalWhere; }
From source file:org.entcore.conversation.service.impl.SqlConversationService.java
License:Open Source License
private String addMessageConditionUnread(String folder, JsonArray values, Boolean unread, UserInfos user) { String messageConditionUnread = ""; if (unread != null && unread) { String upFolder = folder.toUpperCase(); // Only for user folders and trash if (!upFolder.equals("INBOX") && !upFolder.equals("OUTBOX") && !upFolder.equals("DRAFT")) { messageConditionUnread = " AND m.state = ?"; values.add("SENT"); }/*from w ww .j a v a2s.c o m*/ } return messageConditionUnread; }
From source file:org.entcore.directory.controllers.UserBookController.java
License:Open Source License
@BusAddress("activation.ack") public void initUserBookNode(final Message<JsonObject> message) { JsonObject params = new JsonObject(); params.put("userId", message.body().getString("userId")); params.put("avatar", userBookData.getString("default-avatar")); params.put("theme", userBookData.getString("default-theme", "")); JsonArray queries = new fr.wseduc.webutils.collections.JsonArray(); String query = "MERGE (m:UserBook { userid : {userId}}) " + "SET m.type = 'USERBOOK', m.picture = {avatar}, m.motto = '', " + "m.health = '', m.mood = 'default', m.theme = {theme} " + "WITH m " + "MATCH (n:User {id : {userId}}) " + "CREATE UNIQUE n-[:USERBOOK]->m"; queries.add(Neo.toJsonObject(query, params)); String query2 = "MATCH (n:User)-[:USERBOOK]->m " + "WHERE n.id = {userId} " + "CREATE m-[:PUBLIC]->(c:Hobby {category: {category}, values: {values}})"; if (isNotEmpty(message.body().getString("theme"))) { String query3 = "MATCH (u:User {id:{userId}}) " + "MERGE (u)-[:PREFERS]->(uac:UserAppConf) " + "SET uac.theme = {theme} "; JsonObject paramsTheme = new JsonObject().put("userId", message.body().getString("userId")).put("theme", message.body().getString("theme")); queries.add(Neo.toJsonObject(query3, paramsTheme)); }/*from w w w .ja v a 2s . co m*/ for (Object hobby : userBookData.getJsonArray("hobbies")) { JsonObject j = params.copy(); j.put("category", (String) hobby); j.put("values", ""); queries.add(Neo.toJsonObject(query2, j)); } neo.sendBatch(queries, (Handler<Message<JsonObject>>) null); welcomeMessage(message); }
From source file:org.entcore.directory.controllers.UserController.java
License:Open Source License
@Get("/user/structures/list") @ResourceFilter(AdmlOfStructuresByUAI.class) @SecuredAction(value = "", type = ActionType.RESOURCE) public void listUserInStructuresByUAI(final HttpServerRequest request) { final String format = request.params().get("format"); final List<String> structures = request.params().getAll("uai"); JsonArray fields = new fr.wseduc.webutils.collections.JsonArray().add("externalId").add("lastName") .add("firstName").add("login"); if ("true".equalsIgnoreCase(request.params().get("administrativeStructure"))) { fields.add("administrativeStructure"); }/*from ww w . j av a 2 s. co m*/ JsonArray types = new fr.wseduc.webutils.collections.JsonArray(request.params().getAll("type")); boolean isExportFull = false; String isExportFullParameter = request.params().get("full"); if (null != isExportFullParameter && !isExportFullParameter.isEmpty() && "true".equals(isExportFullParameter)) { isExportFull = true; } if ("XML".equalsIgnoreCase(format)) { userService.listByUAI(structures, types, isExportFull, fields, new Handler<Either<String, JsonArray>>() { @Override public void handle(Either<String, JsonArray> event) { if (event.isRight()) { JsonArray r = event.right().getValue(); ObjectMapper mapper = new ObjectMapper(); try { List<Users.User> users = mapper.readValue(r.encode(), new TypeReference<List<Users.User>>() { }); StringWriter response = new StringWriter(); JAXBContext context = JAXBContext.newInstance(Users.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(new Users(users), response); request.response().putHeader("content-type", "application/xml"); request.response().end(response.toString()); } catch (IOException | JAXBException e) { log.error(e.toString(), e); request.response().setStatusCode(500); request.response().end(e.getMessage()); } } else { leftToResponse(request, event.left()); } } }); } else { userService.listByUAI(structures, types, isExportFull, fields, arrayResponseHandler(request)); } }
From source file:org.entcore.directory.services.impl.DefaultShareBookmarkService.java
License:Open Source License
@Override public void list(String userId, Handler<Either<String, JsonArray>> handler) { final String query = "MATCH (:User {id:{userId}})-[:HAS_SB]->(sb:ShareBookmark) return sb"; JsonObject params = new JsonObject(); params.put("userId", userId); neo4j.execute(query, params, fullNodeMergeHandler("sb", node -> { if (node.isRight()) { final JsonObject j = node.right().getValue(); final JsonArray result = new JsonArray(); for (String id : j.fieldNames()) { final JsonArray value = j.getJsonArray(id); if (value == null || value.size() < 2) { delete(userId, id, dres -> { if (dres.isLeft()) { log.error("Error deleting sharebookmark " + id + " : " + dres.left().getValue()); }/*from ww w . j a v a 2 s .c o m*/ }); continue; } final JsonObject r = new fr.wseduc.webutils.collections.JsonObject(); r.put("id", id); r.put("name", value.remove(0)); //r.put("membersIds", value); result.add(r); } handler.handle(new Either.Right<>(result)); } else { handler.handle(new Either.Left<>(node.left().getValue())); } })); }
From source file:org.entcore.directory.services.impl.DefaultTimetableService.java
License:Open Source License
@Override public void listCoursesBetweenTwoDates(String structureId, String teacherId, List<String> groupNames, String begin, String end, Handler<Either<String, JsonArray>> handler) { if (Utils.validationParamsNull(handler, structureId, begin, end)) return;//from w w w . ja va 2 s . c om final JsonObject query = new JsonObject(); query.put("structureId", structureId); if (teacherId != null) { query.put("teacherIds", teacherId); } final String startDate = begin + START_DATE_PATTERN; final String endDate = end + END_DATE_PATTERN; JsonObject betweenStart = new JsonObject(); betweenStart.put("$lte", endDate); JsonObject betweenEnd = new JsonObject(); betweenEnd.put("$gte", startDate); if (groupNames != null) { JsonObject dateOperand = new JsonObject().put("$and", new fr.wseduc.webutils.collections.JsonArray() .add(new JsonObject().put("startDate", betweenStart)) .add(new JsonObject().put("endDate", betweenEnd))); JsonObject groupOperand = new JsonObject(); JsonArray groupsNameArray = new JsonArray(); for (int i = 0; i < groupNames.size(); i++) { String groupName = groupNames.get(i); groupsNameArray.add(new JsonObject().put("classes", groupName)); groupsNameArray.add(new JsonObject().put("groups", groupName)); } groupOperand.put("$or", groupsNameArray); query.put("$and", new JsonArray().add(dateOperand).add(groupOperand)); } else { query.put("$and", new fr.wseduc.webutils.collections.JsonArray() .add(new JsonObject().put("startDate", betweenStart)) .add(new JsonObject().put("endDate", betweenEnd))); } final JsonObject sort = new JsonObject().put("startDate", 1); MongoDb.getInstance().find(COURSES, query, sort, KEYS, validResultsHandler(handler)); }
From source file:org.entcore.directory.services.impl.DefaultTimetableService.java
License:Open Source License
@Override public void importTimetable(String structureId, final String path, final String domain, final String acceptLanguage, final Handler<Either<JsonObject, JsonObject>> handler) { final String query = "MATCH (s:Structure {id:{id}}) RETURN s.UAI as UAI, s.timetable as timetable"; neo4j.execute(query, new JsonObject().put("id", structureId), validUniqueResultHandler(new Handler<Either<String, JsonObject>>() { @Override// w ww . j a v a2 s .c om public void handle(Either<String, JsonObject> event) { final JsonArray errors = new fr.wseduc.webutils.collections.JsonArray(); final JsonObject ge = new JsonObject().put("error.global", errors); if (event.isRight() && isNotEmpty(event.right().getValue().getString("UAI")) && TIMETABLE_TYPES.contains(event.right().getValue().getString("timetable"))) { if (!("EDT".equals(event.right().getValue().getString("timetable")) && !path.endsWith("\\.xml")) && !("UDT".equals(event.right().getValue().getString("timetable")) && !path.endsWith("\\.zip"))) { errors.add(I18n.getInstance().translate("invalid.import.format", domain, acceptLanguage)); handler.handle(new Either.Left<JsonObject, JsonObject>(ge)); return; } JsonObject action = new JsonObject() .put("action", "manual-" + event.right().getValue().getString("timetable").toLowerCase()) .put("path", path).put("UAI", event.right().getValue().getString("UAI")) .put("language", acceptLanguage); eb.send(Directory.FEEDER, action, new DeliveryOptions().setSendTimeout(600000l), handlerToAsyncHandler(new Handler<Message<JsonObject>>() { @Override public void handle(Message<JsonObject> event) { if ("ok".equals(event.body().getString("status"))) { JsonObject r = event.body().getJsonObject("result", new JsonObject()); if (r.getJsonObject("errors", new JsonObject()).size() > 0) { handler.handle(new Either.Left<JsonObject, JsonObject>( r.getJsonObject("errors"))); } else { handler.handle(new Either.Right<JsonObject, JsonObject>( r.getJsonObject("ignored"))); } } else { errors.add(event.body().getString("message", "")); handler.handle(new Either.Left<JsonObject, JsonObject>(ge)); } } })); } else { errors.add(I18n.getInstance().translate("invalid.structure", domain, acceptLanguage)); handler.handle(new Either.Left<JsonObject, JsonObject>(ge)); } } })); }
From source file:org.entcore.directory.services.impl.DefaultUserService.java
License:Open Source License
@Override public void get(String id, boolean getManualGroups, JsonArray filterAttributes, Handler<Either<String, JsonObject>> result) { String getMgroups = ""; String resultMgroups = ""; if (getManualGroups) { getMgroups = "OPTIONAL MATCH u-[:IN]->(mgroup: ManualGroup) WITH COLLECT(distinct {id: mgroup.id, name: mgroup.name}) as manualGroups, admStruct, admGroups, parents, children, functions, u, structureNodes "; resultMgroups = "CASE WHEN manualGroups IS NULL THEN [] ELSE manualGroups END as manualGroups, "; }/*from www. j av a 2 s .co m*/ String query = "MATCH (u:`User` { id : {id}}) " + "OPTIONAL MATCH u-[:IN]->()-[:DEPENDS]->(s:Structure) WITH COLLECT(distinct s) as structureNodes, u " + "OPTIONAL MATCH u-[rf:HAS_FUNCTION]->fg-[:CONTAINS_FUNCTION*0..1]->(f:Function) WITH COLLECT(distinct [f.externalId, rf.scope]) as functions, u, structureNodes " + "OPTIONAL MATCH u<-[:RELATED]-(child: User) WITH COLLECT(distinct {id: child.id, displayName: child.displayName, externalId: child.externalId}) as children, functions, u, structureNodes " + "OPTIONAL MATCH u-[:RELATED]->(parent: User) WITH COLLECT(distinct {id: parent.id, displayName: parent.displayName, externalId: parent.externalId}) as parents, children, functions, u, structureNodes " + "OPTIONAL MATCH u-[:IN]->(fgroup: FunctionalGroup) WITH COLLECT(distinct {id: fgroup.id, name: fgroup.name}) as admGroups, parents, children, functions, u, structureNodes " + "OPTIONAL MATCH u-[:ADMINISTRATIVE_ATTACHMENT]->(admStruct: Structure) WITH COLLECT(distinct {id: admStruct.id}) as admStruct, admGroups, parents, children, functions, u, structureNodes " + getMgroups + "RETURN DISTINCT u.profiles as type, structureNodes, functions, " + "CASE WHEN children IS NULL THEN [] ELSE children END as children, " + "CASE WHEN parents IS NULL THEN [] ELSE parents END as parents, " + "CASE WHEN admGroups IS NULL THEN [] ELSE admGroups END as functionalGroups, " + "CASE WHEN admStruct IS NULL THEN [] ELSE admStruct END as administrativeStructures, " + resultMgroups + "u"; final Handler<Either<String, JsonObject>> filterResultHandler = event -> { if (event.isRight()) { final JsonObject r = event.right().getValue(); filterAttributes.add("password").add("resetCode").add("lastNameSearchField") .add("firstNameSearchField").add("displayNameSearchField").add("checksum"); for (Object o : filterAttributes) { r.remove((String) o); } } result.handle(event); }; neo.execute(query, new JsonObject().put("id", id), fullNodeMergeHandler("u", filterResultHandler, "structureNodes")); }
From source file:org.entcore.directory.services.impl.DefaultUserService.java
License:Open Source License
@Override public void listByUAI(List<String> UAI, JsonArray expectedTypes, boolean isExportFull, JsonArray fields, Handler<Either<String, JsonArray>> results) { if (UAI == null || UAI.isEmpty()) { results.handle(new Either.Left<String, JsonArray>("missing.uai")); return;/*from w w w.j av a 2 s.co m*/ } else { for (String uaiCode : UAI) { if (!StringValidation.isUAI(uaiCode)) { results.handle(new Either.Left<String, JsonArray>("invalid.uai")); return; } } } if (fields == null || fields.size() == 0) { fields = new fr.wseduc.webutils.collections.JsonArray().add("id").add("externalId").add("lastName") .add("firstName").add("login"); } //user's fields for Full Export if (isExportFull) { fields.add("email"); fields.add("emailAcademy"); fields.add("mobile"); fields.add("deleteDate"); fields.add("functions"); fields.add("displayName"); } // Init params and filter for all type of queries String filter = "WHERE s.UAI IN {uai} "; JsonObject params = new JsonObject().put("uai", new fr.wseduc.webutils.collections.JsonArray(UAI)); StringBuilder query = new StringBuilder(); query.append("MATCH (s:Structure)<-[:DEPENDS]-(cpg:ProfileGroup)"); // filter by types if needed OR full export if (isExportFull || (expectedTypes != null && expectedTypes.size() > 0)) { query.append("-[:HAS_PROFILE]->(p:Profile)"); } // filter by types if needed if (expectedTypes != null && expectedTypes.size() > 0) { filter += "AND p.name IN {expectedTypes} "; params.put("expectedTypes", expectedTypes); } query.append(", cpg<-[:IN]-(u:User) ").append(filter); if (fields.contains("administrativeStructure")) { query.append("OPTIONAL MATCH u-[:ADMINISTRATIVE_ATTACHMENT]->sa "); } query.append("RETURN DISTINCT "); for (Object field : fields) { if ("type".equals(field) || "profile".equals(field)) { query.append(" HEAD(u.profiles)"); } else if ("administrativeStructure".equals(field)) { query.append(" sa.externalId "); } else { query.append(" u.").append(field); } query.append(" as ").append(field).append(","); } query.deleteCharAt(query.length() - 1); //Full Export : profiles and Structure if (isExportFull) { query.append(", p.name as profiles"); query.append(", s.externalId as structures") .append(" , CASE WHEN size(u.classes) > 0 THEN last(collect(u.classes)) END as classes"); } neo.execute(query.toString(), params, validResultHandler(results)); }
From source file:org.entcore.feeder.aaf.AAFHandler.java
License:Open Source License
private void addValueInAttribute(String s) throws SAXException { if (s == null || (s.isEmpty() && !"ENTAuxEnsClassesPrincipal".equals(currentAttribute) && !"mobile".equals(currentAttribute) && !"ENTPersonMobileSMS".equals(currentAttribute))) { return;//w ww .jav a 2 s . c om } JsonObject j = mapping.getJsonObject(currentAttribute); if (j == null) { throw new SAXException("Unknown attribute " + currentAttribute); } if (currentStructure == null) { throw new SAXException("Value is found but structure isn't defined."); } String type = j.getString("type"); String attribute = j.getString("attribute"); final boolean prefix = j.getBoolean("prefix", false); if ("birthDate".equals(attribute) && !s.isEmpty()) { s = convertDate(s); } if (type != null && type.contains("array")) { JsonArray a = currentStructure.getJsonArray(attribute); if (a == null) { a = new fr.wseduc.webutils.collections.JsonArray(); currentStructure.put(attribute, a); } if (!s.isEmpty()) { a.add(JsonUtil.convert(s, type, (prefix ? processing.getAcademyPrefix() : null))); } } else { Object v = JsonUtil.convert(s, type, (prefix ? processing.getAcademyPrefix() : null)); if (!(v instanceof JsonUtil.None)) { currentStructure.put(attribute, v); } } }