diff --git a/.classpath b/.classpath index 0c9cd5a..bc09f42 100644 --- a/.classpath +++ b/.classpath @@ -1,12 +1,12 @@ - + - + @@ -39,5 +39,5 @@ - + diff --git a/distro/changelog.xml b/distro/changelog.xml index 7aad0a4..9841a89 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,8 +1,7 @@ - - Removed asl session dependency - Thumbnails are no now stored on ftp server + + Updated method for using ftp server diff --git a/pom.xml b/pom.xml index 757ad6f..f0ba004 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.gcube.portlets.user share-updates war - 2.2.0-SNAPSHOT + 2.3.0-SNAPSHOT gCube Share Updates Portlet gCube Share Updates for exchanging updates with other users of VREs. diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/server/FilePreviewer.java b/src/main/java/org/gcube/portlets/user/shareupdates/server/FilePreviewer.java index 78ed98a..f81e2d4 100644 --- a/src/main/java/org/gcube/portlets/user/shareupdates/server/FilePreviewer.java +++ b/src/main/java/org/gcube/portlets/user/shareupdates/server/FilePreviewer.java @@ -37,6 +37,7 @@ import org.apache.tika.io.TikaInputStream; import org.apache.tika.metadata.Metadata; import org.apache.tika.mime.MediaType; import org.gcube.applicationsupportlayer.social.storage.FTPManager; +import org.gcube.common.portal.PortalContext; import org.gcube.portal.databook.shared.ImageType; import org.gcube.portlets.user.shareupdates.shared.LinkPreview; import org.slf4j.Logger; @@ -64,8 +65,8 @@ public class FilePreviewer { */ private static final String[] handledextensionImages = {"css", "csv", "doc", "docx", "java", "mdb", "mp3", "pdf", "ppt", "pptx", "psd", "rar", "tex", "txt", "xls", "xlsx", "zip"}; - private static FTPManager getFTPManager() { - return FTPManager.getInstance(); + private static FTPManager getFTPManager(String context) { + return FTPManager.getInstance(context); } /** @@ -73,10 +74,11 @@ public class FilePreviewer { * @param fileNameLabel thename of the file * @param path2Pdf the path of the pdf file * @param httpUrl the http url where the file is reachable at + * @param context the current infrastructure context (scope) * @return * @throws Exception */ - protected static LinkPreview getPdfPreview(String fileName, String path2Pdf, String httpUrl, String mimeType) throws Exception { + protected static LinkPreview getPdfPreview(String fileName, String path2Pdf, String httpUrl, String mimeType, String context) throws Exception { ArrayList imagesUrl = new ArrayList(); //description String desc = null; @@ -100,7 +102,7 @@ public class FilePreviewer { raf.close(); _log.error("PDF Parse exception, returning default pdf image"); - imagesUrl.add(getFTPManager().getBaseURL()+PDF_DEFAULT_IMAGE); + imagesUrl.add(getFTPManager(context).getBaseURL()+PDF_DEFAULT_IMAGE); return new LinkPreview(fileName, desc, httpUrl, mimeType, imagesUrl); } PDFPage page = pdf.getPage(0); @@ -127,7 +129,7 @@ public class FilePreviewer { raf.close(); if (result) { - String httpLink = getFTPManager().uploadImageOnFTPServer(new ByteArrayInputStream(out.toByteArray()), ImageType.JPG); + String httpLink = getFTPManager(context).uploadImageOnFTPServer(new ByteArrayInputStream(out.toByteArray()), ImageType.JPG); _log.debug("PDF thumbnail available at: " + httpLink); imagesUrl.add(httpLink); return new LinkPreview(fileName, desc, httpUrl, mimeType, imagesUrl); @@ -143,7 +145,7 @@ public class FilePreviewer { * @return * @throws Exception */ - protected static LinkPreview getImagePreview(String fileName, String path2Image, String httpUrl, String mimeType) { + protected static LinkPreview getImagePreview(String fileName, String path2Image, String httpUrl, String mimeType, String context) { ArrayList imagesUrl = new ArrayList(); Dimension dim; @@ -172,7 +174,7 @@ public class FilePreviewer { catch (IOException e) { _log.warn("Thumbnail extraction failed for this reason: " + e.getMessage()); } - String httpLink = getFTPManager().uploadImageOnFTPServer(new ByteArrayInputStream(out.toByteArray()), ImageType.JPG); + String httpLink = getFTPManager(context).uploadImageOnFTPServer(new ByteArrayInputStream(out.toByteArray()), ImageType.JPG); _log.debug("\nFlushed, Image thumbnail available at: " + httpLink); imagesUrl.add(httpLink); return new LinkPreview(fileName, desc, httpUrl, mimeType, imagesUrl); @@ -208,20 +210,20 @@ public class FilePreviewer { * @return * @throws Exception */ - protected static LinkPreview getUnhandledTypePreview(String fileName, String path2Pdf, String httpUrl, String mimeType) throws Exception { + protected static LinkPreview getUnhandledTypePreview(String fileName, String path2Pdf, String httpUrl, String mimeType, String context) throws Exception { ArrayList imagesUrl = new ArrayList(); String extension = getExtension(fileName); //no description String desc = ""; if (extension == null) - imagesUrl.add(getFTPManager().getBaseURL()+GENERICFILE_DEFAULT_IMAGE); + imagesUrl.add(getFTPManager(context).getBaseURL()+GENERICFILE_DEFAULT_IMAGE); else { int foundIndex = Arrays.binarySearch(handledextensionImages, extension); if (foundIndex < 0) - imagesUrl.add(getFTPManager().getBaseURL()+GENERICFILE_DEFAULT_IMAGE); + imagesUrl.add(getFTPManager(context).getBaseURL()+GENERICFILE_DEFAULT_IMAGE); else - imagesUrl.add(getFTPManager().getBaseURL()+"default/"+extension+".png"); + imagesUrl.add(getFTPManager(context).getBaseURL()+"default/"+extension+".png"); } return new LinkPreview(fileName, desc, httpUrl, mimeType, imagesUrl); } @@ -337,7 +339,7 @@ public class FilePreviewer { * @param urlThumbnail * @return the url of the thumbnail saved on the storage or null in case of error */ - public static String saveThumbnailOnFTPAndGetUrl(String urlThumbnail) { + public static String saveThumbnailOnFTPAndGetUrl(String urlThumbnail, String context) { File localFile; if((localFile = storeAndGetFile(urlThumbnail)) != null){ String mimeType = null; @@ -352,7 +354,7 @@ public class FilePreviewer { case "image/jpg": case "image/jpeg": case "image/bmp": - thumbnailUrlFTP = FilePreviewer.getImagePreview(localFile.getName(), localFile.getAbsolutePath(), null, mimeType).getImageUrls().get(0); + thumbnailUrlFTP = FilePreviewer.getImagePreview(localFile.getName(), localFile.getAbsolutePath(), null, mimeType, context).getImageUrls().get(0); break; default: break; } diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java b/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java index b5210af..17b1341 100644 --- a/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java @@ -149,7 +149,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar if (urlThumbnail == null) urlThumbnail = "null"; else - urlThumbnail = FilePreviewer.saveThumbnailOnFTPAndGetUrl(urlThumbnail); + urlThumbnail = FilePreviewer.saveThumbnailOnFTPAndGetUrl(urlThumbnail, context.getCurrentScope(getThreadLocalRequest())); Date feedDate = new Date(); @@ -619,27 +619,27 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar switch (mimeType) { case "application/pdf": - toReturn = FilePreviewer.getPdfPreview(fileName, fileabsolutePathOnServer, httpURL, mimeType); + toReturn = FilePreviewer.getPdfPreview(fileName, fileabsolutePathOnServer, httpURL, mimeType, context.getCurrentScope(getThreadLocalRequest())); break; case "application/vnd.openxmlformats-officedocument.wordprocessingml.document": mimeType = "application/wordprocessor"; - return FilePreviewer.getUnhandledTypePreview(fileName, fileabsolutePathOnServer, httpURL, mimeType); + return FilePreviewer.getUnhandledTypePreview(fileName, fileabsolutePathOnServer, httpURL, mimeType, context.getCurrentScope(getThreadLocalRequest())); case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": mimeType = "application/spreadsheet"; - return FilePreviewer.getUnhandledTypePreview(fileName, fileabsolutePathOnServer, httpURL, mimeType); + return FilePreviewer.getUnhandledTypePreview(fileName, fileabsolutePathOnServer, httpURL, mimeType, context.getCurrentScope(getThreadLocalRequest())); case "application/vnd.openxmlformats-officedocument.presentationml.presentation": mimeType = "application/presentation"; - return FilePreviewer.getUnhandledTypePreview(fileName, fileabsolutePathOnServer, httpURL, mimeType); + return FilePreviewer.getUnhandledTypePreview(fileName, fileabsolutePathOnServer, httpURL, mimeType, context.getCurrentScope(getThreadLocalRequest())); case "image/png": case "image/gif": case "image/tiff": case "image/jpg": case "image/jpeg": case "image/bmp": - toReturn = FilePreviewer.getImagePreview(fileName, fileabsolutePathOnServer, httpURL, mimeType); + toReturn = FilePreviewer.getImagePreview(fileName, fileabsolutePathOnServer, httpURL, mimeType, context.getCurrentScope(getThreadLocalRequest())); break; default: - return FilePreviewer.getUnhandledTypePreview(fileName, fileabsolutePathOnServer, httpURL, mimeType); + return FilePreviewer.getUnhandledTypePreview(fileName, fileabsolutePathOnServer, httpURL, mimeType, context.getCurrentScope(getThreadLocalRequest())); } @@ -647,7 +647,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar _log.error("Error while resolving or previewing file"); e.printStackTrace(); try { - return FilePreviewer.getUnhandledTypePreview(fileName, fileabsolutePathOnServer, httpURL, "Error During upload on Server!"); + return FilePreviewer.getUnhandledTypePreview(fileName, fileabsolutePathOnServer, httpURL, "Error During upload on Server!", context.getCurrentScope(getThreadLocalRequest())); } catch (Exception e1) { e1.printStackTrace(); }