implemented shared attachments

git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/share-updates@100301 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2014-09-30 15:58:19 +00:00
parent 4b8a43085b
commit 8fa20329a0
6 changed files with 31 additions and 33 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/share-updates-1.5.1-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<classpathentry kind="src" output="target/share-updates-1.5.2-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
@ -31,5 +31,5 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/share-updates-1.5.1-SNAPSHOT/WEB-INF/classes"/>
<classpathentry kind="output" path="target/share-updates-1.5.2-SNAPSHOT/WEB-INF/classes"/>
</classpath>

View File

@ -1,5 +1,5 @@
eclipse.preferences.version=1
jarsExcludedFromWebInfLib=
lastWarOutDir=/Users/massi/Documents/workspace/share-updates/target/share-updates-1.5.1-SNAPSHOT
lastWarOutDir=/Users/massi/Documents/workspace/share-updates/target/share-updates-1.5.2-SNAPSHOT
warSrcDir=src/main/webapp
warSrcDirIsOutput=false

View File

@ -4,9 +4,6 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/gwt"/>
<dependent-module archiveName="pickuser-widget-0.4.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/pickuser-widget/pickuser-widget">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/>
<property name="context-root" value="share-updates"/>
</wb-module>

View File

@ -13,7 +13,7 @@
<groupId>org.gcube.portlets.user</groupId>
<artifactId>share-updates</artifactId>
<packaging>war</packaging>
<version>1.5.1-SNAPSHOT</version>
<version>1.5.2-SNAPSHOT</version>
<name>gCube Share Updates Portlet</name>
<description>

View File

@ -3,7 +3,7 @@
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<g:HTMLPanel styleName="link-previewer">
<div style="padding-left: 10px;">
<g:CheckBox ui:field="saveCheckBox">Also save a copy in my Workspace</g:CheckBox>
<g:CheckBox ui:field="saveCheckBox">Also save a copy in the Workspace (group folder)</g:CheckBox>
</div>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -3,11 +3,13 @@ package org.gcube.portlets.user.shareupdates.server;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Date;
import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemAlreadyExistException;
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException;
import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
import org.gcube.common.homelibrary.util.WorkspaceUtil;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.scope.api.ScopeProvider;
import org.slf4j.Logger;
@ -20,6 +22,7 @@ import org.slf4j.LoggerFactory;
*/
public class UploadToWorkspaceThread implements Runnable {
private static Logger _log = LoggerFactory.getLogger(UploadToWorkspaceThread.class);
public static final String ATTACHMENT_FOLDER ="Shared attachments";
/**
* the identifier of the workspace you are putting
*/
@ -58,33 +61,31 @@ public class UploadToWorkspaceThread implements Runnable {
_log.info("File to upload="+fileabsolutePathOnServer);
File file = new File(fileabsolutePathOnServer);
String mimeType = FilePreviewer.getMimeType(file, fileName);
InputStream fileData = new FileInputStream(file);
String theId = "";
_log.info("mimeType="+mimeType + " fileData null? " + (fileData == null) );
try {
theId = ws.createExternalFile(fileName ,"File added automatically by Share Updates" , mimeType ,fileData, ws.getRoot().getId()).getId();
_log.info("Trying to get Group folder for scope="+currScope);
WorkspaceFolder folder = ws.getVREFolderByScope(currScope);
WorkspaceFolder attachment = null;
try{
attachment = (WorkspaceFolder) ws.getItemByPath(folder.getPath() + "/" + ATTACHMENT_FOLDER);
} catch (ItemNotFoundException e) {
_log.info(ATTACHMENT_FOLDER + " Workspace Folder does not exists, creating it for "+currScope);
Workspace ownerWS = HomeLibrary
.getHomeManagerFactory()
.getHomeManager()
.getHome(folder.getOwner().getPortalLogin()).getWorkspace();
attachment = ownerWS.createFolder(ATTACHMENT_FOLDER, "Folder created automatically by the System", folder.getId());
}
catch (NullPointerException exn) {
_log.warn("null pointer");
exn.printStackTrace();
}
catch (ItemAlreadyExistException ex) {
_log.warn("fileName " + fileName + " exists, appending timestamp");
theId = ws.createExternalFile(fileName+" ("+ new Date()+")" ,"File added automatically by Share Updates" , mimeType ,fileData, ws.getRoot().getId()).getId();
ex.printStackTrace();
} finally {
fileData.close();
}
fileData.close();
_log.debug("Uploaded " + fileName + " - Returned Workspace id=" + theId);
String itemName = WorkspaceUtil.getUniqueName(fileName,attachment);
FolderItem item = WorkspaceUtil.createExternalFile(attachment, itemName, "File added automatically by Share Updates", null, fileData);
_log.debug("Uploaded " + item.getName() + " - Returned Workspace id=" + item.getId());
ScopeProvider.instance.set(currScope);
}
catch (Exception e) {
e.printStackTrace();
_log.error("Something wrong while uploading " + fileName + " in Workspace " + e.getMessage());
}
}
}