This commit is contained in:
Lucio Lelii 2018-10-15 13:39:02 +00:00
parent 9b7f1ea469
commit 3f18f6c41a
5 changed files with 72 additions and 10 deletions

View File

@ -2,6 +2,7 @@ package org.gcube.common.storagehub.client.dsl;
import org.gcube.common.storagehub.client.StreamDescriptor;
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
import org.gcube.common.storagehub.model.Metadata;
import org.gcube.common.storagehub.model.items.FolderItem;
import org.gcube.common.storagehub.model.items.Item;
@ -12,6 +13,8 @@ public abstract class ItemContainer<I extends Item> {
protected String itemId = null;
protected I item;
boolean invalidated = false;
protected ItemContainer(ItemManagerClient itemclient, I item) {
this.itemclient = itemclient;
this.itemId = item.getId();
@ -36,14 +39,18 @@ public abstract class ItemContainer<I extends Item> {
@SuppressWarnings("unchecked")
public I get() {
if (item==null) return (I)itemclient.get(itemId);
if (item==null || invalidated) {
I toRet = (I)itemclient.get(itemId);
invalidated = false;
return toRet;
}
else return item;
}
private I get(boolean reset) {
this.item = (I)itemclient.get(itemId);
return this.item;
protected void invalidateItem() {
invalidated = true;
}
public StreamDescriptor download(String ... nodeIdsToExclude) {
return itemclient.download(this.itemId, nodeIdsToExclude);
@ -55,18 +62,22 @@ public abstract class ItemContainer<I extends Item> {
public void delete() {
itemclient.delete(this.itemId);
invalidateItem();
}
public OpenResolver rename(String newName) {
public void rename(String newName) {
itemclient.rename(this.getId(), newName);
return new OpenResolver(this.get(true), itemclient);
invalidateItem();
}
public OpenResolver move(FolderContainer folder) {
public void move(FolderContainer folder) {
itemclient.move(this.getId(), folder.getId());
return new OpenResolver(this.get(true), itemclient);
invalidateItem();
}
public void setMetadata(Metadata metadata) {
itemclient.setMetadata(this.getId(), metadata);
invalidateItem();
}
public FolderContainer getRootSharedFolder() {

View File

@ -18,6 +18,7 @@ import org.gcube.common.clients.delegates.ProxyDelegate;
import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest;
import org.gcube.common.gxrest.response.inbound.GXInboundResponse;
import org.gcube.common.storagehub.client.StreamDescriptor;
import org.gcube.common.storagehub.model.Metadata;
import org.gcube.common.storagehub.model.acls.ACL;
import org.gcube.common.storagehub.model.acls.AccessType;
import org.gcube.common.storagehub.model.annotations.RootNode;
@ -736,5 +737,34 @@ public class DefaultItemManager implements ItemManagerClient {
throw new RuntimeException(e);
}
}
@Override
public String setMetadata(String id, Metadata metadata) {
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
@Override
public String call(GXWebTargetAdapterRequest manager) throws Exception {
GXWebTargetAdapterRequest myManager = manager.path(id)
.path("metadata");
GXInboundResponse response = myManager.put(Entity.json(metadata));
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(Exception e) {
throw new RuntimeException(e);
}
}
}

View File

@ -6,6 +6,7 @@ import java.util.List;
import java.util.Set;
import org.gcube.common.storagehub.client.StreamDescriptor;
import org.gcube.common.storagehub.model.Metadata;
import org.gcube.common.storagehub.model.acls.ACL;
import org.gcube.common.storagehub.model.acls.AccessType;
import org.gcube.common.storagehub.model.items.Item;
@ -63,4 +64,6 @@ public interface ItemManagerClient {
StreamDescriptor downloadSpecificVersion(String id, String version);
String setMetadata(String id,Metadata metadata);
}

View File

@ -202,6 +202,9 @@ public class Items {
}
/*
static String baseUrl="http://workspace-repository1-d.d4science.org/storagehub";

View File

@ -7,6 +7,7 @@ import java.io.FileOutputStream;
import java.net.URI;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.regex.Matcher;
@ -24,6 +25,7 @@ import org.gcube.common.storagehub.client.StreamDescriptor;
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
import org.gcube.common.storagehub.model.Metadata;
import org.gcube.common.storagehub.model.Paths;
import org.gcube.common.storagehub.model.acls.ACL;
import org.gcube.common.storagehub.model.acls.AccessType;
@ -131,6 +133,19 @@ public class TestCall {
System.in.read();
}
@Test
public void setMetadata() {
final ItemManagerClient client = AbstractPlugin.item().build();
Metadata meta = new Metadata();
HashMap<String, Object> prop = new HashMap<>();
prop.put("folderProp", "test2");
prop.put("folderProp2", "test2");
meta.setValues(prop);
client.setMetadata("8822478a-4fd3-41d5-87de-9ff161d0935e", meta);
}
@Test
public void upload() throws Exception{