Search in sources :

Example 1 with UserToken

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();
}
Also used : User(org.activityinfo.server.database.hibernate.entity.User) Message(org.activityinfo.server.mail.Message) Date(java.util.Date) UserToken(org.activityinfo.server.authentication.UserToken) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Date (java.util.Date)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 UserToken (org.activityinfo.server.authentication.UserToken)1 User (org.activityinfo.server.database.hibernate.entity.User)1 Message (org.activityinfo.server.mail.Message)1