Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

K1J-95: Restructure some errorlogs when sending email notifications for incoming questions/answers #1108

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion devops/dev/config/application-dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ webcert.domain.name=wc.localtest.me
webcert.cookie.domain.name=wc.localtest.me
webcert.host.url=https://wc.localtest.me
webcert.host.url.internal=http://localhost:${dev.http.port}
sakerhetstjanst.saml.entityId=${webcert.host.url}
sakerhetstjanst.saml.entityId=${webcert.host.url}/normal

# Logical adresses
infrastructure.directory.logicalAddress=TEST
Expand Down Expand Up @@ -137,3 +137,6 @@ servicenow.subscription.url=${servicenow.base.url}/services/stubs/servicenowstub
unit.notification.config.path=${application.dir}/config/unit-notification-config.json

integration.intygproxyservice.baseurl=http://localhost:18020

# Utkast lock
job.utkastlock.cron=-
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
package se.inera.intyg.webcert.web.service.mail;

import com.google.common.base.Strings;
import java.util.Locale;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.xml.ws.WebServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -38,13 +44,6 @@
import se.riv.infrastructure.directory.privatepractitioner.v1.EnhetType;
import se.riv.infrastructure.directory.privatepractitioner.v1.HoSPersonType;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.xml.ws.WebServiceException;
import java.util.Locale;

/**
* @author andreaskaltenbach
*/
Expand Down Expand Up @@ -89,15 +88,20 @@ public class MailNotificationServiceImpl implements MailNotificationService {
@Autowired
private HsaOrganizationsService hsaOrganizationsService;

private void logError(String type, MailNotification mailNotification, Exception e) {
String message = "";
if (e != null) {
message = ": " + e.getMessage();
}
LOG.error("Notification mail for " + type + " '" + mailNotification.getQaId()
+ "' concerning certificate '" + mailNotification.getCertificateId()
+ "' couldn't be sent to " + mailNotification.getCareUnitId()
+ " (" + mailNotification.getCareUnitName() + ")" + message);
private void logError(String type, MailNotification mailNotification, Exception ex) {
LOG.error(String.format("Notification mail for %s '%s' concerning certificate '%s' couldn't be sent to %s (%s) due to reason '%s'",
type, mailNotification.getQaId(), mailNotification.getCertificateId(), mailNotification.getCareUnitId(),
mailNotification.getCareUnitName(), ex.getMessage()
),
ex
);
}

private void logError(String type, MailNotification mailNotification, String reason) {
LOG.error("Notification mail for {} '{}' concerning certificate '{}' couldn't be sent to {} ({}) due to reason '{}'",
type, mailNotification.getQaId(), mailNotification.getCertificateId(), mailNotification.getCareUnitId(),
mailNotification.getCareUnitName(), reason
);
}

@Override
Expand All @@ -107,7 +111,7 @@ public void sendMailForIncomingQuestion(MailNotification mailNotification) {
MailNotificationEnhet recipient = getUnit(mailNotification);

if (recipient == null) {
logError(type, mailNotification, null);
logError(type, mailNotification, "Missing recipient");
} else {
try {
String reason = "incoming question '" + mailNotification.getQaId() + "'";
Expand All @@ -126,7 +130,7 @@ public void sendMailForIncomingAnswer(MailNotification mailNotification) {
MailNotificationEnhet recipient = getUnit(mailNotification);

if (recipient == null) {
logError(type, mailNotification, null);
logError(type, mailNotification, "Missing recipient");
} else {
try {
String reason = "incoming answer on question '" + mailNotification.getQaId() + "'";
Expand All @@ -138,14 +142,6 @@ public void sendMailForIncomingAnswer(MailNotification mailNotification) {
}
}

public void setAdminMailAddress(String adminMailAddress) {
this.adminMailAddress = adminMailAddress;
}

public void setWebCertHostUrl(String webCertHostUrl) {
this.webCertHostUrl = webCertHostUrl;
}

private void sendNotificationMailToEnhet(String type, MailNotification mailNotification, String subject, String body,
MailNotificationEnhet receivingEnhet,
String reason) throws MessagingException {
Expand All @@ -157,9 +153,8 @@ private void sendNotificationMailToEnhet(String type, MailNotification mailNotif
if (recipientAddress == null) {
recipientAddress = getParentMailAddress(receivingEnhet.getHsaId());
}
} catch (WebServiceException e) {
LOG.error("Failed to contact HSA to get HSA Id '" + receivingEnhet.getHsaId() + "' : " + e.getMessage());
logError(type, mailNotification, null);
} catch (WebServiceException ex) {
logError(type, mailNotification, ex);
return;
}

Expand All @@ -176,8 +171,8 @@ private String getParentMailAddress(String mottagningsId) {
String parent;
try {
parent = hsaOrganizationsService.getParentUnit(mottagningsId);
} catch (HsaServiceCallException e) {
LOG.warn("Could not call HSA for {}, cause: {}", mottagningsId, e.getMessage());
} catch (HsaServiceCallException ex) {
LOG.warn(String.format("Could not call HSA for '%s', cause: '%s'", mottagningsId, ex.getMessage()), ex);
return null;
}
MailNotificationEnhet parentEnhet = retrieveDataFromHsa(parent);
Expand Down Expand Up @@ -249,8 +244,8 @@ private MailNotificationEnhet retrieveDataFromHsa(String careUnitId) {
try {
Vardenhet enhetData = hsaOrganizationsService.getVardenhet(careUnitId);
return new MailNotificationEnhet(enhetData.getId(), enhetData.getNamn(), enhetData.getEpost());
} catch (WebServiceException e) {
LOG.error("Failed to contact HSA to get HSA Id '" + careUnitId + "' : " + e.getMessage());
} catch (WebServiceException ex) {
LOG.error(String.format("Failed to contact HSA to get HSA Id '%s' : '%s'", careUnitId, ex.getMessage()), ex);
return null;
}
}
Expand All @@ -264,17 +259,17 @@ private MailNotificationEnhet getPrivatePractitionerEnhet(String hsaId) {
return new MailNotificationEnhet(hsaId, enhet.getEnhetsnamn(), enhet.getEpost());
}
}
LOG.error("Failed to lookup privatepractitioner with HSA Id '" + hsaId + "'");
LOG.error("Failed to lookup privatepractitioner with HSA Id '{}'", hsaId);
} catch (Exception e) {
LOG.error("Failed to contact ppService to get HSA Id '" + hsaId + "'", e);
LOG.error(String.format("Failed to contact ppService to get HSA Id '%s'", hsaId), e);
}
return null;
}

@Override
@Transactional(readOnly = true)
public String intygsUrl(MailNotification mailNotification) {
String url = String.valueOf(webCertHostUrl) + "/webcert/web/user/"
String url = webCertHostUrl + "/webcert/web/user/"
+ resolvePathSegment(mailNotification.getCareUnitId(), mailNotification.getCertificateId()) + "/";
if (!Fk7263EntryPoint.MODULE_ID.equalsIgnoreCase(mailNotification.getCertificateType())) {
url += mailNotification.getCertificateType() + "/";
Expand All @@ -284,7 +279,7 @@ public String intygsUrl(MailNotification mailNotification) {
url += "?enhet=" + mailNotification.getCareUnitId();
}

LOG.debug("Intygsurl: " + url);
LOG.debug("Intygsurl: {}", url);
return url;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,26 +626,30 @@ private String notificationMessageToJson(NotificationMessage notificationMessage
}

private void sendNotificationForIncomingQuestionByMail(MailNotification mailNotification) {
// send mail to enhet to inform about new question
try {
mailNotificationService.sendMailForIncomingQuestion(mailNotification);
} catch (MailSendException e) {
LOGGER.error("Notification mail for question '" + mailNotification.getQaId()
+ "' concerning certificate '" + mailNotification.getCertificateId()
+ "' couldn't be sent to " + mailNotification.getCareUnitId()
+ " (" + mailNotification.getCareUnitName() + "): " + e.getMessage());
} catch (MailSendException ex) {
LOGGER.error(
String.format("Notification mail for question '%s' concerning certificate '%s' couldn't be sent to '%s' (%s)",
mailNotification.getQaId(), mailNotification.getCertificateId(), mailNotification.getCareUnitId(),
mailNotification.getCareUnitName()
),
ex
);
}
}

private void sendNotificationForIncomingAnswerByMail(MailNotification mailNotification) {
// send mail to enhet to inform about new question
try {
mailNotificationService.sendMailForIncomingAnswer(mailNotification);
} catch (MailSendException e) {
LOGGER.error("Notification mail for answer '" + mailNotification.getQaId()
+ "' concerning certificate '" + mailNotification.getCertificateId()
+ "' couldn't be sent to " + mailNotification.getCareUnitId()
+ " (" + mailNotification.getCareUnitName() + "): " + e.getMessage());
} catch (MailSendException ex) {
LOGGER.error(
String.format("Notification mail for answer '%s' concerning certificate '%s' couldn't be sent to '%s' (%s)",
mailNotification.getQaId(), mailNotification.getCertificateId(), mailNotification.getCareUnitId(),
mailNotification.getCareUnitName()
),
ex
);
}
}

Expand Down
Loading