public ShowDetailed get(String alias) { DBObject one = db.getCollection("show").findOne(aliasOrId(alias)); if (one == null) { throw new NotFoundException("No such show"); } ShowDetailed detailed = mapper.map(one, ShowDetailed.class); Date now = new Date(); for (SchedulingSimple ss : detailed.getSchedulings()) { if (ss.getValidFrom().compareTo(now) < 0 && ss.getValidTo().compareTo(now) > 0) ss.setText(schedulingTextUtil.create(ss)); } if (detailed.getContributors() != null) { for (ShowContribution contributor : detailed.getContributors()) { if (contributor.getAuthor() != null) { avatarLocator.locateAvatar(contributor.getAuthor()); } } } long mixCount = db.getCollection("mix") .count(new BasicDBObject("show.ref", new DBRef(db, "show", one.get("_id").toString()))); detailed.getStats().mixCount = (int) mixCount; detailed.setUrls(processUrls(detailed.getUrls())); return detailed; }
public OkResponse contact(String alias, MailToShow mailToSend) { ValidationResult validate = captchaValidator.validate(mailToSend.getCaptcha()); if (!validate.isSuccess()) { throw new IllegalArgumentException("Rosszul megadott Captcha: " + validate.toString()); } MimeMessage mail = mailSender.createMimeMessage(); try { MimeMessageHelper helper = new MimeMessageHelper(mail, false); String body = "----- Ez a levél a tilos.hu műsoroldaláról lett küldve-----\n" + "\n" + "A form kitöltője a " + mailToSend.getFrom() + " email-t adta meg válasz címnek, de ennek valódiságát nem ellenőriztük." + "\n" + "-------------------------------------" + "\n" + mailToSend.getBody(); helper.setFrom("*****@*****.**"); helper.setReplyTo(mailToSend.getFrom()); helper.setSubject("[tilos.hu] " + mailToSend.getSubject()); helper.setText(body); DBObject one = db.getCollection("show").findOne(aliasOrId(alias)); if (one == null) { throw new IllegalArgumentException("No such show: " + alias); } ShowDetailed detailed = mapper.map(one, ShowDetailed.class); detailed .getContributors() .forEach( contributor -> { DBObject dbAuthor = db.getCollection("author").findOne(aliasOrId(contributor.getAuthor().getId())); if (dbAuthor.get("email") != null) { try { helper.setTo((String) dbAuthor.get("email")); } catch (MessagingException e) { throw new RuntimeException(e); } mailSender.send(mail); } }); } catch (Exception e) { throw new InternalErrorException("Can't send the email message: " + e.getMessage(), e); } return new OkResponse("Üzenet elküldve."); }