Search in sources :

Example 1 with HashtagsHandler

use of com.google.samples.apps.iosched.io.HashtagsHandler in project iosched by google.

the class ConferenceDataHandler method applyConferenceData.

/**
 * Parses the conference data in the given objects and imports the data into the
 * content provider. The format of the data is documented at https://code.google.com/p/iosched.
 *
 * @param dataBodies       The collection of JSON objects to parse and import.
 * @param dataTimestamp    The timestamp of the data. This should be in RFC1123 format.
 * @param downloadsAllowed Whether or not we are supposed to download data from the internet if
 *                         needed.
 * @throws IOException If there is a problem parsing the data.
 */
public void applyConferenceData(String[] dataBodies, String dataTimestamp, boolean downloadsAllowed) throws IOException {
    LOGD(TAG, "Applying data from " + dataBodies.length + " files, timestamp " + dataTimestamp);
    // create handlers for each data type
    mHandlerForKey.put(DATA_KEY_ROOMS, mRoomsHandler = new RoomsHandler(mContext));
    mHandlerForKey.put(DATA_KEY_BLOCKS, mBlocksHandler = new BlocksHandler(mContext));
    mHandlerForKey.put(DATA_KEY_TAGS, mTagsHandler = new TagsHandler(mContext));
    mHandlerForKey.put(DATA_KEY_SPEAKERS, mSpeakersHandler = new SpeakersHandler(mContext));
    mHandlerForKey.put(DATA_KEY_SESSIONS, mSessionsHandler = new SessionsHandler(mContext));
    mHandlerForKey.put(DATA_KEY_SEARCH_SUGGESTIONS, mSearchSuggestHandler = new SearchSuggestHandler(mContext));
    mHandlerForKey.put(DATA_KEY_MAP, mMapPropertyHandler = new MapPropertyHandler(mContext));
    mHandlerForKey.put(DATA_KEY_HASHTAGS, mHashtagsHandler = new HashtagsHandler(mContext));
    mHandlerForKey.put(DATA_KEY_VIDEOS, mVideosHandler = new VideosHandler(mContext));
    mHandlerForKey.put(DATA_KEY_CARDS, mCardHandler = new CardHandler(mContext));
    // process the jsons. This will call each of the handlers when appropriate to deal
    // with the objects we see in the data.
    LOGD(TAG, "Processing " + dataBodies.length + " JSON objects.");
    for (int i = 0; i < dataBodies.length; i++) {
        LOGD(TAG, "Processing json object #" + (i + 1) + " of " + dataBodies.length);
        processDataBody(dataBodies[i]);
    }
    // the sessions handler needs to know the tag and speaker maps to process sessions
    mSessionsHandler.setTagMap(mTagsHandler.getTagMap());
    mSessionsHandler.setSpeakerMap(mSpeakersHandler.getSpeakerMap());
    // produce the necessary content provider operations
    ArrayList<ContentProviderOperation> batch = new ArrayList<>();
    for (String key : DATA_KEYS_IN_ORDER) {
        LOGI(TAG, "Building content provider operations for: " + key);
        mHandlerForKey.get(key).makeContentProviderOperations(batch);
        LOGI(TAG, "Content provider operations so far: " + batch.size());
    }
    LOGD(TAG, "Total content provider operations: " + batch.size());
    // download or process local map tile overlay files (SVG files)
    LOGD(TAG, "Processing map overlay files");
    processMapOverlayFiles(mMapPropertyHandler.getTileOverlays(), downloadsAllowed);
    // finally, push the changes into the Content Provider
    LOGI(TAG, "Applying " + batch.size() + " content provider operations.");
    try {
        int operations = batch.size();
        if (operations > 0) {
            mContext.getContentResolver().applyBatch(ScheduleContract.CONTENT_AUTHORITY, batch);
        }
        LOGD(TAG, "Successfully applied " + operations + " content provider operations.");
        mContentProviderOperationsDone += operations;
    } catch (RemoteException ex) {
        LOGE(TAG, "RemoteException while applying content provider operations.");
        throw new RuntimeException("Error executing content provider batch operation", ex);
    } catch (OperationApplicationException ex) {
        LOGE(TAG, "OperationApplicationException while applying content provider operations.");
        throw new RuntimeException("Error executing content provider batch operation", ex);
    }
    // notify all top-level paths
    LOGD(TAG, "Notifying changes on all top-level paths on Content Resolver.");
    ContentResolver resolver = mContext.getContentResolver();
    for (String path : ScheduleContract.TOP_LEVEL_PATHS) {
        Uri uri = ScheduleContract.BASE_CONTENT_URI.buildUpon().appendPath(path).build();
        resolver.notifyChange(uri, null);
    }
    // update our data timestamp
    setDataTimestamp(dataTimestamp);
    LOGD(TAG, "Done applying conference data.");
}
Also used : ContentProviderOperation(android.content.ContentProviderOperation) TagsHandler(com.google.samples.apps.iosched.io.TagsHandler) RoomsHandler(com.google.samples.apps.iosched.io.RoomsHandler) SessionsHandler(com.google.samples.apps.iosched.io.SessionsHandler) ArrayList(java.util.ArrayList) BlocksHandler(com.google.samples.apps.iosched.io.BlocksHandler) HashtagsHandler(com.google.samples.apps.iosched.io.HashtagsHandler) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver) VideosHandler(com.google.samples.apps.iosched.io.VideosHandler) MapPropertyHandler(com.google.samples.apps.iosched.io.MapPropertyHandler) SpeakersHandler(com.google.samples.apps.iosched.io.SpeakersHandler) SearchSuggestHandler(com.google.samples.apps.iosched.io.SearchSuggestHandler) CardHandler(com.google.samples.apps.iosched.io.CardHandler) RemoteException(android.os.RemoteException) OperationApplicationException(android.content.OperationApplicationException)

Aggregations

ContentProviderOperation (android.content.ContentProviderOperation)1 ContentResolver (android.content.ContentResolver)1 OperationApplicationException (android.content.OperationApplicationException)1 Uri (android.net.Uri)1 RemoteException (android.os.RemoteException)1 BlocksHandler (com.google.samples.apps.iosched.io.BlocksHandler)1 CardHandler (com.google.samples.apps.iosched.io.CardHandler)1 HashtagsHandler (com.google.samples.apps.iosched.io.HashtagsHandler)1 MapPropertyHandler (com.google.samples.apps.iosched.io.MapPropertyHandler)1 RoomsHandler (com.google.samples.apps.iosched.io.RoomsHandler)1 SearchSuggestHandler (com.google.samples.apps.iosched.io.SearchSuggestHandler)1 SessionsHandler (com.google.samples.apps.iosched.io.SessionsHandler)1 SpeakersHandler (com.google.samples.apps.iosched.io.SpeakersHandler)1 TagsHandler (com.google.samples.apps.iosched.io.TagsHandler)1 VideosHandler (com.google.samples.apps.iosched.io.VideosHandler)1 ArrayList (java.util.ArrayList)1