From 040b2c3817e9d1a635323386f8d96324df2bb3e3 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 5 Sep 2022 14:09:33 +0200 Subject: [PATCH] Bug fixing issues #23676, #23789 --- CHANGELOG.md | 7 ++ pom.xml | 4 +- .../server/util/MimeTypeUtility.java | 67 ++++++------------- .../WsExtensionToMimeTypeMap.properties | 1 + .../WsMimeTypeToExtensionMap.properties | 1 + 5 files changed, 31 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca845d5..74957c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v6.35.2-SNAPSHOT] - 2022-07-27 + +#### Bug fixed + +- [#23676] Fixed - Added extension .txt to ASC files when dowloaded +- [#23789] Fixed - Notebook files (.ipynb) are downloaded with .txt attached. + ## [v6.35.1] - 2022-06-27 - [#23523] Updated to maven-portal-bom 3.6.4 diff --git a/pom.xml b/pom.xml index eab5d0b..4cad3d6 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ org.gcube.portlets.user workspace-tree-widget - 6.35.1 + 6.35.2-SNAPSHOT gCube Workspace Tree Widget gCube Workspace Tree Widget is a widget to navigate and interact with gCube Workspace @@ -46,7 +46,7 @@ org.gcube.distribution maven-portal-bom - 3.6.4 + 3.7.0-SNAPSHOT pom import diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/util/MimeTypeUtility.java b/src/main/java/org/gcube/portlets/user/workspace/server/util/MimeTypeUtility.java index 8fcfd2b..635f6f0 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/util/MimeTypeUtility.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/util/MimeTypeUtility.java @@ -22,7 +22,6 @@ import org.apache.tika.mime.MediaType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - // TODO: Auto-generated Javadoc /** * The Class MimeTypeUtil. @@ -120,7 +119,6 @@ public class MimeTypeUtility { } br.close(); } - /** * Load preview mime types. @@ -169,7 +167,6 @@ public class MimeTypeUtility { * @throws IOException Signals that an I/O exception has occurred. */ public static String getNameWithExtension(String name, String mimeType) throws IOException { - logger.debug("Deriving the file extension for file name: " + name + ", with mimeType: " + mimeType); if (mimeType == null || mimeType.isEmpty()) { @@ -178,52 +175,29 @@ public class MimeTypeUtility { } String declaredExtension = FilenameUtils.getExtension(name); - logger.debug("The name " + name + " contains the extension: " + declaredExtension); + logger.info("The name " + name + " contains the extension: " + declaredExtension); - if (declaredExtension.equals("exe")) + if (declaredExtension != null && !declaredExtension.isEmpty()) { + logger.debug( + "The name contains a not empty extension: " + declaredExtension + ", so returning the name like it is"); return name; - + } + + logger.debug("The name does not contains the extension, deriving it from mimeType"); List extensions = MimeTypeUtility.getExtension(mimeType); - logger.trace("Extension/s available for input mimetype: " + mimeType + " into map is/are: " + extensions); + logger.debug("Extension/s available for input mimetype: " + mimeType + " into map is/are: " + extensions); String toMimeTypeExtension = ""; - if (extensions != null) { - toMimeTypeExtension = extensions.get(extensions.size() - 1); // I'm reading the last extension in the map - // (myme type - list of extensions) - logger.debug("Using the last extension read into list of available extensions: " + toMimeTypeExtension); + String fullName = name; + if (extensions != null && extensions.size() > 0) { + // I'm reading the last extension in the map (myme type - list of extensions) + toMimeTypeExtension = extensions.get(extensions.size() - 1); + logger.info("Using the last extension read into list of available extensions: " + toMimeTypeExtension); + fullName = String.format("%s%s%s", name, DOT_STRING, toMimeTypeExtension); } - - // MANAGING ALREADY DECLARED EXTENSION IN THE FILE NAME - if (!declaredExtension.isEmpty() && !toMimeTypeExtension.isEmpty()) { - String dEextL = declaredExtension.toLowerCase(); - String mtExtL = toMimeTypeExtension.toLowerCase(); - - // The extension writes in the file name is matching the mime type extension - // declared in the map - if (dEextL.equals(mtExtL)) { - logger.trace("The Extension declared in the name " + name - + " is matching derived mime type extension so returning the input name: " + name); - return name; - } - -// if(!dEextL.trim().contains(" ")) { -// logger.trace("The Extension declared in the name "+name+" seems a valid suffix (without other spaces) so returning the input name: "+name); -// return name; -// } - - logger.debug("No logic seems to match the extension declared in the name " + declaredExtension - + " as a valid extension so I'm adding the extension derived from mime type map: " - + toMimeTypeExtension); - } - - // CHECKING THE FOLLOWING IN ORDER TO AVOID THE DOT AS LAST CHAR OF FILENAME - if (toMimeTypeExtension.isEmpty()) { - return name; - } - - String fullname = String.format("%s%s%s", name, DOT_STRING, toMimeTypeExtension); - logger.trace("returning full name:" + fullname); - return fullname; + + logger.info("returning full name:" + fullName); + return fullName; } @@ -314,11 +288,10 @@ public class MimeTypeUtility { public static Map getExtensionToMimeTypeMap() { return extension_mimetype_map; } - - + /** - * Gets the preview mimetype extension map with the - * mime types allowed for preview displaying + * Gets the preview mimetype extension map with the mime types allowed for + * preview displaying * * @return the preview mimetype extension map */ diff --git a/src/main/resources/WsExtensionToMimeTypeMap.properties b/src/main/resources/WsExtensionToMimeTypeMap.properties index f70f355..bc0cd3f 100644 --- a/src/main/resources/WsExtensionToMimeTypeMap.properties +++ b/src/main/resources/WsExtensionToMimeTypeMap.properties @@ -181,6 +181,7 @@ text/iuls=uls text/plain=bas text/plain=c text/plain=h +text/plain=asc text/plain=txt text/richtext=rtx text/scriptlet=sct diff --git a/src/main/resources/WsMimeTypeToExtensionMap.properties b/src/main/resources/WsMimeTypeToExtensionMap.properties index f0ee081..f6eb7a5 100644 --- a/src/main/resources/WsMimeTypeToExtensionMap.properties +++ b/src/main/resources/WsMimeTypeToExtensionMap.properties @@ -149,6 +149,7 @@ text/iuls=uls text/plain=bas text/plain=c text/plain=h +text/plain=asc text/plain=txt text/richtext=rtx text/scriptlet=sct