diff --git a/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultItemManager.java b/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultItemManager.java index 9f47751..794b869 100644 --- a/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultItemManager.java +++ b/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultItemManager.java @@ -54,8 +54,12 @@ public class DefaultItemManager implements ItemManagerClient { GXInboundResponse response = myManager.queryParams(params).get(); - if (response.hasGXError()) - throw response.getException(); + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else + throw new BackendGenericError(); + } ItemList items = response.getSource().readEntity(ItemList.class); @@ -91,8 +95,12 @@ public class DefaultItemManager implements ItemManagerClient { GXInboundResponse response = myManager.queryParams(params).get(); - if (response.hasGXError()) - throw response.getException(); + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else + throw new BackendGenericError(); + } ItemList items = response.getSource().readEntity(ItemList.class); @@ -133,8 +141,12 @@ public class DefaultItemManager implements ItemManagerClient { GXInboundResponse response = myManager.queryParams(params).get(); - if (response.hasGXError()) - throw response.getException(); + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else + throw new BackendGenericError(); + } return response.getSource().readEntity(Integer.class); } @@ -172,8 +184,12 @@ public class DefaultItemManager implements ItemManagerClient { GXInboundResponse response = myManager.queryParams(params).get(); - if (response.hasGXError()) - throw response.getException(); + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else + throw new BackendGenericError(); + } Response resp = response.getSource(); @@ -205,8 +221,12 @@ public class DefaultItemManager implements ItemManagerClient { GXInboundResponse response = myManager.queryParams(params).get(); - if (response.hasGXError()) - throw response.getException(); + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else + throw new BackendGenericError(); + } ItemWrapper item = response.getSource().readEntity(ItemWrapper.class); @@ -230,8 +250,12 @@ public class DefaultItemManager implements ItemManagerClient { GXWebTargetAdapterRequest myManager = manager.path(id).path("rootSharedFolder"); GXInboundResponse response = myManager.get(); - if (response.hasGXError()) - throw response.getException(); + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else + throw new BackendGenericError(); + } ItemWrapper item = response.getSource().readEntity(ItemWrapper.class); @@ -256,8 +280,12 @@ public class DefaultItemManager implements ItemManagerClient { GXWebTargetAdapterRequest myManager = manager.path(id).path("publiclink"); GXInboundResponse response = myManager.get(); - if (response.hasGXError()) - throw response.getException(); + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else + throw new BackendGenericError(); + } URL item = response.getSource().readEntity(URL.class); @@ -285,8 +313,12 @@ public class DefaultItemManager implements ItemManagerClient { GXInboundResponse response = myManager.queryParams(params).get(); - if (response.hasGXError()) - throw response.getException(); + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else + throw new BackendGenericError(); + } ItemList items = response.getSource().readEntity(ItemList.class); @@ -318,8 +350,12 @@ public class DefaultItemManager implements ItemManagerClient { GXInboundResponse response = myManager.post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA)); - if (response.hasGXError()) - throw response.getException(); + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else + throw new BackendGenericError(); + } return response.getSource().readEntity(String.class); } @@ -345,8 +381,12 @@ public class DefaultItemManager implements ItemManagerClient { GXInboundResponse response = myManager.post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA_TYPE)); - if (response.hasGXError()) - throw response.getException(); + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else + throw new BackendGenericError(); + } return response.getSource().readEntity(String.class); @@ -376,10 +416,12 @@ public class DefaultItemManager implements ItemManagerClient { GXInboundResponse response = myManager.post(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED)); - if (response.hasGXError() || response.hasException()) - throw response.getException(); - if (response.hasErrorCode()) - throw new BackendGenericError(); + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else + throw new BackendGenericError(); + } return response.getSource().readEntity(String.class); } @@ -407,8 +449,12 @@ public class DefaultItemManager implements ItemManagerClient { GXInboundResponse response = myManager.put(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA_TYPE)); - if (response.hasGXError()) - throw response.getException(); + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else + throw new BackendGenericError(); + } return response.getSource().readEntity(String.class); } @@ -433,8 +479,12 @@ public class DefaultItemManager implements ItemManagerClient { multipart.field("users", users, MediaType.APPLICATION_JSON_TYPE); GXInboundResponse response = myManager.put(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA_TYPE)); - if (response.hasGXError()) - throw response.getException(); + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else + throw new BackendGenericError(); + } return response.getSource().readEntity(String.class); } @@ -455,8 +505,13 @@ public class DefaultItemManager implements ItemManagerClient { GXWebTargetAdapterRequest myManager = manager.path(id); GXInboundResponse response = myManager.delete(); - if (response.hasGXError()) - throw response.getException(); + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else + throw new BackendGenericError(); + } + return null; } }; @@ -480,8 +535,12 @@ public class DefaultItemManager implements ItemManagerClient { GXInboundResponse response = myManager.queryParams(params).get(); - if (response.hasGXError()) - throw response.getException(); + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else + throw new BackendGenericError(); + } return response.getSource().readEntity(ItemList.class); } @@ -502,8 +561,12 @@ public class DefaultItemManager implements ItemManagerClient { GXWebTargetAdapterRequest myManager = manager.path(id).path("acls"); GXInboundResponse response = myManager.get(); - if (response.hasGXError()) - throw response.getException(); + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else + throw new BackendGenericError(); + } return response.getSource().readEntity(ACLList.class); } @@ -531,8 +594,12 @@ public class DefaultItemManager implements ItemManagerClient { GXInboundResponse response = myManager.post(Entity.form(formData)); - if (response.hasGXError()) - throw response.getException(); + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else + throw new BackendGenericError(); + } return response.getSource().readEntity(String.class); } diff --git a/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultWorkspaceManager.java b/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultWorkspaceManager.java index cdb904f..b19d778 100644 --- a/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultWorkspaceManager.java +++ b/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultWorkspaceManager.java @@ -12,6 +12,7 @@ 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.expressions.OrderField; import org.gcube.common.storagehub.model.expressions.SearchableItem; import org.gcube.common.storagehub.model.items.Item; @@ -44,8 +45,12 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient { GXInboundResponse response = myManager.queryParams(params).get(); - if (response.hasGXError()) - throw response.getException(); + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else + throw new BackendGenericError(); + } return response.getSource().readEntity(ItemWrapper.class); } @@ -95,8 +100,13 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient { GXInboundResponse response = myManager.queryParams(params).get(); - if (response.hasGXError()) - throw response.getException(); + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else + throw new BackendGenericError(); + } + return response.getSource().readEntity(ItemList.class); } }; @@ -124,8 +134,14 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient { GXInboundResponse response = myManager.queryParams(params).get(); - if (response.hasGXError()) - throw response.getException(); + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else + throw new BackendGenericError(); + } + + return response.getSource().readEntity(ItemList.class); } @@ -150,8 +166,14 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient { params.put("exclude",excludeNodes); GXInboundResponse response = myManager.queryParams(params).get(); - if (response.hasGXError()) - throw response.getException(); + + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else + throw new BackendGenericError(); + } + return response.getSource().readEntity(ItemWrapper.class); } }; @@ -172,8 +194,14 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient { GXInboundResponse response = myManager.get(); - if (response.hasGXError()) - throw response.getException(); + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else + throw new BackendGenericError(); + } + + return response.getSource().readEntity(ItemList.class); } }; @@ -198,8 +226,14 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient { params.put("exclude",excludeNodes); GXInboundResponse response = myManager.queryParams(params).get(); - if (response.hasGXError()) - throw response.getException(); + + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else + throw new BackendGenericError(); + } + return response.getSource().readEntity(ItemWrapper.class); } }; @@ -219,8 +253,13 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient { GXWebTargetAdapterRequest myManager = manager.path("trash").path("empty"); GXInboundResponse response = myManager.delete(); - if (response.hasGXError()) - throw response.getException(); + + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else + throw new BackendGenericError(); + } return null; } @@ -240,8 +279,13 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient { GXWebTargetAdapterRequest myManager = manager.path("trash").path("restore"); GXInboundResponse response = myManager.put(Entity.text(id)); - if (response.hasGXError()) - throw response.getException(); + + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else + throw new BackendGenericError(); + } return response.getSource().readEntity(String.class); } @@ -287,8 +331,14 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient { params.put("e", new Object[] { URLEncoder.encode(serializedJson)}); GXInboundResponse response = myManager.queryParams(params).get(); - if (response.hasGXError()) - throw response.getException(); + + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else + throw new BackendGenericError(); + } + return response.getSource().readEntity(ItemList.class); } }; diff --git a/src/test/java/org/gcube/data/access/fs/Items.java b/src/test/java/org/gcube/data/access/fs/Items.java index 34247c6..935526a 100644 --- a/src/test/java/org/gcube/data/access/fs/Items.java +++ b/src/test/java/org/gcube/data/access/fs/Items.java @@ -61,8 +61,8 @@ public class Items { String afi = null; - try(InputStream is = new FileInputStream(new File("/home/lucio/Downloads/ar_bigdata_201705.csv"))){ - shc.getWSRoot().uploadFile(is, "bigfile1GB-test2.scv", "descr"); + try(InputStream is = new FileInputStream(new File("/home/lucio/Downloads/TatyanaSondre.jpg"))){ + shc.getWSRoot().uploadFile(is, "TatyanaSondre.jpg", "descr"); System.out.println(afi); } catch (Exception e) { @@ -96,9 +96,8 @@ public class Items { @Test public void emptyTrash() throws Exception { StorageHubClient shc = new StorageHubClient(); - shc.open("9931e1b1-e824-47b1-a30d-4e9a14e126fa").asFile().getPublicLink(); - //shc.emptyTrash(); + shc.emptyTrash(); }