This commit is contained in:
Lucio Lelii 2018-10-12 11:02:35 +00:00
parent 0ebc3de5f8
commit 7cfb84e4de
3 changed files with 36 additions and 1 deletions

View File

@ -13,7 +13,7 @@
<groupId>org.gcube.common</groupId>
<artifactId>storagehub-client-library</artifactId>
<version>1.0.2-SNAPSHOT</version>
<name>toragehub-client-library</name>
<name>storagehub-client-library</name>
<dependencyManagement>
<dependencies>

View File

@ -209,6 +209,39 @@ public class DefaultItemManager implements ItemManagerClient {
}
}
@Override
public StreamDescriptor downloadSpecificVersion(String id, String version) {
Call<GXWebTargetAdapterRequest, StreamDescriptor> call = new Call<GXWebTargetAdapterRequest, StreamDescriptor>() {
@Override
public StreamDescriptor call(GXWebTargetAdapterRequest manager) throws Exception {
GXWebTargetAdapterRequest myManager = manager.path(id).path("versions").path(version).path("download");
GXInboundResponse response = myManager.get();
if (response.isErrorResponse()) {
if (response.hasException())
throw response.getException();
else
throw new BackendGenericError();
}
Response resp = response.getSource();
InputStream stream = resp.readEntity(InputStream.class);
String disposition = resp.getHeaderString("Content-Disposition");
String fileName = disposition.replaceFirst("attachment; filename = ([^/s]+)?", "$1");
return new StreamDescriptor(stream, fileName);
}
};
try {
StreamDescriptor result = delegate.make(call);
return result;
}catch(Exception e) {
throw new RuntimeException(e);
}
}
@Override
public List<Version> getFileVersions(String id) {
Call<GXWebTargetAdapterRequest, VersionList> call = new Call<GXWebTargetAdapterRequest, VersionList>() {

View File

@ -60,5 +60,7 @@ public interface ItemManagerClient {
String rename(String id, String newName);
List<Version> getFileVersions(String id);
StreamDescriptor downloadSpecificVersion(String id, String version);
}