@Bean public IEmailService<Email> emailService() { return new EmailPersistenceService(); }
@Override public Object run() { final int totalPendingRecipients = emailPersistenceService.countPendingRecipients(); int pending = totalPendingRecipients; int page = 0, sent = 0; while (pending > 0) { for (Email.Addressee addressee : emailPersistenceService.listPendingRecipients(page * emailsPerPage, emailsPerPage)) { if(emailSender.send(addressee)){ emailPersistenceService.markAsSent(addressee); sent++; } } pending -= emailsPerPage; page++; } getLogger().info("{} sent from total of {}", sent, totalPendingRecipients); return sent + " sent from total of "+totalPendingRecipients; }
@Override public boolean send(Email email) { EmailEntity emailEntity = new EmailEntity(); if (!validateRecipients(email.getAllRecipients())) { throw new SingularMailException("O destinatário de e-mail é inválido."); } emailEntity.setSubject(email.getSubject()); emailEntity.setContent(email.getContent()); emailEntity.setReplyTo(email.getReplyToJoining()); String emailIdentifier = Optional.ofNullable(email.getModuleCod()) .orElse(SingularProperties.get().getPropertyOpt(EMAIL_COD_MODULE).orElse(null)); emailEntity.setModule(emailIdentifier); for (IAttachmentRef attachmentRef : email.getAttachments()) { IAttachmentRef attachment = persistenceHandler.copy(attachmentRef, null).getNewAttachmentRef(); emailEntity.getAttachments().add(persistenceHandler.getAttachmentEntity(attachment)); } emailEntity.setCreationDate(new Date()); emailDao.save(emailEntity); for (Email.Addressee addressee : email.getAllRecipients()) { EmailAddresseeEntity addresseeEntity = new EmailAddresseeEntity(); addresseeEntity.setAddress(addressee.getAddress()); addresseeEntity.setAddresseType(addressee.getType()); addresseeEntity.setEmail(emailEntity); emailAddresseeDao.save(addresseeEntity); } return true; }
@Override public boolean send(Email email) { EmailEntity emailEntity = new EmailEntity(); if (!validateRecipients(email.getAllRecipients())) { throw new SingularMailException("O destinatário de e-mail é inválido."); } emailEntity.setSubject(email.getSubject()); emailEntity.setContent(email.getContent()); emailEntity.setReplyTo(email.getReplyToJoining()); for (IAttachmentRef attachmentRef : email.getAttachments()) { IAttachmentRef attachment = persistenceHandler.copy(attachmentRef, null).getNewAttachmentRef(); emailEntity.getAttachments().add(persistenceHandler.getAttachmentEntity(attachment)); } emailEntity.setCreationDate(new Date()); emailDao.save(emailEntity); for (Email.Addressee addressee : email.getAllRecipients()) { EmailAddresseeEntity addresseeEntity = new EmailAddresseeEntity(); addresseeEntity.setAddress(addressee.getAddress()); addresseeEntity.setAddresseType(addressee.getType()); addresseeEntity.setEmail(emailEntity); emailAddresseeDao.save(addresseeEntity); } return true; }
@Override public Object run() { final int totalPendingRecipients = emailPersistenceService.countPendingRecipients(); int pending = totalPendingRecipients; int page = 0, sent = 0; while (pending > 0) { String identifier = Optional.ofNullable(identifierModule).orElse(SingularProperties.get().getProperty(EMAIL_COD_MODULE)); for (Email.Addressee addressee : emailPersistenceService.listPendingRecipients(page * emailsPerPage, emailsPerPage, identifier)) { if(emailSender.send(addressee)){ emailPersistenceService.markAsSent(addressee); sent++; } } pending -= emailsPerPage; page++; } getLogger().info("{} sent from total of {}", sent, totalPendingRecipients); return sent + " sent from total of "+totalPendingRecipients; }
@Bean @DependsOn(SDocument.FILE_PERSISTENCE_SERVICE) public IEmailService<?> emailService() { return new EmailPersistenceService(); }
@Bean @DependsOn(SDocument.FILE_PERSISTENCE_SERVICE) public IEmailService<?> emailService() { return new EmailPersistenceService(); }
@Bean @DependsOn(SDocument.FILE_PERSISTENCE_SERVICE) public IEmailService<?> emailService() { return new EmailPersistenceService(); }