This commit is contained in:
Lucio Lelii 2018-10-11 16:36:21 +00:00
parent 8886f1c88c
commit 0ebc3de5f8
4 changed files with 45 additions and 2 deletions

View File

@ -1,9 +1,11 @@
package org.gcube.common.storagehub.client.dsl;
import java.net.URL;
import java.util.List;
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
import org.gcube.common.storagehub.model.items.AbstractFileItem;
import org.gcube.common.storagehub.model.service.Version;
public class FileContainer extends ItemContainer<AbstractFileItem> {
@ -23,6 +25,10 @@ public class FileContainer extends ItemContainer<AbstractFileItem> {
return itemclient.getPublickLink(this.itemId);
}
public List<Version> getVersions() {
return itemclient.getFileVersions(this.itemId);
}
public FileContainer copy(FolderContainer folder, String newFileName) {
return new FileContainer(itemclient, itemclient.copy(this.itemId, folder.get().getId(), newFileName));
}

View File

@ -25,6 +25,8 @@ import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
import org.gcube.common.storagehub.model.items.Item;
import org.gcube.common.storagehub.model.service.ItemList;
import org.gcube.common.storagehub.model.service.ItemWrapper;
import org.gcube.common.storagehub.model.service.Version;
import org.gcube.common.storagehub.model.service.VersionList;
import org.gcube.common.storagehub.model.types.ACLList;
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
import org.glassfish.jersey.media.multipart.MultiPartFeature;
@ -207,6 +209,34 @@ public class DefaultItemManager implements ItemManagerClient {
}
}
@Override
public List<Version> getFileVersions(String id) {
Call<GXWebTargetAdapterRequest, VersionList> call = new Call<GXWebTargetAdapterRequest, VersionList>() {
@Override
public VersionList call(GXWebTargetAdapterRequest manager) throws Exception {
GXWebTargetAdapterRequest myManager = manager.path(id).path("versions");
GXInboundResponse response = myManager.get();
if (response.isErrorResponse()) {
if (response.hasException())
throw response.getException();
else
throw new BackendGenericError();
}
VersionList versions = response.getSource().readEntity(VersionList.class);
return versions;
}
};
try {
VersionList result = delegate.make(call);
return result.getItemlist();
}catch(Exception e) {
throw new RuntimeException(e);
}
}
@Override
public Item get(String id, String... excludeNodes) {

View File

@ -9,6 +9,7 @@ import org.gcube.common.storagehub.client.StreamDescriptor;
import org.gcube.common.storagehub.model.acls.ACL;
import org.gcube.common.storagehub.model.acls.AccessType;
import org.gcube.common.storagehub.model.items.Item;
import org.gcube.common.storagehub.model.service.Version;
@ -58,6 +59,6 @@ public interface ItemManagerClient {
String rename(String id, String newName);
List<Version> getFileVersions(String id);
}

View File

@ -52,6 +52,12 @@ public class Items {
}
@Test
public void renameFile() throws Exception{
StorageHubClient shc = new StorageHubClient();
shc.open("8822478a-4fd3-41d5-87de-9ff161d0935e").asItem().rename("renamed");
}
@Test
@ -74,7 +80,7 @@ public class Items {
public void download() throws Exception {
StorageHubClient shc = new StorageHubClient();
FolderContainer openResolver = shc.open("ad8ba805-bcc5-4d0e-90c9-53216970b3e6").asFolder();
FolderContainer openResolver = shc.open("894d23bf-e2e9-42b6-a781-b99bb18119c8").asFolder();
StreamDescriptor streamDescr = openResolver.download();