Skip to content

Commit

Permalink
Merge pull request #249 from tanvi029/popular-dataset
Browse files Browse the repository at this point in the history
mlayer dataset API fixes
  • Loading branch information
pranavrd authored Jul 19, 2023
2 parents 5b79f1b + 817a57b commit f37181b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 deletions.
27 changes: 15 additions & 12 deletions src/main/java/iudx/catalogue/server/database/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,17 @@ public class Constants {
+ "\"instance\",\"provider\"]},\"size\": 10000}";

public static final String GET_MLAYER_DATASET =
"{\"query\":{\"bool\":{\"should\":[{\"bool\":{\"must\":[{\"match\": {\"id.keyword\":"
+ " \"$1\"}},{\"match\": {\"type.keyword\":\"iudx:ResourceGroup\"}}]}},{\"bool\":"
+ "{\"must\":[{\"match\": {\"id.keyword\": \"$2\"}},{\"match\":{\"type.keyword\":"
+ " \"iudx:Provider\"}}]}},{\"bool\":{\"must\":[{\"match\":"
+ "{\"resourceGroup.keyword\": \"$1\"}},{\"match\":{\"type.keyword\":"
+ " \"iudx:Resource\"}}]}}]}},\"_source\": {\"includes\": [\"id\",\"type\","
+ "\"label\",\"description\",\"instance\",\"accessPolicy\",\"dataSample\","
+ "\"dataDescriptor\",\"@context\",\"dataQualityFile\",\"dataSampleFile\","
+ "\"resourceType\"]},\"size\": 10000}";
"{\"query\":{\"bool\":{\"should\":[{\"bool\":{\"must\":[{\"match\":{\"id.keyword\": "
+ "\"$1\"}},{\"match\":{\"type.keyword\":\"iudx:ResourceGroup\"}}]}},{\"bool\":"
+ "{\"must\":[{\"match\":{\"id.keyword\": \"2$\"}},{\"match\":{\"type.keyword\": "
+ "\"iudx:Provider\"}}]}},{\"bool\":{\"must\":[{\"match\":{\"resourceGroup.keyword\":"
+ " \"$1\"}},{\"match\":{\"type.keyword\": \"iudx:Resource\"}}]}},{\"bool\":{\"must\""
+ ":[{\"match\":{\"id.keyword\": \"$3\"}},{\"match\":{\"type.keyword\": "
+ "\"iudx:ResourceServer\"}}]}}]}},\"_source\":{\"includes\":[\"resourceServer\","
+ "\"id\",\"type\",\"label\",\"description\",\"instance\",\"accessPolicy\","
+ "\"dataSample\", \"dataDescriptor\",\"@context\",\"dataQualityFile\","
+ "\"dataSampleFile\",\"resourceType\",\"resourceServerHTTPAccessURL\"]},"
+ "\"size\": 10000}";
public static final String GET_MLAYER_INSTANCE_ICON =
"{\"query\":{\"match\":{\"name\":\"$1\"}},\"_source\": {\"includes\": [\"icon\"]}}";
public static final String GET_PROVIDER_AND_RESOURCES =
Expand All @@ -208,9 +210,10 @@ public class Constants {
public static final String GET_SORTED_MLAYER_INSTANCES =
"{\"query\": {\"match_all\":{}},\"sort\":[{\"name\":\"asc\"}],\"_source\": "
+ "{\"includes\": [\"name\",\"cover\",\"icon\"]},\"size\":10000}";
public static final String GET_PROVIDER_ID =
"{\"query\":{\"bool\":{\"must\":[{\"match\":{\"type.keyword\": \"iudx:ResourceGroup\"}},"
+ "{\"match\":{\"id.keyword\":\"$1\"}}]}},\"_source\": [\"provider\"]}";
public static final String GET_PROVIDER_AND_RS_ID =
"{\"query\":{\"bool\":{\"must\":[{\"match\":{\"type.keyword\": \"iudx:ResourceGroup\"}},"
+ "{\"match\":{\"id.keyword\":\"$1\"}}]}},\"_source\": [\"provider\","
+ "\"resourceServer\"]}";
public static final String INSTANCE_FILTER = "{\"match\":" + "{\"instance\": \"" + "$1" + "\"}}";
public static final String BOOL_MUST_QUERY = "{\"query\":{\"bool\":{\"must\":[$1]}}}";
public static final String SHOULD_QUERY = "{\"bool\":{\"should\":$1}}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1822,11 +1822,11 @@ public DatabaseService getMlayerDataset(
String datasetId, Handler<AsyncResult<JsonObject>> handler) {
LOGGER.debug("dataset Id" + datasetId);
client.searchAsync(
GET_PROVIDER_ID.replace("$1", datasetId),
GET_PROVIDER_AND_RS_ID.replace("$1", datasetId),
docIndex,
providerRes -> {
if (providerRes.succeeded()) {
if (providerRes.result().getInteger(TOTAL_HITS) == 0) {
handlerRes -> {
if (handlerRes.succeeded()) {
if (handlerRes.result().getInteger(TOTAL_HITS) == 0) {
LOGGER.debug("The dataset is not available.");
handler.handle(
Future.failedFuture(
Expand All @@ -1837,9 +1837,14 @@ public DatabaseService getMlayerDataset(
.getResponse()));
}
String providerId =
providerRes.result().getJsonArray(RESULTS).getJsonObject(0).getString("provider");
handlerRes.result().getJsonArray(RESULTS).getJsonObject(0).getString("provider");
String resourceServerId = handlerRes.result().getJsonArray(RESULTS).getJsonObject(0)
.getString("resourceServer");
LOGGER.debug("resourceServer id {}", resourceServerId);
LOGGER.debug("provider id " + providerId);
String query = GET_MLAYER_DATASET.replace("$1", datasetId).replace("$2", providerId);
String query = GET_MLAYER_DATASET.replace("$1", datasetId)
.replace("$2", providerId)
.replace("$3", resourceServerId);
LOGGER.debug("Query " + query);
client.searchAsyncDataset(
query,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,14 @@ public void onSuccess(Response response) {
.put("dataSampleFile", record.getJsonArray("dataSampleFile"))
.put("dataQualityFile", record.getJsonArray("dataQualityFile"))
.put(DATA_DESCRIPTOR, record.getJsonObject(DATA_DESCRIPTOR))
.put("schema", schema);
.put("schema", schema)
.put(RESOURCE_SVR, record.getString("resourceServer"));
}
if (type.equals("iudx:ResourceServer")) {
dataset
.put("resourceServerHTTPAccessURL",
record.getString("resourceServerHTTPAccessURL"));

}
}
datasetDetail.put("dataset", dataset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2792,7 +2792,8 @@ public void testGetMlayerDataset(VertxTestContext testContext) {
new JsonObject()
.put("provider", "provider id")
.put("dataset", datasetJson)
.put("icon", "icon-path");
.put("icon", "icon-path")
.put("resourceServer","resourceServer uid");
JsonArray jsonArray = new JsonArray().add(0, json);
JsonObject request = new JsonObject().put(TOTAL_HITS, 0).put(RESULTS, jsonArray);
when(asyncResult.succeeded()).thenReturn(true);
Expand Down

0 comments on commit f37181b

Please sign in to comment.