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;
}
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();
}
}
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();
}
}
Aggregations