use of org.activityinfo.server.authentication.UserToken in project activityinfo by bedatadriven.
the class UserDigestResource method createUserDigest.
@GET
@Produces(MediaType.TEXT_HTML)
public String createUserDigest(@QueryParam(PARAM_USER) int userId, @QueryParam(PARAM_NOW) Long now, @QueryParam(PARAM_DAYS) int days, @QueryParam(PARAM_SENDEMAIL) @DefaultValue(PARAM_SENDEMAIL_DEF) boolean sendEmail) throws IOException, MessagingException {
if (userId <= 0) {
return "no user specified";
}
Date date = now == null ? new Date() : new Date(now);
if (days <= 0) {
days = getDefaultDays();
}
User user = entityManager.get().find(User.class, userId);
if (!user.isEmailNotification()) {
return "user's email notification flag is set to false.";
}
UserToken userToken = UserTokenManager.create(userId, UserTokenScope.SUBSCRIBE, UserTokenScope.UNSUBSCRIBE);
authProvider.set(user);
LOGGER.info("creating digest for " + user.getEmail() + " on " + DateFormatter.formatDateTime(date) + " for activity period: " + days + " day(s)." + " (sending email: " + sendEmail + ")");
UserDigest userDigest = new UserDigest(user, date, days, userToken.getSecureToken());
DigestMessageBuilder digest = new DigestMessageBuilder(digestModelBuilder, digestRenderer);
digest.setUserDigest(userDigest);
Message message = digest.build();
if (message != null && sendEmail) {
mailSender.get().send(message);
}
return message == null ? "no updates found" : message.getHtmlBody();
}