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"?>
<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>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</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>
<attribute name="maven.pomderived" value="true"/>
</attributes>
@ -39,5 +39,5 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</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>

View File

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

View File

@ -13,7 +13,7 @@
<groupId>org.gcube.portlets.user</groupId>
<artifactId>share-updates</artifactId>
<packaging>war</packaging>
<version>2.2.0-SNAPSHOT</version>
<version>2.3.0-SNAPSHOT</version>
<name>gCube Share Updates Portlet</name>
<description>
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.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<String> imagesUrl = new ArrayList<String>();
//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<String> imagesUrl = new ArrayList<String>();
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<String> imagesUrl = new ArrayList<String>();
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;
}

View File

@ -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();
}