restore method added

This commit is contained in:
Lucio Lelii 2020-04-10 13:50:37 +02:00
parent 4135ed017a
commit a2564298d8
4 changed files with 36 additions and 13 deletions

View File

@ -49,7 +49,7 @@ public class StorageHubClient {
return new FolderContainer(itemclient, wsClient.getTrashFolder());
}
public void emptyTrash() {
public void emptyTrash() throws StorageHubException{
wsClient.emptyTrash();
}
@ -61,8 +61,12 @@ public class StorageHubClient {
return wsClient.getTotalItemCount();
}
public GenericItemContainer restoreThrashItem(String itemId) {
return new GenericItemContainer(itemclient, wsClient.restoreFromTrash(itemId));
public GenericItemContainer restoreThrashItem(String trashItemId) throws StorageHubException {
return new GenericItemContainer(itemclient, wsClient.restoreFromTrash(trashItemId, null));
}
public GenericItemContainer restoreThrashItem(String trashItemId, String destinationFolderId) throws StorageHubException {
return new GenericItemContainer(itemclient, wsClient.restoreFromTrash(trashItemId, destinationFolderId));
}
public void createUserAccount(String userId) throws StorageHubException {

View File

@ -5,14 +5,19 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import org.gcube.common.clients.Call;
import org.gcube.common.clients.delegates.ProxyDelegate;
import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest;
import org.gcube.common.gxrest.response.inbound.GXInboundResponse;
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
import org.gcube.common.storagehub.model.expressions.OrderField;
import org.gcube.common.storagehub.model.expressions.SearchableItem;
import org.gcube.common.storagehub.model.items.Item;
@ -246,7 +251,7 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient {
}
@Override
public void emptyTrash() {
public void emptyTrash() throws StorageHubException, BackendGenericError {
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
@Override
public Void call(GXWebTargetAdapterRequest manager) throws Exception {
@ -266,19 +271,28 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient {
};
try {
delegate.make(call);
}catch(Exception e) {
}catch(StorageHubException e) {
throw e;
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
@Override
public String restoreFromTrash(final String id) {
public String restoreFromTrash(String trashedItemid, String destinationFolderId) throws StorageHubException, BackendGenericError{
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
@Override
public String call(GXWebTargetAdapterRequest manager) throws Exception {
Objects.nonNull(trashedItemid);
GXWebTargetAdapterRequest myManager = manager.path("trash").path("restore");
GXInboundResponse response = myManager.put(Entity.text(id));
MultivaluedMap<String, String> formData = new MultivaluedHashMap<String, String>();
formData.add("trashedItemId", trashedItemid);
if (destinationFolderId !=null)
formData.add("destinationId", destinationFolderId);
GXInboundResponse response = myManager.put(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED));
if (response.isErrorResponse()) {
if (response.hasException())
@ -292,7 +306,9 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient {
};
try {
return delegate.make(call);
}catch(Exception e) {
}catch(StorageHubException e) {
throw e;
} catch (Throwable e) {
throw new RuntimeException(e);
}
}

View File

@ -2,6 +2,8 @@ package org.gcube.common.storagehub.client.proxies;
import java.util.List;
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
import org.gcube.common.storagehub.model.expressions.SearchableItem;
import org.gcube.common.storagehub.model.items.Item;
import org.gcube.common.storagehub.model.query.Query;
@ -24,9 +26,9 @@ public interface WorkspaceManagerClient {
List<? extends Item> getRecentModifiedFilePerVre();
String restoreFromTrash(String id);
String restoreFromTrash(String thrashedItemid, String destinationFolderId) throws StorageHubException, BackendGenericError;
void emptyTrash();
void emptyTrash() throws StorageHubException, BackendGenericError;
long getTotalItemCount();

View File

@ -101,10 +101,11 @@ public class TestCall {
}
@Test
public void restore() {
public void restore() throws Exception{
ScopeProvider.instance.set("/gcube");
SecurityTokenProvider.instance.set("b7c80297-e4ed-42ab-ab42-fdc0b8b0eabf-98187548");
WorkspaceManagerClient client = AbstractPlugin.workspace().build();
client.restoreFromTrash("82af9e1c-6cc7-4e16-bba5-9bec6545015a");
System.out.println(client.restoreFromTrash("cd04ff61-e83f-482f-b59e-438c7be7013d", "f3d336cc-cd00-48ba-8339-2bffcbef825e"));
}
@Test