Skip to content
Snippets Groups Projects
Commit 617a464a authored by Piotr Gawron's avatar Piotr Gawron
Browse files

email sender is lazy initialized (because postconstruct is called before...

email sender is lazy initialized (because postconstruct is called before population of the database)
parent 3a557a99
No related branches found
No related tags found
1 merge request!368fresh install of debian package uses flyway
......@@ -10,7 +10,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.mail.MessagingException;
import org.apache.commons.io.IOUtils;
......@@ -121,14 +120,6 @@ public class LayoutService implements ILayoutService {
*/
private EmailSender emailSender;
/**
* Method called after spring initialized all interfaces.
*/
@PostConstruct
public void springInit() {
emailSender = new EmailSender(configurationService);
}
@Override
public boolean userCanAddLayout(Model model, User user) {
// if we don't have privileges to view the object then we cannot add layouts
......@@ -396,7 +387,7 @@ public class LayoutService implements ILayoutService {
layoutDao.update(layout);
try {
emailSender.sendEmail("MapViewer status", "There was a problem with generating layout " + params.getName()
getEmailSender().sendEmail("MapViewer status", "There was a problem with generating layout " + params.getName()
+ ". Contact administrator to solve this issue.", params.getUser());
} catch (MessagingException e1) {
logger.error("Problem with sending email", e1);
......@@ -566,7 +557,7 @@ public class LayoutService implements ILayoutService {
throws MessagingException {
StringBuilder content = new StringBuilder(
"Layout " + layoutName + " in map " + projectId + " was successfully removed.<br/>");
emailSender.sendEmail("MapViewer notification", content.toString(), email);
getEmailSender().sendEmail("MapViewer notification", content.toString(), email);
}
/**
......@@ -588,7 +579,7 @@ public class LayoutService implements ILayoutService {
content.append(table);
String email = params.getModel().getProject().getNotifyEmail();
if (params.getUser() != null) { // send email to a user who owns the layout
emailSender.sendEmail("MapViewer notification", content.toString(), params.getUser());
getEmailSender().sendEmail("MapViewer notification", content.toString(), params.getUser());
// send email to the model owner
if (email != null && !email.equals(params.getUser().getEmail())) {
......@@ -600,11 +591,11 @@ public class LayoutService implements ILayoutService {
content.append(
"User " + username + " created layout in " + params.getModel().getProject().getProjectId() + " map.");
emailSender.sendEmail("MapViewer notification", content.toString(), email);
getEmailSender().sendEmail("MapViewer notification", content.toString(), email);
}
} else if (email != null) {
// if nobody owns the layout then send it to the model owner
emailSender.sendEmail("MapViewer notification", content.toString(), email);
getEmailSender().sendEmail("MapViewer notification", content.toString(), email);
}
}
......@@ -909,6 +900,9 @@ public class LayoutService implements ILayoutService {
@Override
public EmailSender getEmailSender() {
if (emailSender==null) {
emailSender = new EmailSender(configurationService);
}
return emailSender;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment