This commit is contained in:
Lucio Lelii 2018-05-07 16:05:54 +00:00
parent fe50f4983b
commit e0043388c9
2 changed files with 29 additions and 5 deletions

View File

@ -10,6 +10,7 @@ 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.SearchableField;
import org.gcube.common.storagehub.model.expressions.SearchableItem;
import org.gcube.common.storagehub.model.items.Item;
import org.gcube.common.storagehub.model.query.Query;
@ -126,15 +127,30 @@ public class DefaultWorkspaceManager implements WorkspaceManagerClient {
WebTarget myManager = manager.path("query");
if (excludeNodes !=null && excludeNodes.length>0)
myManager = myManager.queryParam("exclude",excludeNodes);
myManager = myManager.queryParam("node", query.getSearchableItem().getNodeValue());
if (query.getOrderFields() !=null && query.getOrderFields().size() >0) {
for (SearchableField<?> field :query.getOrderFields())
myManager = myManager.queryParam("o",field);
}
myManager = myManager.queryParam("n", query.getSearchableItem().getNodeValue());
if (query.getLimit()!=-1)
myManager = myManager.queryParam("l", query.getLimit());
if (query.getOffset()!=-1)
myManager = myManager.queryParam("f", query.getOffset());
ObjectMapper mapper = new ObjectMapper();
String serializedJson = mapper.writeValueAsString(query.getExpression());
System.out.println("serialized json "+serializedJson);
myManager = myManager.queryParam("expr", URLEncoder.encode(serializedJson));
myManager = myManager.queryParam("e", URLEncoder.encode(serializedJson));
System.out.println(myManager.getUri().toString());
Invocation.Builder builder = myManager.request(MediaType.APPLICATION_JSON);
ItemList response = builder.get(ItemList.class);

View File

@ -4,6 +4,7 @@ import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.util.Calendar;
import java.util.List;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
@ -12,8 +13,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.Paths;
import org.gcube.common.storagehub.model.expressions.GenericSearchableItem;
import org.gcube.common.storagehub.model.expressions.SearchableItem;
import org.gcube.common.storagehub.model.expressions.date.Before;
import org.gcube.common.storagehub.model.expressions.logical.And;
import org.gcube.common.storagehub.model.expressions.logical.ISDescendant;
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;
@ -97,9 +102,12 @@ public class TestCall {
Query<SearchableItem<?>> query = Queries.queryFor(Item.class);
query.setExpression(new Contains(GenericSearchableItem.get().title, "Data"));
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, 2015);
query.setExpression(new And(new Contains(GenericSearchableItem.get().title, "Data"), new ISDescendant(Paths.getPath("/Home/lucio.lelii/Workspace/DataMiner")), new Before(GenericSearchableItem.get().creationTime, calendar )));
query.setLimit(10);
query.setOrder(GenericSearchableItem.get().title);
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
List<? extends Item> items = wsclient.search(query, "hl:accounting", "jcr:content");
System.out.println("items are "+items.size());