use of com.github.openjson.JSONObject in project triplea by triplea-game.
the class TripleAForumPoster method getToken.
private String getToken(final CloseableHttpClient client, final int userId) throws IOException {
final HttpPost post = new HttpPost(tripleAForumURL + "/api/v1/users/" + userId + "/tokens");
post.setEntity(new UrlEncodedFormEntity(Collections.singletonList(newPasswordParameter()), StandardCharsets.UTF_8));
HttpProxy.addProxy(post);
try (CloseableHttpResponse response = client.execute(post)) {
final String rawJson = EntityUtils.toString(response.getEntity());
final JSONObject jsonObject = new JSONObject(rawJson);
if (jsonObject.has("code")) {
final String code = jsonObject.getString("code");
if (code.equalsIgnoreCase("ok")) {
return jsonObject.getJSONObject("payload").getString("token");
}
throw new IllegalStateException("Failed to retrieve Token. Code: " + code + " Message: " + jsonObject.getString("message"));
}
throw new IllegalStateException("Failed to retrieve Token, server did not return correct JSON: " + rawJson);
}
}
use of com.github.openjson.JSONObject in project openmeetings by apache.
the class CalendarPanel method onInitialize.
@Override
protected void onInitialize() {
final Form<Date> form = new Form<>("form");
add(form);
dialog = new AppointmentDialog("appointment", this, new CompoundPropertyModel<>(getDefault()));
add(dialog);
boolean isRtl = isRtl();
Options options = new Options();
options.set("isRTL", isRtl);
options.set("header", isRtl ? "{left: 'agendaDay,agendaWeek,month', center: 'title', right: 'today nextYear,next,prev,prevYear'}" : "{left: 'prevYear,prev,next,nextYear today', center: 'title', right: 'month,agendaWeek,agendaDay'}");
options.set("allDaySlot", false);
options.set("axisFormat", Options.asString("H(:mm)"));
options.set("defaultEventMinutes", 60);
options.set("timeFormat", Options.asString("H(:mm)"));
options.set("buttonText", new JSONObject().put("month", getString("801")).put("week", getString("800")).put("day", getString("799")).put("today", getString("1555")).toString());
JSONArray monthes = new JSONArray();
JSONArray shortMonthes = new JSONArray();
JSONArray days = new JSONArray();
JSONArray shortDays = new JSONArray();
// first week day must be Sunday
days.put(0, getString("466"));
shortDays.put(0, getString("459"));
for (int i = 0; i < 12; i++) {
monthes.put(i, getString(String.valueOf(469 + i)));
shortMonthes.put(i, getString(String.valueOf(1556 + i)));
if (i + 1 < 7) {
days.put(i + 1, getString(String.valueOf(460 + i)));
shortDays.put(i + 1, getString(String.valueOf(453 + i)));
}
}
options.set("monthNames", monthes.toString());
options.set("monthNamesShort", shortMonthes.toString());
options.set("dayNames", days.toString());
options.set("dayNamesShort", shortDays.toString());
options.set("firstDay", cfgDao.getInt(CONFIG_CALENDAR_FIRST_DAY, 0));
calendar = new Calendar("calendar", new AppointmentModel(), options) {
private static final long serialVersionUID = 1L;
@Override
protected void onInitialize() {
super.onInitialize();
add(new CalendarFunctionsBehavior(getMarkupId()));
}
@Override
public boolean isSelectable() {
return true;
}
@Override
public boolean isDayClickEnabled() {
return true;
}
@Override
public boolean isEventClickEnabled() {
return true;
}
@Override
public boolean isEventDropEnabled() {
return true;
}
@Override
public boolean isEventResizeEnabled() {
return true;
}
// no need to override onDayClick
@Override
public void onSelect(AjaxRequestTarget target, CalendarView view, LocalDateTime start, LocalDateTime end, boolean allDay) {
Appointment a = getDefault();
LocalDateTime s = start, e = end;
if (CalendarView.month == view) {
LocalDateTime now = ZonedDateTime.now(getZoneId()).toLocalDateTime();
s = start.withHour(now.getHour()).withMinute(now.getMinute());
e = s.plus(1, ChronoUnit.HOURS);
}
a.setStart(getDate(s));
a.setEnd(getDate(e));
dialog.setModelObjectWithAjaxTarget(a, target);
dialog.open(target);
}
@Override
public void onEventClick(AjaxRequestTarget target, CalendarView view, int eventId) {
Appointment a = apptDao.get((long) eventId);
dialog.setModelObjectWithAjaxTarget(a, target);
dialog.open(target);
}
@Override
public void onEventDrop(AjaxRequestTarget target, int eventId, long delta, boolean allDay) {
Appointment a = apptDao.get((long) eventId);
if (!AppointmentDialog.isOwner(a)) {
return;
}
java.util.Calendar cal = WebSession.getCalendar();
cal.setTime(a.getStart());
cal.add(java.util.Calendar.MILLISECOND, (int) delta);
a.setStart(cal.getTime());
cal.setTime(a.getEnd());
cal.add(java.util.Calendar.MILLISECOND, (int) delta);
a.setEnd(cal.getTime());
apptDao.update(a, getUserId());
if (a.getCalendar() != null) {
updatedeleteAppointment(target, CalendarDialog.DIALOG_TYPE.UPDATE_APPOINTMENT, a);
}
}
@Override
public void onEventResize(AjaxRequestTarget target, int eventId, long delta) {
Appointment a = apptDao.get((long) eventId);
if (!AppointmentDialog.isOwner(a)) {
return;
}
java.util.Calendar cal = WebSession.getCalendar();
cal.setTime(a.getEnd());
cal.add(java.util.Calendar.MILLISECOND, (int) delta);
a.setEnd(cal.getTime());
apptDao.update(a, getUserId());
if (a.getCalendar() != null) {
updatedeleteAppointment(target, CalendarDialog.DIALOG_TYPE.UPDATE_APPOINTMENT, a);
}
}
};
form.add(calendar);
populateGoogleCalendars();
add(refreshTimer);
add(syncTimer);
calendarDialog = new CalendarDialog("calendarDialog", this, new CompoundPropertyModel<>(getDefaultCalendar()));
add(calendarDialog);
calendarListContainer.setOutputMarkupId(true);
calendarListContainer.add(new ListView<OmCalendar>("items", new LoadableDetachableModel<List<OmCalendar>>() {
private static final long serialVersionUID = 1L;
@Override
protected List<OmCalendar> load() {
List<OmCalendar> cals = new ArrayList<>(apptManager.getCalendars(getUserId()));
cals.addAll(apptManager.getGoogleCalendars(getUserId()));
return cals;
}
}) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(final ListItem<OmCalendar> item) {
item.setOutputMarkupId(true);
final OmCalendar cal = item.getModelObject();
item.add(new Button("item", new PropertyModel<String>(cal, "title")).add(new AjaxEventBehavior(EVT_CLICK) {
private static final long serialVersionUID = 1L;
@Override
protected void onEvent(AjaxRequestTarget target) {
calendarDialog.open(target, CalendarDialog.DIALOG_TYPE.UPDATE_CALENDAR, cal);
target.add(calendarDialog);
}
}));
}
});
add(new Button("syncCalendarButton").add(new AjaxEventBehavior(EVT_CLICK) {
private static final long serialVersionUID = 1L;
@Override
protected void onEvent(AjaxRequestTarget target) {
syncCalendar(target);
}
}));
add(new Button("submitCalendar").add(new AjaxEventBehavior(EVT_CLICK) {
private static final long serialVersionUID = 1L;
@Override
protected void onEvent(AjaxRequestTarget target) {
calendarDialog.open(target, CalendarDialog.DIALOG_TYPE.UPDATE_CALENDAR, getDefaultCalendar());
target.add(calendarDialog);
}
}));
add(calendarListContainer);
super.onInitialize();
}
use of com.github.openjson.JSONObject in project openmeetings by apache.
the class WbConverter method processText.
private static void processText(Whiteboard wb, List<?> props) {
if (props.size() < 12) {
return;
}
String color = getColor(getInt(props, 2));
String style = (String) props.get(4);
JSONObject o = setColor(init(wb, props), color, color).put(ATTR_TYPE, "i-text").put("text", props.get(1)).put("fontSize", props.get(3));
if (style.indexOf("bold") > -1) {
o.put("fontWeight", "bold");
}
if (style.indexOf("italic") > -1) {
o.put("fontStyle", "inalic");
}
add(wb, o);
}
use of com.github.openjson.JSONObject in project openmeetings by apache.
the class RoomPanel method onEvent.
@Override
public void onEvent(IEvent<?> event) {
Client _c = getClient();
if (_c != null && event.getPayload() instanceof WebSocketPushPayload) {
WebSocketPushPayload wsEvent = (WebSocketPushPayload) event.getPayload();
if (wsEvent.getMessage() instanceof RoomMessage) {
RoomMessage m = (RoomMessage) wsEvent.getMessage();
IPartialPageRequestHandler handler = wsEvent.getHandler();
switch(m.getType()) {
case pollCreated:
menu.updatePoll(handler, m.getUserId());
break;
case pollUpdated:
menu.updatePoll(handler, null);
break;
case recordingStoped:
{
String uid = ((TextRoomMessage) m).getText();
Client c = cm.getBySid(uid);
if (c == null) {
log.error("Not existing/BAD user has stopped recording {} != {} !!!!", uid);
return;
}
recordingUser = null;
cm.update(c.remove(Client.Activity.record));
menu.update(handler);
updateInterviewRecordingButtons(handler);
}
break;
case recordingStarted:
{
JSONObject obj = new JSONObject(((TextRoomMessage) m).getText());
String sid = obj.getString("sid");
Client c = cm.getBySid(sid);
if (c == null) {
log.error("Not existing user has started recording {} !!!!", sid);
return;
}
recordingUser = sid;
cm.update(c.set(Client.Activity.record));
menu.update(handler);
updateInterviewRecordingButtons(handler);
}
break;
case sharingStoped:
{
JSONObject obj = new JSONObject(((TextRoomMessage) m).getText());
String uid = obj.getString("uid");
Client c = cm.getBySid(obj.getString("sid"));
if (c == null) {
log.error("Not existing user has started sharing {} !!!!", obj);
return;
}
handler.appendJavaScript(String.format("VideoManager.close('%s', true);", uid));
sharingUser = null;
cm.update(c.removeStream(uid).remove(Client.Activity.share));
menu.update(handler);
}
break;
case sharingStarted:
{
String uid = ((TextRoomMessage) m).getText();
Client c = cm.get(uid);
if (c == null) {
log.error("Not existing user has started sharing {} !!!!", uid);
return;
}
sharingUser = uid;
cm.update(c.set(Client.Activity.share));
menu.update(handler);
}
break;
case rightUpdated:
{
String uid = ((TextRoomMessage) m).getText();
Client c = cm.get(uid);
if (c == null) {
log.error("Not existing user in rightUpdated {} !!!!", uid);
return;
}
boolean self = _c.getUid().equals(c.getUid());
handler.appendJavaScript(String.format("VideoManager.update(%s);", c.streamJson(_c.getSid(), self, scm).toString(new NullStringer())));
sidebar.update(handler);
menu.update(handler);
wb.update(handler);
updateInterviewRecordingButtons(handler);
}
break;
case newStream:
{
JSONObject obj = new JSONObject(((TextRoomMessage) m).getText());
String uid = obj.getString("uid");
Client c = cm.get(uid);
if (c == null) {
// screen client, ext video stream
c = cm.getBySid(obj.getString("sid"));
}
if (c == null) {
log.error("Not existing user in newStream {} !!!!", uid);
return;
}
boolean self = _c.getSid().equals(c.getSid());
if (!self || Client.Type.room != scm.get(uid).getType()) {
// stream from others or self external video
JSONObject jo = videoJson(c, _c.getSid(), uid);
handler.appendJavaScript(String.format("VideoManager.play(%s);", jo));
}
if (self) {
cm.update(c.addStream(uid));
}
updateInterviewRecordingButtons(handler);
}
break;
case closeStream:
{
JSONObject obj = new JSONObject(((TextRoomMessage) m).getText());
String uid = obj.getString("uid");
Client c = cm.getBySid(obj.getString("sid"));
if (c != null) {
// c == null means client exits the room
if (_c.getUid().equals(c.getUid())) {
cm.update(c.removeStream(uid));
}
}
handler.appendJavaScript(String.format("VideoManager.close('%s');", uid));
updateInterviewRecordingButtons(handler);
}
break;
case roomEnter:
sidebar.update(handler);
menu.update(handler);
sidebar.addActivity(new Activity(m, Activity.Type.roomEnter), handler);
break;
case roomExit:
sidebar.update(handler);
sidebar.addActivity(new Activity(m, Activity.Type.roomExit), handler);
break;
case roomClosed:
handler.add(room.setVisible(false));
roomClosed.open(handler);
break;
case requestRightModerator:
sidebar.addActivity(new Activity((TextRoomMessage) m, Activity.Type.reqRightModerator), handler);
break;
case requestRightPresenter:
sidebar.addActivity(new Activity((TextRoomMessage) m, Activity.Type.reqRightPresenter), handler);
break;
case requestRightWb:
sidebar.addActivity(new Activity((TextRoomMessage) m, Activity.Type.reqRightWb), handler);
break;
case requestRightShare:
sidebar.addActivity(new Activity((TextRoomMessage) m, Activity.Type.reqRightShare), handler);
break;
case requestRightRemote:
sidebar.addActivity(new Activity((TextRoomMessage) m, Activity.Type.reqRightRemote), handler);
break;
case requestRightA:
sidebar.addActivity(new Activity((TextRoomMessage) m, Activity.Type.reqRightA), handler);
break;
case requestRightAv:
sidebar.addActivity(new Activity((TextRoomMessage) m, Activity.Type.reqRightAv), handler);
break;
case requestRightMute:
sidebar.addActivity(new Activity((TextRoomMessage) m, Activity.Type.reqRightMute), handler);
break;
case requestRightExclusive:
sidebar.addActivity(new Activity((TextRoomMessage) m, Activity.Type.reqRightExclusive), handler);
break;
case activityRemove:
sidebar.removeActivity(((TextRoomMessage) m).getText(), handler);
break;
case haveQuestion:
if (_c.hasRight(Room.Right.moderator) || getUserId().equals(m.getUserId())) {
sidebar.addActivity(new Activity((TextRoomMessage) m, Activity.Type.haveQuestion), handler);
}
break;
case kick:
{
String uid = ((TextRoomMessage) m).getText();
if (_c.getUid().equals(uid)) {
handler.add(room.setVisible(false));
getMainPanel().getChat().toggle(handler, false);
clientKicked.open(handler);
cm.exitRoom(_c);
}
}
break;
case mute:
{
JSONObject obj = new JSONObject(((TextRoomMessage) m).getText());
Client c = cm.getBySid(obj.getString("sid"));
if (c == null) {
log.error("Not existing user in mute {} !!!!", obj);
return;
}
if (!_c.getUid().equals(c.getUid())) {
handler.appendJavaScript(String.format("if (typeof(VideoManager) !== 'undefined') {VideoManager.mute('%s', %s);}", obj.getString("uid"), obj.getBoolean("mute")));
}
}
break;
case exclusive:
{
String uid = ((TextRoomMessage) m).getText();
Client c = cm.get(uid);
if (c == null) {
// no luck
return;
}
handler.appendJavaScript(String.format("if (typeof(VideoManager) !== 'undefined') {VideoManager.exclusive('%s');}", uid));
}
break;
case quickPollUpdated:
{
menu.update(handler);
handler.appendJavaScript(getQuickPollJs());
}
break;
}
}
}
super.onEvent(event);
}
use of com.github.openjson.JSONObject in project openmeetings by apache.
the class RoomResourceReference method getFileItem.
@Override
protected FileItem getFileItem(Attributes attr) {
PageParameters params = attr.getParameters();
StringValue _id = params.get("id");
String uid = params.get("uid").toString();
Long id = null;
try {
id = _id.toOptionalLong();
} catch (NumberFormatException e) {
// no-op expected
}
WebSession ws = WebSession.get();
Client c = cm.get(uid);
if (id == null || !ws.isSignedIn() || c == null) {
return null;
}
FileItem f = (FileItem) fileDao.getAny(id);
if (f == null) {
return null;
}
String ruid = params.get("ruid").toString();
String wuid = params.get("wuid").toString();
if (c.getRoom() != null) {
Whiteboards wbs = wbManager.get(c.getRoom().getId());
if (!Strings.isEmpty(wuid) && !Strings.isEmpty(ruid) && ruid.equals(wbs.getUid())) {
for (Entry<Long, Whiteboard> e : wbs.getWhiteboards().entrySet()) {
JSONObject file = e.getValue().get(wuid);
if (file != null && f.getId().equals(file.optLong(ATTR_FILE_ID))) {
// item IS on WB
return f;
}
}
}
}
if (f.getGroupId() != null && groupUserDao.isUserInGroup(f.getGroupId(), getUserId())) {
return f;
}
return null;
}
Aggregations