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:
parent
21b00a6f9c
commit
93d7d59769
|
@ -1,4 +1,10 @@
|
||||||
<ReleaseNotes>
|
<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"
|
<Changeset component="org.gcube.portlets-user.workspace-portlet-tree.6-21-1"
|
||||||
date="2018-07-02">
|
date="2018-07-02">
|
||||||
<Change>[Task #12089] Migrate to workspace-uploader 2.0
|
<Change>[Task #12089] Migrate to workspace-uploader 2.0
|
||||||
|
|
8
pom.xml
8
pom.xml
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
<groupId>org.gcube.portlets.user</groupId>
|
<groupId>org.gcube.portlets.user</groupId>
|
||||||
<artifactId>workspace-tree-widget</artifactId>
|
<artifactId>workspace-tree-widget</artifactId>
|
||||||
<version>6.21.1-SNAPSHOT</version>
|
<version>6.22.0-SNAPSHOT</version>
|
||||||
<name>gCube Workspace Tree Widget</name>
|
<name>gCube Workspace Tree Widget</name>
|
||||||
<description>
|
<description>
|
||||||
gCube Workspace Tree Widget is a widget to navigate and interact with gCube Workspace
|
gCube Workspace Tree Widget is a widget to navigate and interact with gCube Workspace
|
||||||
|
@ -237,6 +237,12 @@
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.common</groupId>
|
||||||
|
<artifactId>storagehub-client-wrapper</artifactId>
|
||||||
|
<version>[0.0.1-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-fileupload</groupId>
|
<groupId>commons-fileupload</groupId>
|
||||||
<artifactId>commons-fileupload</artifactId>
|
<artifactId>commons-fileupload</artifactId>
|
||||||
|
|
|
@ -1466,7 +1466,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
if(clickedButton.equals(Dialog.YES)){
|
if(clickedButton.equals(Dialog.YES)){
|
||||||
|
|
||||||
explorerPanel.getAsycTreePanel().mask("Deleting", ConstantsExplorer.LOADINGSTYLE);
|
explorerPanel.getAsycTreePanel().mask("Deleting", ConstantsExplorer.LOADINGSTYLE);
|
||||||
rpcWorkspaceService.removeItem(event.getFileTarget().getIdentifier(), new AsyncCallback<Boolean>(){
|
rpcWorkspaceService.deleteItem(event.getFileTarget().getIdentifier(), new AsyncCallback<Boolean>(){
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Throwable caught) {
|
public void onFailure(Throwable caught) {
|
||||||
|
|
|
@ -238,14 +238,15 @@ public interface GWTWorkspaceService extends RemoteService{
|
||||||
*/
|
*/
|
||||||
public Boolean moveItem(String itemId, String destinationId) throws Exception;
|
public Boolean moveItem(String itemId, String destinationId) throws Exception;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the item.
|
* Delete item.
|
||||||
*
|
*
|
||||||
* @param itemId the item id
|
* @param itemId the item id
|
||||||
* @return the boolean
|
* @return the boolean
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
public Boolean removeItem(String itemId) throws Exception;
|
public Boolean deleteItem(String itemId) throws Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rename item.
|
* Rename item.
|
||||||
|
@ -788,10 +789,13 @@ public interface GWTWorkspaceService extends RemoteService{
|
||||||
*/
|
*/
|
||||||
List<GcubeVRE> getListOfVREsForLoggedUser()
|
List<GcubeVRE> getListOfVREsForLoggedUser()
|
||||||
throws Exception;
|
throws Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param itemId
|
* Checks if is item under sync.
|
||||||
* @return
|
*
|
||||||
* @throws Exception
|
* @param itemId the item id
|
||||||
|
* @return the boolean
|
||||||
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
Boolean isItemUnderSync(String itemId)
|
Boolean isItemUnderSync(String itemId)
|
||||||
throws Exception;
|
throws Exception;
|
||||||
|
|
|
@ -97,13 +97,14 @@ public interface GWTWorkspaceServiceAsync {
|
||||||
*/
|
*/
|
||||||
void moveItem(String itemId, String destinationId, AsyncCallback<Boolean> callback);
|
void moveItem(String itemId, String destinationId, AsyncCallback<Boolean> callback);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the item.
|
* Delete item.
|
||||||
*
|
*
|
||||||
* @param itemId the item id
|
* @param itemId the item id
|
||||||
* @param callback the callback
|
* @param callback the callback
|
||||||
*/
|
*/
|
||||||
void removeItem(String itemId, AsyncCallback<Boolean> callback);
|
void deleteItem(String itemId, AsyncCallback<Boolean> callback);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rename item.
|
* Rename item.
|
||||||
|
|
|
@ -50,6 +50,7 @@ import org.gcube.common.homelibrary.home.workspace.trash.WorkspaceTrashItem;
|
||||||
import org.gcube.common.portal.PortalContext;
|
import org.gcube.common.portal.PortalContext;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
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.ItemNotSynched;
|
||||||
import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked;
|
import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked;
|
||||||
import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status;
|
import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status;
|
||||||
|
@ -950,17 +951,10 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#removeItem(java.lang.String)
|
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#deleteItem(java.lang.String)
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Removes the item.
|
|
||||||
*
|
|
||||||
* @param itemId the item id
|
|
||||||
* @return the boolean
|
|
||||||
* @throws Exception the exception
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Boolean removeItem(String itemId) throws Exception {
|
public Boolean deleteItem(String itemId) throws Exception {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
@ -969,6 +963,28 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
||||||
|
|
||||||
checkItemLocked(itemId);
|
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();
|
Workspace workspace = getWorkspace();
|
||||||
workspaceLogger.trace("removeItem item for id: "+itemId);
|
workspaceLogger.trace("removeItem item for id: "+itemId);
|
||||||
//NOTIFICATION
|
//NOTIFICATION
|
||||||
|
@ -987,7 +1003,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
||||||
if(sourceFolderSharedId!=null)
|
if(sourceFolderSharedId!=null)
|
||||||
NotificationsUtil.checkSendNotifyRemoveItemToShare(this.getThreadLocalRequest(), sourceItemIsShared, itemName, itemId, sourceFolderSharedId);
|
NotificationsUtil.checkSendNotifyRemoveItemToShare(this.getThreadLocalRequest(), sourceItemIsShared, itemName, itemId, sourceFolderSharedId);
|
||||||
|
|
||||||
|
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
|
*/
|
||||||
|
|
||||||
}catch (WorkspaceFolderLocked e1){
|
}catch (WorkspaceFolderLocked e1){
|
||||||
throw new Exception(e1.getMessage());
|
throw new Exception(e1.getMessage());
|
||||||
|
|
|
@ -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.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
|
||||||
import org.gcube.common.portal.PortalContext;
|
import org.gcube.common.portal.PortalContext;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
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.urlshortener.UrlShortener;
|
||||||
import org.gcube.portlets.user.workspace.client.model.InfoContactModel;
|
import org.gcube.portlets.user.workspace.client.model.InfoContactModel;
|
||||||
import org.gcube.portlets.user.workspace.server.GWTWorkspaceBuilder;
|
import org.gcube.portlets.user.workspace.server.GWTWorkspaceBuilder;
|
||||||
|
@ -412,5 +413,40 @@ public class WsUtil {
|
||||||
return psFolderReader;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
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.HomeLibrary;
|
||||||
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
||||||
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
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.exceptions.WrongDestinationException;
|
||||||
import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile;
|
import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile;
|
||||||
import org.gcube.common.homelibrary.util.WorkspaceUtil;
|
import org.gcube.common.homelibrary.util.WorkspaceUtil;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
|
||||||
import org.gcube.common.scope.impl.ScopeBean;
|
import org.gcube.common.scope.impl.ScopeBean;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
* The Class UploadServletTest.
|
||||||
* @Jun 20, 2013
|
|
||||||
*
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||||
|
* Jul 23, 2018
|
||||||
*/
|
*/
|
||||||
public class UploadServletTest {
|
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,
|
public static void main(String[] args) throws InternalErrorException,
|
||||||
WorkspaceFolderNotFoundException, HomeNotFoundException,
|
WorkspaceFolderNotFoundException, HomeNotFoundException,
|
||||||
UserNotFoundException, InsufficientPrivilegesException,
|
UserNotFoundException, InsufficientPrivilegesException,
|
||||||
ItemAlreadyExistException, WrongDestinationException, IOException {
|
ItemAlreadyExistException, WrongDestinationException, IOException {
|
||||||
|
|
||||||
ScopeBean scope = new ScopeBean("/gcube/devsec");
|
ScopeBean scope = new ScopeBean("/gcube/devsec");
|
||||||
ScopeProvider.instance.set(scope.toString());
|
|
||||||
|
|
||||||
|
SecurityTokenProvider.instance.set("YOUR TOKEN");
|
||||||
|
|
||||||
Workspace workspace = HomeLibrary.getHomeManagerFactory()
|
Workspace workspace = HomeLibrary.getHomeManagerFactory()
|
||||||
.getHomeManager().getHome("francesco.mangiacrapa")
|
.getHomeManager().getHome(YOUR_USERNAME)
|
||||||
.getWorkspace();
|
.getWorkspace();
|
||||||
|
|
||||||
String filePath = "/home/francesco-mangiacrapa";
|
String filePath = "/home/francesco-mangiacrapa";
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue