Search in sources :

Example 51 with JsonPrimitive

use of com.google.gson.JsonPrimitive in project iosched by google.

the class DataExtractor method setVideoForVideoSession.

private JsonPrimitive setVideoForVideoSession(JsonObject origin, JsonObject dest) {
    JsonPrimitive vid = getVideoFromTopicInfo(origin, InputJsonKeys.VendorAPISource.Topics.INFO_VIDEO_URL, null);
    if (vid != null) {
        set(vid, dest, OutputJsonKeys.VideoLibrary.vid);
        JsonPrimitive thumbnail = new JsonPrimitive("http://img.youtube.com/vi/" + vid.getAsString() + "/hqdefault.jpg");
        set(thumbnail, dest, OutputJsonKeys.VideoLibrary.thumbnailUrl);
    }
    return vid;
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive)

Example 52 with JsonPrimitive

use of com.google.gson.JsonPrimitive in project iosched by google.

the class DataExtractor method isLivestreamed.

private boolean isLivestreamed(JsonObject sessionObj) {
    // data generated after the end of the conference should never have livestream URLs
    long endOfConference = Config.CONFERENCE_DAYS[Config.CONFERENCE_DAYS.length - 1][1];
    if (System.currentTimeMillis() > endOfConference) {
        return false;
    }
    JsonPrimitive livestream = getMapValue(get(sessionObj, InputJsonKeys.VendorAPISource.Topics.Info), InputJsonKeys.VendorAPISource.Topics.INFO_IS_LIVE_STREAM, null, null);
    return livestream != null && "true".equalsIgnoreCase(livestream.getAsString());
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive)

Example 53 with JsonPrimitive

use of com.google.gson.JsonPrimitive in project iosched by google.

the class DataExtractor method extractRooms.

public JsonArray extractRooms(JsonDataSources sources) {
    HashSet<String> ids = new HashSet<String>();
    JsonArray result = new JsonArray();
    JsonDataSource source = sources.getSource(InputJsonKeys.VendorAPISource.MainTypes.rooms.name());
    if (source != null) {
        for (JsonObject origin : source) {
            JsonObject dest = new JsonObject();
            JsonElement originalId = get(origin, InputJsonKeys.VendorAPISource.Rooms.Id);
            String id = Config.ROOM_MAPPING.getRoomId(originalId.getAsString());
            if (!ids.contains(id)) {
                String title = Config.ROOM_MAPPING.getTitle(id, get(origin, InputJsonKeys.VendorAPISource.Rooms.Name).getAsString());
                set(new JsonPrimitive(id), dest, OutputJsonKeys.Rooms.id);
                set(originalId, dest, OutputJsonKeys.Rooms.original_id);
                set(new JsonPrimitive(title), dest, OutputJsonKeys.Rooms.name);
                result.add(dest);
                ids.add(id);
            }
        }
    }
    if (Config.DEBUG_FIX_DATA) {
        DebugDataExtractorHelper.changeRooms(result);
    }
    return result;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) HashSet(java.util.HashSet)

Example 54 with JsonPrimitive

use of com.google.gson.JsonPrimitive in project iosched by google.

the class DebugDataExtractorHelper method changeRooms.

public static final void changeRooms(JsonArray allRooms) {
    for (String room : rooms) {
        JsonObject dest = new JsonObject();
        JsonPrimitive roomId = new JsonPrimitive(room);
        JsonPrimitive roomName = new JsonPrimitive("Room " + room);
        DataModelHelper.set(roomId, dest, OutputJsonKeys.Rooms.id);
        DataModelHelper.set(roomName, dest, OutputJsonKeys.Rooms.name);
        allRooms.add(dest);
    }
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive) JsonObject(com.google.gson.JsonObject)

Example 55 with JsonPrimitive

use of com.google.gson.JsonPrimitive in project iosched by google.

the class DebugDataExtractorHelper method changeSession.

public static final void changeSession(JsonObject session, Set<String> usedTags) {
    int hash = session.get(OutputJsonKeys.Sessions.id.name()).getAsString().hashCode();
    r.setSeed(hash);
    // timeslot:
    int day = days[uniform(2)];
    int[] timeSlot = sessionTimes[uniform(sessionTimes.length)];
    Calendar start = new GregorianCalendar(2014, Calendar.JUNE, day, timeSlot[0], timeSlot[1], 0);
    Calendar end = new GregorianCalendar(2014, Calendar.JUNE, day, timeSlot[2], timeSlot[3], 0);
    long offset = TimeZone.getTimeZone("PST").getOffset(start.getTimeInMillis());
    start.setTimeInMillis(start.getTimeInMillis() - offset);
    end.setTimeInMillis(end.getTimeInMillis() - offset);
    String startS = formatter.format(start.getTime());
    String endS = formatter.format(end.getTime());
    DataModelHelper.set(new JsonPrimitive(startS), session, OutputJsonKeys.Sessions.startTimestamp);
    DataModelHelper.set(new JsonPrimitive(endS), session, OutputJsonKeys.Sessions.endTimestamp);
    // Room:
    DataModelHelper.set(new JsonPrimitive(rooms[uniform(rooms.length)]), session, OutputJsonKeys.Sessions.room);
    JsonArray tags = new JsonArray();
    // 2 random topic tags
    // not the most efficient, but good enough and avoid duplicates
    Collections.shuffle(topicTags, r);
    if (topicTags.size() > 0)
        tags.add(topicTags.get(0).get(OutputJsonKeys.Tags.tag.name()));
    if (topicTags.size() > 1)
        tags.add(topicTags.get(1).get(OutputJsonKeys.Tags.tag.name()));
    // 1 randomly distributed theme tag
    tags.add(themeTags[roullette(themeDistribution)].get(OutputJsonKeys.Tags.tag.name()));
    // 1 randomly distributed type tag
    tags.add(typeTags[roullette(typeDistribution)].get(OutputJsonKeys.Tags.tag.name()));
    for (JsonElement tag : tags) {
        usedTags.add(tag.getAsString());
    }
    DataModelHelper.set(tags, session, OutputJsonKeys.Sessions.tags);
    // Livestream
    boolean isLiveStream = uniform(2) == 1;
    if (isLiveStream) {
        DataModelHelper.set(new JsonPrimitive("https://www.youtube.com/watch?v=dQw4w9WgXcQ"), session, OutputJsonKeys.Sessions.youtubeUrl);
        DataModelHelper.set(new JsonPrimitive("http://www.google.com/humans.txt"), session, OutputJsonKeys.Sessions.captionsUrl);
        DataModelHelper.set(new JsonPrimitive(Boolean.TRUE), session, OutputJsonKeys.Sessions.isLivestream);
    } else {
        session.remove(OutputJsonKeys.Sessions.youtubeUrl.name());
        session.remove(OutputJsonKeys.Sessions.captionsUrl.name());
        DataModelHelper.set(new JsonPrimitive(Boolean.FALSE), session, OutputJsonKeys.Sessions.isLivestream);
    }
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) JsonElement(com.google.gson.JsonElement) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar)

Aggregations

JsonPrimitive (com.google.gson.JsonPrimitive)168 JsonArray (com.google.gson.JsonArray)103 JsonObject (com.google.gson.JsonObject)78 Test (org.testng.annotations.Test)56 JsonElement (com.google.gson.JsonElement)47 Test (org.junit.Test)12 Map (java.util.Map)9 Matchers.anyString (org.mockito.Matchers.anyString)8 JsonProcessorInjectionMap (com.builtbroken.mc.lib.json.loading.JsonProcessorInjectionMap)7 Gson (com.google.gson.Gson)5 JsonParser (com.google.gson.JsonParser)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 GsonBuilder (com.google.gson.GsonBuilder)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Matcher (java.util.regex.Matcher)3 LobWrapper (angularBeans.io.LobWrapper)2 DatasetCreationSpec (co.cask.cdap.internal.dataset.DatasetCreationSpec)2 IRenderState (com.builtbroken.mc.client.json.imp.IRenderState)2