Search in sources :

Example 56 with Contributor

use of ai.elimu.model.Contributor in project webapp by elimu-ai.

the class ContributorRegistrationSummaryScheduler method execute.

// @Scheduled(cron="00 00 08 * * *") // At 08:00 every day
public synchronized void execute() {
    logger.info("execute");
    Calendar calendarFrom = Calendar.getInstance();
    calendarFrom.add(Calendar.DAY_OF_MONTH, -1);
    Calendar calendarTo = Calendar.getInstance();
    List<Contributor> contributorsRegisteredRecently = contributorDao.readAll(calendarFrom, calendarTo);
    logger.info("contributorsRegisteredRecently.size(): " + contributorsRegisteredRecently.size());
    if (!contributorsRegisteredRecently.isEmpty()) {
        // Send summary to existing Contributors
        for (Contributor contributor : contributorDao.readAll()) {
            String baseUrl = "http://localhost:8080/webapp";
            if (EnvironmentContextLoaderListener.env == Environment.TEST) {
                baseUrl = "http://test.elimu.ai";
            } else if (EnvironmentContextLoaderListener.env == Environment.PROD) {
                baseUrl = "http://elimu.ai";
            }
            String to = contributor.getEmail();
            String from = "elimu.ai <info@elimu.ai>";
            Locale locale = new Locale("en");
            String subject = contributorsRegisteredRecently.get(0).getFirstName() + " " + contributorsRegisteredRecently.get(0).getLastName() + " joined the community";
            String title = subject;
            String firstName = StringUtils.isBlank(contributor.getFirstName()) ? "" : contributor.getFirstName();
            String htmlText = "<p>Hi, " + firstName + "</p>";
            if (contributorsRegisteredRecently.size() == 1) {
                htmlText += "<p>A new contributor joined the elimu.ai community:</p>";
            } else {
                htmlText += "<p>New contributors joined the elimu.ai community:</p>";
            }
            int counter = 0;
            for (Contributor contributorRegisteredRecently : contributorsRegisteredRecently) {
                if (contributorRegisteredRecently.getId().equals(contributor.getId())) {
                    // Skip if the Contributor is the same as the one registered recently
                    continue;
                } else if (StringUtils.isEmpty(contributorRegisteredRecently.getMotivation())) {
                    // Skip if the contributor did not complete the on-boarding wizard
                    continue;
                }
                htmlText += "<hr style=\"border-color: #CCC; border-top: 0;\" />";
                htmlText += "<p>" + contributorRegisteredRecently.getFirstName() + " " + contributorRegisteredRecently.getLastName() + "</p>";
                if (StringUtils.isNotBlank(contributorRegisteredRecently.getImageUrl())) {
                    htmlText += "<img src=\"" + contributorRegisteredRecently.getImageUrl() + "\" alt=\"\" style=\"max-height: 5em; border-radius: 50%;\">";
                }
                htmlText += "<p>Language: " + messageSource.getMessage("language." + contributorRegisteredRecently.getLocale().getLanguage(), null, locale) + "</p>";
                htmlText += "<p>Teams: " + contributorRegisteredRecently.getTeams() + "</p>";
                htmlText += "<p>Personal motivation:</p>";
                htmlText += "<p><blockquote>\"" + contributorRegisteredRecently.getMotivation() + "\"</blockquote></p>";
                if (++counter == 5) {
                    break;
                }
            }
            htmlText += "<hr style=\"border-color: #CCC; border-top: 0;\" />";
            htmlText += "<p>Do you want to learn more about the new (and existing) contributors?</p>";
            String buttonText = "See complete list of contributors";
            String buttonUrl = baseUrl + "/content/community/contributors";
            if (counter > 0) {
                Mailer.sendHtmlWithButton(to, null, from, subject, title, htmlText, buttonText, buttonUrl);
            }
        }
    }
    logger.info("execute complete");
}
Also used : Locale(java.util.Locale) Calendar(java.util.Calendar) Contributor(ai.elimu.model.Contributor)

Example 57 with Contributor

use of ai.elimu.model.Contributor in project webapp by elimu-ai.

the class MailChimpScheduler method executeImport.

// 10 past every hour
@Scheduled(cron = "00 10 * * * *")
public synchronized void executeImport() {
    logger.info("executeImport");
    if (EnvironmentContextLoaderListener.env != Environment.PROD) {
        return;
    }
    List<Contributor> contributors = contributorDao.readAll();
    logger.info("contributors.size(): " + contributors.size());
    for (Contributor contributor : contributors) {
        try {
            // Check if contributor is already subscribed to the mailing list
            String memberInfo = MailChimpApiHelper.getMemberInfo(contributor.getEmail());
            if (StringUtils.isBlank(memberInfo)) {
                MailChimpApiHelper.subscribeMember(contributor);
            }
        } catch (IOException ex) {
            logger.error(null, ex);
            break;
        }
    }
    logger.info("executeImport complete");
}
Also used : Contributor(ai.elimu.model.Contributor) IOException(java.io.IOException) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Aggregations

Contributor (ai.elimu.model.Contributor)57 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)51 Project (ai.elimu.model.project.Project)12 IOException (java.io.IOException)10 Allophone (ai.elimu.model.content.Allophone)9 Word (ai.elimu.model.content.Word)8 Image (ai.elimu.model.content.multimedia.Image)8 Audio (ai.elimu.model.content.multimedia.Audio)6 Letter (ai.elimu.model.content.Letter)5 Number (ai.elimu.model.content.Number)5 AppCategory (ai.elimu.model.project.AppCategory)5 StoryBook (ai.elimu.model.content.StoryBook)4 Video (ai.elimu.model.content.multimedia.Video)4 Scheduled (org.springframework.scheduling.annotation.Scheduled)4 AppCollection (ai.elimu.model.project.AppCollection)3 AppGroup (ai.elimu.model.project.AppGroup)3 Locale (java.util.Locale)3 Application (ai.elimu.model.admin.Application)2 ApplicationVersion (ai.elimu.model.admin.ApplicationVersion)2 Syllable (ai.elimu.model.content.Syllable)2