List of usage examples for io.vertx.core.json JsonObject getString
public String getString(String key)
From source file:org.entcore.cas.services.LabomepRegisteredService.java
License:Open Source License
@Override protected void prepareUserCas20(User user, String userId, String service, JsonObject data, Document doc, List<Element> additionnalAttributes) { user.setUser(data.getString(principalAttributeName)); try {//from w ww . j a v a2 s . co m // Uid if (data.containsKey("externalId")) { additionnalAttributes.add(createTextElement("uid", data.getString("externalId"), doc)); } // administratives Structures first final List<String> uaiList = new ArrayList<>(); for (Object o : data.getJsonArray("administratives", new fr.wseduc.webutils.collections.JsonArray())) { JsonObject structure = (JsonObject) o; final String uai = structure.getString("UAI"); if (!StringUtils.isEmpty(uai)) { uaiList.add(uai); additionnalAttributes.add(createTextElement("structures", uai, doc)); } } for (Object o : data.getJsonArray("structures", new fr.wseduc.webutils.collections.JsonArray())) { JsonObject structure = (JsonObject) o; final String uai = structure.getString("UAI"); if (!StringUtils.isEmpty(uai) && !uaiList.contains(uai)) { additionnalAttributes.add(createTextElement("structures", uai, doc)); } } // classes for (Object o : data.getJsonArray("classes", new fr.wseduc.webutils.collections.JsonArray())) { JsonObject classe = (JsonObject) o; additionnalAttributes.add(createTextElement("classes", classe.getString("name"), doc)); } // Profile switch (data.getString("type")) { case "Student": additionnalAttributes.add(createTextElement("profile", "National_1", doc)); break; case "Teacher": additionnalAttributes.add(createTextElement("profile", "National_3", doc)); break; case "Relative": additionnalAttributes.add(createTextElement("profile", "National_2", doc)); break; case "Personnel": additionnalAttributes.add(createTextElement("profile", "National_4", doc)); break; } // Lastname if (data.containsKey("lastName")) { additionnalAttributes.add(createTextElement("nom", data.getString("lastName"), doc)); } // Firstname if (data.containsKey("firstName")) { additionnalAttributes.add(createTextElement("prenom", data.getString("firstName"), doc)); } // Email if (data.containsKey("email")) { additionnalAttributes.add(createTextElement("email", data.getString("email"), doc)); } } catch (Exception e) { log.error("Failed to extract user's attributes for Labomep", e); } }
From source file:org.entcore.cas.services.LeSiteTvRegisteredService.java
License:Open Source License
@Override protected void prepareUserCas20(User user, String userId, String service, JsonObject data, Document doc, List<Element> additionnalAttributes) { user.setUser(data.getString(principalAttributeName)); try {/*from ww w .j a v a 2 s. c o m*/ Element root = createElement(LSTV_ROOT, doc); // Uid if (data.containsKey("externalId")) { root.appendChild(createTextElement(LSTV_ID, data.getString("externalId"), doc)); } // Structures for (Object o : data.getJsonArray("structures", new fr.wseduc.webutils.collections.JsonArray()) .getList()) { if (o == null || !(o instanceof JsonObject)) continue; JsonObject structure = (JsonObject) o; if (structure.containsKey("UAI")) { root.appendChild(createTextElement(LSTV_STRUCTURE_UAI, structure.getString("UAI"), doc)); } } // Profile switch (data.getString("type")) { case "Student": root.appendChild(createTextElement(LSTV_PROFILES, "National_1", doc)); break; case "Teacher": root.appendChild(createTextElement(LSTV_PROFILES, "National_3", doc)); break; case "Relative": root.appendChild(createTextElement(LSTV_PROFILES, "National_2", doc)); break; case "Personnel": root.appendChild(createTextElement(LSTV_PROFILES, "National_4", doc)); break; } // Lastname if (data.containsKey("lastName")) { root.appendChild(createTextElement(LSTV_LASTNAME, data.getString("lastName"), doc)); } // Firstname if (data.containsKey("firstName")) { root.appendChild(createTextElement(LSTV_FIRSTNAME, data.getString("firstName"), doc)); } // Email if (data.containsKey("email")) { root.appendChild(createTextElement(LSTV_EMAIL, data.getString("email"), doc)); } additionnalAttributes.add(root); } catch (Exception e) { log.error("Failed to transform User for LeSite.tv", e); } }
From source file:org.entcore.cas.services.MSELRegisteredService.java
License:Open Source License
@Override protected void prepareUserCas20(User user, String userId, String service, JsonObject data, Document doc, List<Element> additionnalAttributes) { // TODO Auto-generated method stub user.setUser(data.getString(principalAttributeName)); try {//from ww w . j a v a 2 s . c o m //uid if (data.containsKey("externalId")) { additionnalAttributes.add(createTextElement(MSEL_ID, data.getString("externalId"), doc)); } // Structures for (Object o : data.getJsonArray("structures", new fr.wseduc.webutils.collections.JsonArray()) .getList()) { if (o == null || !(o instanceof JsonObject)) continue; JsonObject structure = (JsonObject) o; if (structure.containsKey("UAI")) { additionnalAttributes .add(createTextElement(MSEL_STRUCTURE_UAI, structure.getString("UAI"), doc)); } } // Profile switch (data.getString("type")) { case "Student": additionnalAttributes.add(createTextElement(MSEL_PROFILES, "National_1", doc)); break; case "Teacher": additionnalAttributes.add(createTextElement(MSEL_PROFILES, "National_3", doc)); break; case "Relative": additionnalAttributes.add(createTextElement(MSEL_PROFILES, "National_2", doc)); break; case "Personnel": additionnalAttributes.add(createTextElement(MSEL_PROFILES, "National_4", doc)); break; } } catch (Exception e) { log.error("Failed to transform User for Mon stage en ligne", e); } }
From source file:org.entcore.cas.services.ProEPSRegisteredService.java
License:Open Source License
@Override protected void prepareUserCas20(User user, String userId, String service, JsonObject data, Document doc, List<Element> additionnalAttributes) { user.setUser(data.getString(principalAttributeName)); try {/*from w w w. ja v a 2 s.c om*/ // Uid if (data.containsKey("externalId")) { additionnalAttributes.add(createTextElement(UID, data.getString("externalId"), doc)); } // Structures for (Object o : data.getJsonArray("structures", new fr.wseduc.webutils.collections.JsonArray())) { if (!(o instanceof JsonObject)) continue; JsonObject structure = (JsonObject) o; if (structure.containsKey("UAI")) { additionnalAttributes.add(createTextElement(STRUCTURE_UAI, structure.getString("UAI"), doc)); } } // Profile switch (data.getString("type")) { case "Student": additionnalAttributes.add(createTextElement(PROFILE, "National_1", doc)); break; case "Teacher": additionnalAttributes.add(createTextElement(PROFILE, "National_3", doc)); break; case "Relative": additionnalAttributes.add(createTextElement(PROFILE, "National_2", doc)); break; case "Personnel": additionnalAttributes.add(createTextElement(PROFILE, "National_4", doc)); break; } } catch (Exception e) { log.error("Failed to transform User for ProEPS", e); } }
From source file:org.entcore.cas.services.PronoteRegisteredService.java
License:Open Source License
@Override protected void prepareUser(User user, String userId, String service, JsonObject data) { user.setUser(data.getString(principalAttributeName)); user.setAttributes(new HashMap<String, String>()); try {// w w w .j a v a 2 s.c o m if (data.getString("lastName") != null && data.getString("firstName") != null) { user.getAttributes().put("nom", data.getString("lastName")); user.getAttributes().put("prenom", data.getString("firstName")); } if (data.getString("birthDate") != null) { user.getAttributes().put("dateNaissance", data.getString("birthDate").replaceAll("([0-9]+)-([0-9]+)-([0-9]+)", "$3/$2/$1")); } if (data.getString("postalCode") != null) { user.getAttributes().put("codePostal", data.getString("postalCode")); } String category = null; JsonArray types = data.getJsonArray("type"); for (Object type : types.getList()) { switch (type.toString()) { case "Student": category = checkProfile(category, "National_1"); break; case "Teacher": category = checkProfile(category, "National_3"); break; case "Relative": category = checkProfile(category, "National_2"); break; case "Personnel": category = checkProfile(category, "National_4"); break; } } if (category != null) { user.getAttributes().put("categories", category); } } catch (Exception e) { log.error("Failed to transform User for Pronote"); } }
From source file:org.entcore.cas.services.UidRegisteredService.java
License:Open Source License
@Override protected void prepareUserCas20(User user, String userId, String service, JsonObject data, Document doc, List<Element> additionnalAttributes) { user.setUser(data.getString(principalAttributeName)); try {//w w w . j a v a 2 s . c om // Uid if (data.containsKey("externalId")) { additionnalAttributes.add(createTextElement(UID, data.getString("externalId"), doc)); } } catch (Exception e) { log.error("Failed to transform User for Uid service", e); } }
From source file:org.entcore.cas.services.UniversalisRegisteredService.java
License:Open Source License
@Override protected void prepareUserCas20(User user, String userId, String service, JsonObject data, Document doc, List<Element> additionnalAttributes) { user.setUser(data.getString(principalAttributeName)); try {//w w w . jav a 2 s . c o m // Uid if (data.containsKey("externalId")) { additionnalAttributes.add(createTextElement(UNVS_ID, data.getString("externalId"), doc)); } // Structures for (Object o : data.getJsonArray("structures", new fr.wseduc.webutils.collections.JsonArray()) .getList()) { if (o == null || !(o instanceof JsonObject)) continue; JsonObject structure = (JsonObject) o; if (structure.containsKey("UAI")) { additionnalAttributes .add(createTextElement(UNVS_STRUCTURE_UAI, structure.getString("UAI"), doc)); } } // Profile switch (data.getString("type")) { case "Student": additionnalAttributes.add(createTextElement(UNVS_PROFILES, "National_1", doc)); break; case "Teacher": additionnalAttributes.add(createTextElement(UNVS_PROFILES, "National_3", doc)); break; case "Relative": additionnalAttributes.add(createTextElement(UNVS_PROFILES, "National_2", doc)); break; case "Personnel": additionnalAttributes.add(createTextElement(UNVS_PROFILES, "National_4", doc)); break; } // Lastname if (data.containsKey("lastName")) { additionnalAttributes.add(createTextElement(UNVS_LASTNAME, data.getString("lastName"), doc)); } // Firstname if (data.containsKey("firstName")) { additionnalAttributes.add(createTextElement(UNVS_FIRSTNAME, data.getString("firstName"), doc)); } } catch (Exception e) { log.error("Failed to transform User for Universalis", e); } }
From source file:org.entcore.cas.services.WebclasseursRegisteredService.java
License:Open Source License
@Override protected void prepareUserCas20(User user, String userId, String service, JsonObject data, Document doc, List<Element> additionnalAttributes) { user.setUser(data.getString(principalAttributeName)); try {/*from w ww . ja va 2s . c o m*/ // Lastname if (data.containsKey("login")) { additionnalAttributes.add(createTextElement(WEBCLASSEURS_LOGIN, data.getString("login"), doc)); } // Profile JsonArray profiles = data.getJsonArray("type"); if (profiles.contains("Teacher") || profiles.contains("Personnel")) { // Teacher and Personnel seen alike for Webclasseurs additionnalAttributes.add(createTextElement(WEBCLASSEURS_PROFILE, "National_3", doc)); } else if (profiles.contains("Student")) { additionnalAttributes.add(createTextElement(WEBCLASSEURS_PROFILE, "National_1", doc)); } else if (profiles.contains("Relative")) { additionnalAttributes.add(createTextElement(WEBCLASSEURS_PROFILE, "National_2", doc)); } } catch (Exception e) { log.error("Failed to transform User for Webclasseurs", e); } }
From source file:org.entcore.common.bus.WorkspaceHelper.java
License:Open Source License
private void uploadDocument(final HttpServerRequest request, final String id, final String name, final String application, final boolean protectedContent, final JsonArray thumbs, final Handler<AsyncResult<Message<JsonObject>>> handler) { UserUtils.getUserInfos(eb, request, new Handler<UserInfos>() { @Override//from ww w .j ava2s . com public void handle(final UserInfos userInfos) { if (userInfos != null) { request.resume(); storage.writeUploadFile(request, new Handler<JsonObject>() { @Override public void handle(final JsonObject up) { if (up != null && !"error".equals(up.getString("status"))) { Handler<AsyncResult<Message<JsonObject>>> h = message -> { if (message.failed()) { storage.removeFile(up.getString("_id"), new Handler<JsonObject>() { @Override public void handle(JsonObject event) { if (!"ok".equals(event.getString("status"))) { log.error("Error removing file " + up.getString("_id") + " : " + event.getString("message")); } } }); } if (handler != null) { handler.handle(message); } }; if (id != null && !id.trim().isEmpty()) { updateDocument(id, up, name, thumbs, h); } else { addDocument(up, userInfos, name, application, protectedContent, thumbs, h); } } else { if (handler != null) { handleAsyncError("upload.error", handler); } } } }); } else { if (handler != null) { handleAsyncError("invalid.user", handler); } } } }); }
From source file:org.entcore.common.bus.WorkspaceHelper.java
License:Open Source License
public void readDocument(String documentId, final Handler<Document> handler) { getDocument(documentId, new Handler<AsyncResult<Message<JsonObject>>>() { @Override/* w ww . j av a 2 s . co m*/ public void handle(AsyncResult<Message<JsonObject>> event) { if (event.failed()) { handler.handle(null); return; } JsonObject res = event.result().body(); String status = res.getString("status"); final JsonObject result = res.getJsonObject("result"); if ("ok".equals(status) && result != null) { String file = result.getString("file"); if (file != null && !file.trim().isEmpty()) { readFile(file, new Handler<Buffer>() { @Override public void handle(Buffer event) { if (event != null) { handler.handle(new Document(result, event)); } else { handler.handle(null); } } }); } else { handler.handle(null); } } else { handler.handle(null); } } }); }