Search in sources :

Example 1 with Message

use of com.google.appengine.api.mail.MailService.Message in project iosched by google.

the class APIUpdater method reportDataCheckFailures.

private void reportDataCheckFailures(CheckResult result, OutputStream optionalOutput) throws IOException {
    StringBuilder errorMessage = new StringBuilder();
    errorMessage.append("\nHey,\n\n" + "(this message is autogenerated)\n" + "\n** UPDATE: ignore the part of the message below that says the updater is halted. Halting the updating process is not implemented yet. **\n\n" + "The IOSched 2014 data updater is halted because of inconsistent data.\n" + "Please, check the messages below and fix the sources. " + /*+ "If you are ok with the data "
        + "even in an inconsistent state, you or other app admin will need to force an update by "
        + "clicking on the \"Force update\" button at https://iosched-updater-dev.appspot.com/admin/\n\n"*/
    "\n\n" + result.failures.size() + " data non-compliances:\n");
    for (CheckFailure f : result.failures) {
        errorMessage.append(f).append("\n\n");
    }
    // Log error message to syslog, so that it's available even if the log is truncated.
    Logger syslog = Logger.getLogger(APIUpdater.class.getName());
    syslog.log(Level.SEVERE, errorMessage.toString());
    // Send email with error message to project admins.
    if (SystemProperty.environment.value() != SystemProperty.Environment.Value.Development || optionalOutput == null) {
        // send email if user is not running in dev or interactive mode (show=true)
        Message message = new Message();
        message.setSender(Config.EMAIL_FROM);
        message.setSubject("[iosched-data-error] Updater - Inconsistent data");
        String errorMessageStr = errorMessage.toString();
        if (errorMessageStr.length() > ADMIN_MESSAGE_SIZE_LIMIT) {
            int truncatedChars = errorMessage.length() - ADMIN_MESSAGE_SIZE_LIMIT;
            errorMessageStr = errorMessageStr.substring(0, ADMIN_MESSAGE_SIZE_LIMIT);
            errorMessageStr += "\n\n--- MESSAGE TRUNCATED, " + truncatedChars + " CHARS REMAINING (CHECK LOG) ---";
        }
        message.setTextBody(errorMessageStr);
    // TODO(arthurthompson): Reimplement mailing, it currently fails due to invalid sender.
    //MailServiceFactory.getMailService().sendToAdmins(message);
    } else {
        // dump errors to optionalOutput
        optionalOutput.write(errorMessage.toString().getBytes());
    }
}
Also used : Message(com.google.appengine.api.mail.MailService.Message) CheckFailure(com.google.samples.apps.iosched.server.schedule.model.DataCheck.CheckFailure) Logger(java.util.logging.Logger)

Example 2 with Message

use of com.google.appengine.api.mail.MailService.Message 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)

Aggregations

Message (com.google.appengine.api.mail.MailService.Message)2 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 JsonWriter (com.google.gson.stream.JsonWriter)1 CheckFailure (com.google.samples.apps.iosched.server.schedule.model.DataCheck.CheckFailure)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 VendorDynamicInput (com.google.samples.apps.iosched.server.schedule.server.input.VendorDynamicInput)1 Writer (java.io.Writer)1 Logger (java.util.logging.Logger)1