Cargosoft Export - Maximale Dateigröße 10MB

This commit is contained in:
Ralph Soika 2021-10-14 11:49:01 +02:00
parent 042adcdb66
commit a982612190
2 changed files with 29 additions and 1 deletions

View file

@ -50,6 +50,10 @@ public class CargosoftExportAdapter implements SignalAdapter {
public static final String REPORT_ERROR = "REPORT_ERROR"; public static final String REPORT_ERROR = "REPORT_ERROR";
public static final String CONFIG_ERROR = "CONFIG_ERROR"; public static final String CONFIG_ERROR = "CONFIG_ERROR";
@Inject
@ConfigProperty(name = FTPConnector.ENV_EXPORT_FTP_MAX_ATTACHMENT_SIZED, defaultValue = "10485760")
long maxAttachmentSize;
private static Logger logger = Logger.getLogger(CargosoftExportAdapter.class.getName()); private static Logger logger = Logger.getLogger(CargosoftExportAdapter.class.getName());
@Inject @Inject
@ -123,6 +127,11 @@ public class CargosoftExportAdapter implements SignalAdapter {
/** /**
* This method lookups the origin snapshot data and add the content of the $file * This method lookups the origin snapshot data and add the content of the $file
* to the export document * to the export document
* <p>
* Change 14.10.2021 - Wir senden maximal 5MB and Daten, da die Cargosoft
* Schnittstelle größere Datensätze mit großen Dateianhängen einfach verschluckt
* ohne eine Fehlermeldugn zu liefern.
*
* *
* @param document * @param document
* @return * @return
@ -150,8 +159,25 @@ public class CargosoftExportAdapter implements SignalAdapter {
List<FileData> fileDataList = snapshot.getFileData(); List<FileData> fileDataList = snapshot.getFileData();
// transfer origin file content // transfer origin file content
result.removeItem("$file"); result.removeItem("$file");
long currentAttachmentSize = 0;
// we do only accept .pdf files and a maximum size of 10MB
for (FileData filedata : fileDataList) { for (FileData filedata : fileDataList) {
if (filedata.getName().toLowerCase().endsWith(".pdf")) {
// test if the size of the file is below the
// "cargosoft.export.ftp.maxattachmentsize"
if ((currentAttachmentSize + filedata.getContent().length) > maxAttachmentSize) {
long maxSizeInMB = maxAttachmentSize / 1024 / 1024;
String message = "Attachment '" + filedata.getName()
+ "' can not be exported to cargosoft - max file size exeeded (" + maxSizeInMB
+ "MB)!";
logger.warning(message);
// add comment
document.setItemValue("txtComment", message);
} else {
result.addFileData(filedata); result.addFileData(filedata);
currentAttachmentSize = currentAttachmentSize + filedata.getContent().length;
}
}
} }
} else { } else {
logger.warning("...did not found snapshot for origin workitem " + origin.getUniqueID()); logger.warning("...did not found snapshot for origin workitem " + origin.getUniqueID());

View file

@ -59,6 +59,8 @@ public class FTPConnector {
public static final String ENV_EXPORT_FTP_USER = "cargosoft.export.ftp.user"; public static final String ENV_EXPORT_FTP_USER = "cargosoft.export.ftp.user";
public static final String ENV_EXPORT_FTP_PASSWORD = "cargosoft.export.ftp.password"; public static final String ENV_EXPORT_FTP_PASSWORD = "cargosoft.export.ftp.password";
public static final String ENV_EXPORT_FTP_MAX_ATTACHMENT_SIZED = "cargosoft.export.ftp.maxattachmentsize";
private static Logger logger = Logger.getLogger(FTPConnector.class.getName()); private static Logger logger = Logger.getLogger(FTPConnector.class.getName());
@Inject @Inject