Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TASK-5610 Create the CVDB endpoint analysis/clinical/cvdb/variant/summary and overwrite analysis/clinical/variant #102

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public class QueryOptions extends ObjectMap {

public static final String SORT = "sort";
public static final String ORDER = "order";
public static final String ASC = "asc";
public static final String ASCENDING = "ascending";
public static final String DESC = "desc";
public static final String DESCENDING = "descending";

public static final String TIMEOUT = "timeout";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@
import org.opencb.commons.datastore.core.ComplexTypeConverter;
import org.opencb.commons.datastore.core.QueryOptions;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.*;
import java.util.concurrent.*;

import static org.opencb.commons.datastore.mongodb.MongoDBQueryUtils.getProjection;
Expand Down Expand Up @@ -180,8 +177,8 @@ public FindIterable<Document> nativeFind(ClientSession clientSession, Bson query
if (sortObject instanceof Bson) {
findIterable.sort(((Bson) sortObject));
} else if (sortObject instanceof String) {
String order = options.getString(QueryOptions.ORDER, "DESC");
if (order.equalsIgnoreCase(QueryOptions.ASCENDING) || order.equalsIgnoreCase("ASC")
String order = options.getString(QueryOptions.ORDER, QueryOptions.DESC.toUpperCase(Locale.ROOT));
if (order.equalsIgnoreCase(QueryOptions.ASCENDING) || order.equalsIgnoreCase(QueryOptions.ASC)
|| order.equals("1")) {
findIterable.sort(Sorts.ascending(((String) sortObject)));
} else {
Expand All @@ -199,9 +196,9 @@ public FindIterable<Document> nativeFind(ClientSession clientSession, Bson query
order = fieldArray[1];
} else if (fieldArray.length == 1) {
sortField = field;
order = options.getString(QueryOptions.ORDER, "DESC");
order = options.getString(QueryOptions.ORDER, QueryOptions.DESC.toUpperCase(Locale.ROOT));
}
if (QueryOptions.ASCENDING.equalsIgnoreCase(order) || "ASC".equalsIgnoreCase(order)
if (QueryOptions.ASCENDING.equalsIgnoreCase(order) || QueryOptions.ASC.equalsIgnoreCase(order)
|| "1".equals(order)) {
sortedList.add(Sorts.ascending(sortField));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -668,8 +665,8 @@ public static Bson getSort(QueryOptions options) {
if (sortObject instanceof Bson) {
return Aggregates.sort((Bson) sortObject);
} else if (sortObject instanceof String) {
String order = options.getString(QueryOptions.ORDER, "DESC");
if (order.equalsIgnoreCase(QueryOptions.ASCENDING) || order.equalsIgnoreCase("ASC") || order.equals("1")) {
String order = options.getString(QueryOptions.ORDER, QueryOptions.DESC.toUpperCase(Locale.ROOT));
if (order.equalsIgnoreCase(QueryOptions.ASCENDING) || order.equalsIgnoreCase(QueryOptions.ASC) || order.equals("1")) {
return Aggregates.sort(Sorts.ascending((String) sortObject));
} else {
return Aggregates.sort(Sorts.descending((String) sortObject));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public void testDistinct() throws Exception {
public void testSortOrder() throws Exception {
Document query = new Document();
QueryOptions queryOptions = new QueryOptions(QueryOptions.LIMIT, 10).append(QueryOptions.SORT, "number")
.append(QueryOptions.ORDER, "asc");
.append(QueryOptions.ORDER, QueryOptions.ASC);
List<Document> result = mongoDBCollection.find(query, queryOptions).getResults();
assertEquals(0L, result.get(0).get("number"));
}
Expand All @@ -173,8 +173,9 @@ public void testSortOrder() throws Exception {
public void testMultipleSortOrder() throws Exception {
Document query = new Document();
QueryOptions queryOptions = new QueryOptions(QueryOptions.LIMIT, 500)
.append(QueryOptions.SORT, Arrays.asList("age:ASC", "number:DESC"))
.append(QueryOptions.ORDER, "asc");
.append(QueryOptions.SORT, Arrays.asList("age:" + QueryOptions.ASC.toUpperCase(Locale.ROOT),
"number:" + QueryOptions.DESC.toUpperCase(Locale.ROOT)))
.append(QueryOptions.ORDER, QueryOptions.ASC);
int age = 0;
long number = Long.MAX_VALUE;
List<Document> result = mongoDBCollection.find(query, queryOptions).getResults();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.opencb.commons.datastore.core.QueryOptions.*;

public class FacetQueryParser {

public static final String FACET_SEPARATOR = ";";
Expand Down Expand Up @@ -252,6 +254,7 @@ private Map<String, Object> parseFacet(String facet, QueryOptions options) throw
auxMap.put("type", "terms");
setTermLimit(matcher.group(3), options, auxMap);
setTermSkip(options, auxMap);
setTermOrder(options, auxMap);

Map<String, Object> tmpMap = new HashMap<>();
tmpMap.put(matcher.group(1), auxMap);
Expand All @@ -261,6 +264,7 @@ private Map<String, Object> parseFacet(String facet, QueryOptions options) throw
outputMap.put("type", "terms");
setTermLimit(matcher.group(3), options, outputMap);
setTermSkip(options, outputMap);
setTermOrder(options, outputMap);
}
} else {
throw new Exception("Invalid categorical facet: " + facet);
Expand Down Expand Up @@ -290,6 +294,30 @@ private void setTermSkip(QueryOptions options, Map<String, Object> map) {
}
}

private void setTermOrder(QueryOptions options, Map<String, Object> map) throws Exception {
if (options.containsKey(QueryOptions.ORDER)) {
String order = options.getString(QueryOptions.ORDER);
switch (order.toLowerCase(Locale.ROOT)) {
case ASC:
case ASCENDING: {
map.put("sort", "count asc");
break;
}
case DESC:
case DESCENDING: {
map.put("sort", "count desc");
break;
}
default: {
throw new Exception("Invalid order value: '" + order + "'. Valid values are: "
+ StringUtils.join(Arrays.asList(ASC, ASCENDING, DESC, DESCENDING)));
}
}
} else {
map.put("sort", "count desc");
}
}

private void parseNestedFacet(String nestedFacet, QueryOptions options, Map<String, Object> jsonFacet)
throws Exception {
String[] split = nestedFacet.split(NESTED_FACET_SEPARATOR);
Expand Down
Loading