diff --git a/.classpath b/.classpath index 0b2b5ba..4f1b985 100644 --- a/.classpath +++ b/.classpath @@ -1,6 +1,6 @@ - + @@ -31,5 +31,5 @@ - + diff --git a/.settings/com.google.gdt.eclipse.core.prefs b/.settings/com.google.gdt.eclipse.core.prefs index c8fe631..acab52a 100644 --- a/.settings/com.google.gdt.eclipse.core.prefs +++ b/.settings/com.google.gdt.eclipse.core.prefs @@ -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 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 335abd2..fb4e233 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -4,9 +4,6 @@ - - uses - diff --git a/pom.xml b/pom.xml index 38b0309..e71e396 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.gcube.portlets.user share-updates war - 1.5.1-SNAPSHOT + 1.5.2-SNAPSHOT gCube Share Updates Portlet diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/client/view/SaveInWorkspaceBox.ui.xml b/src/main/java/org/gcube/portlets/user/shareupdates/client/view/SaveInWorkspaceBox.ui.xml index 66b2e13..7c5bd2f 100644 --- a/src/main/java/org/gcube/portlets/user/shareupdates/client/view/SaveInWorkspaceBox.ui.xml +++ b/src/main/java/org/gcube/portlets/user/shareupdates/client/view/SaveInWorkspaceBox.ui.xml @@ -3,7 +3,7 @@ xmlns:g="urn:import:com.google.gwt.user.client.ui">
- Also save a copy in my Workspace + Also save a copy in the Workspace (group folder)
\ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/server/UploadToWorkspaceThread.java b/src/main/java/org/gcube/portlets/user/shareupdates/server/UploadToWorkspaceThread.java index a1ef463..89a2c5a 100644 --- a/src/main/java/org/gcube/portlets/user/shareupdates/server/UploadToWorkspaceThread.java +++ b/src/main/java/org/gcube/portlets/user/shareupdates/server/UploadToWorkspaceThread.java @@ -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 */ @@ -50,41 +53,39 @@ public class UploadToWorkspaceThread implements Runnable { try { String currScope = ScopeProvider.instance.get(); ScopeProvider.instance.set("/"+PortalContext.getConfiguration().getInfrastructureName()); - + Workspace ws = HomeLibrary .getHomeManagerFactory() .getHomeManager() .getHome(username).getWorkspace(); - + _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); - ScopeProvider.instance.set(currScope); - } + 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()); } } - }