Task #12489 Migrating delete operation to StorageHub

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@171467 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-09-14 13:42:36 +00:00
parent 21b00a6f9c
commit 93d7d59769
9 changed files with 232 additions and 24 deletions

View File

@ -1,4 +1,10 @@
<ReleaseNotes>
<Changeset component="org.gcube.portlets-user.workspace-portlet-tree.6-22-0"
date="2018-09-14">
<Change>[Task #12489] Migrate delete operation to StorageHub
</Change>
<Change>integrated CLARIN Switchboard with service endpoint query for Switchboard service discovery</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.workspace-portlet-tree.6-21-1"
date="2018-07-02">
<Change>[Task #12089] Migrate to workspace-uploader 2.0

View File

@ -10,7 +10,7 @@
<groupId>org.gcube.portlets.user</groupId>
<artifactId>workspace-tree-widget</artifactId>
<version>6.21.1-SNAPSHOT</version>
<version>6.22.0-SNAPSHOT</version>
<name>gCube Workspace Tree Widget</name>
<description>
gCube Workspace Tree Widget is a widget to navigate and interact with gCube Workspace
@ -237,6 +237,12 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>storagehub-client-wrapper</artifactId>
<version>[0.0.1-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>

View File

@ -1466,7 +1466,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
if(clickedButton.equals(Dialog.YES)){
explorerPanel.getAsycTreePanel().mask("Deleting", ConstantsExplorer.LOADINGSTYLE);
rpcWorkspaceService.removeItem(event.getFileTarget().getIdentifier(), new AsyncCallback<Boolean>(){
rpcWorkspaceService.deleteItem(event.getFileTarget().getIdentifier(), new AsyncCallback<Boolean>(){
@Override
public void onFailure(Throwable caught) {

View File

@ -238,14 +238,15 @@ public interface GWTWorkspaceService extends RemoteService{
*/
public Boolean moveItem(String itemId, String destinationId) throws Exception;
/**
* Removes the item.
* Delete item.
*
* @param itemId the item id
* @return the boolean
* @throws Exception the exception
*/
public Boolean removeItem(String itemId) throws Exception;
public Boolean deleteItem(String itemId) throws Exception;
/**
* Rename item.
@ -788,10 +789,13 @@ public interface GWTWorkspaceService extends RemoteService{
*/
List<GcubeVRE> getListOfVREsForLoggedUser()
throws Exception;
/**
* @param itemId
* @return
* @throws Exception
* Checks if is item under sync.
*
* @param itemId the item id
* @return the boolean
* @throws Exception the exception
*/
Boolean isItemUnderSync(String itemId)
throws Exception;

View File

@ -97,13 +97,14 @@ public interface GWTWorkspaceServiceAsync {
*/
void moveItem(String itemId, String destinationId, AsyncCallback<Boolean> callback);
/**
* Removes the item.
* Delete item.
*
* @param itemId the item id
* @param callback the callback
*/
void removeItem(String itemId, AsyncCallback<Boolean> callback);
void deleteItem(String itemId, AsyncCallback<Boolean> callback);
/**
* Rename item.

View File

@ -50,6 +50,7 @@ import org.gcube.common.homelibrary.home.workspace.trash.WorkspaceTrashItem;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.storagehubwrapper.server.StorageHubWrapper;
import org.gcube.portal.wssynclibrary.shared.ItemNotSynched;
import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked;
import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status;
@ -950,17 +951,10 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
}
/* (non-Javadoc)
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#removeItem(java.lang.String)
*/
/**
* Removes the item.
*
* @param itemId the item id
* @return the boolean
* @throws Exception the exception
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#deleteItem(java.lang.String)
*/
@Override
public Boolean removeItem(String itemId) throws Exception {
public Boolean deleteItem(String itemId) throws Exception {
try {
@ -969,6 +963,28 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
checkItemLocked(itemId);
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
StorageHubWrapper storageHubWrapper = WsUtil.getStorageHubWrapper(this.getThreadLocalRequest(), null, user);
org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem theItem = storageHubWrapper.getWorkspace().getItem(itemId);
boolean sourceItemIsShared = theItem.isShared();
String itemName = theItem.getName();
String sourceFolderSharedId = null;
if(sourceItemIsShared){
org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem rootSharedFolder = storageHubWrapper.getWorkspace().getRootSharedFolder(itemId);
sourceFolderSharedId = rootSharedFolder.getId();
}
//HERE REMOVING THE ITEM
storageHubWrapper.getWorkspace().deleteItem(itemId);
if(sourceFolderSharedId!=null)
NotificationsUtil.checkSendNotifyRemoveItemToShare(this.getThreadLocalRequest(), sourceItemIsShared, itemName, itemId, sourceFolderSharedId);
return Boolean.TRUE;
/*
Workspace workspace = getWorkspace();
workspaceLogger.trace("removeItem item for id: "+itemId);
//NOTIFICATION
@ -987,7 +1003,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
if(sourceFolderSharedId!=null)
NotificationsUtil.checkSendNotifyRemoveItemToShare(this.getThreadLocalRequest(), sourceItemIsShared, itemName, itemId, sourceFolderSharedId);
return Boolean.TRUE;
*/
}catch (WorkspaceFolderLocked e1){
throw new Exception(e1.getMessage());
@ -4438,7 +4456,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
return null;
ServiceEndpoint res = conf.get(0);
//reset the context
ScopeProvider.instance.set(currContext);
ScopeProvider.instance.set(currContext);
return res.profile().runtime().hostedOn();
}

View File

@ -19,6 +19,7 @@ import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.storagehubwrapper.server.StorageHubWrapper;
import org.gcube.portlets.user.urlshortener.UrlShortener;
import org.gcube.portlets.user.workspace.client.model.InfoContactModel;
import org.gcube.portlets.user.workspace.server.GWTWorkspaceBuilder;
@ -412,5 +413,40 @@ public class WsUtil {
return psFolderReader;
}
/**
* Gets the storage hub wrapper.
*
* @param request the request
* @param scopeGroupId the scope group id. If scopeGroupId is null the scope is read by using the request else by using the scopeGroupId
* @param user the user
* @return the storage hub wrapper
* @throws InternalErrorException the internal error exception
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
* @throws Exception the exception
*/
public static StorageHubWrapper getStorageHubWrapper(final HttpServletRequest request, String scopeGroupId, GCubeUser user) throws InternalErrorException, WorkspaceFolderNotFoundException, Exception{
if(user==null || user.getUsername().isEmpty())
throw new Exception("Session expired");
try {
String scope;
PortalContext pContext = PortalContext.getConfiguration();
if(WsUtil.isWithinPortal() && scopeGroupId!=null){
scope = pContext.getCurrentScope(scopeGroupId);
logger.debug(scope+" has retrieved by using the scopeGroupId="+scopeGroupId);
}
else
scope = pContext.getCurrentScope(request);
logger.debug("Instancing "+StorageHubWrapper.class.getSimpleName()+" for user: "+user.getUsername() +", by using the scope: "+scope);
String token = pContext.getCurrentUserToken(scope, user.getUsername());
return new StorageHubWrapper(scope, token);
} catch (Exception e) {
logger.error("Error during getting storageHub wrapper", e);
throw new InternalErrorException("Error on gettig the StorageHub wrapper for userId: "+user);
}
}
}

View File

@ -10,6 +10,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
@ -22,26 +23,46 @@ import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNot
import org.gcube.common.homelibrary.home.workspace.exceptions.WrongDestinationException;
import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile;
import org.gcube.common.homelibrary.util.WorkspaceUtil;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
/**
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Jun 20, 2013
* The Class UploadServletTest.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Jul 23, 2018
*/
public class UploadServletTest {
public static String YOUR_TOKEN = "YOUR TOKEN";
public static String YOUR_USERNAME = "name.surname";
/**
* The main method.
*
* @param args the arguments
* @throws InternalErrorException the internal error exception
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
* @throws HomeNotFoundException the home not found exception
* @throws UserNotFoundException the user not found exception
* @throws InsufficientPrivilegesException the insufficient privileges exception
* @throws ItemAlreadyExistException the item already exist exception
* @throws WrongDestinationException the wrong destination exception
* @throws IOException Signals that an I/O exception has occurred.
*/
public static void main(String[] args) throws InternalErrorException,
WorkspaceFolderNotFoundException, HomeNotFoundException,
UserNotFoundException, InsufficientPrivilegesException,
ItemAlreadyExistException, WrongDestinationException, IOException {
ScopeBean scope = new ScopeBean("/gcube/devsec");
ScopeProvider.instance.set(scope.toString());
SecurityTokenProvider.instance.set("YOUR TOKEN");
Workspace workspace = HomeLibrary.getHomeManagerFactory()
.getHomeManager().getHome("francesco.mangiacrapa")
.getHomeManager().getHome(YOUR_USERNAME)
.getWorkspace();
String filePath = "/home/francesco-mangiacrapa";

View File

@ -0,0 +1,116 @@
/**
*
*/
package org.gcube.portlets.user.workspace;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.common.homelibrary.home.exceptions.UserNotFoundException;
import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
import org.gcube.common.homelibrary.home.workspace.exceptions.InsufficientPrivilegesException;
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemAlreadyExistException;
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
import org.gcube.common.homelibrary.home.workspace.exceptions.WrongDestinationException;
import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile;
import org.gcube.common.homelibrary.util.WorkspaceUtil;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
/**
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Jun 20, 2013
*
*/
public class UploadServletTestToken {
public static void main(String[] args) throws InternalErrorException,
WorkspaceFolderNotFoundException, HomeNotFoundException,
UserNotFoundException, InsufficientPrivilegesException,
ItemAlreadyExistException, WrongDestinationException, IOException {
ScopeBean scope = new ScopeBean("/gcube/devsec");
ScopeProvider.instance.set(scope.toString());
Workspace workspace = HomeLibrary.getHomeManagerFactory()
.getHomeManager().getHome("francesco.mangiacrapa")
.getWorkspace();
String filePath = "/home/francesco-mangiacrapa";
String fileName = "Geo Explorer 2016-01-15 18-51-51.png";
String fullPath = filePath + "/" + fileName;
// String newFilePath =
// "/home/francesco-mangiacrapa/Desktop/icongeoexplorer/testupload.txt";
// String name = "TestReplaceContentImage";
// ExternalPDFFile file = workspace.createExternalPDFFile(name, "",
// null, new FileInputStream(new File(filePath)),
// workspace.getRoot().getId());
WorkspaceFolder root = workspace.getRoot();
// ExternalImage file = (ExternalImage) root.find(name);
// UPLOAD FILE
// String contentType = MimeTypeUtil.getMimeType(fileName, new BufferedInputStream(
// new FileInputStream(new File(fullPath))));
String itemName = WorkspaceUtil.getUniqueName(fileName, root);
System.out.println("Storing data....");
System.out.println("content type " + null);
System.out.println("itemName " + itemName);
ExternalFile file = (ExternalFile) WorkspaceUtil.createExternalFile(
root, itemName, "", null, new FileInputStream(new File(
fullPath)));
System.out.println("Storing data - OK" + "File [id: " + file.getId()
+ ", name: " + file.getName() + "]");
//
// System.out.println("File mimeType" + file.getMimeType());
// System.out.println("File size" + file.getLength());
//
//
// file.setData(new FileInputStream(new File(newFilePath)));
// System.out.println("New File mimeType" + file.getMimeType());
// System.out.println("New File size" + file.getLength());
//
System.out.println("Recovering data");
InputStream inputStream = file.getData();
// write the inputStream to a FileOutputStream
OutputStream out = new FileOutputStream(new File(
"/home/francesco-mangiacrapa/Desktop/download/"+fileName));
int read = 0;
byte[] bytes = new byte[1024];
while ((read = inputStream.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
inputStream.close();
out.flush();
out.close();
System.out.println("Recovering data - OK");
// File file = new File("/home/gioia/Desktop/test");
// InputStream is = new FileInputStream(file);
}
}