This commit is contained in:
Lucio Lelii 2018-05-14 14:14:46 +00:00
parent c076518478
commit c7439264ca
4 changed files with 63 additions and 4 deletions

View File

@ -0,0 +1,30 @@
package org.gcube.common.storagehub.model.expressions;
public class OrderField {
public enum MODE{
ASC, DESC
}
private MODE mode;
private SearchableField<?> field;
public OrderField(SearchableField<?> field, MODE mode) {
this.mode = mode;
this.field = field;
}
public OrderField(SearchableField<?> field) {
this.mode = MODE.ASC;
this.field = field;
}
public MODE getMode() {
return mode;
}
public SearchableField<?> getField() {
return field;
}
}

View File

@ -0,0 +1,25 @@
package org.gcube.common.storagehub.model.expressions;
import java.util.Calendar;
import org.gcube.common.storagehub.model.items.AbstractFileItem;
public class SearchableGenericFile extends SearchableItem<AbstractFileItem>{
private static SearchableGenericFile item = new SearchableGenericFile();
public static SearchableGenericFile get() {
return item;
}
protected SearchableGenericFile() {
super(AbstractFileItem.class, "nthl:workspaceLeafItem");
}
public final SearchableField<String> title = new SearchableField<String>(String.class, "jcr:title");
public final SearchableField<Calendar> lastModification = new SearchableField<Calendar>(Calendar.class, "jcr:lastModified");
public final SearchableField<Calendar> creationTime = new SearchableField<Calendar>(Calendar.class, "jcr:created");
}

View File

@ -4,7 +4,9 @@ import java.util.HashMap;
import java.util.Map;
import org.gcube.common.storagehub.model.expressions.GenericSearchableItem;
import org.gcube.common.storagehub.model.expressions.SearchableGenericFile;
import org.gcube.common.storagehub.model.expressions.SearchableItem;
import org.gcube.common.storagehub.model.items.AbstractFileItem;
import org.gcube.common.storagehub.model.items.Item;
public class Queries {
@ -13,6 +15,8 @@ public class Queries {
static {
searchableRegistry.put(Item.class, GenericSearchableItem.get());
searchableRegistry.put(AbstractFileItem.class, SearchableGenericFile.get());
}
public static <T extends Item> Query<SearchableItem<?>> queryFor(Class<T> searchable) {

View File

@ -4,7 +4,7 @@ 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.OrderField;
import org.gcube.common.storagehub.model.expressions.SearchableItem;
public class Query<T extends SearchableItem<?>> {
@ -17,7 +17,7 @@ public class Query<T extends SearchableItem<?>> {
private int offset =-1;
private List<SearchableField<?>> orderFields = null;
private List<OrderField> orderFields = null;
protected Query(T searchableItem) {
this.searchableItem = searchableItem;
@ -27,7 +27,7 @@ public class Query<T extends SearchableItem<?>> {
this.expression= expression;
}
public void setOrder(SearchableField<?> ... fields ) {
public void setOrder(OrderField ... fields ) {
if (fields!=null && fields.length>0)
this.orderFields = Arrays.asList(fields);
}
@ -56,7 +56,7 @@ public class Query<T extends SearchableItem<?>> {
return offset;
}
public List<SearchableField<?>> getOrderFields() {
public List<OrderField> getOrderFields() {
return orderFields;
}