added method for version removal
This commit is contained in:
parent
78496153a4
commit
2bc4138463
11
pom.xml
11
pom.xml
|
@ -21,6 +21,12 @@
|
|||
<version>2.0.0-SNAPSHOT</version>
|
||||
<name>storagehub-client-library</name>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
</properties>
|
||||
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
@ -33,6 +39,8 @@
|
|||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
|
||||
<dependencies>
|
||||
|
||||
|
||||
|
@ -81,7 +89,8 @@
|
|||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
|
|
|
@ -39,6 +39,11 @@ public class FileContainer extends ItemContainer<AbstractFileItem> {
|
|||
return itemclient.downloadSpecificVersion(this.itemId, versionName);
|
||||
}
|
||||
|
||||
public FileContainer deleteVersion(String version) throws StorageHubException{
|
||||
itemclient.deleteFileVersion(this.itemId, version);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FileContainer copy(FolderContainer folder, String newFileName) throws StorageHubException {
|
||||
return new FileContainer(itemclient, itemclient.copy(this.itemId, folder.get().getId(), newFileName));
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import java.io.InputStream;
|
|||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
@ -36,10 +35,8 @@ 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.BodyPart;
|
||||
import org.glassfish.jersey.media.multipart.ContentDisposition;
|
||||
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
||||
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
|
||||
import org.glassfish.jersey.media.multipart.MultiPart;
|
||||
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
||||
import org.glassfish.jersey.media.multipart.file.FileDataBodyPart;
|
||||
import org.glassfish.jersey.media.multipart.file.StreamDataBodyPart;
|
||||
|
@ -55,8 +52,6 @@ public class DefaultItemManager extends DefaultManagerClient implements ItemMana
|
|||
super(delegate);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public StreamDescriptor resolvePublicLink(String identifier) throws StorageHubException{
|
||||
|
@ -414,6 +409,37 @@ public class DefaultItemManager extends DefaultManagerClient implements ItemMana
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteFileVersion(String id, String versionName) throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
|
||||
@Override
|
||||
public Void call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
Objects.requireNonNull(id, "id cannot be null");
|
||||
Objects.requireNonNull(versionName, "version name cannot be null");
|
||||
GXWebTargetAdapterRequest myManager = manager.path(id).path("versions").path(versionName);
|
||||
|
||||
GXInboundResponse response = myManager.queryParams(initQueryParameters()).delete();
|
||||
|
||||
if (response.isErrorResponse()) {
|
||||
if (response.hasException())
|
||||
throw response.getException();
|
||||
else
|
||||
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
delegate.make(call);
|
||||
}catch(StorageHubException e) {
|
||||
throw e;
|
||||
}catch(Exception e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Item get(String id, String... excludeNodes) throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, ItemWrapper<Item>> call = new Call<GXWebTargetAdapterRequest, ItemWrapper<Item>>() {
|
||||
|
|
|
@ -92,6 +92,8 @@ public interface ItemManagerClient extends ManagerClient{
|
|||
|
||||
StreamDescriptor downloadSpecificVersion(String id, String version) throws StorageHubException;
|
||||
|
||||
void deleteFileVersion(String id, String versionName) throws StorageHubException;
|
||||
|
||||
String setMetadata(String id,Metadata metadata) throws StorageHubException;
|
||||
|
||||
String setHidden(String id,Boolean value) throws StorageHubException;
|
||||
|
|
|
@ -14,6 +14,7 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
|
@ -31,6 +32,7 @@ import org.gcube.common.storagehub.client.proxies.UserManagerClient;
|
|||
import org.gcube.common.storagehub.model.Metadata;
|
||||
import org.gcube.common.storagehub.model.acls.AccessType;
|
||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
||||
import org.gcube.common.storagehub.model.items.FolderItem;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
import org.junit.BeforeClass;
|
||||
|
@ -94,6 +96,19 @@ public class Items {
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void removeVersion() throws Exception {
|
||||
|
||||
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
String id = "024c8cab-f9f7-4fd8-bed2-f6076e5edf91";
|
||||
FileContainer file = shc.open(id).asFile();
|
||||
file.deleteVersion("1.0");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uploadTovolatile() throws StorageHubException {
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
|
@ -112,6 +127,22 @@ public class Items {
|
|||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void uploadfile() {
|
||||
try{
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
shc.impersonate("pasquale.pagano");
|
||||
URI toUpload = new URI("https://data.d4science.org/shub/E_RGNhNU9aaVhZM3ovNEN2dEdtdXpCWitac0tScmMvcGZSeDlISUtOb2JOMklRQkxrdjBCWnJ4YlJHVlM4VnVjVQ==");
|
||||
String fileName = "DRR014055.fastq.gz";
|
||||
|
||||
shc.open("514295c6-2176-49d5-9487-99fb0fb85372").asFolder().uploadFile(toUpload, fileName, "description");
|
||||
//shc.uploadFileOnVolatile(fileIS, "zoom_amd645.deb", file.length());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void removeTest() {
|
||||
try {
|
||||
|
@ -130,11 +161,11 @@ public class Items {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void stressTest() {
|
||||
try {
|
||||
|
@ -184,7 +215,7 @@ public class Items {
|
|||
for (int length; (length = is.read(buffer)) != -1; ) {}
|
||||
}
|
||||
System.out.println("downloaded file "+fileName);
|
||||
|
||||
|
||||
}catch (Exception e) {
|
||||
System.err.println("error downloading public link for id "+id);
|
||||
e.printStackTrace();
|
||||
|
@ -566,8 +597,8 @@ public class Items {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void deleteUnusefulUsers() throws Exception{
|
||||
final UserManagerClient client = AbstractPlugin.users().build();
|
||||
|
|
Loading…
Reference in New Issue