Added copy and move operations
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/storagehub-client-wrapper@171955 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
4381b1b704
commit
8926b422fa
|
@ -5,6 +5,8 @@
|
|||
<Change>[Task #12533] added trash operations</Change>
|
||||
<Change>[Task #12556] added download facility</Change>
|
||||
<Change>[Task #12601] added download folder facility</Change>
|
||||
<Change>[Task #12604] Migrate Move operation to StorageHub</Change>
|
||||
<Change>[Task #12603] Migrate Copy operation to StorageHub</Change>
|
||||
</Changeset>
|
||||
<Changeset component="org.gcube.common.storagehubwrapper.0-1-0"
|
||||
date="2018-06-20">
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
|||
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
|
||||
import org.gcube.common.storagehub.model.acls.ACL;
|
||||
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
||||
import org.gcube.common.storagehub.model.items.FolderItem;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
import org.gcube.common.storagehub.model.items.SharedFolder;
|
||||
|
@ -138,6 +139,19 @@ public class StorageHubClientService {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the folder container.
|
||||
*
|
||||
* @param itemId the item id
|
||||
* @return the folder container
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public FolderContainer getFolderContainer(String itemId) throws Exception{
|
||||
setContextProviders(scope, authorizationToken);
|
||||
return shcClient.open(itemId).asFolder();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the parents.
|
||||
*
|
||||
|
@ -430,7 +444,7 @@ public class StorageHubClientService {
|
|||
*/
|
||||
public void deleteItemById(String itemId) throws Exception{
|
||||
|
||||
Validate.notNull(itemId, "Bad invoking operation the "+itemId+" is null");
|
||||
Validate.notNull(itemId, "Bad invoking operation the itemId is null");
|
||||
shcClient.open(itemId).asItem().delete();
|
||||
|
||||
}
|
||||
|
@ -472,7 +486,7 @@ public class StorageHubClientService {
|
|||
*/
|
||||
public Item restoreThrashItem(String itemId) throws Exception{
|
||||
|
||||
Validate.notNull(itemId, "Bad invoking restore trash item the "+itemId+" is null");
|
||||
Validate.notNull(itemId, "Bad invoking restore trash item the item Id is null");
|
||||
|
||||
GenericItemContainer container = shcClient.restoreThrashItem(itemId);
|
||||
|
||||
|
@ -488,6 +502,44 @@ public class StorageHubClientService {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Move item.
|
||||
*
|
||||
* @param itemId the move item id
|
||||
* @param destFolderContainer the dest folder container
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public void moveItem(String itemId, FolderContainer destFolderContainer) throws Exception{
|
||||
|
||||
Validate.notNull(itemId, "Bad invoking move file, the itemId is null");
|
||||
Validate.notNull(destFolderContainer, "Bad invoking move file, the itemId is null");
|
||||
|
||||
shcClient.open(itemId).asItem().move(destFolderContainer);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy item.
|
||||
*
|
||||
* @param fileItemId the copy item id
|
||||
* @param destFolderContainer the dest folder container
|
||||
* @param newFileName the new file name
|
||||
* @return the abstract file item
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public AbstractFileItem copyFileItem(String fileItemId, FolderContainer destFolderContainer, String newFileName) throws Exception{
|
||||
|
||||
Validate.notNull(fileItemId, "Bad invoking copy file, the fileItemId is null");
|
||||
Validate.notNull(destFolderContainer, "Bad invoking copy file, the destFolderContainer is null");
|
||||
|
||||
FileContainer copyingItem = shcClient.open(fileItemId).asFile();
|
||||
String newName = newFileName!=null && !newFileName.isEmpty()?newFileName:"Copy of "+copyingItem.get().getName();
|
||||
FileContainer newItem = copyingItem.copy(destFolderContainer, newName);
|
||||
return newItem.get();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
|
|
|
@ -12,6 +12,8 @@ import java.util.Map;
|
|||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.gcube.common.storagehub.client.StreamDescriptor;
|
||||
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
||||
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
||||
import org.gcube.common.storagehub.model.items.FolderItem;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
import org.gcube.common.storagehub.model.types.GenericItemType;
|
||||
|
@ -678,6 +680,89 @@ public final class WorkspaceStorageHubClientService implements Workspace{
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Move items.
|
||||
*
|
||||
* @param itemIds the item ids
|
||||
* @param folderDestinationId the folder destination id
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public void moveItems(List<String> itemIds, String folderDestinationId) throws Exception{
|
||||
|
||||
FolderContainer destFolderContainer = null;
|
||||
|
||||
try {
|
||||
|
||||
if(itemIds==null || itemIds.size()==0)
|
||||
throw new Exception("Input list of id for moving is null or empty");
|
||||
|
||||
Validate.notNull(folderDestinationId,"The folderDestinationId is null");
|
||||
|
||||
destFolderContainer = storageHubClientService.getFolderContainer(folderDestinationId);
|
||||
|
||||
for (String itemId : itemIds) {
|
||||
|
||||
try{
|
||||
storageHubClientService.moveItem(itemId, destFolderContainer);
|
||||
}catch(Exception e){
|
||||
logger.error("Error on moving the item with id: "+itemId+ " in the folder id: "+destFolderContainer.get().getId(), e);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Error on moving item/items in the folder with id: "+folderDestinationId, e);
|
||||
String error = e.getMessage()!=null?e.getMessage():"";
|
||||
throw new Exception("Error on moving item/s. "+error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy file items.
|
||||
*
|
||||
* @param itemIds the item ids
|
||||
* @param folderDestinationId the folder destination id
|
||||
* @return the list
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public List<WorkspaceItem> copyFileItems(List<String> itemIds, String folderDestinationId) throws Exception{
|
||||
|
||||
|
||||
FolderContainer destFolderContainer = null;
|
||||
|
||||
try {
|
||||
|
||||
if(itemIds==null || itemIds.size()==0)
|
||||
throw new Exception("Input list of id for copying is null or empty");
|
||||
|
||||
Validate.notNull(folderDestinationId,"The folderDestinationId is null");
|
||||
|
||||
destFolderContainer = storageHubClientService.getFolderContainer(folderDestinationId);
|
||||
|
||||
List<WorkspaceItem> toReturnItems = new ArrayList<WorkspaceItem>(itemIds.size());
|
||||
|
||||
for (String itemId : itemIds) {
|
||||
|
||||
try{
|
||||
AbstractFileItem toReturnItem = storageHubClientService.copyFileItem(itemId, destFolderContainer, null);
|
||||
toReturnItems.add(HLMapper.toWorkspaceItem(toReturnItem));
|
||||
}catch(Exception e){
|
||||
logger.error("Error on copying the item with id: "+itemId+ " in the folder id: "+destFolderContainer.get().getId(), e);
|
||||
}
|
||||
}
|
||||
|
||||
return toReturnItems;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Error on copying item/items in the folder with id: "+folderDestinationId, e);
|
||||
String error = e.getMessage()!=null?e.getMessage():"";
|
||||
throw new Exception("Error on copying item/s. "+error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue