Search in sources :

Example 1 with EmailConfigurationDto

use of org.opencastproject.messages.persistence.EmailConfigurationDto in project opencast by opencast.

the class MailService method mergeEmailConfiguration.

public static EmailConfigurationDto mergeEmailConfiguration(EmailConfiguration config, String organization, EntityManager em) {
    Option<EmailConfigurationDto> configOption = findEmailConfiguration(organization, em);
    EmailConfigurationDto dto;
    if (configOption.isSome()) {
        dto = configOption.get();
        dto.setTransport(config.getTransport());
        dto.setPassword(config.getPassword());
        dto.setPort(config.getPort());
        dto.setServer(config.getServer());
        dto.setSsl(config.isSsl());
        dto.setUserName(config.getUserName());
        em.merge(dto);
    } else {
        dto = new EmailConfigurationDto(organization, config.getTransport(), config.getServer(), config.getPort(), config.getUserName(), config.getPassword(), config.isSsl());
        em.persist(dto);
    }
    return dto;
}
Also used : EmailConfigurationDto(org.opencastproject.messages.persistence.EmailConfigurationDto)

Example 2 with EmailConfigurationDto

use of org.opencastproject.messages.persistence.EmailConfigurationDto in project opencast by opencast.

the class MailService method updateEmailConfiguration.

public EmailConfiguration updateEmailConfiguration(EmailConfiguration emailConfiguration) throws MailServiceException {
    EntityManager em = null;
    EntityTransaction tx = null;
    try {
        em = emf.createEntityManager();
        tx = em.getTransaction();
        tx.begin();
        String orgId = securityService.getOrganization().getId();
        EmailConfigurationDto emailConfig = mergeEmailConfiguration(emailConfiguration, orgId, em);
        tx.commit();
        EmailConfiguration updatedEmailConfiguration = emailConfig.toEmailConfiguration();
        updateSmtpConfiguration(updatedEmailConfiguration);
        return updatedEmailConfiguration;
    } catch (Exception e) {
        logger.error("Could not update email configuration '{}': {}", emailConfiguration, e.getMessage());
        if (tx.isActive())
            tx.rollback();
        throw new MailServiceException(e);
    } finally {
        if (em != null)
            em.close();
    }
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) EmailConfigurationDto(org.opencastproject.messages.persistence.EmailConfigurationDto) MessagingException(javax.mail.MessagingException) NoResultException(javax.persistence.NoResultException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 3 with EmailConfigurationDto

use of org.opencastproject.messages.persistence.EmailConfigurationDto in project opencast by opencast.

the class MailService method getEmailConfiguration.

public EmailConfiguration getEmailConfiguration() throws MailServiceException {
    EntityManager em = null;
    try {
        em = emf.createEntityManager();
        String orgId = securityService.getOrganization().getId();
        Option<EmailConfigurationDto> emailOption = findEmailConfiguration(orgId, em);
        if (emailOption.isSome()) {
            return emailOption.get().toEmailConfiguration();
        } else {
            return EmailConfiguration.DEFAULT;
        }
    } catch (Exception e) {
        logger.error("Could not get email configuration: {}", e.getMessage());
        throw new MailServiceException(e);
    } finally {
        if (em != null)
            em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) EmailConfigurationDto(org.opencastproject.messages.persistence.EmailConfigurationDto) MessagingException(javax.mail.MessagingException) NoResultException(javax.persistence.NoResultException) NotFoundException(org.opencastproject.util.NotFoundException)

Aggregations

EmailConfigurationDto (org.opencastproject.messages.persistence.EmailConfigurationDto)3 MessagingException (javax.mail.MessagingException)2 EntityManager (javax.persistence.EntityManager)2 NoResultException (javax.persistence.NoResultException)2 NotFoundException (org.opencastproject.util.NotFoundException)2 EntityTransaction (javax.persistence.EntityTransaction)1