From 75b21e3bee0ea302ad661600129917e3e8e51702 Mon Sep 17 00:00:00 2001 From: Stephen Kraffmiller Date: Fri, 27 Mar 2020 14:01:45 -0400 Subject: [PATCH] #2734 return handling of one-off cases --- .../java/edu/harvard/iq/dataverse/DataFile.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/DataFile.java b/src/main/java/edu/harvard/iq/dataverse/DataFile.java index 90625d8f22b..8c5653d0199 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DataFile.java +++ b/src/main/java/edu/harvard/iq/dataverse/DataFile.java @@ -405,12 +405,24 @@ public String getOriginalFileName() { DataTable dataTable = getDataTable(); if (dataTable != null) { return dataTable.getOriginalFileName() != null ? dataTable.getOriginalFileName() - : getFileMetadata().getLabel().replaceAll(".tab$", FileUtil.generateOriginalExtension(getOriginalFileFormat())); + : getDerivedOriginalFileName(); } } return null; } + + private String getDerivedOriginalFileName() { + FileMetadata fm = getFileMetadata(); + String filename = fm.getLabel(); + String originalExtension = FileUtil.generateOriginalExtension(getOriginalFileFormat()); + String extensionToRemove = StringUtil.substringIncludingLast(filename, "."); + if (StringUtil.nonEmpty(extensionToRemove)) { + return filename.replaceAll(extensionToRemove + "$", originalExtension); + } else{ + return filename + originalExtension ; + } + } @Override public boolean isAncestorOf( DvObject other ) {