com.github.openjson.JSONObject Java Examples
The following examples show how to use
com.github.openjson.JSONObject.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestCalendarService.java From openmeetings with Apache License 2.0 | 6 votes |
@Test public void testCreateWithOmMm() throws Exception { JSONObject o = createAppointment("test") .put("meetingMembers", new JSONArray() .put(new JSONObject().put("user", new JSONObject() .put("id", 1)))); String uuid = randomUUID().toString(); User u = getUser(uuid); u.addGroup(getBean(GroupDao.class).get(1L)); u = createUser(getBean(UserDao.class), u); ServiceResult sr = login(u.getLogin(), createPass()); Response resp = getClient(getCalendarUrl()) .path("/") .query("sid", sr.getMessage()) .form(new Form().param("appointment", o.toString())); assertNotNull(resp, "Valid AppointmentDTO should be returned"); assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus(), "Call should be successful"); AppointmentDTO dto = resp.readEntity(AppointmentDTO.class); assertNotNull(dto, "Valid DTO should be returned"); assertNotNull(dto.getId(), "DTO id should be valid"); }
Example #2
Source File: OAuthUser.java From openmeetings with Apache License 2.0 | 6 votes |
/** * OAuth constructor * * @param jsonStr - json data from server as string * @param server - {@link OAuthServer} to get mapping */ public OAuthUser(String jsonStr, OAuthServer server) { // get attributes names // we expect login mapping always in place JSONObject json = getJSON(jsonStr, server.getMapping().get(PARAM_LOGIN)); Map<String, String> data = new HashMap<>(); for (Map.Entry<String, String> entry : server.getMapping().entrySet()) { data.put(entry.getKey(), json.optString(entry.getValue())); } String login = data.get(PARAM_LOGIN); String email = data.get(PARAM_EMAIL); if (Strings.isEmpty(email)) { try { data.put(PARAM_EMAIL, String.format("%s@%s", login, new URL(server.getIconUrl()).getHost())); } catch (MalformedURLException e) { log.error("Failed to get user email from JSON: {}", json); } } userData = Collections.unmodifiableMap(data); }
Example #3
Source File: StreamProcessor.java From openmeetings with Apache License 2.0 | 6 votes |
private void handleBroadcastStarted(Client c, final String uid, JSONObject msg) { if (!kHandler.isConnected()) { return; } StreamDesc sd = c.getStream(uid); KStream sender = getByUid(uid); try { if (sender == null) { KRoom room = kHandler.getRoom(c.getRoomId()); sender = room.join(sd); } startBroadcast(sender, sd, msg.getString("sdpOffer")); if (StreamType.SCREEN == sd.getType() && sd.hasActivity(Activity.RECORD) && !isRecording(c.getRoomId())) { startRecording(c); } } catch (KurentoServerException e) { sender.release(this); WebSocketHelper.sendClient(c, newKurentoMsg() .put("id", "broadcastStopped") .put("uid", sd.getUid()) ); sendError(c, "Failed to start broadcast: " + e.getMessage()); log.error("Failed to start broadcast", e); } }
Example #4
Source File: Chat.java From openmeetings with Apache License 2.0 | 6 votes |
@Override protected void respond(AjaxRequestTarget target) { try { String type = getRequest().getRequestParameters().getParameterValue(PARAM_TYPE).toString(null); long roomId = getRequest().getRequestParameters().getParameterValue(PARAM_ROOM_ID).toLong(); if ("accept".equals(type)) { long msgId = getRequest().getRequestParameters().getParameterValue(PARAM_MSG_ID).toLong(); ChatMessage m = chatDao.get(msgId); if (m.isNeedModeration() && isModerator(cm, getUserId(), roomId)) { m.setNeedModeration(false); chatDao.update(m); ChatWebSocketHelper.sendRoom(m, getMessage(List.of(m)).put("mode", "accept")); } else { log.error("It seems like we are being hacked!!!!"); } } else if (type != null && type.indexOf("typing") > -1) { WebSocketHelper.sendRoom(roomId , new JSONObject().put(PARAM_TYPE, "typing") .put("active", type.indexOf("start") > -1) .put("uid", getUid())); } } catch (Exception e) { log.error("Unexpected exception while accepting chat message", e); } }
Example #5
Source File: Client.java From openmeetings with Apache License 2.0 | 6 votes |
private JSONObject addUserJson(JSONObject o) { JSONObject u = new JSONObject(); if (user != null) { JSONObject a = new JSONObject(); u.put("id", user.getId()) .put("firstName", user.getFirstname()) .put("lastName", user.getLastname()) .put("displayName", user.getDisplayName()) .put("address", a) .put("pictureUri", pictureUri); if (user.getAddress() != null) { if (Strings.isEmpty(user.getFirstname()) && Strings.isEmpty(user.getLastname())) { a.put("email", user.getAddress().getEmail()); } a.put("country", user.getAddress().getCountry()); } } return o.put("user", u) .put("level", hasRight(Right.MODERATOR) ? 5 : (hasRight(Right.WHITEBOARD) ? 3 : 1)); }
Example #6
Source File: UserDTO.java From openmeetings with Apache License 2.0 | 6 votes |
public static UserDTO get(JSONObject o) { if (o == null) { return null; } UserDTO u = new UserDTO(); u.id = optLong(o, "id"); u.login = o.optString("login"); u.password = o.optString("password"); u.firstname = o.optString("firstname"); u.lastname = o.optString("lastname"); u.rights.addAll(optEnumList(Right.class, o.optJSONArray("rights"))); u.languageId = o.optLong("languageId"); JSONObject a = o.optJSONObject("address"); if (a != null) { u.address.setId(optLong(a, "id")); u.address.setCountry(a.optString("country")); u.address.setEmail(a.optString("email")); } u.timeZoneId = o.optString("timeZoneId"); u.externalId = o.optString("externalId", null); u.externalType = o.optString("externalType", null); u.type = optEnum(Type.class, o, "type"); u.pictureUri = o.optString("pictureUri", null); return u; }
Example #7
Source File: WbConverter.java From openmeetings with Apache License 2.0 | 6 votes |
private static JSONObject init(Whiteboard wb, List<?> props, boolean addDim) { double left = ((Number)props.get(props.size() - 5)).doubleValue(); double top = ((Number)props.get(props.size() - 4)).doubleValue(); double w = ((Number)props.get(props.size() - 3)).doubleValue(); double h = ((Number)props.get(props.size() - 2)).doubleValue(); JSONObject o = new JSONObject().put(ATTR_SLIDE, 0); if (addDim) { o.put("left", left) .put("top", top) .put("width", w) .put("height", h); wb.setWidth((int)Math.max(wb.getWidth(), w + left)); wb.setHeight((int)Math.max(wb.getHeight(), h + top)); } return o; }
Example #8
Source File: Whiteboard.java From openmeetings with Apache License 2.0 | 6 votes |
public JSONObject toJson() { //deep-copy JSONObject json = new JSONObject(new JSONObject(this).toString(new NullStringer())); json.remove("id"); //filtering json.remove("empty"); //filtering JSONObject items = new JSONObject(); for (Entry<String, String> e : roomItems.entrySet()) { JSONObject o = new JSONObject(e.getValue()); //filtering if ("Clipart".equals(o.opt(ATTR_OMTYPE))) { if (o.has(PARAM__SRC)) { o.put(PARAM_SRC, o.get(PARAM__SRC)); } } else { o.remove(PARAM_SRC); } o.remove(PARAM__SRC); items.put(e.getKey(), o); } json.put(ITEMS_KEY, items); return json; }
Example #9
Source File: WbConverter.java From openmeetings with Apache License 2.0 | 6 votes |
private static void processPath(Whiteboard wb, List<?> props) { if (props.size() < 13) { return; } String color = getColor(getInt(props, 4)); JSONObject o = setColor(init(wb, props), color, null) .put(ATTR_TYPE, "path") .put(ATTR_STROKE, props.get(3)); @SuppressWarnings("unchecked") List<List<?>> points = (List<List<?>>)props.get(1); JSONArray path = new JSONArray(); for (List<?> point : points) { if (path.length() == 0) { path.put(new JSONArray(List.of("M", getInt(point, 1), getInt(point, 2)))); } else if (path.length() == points.size() - 1) { path.put(new JSONArray(List.of("L", getInt(point, 3), getInt(point, 4)))); } else { path.put(new JSONArray(List.of("Q" , getInt(point, 1), getInt(point, 2) , getInt(point, 3), getInt(point, 4)))); } } add(wb, o.put("path", path).put(ATTR_OPACITY, props.get(5))); }
Example #10
Source File: TestRecordingFlowMocked.java From openmeetings with Apache License 2.0 | 6 votes |
/** * This should stop the recording. AND stop the sharing, as the sharing wasn't initially started. * * @throws Exception */ private void testStopRecordingWhenNoSharingStarted() throws Exception { // Mock out the methods that would produce the Recording Recording rec = new Recording(); doReturn(rec).when(recDao).get(Long.valueOf(1L)); // Mock out the method that would start recording doReturn(true).when(streamProcessor).startConvertion(any(Recording.class)); // Needed for stopping, needs to stop by sid doReturn(c).when(streamProcessor).getBySid(c.getSid()); JSONObject msg = new JSONObject(MSG_BASE.toString()) .put("id", "stopRecord") .put("type", "kurento") .put("uid", streamDescUID) ; handler.onMessage(c, msg); // Verify it did also stop the sharing stream verify(streamProcessor).pauseSharing(any(), any()); // Verify all streams gone assertTrue(c.getStreams().size() == 0); }
Example #11
Source File: InvitationDTO.java From openmeetings with Apache License 2.0 | 6 votes |
public static InvitationDTO get(JSONObject o) { if (o == null) { return null; } InvitationDTO i = new InvitationDTO(); i.firstname = o.optString("firstname"); i.lastname = o.optString("lastname"); i.email = o.optString("email"); i.password = o.optString("password"); i.passwordProtected = o.optBoolean("passwordProtected", false); i.subject = o.optString("subject"); i.roomId = o.getLong("roomId"); i.message = o.optString("message"); i.valid = Valid.valueOf(o.optString("valid", Valid.PERIOD.name())); i.validFrom = o.optString("validFrom"); i.validTo = o.optString("validTo"); return i; }
Example #12
Source File: FolderPanel.java From openmeetings with Apache License 2.0 | 6 votes |
private void onClick(AjaxRequestTarget target, BaseFileItem f) { String mod = getRequest().getRequestParameters().getParameterValue(PARAM_MOD).toOptionalString(); boolean shift = false , ctrl = false; if (!Strings.isEmpty(mod)) { JSONObject o = new JSONObject(mod); shift = o.optBoolean(PARAM_SHIFT); ctrl = o.optBoolean(PARAM_CTRL); } treePanel.select(f, target, shift, ctrl); if (Type.FOLDER == f.getType() && treePanel.tree.getState(f) == State.COLLAPSED) { treePanel.tree.expand(f); } else { treePanel.update(target, f); } }
Example #13
Source File: WbPanel.java From openmeetings with Apache License 2.0 | 6 votes |
private JSONObject addFileUrl(Client cl, String ruid, JSONObject file, Consumer<BaseFileItem> consumer) { try { final long fid = file.optLong(ATTR_FILE_ID, -1); if (fid > 0) { BaseFileItem fi = fileDao.getAny(fid); if (fi != null) { if (consumer != null) { consumer.accept(fi); } return WbWebSocketHelper.addFileUrl(ruid, file, fi, cl); } } } catch (Exception e) { //no-op, non-file object } return file; }
Example #14
Source File: NetTestPanel.java From openmeetings with Apache License 2.0 | 6 votes |
private JSONObject getStringLabels() { JSONObject o = new JSONObject(); for (String id : new String[] {"network.test.ms", "network.test.mb", "network.test.sec" , "network.test.click.play", "network.test.copy.log", "network.test.report.start" , "network.test.ping", "network.test.ping.avg", "network.test.ping.rcv" , "network.test.ping.lost", "network.test.ping.load" , "network.test.port", "network.test.port.avail", "network.test.port.stopped" , "network.test.jitter", "network.test.jitter.avg", "network.test.jitter.min" , "network.test.jitter.max", "network.test.jitter.avgAbbr" , "network.test.dwn", "network.test.dwn.bytes", "network.test.dwn.time" , "network.test.dwn.speed" , "network.test.upl", "network.test.upl.bytes", "network.test.upl.time" , "network.test.upl.speed"}) { o.put(id.substring("network.test.".length()), getString(id)); } return o; }
Example #15
Source File: TestCalendarService.java From openmeetings with Apache License 2.0 | 6 votes |
private String createApp(String title) throws Exception { JSONObject o = createAppointment(title); String sid = loginNewUser(); Response resp = getClient(getCalendarUrl()) .path("/") .query("sid", sid) .form(new Form().param("appointment", o.toString())); assertNotNull(resp, "Valid AppointmentDTO should be returned"); assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus(), "Call should be successful"); AppointmentDTO dto = resp.readEntity(AppointmentDTO.class); assertNotNull(dto, "Valid DTO should be returned"); assertNotNull(dto.getId(), "DTO id should be valid"); return sid; }
Example #16
Source File: WbWebSocketHelper.java From openmeetings with Apache License 2.0 | 6 votes |
private static JSONObject patchUrls(BaseFileItem fi, Client c, JSONObject _f) { JSONObject f = new JSONObject(_f.toString()); // deep copy to ensure thread safety switch (fi.getType()) { case VIDEO: f.put(PARAM__SRC, patchUrl(f.getString(PARAM__SRC), c)); f.put(PARAM__POSTER, patchUrl(f.getString(PARAM__POSTER), c)); break; case RECORDING: f.put(PARAM__SRC, patchUrl(f.getString(PARAM__SRC), c)); f.put(PARAM__POSTER, patchUrl(f.getString(PARAM__POSTER), c)); break; case PRESENTATION: f.put(PARAM__SRC, patchUrl(f.getString(PARAM__SRC), c)); break; default: f.put(PARAM_SRC, patchUrl(f.getString(PARAM_SRC), c)); break; } return f; }
Example #17
Source File: MtasUimaParser.java From inception with Apache License 2.0 | 6 votes |
public MtasUimaParser(MtasConfiguration config) { super(config); // Perform dependency injection AutowireCapableBeanFactory factory = ApplicationContextProvider.getApplicationContext() .getAutowireCapableBeanFactory(); factory.autowireBean(this); factory.initializeBean(this, "transientParser"); JSONObject jsonParserConfiguration = new JSONObject( config.attributes.get(ARGUMENT_PARSER_ARGS)); MtasDocumentIndex index = MtasDocumentIndex .getIndex(jsonParserConfiguration.getLong(PARAM_PROJECT_ID)); // Initialize and populate the hash maps for the layers and features for (AnnotationFeature feature : index.getFeaturesToIndex()) { layers.put(feature.getLayer().getName(), feature.getLayer()); layerFeatures .computeIfAbsent(feature.getLayer().getName(), key -> new ArrayList<>()) .add(feature); } }
Example #18
Source File: TestRoomFlowMocked.java From openmeetings with Apache License 2.0 | 5 votes |
@Test public void testWannaRecord2() throws Exception { JSONObject msg = new JSONObject(MSG_BASE.toString()).put("id", "wannaRecord"); Client c = getClientFull(); c.getRoom().setType(Room.Type.INTERVIEW); doReturn(c.getRoom()).when(roomDao).get(ROOM_ID); handler.onMessage(c, msg); }
Example #19
Source File: WebSocketHelper.java From openmeetings with Apache License 2.0 | 5 votes |
static void sendUser(final Long userId, final JSONObject m, BiFunction<JSONObject, Client, JSONObject> func, boolean publish) { if (publish) { publish(new WsMessageUser(userId, m)); } send(a -> ((IApplication)a).getBean(IClientManager.class).listByUser(userId) , (t, c) -> doSend(t, c, m, func, "user"), null); }
Example #20
Source File: RoomMenuPanel.java From openmeetings with Apache License 2.0 | 5 votes |
public void update(IPartialPageRequestHandler handler) { if (!isVisible()) { return; } Room r = room.getRoom(); boolean isInterview = Room.Type.INTERVIEW == r.getType(); User u = room.getClient().getUser(); boolean notExternalUser = u.getType() != User.Type.CONTACT; exitMenuItem.setVisible(notExternalUser); filesMenu.setVisible(!isInterview && room.getSidebar().isShowFiles()); boolean moder = room.getClient().hasRight(Room.Right.MODERATOR); actionsSubMenu.update(moder, notExternalUser); pollsSubMenu.update(moder, notExternalUser, r); menuPanel.update(handler); StringBuilder roomClass = new StringBuilder("room name"); String roomTitle = ""; if (streamProcessor.isRecording(r.getId())) { JSONObject ru = kHandler.getRecordingUser(r.getId()); if (!Strings.isEmpty(ru.optString("login"))) { roomTitle += getString("419") + " " + ru.getString("login"); if (!Strings.isEmpty(ru.optString("firstName"))) { roomTitle += " " + ru.getString("firstName"); } if (!Strings.isEmpty(ru.optString("lastName"))) { roomTitle += " " + ru.getString("lastName"); } roomTitle += " " + df.format(new Date(ru.getLong("started"))); roomClass.append(" screen"); } } handler.add(roomName.add(AttributeModifier.replace(ATTR_CLASS, roomClass), AttributeModifier.replace(ATTR_TITLE, roomTitle))); handler.add(askBtn.setVisible(!moder && r.isAllowUserQuestions())); handler.add(shareBtn.setVisible(room.screenShareAllowed())); handler.appendJavaScript("$('#share-dlg-btn').off().click(Sharer.open);"); }
Example #21
Source File: AppointmentParamConverter.java From openmeetings with Apache License 2.0 | 5 votes |
public static JSONObject json(AppointmentDTO val) { Date i = val.getInserted(), u = val.getUpdated(); return new JSONObject(val) .put("start", ISO8601_FULL_FORMAT.format(val.getStart())) .put("end", ISO8601_FULL_FORMAT.format(val.getEnd())) .put("inserted", i == null ? null : ISO8601_FULL_FORMAT.format(i)) .put("updated", u == null ? null : ISO8601_FULL_FORMAT.format(u)); }
Example #22
Source File: UserParamConverter.java From openmeetings with Apache License 2.0 | 5 votes |
@Override public UserDTO fromString(String val) { JSONObject o = new JSONObject(val); if (o.has(ROOT)) { o = o.getJSONObject(ROOT); } return UserDTO.get(o); }
Example #23
Source File: WsMessageWbFile.java From openmeetings with Apache License 2.0 | 5 votes |
public WsMessageWbFile(Long roomId, long wbId, String ruid, JSONObject file, BaseFileItem fi) { this.roomId = roomId; this.wbId = wbId; this.ruid = ruid; this.file = file.toString(new NullStringer()); this.fi = fi; }
Example #24
Source File: TestCalendarService.java From openmeetings with Apache License 2.0 | 5 votes |
private static JSONObject createAppointment(String title) { return new JSONObject() .put("title", title) .put("start", "2025-01-20T20:30:03+0300") .put("end", "2025-01-20T21:30:03+0300") .put("description", "Русский Тест") .put("reminder", "EMAIL") .put("room", new JSONObject() .put("name", "test24") .put("comment", "appointment test room") .put("type", "CONFERENCE") .put("capacity", 15) .put("appointment", true) .put("isPublic", false) .put("demo", false) .put("closed", false) .put("externalId", 10) .put("externalType", "HuntingLabCMS") .put("redirectUrl", "") .put("moderated", true) .put("allowUserQuestions", true) .put("allowRecording", false) .put("waitRecording", false) .put("audioOnly", true)) .put("languageId", 9) .put("passwordProtected", false) .put("connectedEvent", false) .put("reminderEmailSend", false); }
Example #25
Source File: OmAjaxClientInfoBehavior.java From openmeetings with Apache License 2.0 | 5 votes |
@Override public void renderHead(Component component, IHeaderResponse response) { super.renderHead(component, response); response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forReference(MAIN_JS))); response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forScript( String.format("OmUtil.init(%s)", new JSONObject() .put("debug", DEVELOPMENT == Application.get().getConfigurationType())) , "om-util-init"))); }
Example #26
Source File: ConfigurationDao.java From openmeetings with Apache License 2.0 | 5 votes |
private static JSONObject getHotkey(String value) { List<String> partList = List.of(value.split("\\+")); Set<String> parts = new HashSet<>(partList); return new JSONObject() .put("alt", parts.contains("Alt")) .put("shift", parts.contains("Shift")) .put("ctrl", parts.contains("Ctrl")) .put("code", partList.get(partList.size() - 1)); }
Example #27
Source File: ODateField.java From Orienteer with Apache License 2.0 | 5 votes |
private JSONObject getDatePickerParams() { JSONObject params = new JSONObject(); params.put("autoclose", Boolean.toString(true)); params.put("language", getLocale().getLanguage()); params.put("orientation", "bottom"); params.put("weekStart", Integer.toString(1)); params.put("format", getJavaScriptDatePattern()); return params; }
Example #28
Source File: Client.java From openmeetings with Apache License 2.0 | 5 votes |
public JSONObject toJson() { return addUserJson(new JSONObject() .put("uid", uuid) .put("type", type.name()) .put("width", swidth) .put("height", sheight) .put("activities", new JSONArray(sactivities)) .put("cuid", uid)); }
Example #29
Source File: RoomFileDTO.java From openmeetings with Apache License 2.0 | 5 votes |
public static RoomFileDTO get(JSONObject o) { if (o == null) { return null; } RoomFileDTO rf = new RoomFileDTO(); rf.id = optLong(o, "id"); rf.fileId = o.getLong("fileId"); rf.wbIdx = optLong(o, "wbIdx"); return rf; }
Example #30
Source File: QuickPollManager.java From openmeetings with Apache License 2.0 | 5 votes |
public JSONObject toJson(Long roomId) { boolean started = isStarted(roomId); JSONObject o = new JSONObject().put("started", started); if (started) { Map<Long, Boolean> votes = map().get(roomId); o.put("voted", votes.containsKey(getUserId())); o.put("pros", votes.entrySet().stream().filter(Entry::getValue).count()) .put("cons", votes.entrySet().stream().filter(e -> !e.getValue()).count()); } return o; }