Skip to content

Commit

Permalink
Merge pull request #258 from tanvi029/mlayer-dataset-changes
Browse files Browse the repository at this point in the history
mlayer-datasetAPI updates
  • Loading branch information
pranavrd authored Aug 30, 2023
2 parents e733a68 + cc866e9 commit d91b92f
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 24 deletions.
7 changes: 7 additions & 0 deletions docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1980,6 +1980,13 @@ paths:
get:
tags:
- Mlayer Dataset
parameters:
- name: instance
description: |
`name` of the instance from where the datasets belong
schema:
type: string
in: query
responses:
200:
content:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,12 @@ public void getMlayerAllDatasetsHandler(RoutingContext routingContext) {
LOGGER.debug("Info : fetching all datasets that belong to IUDX");
HttpServerResponse response = routingContext.response();
response.putHeader(HEADER_CONTENT_TYPE, MIME_APPLICATION_JSON);
String instance = "";
if (routingContext.request().getParam(INSTANCE) != null) {
instance = routingContext.request().getParam(INSTANCE);
}
mlayerService.getMlayerAllDatasets(
handler -> {
instance, handler -> {
if (handler.succeeded()) {
response.setStatusCode(200).end(handler.result().toString());
} else {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/iudx/catalogue/server/database/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ public class Constants {
+ "\"_source\":{\"includes\": [\"id\",\"label\",\"accessPolicy\",\"tags\","
+ "\"instance\",\"provider\"]},\"size\": 10000}";

public static final String GET_INSTANCE_BASED_MLAYER_DATASETS =
"{\"query\":{\"bool\":{\"must\":[{\"match\":{\"type.keyword\": \"iudx:ResourceGroup\"}},"
+ "{\"match\":{\"instance.keyword\": \"$1\"}}]}},\"_source\":{\"includes\": "
+ "[\"id\", \"label\", \"accessPolicy\", \"tags\", \"instance\", \"provider\"]},"
+ "\"size\": 10000}\n";
public static final String GET_MLAYER_DATASET =
"{\"query\":{\"bool\":{\"should\":[{\"bool\":{\"must\":[{\"match\":{\"id.keyword\": "
+ "\"$1\"}},{\"match\":{\"type.keyword\":\"iudx:ResourceGroup\"}}]}},{\"bool\":"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,12 @@ DatabaseService updateMlayerInstance(
/**
* The get Mlayer All Datasets gets all the dataset belonging to IUDX.
*
* @param instance which is a string
* @param handler which is a request handler
* @return DatabaseService which is a Service
*/
@Fluent
DatabaseService getMlayerAllDatasets(Handler<AsyncResult<JsonObject>> handler);
DatabaseService getMlayerAllDatasets(String instance, Handler<AsyncResult<JsonObject>> handler);

/**
* The get Mlayer datasset get details of the dataset.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package iudx.catalogue.server.database;

import static iudx.catalogue.server.database.Constants.*;
import static iudx.catalogue.server.database.Constants.GET_DOC_QUERY_WITH_TYPE;
import static iudx.catalogue.server.mlayer.util.Constants.*;
import static iudx.catalogue.server.util.Constants.*;

Expand Down Expand Up @@ -1693,9 +1692,14 @@ public DatabaseService getMlayerGeoQuery(
}

@Override
public DatabaseService getMlayerAllDatasets(Handler<AsyncResult<JsonObject>> handler) {
String query = GET_MLAYER_ALL_DATASETS;
LOGGER.debug(query);
public DatabaseService getMlayerAllDatasets(String datasetInstance,
Handler<AsyncResult<JsonObject>> handler) {
String query = "";
if (datasetInstance == null || datasetInstance.isBlank()) {
query = GET_MLAYER_ALL_DATASETS;
} else {
query = GET_INSTANCE_BASED_MLAYER_DATASETS.replace("$1", datasetInstance);
}
// Elastic client call to get all datasets.
client.searchAsync(
query,
Expand All @@ -1704,6 +1708,13 @@ public DatabaseService getMlayerAllDatasets(Handler<AsyncResult<JsonObject>> han
if (resultHandler.succeeded()) {
LOGGER.debug("Success: Successful DB Request");
int size = resultHandler.result().getJsonArray(RESULTS).size();
if (size == 0) {
handler.handle(Future.failedFuture(new RespBuilder()
.withType(TYPE_ITEM_NOT_FOUND)
.withTitle(TITLE_ITEM_NOT_FOUND)
.withDetail("no datasets are present")
.getResponse()));
}
ArrayList<String> instanceList = new ArrayList<String>();
ArrayList<String> providerList = new ArrayList<String>();
// make a list of instance names and provider_id.
Expand Down Expand Up @@ -1733,7 +1744,9 @@ public DatabaseService getMlayerAllDatasets(Handler<AsyncResult<JsonObject>> han
String combinedQuery = GET_MLAYER_BOOL_ICON.replace("$2", instance);
sb.append(combinedQuery).append(",");
}
sb.deleteCharAt(sb.length() - 1);
if (sb.length() > 0) {
sb.deleteCharAt(sb.length() - 1);
}
String getIconQuery = GET_MLAYER_INSTANCE_ICON_PATH.replace("$1", sb);
// query to get provider description and total Resource
StringBuilder sb1 = new StringBuilder();
Expand All @@ -1745,7 +1758,9 @@ public DatabaseService getMlayerAllDatasets(Handler<AsyncResult<JsonObject>> han

sb1.append(combinedQuery).append(",");
}
sb1.deleteCharAt(sb1.length() - 1);
if (sb1.length() > 0) {
sb1.deleteCharAt(sb1.length() - 1);
}
String getProviderQuery = GET_MLAYER_PROVIDER_RESOURCE.replace("$1", sb1);
// Elastic client call to get instance icon paths.
client.searchAsync(
Expand Down Expand Up @@ -2048,7 +2063,7 @@ private void searchSortedMlayerInstances(Promise<JsonObject> instanceResult) {

private void allMlayerDomains(Promise<JsonArray> domainResult) {
client.searchAsync(
GET_MLAYER_DOMAIN_QUERY,
GET_ALL_MLAYER_DOMAIN_QUERY,
mlayerDomainIndex,
getDomainHandler -> {
if (getDomainHandler.succeeded()) {
Expand Down Expand Up @@ -2096,6 +2111,9 @@ private void datasets(String instance, Promise<JsonObject> datasetResult,
Map<String, Integer> resourceGroupCount = new HashMap<>();
Map<String, String> providerDescription = new HashMap<>();
Map<String, Integer> typeCount = new HashMap<>();
typeCount.put("iudx:Provider", 0);
typeCount.put("iudx:ResourceGroup", 0);
typeCount.put("iudx:Resource", 0);

for (int i = 0; i < getCatRecords.result().getJsonArray(RESULTS).size(); i++) {
JsonObject record = getCatRecords.result().getJsonArray(RESULTS).getJsonObject(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static MlayerService createProxy(Vertx vertx, String address) {
MlayerService getMlayerGeoQuery(JsonObject request, Handler<AsyncResult<JsonObject>> handler);

@Fluent
MlayerService getMlayerAllDatasets(Handler<AsyncResult<JsonObject>> handler);
MlayerService getMlayerAllDatasets(String instance, Handler<AsyncResult<JsonObject>> handler);

@Fluent
MlayerService getMlayerDataset(String datasetId, Handler<AsyncResult<JsonObject>> handler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,10 @@ public MlayerService getMlayerGeoQuery(
}

@Override
public MlayerService getMlayerAllDatasets(Handler<AsyncResult<JsonObject>> handler) {
public MlayerService getMlayerAllDatasets(String instance,
Handler<AsyncResult<JsonObject>> handler) {
databaseService.getMlayerAllDatasets(
getMlayerAllDatasets -> {
instance, getMlayerAllDatasets -> {
if (getMlayerAllDatasets.succeeded()) {
LOGGER.info("Success: Getting all datasets");
handler.handle(Future.succeededFuture(getMlayerAllDatasets.result()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2879,7 +2879,7 @@ public AsyncResult<JsonObject> answer(InvocationOnMock arg0) throws Throwable {
.searchAsync(any(), any(), any());

dbService.getMlayerAllDatasets(
handler -> {
"abc", handler -> {
if (handler.succeeded()) {
// verify(DatabaseServiceImpl.client, times(1)).searchAsyncDataset(any(), any(), any());
verify(DatabaseServiceImpl.client, times(3)).searchAsync(any(), any(), any());
Expand Down Expand Up @@ -2923,7 +2923,7 @@ public AsyncResult<JsonObject> answer(InvocationOnMock arg0) throws Throwable {
.searchAsync(any(), any(), any());

dbService.getMlayerAllDatasets(
handler -> {
"abc", handler -> {
if (handler.succeeded()) {
// verify(DatabaseServiceImpl.client, times(1)).searchAsyncDataset(any(), any(), any());
verify(DatabaseServiceImpl.client, times(3)).searchAsync(any(), any(), any());
Expand Down Expand Up @@ -2956,7 +2956,7 @@ public AsyncResult<JsonObject> answer(InvocationOnMock arg0) throws Throwable {
.searchAsync(any(), any(), any());

dbService.getMlayerAllDatasets(
handler -> {
"abc" ,handler -> {
if (handler.failed()) {
// verify(DatabaseServiceImpl.client, times(1)).searchAsyncDataset(any(), any(), any());
verify(DatabaseServiceImpl.client, times(1)).searchAsync(any(), any(), any());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,16 +702,16 @@ void successfulGetMlayerAllDatasetsTest(VertxTestContext testContext) {
@SuppressWarnings("unchecked")
@Override
public AsyncResult<JsonObject> answer(InvocationOnMock arg0) throws Throwable {
((Handler<AsyncResult<JsonObject>>) arg0.getArgument(0)).handle(asyncResult);
((Handler<AsyncResult<JsonObject>>) arg0.getArgument(1)).handle(asyncResult);
return null;
}
})
.when(databaseService)
.getMlayerAllDatasets(any());
.getMlayerAllDatasets(any(), any());
mlayerService.getMlayerAllDatasets(
handler -> {
"abc" ,handler -> {
if (handler.succeeded()) {
verify(databaseService, times(1)).getMlayerAllDatasets(any());
verify(databaseService, times(1)).getMlayerAllDatasets(any(), any());
testContext.completeNow();
} else {
LOGGER.debug("Fail");
Expand All @@ -732,17 +732,17 @@ void failureMlayerAllDatasetsTest(VertxTestContext testContext) {
@SuppressWarnings("unchecked")
@Override
public AsyncResult<JsonObject> answer(InvocationOnMock arg0) throws Throwable {
((Handler<AsyncResult<JsonObject>>) arg0.getArgument(0)).handle(asyncResult);
((Handler<AsyncResult<JsonObject>>) arg0.getArgument(1)).handle(asyncResult);
return null;
}
})
.when(databaseService)
.getMlayerAllDatasets(any());
.getMlayerAllDatasets(any(), any());

mlayerService.getMlayerAllDatasets(
handler -> {
"abc" ,handler -> {
if (handler.succeeded()) {
verify(databaseService, times(1)).getMlayerAllDatasets(any());
verify(databaseService, times(1)).getMlayerAllDatasets(any(), any());
LOGGER.debug("Fail");
testContext.failNow(handler.cause());
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info": {
"_postman_id": "8c237a3f-4eb3-4493-ad58-e466725f897c",
"_postman_id": "4d4a864a-b4ed-40bb-9058-57a3fab08809",
"name": "iudx-catalogue-server v5.0.0",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "27217689"
Expand Down Expand Up @@ -13957,6 +13957,56 @@
},
"response": []
},
{
"name": "200 (Success) - Get All Datasets Based on Instance param",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Response status\", function () {\r",
" pm.response.to.have.status(200);\r",
"});\r",
"\r",
"pm.test(\"Check response body\", function () { \r",
" const body = pm.response.json();\r",
" pm.expect(body).to.have.property(\"type\", \"urn:dx:cat:Success\");\r",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [
{
"key": "",
"value": "",
"type": "text",
"disabled": true
}
],
"url": {
"raw": "{{host}}{{base}}/internal/ui/dataset?instance=pune",
"host": [
"{{host}}{{base}}"
],
"path": [
"internal",
"ui",
"dataset"
],
"query": [
{
"key": "instance",
"value": "pune"
}
]
}
},
"response": []
},
{
"name": "200 (Success) - Post Dataset",
"event": [
Expand Down

0 comments on commit d91b92f

Please sign in to comment.