Unificata e migliorata logica di creazione delle mail di errore con un template unico
This commit is contained in:
@@ -768,7 +768,8 @@ public class WooCommerceService {
|
||||
|
||||
private void sendErrorMail(String errorMsg, String service, byte[] content, String filename, List<AnomalieDTO> anomalie) {
|
||||
try {
|
||||
mailService.sendErrorMail(multiDBTransactionManager, service, "WOOCOMMERCE", null, content, filename, anomalie);
|
||||
mailService.sendErrorMailByGestNameSection(multiDBTransactionManager, service, "WOOCOMMERCE", "Errore WooCommerce",
|
||||
null, content, filename, anomalie);
|
||||
} catch (Exception exception) {
|
||||
logger.error(service, exception);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
@Deprecated
|
||||
public class FileItem {
|
||||
|
||||
private String fileName;
|
||||
|
||||
@@ -249,7 +249,7 @@ public class EmsServices {
|
||||
entityBases.add(entityBase);
|
||||
logger.error("Import entity", ex);
|
||||
try {
|
||||
mailService.sendErrorMail(multiDBTransactionManager, gestName, format, entityBases, fileContent, file.getName(), null);
|
||||
mailService.sendErrorMailByGestNameSection(multiDBTransactionManager, gestName, format, "Importazione entity", entityBases, fileContent, file.getName(), null);
|
||||
} catch (Exception e) {
|
||||
logger.error("Import entity", e);
|
||||
}
|
||||
@@ -302,7 +302,7 @@ public class EmsServices {
|
||||
entityBases.add(entityBase);
|
||||
logger.error("Import entity", ex);
|
||||
try {
|
||||
mailService.sendErrorMail(multiDBTransactionManager, gestName, format, entityBases, fileContent, fileName, null);
|
||||
mailService.sendErrorMailByGestNameSection(multiDBTransactionManager, gestName, format, "Importazione entity", entityBases, fileContent, fileName, null);
|
||||
} catch (Exception e) {
|
||||
logger.error("Import entity", e);
|
||||
}
|
||||
@@ -393,7 +393,7 @@ public class EmsServices {
|
||||
logger.error("Import entity", anomalie.get(0).getException());
|
||||
else logger.error(anomalie.get(0).getMessage());
|
||||
}
|
||||
mailService.sendErrorMail(multiDBTransactionManager, gestName, format, tmpResult, fileInput, fileName, anomalie);
|
||||
mailService.sendErrorMailByGestNameSection(multiDBTransactionManager, gestName, format, "Importazione entity", tmpResult, fileInput, fileName, anomalie);
|
||||
}
|
||||
|
||||
|
||||
@@ -418,7 +418,7 @@ public class EmsServices {
|
||||
if (anomalie.get(0).getException() != null)
|
||||
logger.error("Export entity", anomalie.get(0).getException());
|
||||
else logger.error(anomalie.get(0).getMessage());
|
||||
mailService.sendErrorMail(multiDBTransactionManager, gestName, format, null, null, null, anomalie);
|
||||
mailService.sendErrorMailByGestNameSection(multiDBTransactionManager, gestName, format, "Esportazione entity", null, null, null, anomalie);
|
||||
}
|
||||
|
||||
|
||||
@@ -486,7 +486,7 @@ public class EmsServices {
|
||||
newEx.setStackTrace(ex.getStackTrace());
|
||||
entityBase.setException(newEx);
|
||||
entityBases.add(entityBase);
|
||||
mailService.sendErrorMail(multiDBTransactionManager, "EXPORT_" + type, format, entityBases, null, null, null);
|
||||
mailService.sendErrorMailByGestNameSection(multiDBTransactionManager, "EXPORT_" + type, format, "Esportazione entity", entityBases, null, null, null);
|
||||
throw ex;
|
||||
} else {
|
||||
throw ex;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package it.integry.ems.service;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
import it.integry.common.var.CommonConstants;
|
||||
import it.integry.common.var.EmsDBConst;
|
||||
import it.integry.ems.Import.dto.AnomalieDTO;
|
||||
import it.integry.ems.dto.StbActivityEmailObject;
|
||||
import it.integry.ems.dto.StbActivityEmailObjectAttachment;
|
||||
@@ -15,21 +15,20 @@ import it.integry.ems.response.FileItem;
|
||||
import it.integry.ems.response.ServiceRestResponse;
|
||||
import it.integry.ems.rules.completing.CommonRules;
|
||||
import it.integry.ems.service.dto.CustomEmailDTO;
|
||||
import it.integry.ems.service.dto.MailTemplateDataDTO;
|
||||
import it.integry.ems.settings.Model.MailConfigurationModel;
|
||||
import it.integry.ems.settings.Model.SettingsModel;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems_model.base.EntityBase;
|
||||
import it.integry.ems_model.entity.StbEmail;
|
||||
import it.integry.ems_model.entity.StbGestSetup;
|
||||
import it.integry.ems_model.service.SetupGest;
|
||||
import it.integry.ems_model.utility.UtilityDB;
|
||||
import it.integry.ems_model.utility.UtilityDate;
|
||||
import it.integry.ems_model.utility.UtilityLocalDate;
|
||||
import it.integry.ems_model.utility.UtilityString;
|
||||
import it.integry.security.utility.CryptoUtils;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.SerializationUtils;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -42,21 +41,24 @@ import javax.mail.*;
|
||||
import javax.mail.internet.*;
|
||||
import javax.mail.util.ByteArrayDataSource;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.*;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.net.InetAddress;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.sql.Connection;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@Service
|
||||
public class MailService {
|
||||
|
||||
@Autowired
|
||||
MailPropertiesService mailPropertiesService;
|
||||
private MailPropertiesService mailPropertiesService;
|
||||
|
||||
@Autowired
|
||||
private SetupGest setupGest;
|
||||
@@ -67,9 +69,15 @@ public class MailService {
|
||||
@Autowired
|
||||
private MimeTypesHandler mimetypesFileTypeMap;
|
||||
|
||||
@Autowired
|
||||
private MailTemplateService mailTemplateService;
|
||||
|
||||
@Autowired
|
||||
private EmsDBConst emsDBConst;
|
||||
|
||||
private final Logger logger = LogManager.getLogger();
|
||||
|
||||
private enum TYPE {
|
||||
public enum Level {
|
||||
INFO,
|
||||
SUCCESS,
|
||||
WARNING,
|
||||
@@ -137,7 +145,6 @@ public class MailService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Message sendMail(String from, String fromName, String to, String cc, String ccn, String subject, String
|
||||
msgText, Boolean isHtml, List<FileItem> fileItemAttachments, boolean debug) throws Exception {
|
||||
|
||||
@@ -251,7 +258,7 @@ public class MailService {
|
||||
EmailFileSharer emailFileSharer = new EmailFileSharer();
|
||||
emailFileSharer.Init(fileSharerSettings);
|
||||
|
||||
if (emailFileAttachmentList != null && emailFileAttachmentList.size() > 0) {
|
||||
if (emailFileAttachmentList != null && !emailFileAttachmentList.isEmpty()) {
|
||||
return emailFileSharer.sendWReturnMessage(emailFileAttachmentList);
|
||||
} else {
|
||||
return emailFileSharer.sendWReturnMessage();
|
||||
@@ -268,136 +275,136 @@ public class MailService {
|
||||
return sendMailPrimary(null, null, to, cc, null, subject, msg, false, false, null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Metodo che recupera la key_section EMAIL_FOR_LOG dalla tabella {@link StbGestSetup}
|
||||
*
|
||||
* @param connection
|
||||
* @param gestname Campo gest_name della tabella {@link StbGestSetup}
|
||||
* @param section Campo section della tabella {@link StbGestSetup}
|
||||
* @return Campo value della tabella {@link StbGestSetup}
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
private String getEmailForLog(Connection connection, String gestname, String section) throws Exception {
|
||||
return setupGest.getSetup(connection, gestname, section, "EMAIL_FOR_LOG");
|
||||
public void sendErrorMailByGestNameSection(MultiDBTransactionManager multiDBTransactionManager, String emailDestination, String gestName, String section,
|
||||
String mailTitle, List<EntityBase> entitiesList, byte[] fileInput, String fileName, List<AnomalieDTO> anomalie) throws Exception {
|
||||
|
||||
|
||||
List<EmailFileAttachment> attachments = new ArrayList<>();
|
||||
attachments.add(new EmailFileAttachment(fileName, fileInput));
|
||||
|
||||
sendErrorMail(multiDBTransactionManager, emailDestination,
|
||||
mailTitle,
|
||||
String.format("%s %s", gestName, section),
|
||||
entitiesList,
|
||||
attachments,
|
||||
anomalie,
|
||||
null);
|
||||
|
||||
}
|
||||
|
||||
public void sendErrorMailByGestNameSection(MultiDBTransactionManager multiDBTransactionManager, String gestName, String section,
|
||||
String mailTitle, List<EntityBase> entitiesList, byte[] fileInput, String fileName, List<AnomalieDTO> anomalie) throws Exception {
|
||||
|
||||
|
||||
public void sendErrorMail(MultiDBTransactionManager multiDBTransactionManager, String gestName, String
|
||||
section, List<EntityBase> entitiesList, byte[] fileInput, String fileName, List<AnomalieDTO> anomalie) throws
|
||||
Exception {
|
||||
// GET DESTINATION
|
||||
String emailDestination = this.getEmailForLog(multiDBTransactionManager.getPrimaryConnection(), gestName, section);
|
||||
String emailDestination = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), gestName, section, "EMAIL_FOR_LOG");
|
||||
|
||||
if (!UtilityString.isNullOrEmpty(emailDestination)) {
|
||||
// BUILD MESSAGE
|
||||
String subject = String.format("[%s] - Errore durante operazione di %s su %s", multiDBTransactionManager.getPrimaryDatasource().getProfile(), gestName, InetAddress.getLocalHost().getHostName());
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
|
||||
URL url = new URL("https://www2.studioml.it/ems-api/mail_models/mail.php");
|
||||
InputStream inputStream = url.openStream();
|
||||
String messageText = IOUtils.toString(inputStream);
|
||||
messageText = messageText.replace("%%SYNC_TYPE%%", String.format("%s %s", gestName, section));
|
||||
messageText = messageText.replace("%%DATA_ERR_SYNC%%", dateFormat.format(new Date()));
|
||||
List<EmailFileAttachment> attachments = new ArrayList<>();
|
||||
attachments.add(new EmailFileAttachment(fileName, fileInput));
|
||||
|
||||
sendErrorMail(multiDBTransactionManager, emailDestination,
|
||||
mailTitle,
|
||||
String.format("%s %s", gestName, section),
|
||||
entitiesList,
|
||||
attachments,
|
||||
anomalie,
|
||||
null);
|
||||
|
||||
inputStream.close();
|
||||
}
|
||||
|
||||
// ATTACH FILES
|
||||
List<IFileSharerAttachment> attachedFiles = new ArrayList<IFileSharerAttachment>();
|
||||
public void sendErrorMail(MultiDBTransactionManager multiDBTransactionManager, String emailDestination, String mailTitle, String action,
|
||||
List<EntityBase> entitiesList, List<EmailFileAttachment> attachments, List<AnomalieDTO> anomalie, List<Exception> customExceptions) throws Exception {
|
||||
|
||||
String firstError = "";
|
||||
if (entitiesList != null && entitiesList.size() > 0) {
|
||||
StringBuilder stacktraceError = new StringBuilder();
|
||||
StringWriter writer = new StringWriter();
|
||||
|
||||
for (EntityBase entity : entitiesList) {
|
||||
if (entity.getException() != null) {
|
||||
if (UtilityString.isNullOrEmpty(firstError)) {
|
||||
firstError = entity.getException().getMessage();
|
||||
}
|
||||
stacktraceError.append(ExceptionUtils.getStackTrace(entity.getException()));
|
||||
jsonObjectMapper.writeValue(writer, entity);
|
||||
}
|
||||
}
|
||||
|
||||
writer.close();
|
||||
EmailFileAttachment stacktraceFile = new EmailFileAttachment("stackTrace.txt", stacktraceError.toString().getBytes());
|
||||
EmailFileAttachment entityJsonFile = new EmailFileAttachment("entity.json", SerializationUtils.serialize(writer.toString()));
|
||||
attachedFiles.add(stacktraceFile);
|
||||
attachedFiles.add(entityJsonFile);
|
||||
}
|
||||
|
||||
messageText = messageText.replace("%%ERR_STRING%%", entitiesList != null && entitiesList.size() > 0 ? (!UtilityString.isNullOrEmpty(firstError) ? firstError : "Causa non rilevata. Controllare lo stacktrace") : (anomalie != null && anomalie.size() > 0 ? anomalie.get(0).getMessage() + "..." : ""));
|
||||
|
||||
if (fileInput != null) {
|
||||
EmailFileAttachment instanceFile = new EmailFileAttachment(fileName, fileInput);
|
||||
attachedFiles.add(instanceFile);
|
||||
}
|
||||
|
||||
if (anomalie != null && anomalie.size() > 0) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (AnomalieDTO anomalia : anomalie) {
|
||||
stringBuilder.append(String.format("%s\t%s\r\n", anomalia.getTipo(), anomalia.getMessage()));
|
||||
}
|
||||
EmailFileAttachment anomaliesFile = new EmailFileAttachment("log_anomalie.txt", stringBuilder.toString().getBytes());
|
||||
attachedFiles.add(anomaliesFile);
|
||||
}
|
||||
|
||||
// SEND
|
||||
this.sendMailPrimary(null, null, emailDestination, null, null, subject, messageText, true, false, null, null, attachedFiles);
|
||||
logger.debug(String.format("Inviata mail di errore all'indirizzo %s con %d allegati.", emailDestination, attachedFiles.size()));
|
||||
if (UtilityString.isNullOrEmpty(emailDestination)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void sendErrorMail(MultiDBTransactionManager multiDBTransactionManager, String gestName, String section, EntityBase entity) throws Exception {
|
||||
// GET DESTINATION
|
||||
String emailDestination = this.getEmailForLog(multiDBTransactionManager.getPrimaryConnection(), gestName, section);
|
||||
sendErrorMail(multiDBTransactionManager, gestName, section, entity, emailDestination);
|
||||
}
|
||||
public void sendErrorMail(MultiDBTransactionManager multiDBTransactionManager, String gestName, String
|
||||
section, EntityBase entity, String emailDestination) throws Exception {
|
||||
StringBuilder mailMessage = new StringBuilder()
|
||||
.append("<p>Gentile <b>Amministratore</b>,<br />")
|
||||
.append("Ti informiamo che si è verificato un errore durante l'operazione di <b>")
|
||||
.append(action)
|
||||
.append("</b> in data ")
|
||||
.append(CommonConstants.DATETIME_DMY_SLASHED_FORMATTER.format(UtilityLocalDate.getNowTime()))
|
||||
.append(".<br /><br /></p>");
|
||||
|
||||
if (!UtilityString.isNullOrEmpty(emailDestination)) {
|
||||
// BUILD MESSAGE
|
||||
String subject = String.format("[%s] - Errore durante operazione di %s su %s", multiDBTransactionManager.getPrimaryDatasource().getProfile(), gestName, InetAddress.getLocalHost().getHostName());
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
|
||||
URL url = new URL("https://www2.studioml.it/ems-api/mail_models/mail.php");
|
||||
InputStream inputStream = url.openStream();
|
||||
String messageText = IOUtils.toString(inputStream);
|
||||
messageText = messageText.replace("%%SYNC_TYPE%%", String.format("%s %s", gestName, section));
|
||||
messageText = messageText.replace("%%DATA_ERR_SYNC%%", dateFormat.format(new Date()));
|
||||
messageText = messageText.replace("%%ERR_STRING%%", entity != null ? (entity.getException().getMessage() != null ? entity.getException().getMessage() : "Causa non rilevata. Controllare lo stacktrace") : "");
|
||||
|
||||
inputStream.close();
|
||||
String nomeAzienda = emsDBConst.getConsts(multiDBTransactionManager.getPrimaryDatasource().getProfile())
|
||||
.getNomeAzienda();
|
||||
|
||||
// ATTACH FILES
|
||||
List<IFileSharerAttachment> attachedFiles = new ArrayList<IFileSharerAttachment>();
|
||||
String subject = String.format("[%s] - Errore durante operazione di %s su %s", nomeAzienda, action, InetAddress.getLocalHost().getHostName());
|
||||
|
||||
if (entity != null) {
|
||||
EmailFileAttachment stacktraceFile = new EmailFileAttachment("stackTrace.txt", ExceptionUtils.getStackTrace(entity.getException()).getBytes());
|
||||
final MailTemplateDataDTO mailTemplateData = new MailTemplateDataDTO()
|
||||
.setTitle(mailTitle)
|
||||
.setContent(mailMessage.toString());
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
if (customExceptions != null)
|
||||
mailTemplateData.getExceptions().addAll(customExceptions);
|
||||
|
||||
|
||||
List<IFileSharerAttachment> attachedFiles = new ArrayList<>();
|
||||
|
||||
if (entitiesList != null && !entitiesList.isEmpty()) {
|
||||
|
||||
List<EntityBase> errorEntities = entitiesList.stream()
|
||||
.filter(x -> x.getException() != null)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
mailTemplateData.getExceptions().addAll(errorEntities.stream()
|
||||
.map(EntityBase::getException)
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
|
||||
//Entity Json attachment
|
||||
errorEntities = errorEntities.stream()
|
||||
.peek(x -> x.setException(null))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
for (EntityBase entity : errorEntities) {
|
||||
jsonObjectMapper.writeValue(writer, entity);
|
||||
EmailFileAttachment entityJsonFile = new EmailFileAttachment("entity.json", SerializationUtils.serialize(writer.toString()));
|
||||
writer.close();
|
||||
|
||||
attachedFiles.add(stacktraceFile);
|
||||
attachedFiles.add(entityJsonFile);
|
||||
}
|
||||
writer.close();
|
||||
|
||||
attachedFiles.add(new EmailFileAttachment("entity.json", SerializationUtils.serialize(writer.toString())));
|
||||
|
||||
// SEND
|
||||
this.sendMailPrimary(null, null, emailDestination, null, null, subject, messageText, true, false, null, null, attachedFiles);
|
||||
logger.debug(String.format("Inviata mail di errore all'indirizzo %s con %d allegati.", emailDestination, attachedFiles.size()));
|
||||
}
|
||||
|
||||
//StackTrace attachment
|
||||
List<String> exceptionHtml = mailTemplateService.renderExceptionsToHtml(mailTemplateData.getExceptions(), false);
|
||||
String stacktrace = StringUtils.join(exceptionHtml, System.lineSeparator());
|
||||
attachedFiles.add(new EmailFileAttachment("stackTrace.txt", stacktrace.getBytes()));
|
||||
|
||||
|
||||
String htmlMailText = mailTemplateService.getGenericEmailTemplate(Level.ERROR, mailTemplateData);
|
||||
|
||||
if (attachments != null && !attachments.isEmpty())
|
||||
attachedFiles.addAll(attachments);
|
||||
|
||||
if (anomalie != null && !anomalie.isEmpty()) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (AnomalieDTO anomalia : anomalie) {
|
||||
stringBuilder.append(String.format("%s\t%s\r\n", anomalia.getTipo(), anomalia.getMessage()));
|
||||
}
|
||||
EmailFileAttachment anomaliesFile = new EmailFileAttachment("log_anomalie.txt", stringBuilder.toString().getBytes());
|
||||
attachedFiles.add(anomaliesFile);
|
||||
}
|
||||
|
||||
// SEND
|
||||
this.sendMailPrimary(multiDBTransactionManager, null, null, emailDestination, null, null,
|
||||
subject, htmlMailText, true, false, null, null,
|
||||
attachedFiles, false, null);
|
||||
logger.debug(String.format("Inviata mail di errore all'indirizzo %s con %d allegati.", emailDestination, attachedFiles.size()));
|
||||
}
|
||||
|
||||
|
||||
public void sendSystemInfoLog(String mailSubject, String mailTitle, String mailContent, Date footerDate) throws Exception {
|
||||
internalSendSystemMail(TYPE.INFO, mailSubject, mailTitle, mailContent, footerDate);
|
||||
internalSendSystemMail(Level.INFO, mailSubject, mailTitle, mailContent, footerDate);
|
||||
}
|
||||
|
||||
public void sendSystemSuccessLog(String mailSubject, String mailTitle, String mailContent, Date footerDate) throws Exception {
|
||||
internalSendSystemMail(TYPE.SUCCESS, mailSubject, mailTitle, mailContent, footerDate);
|
||||
internalSendSystemMail(Level.SUCCESS, mailSubject, mailTitle, mailContent, footerDate);
|
||||
}
|
||||
|
||||
public void sendSystemWarningLog(String mailSubject, String mailTitle, String mailContent, String exceptionMessage, Date footerDate) throws Exception {
|
||||
@@ -407,7 +414,7 @@ public class MailService {
|
||||
"<p style=\"text-align: left; font-weight: bold;font-size: 12px;\">ERROR LOG</p>" +
|
||||
"<p style=\"text-align: left; font-size: 12px; color: gray; font-family: consolas;\">" + exceptionMessage + "</p>";
|
||||
|
||||
internalSendSystemMail(TYPE.WARNING, mailSubject, mailTitle, mailContent, footerDate);
|
||||
internalSendSystemMail(Level.WARNING, mailSubject, mailTitle, mailContent, footerDate);
|
||||
}
|
||||
|
||||
public void sendSystemWarningLog(String mailSubject, String mailTitle, String mailContent, Exception ex, Date footerDate) throws Exception {
|
||||
@@ -423,7 +430,7 @@ public class MailService {
|
||||
pw.close();
|
||||
sw.close();
|
||||
|
||||
internalSendSystemMail(TYPE.WARNING, mailSubject, mailTitle, mailContent, footerDate);
|
||||
internalSendSystemMail(Level.WARNING, mailSubject, mailTitle, mailContent, footerDate);
|
||||
}
|
||||
|
||||
public void sendSystemErrorLog(String mailSubject, String mailTitle, String mailContent, String exceptionMessage, Date footerDate) throws Exception {
|
||||
@@ -433,7 +440,7 @@ public class MailService {
|
||||
"<p style=\"text-align: left; font-weight: bold;font-size: 12px;\">ERROR LOG</p>" +
|
||||
"<p style=\"text-align: left; font-size: 12px; color: gray; font-family: consolas;\">" + exceptionMessage + "</p>";
|
||||
|
||||
internalSendSystemMail(TYPE.ERROR, mailSubject, mailTitle, mailContent, footerDate);
|
||||
internalSendSystemMail(Level.ERROR, mailSubject, mailTitle, mailContent, footerDate);
|
||||
}
|
||||
|
||||
public void sendSystemErrorLog(String mailSubject, String mailTitle, String mailContent, Exception ex, Date footerDate) throws Exception {
|
||||
@@ -449,43 +456,19 @@ public class MailService {
|
||||
pw.close();
|
||||
sw.close();
|
||||
|
||||
internalSendSystemMail(TYPE.ERROR, mailSubject, mailTitle, mailContent, footerDate);
|
||||
internalSendSystemMail(Level.ERROR, mailSubject, mailTitle, mailContent, footerDate);
|
||||
}
|
||||
|
||||
private void internalSendSystemMail(TYPE mailType, String mailSubject, String mailTitle, String mailContent, Date footerDate) throws Exception {
|
||||
private void internalSendSystemMail(Level mailLevel, String mailSubject, String mailTitle, String mailContent, Date footerDate) throws Exception {
|
||||
|
||||
String urlString = "https://www2.studioml.it/ems-api/mail_models/";
|
||||
String htmlEmail = mailTemplateService.getGenericEmailTemplate(mailLevel, new MailTemplateDataDTO()
|
||||
.setTitle(mailTitle)
|
||||
.setContent(mailContent));
|
||||
|
||||
switch (mailType) {
|
||||
case SUCCESS:
|
||||
urlString += "success_email.html";
|
||||
break;
|
||||
case WARNING:
|
||||
urlString += "warning_email.html";
|
||||
break;
|
||||
case ERROR:
|
||||
urlString += "error_email.html";
|
||||
break;
|
||||
case INFO:
|
||||
default:
|
||||
urlString += "info_email.html";
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
URL url = new URL(urlString);
|
||||
InputStream inputStream = url.openStream();
|
||||
|
||||
String messageText = IOUtils.toString(inputStream, "UTF-8")
|
||||
.replace("#MAIL_TITLE#", mailTitle)
|
||||
.replace("#MAIL_CONTENT#", mailContent)
|
||||
.replace("#FOOTER_DATE#", UtilityDate.formatDate(footerDate, "dd MMM yyyy HH:mm"));
|
||||
|
||||
inputStream.close();
|
||||
|
||||
EmailFileSharerSettings fileSharerSettings = useSystemParams()
|
||||
.withSubject(mailSubject)
|
||||
.withHtmlMessage(messageText)
|
||||
.withHtmlMessage(htmlEmail)
|
||||
.to("developer@integry.it")
|
||||
.cc("syslogs@integry.it")
|
||||
.cc("helpdesk@integry.it");
|
||||
@@ -556,7 +539,7 @@ public class MailService {
|
||||
message.setFrom(new InternetAddress(emailObject.getFrom().getDisplayName().replaceAll(",", "") + "<" + emailObject.getFrom().getEmailAddress().replaceAll(",", "") + ">"));
|
||||
message.setSentDate(emailObject.getDateTimeCreated());
|
||||
|
||||
List<InternetAddress> toList = Stream.of(emailObject.getTo())
|
||||
List<InternetAddress> toList = emailObject.getTo().stream()
|
||||
.map(x -> {
|
||||
try {
|
||||
return new InternetAddress(x.getDisplayName().replaceAll(",", "") + "<" + x.getEmailAddress().replaceAll(",", "") + ">");
|
||||
@@ -565,7 +548,7 @@ public class MailService {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.toList();
|
||||
.collect(Collectors.toList());
|
||||
InternetAddress[] toArray = new InternetAddress[toList.size()];
|
||||
toList.toArray(toArray);
|
||||
|
||||
@@ -573,7 +556,7 @@ public class MailService {
|
||||
|
||||
String body = emailObject.getBody();
|
||||
|
||||
if(body != null && emailObject.isBodyInBase64())
|
||||
if (body != null && emailObject.isBodyInBase64())
|
||||
body = new String(Base64.decodeBase64(body), StandardCharsets.UTF_8);
|
||||
|
||||
body = body.replaceAll("@.{8}\\..{8}", "");
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
package it.integry.ems.service;
|
||||
|
||||
import it.integry.common.var.CommonConstants;
|
||||
import it.integry.ems.service.dto.MailTemplateDataDTO;
|
||||
import it.integry.ems_model.utility.UtilityLocalDate;
|
||||
import it.integry.ems_model.utility.UtilityString;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class MailTemplateService {
|
||||
|
||||
|
||||
public String getGenericEmailTemplate(MailService.Level level, MailTemplateDataDTO mailTemplateData) throws Exception {
|
||||
URL url = new URL("https://www2.studioml.it/ems-api/mail_models/integry-generic-communication-mail-template.html");
|
||||
|
||||
InputStream inputStream = url.openStream();
|
||||
String htmlMailBody = IOUtils.toString(inputStream, "UTF-8");
|
||||
inputStream.close();
|
||||
|
||||
String bannerBgColor;
|
||||
|
||||
switch (level) {
|
||||
case WARNING:
|
||||
bannerBgColor = "#C67F2A";
|
||||
break;
|
||||
case ERROR:
|
||||
bannerBgColor = "#B2222D";
|
||||
break;
|
||||
case SUCCESS:
|
||||
bannerBgColor = "#2A7537";
|
||||
break;
|
||||
case INFO:
|
||||
default:
|
||||
bannerBgColor = "#2d3142";
|
||||
break;
|
||||
}
|
||||
|
||||
htmlMailBody = htmlMailBody.replaceAll("#BANNER_BG_COLOR#", bannerBgColor);
|
||||
|
||||
|
||||
String title = mailTemplateData.getTitle();
|
||||
|
||||
if (UtilityString.isNullOrEmpty(title)) {
|
||||
switch (level) {
|
||||
case WARNING:
|
||||
title = "Attenzione";
|
||||
break;
|
||||
case ERROR:
|
||||
title = "Errore";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
htmlMailBody = htmlMailBody.replaceAll("#MAIL_TITLE#", UtilityString.blankIfNull(title));
|
||||
htmlMailBody = htmlMailBody.replaceAll("#MAIL_SUBTITLE#", UtilityString.blankIfNull(mailTemplateData.getSubtitle()));
|
||||
|
||||
|
||||
//Exceptions
|
||||
final StringBuilder exceptionHtml = new StringBuilder();
|
||||
|
||||
if (mailTemplateData.anyException()) {
|
||||
exceptionHtml.append("<br /><br /><br />")
|
||||
.append("<hr noshade size=\"1\"><br />")
|
||||
.append("<p style=\"text-align: left; font-weight: bold;font-size: 12px;\">Errori rilevati</p>");
|
||||
|
||||
mailTemplateData.getExceptions()
|
||||
.forEach(x -> exceptionHtml.append(x.getMessage()).append("<br />"));
|
||||
}
|
||||
|
||||
htmlMailBody = htmlMailBody.replaceAll("#MAIL_CONTENT#",
|
||||
UtilityString.blankIfNull(mailTemplateData.getContent()) + exceptionHtml);
|
||||
|
||||
|
||||
htmlMailBody = htmlMailBody.replaceAll("#FOOTER_DATE#", CommonConstants.DATETIME_DMY_SLASHED_FORMATTER.format(UtilityLocalDate.getNowTime()));
|
||||
|
||||
return htmlMailBody;
|
||||
}
|
||||
|
||||
|
||||
public List<String> renderExceptionsToHtml(List<Exception> exceptions, boolean applyConsoleStyle) {
|
||||
List<String> renderedExceptions = new ArrayList<>();
|
||||
|
||||
for (Exception exception : exceptions) {
|
||||
renderedExceptions.add(renderExceptionToHtml(exception, applyConsoleStyle));
|
||||
}
|
||||
|
||||
return renderedExceptions;
|
||||
}
|
||||
|
||||
|
||||
public String renderExceptionToHtml(Exception ex, boolean applyConsoleStyle) {
|
||||
StringBuilder htmlContent = new StringBuilder();
|
||||
|
||||
if (applyConsoleStyle)
|
||||
htmlContent.append("<p style=\"text-align: left; font-size: 12px; color: gray; font-family: consolas;\">");
|
||||
|
||||
htmlContent.append(ExceptionUtils.getStackTrace(ex));
|
||||
|
||||
if (applyConsoleStyle) htmlContent.append("</p>");
|
||||
|
||||
return htmlContent.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package it.integry.ems.service.dto;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MailTemplateDataDTO {
|
||||
|
||||
private String title;
|
||||
private String subtitle;
|
||||
|
||||
private String content;
|
||||
|
||||
private List<Exception> exceptions = new ArrayList<>();
|
||||
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public MailTemplateDataDTO setTitle(String title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getSubtitle() {
|
||||
return subtitle;
|
||||
}
|
||||
|
||||
public MailTemplateDataDTO setSubtitle(String subtitle) {
|
||||
this.subtitle = subtitle;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public MailTemplateDataDTO setContent(String content) {
|
||||
this.content = content;
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<Exception> getExceptions() {
|
||||
return exceptions;
|
||||
}
|
||||
|
||||
public MailTemplateDataDTO setExceptions(List<Exception> exceptions) {
|
||||
this.exceptions = exceptions;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean anyException() {
|
||||
return exceptions != null && !exceptions.isEmpty();
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,6 @@ import it.integry.common.var.EmsDBConst;
|
||||
import it.integry.ems.datasource.DataSource;
|
||||
import it.integry.ems.dynamic_cache.DynamicCacheService;
|
||||
import it.integry.ems.exception.SyncException;
|
||||
import it.integry.ems.file_sharer.IFileSharerAttachment;
|
||||
import it.integry.ems.file_sharer.sharers.email.EmailFileAttachment;
|
||||
import it.integry.ems.json.JSONObjectMapper;
|
||||
import it.integry.ems.service.MailService;
|
||||
import it.integry.ems.settings.Model.AvailableConnectionsModel;
|
||||
@@ -19,7 +17,6 @@ import it.integry.ems_model.exception.EntityException;
|
||||
import it.integry.ems_model.service.SetupGest;
|
||||
import it.integry.ems_model.types.OperationType;
|
||||
import it.integry.ems_model.utility.UtilityString;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.josql.Query;
|
||||
@@ -28,16 +25,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URL;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -128,44 +120,18 @@ public class SyncManager {
|
||||
} else if (e instanceof SQLException && "23000".equals(((SQLException) e).getSQLState())) {
|
||||
//Se l'errore è di chiave duplicata non inviamo nessuna email
|
||||
} else {
|
||||
try {
|
||||
|
||||
URL url = new URL("https://www2.studioml.it/ems-api/mail_models/mail.php");
|
||||
InputStream is = url.openStream();
|
||||
htmlMailBody = IOUtils.toString(is);
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
|
||||
String tipoSync = "";
|
||||
if (UtilityString.isNullOrEmpty(transactionId)) tipoSync = "online";
|
||||
else tipoSync = "offline ( ID TRANSAZIONE:" + transactionId + ")";
|
||||
htmlMailBody = htmlMailBody.replace("%%SYNC_TYPE%%", "Sincronizzazione " + tipoSync);
|
||||
htmlMailBody = htmlMailBody.replace("%%DATA_ERR_SYNC%%", sdf.format(new Date()));
|
||||
htmlMailBody = htmlMailBody.replace("%%ERR_STRING%%", e.toString());
|
||||
} catch (Exception ex) {
|
||||
htmlMailBody = "ERRORE INVOCAZIONE SYNC REST PER LA TRANSAZIONE N° " + transactionId + "\n\n" + e.toString();
|
||||
}
|
||||
|
||||
String toEmailDbg = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), "WS_REST", "SYNC_ONLINE", "EMAIL_FOR_LOG");
|
||||
|
||||
String nomeAzienda = emsDBConst.getConsts(multiDBTransactionManager.getPrimaryDatasource().getProfile())
|
||||
.getNomeAzienda();
|
||||
if (UtilityString.isNullOrEmpty(toEmailDbg))
|
||||
return;
|
||||
|
||||
String tipoSync;
|
||||
|
||||
if (!UtilityString.isNullOrEmpty(toEmailDbg)) {
|
||||
if (UtilityString.isNullOrEmpty(transactionId)) tipoSync = "online";
|
||||
else tipoSync = "offline (#" + transactionId + ")";
|
||||
|
||||
List<IFileSharerAttachment> filesToAttach = new ArrayList<IFileSharerAttachment>();
|
||||
|
||||
ByteArrayOutputStream stackTrace = new ByteArrayOutputStream();
|
||||
PrintStream pw = new PrintStream(stackTrace);
|
||||
e.printStackTrace(pw);
|
||||
|
||||
filesToAttach.add(new EmailFileAttachment("stacktrace.txt", stackTrace.toByteArray()));
|
||||
filesToAttach.add(new EmailFileAttachment("entity.json", entityByteArray));
|
||||
|
||||
String mailSubject = nomeAzienda + " - ERRORE SYNC SU " + InetAddress.getLocalHost().getHostName() + " (Publication: " + publicator + " - Subscriptor: " + subscriptor + ")";
|
||||
|
||||
mailService.sendMailPrimary(null, null, toEmailDbg, null, null, mailSubject, htmlMailBody, true, false, null, null, filesToAttach);
|
||||
}
|
||||
mailService.sendErrorMail(multiDBTransactionManager, toEmailDbg, "Sincronizzazione", "Sincronizzazione " + tipoSync,
|
||||
null, null, null, Collections.singletonList(e));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,7 +226,7 @@ public class SyncManager {
|
||||
|
||||
List<StbSubscription> subscriptions = dynamicCacheService.getEntity(DynamicCacheService.Keys.ENTITY_SYNC_KEY, dbNameDistributore);
|
||||
|
||||
if(subscriptions == null) return null;
|
||||
if (subscriptions == null) return null;
|
||||
|
||||
boolean isCurrentlyOnDistributore = profileDb.equalsIgnoreCase(profileDbDistributore);
|
||||
|
||||
|
||||
@@ -22,9 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.sql.Connection;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
@@ -410,7 +408,7 @@ public class ContabilImportService {
|
||||
CsvMapper mapper = new CsvMapper();
|
||||
String csv = mapper.serialize(movPagheAnomalie, ";", header, true);
|
||||
|
||||
mailService.sendErrorMail(multiDBTransactionManager, "IMPORT_" + type, format, null, csv.getBytes(), "ANOMALIE_MOV_PAGHE.CSV", null);
|
||||
mailService.sendErrorMailByGestNameSection(multiDBTransactionManager, "IMPORT_" + type, format, "Importazione movimenti paghe", null, csv.getBytes(), "ANOMALIE_MOV_PAGHE.CSV", null);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -958,7 +958,7 @@ public class DocumentController {
|
||||
try {
|
||||
|
||||
List<EntityBase> entityList = trasformaPrevServices.trasformaPrev(input, headless);
|
||||
if (entityList != null && entityList.size() > 0) {
|
||||
if (entityList != null && !entityList.isEmpty()) {
|
||||
listResponse = UtilityEntity.toServiceRestResponse(entityList);
|
||||
} else {
|
||||
listResponse.add(new ServiceRestResponse(EsitoType.OK));
|
||||
|
||||
@@ -1,22 +1,19 @@
|
||||
package it.integry.ems.document.service;
|
||||
|
||||
import com.annimon.stream.ComparatorCompat;
|
||||
import com.annimon.stream.Optional;
|
||||
import com.annimon.stream.Stream;
|
||||
import it.integry.common.var.CommonConstants;
|
||||
import it.integry.ems.Import.dto.AnomalieDTO;
|
||||
import it.integry.ems.contabil.Import.dto.MovPagheDTO;
|
||||
import it.integry.ems.document.dto.CambioTipoDocDTO;
|
||||
import it.integry.ems.rules.completing.CommonRules;
|
||||
import it.integry.ems.service.EntityProcessor;
|
||||
import it.integry.ems.service.MailService;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems_model.base.EntityBase;
|
||||
import it.integry.ems_model.entity.DtbDoctCambioTipoDoc;
|
||||
import it.integry.ems_model.entity.DtbOrdr;
|
||||
import it.integry.ems_model.service.SetupGest;
|
||||
import it.integry.ems_model.types.OperationType;
|
||||
import it.integry.ems_model.utility.*;
|
||||
import it.integry.ems_model.utility.Query;
|
||||
import it.integry.ems_model.utility.UtilityDB;
|
||||
import it.integry.ems_model.utility.UtilityDate;
|
||||
import it.integry.ems_model.utility.UtilityString;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -24,6 +21,7 @@ import org.springframework.web.context.ContextLoader;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class CambioTipoDocPlanService {
|
||||
@@ -114,40 +112,44 @@ public class CambioTipoDocPlanService {
|
||||
|
||||
if (existDoc) {
|
||||
List<CambioTipoDocDTO.Allegati> listaAllegati =
|
||||
Stream.of(doc.getValue())
|
||||
doc.getValue().stream()
|
||||
.filter(x -> x.getIdAllegato() != null)
|
||||
.map(
|
||||
x -> {
|
||||
CambioTipoDocDTO.Allegati allegati = new CambioTipoDocDTO.Allegati()
|
||||
.setIdAllegato(x.getIdAllegato());
|
||||
return allegati;
|
||||
}
|
||||
).distinct().toList();
|
||||
.map(x -> new CambioTipoDocDTO.Allegati()
|
||||
.setIdAllegato(x.getIdAllegato()))
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (listaAllegati != null && !listaAllegati.isEmpty()) {
|
||||
if (!listaAllegati.isEmpty()) {
|
||||
doc.getKey().setAllegati(listaAllegati);
|
||||
}
|
||||
|
||||
doc.getKey().setDataCmov(UtilityDate.getTodayWithoutTime());
|
||||
entityList = entityProcessor.processEntityList(cambioTipoDocService.getListaDoc(doc.getKey()), doc.getKey().getUserName(), true, true, true);
|
||||
|
||||
Optional<EntityBase> first = Stream.of(entityList).filter(x -> x.getException() != null).findFirst();
|
||||
Optional<EntityBase> first = entityList.stream()
|
||||
.filter(x -> x.getException() != null)
|
||||
.findFirst();
|
||||
|
||||
if (first.isPresent()) {
|
||||
logger.error(first.get().getException());
|
||||
mailService.sendErrorMail(multiDBTransactionManager, "CAMBIO TIPO DOCUMENTO", "", first.get(), emailForLog);
|
||||
Exception catchedException = first.get().getException();
|
||||
logger.error("Errore durante il cambio di tipo documento", catchedException);
|
||||
|
||||
mailService.sendErrorMail(multiDBTransactionManager, emailForLog, "Cambio tipo documento",
|
||||
"Cambio tipo documento", Collections.singletonList(first.get()), null, null, null);
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
|
||||
List<DtbDoctCambioTipoDoc> dtbDoctCambioTipoDocDel = Stream.of(dtbDoctCambioTipoDocs)
|
||||
List<DtbDoctCambioTipoDoc> dtbDoctCambioTipoDocDel = dtbDoctCambioTipoDocs.stream()
|
||||
.filter(x -> x.getCodAnag().equalsIgnoreCase(doc.getKey().getCodAnag()) &&
|
||||
x.getCodDtip().equalsIgnoreCase(doc.getKey().getCodDtip()) &&
|
||||
x.getDataDoc().equals(doc.getKey().getDataDoc()) &&
|
||||
x.getSerDoc().equalsIgnoreCase(doc.getKey().getSerDoc()) &&
|
||||
x.getNumDoc().equals(doc.getKey().getNumDoc()))
|
||||
.toList();
|
||||
.collect(Collectors.toList());
|
||||
|
||||
dtbDoctCambioTipoDocDel.forEach(x -> x.setOperation(OperationType.DELETE));
|
||||
|
||||
entityProcessor.processEntityList(dtbDoctCambioTipoDocDel, true);
|
||||
|
||||
if (error) {
|
||||
|
||||
@@ -176,7 +176,7 @@ public class GeneraCorrispettiviService {
|
||||
}
|
||||
String emailForLog = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), "CORRISPETTIVI", "SETUP", "EMAIL_FOR_LOG");
|
||||
if (!UtilityString.isNullOrEmpty(emailForLog) && Stream.of(anomalie).filter(x -> !x.getTipo().equals(AnomalieDTO.Type.INFO)).findFirst().isPresent()) {
|
||||
mailService.sendErrorMail(multiDBTransactionManager, "CORRISPETTIVI", "SETUP", entityReturn, null, null, anomalie);
|
||||
mailService.sendErrorMailByGestNameSection(multiDBTransactionManager, "CORRISPETTIVI", "SETUP", "Generazione corrispettivi", entityReturn, null, null, anomalie);
|
||||
}
|
||||
|
||||
mLastProcedureStartTime.remove(profileDb);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package it.integry.ems.document.service;
|
||||
|
||||
import com.annimon.stream.Optional;
|
||||
import com.annimon.stream.Stream;
|
||||
import com.microsoft.sqlserver.jdbc.SQLServerCallableStatement;
|
||||
import com.microsoft.sqlserver.jdbc.SQLServerDataTable;
|
||||
@@ -54,17 +53,16 @@ public class TrasformaPrevServices {
|
||||
|
||||
int segnoQtaDoc = getSegnoQtaDoc(input.getCodDtip());
|
||||
|
||||
Date inzio = new Date();
|
||||
String to = UtilityHashMap.getValueIfExists(setup, "EMAIL_FOR_LOG");
|
||||
if (UtilityString.isNullOrEmpty(to)) {
|
||||
to = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(),
|
||||
"SELECT e_mail from stb_email WHERE flag_default = 'S'");
|
||||
sendError(headless, to, "Indirizzo email con configurato");
|
||||
sendError(headless, to, new Exception("Indirizzo email con configurato"));
|
||||
}
|
||||
|
||||
String whereCond = input.getWhereCond();
|
||||
if (UtilityString.isNullOrEmpty(whereCond)) {
|
||||
sendError(headless, to, "Impossibile leggere le condizioni di where");
|
||||
sendError(headless, to, new Exception("Impossibile leggere le condizioni di where"));
|
||||
}
|
||||
|
||||
short anno = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(
|
||||
@@ -73,11 +71,11 @@ public class TrasformaPrevServices {
|
||||
|
||||
List<DtbDoct> dtbDoctDelete = listaPrev(multiDBTransactionManager.getPrimaryConnection(), input);
|
||||
|
||||
boolean dataNonAmmessa = Stream.of(dtbDoctDelete).anyMatch(x -> UtilityDate.datePart(Calendar.YEAR, x.getDataDoc()) < anno);
|
||||
boolean dataNonAmmessa = dtbDoctDelete.stream().anyMatch(x -> UtilityDate.datePart(Calendar.YEAR, x.getDataDoc()) < anno);
|
||||
|
||||
if (dataNonAmmessa) {
|
||||
if (headless) {
|
||||
sendError(headless, to, "Data documento non ammessa, verificare anno contabile e anno di magazzino.");
|
||||
sendError(headless, to, new Exception("Data documento non ammessa, verificare anno contabile e anno di magazzino."));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +113,7 @@ public class TrasformaPrevServices {
|
||||
|
||||
List<EntityBase> entityRet= entityProcessor.processEntityList(entityList, true);
|
||||
|
||||
Optional<EntityBase> firstError = Stream.of(entityRet).filter(x -> x.getException() != null).findFirst();
|
||||
Optional<EntityBase> firstError = entityRet.stream().filter(x -> x.getException() != null).findFirst();
|
||||
|
||||
if (firstError.isPresent()) {
|
||||
errori.add(String.format("%s del %s n. %s/%s: %s",
|
||||
@@ -128,9 +126,11 @@ public class TrasformaPrevServices {
|
||||
if (headless) {
|
||||
logger.error("Trasformazione preventivi: ", firstError.get().getException());
|
||||
try {
|
||||
mailService.sendErrorMail(multiDBTransactionManager, gestName, section, firstError.get(), to);
|
||||
mailService.sendErrorMailByGestNameSection(multiDBTransactionManager, to, gestName, section, "Trasformazione preventivi",
|
||||
Collections.singletonList(firstError.get()), null, null, null);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Trasformazione preventivi:", e);
|
||||
logger.error("Trasformazione preventivi - Invio mail:", e);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
@@ -179,11 +179,12 @@ public class TrasformaPrevServices {
|
||||
return UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
}
|
||||
|
||||
private void sendError(boolean headless, String to, String errorMessage) throws Exception{
|
||||
private void sendError(boolean headless, String to, Exception generatedError) throws Exception{
|
||||
if (headless ) {
|
||||
mailService.sendMail(to, null, "PROCEDURA DI TRAFERIMENTO PREV", errorMessage);
|
||||
mailService.sendErrorMail(multiDBTransactionManager, to, "Trasferimento prev",
|
||||
"Procedura di trasferimento prev", null, null, null, Collections.singletonList(generatedError));
|
||||
}
|
||||
throw new Exception(errorMessage);
|
||||
throw generatedError;
|
||||
}
|
||||
|
||||
private MtbColt generaCollo(Connection conn, DtbDoct dtbDoct, TrasformaPrevDTO input, String codMdep, int segnoDoc) throws Exception {
|
||||
|
||||
@@ -31,10 +31,8 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Scope("request")
|
||||
@@ -91,21 +89,21 @@ public class Slim2kLogisticService {
|
||||
}
|
||||
|
||||
String sql =
|
||||
" SELECT shippingplan_export.listdate as data_collo," +
|
||||
" shippingplan_export.docnum as num_ord," +
|
||||
" shippingplan_export.item as cod_mart," +
|
||||
" shippingplan_export.qtychecked as qta_col," +
|
||||
" shippingplan_export.ref as cod_anag," +
|
||||
" shippingplan_export.dest as cod_vdes," +
|
||||
" shippingplan_export.docdate as data_ord," +
|
||||
" shippingplan_export.workorder as partita_mag," +
|
||||
" shippingplan_export.docrow as riga_ord," +
|
||||
" shippingplan_export.pltcode as plt_code, " +
|
||||
" shippingplan_export.whouse as cod_mdep, " +
|
||||
" shippingplan_export.qtycheckedalt as num_cnf, " +
|
||||
" shippingplan_export.picker as picker " +
|
||||
" SELECT shippingplan_export.listdate AS data_collo," +
|
||||
" shippingplan_export.docnum AS num_ord," +
|
||||
" shippingplan_export.item AS cod_mart," +
|
||||
" shippingplan_export.qtychecked AS qta_col," +
|
||||
" shippingplan_export.ref AS cod_anag," +
|
||||
" shippingplan_export.dest AS cod_vdes," +
|
||||
" shippingplan_export.docdate AS data_ord," +
|
||||
" shippingplan_export.workorder AS partita_mag," +
|
||||
" shippingplan_export.docrow AS riga_ord," +
|
||||
" shippingplan_export.pltcode AS plt_code, " +
|
||||
" shippingplan_export.whouse AS cod_mdep, " +
|
||||
" shippingplan_export.qtycheckedalt AS num_cnf, " +
|
||||
" shippingplan_export.picker AS picker " +
|
||||
" FROM shippingplan_export" +
|
||||
" WHERE shippingplan_export.qtydelivered <> 0 AND shippingplan_export.whouse is not null " +
|
||||
" WHERE shippingplan_export.qtydelivered <> 0 AND shippingplan_export.whouse IS NOT NULL " +
|
||||
" ORDER BY shippingplan_export.whouse, " +
|
||||
" shippingplan_export.listcode, " +
|
||||
" shippingplan_export.listdate DESC, " +
|
||||
@@ -237,7 +235,9 @@ public class Slim2kLogisticService {
|
||||
for (EntityBase entity : colli) {
|
||||
if (entity.getException() != null) {
|
||||
respList.add(new ServiceRestResponse(EsitoType.KO, entity.getException().getMessage()));
|
||||
mailService.sendErrorMail(multiDBTransactionManager, type, format, entity);
|
||||
|
||||
mailService.sendErrorMailByGestNameSection(multiDBTransactionManager, type, format, null,
|
||||
Collections.singletonList(entity), null, null, null);
|
||||
} else {
|
||||
respList.add(new ServiceRestResponse(EsitoType.OK, entity, multiDBTransactionManager.getPrimaryDatasource().getProfile()));
|
||||
}
|
||||
@@ -492,13 +492,20 @@ public class Slim2kLogisticService {
|
||||
try {
|
||||
colli = entityProcessor.processEntityList(colli, true);
|
||||
|
||||
final List<EntityBase> entitiesWithErrors = colli.stream()
|
||||
.filter(x -> x.getException() != null)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (!entitiesWithErrors.isEmpty()) {
|
||||
mailService.sendErrorMailByGestNameSection(multiDBTransactionManager, type, format, null,
|
||||
entitiesWithErrors, null, null, null);
|
||||
}
|
||||
|
||||
for (EntityBase entity : colli) {
|
||||
if (entity.getException() != null) {
|
||||
respList.add(new ServiceRestResponse(EsitoType.KO, entity.getException().getMessage()));
|
||||
mailService.sendErrorMail(multiDBTransactionManager, type, format, entity);
|
||||
} else {
|
||||
respList.add(new ServiceRestResponse(EsitoType.OK, entity, multiDBTransactionManager.getPrimaryDatasource().getProfile()));
|
||||
}
|
||||
if (entity.getException() != null)
|
||||
respList.add(ServiceRestResponse.createNegativeResponse(entity.getException()));
|
||||
else
|
||||
respList.add(ServiceRestResponse.createEntityPositiveResponse(entity));
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -1649,6 +1649,18 @@ public class SystemController {
|
||||
return ServiceRestResponse.createPositiveResponse();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/system/test", method = RequestMethod.POST)
|
||||
public @ResponseBody
|
||||
ServiceRestResponse systemTest() throws Exception {
|
||||
|
||||
mailService.sendErrorMail(multiDBTransactionManager, "g.scorrano@integry.it", "Test",
|
||||
"Test email", null, null, null,
|
||||
Collections.singletonList(new NotValidLicenseException()));
|
||||
|
||||
|
||||
return ServiceRestResponse.createPositiveResponse();
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "word/implode/test", method = RequestMethod.POST)
|
||||
public @ResponseBody
|
||||
|
||||
@@ -36,6 +36,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Scope(value = "request")
|
||||
@@ -53,6 +54,9 @@ public class AnagImportService {
|
||||
@Autowired
|
||||
private MapService mapService;
|
||||
|
||||
@Autowired
|
||||
private MailService mailService;
|
||||
|
||||
private Logger logger = LogManager.getLogger();
|
||||
|
||||
public void setCoodinateGeoClie() throws Exception {
|
||||
@@ -147,22 +151,18 @@ public class AnagImportService {
|
||||
|
||||
}
|
||||
|
||||
if (entityList.size() > 0) {
|
||||
if (!entityList.isEmpty()) {
|
||||
entityProcessor.processEntityList(entityList, false);
|
||||
|
||||
List<GtbAnag> listError =
|
||||
Stream.of(entityList).filter(x -> x.getException() != null).toList();
|
||||
|
||||
if (listError != null && listError.size() > 0) {
|
||||
for (GtbAnag anag : listError) {
|
||||
anomalie.add(AnomalieDTO.error(anag.getException()));
|
||||
}
|
||||
}
|
||||
anomalie.addAll(
|
||||
entityList.stream()
|
||||
.filter(x -> x.getException() != null)
|
||||
.map(x -> AnomalieDTO.error(x.getException()))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
if (anomalie.size() > 0 && !UtilityString.isNullOrEmpty(setup.get("EMAIL_FOR_LOG"))) {
|
||||
MailService mailService = new MailService();
|
||||
mailService.sendErrorMail(multiDBTransactionManager, "CORRISPETTIVI", "SETUP", null, null, null, anomalie);
|
||||
if (!anomalie.isEmpty() && !UtilityString.isNullOrEmpty(setup.get("EMAIL_FOR_LOG"))) {
|
||||
mailService.sendErrorMailByGestNameSection(multiDBTransactionManager, "CORRISPETTIVI", "SETUP", "Impostazione coordinate cliente", null, null, null, anomalie);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user