This commit is contained in:
Lucio Lelii 2018-05-23 16:26:06 +00:00
parent 4abf8a5508
commit b39174755f
3 changed files with 42 additions and 2 deletions

View File

@ -7,12 +7,15 @@ import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import org.gcube.common.clients.Call;
import org.gcube.common.clients.delegates.ProxyDelegate;
import org.gcube.common.storagehub.client.StreamDescriptor;
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.gcube.common.storagehub.model.service.ItemList;
import org.gcube.common.storagehub.model.service.ItemWrapper;
@ -159,6 +162,29 @@ public class DefaultItemManager implements ItemManagerClient {
}
}
@Override
public FolderItem createFolder(String parentId, String name, String description) {
Call<WebTarget, ItemWrapper<FolderItem>> call = new Call<WebTarget, ItemWrapper<FolderItem>>() {
@Override
public ItemWrapper<FolderItem> call(WebTarget manager) throws Exception {
WebTarget myManager = manager.path(parentId)
.path("create").path("FOLDER").queryParam("name", name).queryParam("description", description);
Invocation.Builder builder = myManager.request();
MultivaluedMap<String, String> formData = new MultivaluedHashMap<String, String>();
formData.add("name", name);
formData.add("description", description);
ItemWrapper<FolderItem> response = builder.post(Entity.form(formData),ItemWrapper.class);
return response;
}
};
try {
ItemWrapper<FolderItem> result = delegate.make(call);
return result.getItem();
}catch(Exception e) {
throw new RuntimeException(e);
}
}
@Override
public List<? extends Item> getAnchestors(String id, String... excludeNodes) {

View File

@ -5,6 +5,7 @@ import java.util.List;
import org.gcube.common.storagehub.client.StreamDescriptor;
import org.gcube.common.storagehub.model.items.AbstractFileItem;
import org.gcube.common.storagehub.model.items.FolderItem;
import org.gcube.common.storagehub.model.items.Item;
@ -27,4 +28,6 @@ public interface ItemManagerClient {
<T extends AbstractFileItem> T uploadFile(InputStream stream, String parentId, String fileName, String description);
FolderItem createFolder(String parentId, String name, String description);
}

View File

@ -58,10 +58,13 @@ public class TestCall {
@Test
public void getById() throws Exception{
final ItemManagerClient client = AbstractPlugin.item().build();
List<? extends Item> items = client.getChildren("07cd8d55-a35b-4445-9680-c98f158c55de",10, 5, "hl:accounting", "jcr:content");
List<? extends Item> items = client.getAnchestors("29b417e2-dc2f-419a-be0b-7f49e76c9d7c", "hl:accounting", "jcr:content");
System.out.println("items are "+items.size());
for (Item item: items)
System.out.println(item.getName()+ " "+item.getPath());
System.in.read();
}
@ -102,6 +105,14 @@ public class TestCall {
}
@Test
public void createFolder() {
ItemManagerClient itemclient = AbstractPlugin.item().build();
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
itemclient.createFolder(wsclient.getWorkspace().getId(),"terzo tentativo","secondo tentativo");
}
@Test
public void search() {