This commit is contained in:
Lucio Lelii 2018-04-20 16:26:44 +00:00
parent 7c7d7f9a50
commit fe50f4983b
3 changed files with 61 additions and 0 deletions

View File

@ -1,17 +1,24 @@
package org.gcube.common.storagehub.client.proxies;
import java.net.URLEncoder;
import java.util.List;
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 org.gcube.common.clients.Call;
import org.gcube.common.clients.delegates.ProxyDelegate;
import org.gcube.common.storagehub.model.expressions.SearchableItem;
import org.gcube.common.storagehub.model.items.Item;
import org.gcube.common.storagehub.model.query.Query;
import org.gcube.common.storagehub.model.service.ItemList;
import org.gcube.common.storagehub.model.service.ItemWrapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
public class DefaultWorkspaceManager implements WorkspaceManagerClient {
private final ProxyDelegate<WebTarget> delegate;
@ -111,4 +118,35 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient {
}
}
@Override
public List<? extends Item> search(Query<SearchableItem<?>> query, String ... excludeNodes) {
Call<WebTarget, ItemList> call = new Call<WebTarget, ItemList>() {
@Override
public ItemList call(WebTarget manager) throws Exception {
WebTarget myManager = manager.path("query");
if (excludeNodes !=null && excludeNodes.length>0)
myManager = myManager.queryParam("exclude",excludeNodes);
myManager = myManager.queryParam("node", query.getSearchableItem().getNodeValue());
ObjectMapper mapper = new ObjectMapper();
String serializedJson = mapper.writeValueAsString(query.getExpression());
System.out.println("serialized json "+serializedJson);
myManager = myManager.queryParam("expr", URLEncoder.encode(serializedJson));
Invocation.Builder builder = myManager.request(MediaType.APPLICATION_JSON);
ItemList response = builder.get(ItemList.class);
return response;
}
};
try {
ItemList result = delegate.make(call);
return result.getItemlist();
}catch(Exception e) {
throw new RuntimeException(e);
}
}
}

View File

@ -2,7 +2,9 @@ package org.gcube.common.storagehub.client.proxies;
import java.util.List;
import org.gcube.common.storagehub.model.expressions.SearchableItem;
import org.gcube.common.storagehub.model.items.Item;
import org.gcube.common.storagehub.model.query.Query;
public interface WorkspaceManagerClient {
@ -13,5 +15,7 @@ public interface WorkspaceManagerClient {
List<? extends Item> getVreFolders(int start, int limit, String ... excludeNodes);
<T extends Item> T getVreFolder(String ... excludeNodes);
List<? extends Item> search(Query<SearchableItem<?>> query, String ... excludeNodes);
}

View File

@ -12,7 +12,12 @@ 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.expressions.GenericSearchableItem;
import org.gcube.common.storagehub.model.expressions.SearchableItem;
import org.gcube.common.storagehub.model.expressions.text.Contains;
import org.gcube.common.storagehub.model.items.Item;
import org.gcube.common.storagehub.model.query.Queries;
import org.gcube.common.storagehub.model.query.Query;
import org.junit.BeforeClass;
import org.junit.Test;
@ -87,6 +92,20 @@ public class TestCall {
}
@Test
public void search() {
Query<SearchableItem<?>> query = Queries.queryFor(Item.class);
query.setExpression(new Contains(GenericSearchableItem.get().title, "Data"));
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
List<? extends Item> items = wsclient.search(query, "hl:accounting", "jcr:content");
System.out.println("items are "+items.size());
}
/*
@Test
public void createFolder() throws Exception{