Search in sources :

Example 1 with VendorDynamicInput

use of com.google.samples.apps.iosched.server.schedule.server.input.VendorDynamicInput in project iosched by google.

the class APIExtractor method run.

public void run(OutputStream optionalOutput, boolean extractUnpublished) throws IOException {
    // fill sources with extra input:
    JsonDataSources sources = new ExtraInput().fetchAllDataSources();
    // fill sources with vendor API input:
    VendorDynamicInput vendorInput = new VendorDynamicInput();
    vendorInput.setExtractUnpublished(extractUnpublished);
    sources.putAll(vendorInput.fetchAllDataSources());
    // extract session data from inputs:
    JsonObject newData = new DataExtractor(false).extractFromDataSources(sources);
    // send data to the outputstream
    Writer writer = Channels.newWriter(Channels.newChannel(optionalOutput), "UTF-8");
    JsonWriter optionalOutputWriter = new JsonWriter(writer);
    optionalOutputWriter.setIndent("  ");
    new Gson().toJson(newData, optionalOutputWriter);
    optionalOutputWriter.flush();
}
Also used : JsonDataSources(com.google.samples.apps.iosched.server.schedule.model.JsonDataSources) ExtraInput(com.google.samples.apps.iosched.server.schedule.server.input.ExtraInput) DataExtractor(com.google.samples.apps.iosched.server.schedule.model.DataExtractor) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) VendorDynamicInput(com.google.samples.apps.iosched.server.schedule.server.input.VendorDynamicInput) JsonWriter(com.google.gson.stream.JsonWriter) Writer(java.io.Writer) JsonWriter(com.google.gson.stream.JsonWriter)

Example 2 with VendorDynamicInput

use of com.google.samples.apps.iosched.server.schedule.server.input.VendorDynamicInput in project iosched by google.

the class VendorInputTest method testFetch.

@Test
public void testFetch() throws IOException {
    VendorDynamicInput api = new VendorDynamicInput(fakeFetcher);
    JsonArray categories = api.fetch(MainTypes.categories);
    JsonArray rooms = api.fetch(MainTypes.rooms);
    JsonArray speakers = api.fetch(MainTypes.speakers);
    JsonArray topics = api.fetch(MainTypes.topics);
    assertEquals(8, rooms.size());
    assertEquals(28, categories.size());
    assertEquals(44, speakers.size());
    assertEquals(55, topics.size());
}
Also used : JsonArray(com.google.gson.JsonArray) VendorDynamicInput(com.google.samples.apps.iosched.server.schedule.server.input.VendorDynamicInput) Test(org.junit.Test)

Example 3 with VendorDynamicInput

use of com.google.samples.apps.iosched.server.schedule.server.input.VendorDynamicInput in project iosched by google.

the class DataExtractorTest method setUp.

/**
   * @throws java.lang.Exception
   */
@Before
public void setUp() throws Exception {
    fakeFetcher = new EntityFetcher() {

        @Override
        public JsonElement fetch(Enum<?> entityType, Map<String, String> params) throws IOException {
            String filename = "sample_" + entityType.name();
            if (params != null && params.get("page") != null && Integer.parseInt(params.get("page")) > 1) {
                filename += "_page" + params.get("page");
            }
            filename += ".json";
            InputStream stream = TestHelper.openTestDataFileStream(filename);
            JsonReader reader = new JsonReader(new InputStreamReader(stream, Charset.forName("UTF-8")));
            return new JsonParser().parse(reader);
        }
    };
    RemoteFilesEntityFetcherFactory.setBuilder(new FetcherBuilder() {

        @Override
        public FetcherBuilder setSourceFiles(String... filenames) {
            return this;
        }

        @Override
        public EntityFetcher build() {
            return fakeFetcher;
        }
    });
    sources = new ExtraInput().fetchAllDataSources();
    sources.putAll(new VendorDynamicInput(fakeFetcher).fetchAllDataSources());
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) IOException(java.io.IOException) FetcherBuilder(com.google.samples.apps.iosched.server.schedule.input.fetcher.RemoteFilesEntityFetcherFactory.FetcherBuilder) EntityFetcher(com.google.samples.apps.iosched.server.schedule.input.fetcher.EntityFetcher) JsonElement(com.google.gson.JsonElement) ExtraInput(com.google.samples.apps.iosched.server.schedule.server.input.ExtraInput) JsonReader(com.google.gson.stream.JsonReader) VendorDynamicInput(com.google.samples.apps.iosched.server.schedule.server.input.VendorDynamicInput) JsonParser(com.google.gson.JsonParser) Before(org.junit.Before)

Example 4 with VendorDynamicInput

use of com.google.samples.apps.iosched.server.schedule.server.input.VendorDynamicInput in project iosched by google.

the class CMSUpdateServlet method process.

private void process(HttpServletResponse resp, boolean showOnly) throws IOException {
    // 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);
    }
    if (showOnly) {
        // Show generated contents to the output
        resp.setContentType("application/json");
        Writer writer = Channels.newWriter(Channels.newChannel(resp.getOutputStream()), "UTF-8");
        JsonWriter outputWriter = new JsonWriter(writer);
        outputWriter.setIndent("  ");
        new Gson().toJson(contents, outputWriter);
        outputWriter.flush();
    } else {
        // Write file to cloud storage
        CloudFileManager fileManager = new CloudFileManager();
        fileManager.createOrUpdate("__raw_session_data.json", contents, true);
        // send email
        Message message = new Message();
        message.setSender(Config.EMAIL_FROM);
        message.setSubject("[iosched-data-update] Manual sync from CMS");
        message.setTextBody("Hey,\n\n" + "(this message is autogenerated)\n" + "This is a heads up that " + userService.getCurrentUser().getEmail() + " has just updated the IOSched 2015 data from the Vendor CMS.\n\n" + "Here is a brief status of what has been extracted from the Vendor API:\n" + summary + "\n\n" + "If you want to check the most current data that will soon be sync'ed to the IOSched Android app, " + "check this link: http://storage.googleapis.com/iosched-updater-dev.appspot.com/__raw_session_data.json\n" + "This data will remain unchanged until someone with proper privileges updates it again on https://iosched-updater-dev.appspot.com/cmsupdate\n\n" + "Thanks!\n\n" + "A robot on behalf of the IOSched team!\n\n" + "PS: you are receiving this either because you are an admin of the IOSched project or " + "because you are in a hard-coded list of I/O organizers. If you don't want to " + "receive it anymore, pay me a beer and ask kindly.");
        // TODO(arthurthompson): Reimplement mailing, it currently fails due to invalid sender.
        //MailServiceFactory.getMailService().sendToAdmins(message);
        resp.sendRedirect("/admin/schedule/updateok.html");
    }
}
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) Message(com.google.appengine.api.mail.MailService.Message) JsonDataSources(com.google.samples.apps.iosched.server.schedule.model.JsonDataSources) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) VendorDynamicInput(com.google.samples.apps.iosched.server.schedule.server.input.VendorDynamicInput) JsonWriter(com.google.gson.stream.JsonWriter) Writer(java.io.Writer) JsonWriter(com.google.gson.stream.JsonWriter)

Example 5 with VendorDynamicInput

use of com.google.samples.apps.iosched.server.schedule.server.input.VendorDynamicInput in project iosched by google.

the class VendorInputTest method testRemoteFetch.

/**
   *
   * This is the real remote fetch. Doesn't fit well as a unit test, though, but it's here to
   * help quickly identifying issues in the remote API. This test is only run if the vender
   * base url is set.
   *
   * @throws IOException
   */
@Test
public void testRemoteFetch() throws IOException {
    if (!VendorAPIEntityFetcher.BASE_URL.equals("UNDEFINED")) {
        VendorDynamicInput api = new VendorDynamicInput();
        JsonArray categories = api.fetch(MainTypes.categories);
        JsonArray rooms = api.fetch(MainTypes.rooms);
        JsonArray speakers = api.fetch(MainTypes.speakers);
        JsonArray topics = api.fetch(MainTypes.topics);
        assertNotNull(categories);
        assertNotNull(rooms);
        assertNotNull(speakers);
        assertNotNull(topics);
    }
}
Also used : JsonArray(com.google.gson.JsonArray) VendorDynamicInput(com.google.samples.apps.iosched.server.schedule.server.input.VendorDynamicInput) Test(org.junit.Test)

Aggregations

VendorDynamicInput (com.google.samples.apps.iosched.server.schedule.server.input.VendorDynamicInput)5 JsonArray (com.google.gson.JsonArray)3 Gson (com.google.gson.Gson)2 JsonObject (com.google.gson.JsonObject)2 JsonWriter (com.google.gson.stream.JsonWriter)2 JsonDataSources (com.google.samples.apps.iosched.server.schedule.model.JsonDataSources)2 ExtraInput (com.google.samples.apps.iosched.server.schedule.server.input.ExtraInput)2 Writer (java.io.Writer)2 Test (org.junit.Test)2 Message (com.google.appengine.api.mail.MailService.Message)1 JsonElement (com.google.gson.JsonElement)1 JsonParser (com.google.gson.JsonParser)1 JsonReader (com.google.gson.stream.JsonReader)1 EntityFetcher (com.google.samples.apps.iosched.server.schedule.input.fetcher.EntityFetcher)1 FetcherBuilder (com.google.samples.apps.iosched.server.schedule.input.fetcher.RemoteFilesEntityFetcherFactory.FetcherBuilder)1 DataExtractor (com.google.samples.apps.iosched.server.schedule.model.DataExtractor)1 JsonDataSource (com.google.samples.apps.iosched.server.schedule.model.JsonDataSource)1 CloudFileManager (com.google.samples.apps.iosched.server.schedule.server.cloudstorage.CloudFileManager)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1