git-svn-id: https://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/Common/storagehub-client@181340 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
05b8f286b7
commit
d2baa2dda7
|
@ -4,6 +4,7 @@ public enum ContainerType {
|
|||
|
||||
FOLDER,
|
||||
FILE,
|
||||
GENERIC_ITEM
|
||||
GENERIC_ITEM,
|
||||
URL
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.gcube.common.storagehub.client.dsl;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -57,6 +58,21 @@ public class FolderContainer extends ItemContainer<FolderItem>{
|
|||
return new FileContainer(itemclient, itemclient.uploadFile(stream, this.itemId , filename, description));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* creates a {@ExternalLink} inside the folder represented by this FolderContainer
|
||||
*
|
||||
* @param url the url
|
||||
* @param name the name of the item in the workspace
|
||||
* @param description the description of the item in the workspace
|
||||
* @return {@URLContainer} of the Item created
|
||||
* @throws {@InvalidItemException}
|
||||
* @throws {@UserNotAuthorizedException} if user is not authorized to write in this folder
|
||||
*/
|
||||
public URLContainer addUrl(URL url, String name, String description) throws StorageHubException {
|
||||
return new URLContainer(itemclient, itemclient.createURL(this.itemId, name, description, url));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* creates a set of {@Item} in the workspace extracting the Archive
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.gcube.common.storagehub.client.dsl;
|
|||
|
||||
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
||||
import org.gcube.common.storagehub.model.items.ExternalLink;
|
||||
import org.gcube.common.storagehub.model.items.FolderItem;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
|
||||
|
@ -30,4 +31,10 @@ public class OpenResolver {
|
|||
return new FileContainer(itemclient, (AbstractFileItem)item);
|
||||
else throw new RuntimeException("this item is not a File");
|
||||
}
|
||||
|
||||
public URLContainer asURL() {
|
||||
if (item instanceof ExternalLink)
|
||||
return new URLContainer(itemclient, (ExternalLink)item);
|
||||
else throw new RuntimeException("this item is not a File");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package org.gcube.common.storagehub.client.dsl;
|
||||
|
||||
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||
import org.gcube.common.storagehub.model.items.ExternalLink;
|
||||
|
||||
public class URLContainer extends ItemContainer<ExternalLink> {
|
||||
|
||||
protected URLContainer(ItemManagerClient itemclient, ExternalLink item) {
|
||||
super(itemclient, item);
|
||||
}
|
||||
|
||||
protected URLContainer(ItemManagerClient itemclient, String itemId) {
|
||||
super(itemclient, itemId);
|
||||
}
|
||||
|
||||
public ContainerType getType() {
|
||||
return ContainerType.URL;
|
||||
}
|
||||
|
||||
}
|
|
@ -676,6 +676,48 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String createURL(String parentId, String name, String description,URL url) throws StorageHubException {
|
||||
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("URL");
|
||||
|
||||
MultivaluedMap<String, String> formData = new MultivaluedHashMap<String, String>();
|
||||
formData.add("name", name);
|
||||
formData.add("description", description);
|
||||
formData.add("value", url.toString());
|
||||
|
||||
|
||||
GXInboundResponse response = myManager.post(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED));
|
||||
|
||||
if (response.isErrorResponse()) {
|
||||
if (response.hasException())
|
||||
throw response.getException();
|
||||
else
|
||||
throw new BackendGenericError();
|
||||
}
|
||||
|
||||
return response.getSource().readEntity(String.class);
|
||||
}
|
||||
};
|
||||
try {
|
||||
return delegate.make(call);
|
||||
}catch(StorageHubException e) {
|
||||
throw e;
|
||||
}catch(Exception e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String createGcubeItem(String parentId, GCubeItem item) throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
||||
|
|
|
@ -40,6 +40,8 @@ public interface ItemManagerClient {
|
|||
|
||||
String createFolder(String parentId, String name, String description, boolean hidden) throws StorageHubException;
|
||||
|
||||
String createURL(String parentId, String name, String description, URL url) throws StorageHubException;
|
||||
|
||||
@Deprecated
|
||||
String createFolder(String parentId, String name, String description) throws StorageHubException;
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@ import java.io.File;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
@ -54,9 +56,9 @@ public class Items {
|
|||
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
|
||||
FolderContainer fc = shc.open("7343dd7d-0f2b-4dc7-968e-b856e7073ea8").asFolder();
|
||||
|
||||
fc.newFolder("testLucio","testLucio");
|
||||
|
||||
shc.getWSRoot().addUrl(new URI("https://www.youtube.com/watch?v=bGef_U0S7Uo").toURL(), "video test 3", "video test descr 3");
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue