Updated method for using ftp server

git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/share-updates@141594 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2017-01-16 17:22:39 +00:00
parent 08daafe71e
commit a094714ee0
5 changed files with 30 additions and 29 deletions

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" output="target/share-updates-2.2.0-SNAPSHOT/WEB-INF/classes" path="src/main/java"> <classpathentry kind="src" output="target/share-updates-2.3.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes> <attributes>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry excluding="**" kind="src" output="target/share-updates-2.2.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources"> <classpathentry excluding="**" kind="src" output="target/share-updates-2.3.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
@ -39,5 +39,5 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="output" path="target/share-updates-2.2.0-SNAPSHOT/WEB-INF/classes"/> <classpathentry kind="output" path="target/share-updates-2.3.0-SNAPSHOT/WEB-INF/classes"/>
</classpath> </classpath>

View File

@ -1,8 +1,7 @@
<ReleaseNotes> <ReleaseNotes>
<Changeset component="org.gcube.portlets-user.shareupdates.2-2-0" <Changeset component="org.gcube.portlets-user.shareupdates.2-3-0"
date="2016-12-02"> date="2017-01-16">
<Change>Removed asl session dependency</Change> <Change>Updated method for using ftp server</Change>
<Change>Thumbnails are no now stored on ftp server</Change>
</Changeset> </Changeset>
<Changeset component="org.gcube.portlets-user.shareupdates.2-1-0" <Changeset component="org.gcube.portlets-user.shareupdates.2-1-0"
date="2016-09-29"> date="2016-09-29">

View File

@ -13,7 +13,7 @@
<groupId>org.gcube.portlets.user</groupId> <groupId>org.gcube.portlets.user</groupId>
<artifactId>share-updates</artifactId> <artifactId>share-updates</artifactId>
<packaging>war</packaging> <packaging>war</packaging>
<version>2.2.0-SNAPSHOT</version> <version>2.3.0-SNAPSHOT</version>
<name>gCube Share Updates Portlet</name> <name>gCube Share Updates Portlet</name>
<description> <description>
gCube Share Updates for exchanging updates with other users of VREs. gCube Share Updates for exchanging updates with other users of VREs.

View File

@ -37,6 +37,7 @@ import org.apache.tika.io.TikaInputStream;
import org.apache.tika.metadata.Metadata; import org.apache.tika.metadata.Metadata;
import org.apache.tika.mime.MediaType; import org.apache.tika.mime.MediaType;
import org.gcube.applicationsupportlayer.social.storage.FTPManager; import org.gcube.applicationsupportlayer.social.storage.FTPManager;
import org.gcube.common.portal.PortalContext;
import org.gcube.portal.databook.shared.ImageType; import org.gcube.portal.databook.shared.ImageType;
import org.gcube.portlets.user.shareupdates.shared.LinkPreview; import org.gcube.portlets.user.shareupdates.shared.LinkPreview;
import org.slf4j.Logger; 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 final String[] handledextensionImages = {"css", "csv", "doc", "docx", "java", "mdb", "mp3", "pdf", "ppt", "pptx", "psd", "rar", "tex", "txt", "xls", "xlsx", "zip"};
private static FTPManager getFTPManager() { private static FTPManager getFTPManager(String context) {
return FTPManager.getInstance(); return FTPManager.getInstance(context);
} }
/** /**
@ -73,10 +74,11 @@ public class FilePreviewer {
* @param fileNameLabel thename of the file * @param fileNameLabel thename of the file
* @param path2Pdf the path of the pdf file * @param path2Pdf the path of the pdf file
* @param httpUrl the http url where the file is reachable at * @param httpUrl the http url where the file is reachable at
* @param context the current infrastructure context (scope)
* @return * @return
* @throws Exception * @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<String> imagesUrl = new ArrayList<String>(); ArrayList<String> imagesUrl = new ArrayList<String>();
//description //description
String desc = null; String desc = null;
@ -100,7 +102,7 @@ public class FilePreviewer {
raf.close(); raf.close();
_log.error("PDF Parse exception, returning default pdf image"); _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); return new LinkPreview(fileName, desc, httpUrl, mimeType, imagesUrl);
} }
PDFPage page = pdf.getPage(0); PDFPage page = pdf.getPage(0);
@ -127,7 +129,7 @@ public class FilePreviewer {
raf.close(); raf.close();
if (result) { 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); _log.debug("PDF thumbnail available at: " + httpLink);
imagesUrl.add(httpLink); imagesUrl.add(httpLink);
return new LinkPreview(fileName, desc, httpUrl, mimeType, imagesUrl); return new LinkPreview(fileName, desc, httpUrl, mimeType, imagesUrl);
@ -143,7 +145,7 @@ public class FilePreviewer {
* @return * @return
* @throws Exception * @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<String> imagesUrl = new ArrayList<String>(); ArrayList<String> imagesUrl = new ArrayList<String>();
Dimension dim; Dimension dim;
@ -172,7 +174,7 @@ public class FilePreviewer {
catch (IOException e) { catch (IOException e) {
_log.warn("Thumbnail extraction failed for this reason: " + e.getMessage()); _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); _log.debug("\nFlushed, Image thumbnail available at: " + httpLink);
imagesUrl.add(httpLink); imagesUrl.add(httpLink);
return new LinkPreview(fileName, desc, httpUrl, mimeType, imagesUrl); return new LinkPreview(fileName, desc, httpUrl, mimeType, imagesUrl);
@ -208,20 +210,20 @@ public class FilePreviewer {
* @return * @return
* @throws Exception * @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<String> imagesUrl = new ArrayList<String>(); ArrayList<String> imagesUrl = new ArrayList<String>();
String extension = getExtension(fileName); String extension = getExtension(fileName);
//no description //no description
String desc = ""; String desc = "";
if (extension == null) if (extension == null)
imagesUrl.add(getFTPManager().getBaseURL()+GENERICFILE_DEFAULT_IMAGE); imagesUrl.add(getFTPManager(context).getBaseURL()+GENERICFILE_DEFAULT_IMAGE);
else { else {
int foundIndex = Arrays.binarySearch(handledextensionImages, extension); int foundIndex = Arrays.binarySearch(handledextensionImages, extension);
if (foundIndex < 0) if (foundIndex < 0)
imagesUrl.add(getFTPManager().getBaseURL()+GENERICFILE_DEFAULT_IMAGE); imagesUrl.add(getFTPManager(context).getBaseURL()+GENERICFILE_DEFAULT_IMAGE);
else else
imagesUrl.add(getFTPManager().getBaseURL()+"default/"+extension+".png"); imagesUrl.add(getFTPManager(context).getBaseURL()+"default/"+extension+".png");
} }
return new LinkPreview(fileName, desc, httpUrl, mimeType, imagesUrl); return new LinkPreview(fileName, desc, httpUrl, mimeType, imagesUrl);
} }
@ -337,7 +339,7 @@ public class FilePreviewer {
* @param urlThumbnail * @param urlThumbnail
* @return the url of the thumbnail saved on the storage or null in case of error * @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; File localFile;
if((localFile = storeAndGetFile(urlThumbnail)) != null){ if((localFile = storeAndGetFile(urlThumbnail)) != null){
String mimeType = null; String mimeType = null;
@ -352,7 +354,7 @@ public class FilePreviewer {
case "image/jpg": case "image/jpg":
case "image/jpeg": case "image/jpeg":
case "image/bmp": 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; break;
default: break; default: break;
} }

View File

@ -149,7 +149,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
if (urlThumbnail == null) if (urlThumbnail == null)
urlThumbnail = "null"; urlThumbnail = "null";
else else
urlThumbnail = FilePreviewer.saveThumbnailOnFTPAndGetUrl(urlThumbnail); urlThumbnail = FilePreviewer.saveThumbnailOnFTPAndGetUrl(urlThumbnail, context.getCurrentScope(getThreadLocalRequest()));
Date feedDate = new Date(); Date feedDate = new Date();
@ -619,27 +619,27 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
switch (mimeType) { switch (mimeType) {
case "application/pdf": case "application/pdf":
toReturn = FilePreviewer.getPdfPreview(fileName, fileabsolutePathOnServer, httpURL, mimeType); toReturn = FilePreviewer.getPdfPreview(fileName, fileabsolutePathOnServer, httpURL, mimeType, context.getCurrentScope(getThreadLocalRequest()));
break; break;
case "application/vnd.openxmlformats-officedocument.wordprocessingml.document": case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
mimeType = "application/wordprocessor"; 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": case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
mimeType = "application/spreadsheet"; 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": case "application/vnd.openxmlformats-officedocument.presentationml.presentation":
mimeType = "application/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/png":
case "image/gif": case "image/gif":
case "image/tiff": case "image/tiff":
case "image/jpg": case "image/jpg":
case "image/jpeg": case "image/jpeg":
case "image/bmp": case "image/bmp":
toReturn = FilePreviewer.getImagePreview(fileName, fileabsolutePathOnServer, httpURL, mimeType); toReturn = FilePreviewer.getImagePreview(fileName, fileabsolutePathOnServer, httpURL, mimeType, context.getCurrentScope(getThreadLocalRequest()));
break; break;
default: 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"); _log.error("Error while resolving or previewing file");
e.printStackTrace(); e.printStackTrace();
try { 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) { } catch (Exception e1) {
e1.printStackTrace(); e1.printStackTrace();
} }