<commit_before>package com.cineplexnotifier.services;

import java.io.IOException;
import java.io.Serializable;
import java.util.concurrent.Future;

import javax.ejb.AsyncResult;
import javax.ejb.Asynchronous;
import javax.ejb.EJB;
import javax.ejb.Stateless;

import org.jboss.logging.Logger;

import com.cineplexnotifier.model.Movie;
import com.cineplexnotifier.model.User;
import com.sendgrid.Content;
import com.sendgrid.Email;
import com.sendgrid.Mail;
import com.sendgrid.Method;
import com.sendgrid.Personalization;
import com.sendgrid.Request;
import com.sendgrid.Response;
import com.sendgrid.SendGrid;

@Stateless
@SuppressWarnings("serial")
public class NotificationService implements Serializable {

	@EJB
	private SendGridFactory sendGridFactory;

	private static final String SUBJECT_MOVIE_NOW_AVAILABLE = "Tickets for %s are now available from cineplex.com!";
	private static final String BODY_MOVIE_NOW_AVAILABLE = SUBJECT_MOVIE_NOW_AVAILABLE;

	@Asynchronous
	public Future<Void> notifySubscribers(Movie m)  {
		if (m.isAvailable()) {
			for (User u : m.getUsers()) {
				Email from = new Email("<EMAIL>");
				Email to = new Email(u.getEmail());

				String subject = String.format(SUBJECT_MOVIE_NOW_AVAILABLE, m.getName());
				Content content = new Content("text/html", String.format(BODY_MOVIE_NOW_AVAILABLE, m.getName()));

				Mail mail = new Mail(from, subject, to, content);
				mail.setTemplateId("db73998c-d70d-4301-9e10-f2e68b31ecdf");

				Personalization p = mail.getPersonalization().get(0);
				p.addSubstitution("-movieName-", m.getName());
				p.addSubstitution("-cineplexKey-", m.getCineplexKey());

				mail.sendAt();

				SendGrid sg = sendGridFactory.get();
				Request request = new Request();
				try {
					request.method = Method.POST;
					request.endpoint = "mail/send";
					request.body = mail.build();
					Response response = sg.api(request);
					if (response.statusCode < 200 || response.statusCode >= 300) {
						throw new IOException(response.toString());
					}
				} catch (IOException e) {
					Logger.getLogger(this.getClass().getName()).error(e);
				}
			}
		}
		return new AsyncResult<Void>(null);
	}

}
<commit_msg>purge email list after sending emails to end users.<commit_after>package com.cineplexnotifier.services;

import java.io.IOException;
import java.io.Serializable;
import java.util.concurrent.Future;

import javax.ejb.AsyncResult;
import javax.ejb.Asynchronous;
import javax.ejb.EJB;
import javax.ejb.Stateless;

import org.jboss.logging.Logger;

import com.cineplexnotifier.model.Movie;
import com.cineplexnotifier.model.User;
import com.sendgrid.Content;
import com.sendgrid.Email;
import com.sendgrid.Mail;
import com.sendgrid.Method;
import com.sendgrid.Personalization;
import com.sendgrid.Request;
import com.sendgrid.Response;
import com.sendgrid.SendGrid;

@Stateless
@SuppressWarnings("serial")
public class NotificationService implements Serializable {

	@EJB
	private SendGridFactory sendGridFactory;

	private static final String SUBJECT_MOVIE_NOW_AVAILABLE = "Tickets for %s are now available from cineplex.com!";
	private static final String BODY_MOVIE_NOW_AVAILABLE = SUBJECT_MOVIE_NOW_AVAILABLE;

	@Asynchronous
	public Future<Void> notifySubscribers(Movie m)  {
		if (m.isAvailable()) {
			for (User u : m.getUsers()) {
				Email from = new Email("no-reply@cine<EMAIL>");
				Email to = new Email(u.getEmail());

				String subject = String.format(SUBJECT_MOVIE_NOW_AVAILABLE, m.getName());
				Content content = new Content("text/html", String.format(BODY_MOVIE_NOW_AVAILABLE, m.getName()));

				Mail mail = new Mail(from, subject, to, content);
				mail.setTemplateId("db73998c-d70d-4301-9e10-f2e68b31ecdf");

				Personalization p = mail.getPersonalization().get(0);
				p.addSubstitution("-movieName-", m.getName());
				p.addSubstitution("-cineplexKey-", m.getCineplexKey());

				mail.sendAt();

				SendGrid sg = sendGridFactory.get();
				Request request = new Request();
				try {
					request.method = Method.POST;
					request.endpoint = "mail/send";
					request.body = mail.build();
					Response response = sg.api(request);
					if (response.statusCode < 200 || response.statusCode >= 300) {
						throw new IOException(response.toString());
					}
				} catch (IOException e) {
					Logger.getLogger(this.getClass().getName()).error(e);
				}
			}

			m.getUsers().clear();
		}
		return new AsyncResult<Void>(null);
	}

}

{'fraction_non_alphanumeric': 0.12327839241363739, 'fraction_numerical': 0.011740799277489276, 'mean_word_length': 4.496277915632755, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5530020', 'n_tokens_mistral': 1683, 'n_tokens_neox': 1418, 'n_words': 299}