feature_22506 #3
|
@ -18,7 +18,9 @@ import org.gcube.application.geoportal.common.rest.MongoConcessioni;
|
||||||
import org.gcube.application.geoportalcommon.shared.ItemField;
|
import org.gcube.application.geoportalcommon.shared.ItemField;
|
||||||
import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData;
|
import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData;
|
||||||
import org.gcube.application.geoportalcommon.shared.SearchingFilter;
|
import org.gcube.application.geoportalcommon.shared.SearchingFilter;
|
||||||
|
import org.gcube.application.geoportalcommon.shared.SearchingFilter.LOGICAL_OP;
|
||||||
import org.gcube.application.geoportalcommon.shared.SearchingFilter.ORDER;
|
import org.gcube.application.geoportalcommon.shared.SearchingFilter.ORDER;
|
||||||
|
import org.gcube.application.geoportalcommon.shared.WhereClause;
|
||||||
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
|
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -169,9 +171,17 @@ public class MongoServiceCommon {
|
||||||
|
|
||||||
request.setOrdering(ordering);
|
request.setOrdering(ordering);
|
||||||
|
|
||||||
Document query = null;
|
Document query = new Document();
|
||||||
if (filter.getSearchInto() != null) {
|
if(filter.getConditions()!=null) {
|
||||||
Map<String, Object> searchFields = filter.getSearchInto();
|
for (WhereClause whereClause : filter.getConditions()) {
|
||||||
|
|
||||||
|
LOGICAL_OP searchWithOperator = whereClause.getOperator();
|
||||||
|
if(searchWithOperator==null) {
|
||||||
|
searchWithOperator = LOGICAL_OP.OR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (whereClause.getSearchInto() != null) {
|
||||||
|
Map<String, Object> searchFields = whereClause.getSearchInto();
|
||||||
BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
|
BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
|
||||||
for (String key : searchFields.keySet()) {
|
for (String key : searchFields.keySet()) {
|
||||||
// using regex and case-insensitive
|
// using regex and case-insensitive
|
||||||
|
@ -191,15 +201,24 @@ public class MongoServiceCommon {
|
||||||
Document doc = new Document((String) key, value);
|
Document doc = new Document((String) key, value);
|
||||||
list.add(doc);
|
list.add(doc);
|
||||||
}
|
}
|
||||||
query = new Document();
|
|
||||||
query.put("$or", list);
|
//query = new Document();
|
||||||
request.setFilter(query);
|
query.put(searchWithOperator.getOperator(), list);
|
||||||
|
|
||||||
|
// BasicDBObject bs = new BasicDBObject();
|
||||||
|
// bs.append("$eq", "PASSED");
|
||||||
|
// query.put("report.status", bs);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
request.setFilter(query);
|
||||||
|
|
||||||
LOG.info("Paging offset: " + offsetIndex + ", limit: " + limitIndex);
|
LOG.info("Paging offset: " + offsetIndex + ", limit: " + limitIndex);
|
||||||
LOG.info("Direction: " + sDirection);
|
LOG.info("Direction: " + sDirection);
|
||||||
LOG.info("Order by Fields: " + orderingFields);
|
LOG.info("Order by Fields: " + orderingFields);
|
||||||
LOG.info("Search for: " + filter.getSearchInto());
|
LOG.info("Search for conditions: " + filter.getConditions());
|
||||||
if (query != null) {
|
if (query != null) {
|
||||||
LOG.info("Search query to JSON: " + query.toJson());
|
LOG.info("Search query to JSON: " + query.toJson());
|
||||||
}
|
}
|
||||||
|
@ -211,7 +230,7 @@ public class MongoServiceCommon {
|
||||||
ConcessioneDV concessioneDV = ConvertToDataViewModel.toMetadataConcessione(concessione, true);
|
ConcessioneDV concessioneDV = ConvertToDataViewModel.toMetadataConcessione(concessione, true);
|
||||||
toReturnList.add(concessioneDV);
|
toReturnList.add(concessioneDV);
|
||||||
i++;
|
i++;
|
||||||
LOG.trace("converted: " + concessioneDV);
|
LOG.trace(i+") converted: " + concessioneDV);
|
||||||
}
|
}
|
||||||
LOG.debug("read " + toReturnList + " project/s");
|
LOG.debug("read " + toReturnList + " project/s");
|
||||||
|
|
||||||
|
@ -219,8 +238,9 @@ public class MongoServiceCommon {
|
||||||
|
|
||||||
// TODO WORKAROUND MUST BE REMOVE AFTER THE QUERY COUNT
|
// TODO WORKAROUND MUST BE REMOVE AFTER THE QUERY COUNT
|
||||||
// AND LIST.SIZE WILL BE AVAILABLE IN THE SERVICE
|
// AND LIST.SIZE WILL BE AVAILABLE IN THE SERVICE
|
||||||
if (filter.getSearchInto() != null) {
|
if (filter.getConditions() != null) {
|
||||||
searchedData.setTotalItems(toReturnList.size());
|
searchedData.setTotalItems(toReturnList.size());
|
||||||
|
totalItems = toReturnList.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (totalItems == limit || totalItems == 0) {
|
if (totalItems == limit || totalItems == 0) {
|
||||||
|
|
|
@ -2,7 +2,6 @@ package org.gcube.application.geoportalcommon.shared;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class SearchingFilter.
|
* The Class SearchingFilter.
|
||||||
|
@ -44,6 +43,37 @@ public class SearchingFilter implements Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Enum LOGICAL_OP.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* Dec 15, 2021
|
||||||
|
*/
|
||||||
|
public static enum LOGICAL_OP {
|
||||||
|
AND("$and"), OR("$or");
|
||||||
|
|
||||||
|
String operator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new order.
|
||||||
|
*
|
||||||
|
* @param operator the operator
|
||||||
|
*/
|
||||||
|
LOGICAL_OP(String operator) {
|
||||||
|
this.operator = operator;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the operator.
|
||||||
|
*
|
||||||
|
* @return the operator
|
||||||
|
*/
|
||||||
|
public String getOperator() {
|
||||||
|
return operator;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -51,9 +81,9 @@ public class SearchingFilter implements Serializable {
|
||||||
|
|
||||||
private List<ItemField> orderByFields;
|
private List<ItemField> orderByFields;
|
||||||
|
|
||||||
private ORDER order;
|
private ORDER order = ORDER.ASC;
|
||||||
|
|
||||||
private Map<String, Object> searchInto;
|
private List<WhereClause> conditions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new sort filter.
|
* Instantiates a new sort filter.
|
||||||
|
@ -80,19 +110,18 @@ public class SearchingFilter implements Serializable {
|
||||||
* @param order the order
|
* @param order the order
|
||||||
* @param searchInto the search into
|
* @param searchInto the search into
|
||||||
*/
|
*/
|
||||||
public SearchingFilter(List<ItemField> orderByFields, ORDER order, Map<String, Object> searchInto) {
|
public SearchingFilter(List<ItemField> orderByFields, ORDER order, List<WhereClause> conditions) {
|
||||||
this.orderByFields = orderByFields;
|
this.orderByFields = orderByFields;
|
||||||
this.order = order;
|
this.order = order;
|
||||||
this.searchInto = searchInto;
|
this.conditions = conditions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public List<WhereClause> getConditions() {
|
||||||
* Sets the search into.
|
return conditions;
|
||||||
*
|
}
|
||||||
* @param searchInto the search into
|
|
||||||
*/
|
public void setConditions(List<WhereClause> conditions) {
|
||||||
public void setSearchInto(Map<String, Object> searchInto) {
|
this.conditions = conditions;
|
||||||
this.searchInto = searchInto;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -131,15 +160,6 @@ public class SearchingFilter implements Serializable {
|
||||||
this.order = order;
|
this.order = order;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the search into.
|
|
||||||
*
|
|
||||||
* @return the search into
|
|
||||||
*/
|
|
||||||
public Map<String, Object> getSearchInto() {
|
|
||||||
return searchInto;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
@ -147,8 +167,8 @@ public class SearchingFilter implements Serializable {
|
||||||
builder.append(orderByFields);
|
builder.append(orderByFields);
|
||||||
builder.append(", order=");
|
builder.append(", order=");
|
||||||
builder.append(order);
|
builder.append(order);
|
||||||
builder.append(", searchInto=");
|
builder.append(", conditions=");
|
||||||
builder.append(searchInto);
|
builder.append(conditions);
|
||||||
builder.append("]");
|
builder.append("]");
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,97 @@
|
||||||
|
package org.gcube.application.geoportalcommon.shared;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.gcube.application.geoportalcommon.shared.SearchingFilter.LOGICAL_OP;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class WhereClause.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* Dec 15, 2021
|
||||||
|
*/
|
||||||
|
public class WhereClause implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = -8577885822669878296L;
|
||||||
|
|
||||||
|
private LOGICAL_OP operator = LOGICAL_OP.OR;
|
||||||
|
|
||||||
|
private Map<String, Object> searchInto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new where clause.
|
||||||
|
*/
|
||||||
|
public WhereClause() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new where clause.
|
||||||
|
*
|
||||||
|
* @param operator the operator
|
||||||
|
* @param searchInto the search into
|
||||||
|
*/
|
||||||
|
public WhereClause(LOGICAL_OP operator, Map<String, Object> searchInto) {
|
||||||
|
super();
|
||||||
|
this.operator = operator;
|
||||||
|
this.searchInto = searchInto;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the operator.
|
||||||
|
*
|
||||||
|
* @return the operator
|
||||||
|
*/
|
||||||
|
public LOGICAL_OP getOperator() {
|
||||||
|
return operator;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the search into.
|
||||||
|
*
|
||||||
|
* @return the search into
|
||||||
|
*/
|
||||||
|
public Map<String, Object> getSearchInto() {
|
||||||
|
return searchInto;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the operator.
|
||||||
|
*
|
||||||
|
* @param operator the new operator
|
||||||
|
*/
|
||||||
|
public void setOperator(LOGICAL_OP operator) {
|
||||||
|
this.operator = operator;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the search into.
|
||||||
|
*
|
||||||
|
* @param searchInto the search into
|
||||||
|
*/
|
||||||
|
public void setSearchInto(Map<String, Object> searchInto) {
|
||||||
|
this.searchInto = searchInto;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To string.
|
||||||
|
*
|
||||||
|
* @return the string
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("WhereClause [operator=");
|
||||||
|
builder.append(operator);
|
||||||
|
builder.append(", searchInto=");
|
||||||
|
builder.append(searchInto);
|
||||||
|
builder.append("]");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package org.gcube.application;
|
package org.gcube.application;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -10,6 +11,8 @@ import org.gcube.application.geoportalcommon.shared.GeoNaDataViewerProfile;
|
||||||
import org.gcube.application.geoportalcommon.shared.GeoNaItemRef;
|
import org.gcube.application.geoportalcommon.shared.GeoNaItemRef;
|
||||||
import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData;
|
import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData;
|
||||||
import org.gcube.application.geoportalcommon.shared.SearchingFilter;
|
import org.gcube.application.geoportalcommon.shared.SearchingFilter;
|
||||||
|
import org.gcube.application.geoportalcommon.shared.WhereClause;
|
||||||
|
import org.gcube.application.geoportalcommon.shared.SearchingFilter.LOGICAL_OP;
|
||||||
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
|
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
|
||||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
@ -59,9 +62,20 @@ public class TestGNACommon {
|
||||||
SearchingFilter filter = new SearchingFilter();
|
SearchingFilter filter = new SearchingFilter();
|
||||||
|
|
||||||
Map<String, Object> searchInto = new HashMap<String, Object>();
|
Map<String, Object> searchInto = new HashMap<String, Object>();
|
||||||
//searchInto.put("nome", "mock");
|
searchInto.put("nome", "san");
|
||||||
searchInto.put("authors", "annalisa");
|
searchInto.put("authors", "silvia");
|
||||||
filter.setSearchInto(searchInto);
|
//searchInto.put("report.status", "PASSED");
|
||||||
|
|
||||||
|
WhereClause where1 = new WhereClause(LOGICAL_OP.OR, searchInto);
|
||||||
|
|
||||||
|
Map<String, Object> searchInto2 = new HashMap<String, Object>();
|
||||||
|
searchInto2.put("report.status", "PASSED");
|
||||||
|
WhereClause where2 = new WhereClause(LOGICAL_OP.AND, searchInto2);
|
||||||
|
|
||||||
|
ArrayList<WhereClause> list = new ArrayList<WhereClause>();
|
||||||
|
list.add(where1);
|
||||||
|
//list.add(where2);
|
||||||
|
filter.setConditions(list);
|
||||||
ResultSetPaginatedData result = msc.queryOnMongo(30, 0, 30, filter, "concessione");
|
ResultSetPaginatedData result = msc.queryOnMongo(30, 0, 30, filter, "concessione");
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
Loading…
Reference in New Issue