git-svn-id: https://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/Common/storagehub-client@176354 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
dbd167df9b
commit
0a094a5bc4
|
@ -26,6 +26,10 @@ public class FileContainer extends ItemContainer<AbstractFileItem> {
|
|||
return itemclient.getPublickLink(this.itemId);
|
||||
}
|
||||
|
||||
public URL getPublicLink(String version) {
|
||||
return itemclient.getPublickLink(this.itemId, version);
|
||||
}
|
||||
|
||||
public List<Version> getVersions() {
|
||||
return itemclient.getFileVersions(this.itemId);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.net.URL;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.client.Entity;
|
||||
|
@ -50,6 +51,8 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
Call<GXWebTargetAdapterRequest, StreamDescriptor> call = new Call<GXWebTargetAdapterRequest, StreamDescriptor>() {
|
||||
@Override
|
||||
public StreamDescriptor call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
Objects.requireNonNull(identifier, "id cannot be null");
|
||||
|
||||
GXWebTargetAdapterRequest myManager = manager.path("publiclink").path(identifier);
|
||||
Map<String, Object[]> params = new HashMap<>();
|
||||
|
||||
|
@ -87,6 +90,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
Call<GXWebTargetAdapterRequest, ItemList> call = new Call<GXWebTargetAdapterRequest, ItemList>() {
|
||||
@Override
|
||||
public ItemList call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
Objects.requireNonNull(id, "id cannot be null");
|
||||
GXWebTargetAdapterRequest myManager = manager.path(id).path("children");
|
||||
Map<String, Object[]> params = new HashMap<>();
|
||||
if (excludeNodes !=null && excludeNodes.length>0)
|
||||
|
@ -124,6 +128,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
Call<GXWebTargetAdapterRequest, ItemList> call = new Call<GXWebTargetAdapterRequest, ItemList>() {
|
||||
@Override
|
||||
public ItemList call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
Objects.requireNonNull(id, "id cannot be null");
|
||||
GXWebTargetAdapterRequest myManager = manager.path(id).path("children").path("paged");
|
||||
Map<String, Object[]> params = new HashMap<>();
|
||||
|
||||
|
@ -190,6 +195,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
Call<GXWebTargetAdapterRequest, Integer> call = new Call<GXWebTargetAdapterRequest, Integer>() {
|
||||
@Override
|
||||
public Integer call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
Objects.requireNonNull(id, "id cannot be null");
|
||||
GXWebTargetAdapterRequest myManager = manager.path(id).path("children").path("count");
|
||||
Map<String, Object[]> params = new HashMap<>();
|
||||
if (onlyOfType!=null)
|
||||
|
@ -240,6 +246,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
Call<GXWebTargetAdapterRequest, StreamDescriptor> call = new Call<GXWebTargetAdapterRequest, StreamDescriptor>() {
|
||||
@Override
|
||||
public StreamDescriptor call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
Objects.requireNonNull(id, "id cannot be null");
|
||||
GXWebTargetAdapterRequest myManager = manager.path(id).path("download");
|
||||
Map<String, Object[]> params = new HashMap<>();
|
||||
|
||||
|
@ -273,6 +280,9 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
Call<GXWebTargetAdapterRequest, StreamDescriptor> call = new Call<GXWebTargetAdapterRequest, StreamDescriptor>() {
|
||||
@Override
|
||||
public StreamDescriptor call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
Objects.requireNonNull(id, "id cannot be null");
|
||||
Objects.requireNonNull(version, "version cannot be null");
|
||||
|
||||
GXWebTargetAdapterRequest myManager = manager.path(id).path("versions").path(version).path("download");
|
||||
|
||||
GXInboundResponse response = myManager.get();
|
||||
|
@ -303,6 +313,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
Call<GXWebTargetAdapterRequest, VersionList> call = new Call<GXWebTargetAdapterRequest, VersionList>() {
|
||||
@Override
|
||||
public VersionList call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
Objects.requireNonNull(id, "id cannot be null");
|
||||
GXWebTargetAdapterRequest myManager = manager.path(id).path("versions");
|
||||
|
||||
GXInboundResponse response = myManager.get();
|
||||
|
@ -332,6 +343,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
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");
|
||||
GXWebTargetAdapterRequest myManager = manager.path(id);
|
||||
Map<String, Object[]> params = new HashMap<>();
|
||||
|
||||
|
@ -366,6 +378,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
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");
|
||||
GXWebTargetAdapterRequest myManager = manager.path(id).path("rootSharedFolder");
|
||||
GXInboundResponse response = myManager.get();
|
||||
|
||||
|
@ -396,6 +409,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
Call<GXWebTargetAdapterRequest, URL> call = new Call<GXWebTargetAdapterRequest, URL>() {
|
||||
@Override
|
||||
public URL call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
Objects.requireNonNull(id, "id cannot be null");
|
||||
GXWebTargetAdapterRequest myManager = manager.path(id).path("publiclink");
|
||||
GXInboundResponse response = myManager.get();
|
||||
|
||||
|
@ -419,11 +433,48 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getPublickLink(String id, String version) {
|
||||
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");
|
||||
|
||||
GXWebTargetAdapterRequest myManager = manager.path(id).path("publiclink");
|
||||
Map<String, Object[]> params = new HashMap<>();
|
||||
params.put("version",new Object[] {version});
|
||||
GXInboundResponse response = myManager.queryParams(params).get();
|
||||
|
||||
if (response.isErrorResponse()) {
|
||||
if (response.hasException())
|
||||
throw response.getException();
|
||||
else
|
||||
throw new BackendGenericError();
|
||||
}
|
||||
|
||||
URL item = response.getSource().readEntity(URL.class);
|
||||
|
||||
return item;
|
||||
}
|
||||
};
|
||||
try {
|
||||
URL result = delegate.make(call);
|
||||
return result;
|
||||
}catch(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<? extends Item> findChildrenByNamePattern(String id, String name, String... excludeNodes) {
|
||||
Call<GXWebTargetAdapterRequest, ItemList> call = new Call<GXWebTargetAdapterRequest, ItemList>() {
|
||||
@Override
|
||||
public ItemList call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
Objects.requireNonNull(id, "id cannot be null");
|
||||
Objects.requireNonNull(id, "name cannot be null");
|
||||
|
||||
GXWebTargetAdapterRequest myManager = manager.path(id).path("items").path(name);
|
||||
Map<String, Object[]> params = new HashMap<>();
|
||||
|
||||
|
@ -458,6 +509,11 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
||||
@Override
|
||||
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
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");
|
||||
|
||||
GXWebTargetAdapterRequest myManager = manager.register(MultiPartFeature.class).path(parentId)
|
||||
.path("create").path("FILE");
|
||||
|
||||
|
@ -491,6 +547,10 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
||||
@Override
|
||||
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
Objects.requireNonNull(stream, "stream cannot be null");
|
||||
Objects.requireNonNull(parentId, "parentId cannot be null");
|
||||
Objects.requireNonNull(extractionFolderName, "extraction folder name cannot be null");
|
||||
|
||||
GXWebTargetAdapterRequest myManager = manager.register(MultiPartFeature.class).path(parentId)
|
||||
.path("create").path("ARCHIVE");
|
||||
|
||||
|
@ -540,6 +600,11 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
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("FOLDER");
|
||||
|
||||
|
@ -573,6 +638,10 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
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(item, "item cannot be null");
|
||||
|
||||
GXWebTargetAdapterRequest myManager = manager.path(parentId)
|
||||
.path("create").path("GCUBEITEM");
|
||||
|
||||
|
@ -601,7 +670,10 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
||||
@Override
|
||||
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
System.out.println("id is: "+id);
|
||||
|
||||
Objects.requireNonNull(id, "id cannot be null");
|
||||
Objects.requireNonNull(users, "users list cannot be null");
|
||||
Objects.requireNonNull(accessType, "access type cannot be null");
|
||||
|
||||
GXWebTargetAdapterRequest myManager = manager.register(MultiPartFeature.class).path(id)
|
||||
.path("share");
|
||||
|
@ -635,6 +707,9 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
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(users, "users list cannot be null");
|
||||
|
||||
GXWebTargetAdapterRequest myManager = manager.register(MultiPartFeature.class).path(id)
|
||||
.path("unshare");
|
||||
|
||||
|
@ -665,6 +740,8 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
|
||||
@Override
|
||||
public Void call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
Objects.requireNonNull(id, "id cannot be null");
|
||||
|
||||
GXWebTargetAdapterRequest myManager = manager.path(id);
|
||||
GXInboundResponse response = myManager.delete();
|
||||
|
||||
|
@ -691,6 +768,8 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
Call<GXWebTargetAdapterRequest, ItemList> call = new Call<GXWebTargetAdapterRequest, ItemList>() {
|
||||
@Override
|
||||
public ItemList call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
Objects.requireNonNull(id, "id cannot be null");
|
||||
|
||||
GXWebTargetAdapterRequest myManager = manager.path(id).path("anchestors");
|
||||
Map<String, Object[]> params = new HashMap<>();
|
||||
|
||||
|
@ -722,6 +801,8 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
Call<GXWebTargetAdapterRequest, ACLList> call = new Call<GXWebTargetAdapterRequest, ACLList>() {
|
||||
@Override
|
||||
public ACLList call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
Objects.requireNonNull(id, "id cannot be null");
|
||||
|
||||
GXWebTargetAdapterRequest myManager = manager.path(id).path("acls");
|
||||
GXInboundResponse response = myManager.get();
|
||||
|
||||
|
@ -748,6 +829,10 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
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(newFilename, "new file name cannot be null");
|
||||
|
||||
GXWebTargetAdapterRequest myManager = manager.path(id)
|
||||
.path("copy");
|
||||
|
||||
|
@ -780,6 +865,10 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
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(destinationFolderId, "destination folder cannot be null");
|
||||
|
||||
|
||||
GXWebTargetAdapterRequest myManager = manager.path(id)
|
||||
.path("move");
|
||||
|
||||
|
@ -811,6 +900,9 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
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(newName, "new name cannot be null");
|
||||
|
||||
GXWebTargetAdapterRequest myManager = manager.path(id)
|
||||
.path("rename");
|
||||
|
||||
|
@ -843,6 +935,10 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
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(metadata, "metadata cannot be null");
|
||||
|
||||
|
||||
GXWebTargetAdapterRequest myManager = manager.path(id)
|
||||
.path("metadata");
|
||||
|
||||
|
|
|
@ -47,6 +47,8 @@ public interface ItemManagerClient {
|
|||
void delete(String id);
|
||||
|
||||
URL getPublickLink(String id);
|
||||
|
||||
URL getPublickLink(String id, String version);
|
||||
|
||||
List<? extends Item> findChildrenByNamePattern(String id, String name, String ... excludeNodes);
|
||||
|
||||
|
@ -85,5 +87,7 @@ public interface ItemManagerClient {
|
|||
|
||||
@Deprecated
|
||||
Integer childrenCount(String id);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public class Items {
|
|||
|
||||
@BeforeClass
|
||||
public static void setUp(){
|
||||
SecurityTokenProvider.instance.set("04269c7d-dab7-498a-841d-8d38ae2d482b-98187548");
|
||||
SecurityTokenProvider.instance.set("a5b623b6-6577-4271-aba6-7ada687d29cf-98187548");
|
||||
//SecurityTokenProvider.instance.set("a5b623b6-6577-4271-aba6-7ada687d29cf-98187548");
|
||||
|
||||
ScopeProvider.instance.set("/gcube");
|
||||
|
@ -50,9 +50,7 @@ public class Items {
|
|||
FolderContainer myRoot = shc.getWSRoot().newFolder("AnimalsMatcher", "");
|
||||
|
||||
FolderContainer children = myRoot.newFolder("build", "build folder");
|
||||
|
||||
|
||||
|
||||
|
||||
FileContainer file = null;
|
||||
try(InputStream is = new FileInputStream(new File("/home/lucio/Downloads/mg.jpg"))){
|
||||
file = myRoot.uploadFile(is, "mg.jpg", "file");
|
||||
|
@ -179,6 +177,22 @@ public class Items {
|
|||
public void downloadFile() {
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
|
||||
StreamDescriptor descr = shc.open("6c5fb143-3711-4097-9bdc-952e41355440").asFile().
|
||||
|
||||
File targetFile = new File("/tmp/"+descr.getFileName());
|
||||
|
||||
try {
|
||||
java.nio.file.Files.copy(
|
||||
descr.getStream(),
|
||||
targetFile.toPath(),
|
||||
StandardCopyOption.REPLACE_EXISTING);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("file created "+targetFile.getAbsolutePath());
|
||||
/*
|
||||
|
||||
List<ItemContainer<? extends Item>> containers = shc.getWSRoot().list().getContainers();
|
||||
|
||||
for (ItemContainer<? extends Item> container : containers) {
|
||||
|
@ -199,7 +213,7 @@ public class Items {
|
|||
System.out.println("file created "+targetFile.getAbsolutePath());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue