This commit is contained in:
Lucio Lelii 2018-04-19 17:00:44 +00:00
parent fdbc419887
commit 7c6a489248
6 changed files with 64 additions and 2 deletions

View File

@ -15,7 +15,14 @@ public final class SearchableField<T> {
public String toString() {
return "[" + name +"]";
}
public Class<T> getType() {
return type;
}
public String getName() {
return name;
}
}

View File

@ -9,13 +9,17 @@ import org.gcube.common.storagehub.model.expressions.Expression;
public class And implements Expression<Boolean>{
List<Expression<Boolean>> expressions = new ArrayList<>();
private List<Expression<Boolean>> expressions = new ArrayList<>();
public And(Expression<Boolean> first , Expression<Boolean> second , Expression<Boolean> ... others ) {
expressions = Arrays.asList(first, second);
if (others !=null && others.length>0)
expressions.addAll(Arrays.asList(others));
}
public List<Expression<Boolean>> getExpressions() {
return expressions;
}
@Override
public String toString() {

View File

@ -16,6 +16,10 @@ public class Or implements Expression<Boolean>{
if (others !=null && others.length>0)
expressions.addAll(Arrays.asList(others));
}
public List<Expression<Boolean>> getExpressions() {
return expressions;
}
@Override
public String toString() {

View File

@ -0,0 +1,22 @@
package org.gcube.common.storagehub.model.query;
import java.util.HashMap;
import java.util.Map;
import org.gcube.common.storagehub.model.expressions.GenericSearchableItem;
import org.gcube.common.storagehub.model.expressions.SearchableItem;
import org.gcube.common.storagehub.model.items.Item;
public class Queries {
private static Map<Class<?>,SearchableItem<?>> searchableRegistry = new HashMap<>();
static {
searchableRegistry.put(GenericSearchableItem.class, GenericSearchableItem.get());
}
public static <T extends Item> Query<SearchableItem<?>> queryFor(Class<T> searchable) {
return new Query<>(searchableRegistry.get(searchable));
}
}

View File

@ -0,0 +1,13 @@
package org.gcube.common.storagehub.model.query;
import org.gcube.common.storagehub.model.expressions.SearchableItem;
public class Query<T extends SearchableItem<?>> {
private T searchableItem;
public Query(T searchableItem) {
this.searchableItem = searchableItem;
}
}

View File

@ -1,7 +1,11 @@
package org.gcube.storagehub.model.expressions;
import java.util.Calendar;
import org.gcube.common.storagehub.model.expressions.Expression;
import org.gcube.common.storagehub.model.expressions.GenericSearchableItem;
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.text.Contains;
import org.junit.Test;
@ -12,7 +16,15 @@ public class ExpressionsTest {
public void contains() {
Expression<Boolean> expr = new Contains(GenericSearchableItem.get().title, "Data");
System.out.println( expr.toString());
}
@Test
public void and() {
Expression<Boolean> cont1 = new Contains(GenericSearchableItem.get().title, "Data");
Expression<Boolean> before = new Before(GenericSearchableItem.get().creationTime, Calendar.getInstance());
Expression<Boolean> andExpr = new And(cont1, before);
System.out.println( andExpr.toString());
}
}