Java Code Examples for com.github.openjson.JSONObject#optString()

The following examples show how to use com.github.openjson.JSONObject#optString() . 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: UserDTO.java    From openmeetings with Apache License 2.0 6 votes vote down vote up
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 2
Source File: InvitationDTO.java    From openmeetings with Apache License 2.0 6 votes vote down vote up
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 3
Source File: RemoteSessionObject.java    From openmeetings with Apache License 2.0 5 votes vote down vote up
public static RemoteSessionObject fromString(String s) {
	JSONObject o = new JSONObject(s);
	RemoteSessionObject ro = new RemoteSessionObject();
	ro.username = o.optString("username");
	ro.firstname = o.optString("firstname");
	ro.lastname = o.optString("lastname");
	ro.pictureUrl = o.optString("pictureUrl");
	ro.email = o.optString("email");
	ro.externalId = o.getString("externalId");
	ro.externalType = o.getString("externalType");
	return ro;
}
 
Example 4
Source File: ExternalUserDTO.java    From openmeetings with Apache License 2.0 5 votes vote down vote up
public static ExternalUserDTO fromString(String s) {
	JSONObject o = new JSONObject(s);
	ExternalUserDTO u = new ExternalUserDTO();
	u.email = o.optString("email", null);
	u.externalId = o.optString("externalId", null);
	u.externalType = o.optString("externalType", null);
	u.firstname = o.optString("firstname", null);
	u.lastname = o.optString("lastname", null);
	u.login = o.optString("login", null);
	u.profilePictureUrl = o.optString("profilePictureUrl", null);
	return u;
}
 
Example 5
Source File: RoomDTO.java    From openmeetings with Apache License 2.0 5 votes vote down vote up
public static RoomDTO get(JSONObject o) {
	if (o == null) {
		return null;
	}
	RoomDTO r = new RoomDTO();
	r.id = optLong(o, "id");
	r.name = o.optString("name");
	r.tag = o.optString("tag");
	r.comment = o.optString("comment");
	r.type = optEnum(Room.Type.class, o, "type");
	if (r.type == null) {
		throw new IllegalArgumentException("Room should have valid type");
	}
	r.capacity = o.optLong("capacity", 4);
	r.appointment = o.optBoolean("appointment", false);
	r.confno = o.optString("confno");
	r.isPublic = o.optBoolean("isPublic", false);
	r.demo = o.optBoolean("demo", false);
	r.closed = o.optBoolean("closed", false);
	r.demoTime = optInt(o, "demoTime");
	r.externalId = o.optString("externalId", null);
	r.externalType = o.optString("externalType", null);
	r.redirectUrl = o.optString("redirectUrl");
	r.moderated = o.optBoolean("moderated", false);
	r.waitModerator = o.optBoolean("waitModerator", false);
	r.allowUserQuestions = o.optBoolean("allowUserQuestions", false);
	r.allowRecording = o.optBoolean("allowRecording", false);
	r.waitRecording = o.optBoolean("waitRecording", false);
	r.audioOnly = o.optBoolean("audioOnly", false);
	r.getHiddenElements().addAll(optEnumList(RoomElement.class, o.optJSONArray("hiddenElements")));
	JSONArray fa = o.optJSONArray("files");
	if (fa != null) {
		for (int i = 0; i < fa.length(); ++i) {
			r.getFiles().add(RoomFileDTO.get(fa.getJSONObject(i)));
		}
	}
	return r;
}
 
Example 6
Source File: SignInPage.java    From openmeetings with Apache License 2.0 5 votes vote down vote up
AuthInfo(String jsonStr) {
	log.debug("AuthInfo={}", jsonStr);
	JSONObject json = new JSONObject(jsonStr);
	accessToken = json.optString("access_token");
	refreshToken = json.optString("refresh_token");
	tokenType = json.optString("token_type");
	userId = json.optString("user_id");
	expiresIn = json.optLong("expires_in");
}
 
Example 7
Source File: RoomPanel.java    From openmeetings with Apache License 2.0 5 votes vote down vote up
@Override
protected void process(IPartialPageRequestHandler handler, JSONObject o) throws IOException {
	if (room.isVisible() && "room".equals(o.optString("area"))) {
		final String type = o.optString("type");
		if ("wb".equals(type)) {
			WbAction a = WbAction.valueOf(o.getString(PARAM_ACTION));
			wb.processWbAction(a, o.optJSONObject("data"), handler);
		} else if ("room".equals(type)) {
			sidebar.roomAction(handler, o);
		} else if ("av".equals(type)) {
			ExtendedClientProperties cp = WebSession.get().getExtendedProperties();
			Client c = cp.setSettings(o.optJSONObject("settings")).update(getClient());
			if (!avInited) {
				avInited = true;
				if (Room.Type.CONFERENCE == r.getType()) {
					if (!activityAllowed(c, Client.Activity.AUDIO, c.getRoom())) {
						c.allow(Room.Right.AUDIO);
					}
					if (!c.getRoom().isAudioOnly() && !activityAllowed(c, Client.Activity.VIDEO, c.getRoom())) {
						c.allow(Room.Right.VIDEO);
					}
					streamProcessor.toggleActivity(c, c.getRoom().isAudioOnly()
							? Client.Activity.AUDIO
							: Client.Activity.AUDIO_VIDEO);
				}
			}
			c.getCamStreams().forEach(sd -> {
				sd.setWidth(c.getWidth());
				sd.setHeight(c.getHeight());
			});
			broadcast(c);
		}
	}
}
 
Example 8
Source File: StreamProcessor.java    From openmeetings with Apache License 2.0 4 votes vote down vote up
void onMessage(Client c, final String cmdId, JSONObject msg) {
	final String uid = msg.optString("uid");
	KStream sender;
	StreamDesc sd;
	Optional<StreamDesc> osd;
	log.debug("Incoming message from user with ID '{}': {}", c.getUserId(), msg);
	switch (cmdId) {
		case "devicesAltered":
			sd = c.getStream(uid);
			if (sd != null) {
				if (!msg.getBoolean("audio") && c.hasActivity(Activity.AUDIO)) {
					c.remove(Activity.AUDIO);
				}
				if (!msg.getBoolean("video") && c.hasActivity(Activity.VIDEO)) {
					c.remove(Activity.VIDEO);
				}
				sd.setActivities();
				WebSocketHelper.sendRoom(new TextRoomMessage(c.getRoomId(), cm.update(c), RoomMessage.Type.RIGHT_UPDATED, c.getUid()));
			}
			break;
		case "toggleActivity":
			toggleActivity(c, Activity.valueOf(msg.getString("activity")));
			break;
		case "broadcastStarted":
			handleBroadcastStarted(c, uid, msg);
			break;
		case "onIceCandidate":
			sender = getByUid(uid);
			if (sender != null) {
				JSONObject candidate = msg.getJSONObject(PARAM_CANDIDATE);
				String candStr = candidate.getString(PARAM_CANDIDATE);
				if (!Strings.isEmpty(candStr)) {
					IceCandidate cand = new IceCandidate(
							candStr
							, candidate.getString("sdpMid")
							, candidate.getInt("sdpMLineIndex"));
					sender.addCandidate(cand, msg.getString("luid"));
				}
			}
			break;
		case "addListener":
			sender = getByUid(msg.getString("sender"));
			if (sender != null) {
				Client sendClient = cm.getBySid(sender.getSid());
				sd = sendClient.getStream(sender.getUid());
				if (sd == null) {
					break;
				}
				if (StreamType.SCREEN == sd.getType() && sd.hasActivity(Activity.RECORD) && !sd.hasActivity(Activity.SCREEN)) {
					break;
				}
				sender.addListener(this, c.getSid(), c.getUid(), msg.getString("sdpOffer"));
			}
			break;
		case "wannaShare":
			osd = c.getScreenStream();
			if (screenShareAllowed(c) || (osd.isPresent() && !osd.get().hasActivity(Activity.SCREEN))) {
				startSharing(c, osd, msg, Activity.SCREEN);
			}
			break;
		case "wannaRecord":
			osd = c.getScreenStream();
			if (recordingAllowed(c)) {
				Room r = c.getRoom();
				if (Room.Type.INTERVIEW == r.getType()) {
					log.warn("This shouldn't be called for interview room");
					break;
				}
				boolean sharing = isSharing(r.getId());
				startSharing(c, osd, msg, Activity.RECORD);
				if (sharing) {
					startRecording(c);
				}
			}
			break;
		case "pauseSharing":
			pauseSharing(c, uid);
			break;
		case "stopRecord":
			stopRecording(c);
			break;
		case "errorSharing":
			errorSharing(c);
			break;
		default:
			// no-op
			break;
	}
}