Search in sources :

Example 26 with JsonParser

use of com.google.gson.JsonParser in project bigbluebutton by bigbluebutton.

the class SendLockSettingsMessage method fromJson.

public static SendLockSettingsMessage fromJson(String message) {
    JsonParser parser = new JsonParser();
    JsonObject obj = (JsonObject) parser.parse(message);
    if (obj.has("header") && obj.has("payload")) {
        JsonObject header = (JsonObject) obj.get("header");
        JsonObject payload = (JsonObject) obj.get("payload");
        if (header.has("name")) {
            String messageName = header.get("name").getAsString();
            if (SEND_LOCK_SETTINGS.equals(messageName)) {
                if (payload.has(Constants.MEETING_ID) && payload.has(Constants.USER_ID) && payload.has(Constants.SETTINGS)) {
                    JsonObject settingsObj = (JsonObject) payload.get(Constants.SETTINGS).getAsJsonObject();
                    if (settingsObj.has(Constants.DISABLE_CAMERA) && settingsObj.has(Constants.DISABLE_CAMERA) && settingsObj.has(Constants.DISABLE_MICROPHONE) && settingsObj.has(Constants.DISABLE_PRIVATE_CHAT) && settingsObj.has(Constants.DISABLE_PUBLIC_CHAT) && settingsObj.has(Constants.LOCKED_LAYOUT) && settingsObj.has(Constants.LOCK_ON_JOIN) && settingsObj.has(Constants.LOCK_ON_JOIN_CONFIGURABLE)) {
                        Map<String, Boolean> settingsMap = new HashMap<String, Boolean>();
                        settingsMap.put("disableCam", settingsObj.get(Constants.DISABLE_CAMERA).getAsBoolean());
                        settingsMap.put("disableMic", settingsObj.get(Constants.DISABLE_MICROPHONE).getAsBoolean());
                        settingsMap.put("disablePrivateChat", settingsObj.get(Constants.DISABLE_PRIVATE_CHAT).getAsBoolean());
                        settingsMap.put("disablePublicChat", settingsObj.get(Constants.DISABLE_PUBLIC_CHAT).getAsBoolean());
                        settingsMap.put("lockedLayout", settingsObj.get(Constants.LOCKED_LAYOUT).getAsBoolean());
                        settingsMap.put("lockOnJoin", settingsObj.get(Constants.LOCK_ON_JOIN).getAsBoolean());
                        settingsMap.put("lockOnJoinConfigurable", settingsObj.get(Constants.LOCK_ON_JOIN_CONFIGURABLE).getAsBoolean());
                        String meetingId = payload.get(Constants.MEETING_ID).getAsString();
                        String userId = payload.get(Constants.USER_ID).getAsString();
                        return new SendLockSettingsMessage(meetingId, userId, settingsMap);
                    }
                }
            }
        }
    }
    return null;
}
Also used : HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Example 27 with JsonParser

use of com.google.gson.JsonParser in project bigbluebutton by bigbluebutton.

the class SendPageCountErrorMessage method fromJson.

public static SendPageCountErrorMessage fromJson(String message) {
    JsonParser parser = new JsonParser();
    JsonObject obj = (JsonObject) parser.parse(message);
    if (obj.has("header") && obj.has("payload")) {
        JsonObject header = (JsonObject) obj.get("header");
        JsonObject payload = (JsonObject) obj.get("payload");
        if (header.has("name")) {
            String messageName = header.get("name").getAsString();
            if (SEND_PAGE_COUNT_ERROR.equals(messageName)) {
                if (payload.has(Constants.MEETING_ID) && payload.has(Constants.MESSAGE_KEY) && payload.has(Constants.CODE) && payload.has(Constants.PRESENTATION_ID) && payload.has(Constants.MAX_NUM_PAGES) && payload.has(Constants.NUM_PAGES) && payload.has(Constants.PRESENTATION_NAME)) {
                    String meetingId = payload.get(Constants.MEETING_ID).getAsString();
                    String messageKey = payload.get(Constants.MESSAGE_KEY).getAsString();
                    String code = payload.get(Constants.CODE).getAsString();
                    String presId = payload.get(Constants.PRESENTATION_ID).getAsString();
                    int numberOfPages = payload.get(Constants.NUM_PAGES).getAsInt();
                    int maxNumberPages = payload.get(Constants.MAX_NUM_PAGES).getAsInt();
                    String presName = payload.get(Constants.PRESENTATION_NAME).getAsString();
                    return new SendPageCountErrorMessage(messageKey, meetingId, code, presId, numberOfPages, maxNumberPages, presName);
                }
            }
        }
    }
    return null;
}
Also used : JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Example 28 with JsonParser

use of com.google.gson.JsonParser in project bigbluebutton by bigbluebutton.

the class SendPrivateChatMessage method fromJson.

public static SendPrivateChatMessage fromJson(String message) {
    JsonParser parser = new JsonParser();
    JsonObject obj = (JsonObject) parser.parse(message);
    if (obj.has("header") && obj.has("payload")) {
        JsonObject header = (JsonObject) obj.get("header");
        JsonObject payload = (JsonObject) obj.get("payload");
        if (header.has("name")) {
            String messageName = header.get("name").getAsString();
            if (SEND_PRIVATE_CHAT_MESSAGE.equals(messageName)) {
                if (payload.has(Constants.MEETING_ID) && payload.has(Constants.MESSAGE)) {
                    String meetingId = payload.get(Constants.MEETING_ID).getAsString();
                    JsonObject msgObj = (JsonObject) payload.get(Constants.MESSAGE).getAsJsonObject();
                    Map<String, String> messageInfo = new HashMap<String, String>();
                    if (msgObj.has(ChatKeyUtil.CHAT_TYPE) && msgObj.has(ChatKeyUtil.MESSAGE) && msgObj.has(ChatKeyUtil.TO_USERNAME) && msgObj.has(ChatKeyUtil.FROM_TZ_OFFSET) && msgObj.has(ChatKeyUtil.FROM_COLOR) && msgObj.has(ChatKeyUtil.TO_USERID) && msgObj.has(ChatKeyUtil.FROM_USERID) && msgObj.has(ChatKeyUtil.FROM_TIME) && msgObj.has(ChatKeyUtil.FROM_USERNAME)) {
                        messageInfo.put(ChatKeyUtil.CHAT_TYPE, msgObj.get(ChatKeyUtil.CHAT_TYPE).getAsString());
                        messageInfo.put(ChatKeyUtil.MESSAGE, msgObj.get(ChatKeyUtil.MESSAGE).getAsString());
                        messageInfo.put(ChatKeyUtil.TO_USERNAME, msgObj.get(ChatKeyUtil.TO_USERNAME).getAsString());
                        messageInfo.put(ChatKeyUtil.FROM_TZ_OFFSET, msgObj.get(ChatKeyUtil.FROM_TZ_OFFSET).getAsString());
                        messageInfo.put(ChatKeyUtil.FROM_COLOR, msgObj.get(ChatKeyUtil.FROM_COLOR).getAsString());
                        messageInfo.put(ChatKeyUtil.TO_USERID, msgObj.get(ChatKeyUtil.TO_USERID).getAsString());
                        messageInfo.put(ChatKeyUtil.FROM_USERID, msgObj.get(ChatKeyUtil.FROM_USERID).getAsString());
                        messageInfo.put(ChatKeyUtil.FROM_TIME, msgObj.get(ChatKeyUtil.FROM_TIME).getAsString());
                        messageInfo.put(ChatKeyUtil.FROM_USERNAME, msgObj.get(ChatKeyUtil.FROM_USERNAME).getAsString());
                        String requesterId = messageInfo.get(ChatKeyUtil.FROM_USERID);
                        return new SendPrivateChatMessage(meetingId, requesterId, messageInfo);
                    } else if (msgObj.has(Constants.CHAT_TYPE) && msgObj.has(Constants.MESSAGE) && msgObj.has(Constants.TO_USERNAME) && msgObj.has(Constants.FROM_TZ_OFFSET) && msgObj.has(Constants.FROM_COLOR) && msgObj.has(Constants.TO_USERID) && msgObj.has(Constants.FROM_USERID) && msgObj.has(Constants.FROM_TIME) && msgObj.has(Constants.FROM_USERNAME)) {
                        messageInfo.put(ChatKeyUtil.CHAT_TYPE, msgObj.get(Constants.CHAT_TYPE).getAsString());
                        messageInfo.put(ChatKeyUtil.MESSAGE, msgObj.get(Constants.MESSAGE).getAsString());
                        messageInfo.put(ChatKeyUtil.TO_USERNAME, msgObj.get(Constants.TO_USERNAME).getAsString());
                        messageInfo.put(ChatKeyUtil.FROM_TZ_OFFSET, msgObj.get(Constants.FROM_TZ_OFFSET).getAsString());
                        messageInfo.put(ChatKeyUtil.FROM_COLOR, msgObj.get(Constants.FROM_COLOR).getAsString());
                        messageInfo.put(ChatKeyUtil.TO_USERID, msgObj.get(Constants.TO_USERID).getAsString());
                        messageInfo.put(ChatKeyUtil.FROM_USERID, msgObj.get(Constants.FROM_USERID).getAsString());
                        messageInfo.put(ChatKeyUtil.FROM_TIME, msgObj.get(Constants.FROM_TIME).getAsString());
                        messageInfo.put(ChatKeyUtil.FROM_USERNAME, msgObj.get(Constants.FROM_USERNAME).getAsString());
                        String requesterId = messageInfo.get(ChatKeyUtil.FROM_USERID);
                        return new SendPrivateChatMessage(meetingId, requesterId, messageInfo);
                    }
                }
            }
        }
    }
    return null;
}
Also used : HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Example 29 with JsonParser

use of com.google.gson.JsonParser in project bigbluebutton by bigbluebutton.

the class SendPublicChatMessage method fromJson.

public static SendPublicChatMessage fromJson(String message) {
    JsonParser parser = new JsonParser();
    JsonObject obj = (JsonObject) parser.parse(message);
    if (obj.has("header") && obj.has("payload")) {
        JsonObject header = (JsonObject) obj.get("header");
        JsonObject payload = (JsonObject) obj.get("payload");
        if (header.has("name")) {
            String messageName = header.get("name").getAsString();
            if (SEND_PUBLIC_CHAT_MESSAGE.equals(messageName)) {
                if (payload.has(Constants.MEETING_ID) && payload.has(Constants.MESSAGE)) {
                    String meetingId = payload.get(Constants.MEETING_ID).getAsString();
                    JsonObject msgObj = (JsonObject) payload.get(Constants.MESSAGE).getAsJsonObject();
                    Map<String, String> messageInfo = new HashMap<String, String>();
                    if (msgObj.has(ChatKeyUtil.CHAT_TYPE) && msgObj.has(ChatKeyUtil.MESSAGE) && msgObj.has(ChatKeyUtil.TO_USERNAME) && msgObj.has(ChatKeyUtil.FROM_TZ_OFFSET) && msgObj.has(ChatKeyUtil.FROM_COLOR) && msgObj.has(ChatKeyUtil.TO_USERID) && msgObj.has(ChatKeyUtil.FROM_USERID) && msgObj.has(ChatKeyUtil.FROM_TIME) && msgObj.has(ChatKeyUtil.FROM_USERNAME)) {
                        messageInfo.put(ChatKeyUtil.CHAT_TYPE, msgObj.get(ChatKeyUtil.CHAT_TYPE).getAsString());
                        messageInfo.put(ChatKeyUtil.MESSAGE, msgObj.get(ChatKeyUtil.MESSAGE).getAsString());
                        messageInfo.put(ChatKeyUtil.TO_USERNAME, msgObj.get(ChatKeyUtil.TO_USERNAME).getAsString());
                        messageInfo.put(ChatKeyUtil.FROM_TZ_OFFSET, msgObj.get(ChatKeyUtil.FROM_TZ_OFFSET).getAsString());
                        messageInfo.put(ChatKeyUtil.FROM_COLOR, msgObj.get(ChatKeyUtil.FROM_COLOR).getAsString());
                        messageInfo.put(ChatKeyUtil.TO_USERID, msgObj.get(ChatKeyUtil.TO_USERID).getAsString());
                        messageInfo.put(ChatKeyUtil.FROM_USERID, msgObj.get(ChatKeyUtil.FROM_USERID).getAsString());
                        messageInfo.put(ChatKeyUtil.FROM_TIME, msgObj.get(ChatKeyUtil.FROM_TIME).getAsString());
                        messageInfo.put(ChatKeyUtil.FROM_USERNAME, msgObj.get(ChatKeyUtil.FROM_USERNAME).getAsString());
                        String requesterId = messageInfo.get(ChatKeyUtil.FROM_USERID);
                        return new SendPublicChatMessage(meetingId, requesterId, messageInfo);
                    } else if (msgObj.has(Constants.CHAT_TYPE) && msgObj.has(Constants.MESSAGE) && msgObj.has(Constants.TO_USERNAME) && msgObj.has(Constants.FROM_TZ_OFFSET) && msgObj.has(Constants.FROM_COLOR) && msgObj.has(Constants.TO_USERID) && msgObj.has(Constants.FROM_USERID) && msgObj.has(Constants.FROM_TIME) && msgObj.has(Constants.FROM_USERNAME)) {
                        messageInfo.put(ChatKeyUtil.CHAT_TYPE, msgObj.get(Constants.CHAT_TYPE).getAsString());
                        messageInfo.put(ChatKeyUtil.MESSAGE, msgObj.get(Constants.MESSAGE).getAsString());
                        messageInfo.put(ChatKeyUtil.TO_USERNAME, msgObj.get(Constants.TO_USERNAME).getAsString());
                        messageInfo.put(ChatKeyUtil.FROM_TZ_OFFSET, msgObj.get(Constants.FROM_TZ_OFFSET).getAsString());
                        messageInfo.put(ChatKeyUtil.FROM_COLOR, msgObj.get(Constants.FROM_COLOR).getAsString());
                        messageInfo.put(ChatKeyUtil.TO_USERID, msgObj.get(Constants.TO_USERID).getAsString());
                        messageInfo.put(ChatKeyUtil.FROM_USERID, msgObj.get(Constants.FROM_USERID).getAsString());
                        messageInfo.put(ChatKeyUtil.FROM_TIME, msgObj.get(Constants.FROM_TIME).getAsString());
                        messageInfo.put(ChatKeyUtil.FROM_USERNAME, msgObj.get(Constants.FROM_USERNAME).getAsString());
                        String requesterId = messageInfo.get(ChatKeyUtil.FROM_USERID);
                        return new SendPublicChatMessage(meetingId, requesterId, messageInfo);
                    }
                }
            }
        }
    }
    return null;
}
Also used : HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Example 30 with JsonParser

use of com.google.gson.JsonParser in project bigbluebutton by bigbluebutton.

the class SendSlideGeneratedMessage method fromJson.

public static SendSlideGeneratedMessage fromJson(String message) {
    JsonParser parser = new JsonParser();
    JsonObject obj = (JsonObject) parser.parse(message);
    if (obj.has("header") && obj.has("payload")) {
        JsonObject header = (JsonObject) obj.get("header");
        JsonObject payload = (JsonObject) obj.get("payload");
        if (header.has("name")) {
            String messageName = header.get("name").getAsString();
            if (SEND_SLIDE_GENERATED.equals(messageName)) {
                if (payload.has(Constants.MEETING_ID) && payload.has(Constants.MESSAGE_KEY) && payload.has(Constants.CODE) && payload.has(Constants.PRESENTATION_ID) && payload.has(Constants.PAGES_COMPLETED) && payload.has(Constants.NUM_PAGES) && payload.has(Constants.PRESENTATION_NAME)) {
                    String meetingId = payload.get(Constants.MEETING_ID).getAsString();
                    String messageKey = payload.get(Constants.MESSAGE_KEY).getAsString();
                    String code = payload.get(Constants.CODE).getAsString();
                    String presId = payload.get(Constants.PRESENTATION_ID).getAsString();
                    int numberOfPages = payload.get(Constants.NUM_PAGES).getAsInt();
                    int pagesCompleted = payload.get(Constants.PAGES_COMPLETED).getAsInt();
                    String presName = payload.get(Constants.PRESENTATION_NAME).getAsString();
                    return new SendSlideGeneratedMessage(messageKey, meetingId, code, presId, numberOfPages, pagesCompleted, presName);
                }
            }
        }
    }
    return null;
}
Also used : JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Aggregations

JsonParser (com.google.gson.JsonParser)323 JsonObject (com.google.gson.JsonObject)263 JsonElement (com.google.gson.JsonElement)88 JsonArray (com.google.gson.JsonArray)49 IOException (java.io.IOException)39 Gson (com.google.gson.Gson)31 InputStreamReader (java.io.InputStreamReader)24 HashMap (java.util.HashMap)20 Map (java.util.Map)18 ArrayList (java.util.ArrayList)16 JsonReader (com.google.gson.stream.JsonReader)11 Test (org.junit.Test)11 AssetManager (android.content.res.AssetManager)10 InputStream (java.io.InputStream)10 Type (java.lang.reflect.Type)10 URL (java.net.URL)9 Test (org.testng.annotations.Test)9 UserType (com.glitchcog.fontificator.bot.UserType)8 EmojiType (com.glitchcog.fontificator.emoji.EmojiType)8 JsonParseException (com.google.gson.JsonParseException)8