Skip to content

Commit c56d8db

Browse files
committed
Cover further corner cases so te catalog query count always returns 0 if no datasets
1 parent babc83f commit c56d8db

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

federated-catalog/src/main/java/org/eclipse/edc/heleade/federated/catalog/extension/store/mongodb/cache/MongodbFederatedCatalogCache.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,17 +241,18 @@ private String countInternalDatasets(MongoClient connection, QuerySpec querySpec
241241
// add count
242242
aggregations.add(Aggregates.count());
243243

244+
// run the aggregation
244245
var documents = getCollection(connection, getFederatedCatalogCollectionName()).aggregate(aggregations);
245246

246247
// check result is not empty
247-
if (!documents.iterator().hasNext()) {
248-
return "{\"count\": 0}";
248+
if (documents.iterator().hasNext()) {
249+
var document = documents.first();
250+
if (document != null && !document.isEmpty()) {
251+
return document.toJson();
252+
}
249253
}
250254

251-
var document = documents.first();
252-
String result = document == null ? "{\"count\": 0}" : document.toJson();
253-
254-
return result;
255+
return "{\"count\": 0}";
255256
}
256257

257258
private void upsertInternal(MongoClient connection, String id, Catalog catalog) {

0 commit comments

Comments
 (0)