Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 8f80601f authored by Joze RIHTARSIC's avatar Joze RIHTARSIC
Browse files

Fix mail sending for alerts if locale is not defined. Fix build logging.

parent 56684015
No related branches found
No related tags found
No related merge requests found
Pipeline #196299 failed
......@@ -29,6 +29,8 @@ import eu.europa.ec.edelivery.smp.data.model.user.DBUser;
import eu.europa.ec.edelivery.smp.data.ui.enums.AlertLevelEnum;
import eu.europa.ec.edelivery.smp.data.ui.enums.AlertStatusEnum;
import eu.europa.ec.edelivery.smp.data.ui.enums.AlertTypeEnum;
import eu.europa.ec.edelivery.smp.exceptions.ErrorCode;
import eu.europa.ec.edelivery.smp.exceptions.SMPRuntimeException;
import eu.europa.ec.edelivery.smp.logging.SMPLogger;
import eu.europa.ec.edelivery.smp.logging.SMPLoggerFactory;
import eu.europa.ec.edelivery.smp.services.mail.MailDataModel;
......@@ -165,7 +167,7 @@ public class CredentialsAlertService {
public void alertCredentialVerificationFailed(DBCredential credential) {
LOG.info("Alert on Login failure [{}]!", credential);
Boolean loginFailureEnabled = configurationService.getAlertUserLoginFailureEnabled();
boolean loginFailureEnabled = configurationService.getAlertUserLoginFailureEnabled();
if (!loginFailureEnabled) {
LOG.warn("Alert Login failure is disabled!");
return;
......@@ -196,7 +198,7 @@ public class CredentialsAlertService {
public void alertCredentialsSuspended(DBCredential credential) {
Boolean suspensionAlertEnabled = configurationService.getAlertUserSuspendedEnabled();
boolean suspensionAlertEnabled = configurationService.getAlertUserSuspendedEnabled();
if (!suspensionAlertEnabled) {
LOG.info("Alert suspended is disabled!");
return;
......@@ -384,7 +386,7 @@ public class CredentialsAlertService {
resetUrl = smpUrlBuilder.buildSMPUriForApplication().toURL();
LOG.warn("Reset URL is not set! Use default SMP URL [{}]", resetUrl);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
throw new SMPRuntimeException(ErrorCode.INTERNAL_ERROR, e);
}
}
String resetUrlPath = StringUtils.appendIfMissing(resetUrl.toString(), "/", "/") + "ui/#/reset-credential/" + token;
......@@ -489,6 +491,7 @@ public class CredentialsAlertService {
} catch (Throwable exc) {
LOG.error("Can not send mail [{}] for alert [{}]! Error [{}]",
mailTo, alert, ExceptionUtils.getRootCauseMessage(exc));
LOG.error("Error sending mail", exc);
updateAlertStatus(alert, AlertStatusEnum.FAILED, ExceptionUtils.getRootCauseMessage(exc));
}
......
......@@ -20,11 +20,13 @@ package eu.europa.ec.edelivery.smp.services.mail;
import eu.europa.ec.edelivery.smp.data.model.DBAlert;
import eu.europa.ec.edelivery.smp.data.ui.enums.AlertTypeEnum;
import org.apache.commons.lang3.StringUtils;
import java.util.HashMap;
import java.util.Map;
public class MailDataModel {
private static final String DEFAULT_LANGUAGE = "en";
public enum CommonProperties {
CURRENT_DATETIME,
SMP_INSTANCE_NAME,
......@@ -46,8 +48,12 @@ public class MailDataModel {
alert.getProperties().forEach((key, prop) -> this.model.put(key, prop.getValue()));
}
/**
* Get language of the mail. If not set, default language "en" is used.
* @return language of the mail or "en" if not set
*/
public String getLanguage() {
return language;
return StringUtils.isBlank(language)?DEFAULT_LANGUAGE:language;
}
public AlertTypeEnum getMailType() {
......
......@@ -25,7 +25,7 @@
<property name="consolePattern" value="%d{ISO8601} [%X{smp_user}] [%X{smp_session_id}] [%X{smp_request_id}] [%thread] %5p %c{1}:%L - %m%n" scope="global"/>
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${buildDirectory}/logs/edelivery-smp.log</file>
<file>target/logs/edelivery-smp.log</file>
<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
<evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
<marker>SECURITY</marker>
......@@ -36,7 +36,7 @@
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>${buildDirectory}/logs/edelivery-smp-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<fileNamePattern>target/logs/edelivery-smp-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<!-- each file should be at most 30MB, keep 60 days worth of history, but at most 20GB -->
<maxFileSize>30MB</maxFileSize>
<maxHistory>60</maxHistory>
......
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