use of com.google.samples.apps.iosched.io.BlocksHandler 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.");
}
Aggregations