getByPath method added
This commit is contained in:
parent
44e4ebd403
commit
6b013ec305
2
pom.xml
2
pom.xml
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
<groupId>org.gcube.common</groupId>
|
<groupId>org.gcube.common</groupId>
|
||||||
<artifactId>storagehub-client-library</artifactId>
|
<artifactId>storagehub-client-library</artifactId>
|
||||||
<version>1.0.8</version>
|
<version>1.1.0-SNAPSHOT</version>
|
||||||
<name>storagehub-client-library</name>
|
<name>storagehub-client-library</name>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
|
|
|
@ -177,6 +177,19 @@ public class FolderContainer extends ItemContainer<FolderItem>{
|
||||||
return new ListResolver((onlyType, includeHidden, excludes) -> itemclient.findChildrenByNamePattern(itemId, namePattern , excludes), itemclient);
|
return new ListResolver((onlyType, includeHidden, excludes) -> itemclient.findChildrenByNamePattern(itemId, namePattern , excludes), itemclient);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* returns the children of this {@FolderContainer} that matches the name pattern
|
||||||
|
*
|
||||||
|
* @return {@ListResolver}
|
||||||
|
* @throws {@InvalidItemException}
|
||||||
|
* @throws {@UserNotAuthorizedException} if user is not authorized to read this folder
|
||||||
|
*/
|
||||||
|
public OpenResolver openByRelativePath(String relativePath) throws StorageHubException {
|
||||||
|
final String id = this.itemId;
|
||||||
|
return new OpenResolver(itemclient.getByRelativePath(id, relativePath), itemclient);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* returns the items that matches the name pattern searching recursively on all subfolders
|
* returns the items that matches the name pattern searching recursively on all subfolders
|
||||||
|
|
|
@ -37,4 +37,15 @@ public class OpenResolver {
|
||||||
return new URLContainer(itemclient, (ExternalLink)item);
|
return new URLContainer(itemclient, (ExternalLink)item);
|
||||||
else throw new RuntimeException("this item is not a File");
|
else throw new RuntimeException("this item is not a File");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ItemContainer<?> resolve(){
|
||||||
|
if (item instanceof FolderItem)
|
||||||
|
return this.asFolder();
|
||||||
|
if (item instanceof AbstractFileItem)
|
||||||
|
return this.asFile();
|
||||||
|
if (item instanceof ExternalLink)
|
||||||
|
return this.asURL();
|
||||||
|
else return this.asItem();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -436,6 +436,47 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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");
|
||||||
|
Map<String, Object[]> params = new HashMap<>();
|
||||||
|
|
||||||
|
params.put("path",new String[] {path});
|
||||||
|
|
||||||
|
if (excludeNodes !=null && excludeNodes.length>0)
|
||||||
|
params.put("exclude",excludeNodes);
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Item getRootSharedFolder(String id) throws StorageHubException {
|
public Item getRootSharedFolder(String id) throws StorageHubException {
|
||||||
Call<GXWebTargetAdapterRequest, ItemWrapper<Item>> call = new Call<GXWebTargetAdapterRequest, ItemWrapper<Item>>() {
|
Call<GXWebTargetAdapterRequest, ItemWrapper<Item>> call = new Call<GXWebTargetAdapterRequest, ItemWrapper<Item>>() {
|
||||||
|
|
|
@ -36,6 +36,8 @@ public interface ItemManagerClient {
|
||||||
|
|
||||||
Item get(String id, String ... excludeNodes) throws StorageHubException;
|
Item get(String id, String ... excludeNodes) throws StorageHubException;
|
||||||
|
|
||||||
|
Item getByRelativePath(String id, String path, String ... excludeNodes) throws StorageHubException;
|
||||||
|
|
||||||
StreamDescriptor download(String id, String... excludeNodes) throws StorageHubException;
|
StreamDescriptor download(String id, String... excludeNodes) throws StorageHubException;
|
||||||
|
|
||||||
String uploadFile(InputStream stream, String parentId, String fileName, String description) throws StorageHubException;
|
String uploadFile(InputStream stream, String parentId, String fileName, String description) throws StorageHubException;
|
||||||
|
|
|
@ -31,8 +31,8 @@ public class Items {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp(){
|
public static void setUp(){
|
||||||
SecurityTokenProvider.instance.set("b7c80297-e4ed-42ab-ab42-fdc0b8b0eabf-98187548");
|
SecurityTokenProvider.instance.set("52e1492d-4bd1-4058-946f-d2fe5059ddc4-843339462");
|
||||||
ScopeProvider.instance.set("/gcube");
|
ScopeProvider.instance.set("/d4science.research-infrastructures.eu");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -127,19 +127,22 @@ public class Items {
|
||||||
StorageHubClient shc = new StorageHubClient();
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
|
||||||
|
|
||||||
StreamDescriptor streamDescr = shc.open("a5bcf8b8-d149-42c2-92be-7f671223eba4").asFile().downloadSpecificVersion("1.2");
|
StreamDescriptor streamDescr = shc.open("1104d6fc-b2ab-4915-b480-cb60257320a4").asFile().download();
|
||||||
|
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
|
||||||
File output = Files.createTempFile("down", streamDescr.getFileName()).toFile();
|
File output = Files.createTempFile("down", streamDescr.getFileName()).toFile();
|
||||||
try (BufferedInputStream bi = new BufferedInputStream(streamDescr.getStream()); FileOutputStream fo = new FileOutputStream(output)){
|
try (BufferedInputStream bi = new BufferedInputStream(streamDescr.getStream()); FileOutputStream fo = new FileOutputStream(output)){
|
||||||
byte[] buf = new byte[2048];
|
byte[] buf = new byte[2046];
|
||||||
int read = -1;
|
int read = -1;
|
||||||
while ((read=bi.read(buf))!=-1) {
|
while ((read=bi.read(buf))!=-1) {
|
||||||
fo.write(buf, 0, read);
|
fo.write(buf, 0, read);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("file written "+output.getAbsolutePath());
|
|
||||||
|
|
||||||
|
System.out.println("file written "+output.getAbsolutePath()+" in "+(System.currentTimeMillis()-start));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue