Skip to content

Commit 0569fdd

Browse files
Merge branch 'develop' of github.com:opencb/java-common-libs into develop
2 parents 9253364 + a4d6c33 commit 0569fdd

12 files changed

Lines changed: 182 additions & 71 deletions

File tree

.github/workflows/deploy-maven-repository-workflow.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ on:
77
type: string
88
required: false
99
secrets:
10-
MAVEN_NEXUS_USER:
11-
required: true
12-
MAVEN_NEXUS_PASSWORD:
13-
required: true
1410
MAVEN_GPG_PASSPHRASE:
1511
required: true
1612
MAVEN_GPG_PRIVATE_KEY:

.github/workflows/pull-request-approved.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77

88
jobs:
99
calculate-xetabase-branch:
10+
if: github.event.review.state == 'approved'
1011
name: Calculate Xetabase branch
1112
runs-on: ubuntu-22.04
1213
outputs:
@@ -25,7 +26,7 @@ jobs:
2526
echo "github.event.pull_request.base.ref: ${{ github.event.pull_request.base.ref }}"
2627
echo "github.event.pull_request.head.ref: ${{ github.event.pull_request.head.ref }}"
2728
echo "secrets.ZETTA_REPO_ACCESS_TOKEN: ${{ secrets.ZETTA_REPO_ACCESS_TOKEN }}"
28-
xetabase_branch=$(./.github/workflows/scripts/get-xetabase-branch.sh ${{ github.event.pull_request.base.ref }})
29+
xetabase_branch=$(./.github/workflows/scripts/get-xetabase-branch.sh ${{ github.event.pull_request.base.ref }} ${{ github.event.pull_request.head.ref }})
2930
echo "__Xetabase ref:__ \"${xetabase_branch}\"" | tee -a ${GITHUB_STEP_SUMMARY}
3031
echo "xetabase_branch=${xetabase_branch}" >> $GITHUB_OUTPUT
3132
env:

.github/workflows/scripts/get-xetabase-branch.sh

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,26 @@ set -x
44
# Function to calculate the corresponding branch of Xetabase project
55
get_xetabase_branch() {
66
# Input parameter (branch name)
7-
input_branch="$1"
7+
# Input parameter (branch name)
8+
target_branch="$1"
9+
current_branch="$2"
810

911
# If the branch begins with 'TASK' and exists in the opencga-enterprise repository, I return it
10-
if [[ $input_branch == TASK* ]]; then
11-
if [ "$(git ls-remote "https://$ZETTA_REPO_ACCESS_TOKEN@github.com/zetta-genomics/opencga-enterprise.git" "$input_branch" )" ] ; then
12-
echo $input_branch;
12+
if [[ $current_branch == TASK* ]]; then
13+
if [ "$(git ls-remote "https://$ZETTA_REPO_ACCESS_TOKEN@github.com/zetta-genomics/opencga-enterprise.git" "$current_branch" )" ] ; then
14+
echo "$current_branch";
1315
return 0;
1416
fi
1517
fi
1618

1719
# Check if the branch name is "develop" in that case return the same branch name
18-
if [[ "$input_branch" == "develop" ]]; then
20+
if [[ "$target_branch" == "develop" ]]; then
1921
echo "develop"
2022
return 0
2123
fi
2224

2325
# Check if the branch name starts with "release-" and follows the patterns "release-a.x.x" or "release-a.b.x"
24-
if [[ "$input_branch" =~ ^release-([0-9]+)\.x\.x$ ]] || [[ "$input_branch" =~ ^release-([0-9]+)\.([0-9]+)\.x$ ]]; then
26+
if [[ "$target_branch" =~ ^release-([0-9]+)\.x\.x$ ]] || [[ "$target_branch" =~ ^release-([0-9]+)\.([0-9]+)\.x$ ]]; then
2527
# Extract the MAJOR part of the branch name
2628
MAJOR=${BASH_REMATCH[1]}
2729
# Calculate the XETABASE_MAJOR by subtracting 3 from MAJOR
@@ -32,7 +34,7 @@ get_xetabase_branch() {
3234
return 1
3335
fi
3436
# Construct and echo the new branch name
35-
echo "release-$XETABASE_MAJOR.${input_branch#release-$MAJOR.}"
37+
echo "release-$XETABASE_MAJOR.${target_branch#release-$MAJOR.}"
3638
return 0
3739
fi
3840

@@ -41,6 +43,11 @@ get_xetabase_branch() {
4143
return 1
4244
}
4345

46+
# Check if the script receives exactly one argument
47+
if [ "$#" -ne 2 ]; then
48+
echo "Usage: $0 <target-branch> <current-branch>"
49+
exit 1
50+
fi
4451

4552
# Call the function with the input branch name
46-
get_xetabase_branch "$1"
53+
get_xetabase_branch "$1" "$2"

commons-datastore/commons-datastore-core/src/main/java/org/opencb/commons/datastore/core/QueryOptions.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ public class QueryOptions extends ObjectMap {
3333

3434
public static final String SORT = "sort";
3535
public static final String ORDER = "order";
36+
public static final String ASC = "asc";
3637
public static final String ASCENDING = "ascending";
38+
public static final String DESC = "desc";
3739
public static final String DESCENDING = "descending";
3840

3941
public static final String TIMEOUT = "timeout";

commons-datastore/commons-datastore-mongodb/src/main/java/org/opencb/commons/datastore/mongodb/MongoDBCollection.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,22 @@ public <T> List<DataResult<T>> privateFind(List<? extends Bson> queries, Bson pr
322322
return queryResultList;
323323
}
324324

325+
public DataResult<Document> aggregate(ClientSession clientSession, List<? extends Bson> operations,
326+
QueryOptions options) {
327+
return aggregate(clientSession, operations, null, options);
328+
}
329+
325330
public DataResult<Document> aggregate(List<? extends Bson> operations, QueryOptions options) {
326331
return aggregate(operations, null, options);
327332
}
328333

329334
public <T> DataResult<T> aggregate(List<? extends Bson> operations, ComplexTypeConverter<T, Document> converter,
330335
QueryOptions options) {
336+
return aggregate(null, operations, converter, options);
337+
}
331338

339+
public <T> DataResult<T> aggregate(ClientSession clientSession, List<? extends Bson> operations,
340+
ComplexTypeConverter<T, Document> converter, QueryOptions options) {
332341
long start = startQuery();
333342
DataResult<T> queryResult;
334343
List<T> list = new LinkedList<>();

commons-datastore/commons-datastore-mongodb/src/main/java/org/opencb/commons/datastore/mongodb/MongoDBNativeQuery.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@
2828
import org.opencb.commons.datastore.core.ComplexTypeConverter;
2929
import org.opencb.commons.datastore.core.QueryOptions;
3030

31-
import java.util.ArrayList;
32-
import java.util.Collection;
33-
import java.util.Iterator;
34-
import java.util.List;
31+
import java.util.*;
3532
import java.util.concurrent.*;
3633

3734
import static org.opencb.commons.datastore.mongodb.MongoDBQueryUtils.getProjection;
@@ -121,7 +118,6 @@ public <T> MongoDBIterator<T> aggregate(ClientSession clientSession, List<? exte
121118
// we need to be sure that the List is mutable
122119
List<Bson> bsonOperations = new ArrayList<>(operations);
123120
parseQueryOptions(bsonOperations, options);
124-
System.out.println("bsonOperations = " + bsonOperations);
125121
MongoDBIterator<T> iterator = null;
126122
if (bsonOperations.size() > 0) {
127123
long numMatches = -1;
@@ -181,8 +177,8 @@ public FindIterable<Document> nativeFind(ClientSession clientSession, Bson query
181177
if (sortObject instanceof Bson) {
182178
findIterable.sort(((Bson) sortObject));
183179
} else if (sortObject instanceof String) {
184-
String order = options.getString(QueryOptions.ORDER, "DESC");
185-
if (order.equalsIgnoreCase(QueryOptions.ASCENDING) || order.equalsIgnoreCase("ASC")
180+
String order = options.getString(QueryOptions.ORDER, QueryOptions.DESC.toUpperCase(Locale.ROOT));
181+
if (order.equalsIgnoreCase(QueryOptions.ASCENDING) || order.equalsIgnoreCase(QueryOptions.ASC)
186182
|| order.equals("1")) {
187183
findIterable.sort(Sorts.ascending(((String) sortObject)));
188184
} else {
@@ -200,9 +196,9 @@ public FindIterable<Document> nativeFind(ClientSession clientSession, Bson query
200196
order = fieldArray[1];
201197
} else if (fieldArray.length == 1) {
202198
sortField = field;
203-
order = options.getString(QueryOptions.ORDER, "DESC");
199+
order = options.getString(QueryOptions.ORDER, QueryOptions.DESC.toUpperCase(Locale.ROOT));
204200
}
205-
if (QueryOptions.ASCENDING.equalsIgnoreCase(order) || "ASC".equalsIgnoreCase(order)
201+
if (QueryOptions.ASCENDING.equalsIgnoreCase(order) || QueryOptions.ASC.equalsIgnoreCase(order)
206202
|| "1".equals(order)) {
207203
sortedList.add(Sorts.ascending(sortField));
208204
} else {

commons-datastore/commons-datastore-mongodb/src/main/java/org/opencb/commons/datastore/mongodb/MongoDBQueryUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,8 +1052,8 @@ public static Bson getSort(QueryOptions options) {
10521052
if (sortObject instanceof Bson) {
10531053
return Aggregates.sort((Bson) sortObject);
10541054
} else if (sortObject instanceof String) {
1055-
String order = options.getString(QueryOptions.ORDER, "DESC");
1056-
if (order.equalsIgnoreCase(QueryOptions.ASCENDING) || order.equalsIgnoreCase("ASC") || order.equals("1")) {
1055+
String order = options.getString(QueryOptions.ORDER, QueryOptions.DESC.toUpperCase(Locale.ROOT));
1056+
if (order.equalsIgnoreCase(QueryOptions.ASCENDING) || order.equalsIgnoreCase(QueryOptions.ASC) || order.equals("1")) {
10571057
return Aggregates.sort(Sorts.ascending((String) sortObject));
10581058
} else {
10591059
return Aggregates.sort(Sorts.descending((String) sortObject));

commons-datastore/commons-datastore-mongodb/src/test/java/org/opencb/commons/datastore/mongodb/MongoDBCollectionTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import java.util.*;
3838

3939
import static org.junit.Assert.*;
40-
import static org.opencb.commons.datastore.core.QueryOptions.SORT;
4140
import static org.opencb.commons.datastore.mongodb.MongoDBQueryUtils.*;
4241
import static org.opencb.commons.datastore.mongodb.MongoDBQueryUtils.Accumulator.*;
4342

@@ -256,8 +255,8 @@ public void testDistinct() throws Exception {
256255
@Test
257256
public void testSortOrder() throws Exception {
258257
Document query = new Document();
259-
QueryOptions queryOptions = new QueryOptions(QueryOptions.LIMIT, 10).append(SORT, "number")
260-
.append(QueryOptions.ORDER, "asc");
258+
QueryOptions queryOptions = new QueryOptions(QueryOptions.LIMIT, 10).append(QueryOptions.SORT, "number")
259+
.append(QueryOptions.ORDER, QueryOptions.ASC);
261260
List<Document> result = mongoDBCollection.find(query, queryOptions).getResults();
262261
assertEquals(0L, result.get(0).get("number"));
263262
}
@@ -266,8 +265,9 @@ public void testSortOrder() throws Exception {
266265
public void testMultipleSortOrder() throws Exception {
267266
Document query = new Document();
268267
QueryOptions queryOptions = new QueryOptions(QueryOptions.LIMIT, 500)
269-
.append(SORT, Arrays.asList("age:ASC", "number:DESC"))
270-
.append(QueryOptions.ORDER, "asc");
268+
.append(QueryOptions.SORT, Arrays.asList("age:" + QueryOptions.ASC.toUpperCase(Locale.ROOT),
269+
"number:" + QueryOptions.DESC.toUpperCase(Locale.ROOT)))
270+
.append(QueryOptions.ORDER, QueryOptions.ASC);
271271
int age = 0;
272272
long number = Long.MAX_VALUE;
273273
List<Document> result = mongoDBCollection.find(query, queryOptions).getResults();

commons-datastore/commons-datastore-solr/src/main/java/org/opencb/commons/datastore/solr/FacetQueryParser.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import java.util.regex.Matcher;
2626
import java.util.regex.Pattern;
2727

28+
import static org.opencb.commons.datastore.core.QueryOptions.*;
29+
2830
public class FacetQueryParser {
2931

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

256259
Map<String, Object> tmpMap = new HashMap<>();
257260
tmpMap.put(matcher.group(1), auxMap);
@@ -261,6 +264,7 @@ private Map<String, Object> parseFacet(String facet, QueryOptions options) throw
261264
outputMap.put("type", "terms");
262265
setTermLimit(matcher.group(3), options, outputMap);
263266
setTermSkip(options, outputMap);
267+
setTermOrder(options, outputMap);
264268
}
265269
} else {
266270
throw new Exception("Invalid categorical facet: " + facet);
@@ -290,6 +294,30 @@ private void setTermSkip(QueryOptions options, Map<String, Object> map) {
290294
}
291295
}
292296

297+
private void setTermOrder(QueryOptions options, Map<String, Object> map) throws Exception {
298+
if (options.containsKey(QueryOptions.ORDER)) {
299+
String order = options.getString(QueryOptions.ORDER);
300+
switch (order.toLowerCase(Locale.ROOT)) {
301+
case ASC:
302+
case ASCENDING: {
303+
map.put("sort", "count asc");
304+
break;
305+
}
306+
case DESC:
307+
case DESCENDING: {
308+
map.put("sort", "count desc");
309+
break;
310+
}
311+
default: {
312+
throw new Exception("Invalid order value: '" + order + "'. Valid values are: "
313+
+ StringUtils.join(Arrays.asList(ASC, ASCENDING, DESC, DESCENDING)));
314+
}
315+
}
316+
} else {
317+
map.put("sort", "count desc");
318+
}
319+
}
320+
293321
private void parseNestedFacet(String nestedFacet, QueryOptions options, Map<String, Object> jsonFacet)
294322
throws Exception {
295323
String[] split = nestedFacet.split(NESTED_FACET_SEPARATOR);

commons-datastore/commons-datastore-solr/src/main/java/org/opencb/commons/datastore/solr/SolrFacetToFacetFieldsConverter.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ public static List<FacetField> convert(QueryResponse solrResponse, Map<String, S
3535

3636
SimpleOrderedMap<Object> solrFacets = (SimpleOrderedMap<Object>) solrResponse.getResponse().get("facets");
3737
List<FacetField> fields = new ArrayList<>();
38-
int count = (int) solrFacets.get("count");
38+
long count = 0;
39+
if (solrFacets.get("count") != null) {
40+
count = ((Number) solrFacets.get("count")).longValue();
41+
}
3942
for (int i = 0; i < solrFacets.size(); i++) {
4043
String name = solrFacets.getName(i);
4144
if (!"count".equals(name)) {
@@ -71,8 +74,8 @@ private static long getBucketCount(SimpleOrderedMap<Object> solrFacets, long def
7174
List<SimpleOrderedMap<Object>> solrBuckets = (List<SimpleOrderedMap<Object>>) solrFacets.get("buckets");
7275
if (solrBuckets == null) {
7376
for (int i = 0; i < solrFacets.size(); i++) {
74-
if (solrFacets.getName(i).equals("count")) {
75-
return (long) solrFacets.getVal(i);
77+
if (solrFacets.getName(i).equals("count") && solrFacets.getVal(i) != null) {
78+
return ((Number) solrFacets.getVal(i)).longValue();
7679
}
7780
}
7881
}

0 commit comments

Comments
 (0)