Search in sources :

Example 1 with ImageUpdater

use of com.google.samples.apps.iosched.server.schedule.server.image.ImageUpdater in project iosched by google.

the class CmsUpdateEndpoint method getDataFromCms.

/**
 * Retrieve session data from CMS and make it ready for processing.
 *
 * @param user User making the request (injected by Endpoints)
 * @throws UnauthorizedException
 * @throws IOException
 */
@ApiMethod(name = "getDataFromCms", path = "topics")
public void getDataFromCms(User user) throws UnauthorizedException, IOException {
    if (user == null || !isAllowed(user)) {
        throw new UnauthorizedException("Invalid credentials");
    }
    // everything ok, let's update
    StringBuilder summary = new StringBuilder();
    JsonObject contents = new JsonObject();
    JsonDataSources sources = new VendorDynamicInput().fetchAllDataSources();
    for (String entity : sources) {
        JsonArray array = new JsonArray();
        JsonDataSource source = sources.getSource(entity);
        for (JsonObject obj : source) {
            array.add(obj);
        }
        summary.append(entity).append(": ").append(source.size()).append("\n");
        contents.add(entity, array);
    }
    // Fetch new images and set up serving URLs.
    new ImageUpdater().run(sources);
    // Write file to cloud storage
    CloudFileManager fileManager = new CloudFileManager();
    fileManager.createOrUpdate("__raw_session_data.json", contents, true);
}
Also used : JsonArray(com.google.gson.JsonArray) JsonDataSource(com.google.samples.apps.iosched.server.schedule.model.JsonDataSource) CloudFileManager(com.google.samples.apps.iosched.server.schedule.server.cloudstorage.CloudFileManager) ImageUpdater(com.google.samples.apps.iosched.server.schedule.server.image.ImageUpdater) JsonDataSources(com.google.samples.apps.iosched.server.schedule.model.JsonDataSources) UnauthorizedException(com.google.api.server.spi.response.UnauthorizedException) JsonObject(com.google.gson.JsonObject) VendorDynamicInput(com.google.samples.apps.iosched.server.schedule.server.input.VendorDynamicInput) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Aggregations

ApiMethod (com.google.api.server.spi.config.ApiMethod)1 UnauthorizedException (com.google.api.server.spi.response.UnauthorizedException)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 JsonDataSource (com.google.samples.apps.iosched.server.schedule.model.JsonDataSource)1 JsonDataSources (com.google.samples.apps.iosched.server.schedule.model.JsonDataSources)1 CloudFileManager (com.google.samples.apps.iosched.server.schedule.server.cloudstorage.CloudFileManager)1 ImageUpdater (com.google.samples.apps.iosched.server.schedule.server.image.ImageUpdater)1 VendorDynamicInput (com.google.samples.apps.iosched.server.schedule.server.input.VendorDynamicInput)1