2018-02-15 18:13:50 +01:00
|
|
|
package org.gcube.common.storagehub.client.proxies;
|
|
|
|
|
2022-02-07 10:24:33 +01:00
|
|
|
import java.io.File;
|
2018-02-15 18:13:50 +01:00
|
|
|
import java.io.InputStream;
|
2021-10-15 19:53:14 +02:00
|
|
|
import java.net.URI;
|
2018-06-22 16:27:21 +02:00
|
|
|
import java.net.URL;
|
2020-03-16 16:58:12 +01:00
|
|
|
import java.net.URLEncoder;
|
2022-02-07 10:24:33 +01:00
|
|
|
import java.util.Arrays;
|
2018-02-15 18:13:50 +01:00
|
|
|
import java.util.List;
|
2018-09-20 14:52:23 +02:00
|
|
|
import java.util.Map;
|
2019-01-08 12:17:36 +01:00
|
|
|
import java.util.Objects;
|
2018-06-29 15:03:05 +02:00
|
|
|
import java.util.Set;
|
2018-02-15 18:13:50 +01:00
|
|
|
|
2018-03-29 18:19:01 +02:00
|
|
|
import javax.ws.rs.client.Entity;
|
2018-02-15 18:13:50 +01:00
|
|
|
import javax.ws.rs.core.MediaType;
|
2018-05-23 18:26:06 +02:00
|
|
|
import javax.ws.rs.core.MultivaluedHashMap;
|
|
|
|
import javax.ws.rs.core.MultivaluedMap;
|
2018-02-15 18:13:50 +01:00
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
|
|
|
|
import org.gcube.common.clients.Call;
|
|
|
|
import org.gcube.common.clients.delegates.ProxyDelegate;
|
2018-09-20 14:52:23 +02:00
|
|
|
import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest;
|
|
|
|
import org.gcube.common.gxrest.response.inbound.GXInboundResponse;
|
2018-02-15 18:13:50 +01:00
|
|
|
import org.gcube.common.storagehub.client.StreamDescriptor;
|
2018-10-15 15:39:02 +02:00
|
|
|
import org.gcube.common.storagehub.model.Metadata;
|
2018-05-25 18:05:44 +02:00
|
|
|
import org.gcube.common.storagehub.model.acls.ACL;
|
2018-06-29 15:03:05 +02:00
|
|
|
import org.gcube.common.storagehub.model.acls.AccessType;
|
2018-09-26 15:24:21 +02:00
|
|
|
import org.gcube.common.storagehub.model.annotations.RootNode;
|
2018-09-24 15:21:20 +02:00
|
|
|
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
2019-03-13 18:33:58 +01:00
|
|
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
2018-10-15 16:43:53 +02:00
|
|
|
import org.gcube.common.storagehub.model.items.GCubeItem;
|
2018-02-15 18:13:50 +01:00
|
|
|
import org.gcube.common.storagehub.model.items.Item;
|
|
|
|
import org.gcube.common.storagehub.model.service.ItemList;
|
2018-03-07 18:45:58 +01:00
|
|
|
import org.gcube.common.storagehub.model.service.ItemWrapper;
|
2018-10-11 18:36:21 +02:00
|
|
|
import org.gcube.common.storagehub.model.service.Version;
|
|
|
|
import org.gcube.common.storagehub.model.service.VersionList;
|
2018-05-25 18:05:44 +02:00
|
|
|
import org.gcube.common.storagehub.model.types.ACLList;
|
2022-02-07 10:24:33 +01:00
|
|
|
import org.glassfish.jersey.media.multipart.BodyPart;
|
|
|
|
import org.glassfish.jersey.media.multipart.ContentDisposition;
|
2018-06-29 15:03:05 +02:00
|
|
|
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
|
2018-03-29 18:19:01 +02:00
|
|
|
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
2022-02-07 10:24:33 +01:00
|
|
|
import org.glassfish.jersey.media.multipart.file.FileDataBodyPart;
|
2021-10-28 15:49:12 +02:00
|
|
|
import org.glassfish.jersey.media.multipart.file.StreamDataBodyPart;
|
2018-02-15 18:13:50 +01:00
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
public class DefaultItemManager extends DefaultManagerClient implements ItemManagerClient {
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
|
2018-12-18 15:08:40 +01:00
|
|
|
private static final String CONTENT_DISPOSITION= "Content-Disposition";
|
|
|
|
private static final String CONTENT_TYPE= "Content-Type";
|
2019-10-02 11:55:26 +02:00
|
|
|
private static final String CONTENT_LENGHT= "Content-Length";
|
2018-06-29 15:03:05 +02:00
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
public DefaultItemManager(ProxyDelegate<GXWebTargetAdapterRequest> delegate) {
|
|
|
|
super(delegate);
|
2018-02-15 18:13:50 +01:00
|
|
|
}
|
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
|
|
|
|
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-12-11 17:58:49 +01:00
|
|
|
@Override
|
2019-03-13 18:33:58 +01:00
|
|
|
public StreamDescriptor resolvePublicLink(String identifier) throws StorageHubException{
|
2018-12-11 17:58:49 +01:00
|
|
|
Call<GXWebTargetAdapterRequest, StreamDescriptor> call = new Call<GXWebTargetAdapterRequest, StreamDescriptor>() {
|
|
|
|
@Override
|
2019-03-13 18:33:58 +01:00
|
|
|
public StreamDescriptor call(GXWebTargetAdapterRequest manager) throws StorageHubException, Exception {
|
2019-01-08 12:17:36 +01:00
|
|
|
Objects.requireNonNull(identifier, "id cannot be null");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-12-11 17:58:49 +01:00
|
|
|
GXWebTargetAdapterRequest myManager = manager.path("publiclink").path(identifier);
|
2022-03-28 18:28:06 +02:00
|
|
|
Map<String, Object[]> params = initQueryParameters();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-12-11 17:58:49 +01:00
|
|
|
GXInboundResponse response = myManager.queryParams(params).get();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-12-11 17:58:49 +01:00
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2018-12-11 17:58:49 +01:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-12-11 17:58:49 +01:00
|
|
|
Response resp = response.getSource();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-12-18 15:08:40 +01:00
|
|
|
return createStreamDescriptor(resp);
|
2018-12-11 17:58:49 +01:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-12-11 17:58:49 +01:00
|
|
|
};
|
|
|
|
try {
|
|
|
|
StreamDescriptor result = delegate.make(call);
|
|
|
|
return result;
|
2019-03-13 18:33:58 +01:00
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
2018-12-11 17:58:49 +01:00
|
|
|
}
|
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
@Override
|
2019-01-03 12:16:53 +01:00
|
|
|
@Deprecated
|
2019-03-13 18:33:58 +01:00
|
|
|
public List<? extends Item> getChildren(String id, Class<? extends Item> onlyOfType, String ... excludeNodes) throws StorageHubException {
|
2019-01-03 12:16:53 +01:00
|
|
|
return getChildren(id, onlyOfType, false, excludeNodes);
|
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2019-01-03 12:16:53 +01:00
|
|
|
@Override
|
2019-03-13 18:33:58 +01:00
|
|
|
public List<? extends Item> getChildren(String id, Class<? extends Item> onlyOfType, boolean showHidden, String ... excludeNodes) throws StorageHubException{
|
2018-09-20 14:52:23 +02:00
|
|
|
Call<GXWebTargetAdapterRequest, ItemList> call = new Call<GXWebTargetAdapterRequest, ItemList>() {
|
2018-02-15 18:13:50 +01:00
|
|
|
@Override
|
2019-03-13 18:33:58 +01:00
|
|
|
public ItemList call(GXWebTargetAdapterRequest manager) throws StorageHubException, Exception {
|
2019-01-08 12:17:36 +01:00
|
|
|
Objects.requireNonNull(id, "id cannot be null");
|
2018-09-20 14:52:23 +02:00
|
|
|
GXWebTargetAdapterRequest myManager = manager.path(id).path("children");
|
2022-03-28 18:28:06 +02:00
|
|
|
Map<String, Object[]> params = initQueryParameters();
|
2018-02-15 18:13:50 +01:00
|
|
|
if (excludeNodes !=null && excludeNodes.length>0)
|
2018-09-20 14:52:23 +02:00
|
|
|
params.put("exclude",excludeNodes);
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-26 15:24:21 +02:00
|
|
|
if (onlyOfType!=null)
|
|
|
|
params.put("onlyType", new Object[] {resolveNodeType(onlyOfType)});
|
2019-01-03 12:16:53 +01:00
|
|
|
params.put("showHidden", new Object[] {showHidden});
|
2022-03-28 18:28:06 +02:00
|
|
|
|
|
|
|
|
2018-09-27 18:27:55 +02:00
|
|
|
GXInboundResponse response = myManager.queryParams(params).get();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-28 15:36:08 +02:00
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2018-09-28 15:36:08 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-20 14:52:23 +02:00
|
|
|
ItemList items = response.getSource().readEntity(ItemList.class);
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-20 14:52:23 +02:00
|
|
|
return items;
|
2018-02-15 18:13:50 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
ItemList result = delegate.make(call);
|
|
|
|
return result.getItemlist();
|
2019-03-13 18:33:58 +01:00
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
2018-02-15 18:13:50 +01:00
|
|
|
}
|
|
|
|
}
|
2020-01-24 11:56:40 +01:00
|
|
|
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-26 15:24:21 +02:00
|
|
|
@Override
|
2019-03-13 18:33:58 +01:00
|
|
|
public List<? extends Item> getChildren(String id, int start, int limit, boolean showHidden, Class<? extends Item> onlyOfType, String... excludeNodes) throws StorageHubException{
|
2018-09-26 15:24:21 +02:00
|
|
|
Call<GXWebTargetAdapterRequest, ItemList> call = new Call<GXWebTargetAdapterRequest, ItemList>() {
|
|
|
|
@Override
|
|
|
|
public ItemList call(GXWebTargetAdapterRequest manager) throws Exception {
|
2019-01-08 12:17:36 +01:00
|
|
|
Objects.requireNonNull(id, "id cannot be null");
|
2019-03-13 18:33:58 +01:00
|
|
|
try {
|
|
|
|
GXWebTargetAdapterRequest myManager = manager.path(id).path("children").path("paged");
|
2022-03-28 18:28:06 +02:00
|
|
|
Map<String, Object[]> params = initQueryParameters();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
if (excludeNodes !=null && excludeNodes.length>0)
|
|
|
|
params.put("exclude",excludeNodes);
|
|
|
|
|
|
|
|
if (onlyOfType!=null)
|
|
|
|
params.put("onlyType", new Object[] {resolveNodeType(onlyOfType)});
|
|
|
|
|
|
|
|
params.put("start", new Object[] {start});
|
|
|
|
params.put("limit", new Object[] {limit});
|
|
|
|
params.put("showHidden", new Object[] {showHidden});
|
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
|
2019-03-13 18:33:58 +01:00
|
|
|
GXInboundResponse response = myManager.queryParams(params).get();
|
|
|
|
|
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2019-03-13 18:33:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ItemList items = response.getSource().readEntity(ItemList.class);
|
|
|
|
|
|
|
|
return items;
|
|
|
|
}catch(Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
throw e;
|
2018-09-28 15:36:08 +02:00
|
|
|
}
|
2018-09-26 15:24:21 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
ItemList result = delegate.make(call);
|
|
|
|
return result.getItemlist();
|
2019-03-13 18:33:58 +01:00
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
2018-09-26 15:24:21 +02:00
|
|
|
}
|
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-26 15:24:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2019-01-03 12:16:53 +01:00
|
|
|
public List<? extends Item> getChildren(String id, int start, int limit, boolean showHidden,
|
2019-03-13 18:33:58 +01:00
|
|
|
String... excludeNodes) throws StorageHubException {
|
2019-01-03 12:16:53 +01:00
|
|
|
return getChildren(id, start, limit, showHidden, null, excludeNodes);
|
2018-09-26 15:24:21 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-26 15:24:21 +02:00
|
|
|
@Override
|
2019-01-03 12:16:53 +01:00
|
|
|
@Deprecated
|
2019-03-13 18:33:58 +01:00
|
|
|
public List<? extends Item> getChildren(String id, String ... excludeNodes) throws StorageHubException{
|
2019-01-03 12:16:53 +01:00
|
|
|
return getChildren(id, false,excludeNodes);
|
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2019-01-03 12:16:53 +01:00
|
|
|
@Override
|
2019-03-13 18:33:58 +01:00
|
|
|
public List<? extends Item> getChildren(String id, boolean showHidden, String ... excludeNodes) throws StorageHubException{
|
2019-01-03 12:16:53 +01:00
|
|
|
return getChildren(id, null, showHidden, excludeNodes);
|
2018-09-26 15:24:21 +02:00
|
|
|
}
|
|
|
|
|
2020-03-16 16:58:12 +01:00
|
|
|
public List<? extends Item> search(String id, Class<? extends Item> onlyOfType, boolean showHidden, boolean excludeTrashed, String nameToMatch, String ... excludeNodes) throws StorageHubException{
|
2020-01-24 11:56:40 +01:00
|
|
|
Call<GXWebTargetAdapterRequest, ItemList> call = new Call<GXWebTargetAdapterRequest, ItemList>() {
|
|
|
|
@Override
|
|
|
|
public ItemList call(GXWebTargetAdapterRequest manager) throws StorageHubException, Exception {
|
|
|
|
Objects.requireNonNull(id, "id cannot be null");
|
|
|
|
GXWebTargetAdapterRequest myManager = manager.path(id).path("search");
|
2022-03-28 18:28:06 +02:00
|
|
|
Map<String, Object[]> params = initQueryParameters();
|
2020-01-24 11:56:40 +01:00
|
|
|
if (excludeNodes !=null && excludeNodes.length>0)
|
|
|
|
params.put("exclude",excludeNodes);
|
|
|
|
|
|
|
|
if (onlyOfType!=null)
|
|
|
|
params.put("onlyType", new Object[] {resolveNodeType(onlyOfType)});
|
|
|
|
params.put("showHidden", new Object[] {showHidden});
|
2020-03-16 16:58:12 +01:00
|
|
|
params.put("name", new String[] {URLEncoder.encode( nameToMatch, "UTF-8" )});
|
|
|
|
params.put("excludeTrashed", new Object[] {excludeTrashed});
|
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
|
2020-01-24 11:56:40 +01:00
|
|
|
GXInboundResponse response = myManager.queryParams(params).get();
|
|
|
|
|
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemList items = response.getSource().readEntity(ItemList.class);
|
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
ItemList result = delegate.make(call);
|
|
|
|
return result.getItemlist();
|
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-26 15:24:21 +02:00
|
|
|
@Override
|
2019-01-03 12:16:53 +01:00
|
|
|
@Deprecated
|
2019-03-13 18:33:58 +01:00
|
|
|
public Integer childrenCount(String id , Class<? extends Item> onlyOfType) throws StorageHubException{
|
2019-01-03 12:16:53 +01:00
|
|
|
return childrenCount(id , false, onlyOfType);
|
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2019-01-03 12:16:53 +01:00
|
|
|
@Override
|
2019-03-13 18:33:58 +01:00
|
|
|
public Integer childrenCount(String id , boolean showHidden, Class<? extends Item> onlyOfType) throws StorageHubException {
|
2018-09-26 15:24:21 +02:00
|
|
|
Call<GXWebTargetAdapterRequest, Integer> call = new Call<GXWebTargetAdapterRequest, Integer>() {
|
|
|
|
@Override
|
|
|
|
public Integer call(GXWebTargetAdapterRequest manager) throws Exception {
|
2019-01-08 12:17:36 +01:00
|
|
|
Objects.requireNonNull(id, "id cannot be null");
|
2018-09-26 15:24:21 +02:00
|
|
|
GXWebTargetAdapterRequest myManager = manager.path(id).path("children").path("count");
|
2022-03-28 18:28:06 +02:00
|
|
|
Map<String, Object[]> params = initQueryParameters();
|
2018-09-26 15:24:21 +02:00
|
|
|
if (onlyOfType!=null)
|
|
|
|
params.put("onlyType", new Object[] {resolveNodeType(onlyOfType)});
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2019-01-03 12:16:53 +01:00
|
|
|
params.put("showHidden", new Object[] {showHidden});
|
2022-03-28 18:28:06 +02:00
|
|
|
|
|
|
|
|
2018-09-27 18:27:55 +02:00
|
|
|
GXInboundResponse response = myManager.queryParams(params).get();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-28 15:36:08 +02:00
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2018-09-28 15:36:08 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-26 15:24:21 +02:00
|
|
|
return response.getSource().readEntity(Integer.class);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
Integer result = delegate.make(call);
|
|
|
|
return result;
|
2019-03-13 18:33:58 +01:00
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
2018-09-26 15:24:21 +02:00
|
|
|
}
|
|
|
|
}
|
2018-02-15 18:13:50 +01:00
|
|
|
|
2018-09-26 15:24:21 +02:00
|
|
|
@Override
|
2019-01-03 12:16:53 +01:00
|
|
|
@Deprecated
|
2019-03-13 18:33:58 +01:00
|
|
|
public Integer childrenCount(String id) throws StorageHubException{
|
2019-01-03 12:16:53 +01:00
|
|
|
return childrenCount(id, false);
|
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2019-01-03 12:16:53 +01:00
|
|
|
@Override
|
2019-03-13 18:33:58 +01:00
|
|
|
public Integer childrenCount(String id, boolean showHidden) throws StorageHubException {
|
2019-01-03 12:16:53 +01:00
|
|
|
return childrenCount(id, showHidden, null);
|
2018-09-26 15:24:21 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
private String resolveNodeType(Class<? extends Item> itemClass) throws StorageHubException {
|
2018-09-26 15:24:21 +02:00
|
|
|
if (!itemClass.isAnnotationPresent(RootNode.class)) return null;
|
|
|
|
String nodeType= itemClass.getAnnotation(RootNode.class).value();
|
|
|
|
return nodeType;
|
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-06-29 15:03:05 +02:00
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
@Override
|
2019-03-13 18:33:58 +01:00
|
|
|
public StreamDescriptor download(String id, String... excludeNodes) throws StorageHubException {
|
2018-09-20 14:52:23 +02:00
|
|
|
Call<GXWebTargetAdapterRequest, StreamDescriptor> call = new Call<GXWebTargetAdapterRequest, StreamDescriptor>() {
|
2018-02-15 18:13:50 +01:00
|
|
|
@Override
|
2018-09-20 14:52:23 +02:00
|
|
|
public StreamDescriptor call(GXWebTargetAdapterRequest manager) throws Exception {
|
2019-01-08 12:17:36 +01:00
|
|
|
Objects.requireNonNull(id, "id cannot be null");
|
2018-09-20 14:52:23 +02:00
|
|
|
GXWebTargetAdapterRequest myManager = manager.path(id).path("download");
|
2022-03-28 18:28:06 +02:00
|
|
|
Map<String, Object[]> params = initQueryParameters();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-04 11:21:08 +02:00
|
|
|
if (excludeNodes !=null && excludeNodes.length>0)
|
2018-09-20 14:52:23 +02:00
|
|
|
params.put("exclude",excludeNodes);
|
2022-03-28 18:28:06 +02:00
|
|
|
|
2018-09-27 18:27:55 +02:00
|
|
|
GXInboundResponse response = myManager.queryParams(params).get();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-28 15:36:08 +02:00
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2018-09-28 15:36:08 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-20 14:52:23 +02:00
|
|
|
Response resp = response.getSource();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-12-18 15:08:40 +01:00
|
|
|
return createStreamDescriptor(resp);
|
2018-02-15 18:13:50 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
StreamDescriptor result = delegate.make(call);
|
|
|
|
return result;
|
2019-03-13 18:33:58 +01:00
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
2018-02-15 18:13:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-12 13:02:35 +02:00
|
|
|
@Override
|
2019-03-13 18:33:58 +01:00
|
|
|
public StreamDescriptor downloadSpecificVersion(String id, String version) throws StorageHubException {
|
2018-10-12 13:02:35 +02:00
|
|
|
Call<GXWebTargetAdapterRequest, StreamDescriptor> call = new Call<GXWebTargetAdapterRequest, StreamDescriptor>() {
|
|
|
|
@Override
|
|
|
|
public StreamDescriptor call(GXWebTargetAdapterRequest manager) throws Exception {
|
2019-01-08 12:17:36 +01:00
|
|
|
Objects.requireNonNull(id, "id cannot be null");
|
|
|
|
Objects.requireNonNull(version, "version cannot be null");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
GXWebTargetAdapterRequest myManager = manager.path(id).queryParams(initQueryParameters()).path("versions").path(version).path("download");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-10-12 13:02:35 +02:00
|
|
|
GXInboundResponse response = myManager.get();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-10-12 13:02:35 +02:00
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2018-10-12 13:02:35 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-10-12 13:02:35 +02:00
|
|
|
Response resp = response.getSource();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-12-18 15:08:40 +01:00
|
|
|
return createStreamDescriptor(resp);
|
2018-10-12 13:02:35 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
StreamDescriptor result = delegate.make(call);
|
|
|
|
return result;
|
2019-03-13 18:33:58 +01:00
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
2018-10-12 13:02:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-10-11 18:36:21 +02:00
|
|
|
@Override
|
2019-03-13 18:33:58 +01:00
|
|
|
public List<Version> getFileVersions(String id) throws StorageHubException {
|
2018-10-11 18:36:21 +02:00
|
|
|
Call<GXWebTargetAdapterRequest, VersionList> call = new Call<GXWebTargetAdapterRequest, VersionList>() {
|
|
|
|
@Override
|
|
|
|
public VersionList call(GXWebTargetAdapterRequest manager) throws Exception {
|
2019-01-08 12:17:36 +01:00
|
|
|
Objects.requireNonNull(id, "id cannot be null");
|
2018-10-11 18:36:21 +02:00
|
|
|
GXWebTargetAdapterRequest myManager = manager.path(id).path("versions");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).get();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-10-11 18:36:21 +02:00
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2018-10-11 18:36:21 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-10-11 18:36:21 +02:00
|
|
|
VersionList versions = response.getSource().readEntity(VersionList.class);
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-10-11 18:36:21 +02:00
|
|
|
return versions;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
VersionList result = delegate.make(call);
|
|
|
|
return result.getItemlist();
|
2019-03-13 18:33:58 +01:00
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
2018-10-11 18:36:21 +02:00
|
|
|
}
|
|
|
|
}
|
2018-03-07 18:45:58 +01:00
|
|
|
|
|
|
|
@Override
|
2019-03-13 18:33:58 +01:00
|
|
|
public Item get(String id, String... excludeNodes) throws StorageHubException {
|
2018-09-20 14:52:23 +02:00
|
|
|
Call<GXWebTargetAdapterRequest, ItemWrapper<Item>> call = new Call<GXWebTargetAdapterRequest, ItemWrapper<Item>>() {
|
2018-03-07 18:45:58 +01:00
|
|
|
@Override
|
2018-09-20 14:52:23 +02:00
|
|
|
public ItemWrapper<Item> call(GXWebTargetAdapterRequest manager) throws Exception {
|
2019-01-08 12:17:36 +01:00
|
|
|
Objects.requireNonNull(id, "id cannot be null");
|
2018-09-20 14:52:23 +02:00
|
|
|
GXWebTargetAdapterRequest myManager = manager.path(id);
|
2022-03-28 18:28:06 +02:00
|
|
|
Map<String, Object[]> params = initQueryParameters();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-03-07 18:45:58 +01:00
|
|
|
if (excludeNodes !=null && excludeNodes.length>0)
|
2018-09-20 14:52:23 +02:00
|
|
|
params.put("exclude",excludeNodes);
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-27 18:27:55 +02:00
|
|
|
GXInboundResponse response = myManager.queryParams(params).get();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-28 15:36:08 +02:00
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2018-09-28 15:36:08 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-20 14:52:23 +02:00
|
|
|
ItemWrapper<Item> item = response.getSource().readEntity(ItemWrapper.class);
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
|
2018-09-20 14:52:23 +02:00
|
|
|
return item;
|
2018-03-07 18:45:58 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
ItemWrapper<Item> result = delegate.make(call);
|
|
|
|
return result.getItem();
|
2019-03-13 18:33:58 +01:00
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
2018-03-07 18:45:58 +01:00
|
|
|
}
|
|
|
|
}
|
2020-03-05 15:19:45 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Item getByRelativePath(String id, String path, String... excludeNodes) throws StorageHubException {
|
|
|
|
Call<GXWebTargetAdapterRequest, ItemWrapper<Item>> call = new Call<GXWebTargetAdapterRequest, ItemWrapper<Item>>() {
|
|
|
|
@Override
|
|
|
|
public ItemWrapper<Item> call(GXWebTargetAdapterRequest manager) throws Exception {
|
|
|
|
Objects.requireNonNull(id, "id cannot be null");
|
|
|
|
Objects.requireNonNull(path, "path cannot be null");
|
|
|
|
|
|
|
|
GXWebTargetAdapterRequest myManager = manager.path(id).path("path");
|
2022-03-28 18:28:06 +02:00
|
|
|
Map<String, Object[]> params = initQueryParameters();
|
2020-03-05 15:19:45 +01:00
|
|
|
|
|
|
|
params.put("path",new String[] {path});
|
|
|
|
|
|
|
|
if (excludeNodes !=null && excludeNodes.length>0)
|
|
|
|
params.put("exclude",excludeNodes);
|
|
|
|
|
|
|
|
GXInboundResponse response = myManager.queryParams(params).get();
|
2018-03-07 18:45:58 +01:00
|
|
|
|
2020-03-05 15:19:45 +01:00
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemWrapper<Item> item = response.getSource().readEntity(ItemWrapper.class);
|
|
|
|
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
ItemWrapper<Item> result = delegate.make(call);
|
|
|
|
return result.getItem();
|
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-27 15:36:50 +02:00
|
|
|
@Override
|
2019-03-13 18:33:58 +01:00
|
|
|
public Item getRootSharedFolder(String id) throws StorageHubException {
|
2018-09-20 14:52:23 +02:00
|
|
|
Call<GXWebTargetAdapterRequest, ItemWrapper<Item>> call = new Call<GXWebTargetAdapterRequest, ItemWrapper<Item>>() {
|
2018-06-27 15:36:50 +02:00
|
|
|
@Override
|
2018-09-20 14:52:23 +02:00
|
|
|
public ItemWrapper<Item> call(GXWebTargetAdapterRequest manager) throws Exception {
|
2019-01-08 12:17:36 +01:00
|
|
|
Objects.requireNonNull(id, "id cannot be null");
|
2022-03-28 18:28:06 +02:00
|
|
|
GXWebTargetAdapterRequest myManager = manager.path(id).queryParams(initQueryParameters()).path("rootSharedFolder");
|
2018-09-27 18:27:55 +02:00
|
|
|
GXInboundResponse response = myManager.get();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-28 15:36:08 +02:00
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2018-09-28 15:36:08 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-20 14:52:23 +02:00
|
|
|
ItemWrapper<Item> item = response.getSource().readEntity(ItemWrapper.class);
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
|
2018-09-20 14:52:23 +02:00
|
|
|
return item;
|
2018-06-27 15:36:50 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
ItemWrapper<Item> result = delegate.make(call);
|
|
|
|
return result.getItem();
|
2019-03-13 18:33:58 +01:00
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
2018-06-27 15:36:50 +02:00
|
|
|
}
|
|
|
|
}
|
2018-06-29 15:03:05 +02:00
|
|
|
|
2018-03-14 16:21:13 +01:00
|
|
|
|
2018-06-22 16:27:21 +02:00
|
|
|
@Override
|
2019-03-13 18:33:58 +01:00
|
|
|
public URL getPublickLink(String id) throws StorageHubException {
|
2018-09-20 14:52:23 +02:00
|
|
|
Call<GXWebTargetAdapterRequest, URL> call = new Call<GXWebTargetAdapterRequest, URL>() {
|
2018-06-22 16:27:21 +02:00
|
|
|
@Override
|
2018-09-20 14:52:23 +02:00
|
|
|
public URL call(GXWebTargetAdapterRequest manager) throws Exception {
|
2019-01-08 12:17:36 +01:00
|
|
|
Objects.requireNonNull(id, "id cannot be null");
|
2018-09-20 14:52:23 +02:00
|
|
|
GXWebTargetAdapterRequest myManager = manager.path(id).path("publiclink");
|
2022-03-28 18:28:06 +02:00
|
|
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).get();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-28 15:36:08 +02:00
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2018-09-28 15:36:08 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-20 14:52:23 +02:00
|
|
|
URL item = response.getSource().readEntity(URL.class);
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-20 14:52:23 +02:00
|
|
|
return item;
|
2018-06-22 16:27:21 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
URL result = delegate.make(call);
|
|
|
|
return result;
|
2019-03-13 18:33:58 +01:00
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
2018-06-22 16:27:21 +02:00
|
|
|
}
|
|
|
|
}
|
2018-06-29 15:03:05 +02:00
|
|
|
|
2019-01-08 12:17:36 +01:00
|
|
|
@Override
|
2019-03-13 18:33:58 +01:00
|
|
|
public URL getPublickLink(String id, String version) throws StorageHubException {
|
2019-01-08 12:17:36 +01:00
|
|
|
Call<GXWebTargetAdapterRequest, URL> call = new Call<GXWebTargetAdapterRequest, URL>() {
|
|
|
|
@Override
|
|
|
|
public URL call(GXWebTargetAdapterRequest manager) throws Exception {
|
|
|
|
Objects.requireNonNull(id, "id cannot be null");
|
|
|
|
Objects.requireNonNull(version, "version cannot be null");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2019-01-08 12:17:36 +01:00
|
|
|
GXWebTargetAdapterRequest myManager = manager.path(id).path("publiclink");
|
2022-03-28 18:28:06 +02:00
|
|
|
Map<String, Object[]> params = initQueryParameters();
|
2019-01-08 12:17:36 +01:00
|
|
|
params.put("version",new Object[] {version});
|
|
|
|
GXInboundResponse response = myManager.queryParams(params).get();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2019-01-08 12:17:36 +01:00
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2019-01-08 12:17:36 +01:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2019-01-08 12:17:36 +01:00
|
|
|
URL item = response.getSource().readEntity(URL.class);
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2019-01-08 12:17:36 +01:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
URL result = delegate.make(call);
|
|
|
|
return result;
|
2019-03-13 18:33:58 +01:00
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
2019-01-08 12:17:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-06-26 15:30:30 +02:00
|
|
|
@Override
|
2019-03-13 18:33:58 +01:00
|
|
|
public List<? extends Item> findChildrenByNamePattern(String id, String name, String... excludeNodes) throws StorageHubException {
|
2018-09-20 14:52:23 +02:00
|
|
|
Call<GXWebTargetAdapterRequest, ItemList> call = new Call<GXWebTargetAdapterRequest, ItemList>() {
|
2018-06-26 15:30:30 +02:00
|
|
|
@Override
|
2018-09-20 14:52:23 +02:00
|
|
|
public ItemList call(GXWebTargetAdapterRequest manager) throws Exception {
|
2019-01-08 12:17:36 +01:00
|
|
|
Objects.requireNonNull(id, "id cannot be null");
|
|
|
|
Objects.requireNonNull(id, "name cannot be null");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2021-04-29 16:58:14 +02:00
|
|
|
GXWebTargetAdapterRequest myManager = manager.path(id).path("items");
|
2022-03-28 18:28:06 +02:00
|
|
|
Map<String, Object[]> params = initQueryParameters();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-06-26 15:30:30 +02:00
|
|
|
if (excludeNodes !=null && excludeNodes.length>0)
|
2018-09-20 14:52:23 +02:00
|
|
|
params.put("exclude",excludeNodes);
|
2021-04-29 16:58:14 +02:00
|
|
|
params.put("name", new Object[] {name});
|
|
|
|
|
2018-09-27 18:27:55 +02:00
|
|
|
GXInboundResponse response = myManager.queryParams(params).get();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-28 15:36:08 +02:00
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2018-09-28 15:36:08 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-20 14:52:23 +02:00
|
|
|
ItemList items = response.getSource().readEntity(ItemList.class);
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-20 14:52:23 +02:00
|
|
|
return items;
|
2018-06-26 15:30:30 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
ItemList result = delegate.make(call);
|
|
|
|
return result.getItemlist();
|
2019-03-13 18:33:58 +01:00
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
2018-06-26 15:30:30 +02:00
|
|
|
}
|
|
|
|
}
|
2022-02-07 10:24:33 +01:00
|
|
|
|
2018-03-29 18:19:01 +02:00
|
|
|
@Override
|
2019-03-13 18:33:58 +01:00
|
|
|
public String uploadFile(InputStream stream, String parentId, String fileName, String description) throws StorageHubException {
|
2022-02-07 10:24:33 +01:00
|
|
|
return this.uploadFile(stream, parentId, fileName, description, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String uploadFile(InputStream stream, String parentId, String fileName, String description, long contentLength) throws StorageHubException {
|
2018-09-20 14:52:23 +02:00
|
|
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
2018-03-29 18:19:01 +02:00
|
|
|
@Override
|
2018-09-20 14:52:23 +02:00
|
|
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
2019-01-08 12:17:36 +01:00
|
|
|
Objects.requireNonNull(stream, "stream cannot be null");
|
|
|
|
Objects.requireNonNull(parentId, "parentId cannot be null");
|
|
|
|
Objects.requireNonNull(fileName, "parentId cannot be null");
|
|
|
|
Objects.requireNonNull(description, "parentId cannot be null");
|
2021-10-28 15:49:12 +02:00
|
|
|
|
2018-09-20 14:52:23 +02:00
|
|
|
GXWebTargetAdapterRequest myManager = manager.register(MultiPartFeature.class).path(parentId)
|
2018-07-05 12:31:52 +02:00
|
|
|
.path("create").path("FILE");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2019-05-06 12:05:07 +02:00
|
|
|
GXInboundResponse response =null;
|
2018-07-05 15:37:29 +02:00
|
|
|
FormDataMultiPart multipart = new FormDataMultiPart();
|
2019-09-11 18:12:46 +02:00
|
|
|
|
2018-07-05 15:37:29 +02:00
|
|
|
multipart.field("name", fileName);
|
|
|
|
multipart.field("description", description);
|
2021-10-28 15:49:12 +02:00
|
|
|
|
2022-02-07 10:24:33 +01:00
|
|
|
ContentDisposition contentDisposition;
|
|
|
|
if (contentLength>0)
|
|
|
|
contentDisposition = ContentDisposition.type("attachment").fileName(fileName).size(contentLength).build();
|
|
|
|
else
|
|
|
|
contentDisposition = ContentDisposition.type("attachment").fileName(fileName).build();
|
2021-10-28 15:49:12 +02:00
|
|
|
|
|
|
|
|
2022-02-07 10:24:33 +01:00
|
|
|
BodyPart fdp = new StreamDataBodyPart("file", stream);
|
2022-03-28 18:28:06 +02:00
|
|
|
|
2022-02-07 10:24:33 +01:00
|
|
|
multipart.bodyPart(fdp);
|
|
|
|
|
2019-05-06 12:05:07 +02:00
|
|
|
Entity<FormDataMultiPart> entity = Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA);
|
2019-09-11 18:12:46 +02:00
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
response = myManager.queryParams(initQueryParameters()).header("Content-Disposition",Arrays.asList(contentDisposition.toString())).post(entity);
|
2019-09-11 18:12:46 +02:00
|
|
|
|
2018-09-28 15:36:08 +02:00
|
|
|
if (response.isErrorResponse()) {
|
2019-05-06 12:05:07 +02:00
|
|
|
if (response.hasException()) {
|
2018-09-28 15:36:08 +02:00
|
|
|
throw response.getException();
|
2019-05-06 12:05:07 +02:00
|
|
|
}else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2018-09-28 15:36:08 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-20 14:52:23 +02:00
|
|
|
return response.getSource().readEntity(String.class);
|
2018-03-29 18:19:01 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
2018-06-19 11:42:57 +02:00
|
|
|
return delegate.make(call);
|
2019-03-13 18:33:58 +01:00
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
2018-03-29 18:19:01 +02:00
|
|
|
}
|
|
|
|
}
|
2022-02-07 10:24:33 +01:00
|
|
|
|
2021-10-15 19:53:14 +02:00
|
|
|
@Override
|
2022-02-07 10:24:33 +01:00
|
|
|
public String uploadFile(File file, String parentId, String fileName, String description) throws StorageHubException {
|
2021-10-15 19:53:14 +02:00
|
|
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
|
|
|
@Override
|
|
|
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
2022-02-07 10:24:33 +01:00
|
|
|
Objects.requireNonNull(file, "file cannot be null");
|
2021-10-15 19:53:14 +02:00
|
|
|
Objects.requireNonNull(parentId, "parentId cannot be null");
|
|
|
|
Objects.requireNonNull(fileName, "parentId cannot be null");
|
|
|
|
Objects.requireNonNull(description, "parentId cannot be null");
|
|
|
|
|
|
|
|
GXWebTargetAdapterRequest myManager = manager.register(MultiPartFeature.class).path(parentId)
|
|
|
|
.path("create").path("FILE");
|
|
|
|
|
|
|
|
GXInboundResponse response =null;
|
2022-02-07 10:24:33 +01:00
|
|
|
FormDataMultiPart multipart = new FormDataMultiPart();
|
|
|
|
|
|
|
|
multipart.field("name", fileName);
|
|
|
|
multipart.field("description", description);
|
|
|
|
|
|
|
|
BodyPart fdp = new FileDataBodyPart("file", file);
|
|
|
|
|
|
|
|
multipart.bodyPart(fdp);
|
|
|
|
|
|
|
|
Entity<FormDataMultiPart> entity = Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA);
|
2021-10-15 19:53:14 +02:00
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
response = myManager.queryParams(initQueryParameters()).post(entity);
|
2021-10-15 19:53:14 +02:00
|
|
|
|
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException()) {
|
|
|
|
throw response.getException();
|
|
|
|
}else
|
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
|
|
|
}
|
|
|
|
|
|
|
|
return response.getSource().readEntity(String.class);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
return delegate.make(call);
|
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
|
|
|
}
|
2022-02-07 10:24:33 +01:00
|
|
|
}
|
2021-10-15 19:53:14 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String uploadFile(URI uri, String parentId, String fileName, String description) throws StorageHubException {
|
|
|
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
|
|
|
@Override
|
|
|
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
|
|
|
Objects.requireNonNull(uri, "uri cannot be null");
|
|
|
|
Objects.requireNonNull(parentId, "parentId cannot be null");
|
|
|
|
Objects.requireNonNull(fileName, "parentId cannot be null");
|
|
|
|
Objects.requireNonNull(description, "parentId cannot be null");
|
|
|
|
|
|
|
|
GXWebTargetAdapterRequest myManager = manager.register(MultiPartFeature.class).path(parentId)
|
|
|
|
.path("create").path("FILE");
|
|
|
|
|
|
|
|
MultivaluedMap<String, String> formData = new MultivaluedHashMap<String, String>();
|
|
|
|
formData.add("url", uri.toString());
|
|
|
|
formData.add("name", fileName);
|
|
|
|
formData.add("description", description);
|
|
|
|
|
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).post(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED));
|
2021-10-15 19:53:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException()) {
|
|
|
|
throw response.getException();
|
|
|
|
}else
|
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
|
|
|
}
|
2018-03-29 18:19:01 +02:00
|
|
|
|
2021-10-15 19:53:14 +02:00
|
|
|
return response.getSource().readEntity(String.class);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
return delegate.make(call);
|
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-30 12:38:34 +02:00
|
|
|
@Override
|
2022-02-07 10:24:33 +01:00
|
|
|
public String uploadArchive(InputStream stream, String parentId, String extractionFolderName, long contentLength)
|
|
|
|
throws StorageHubException {
|
2018-09-20 14:52:23 +02:00
|
|
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
2018-07-30 12:38:34 +02:00
|
|
|
@Override
|
2018-09-20 14:52:23 +02:00
|
|
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
2019-01-08 12:17:36 +01:00
|
|
|
Objects.requireNonNull(stream, "stream cannot be null");
|
|
|
|
Objects.requireNonNull(parentId, "parentId cannot be null");
|
|
|
|
Objects.requireNonNull(extractionFolderName, "extraction folder name cannot be null");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-20 14:52:23 +02:00
|
|
|
GXWebTargetAdapterRequest myManager = manager.register(MultiPartFeature.class).path(parentId)
|
2018-07-30 12:38:34 +02:00
|
|
|
.path("create").path("ARCHIVE");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-07-30 12:38:34 +02:00
|
|
|
FormDataMultiPart multipart = new FormDataMultiPart();
|
|
|
|
multipart.field("parentFolderName", extractionFolderName);
|
|
|
|
multipart.field("file", stream, MediaType.APPLICATION_OCTET_STREAM_TYPE);
|
2022-02-07 10:24:33 +01:00
|
|
|
|
|
|
|
if (contentLength >0)
|
|
|
|
myManager = myManager.header("Content-Length", contentLength);
|
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA_TYPE));
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-28 15:36:08 +02:00
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2018-09-28 15:36:08 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-20 14:52:23 +02:00
|
|
|
return response.getSource().readEntity(String.class);
|
2018-07-30 12:38:34 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
return delegate.make(call);
|
2019-03-13 18:33:58 +01:00
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
2018-07-30 12:38:34 +02:00
|
|
|
}
|
|
|
|
}
|
2022-02-07 10:24:33 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String uploadArchive(InputStream stream, String parentId, String extractionFolderName) throws StorageHubException {
|
|
|
|
return this.uploadArchive(stream, parentId, extractionFolderName, 0);
|
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-12-18 16:24:08 +01:00
|
|
|
@Override
|
|
|
|
@Deprecated
|
2019-03-13 18:33:58 +01:00
|
|
|
public String createFolder(String parentId, String name, String description) throws StorageHubException {
|
2018-12-18 16:24:08 +01:00
|
|
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
|
|
|
@Override
|
|
|
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
|
|
|
return createFolder(parentId, name, description, false);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
return delegate.make(call);
|
2019-03-13 18:33:58 +01:00
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
2018-12-18 16:24:08 +01:00
|
|
|
}
|
|
|
|
}
|
2018-09-20 14:52:23 +02:00
|
|
|
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-05-23 18:26:06 +02:00
|
|
|
@Override
|
2019-03-13 18:33:58 +01:00
|
|
|
public String createFolder(String parentId, String name, String description, boolean hidden) throws StorageHubException {
|
2018-09-20 14:52:23 +02:00
|
|
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
2018-05-23 18:26:06 +02:00
|
|
|
@Override
|
2018-09-20 14:52:23 +02:00
|
|
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
2019-01-08 12:17:36 +01:00
|
|
|
Objects.requireNonNull(parentId, "parentId cannot be null");
|
|
|
|
Objects.requireNonNull(name, "folder name cannot be null");
|
|
|
|
Objects.requireNonNull(description, "parentId cannot be null");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
|
2018-09-20 14:52:23 +02:00
|
|
|
GXWebTargetAdapterRequest myManager = manager.path(parentId)
|
|
|
|
.path("create").path("FOLDER");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-12-18 18:25:04 +01:00
|
|
|
MultivaluedMap<String, String> formData = new MultivaluedHashMap<String, String>();
|
2018-06-29 15:03:05 +02:00
|
|
|
formData.add("name", name);
|
|
|
|
formData.add("description", description);
|
2018-12-18 18:25:04 +01:00
|
|
|
formData.add("hidden", Boolean.toString(hidden));
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).post(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED));
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-28 15:36:08 +02:00
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2018-09-28 15:36:08 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-20 14:52:23 +02:00
|
|
|
return response.getSource().readEntity(String.class);
|
2018-05-23 18:26:06 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
2018-06-19 11:42:57 +02:00
|
|
|
return delegate.make(call);
|
2019-03-13 18:33:58 +01:00
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
2018-05-23 18:26:06 +02:00
|
|
|
}
|
|
|
|
}
|
2019-09-11 18:12:46 +02:00
|
|
|
|
|
|
|
|
2019-07-29 16:25:52 +02:00
|
|
|
@Override
|
|
|
|
public String createURL(String parentId, String name, String description,URL url) throws StorageHubException {
|
|
|
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
|
|
|
@Override
|
|
|
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
|
|
|
Objects.requireNonNull(parentId, "parentId cannot be null");
|
|
|
|
Objects.requireNonNull(name, "folder name cannot be null");
|
|
|
|
Objects.requireNonNull(description, "parentId cannot be null");
|
|
|
|
|
|
|
|
|
|
|
|
GXWebTargetAdapterRequest myManager = manager.path(parentId)
|
|
|
|
.path("create").path("URL");
|
|
|
|
|
|
|
|
MultivaluedMap<String, String> formData = new MultivaluedHashMap<String, String>();
|
|
|
|
formData.add("name", name);
|
|
|
|
formData.add("description", description);
|
|
|
|
formData.add("value", url.toString());
|
|
|
|
|
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).post(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED));
|
2019-07-29 16:25:52 +02:00
|
|
|
|
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2019-07-29 16:25:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return response.getSource().readEntity(String.class);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
return delegate.make(call);
|
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-10-15 16:43:53 +02:00
|
|
|
@Override
|
2019-03-13 18:33:58 +01:00
|
|
|
public String createGcubeItem(String parentId, GCubeItem item) throws StorageHubException {
|
2018-10-15 16:43:53 +02:00
|
|
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
|
|
|
@Override
|
|
|
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2019-01-08 12:17:36 +01:00
|
|
|
Objects.requireNonNull(parentId, "parentId cannot be null");
|
|
|
|
Objects.requireNonNull(item, "item cannot be null");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-10-15 16:43:53 +02:00
|
|
|
GXWebTargetAdapterRequest myManager = manager.path(parentId)
|
|
|
|
.path("create").path("GCUBEITEM");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).post(Entity.json(item));
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-10-15 16:43:53 +02:00
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2018-10-15 16:43:53 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-10-15 16:43:53 +02:00
|
|
|
return response.getSource().readEntity(String.class);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
return delegate.make(call);
|
2019-03-13 18:33:58 +01:00
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
2018-10-15 16:43:53 +02:00
|
|
|
}
|
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-06-29 15:03:05 +02:00
|
|
|
@Override
|
2019-03-13 18:33:58 +01:00
|
|
|
public String shareFolder(String id, Set<String> users, AccessType accessType) throws StorageHubException {
|
2018-09-20 14:52:23 +02:00
|
|
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
2018-06-29 15:03:05 +02:00
|
|
|
@Override
|
2018-09-20 14:52:23 +02:00
|
|
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2019-01-08 12:17:36 +01:00
|
|
|
Objects.requireNonNull(id, "id cannot be null");
|
|
|
|
Objects.requireNonNull(users, "users list cannot be null");
|
|
|
|
Objects.requireNonNull(accessType, "access type cannot be null");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-20 14:52:23 +02:00
|
|
|
GXWebTargetAdapterRequest myManager = manager.register(MultiPartFeature.class).path(id)
|
2018-06-29 15:03:05 +02:00
|
|
|
.path("share");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-06-29 15:03:05 +02:00
|
|
|
try (FormDataMultiPart multipart = new FormDataMultiPart()){
|
|
|
|
multipart.field("defaultAccessType", accessType, MediaType.APPLICATION_JSON_TYPE);
|
|
|
|
multipart.field("users", users, MediaType.APPLICATION_JSON_TYPE);
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).put(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA_TYPE));
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-28 15:36:08 +02:00
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2018-09-28 15:36:08 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-20 14:52:23 +02:00
|
|
|
return response.getSource().readEntity(String.class);
|
2018-06-29 15:03:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
return delegate.make(call);
|
2019-03-13 18:33:58 +01:00
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
2018-06-29 15:03:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-07 17:42:04 +02:00
|
|
|
@Override
|
2019-03-13 18:33:58 +01:00
|
|
|
public String unshareFolder(String id, Set<String> users) throws StorageHubException {
|
2018-09-20 14:52:23 +02:00
|
|
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
2018-09-07 17:42:04 +02:00
|
|
|
@Override
|
2018-09-20 14:52:23 +02:00
|
|
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
2019-01-08 12:17:36 +01:00
|
|
|
Objects.requireNonNull(id, "id cannot be null");
|
|
|
|
Objects.requireNonNull(users, "users list cannot be null");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-20 14:52:23 +02:00
|
|
|
GXWebTargetAdapterRequest myManager = manager.register(MultiPartFeature.class).path(id)
|
2018-09-07 17:42:04 +02:00
|
|
|
.path("unshare");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-07 17:42:04 +02:00
|
|
|
try (FormDataMultiPart multipart = new FormDataMultiPart()){
|
|
|
|
multipart.field("users", users, MediaType.APPLICATION_JSON_TYPE);
|
2022-03-28 18:28:06 +02:00
|
|
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).put(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA_TYPE));
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-28 15:36:08 +02:00
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2018-09-28 15:36:08 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-20 14:52:23 +02:00
|
|
|
return response.getSource().readEntity(String.class);
|
2018-09-07 17:42:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
return delegate.make(call);
|
2019-03-13 18:33:58 +01:00
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
2018-09-07 17:42:04 +02:00
|
|
|
}
|
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-05-30 18:15:56 +02:00
|
|
|
@Override
|
2019-05-22 17:12:47 +02:00
|
|
|
@Deprecated
|
2019-03-13 18:33:58 +01:00
|
|
|
public void delete(String id) throws StorageHubException {
|
2019-05-22 17:12:47 +02:00
|
|
|
delete(id, false);
|
|
|
|
}
|
2019-09-11 18:12:46 +02:00
|
|
|
|
2019-05-22 17:12:47 +02:00
|
|
|
@Override
|
|
|
|
public void delete(String id, boolean force) throws StorageHubException {
|
2018-09-20 14:52:23 +02:00
|
|
|
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
|
2018-05-30 18:15:56 +02:00
|
|
|
@Override
|
2018-09-20 14:52:23 +02:00
|
|
|
public Void call(GXWebTargetAdapterRequest manager) throws Exception {
|
2019-01-08 12:17:36 +01:00
|
|
|
Objects.requireNonNull(id, "id cannot be null");
|
2019-09-11 18:12:46 +02:00
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
Map<String, Object[]> queryParam = initQueryParameters();
|
2019-05-22 17:12:47 +02:00
|
|
|
queryParam.put("force", new Object[] {force});
|
2019-09-11 18:12:46 +02:00
|
|
|
|
2018-09-20 14:52:23 +02:00
|
|
|
GXWebTargetAdapterRequest myManager = manager.path(id);
|
2019-05-23 15:18:37 +02:00
|
|
|
GXInboundResponse response = myManager.queryParams(queryParam).delete();
|
2019-09-11 18:12:46 +02:00
|
|
|
|
2018-09-28 15:36:08 +02:00
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-28 15:36:08 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-06-29 15:03:05 +02:00
|
|
|
return null;
|
2018-05-30 18:15:56 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
delegate.make(call);
|
2019-03-13 18:33:58 +01:00
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
2018-05-30 18:15:56 +02:00
|
|
|
}
|
|
|
|
}
|
2018-06-29 15:03:05 +02:00
|
|
|
|
2018-05-21 16:38:49 +02:00
|
|
|
@Override
|
2019-03-13 18:33:58 +01:00
|
|
|
public List<? extends Item> getAnchestors(String id, String... excludeNodes) throws StorageHubException {
|
2018-09-20 14:52:23 +02:00
|
|
|
Call<GXWebTargetAdapterRequest, ItemList> call = new Call<GXWebTargetAdapterRequest, ItemList>() {
|
2018-05-21 16:38:49 +02:00
|
|
|
@Override
|
2018-09-20 14:52:23 +02:00
|
|
|
public ItemList call(GXWebTargetAdapterRequest manager) throws Exception {
|
2019-01-08 12:17:36 +01:00
|
|
|
Objects.requireNonNull(id, "id cannot be null");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-20 14:52:23 +02:00
|
|
|
GXWebTargetAdapterRequest myManager = manager.path(id).path("anchestors");
|
2022-03-28 18:28:06 +02:00
|
|
|
Map<String, Object[]> params = initQueryParameters();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-05-21 16:38:49 +02:00
|
|
|
if (excludeNodes !=null && excludeNodes.length>0)
|
2018-09-20 14:52:23 +02:00
|
|
|
params.put("exclude",excludeNodes);
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-27 18:27:55 +02:00
|
|
|
GXInboundResponse response = myManager.queryParams(params).get();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-28 15:36:08 +02:00
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2018-09-28 15:36:08 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-20 14:52:23 +02:00
|
|
|
return response.getSource().readEntity(ItemList.class);
|
2018-05-21 16:38:49 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
ItemList result = delegate.make(call);
|
|
|
|
return result.getItemlist();
|
2019-03-13 18:33:58 +01:00
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
2018-05-21 16:38:49 +02:00
|
|
|
}
|
|
|
|
}
|
2018-06-29 15:03:05 +02:00
|
|
|
|
2018-05-25 18:05:44 +02:00
|
|
|
@Override
|
2019-03-13 18:33:58 +01:00
|
|
|
public List<ACL> getACL(String id) throws StorageHubException {
|
2018-09-20 14:52:23 +02:00
|
|
|
Call<GXWebTargetAdapterRequest, ACLList> call = new Call<GXWebTargetAdapterRequest, ACLList>() {
|
2018-05-25 18:05:44 +02:00
|
|
|
@Override
|
2018-09-20 14:52:23 +02:00
|
|
|
public ACLList call(GXWebTargetAdapterRequest manager) throws Exception {
|
2019-01-08 12:17:36 +01:00
|
|
|
Objects.requireNonNull(id, "id cannot be null");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
GXWebTargetAdapterRequest myManager = manager.queryParams(initQueryParameters()).path(id).path("acls");
|
2018-09-27 18:27:55 +02:00
|
|
|
GXInboundResponse response = myManager.get();
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-28 15:36:08 +02:00
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2018-09-28 15:36:08 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-20 14:52:23 +02:00
|
|
|
return response.getSource().readEntity(ACLList.class);
|
2018-05-25 18:05:44 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
return delegate.make(call).getAcls();
|
2019-03-13 18:33:58 +01:00
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
2018-05-25 18:05:44 +02:00
|
|
|
}
|
|
|
|
}
|
2018-05-21 16:38:49 +02:00
|
|
|
|
2019-09-11 18:12:46 +02:00
|
|
|
|
|
|
|
|
2019-06-05 18:10:28 +02:00
|
|
|
@Override
|
|
|
|
public boolean canWriteInto(String id) throws StorageHubException {
|
|
|
|
Call<GXWebTargetAdapterRequest, Boolean> call = new Call<GXWebTargetAdapterRequest, Boolean>() {
|
|
|
|
@Override
|
|
|
|
public Boolean call(GXWebTargetAdapterRequest manager) throws Exception {
|
|
|
|
Objects.requireNonNull(id, "id cannot be null");
|
2019-09-11 18:12:46 +02:00
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
GXWebTargetAdapterRequest myManager = manager.queryParams(initQueryParameters()).path(id).path("acls").path("write");
|
2019-09-11 18:12:46 +02:00
|
|
|
|
|
|
|
|
2019-06-05 18:10:28 +02:00
|
|
|
GXInboundResponse response = myManager.get();
|
2019-09-11 18:12:46 +02:00
|
|
|
|
2019-06-05 18:10:28 +02:00
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2019-06-05 18:10:28 +02:00
|
|
|
}
|
2019-09-11 18:12:46 +02:00
|
|
|
|
|
|
|
|
2019-06-05 18:10:28 +02:00
|
|
|
return response.getSource().readEntity(Boolean.class);
|
2019-09-11 18:12:46 +02:00
|
|
|
|
2019-06-05 18:10:28 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
return delegate.make(call);
|
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
|
|
|
}
|
|
|
|
}
|
2019-09-11 18:12:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-05-22 17:12:47 +02:00
|
|
|
@Override
|
|
|
|
public String changeACL(String id, String user, AccessType accessType) throws StorageHubException {
|
|
|
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
|
|
|
@Override
|
|
|
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
|
|
|
Objects.requireNonNull(id, "id cannot be null");
|
|
|
|
Objects.requireNonNull(user, "user cannot be null");
|
2019-09-11 18:12:46 +02:00
|
|
|
|
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
GXWebTargetAdapterRequest myManager = manager.queryParams(initQueryParameters()).path(id).path("acls");
|
2019-09-11 18:12:46 +02:00
|
|
|
|
2019-05-22 17:12:47 +02:00
|
|
|
try (FormDataMultiPart multipart = new FormDataMultiPart()){
|
2019-09-09 16:29:40 +02:00
|
|
|
multipart.field("access", accessType, MediaType.APPLICATION_JSON_TYPE);
|
2019-05-22 17:12:47 +02:00
|
|
|
multipart.field("user", user);
|
|
|
|
|
|
|
|
GXInboundResponse response = myManager.put(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA_TYPE));
|
|
|
|
|
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2019-05-22 17:12:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return response.getSource().readEntity(String.class);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
return delegate.make(call);
|
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
|
|
|
}
|
|
|
|
}
|
2018-09-21 17:57:37 +02:00
|
|
|
|
2019-09-11 18:12:46 +02:00
|
|
|
|
|
|
|
@Override
|
2020-01-15 19:10:33 +01:00
|
|
|
public String removeAdmin(String id, String user) throws StorageHubException {
|
2019-09-11 18:12:46 +02:00
|
|
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
|
|
|
@Override
|
|
|
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
|
|
|
Objects.requireNonNull(id, "id cannot be null");
|
|
|
|
Objects.requireNonNull(user, "user cannot be null");
|
|
|
|
|
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
GXWebTargetAdapterRequest myManager = manager.queryParams(initQueryParameters()).path(id).path("acls").path(user);
|
2019-09-11 18:12:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
GXInboundResponse response = myManager.delete();
|
|
|
|
|
|
|
|
|
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2019-09-11 18:12:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return response.getSource().readEntity(String.class);
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
return delegate.make(call);
|
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
|
|
|
}
|
2020-01-15 19:10:33 +01:00
|
|
|
}
|
2019-09-11 18:12:46 +02:00
|
|
|
|
|
|
|
|
2018-09-21 17:57:37 +02:00
|
|
|
@Override
|
2019-03-13 18:33:58 +01:00
|
|
|
public String copy(String id, String destinationFolderId, String newFilename) throws StorageHubException {
|
2018-09-21 17:57:37 +02:00
|
|
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
|
|
|
@Override
|
|
|
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2019-01-08 12:17:36 +01:00
|
|
|
Objects.requireNonNull(id, "id cannot be null");
|
|
|
|
Objects.requireNonNull(newFilename, "new file name cannot be null");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-21 17:57:37 +02:00
|
|
|
GXWebTargetAdapterRequest myManager = manager.path(id)
|
|
|
|
.path("copy");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-21 17:57:37 +02:00
|
|
|
MultivaluedMap<String, String> formData = new MultivaluedHashMap<String, String>();
|
|
|
|
formData.add("destinationId", destinationFolderId);
|
|
|
|
formData.add("fileName", newFilename);
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).put(Entity.form(formData));
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-28 15:36:08 +02:00
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2018-09-28 15:36:08 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-09-21 17:57:37 +02:00
|
|
|
return response.getSource().readEntity(String.class);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
return delegate.make(call);
|
2019-03-13 18:33:58 +01:00
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
2018-09-21 17:57:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-11 18:12:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-09-09 16:29:40 +02:00
|
|
|
@Override
|
|
|
|
public String setPublic(String id, boolean publish) throws StorageHubException {
|
|
|
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
|
|
|
@Override
|
|
|
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
|
|
|
Objects.requireNonNull(id, "id cannot be null");
|
2019-09-11 18:12:46 +02:00
|
|
|
|
2019-09-09 16:29:40 +02:00
|
|
|
GXWebTargetAdapterRequest myManager = manager.path(id)
|
|
|
|
.path("publish");
|
|
|
|
|
|
|
|
MultivaluedMap<String, String> formData = new MultivaluedHashMap<String, String>();
|
|
|
|
formData.add("publish", Boolean.toString(publish));
|
|
|
|
|
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).put(Entity.form(formData));
|
2019-09-09 16:29:40 +02:00
|
|
|
|
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2019-09-09 16:29:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return response.getSource().readEntity(String.class);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
return delegate.make(call);
|
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-04 16:53:47 +02:00
|
|
|
@Override
|
2019-03-13 18:33:58 +01:00
|
|
|
public String move(String id, String destinationFolderId) throws StorageHubException {
|
2018-10-04 16:53:47 +02:00
|
|
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
|
|
|
@Override
|
|
|
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
2019-01-08 12:17:36 +01:00
|
|
|
Objects.requireNonNull(id, "id cannot be null");
|
|
|
|
Objects.requireNonNull(destinationFolderId, "destination folder cannot be null");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
|
2018-10-04 16:53:47 +02:00
|
|
|
GXWebTargetAdapterRequest myManager = manager.path(id)
|
|
|
|
.path("move");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-10-04 16:53:47 +02:00
|
|
|
MultivaluedMap<String, String> formData = new MultivaluedHashMap<String, String>();
|
|
|
|
formData.add("destinationId", destinationFolderId);
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).put(Entity.form(formData));
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-10-04 16:53:47 +02:00
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2018-10-04 16:53:47 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-10-04 16:53:47 +02:00
|
|
|
return response.getSource().readEntity(String.class);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
return delegate.make(call);
|
2019-03-13 18:33:58 +01:00
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
2018-10-04 16:53:47 +02:00
|
|
|
}
|
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-10-04 17:41:01 +02:00
|
|
|
@Override
|
2019-03-13 18:33:58 +01:00
|
|
|
public String rename(String id, String newName) throws StorageHubException {
|
2018-10-04 17:41:01 +02:00
|
|
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
|
|
|
@Override
|
|
|
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
2019-01-08 12:17:36 +01:00
|
|
|
Objects.requireNonNull(id, "id cannot be null");
|
|
|
|
Objects.requireNonNull(newName, "new name cannot be null");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-10-04 17:41:01 +02:00
|
|
|
GXWebTargetAdapterRequest myManager = manager.path(id)
|
|
|
|
.path("rename");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-10-04 17:41:01 +02:00
|
|
|
MultivaluedMap<String, String> formData = new MultivaluedHashMap<String, String>();
|
|
|
|
formData.add("newName", newName);
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).put(Entity.form(formData));
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-10-04 17:41:01 +02:00
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2018-10-04 17:41:01 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-10-04 17:41:01 +02:00
|
|
|
return response.getSource().readEntity(String.class);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
return delegate.make(call);
|
2019-03-13 18:33:58 +01:00
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
2018-10-04 17:41:01 +02:00
|
|
|
}
|
|
|
|
}
|
2018-10-15 15:39:02 +02:00
|
|
|
|
2020-03-16 16:58:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String setHidden(String id, Boolean value) throws StorageHubException {
|
|
|
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
|
|
|
@Override
|
|
|
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
|
|
|
Objects.requireNonNull(id, "id cannot be null");
|
|
|
|
Objects.requireNonNull(value, "value cannot be null");
|
|
|
|
|
|
|
|
|
|
|
|
GXWebTargetAdapterRequest myManager = manager.path(id)
|
|
|
|
.path("hidden");
|
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).put(Entity.json(value));
|
2020-03-16 16:58:12 +01:00
|
|
|
|
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
|
|
|
}
|
|
|
|
|
|
|
|
return response.getSource().readEntity(String.class);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
return delegate.make(call);
|
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-16 11:03:06 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String setDescription(String id, String description) throws StorageHubException {
|
|
|
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
|
|
|
@Override
|
|
|
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
|
|
|
Objects.requireNonNull(id, "id cannot be null");
|
|
|
|
Objects.requireNonNull(description, "description cannot be null");
|
|
|
|
|
|
|
|
|
|
|
|
GXWebTargetAdapterRequest myManager = manager.path(id)
|
|
|
|
.path("description");
|
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).put(Entity.json(description));
|
2020-09-16 11:03:06 +02:00
|
|
|
|
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
|
|
|
}
|
|
|
|
|
|
|
|
return response.getSource().readEntity(String.class);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
return delegate.make(call);
|
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-15 15:39:02 +02:00
|
|
|
|
|
|
|
@Override
|
2019-03-13 18:33:58 +01:00
|
|
|
public String setMetadata(String id, Metadata metadata) throws StorageHubException {
|
2018-10-15 15:39:02 +02:00
|
|
|
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
|
|
|
@Override
|
|
|
|
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
2019-01-08 12:17:36 +01:00
|
|
|
Objects.requireNonNull(id, "id cannot be null");
|
|
|
|
Objects.requireNonNull(metadata, "metadata cannot be null");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
|
2018-10-15 15:39:02 +02:00
|
|
|
GXWebTargetAdapterRequest myManager = manager.path(id)
|
|
|
|
.path("metadata");
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
|
2022-03-28 18:28:06 +02:00
|
|
|
GXInboundResponse response = myManager.queryParams(initQueryParameters()).put(Entity.json(metadata));
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-10-15 15:39:02 +02:00
|
|
|
if (response.isErrorResponse()) {
|
|
|
|
if (response.hasException())
|
|
|
|
throw response.getException();
|
|
|
|
else
|
2020-01-24 11:56:40 +01:00
|
|
|
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
2018-10-15 15:39:02 +02:00
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
2018-10-15 15:39:02 +02:00
|
|
|
return response.getSource().readEntity(String.class);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
return delegate.make(call);
|
2019-03-13 18:33:58 +01:00
|
|
|
}catch(StorageHubException e) {
|
|
|
|
throw e;
|
|
|
|
}catch(Exception e1) {
|
|
|
|
throw new RuntimeException(e1);
|
2018-10-15 15:39:02 +02:00
|
|
|
}
|
|
|
|
}
|
2019-03-13 18:33:58 +01:00
|
|
|
|
|
|
|
|
2018-12-18 15:08:40 +01:00
|
|
|
private StreamDescriptor createStreamDescriptor(Response resp) {
|
|
|
|
InputStream stream = resp.readEntity(InputStream.class);
|
|
|
|
String disposition = resp.getHeaderString(CONTENT_DISPOSITION);
|
|
|
|
String fileName = disposition.replaceFirst("attachment; filename = ([^/s]+)?", "$1");
|
|
|
|
String contentType = resp.getHeaderString(CONTENT_TYPE);
|
2019-10-02 11:55:26 +02:00
|
|
|
long contentLenght = -1l;
|
|
|
|
try {
|
|
|
|
contentLenght = Long.parseLong(resp.getHeaderString(CONTENT_LENGHT));
|
|
|
|
}catch (Exception e) {
|
|
|
|
//DO NOTHING
|
|
|
|
}
|
|
|
|
return new StreamDescriptor(stream, fileName, contentType, contentLenght);
|
2018-12-18 15:08:40 +01:00
|
|
|
}
|
2022-02-07 10:24:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
}
|