From 397add5f3ef9de392e707f7890e1360211a00747 Mon Sep 17 00:00:00 2001 From: Lucio Lelii Date: Fri, 20 Apr 2018 16:26:38 +0000 Subject: [PATCH] git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/storagehub-model@167148 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../model/expressions/Expression.java | 3 ++ .../expressions/GenericSearchableItem.java | 2 +- .../model/expressions/SearchableField.java | 2 + .../model/expressions/SearchableItem.java | 14 ++++- .../model/expressions/logical/And.java | 2 + .../expressions/logical/ISDescendant.java | 18 +++++++ .../model/expressions/text/Contains.java | 2 + .../model/items/AbstractFileItem.java | 2 - .../storagehub/model/query/ItemFilter.java | 7 --- .../storagehub/model/query/OrderBy.java | 5 -- .../storagehub/model/query/Queries.java | 2 +- .../common/storagehub/model/query/Query.java | 52 ++++++++++++++++++- 12 files changed, 92 insertions(+), 19 deletions(-) create mode 100644 src/main/java/org/gcube/common/storagehub/model/expressions/logical/ISDescendant.java delete mode 100644 src/main/java/org/gcube/common/storagehub/model/query/ItemFilter.java delete mode 100644 src/main/java/org/gcube/common/storagehub/model/query/OrderBy.java diff --git a/src/main/java/org/gcube/common/storagehub/model/expressions/Expression.java b/src/main/java/org/gcube/common/storagehub/model/expressions/Expression.java index e95447b..384619f 100644 --- a/src/main/java/org/gcube/common/storagehub/model/expressions/Expression.java +++ b/src/main/java/org/gcube/common/storagehub/model/expressions/Expression.java @@ -1,5 +1,8 @@ package org.gcube.common.storagehub.model.expressions; +import com.fasterxml.jackson.annotation.JsonTypeInfo; + +@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.PROPERTY, property="@class") public interface Expression { } diff --git a/src/main/java/org/gcube/common/storagehub/model/expressions/GenericSearchableItem.java b/src/main/java/org/gcube/common/storagehub/model/expressions/GenericSearchableItem.java index 29770c2..0efdf42 100644 --- a/src/main/java/org/gcube/common/storagehub/model/expressions/GenericSearchableItem.java +++ b/src/main/java/org/gcube/common/storagehub/model/expressions/GenericSearchableItem.java @@ -13,7 +13,7 @@ public class GenericSearchableItem extends SearchableItem{ } protected GenericSearchableItem() { - super(Item.class); + super(Item.class,"nthl:workspaceItem"); } public final SearchableField title = new SearchableField(String.class, "jcr:title"); diff --git a/src/main/java/org/gcube/common/storagehub/model/expressions/SearchableField.java b/src/main/java/org/gcube/common/storagehub/model/expressions/SearchableField.java index ca746ed..a6bb971 100644 --- a/src/main/java/org/gcube/common/storagehub/model/expressions/SearchableField.java +++ b/src/main/java/org/gcube/common/storagehub/model/expressions/SearchableField.java @@ -6,6 +6,8 @@ public final class SearchableField { private String name; + protected SearchableField() {} + protected SearchableField(Class _class, String name) { this.type = _class; this.name = name; diff --git a/src/main/java/org/gcube/common/storagehub/model/expressions/SearchableItem.java b/src/main/java/org/gcube/common/storagehub/model/expressions/SearchableItem.java index dbd3fd1..267e7ab 100644 --- a/src/main/java/org/gcube/common/storagehub/model/expressions/SearchableItem.java +++ b/src/main/java/org/gcube/common/storagehub/model/expressions/SearchableItem.java @@ -4,10 +4,20 @@ import org.gcube.common.storagehub.model.items.Item; public class SearchableItem { - Class type; + private Class type; + private String nodeValue; - protected SearchableItem(Class _class){ + protected SearchableItem(Class _class, String nodeValue){ this.type = _class; + this.nodeValue = nodeValue; + } + + public Class getType() { + return type; + } + + public String getNodeValue() { + return nodeValue; } } diff --git a/src/main/java/org/gcube/common/storagehub/model/expressions/logical/And.java b/src/main/java/org/gcube/common/storagehub/model/expressions/logical/And.java index 5392959..8355975 100644 --- a/src/main/java/org/gcube/common/storagehub/model/expressions/logical/And.java +++ b/src/main/java/org/gcube/common/storagehub/model/expressions/logical/And.java @@ -11,6 +11,8 @@ public class And implements Expression{ private List> expressions = new ArrayList<>(); + protected And() {} + public And(Expression first , Expression second , Expression ... others ) { expressions = Arrays.asList(first, second); if (others !=null && others.length>0) diff --git a/src/main/java/org/gcube/common/storagehub/model/expressions/logical/ISDescendant.java b/src/main/java/org/gcube/common/storagehub/model/expressions/logical/ISDescendant.java new file mode 100644 index 0000000..8e75780 --- /dev/null +++ b/src/main/java/org/gcube/common/storagehub/model/expressions/logical/ISDescendant.java @@ -0,0 +1,18 @@ +package org.gcube.common.storagehub.model.expressions.logical; + +import org.gcube.common.storagehub.model.Path; +import org.gcube.common.storagehub.model.expressions.Expression; + +public class ISDescendant implements Expression{ + + private Path path; + + public ISDescendant(Path path) { + this.path = path; + } + + public Path getPath() { + return path; + } + +} diff --git a/src/main/java/org/gcube/common/storagehub/model/expressions/text/Contains.java b/src/main/java/org/gcube/common/storagehub/model/expressions/text/Contains.java index 1bb12e9..8a5a6e0 100644 --- a/src/main/java/org/gcube/common/storagehub/model/expressions/text/Contains.java +++ b/src/main/java/org/gcube/common/storagehub/model/expressions/text/Contains.java @@ -8,6 +8,8 @@ public class Contains implements Expression { private SearchableField searchableField; private String value; + + protected Contains() {} public Contains(SearchableField searchableField, String value) { super(); diff --git a/src/main/java/org/gcube/common/storagehub/model/items/AbstractFileItem.java b/src/main/java/org/gcube/common/storagehub/model/items/AbstractFileItem.java index 9501295..2e8da34 100644 --- a/src/main/java/org/gcube/common/storagehub/model/items/AbstractFileItem.java +++ b/src/main/java/org/gcube/common/storagehub/model/items/AbstractFileItem.java @@ -1,7 +1,5 @@ package org.gcube.common.storagehub.model.items; -import java.util.List; - import org.gcube.common.storagehub.model.items.nodes.Content; public abstract class AbstractFileItem extends Item{ diff --git a/src/main/java/org/gcube/common/storagehub/model/query/ItemFilter.java b/src/main/java/org/gcube/common/storagehub/model/query/ItemFilter.java deleted file mode 100644 index d1e8b2f..0000000 --- a/src/main/java/org/gcube/common/storagehub/model/query/ItemFilter.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.gcube.common.storagehub.model.query; - -import org.gcube.common.storagehub.model.items.Item; - -public interface ItemFilter { - -} diff --git a/src/main/java/org/gcube/common/storagehub/model/query/OrderBy.java b/src/main/java/org/gcube/common/storagehub/model/query/OrderBy.java deleted file mode 100644 index 5052e42..0000000 --- a/src/main/java/org/gcube/common/storagehub/model/query/OrderBy.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.gcube.common.storagehub.model.query; - -public interface OrderBy { - -} diff --git a/src/main/java/org/gcube/common/storagehub/model/query/Queries.java b/src/main/java/org/gcube/common/storagehub/model/query/Queries.java index b4f6e61..63b7ea3 100644 --- a/src/main/java/org/gcube/common/storagehub/model/query/Queries.java +++ b/src/main/java/org/gcube/common/storagehub/model/query/Queries.java @@ -12,7 +12,7 @@ public class Queries { private static Map,SearchableItem> searchableRegistry = new HashMap<>(); static { - searchableRegistry.put(GenericSearchableItem.class, GenericSearchableItem.get()); + searchableRegistry.put(Item.class, GenericSearchableItem.get()); } public static Query> queryFor(Class searchable) { diff --git a/src/main/java/org/gcube/common/storagehub/model/query/Query.java b/src/main/java/org/gcube/common/storagehub/model/query/Query.java index ce239f1..b334b92 100644 --- a/src/main/java/org/gcube/common/storagehub/model/query/Query.java +++ b/src/main/java/org/gcube/common/storagehub/model/query/Query.java @@ -1,13 +1,63 @@ package org.gcube.common.storagehub.model.query; +import java.util.Arrays; +import java.util.List; + +import org.gcube.common.storagehub.model.expressions.Expression; +import org.gcube.common.storagehub.model.expressions.SearchableField; import org.gcube.common.storagehub.model.expressions.SearchableItem; public class Query> { private T searchableItem; - public Query(T searchableItem) { + private Expression expression; + + private int limit = -1; + + private int offset =-1; + + private List> orderFields = null; + + protected Query(T searchableItem) { this.searchableItem = searchableItem; } + public void setExpression(Expression expression) { + this.expression= expression; + } + + public void setOrder(SearchableField ... fields ) { + if (fields!=null && fields.length>0) + this.orderFields = Arrays.asList(fields); + } + + public void setLimit(int limit) { + this.limit = limit; + } + + public void setOffset(int offset) { + this.offset = offset; + } + + public T getSearchableItem() { + return searchableItem; + } + + public Expression getExpression() { + return expression; + } + + public int getLimit() { + return limit; + } + + public int getOffset() { + return offset; + } + + public List> getOrderFields() { + return orderFields; + } + }