Skip to content

Commit d96d033

Browse files
authored
Merge pull request #150 from CBIIT/INS-1475
INS-1475
2 parents 031d6f7 + c8e9227 commit d96d033

File tree

4 files changed

+107
-4
lines changed

4 files changed

+107
-4
lines changed

src/main/java/gov/nih/nci/bento_ri/model/PrivateESDataFetcher.java

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
import gov.nih.nci.bento.service.ESService;
77
import gov.nih.nci.bento.utility.TypeChecker;
88
import gov.nih.nci.bento_ri.service.InsESService;
9+
910
import graphql.schema.idl.RuntimeWiring;
11+
1012
import org.apache.logging.log4j.LogManager;
1113
import org.apache.logging.log4j.Logger;
1214
import org.opensearch.client.Request;
15+
import org.springframework.beans.factory.annotation.Value;
1316
import org.springframework.stereotype.Component;
1417

1518
import com.google.gson.JsonArray;
@@ -27,13 +30,17 @@ public class PrivateESDataFetcher extends AbstractPrivateESDataFetcher {
2730
private final YamlQueryFactory yamlQueryFactory;
2831
private InsESService insEsService;
2932

33+
@Value("${aws.cloudfront.url:#{environment.AWS_CLOUDFRONT_URL}}")
34+
private String cloudFrontUrl;
35+
3036
// parameters used in queries
3137
final String PAGE_SIZE = "first";
3238
final String OFFSET = "offset";
3339
final String ORDER_BY = "order_by";
3440
final String SORT_DIRECTION = "sort_direction";
3541

3642
final String DATASETS_END_POINT = "/datasets/_search";
43+
final String FILES_END_POINT = "/files/_search";
3744
final String GRANTS_END_POINT = "/grants/_search";
3845
final String PROGRAMS_END_POINT = "/programs/_search";
3946
final String PROJECTS_END_POINT = "/projects/_search";
@@ -127,6 +134,10 @@ public RuntimeWiring buildRuntimeWiring() throws IOException {
127134
Map<String, Object> args = env.getArguments();
128135
return datasetDetails(args);
129136
})
137+
.dataFetcher("getDatasetFiles", env -> {
138+
Map<String, Object> args = env.getArguments();
139+
return getDatasetFiles(args);
140+
})
130141
.dataFetcher("programDetails", env -> {
131142
Map<String, Object> args = env.getArguments();
132143
return programDetails(args);
@@ -826,6 +837,83 @@ private Map<String, Object> datasetDetails(Map<String, Object> params) throws IO
826837
return dataset;
827838
}
828839

840+
/**
841+
* Gets the files for a single Dataset record
842+
*
843+
* @param params The filters applied
844+
* @return A list of the Dataset's files
845+
* @throws IOException
846+
*/
847+
private List<Map<String, Object>> getDatasetFiles(Map<String, Object> params) throws IOException {
848+
List<Map<String, Object>> files;
849+
850+
final String[][] PROPERTIES = new String[][]{
851+
new String[]{"dataset_source_id", "dataset_source_id"},
852+
new String[]{"file_url_repo_prefix", "file_url_repo_prefix"},
853+
new String[]{"file_id", "file_id"},
854+
new String[]{"file_name", "file_name"},
855+
new String[]{"file_type", "file_type"},
856+
new String[]{"file_url", "file_url"},
857+
new String[]{"access_level", "access_level"}
858+
};
859+
860+
Map<String, String> mapping = Map.ofEntries(
861+
Map.entry("dataset_source_id", "dataset_source_id.sort"),
862+
Map.entry("file_url_repo_prefix", "file_url_repo_prefix.sort"),
863+
Map.entry("file_id", "file_id.sort"),
864+
Map.entry("file_name", "file_name.sort"),
865+
Map.entry("file_type", "file_type.sort"),
866+
Map.entry("file_url", "file_url.sort"),
867+
Map.entry("access_level", "access_level.sort")
868+
);
869+
870+
// Create a new params object rather than mutating the input
871+
Map<String, Object> queryParams = new HashMap<>(params);
872+
873+
// Rename 'accessTypes' to 'access_level'
874+
queryParams.put("access_level.search", queryParams.remove("accessTypes"));
875+
876+
// Turn dataset_source_id into a list
877+
queryParams.put("dataset_source_id.search", List.of(queryParams.remove("dataset_source_id")));
878+
879+
// Turn filters into lowercase
880+
for (String key : queryParams.keySet()) {
881+
@SuppressWarnings("unchecked")
882+
List<String> list = (List<String>) queryParams.get(key);
883+
List<String> lowerCaseList = new ArrayList<String>();
884+
list.forEach(s -> lowerCaseList.add(s.toLowerCase()));
885+
queryParams.put(key, lowerCaseList);
886+
}
887+
888+
// Add missing sorting params if not present
889+
queryParams.putIfAbsent(ORDER_BY, "file_name");
890+
queryParams.putIfAbsent(SORT_DIRECTION, "ASC");
891+
queryParams.putIfAbsent(PAGE_SIZE, InsESService.MAX_ES_SIZE); // use MAX_ES_SIZE for maximum files per request
892+
queryParams.putIfAbsent(OFFSET, 0);
893+
894+
files = overview(FILES_END_POINT, queryParams, PROPERTIES, "file_name", mapping, REGULAR_PARAMS, "nested_filters", "files");
895+
896+
// Form URLs for download
897+
for (Map<String, Object> file : files) {
898+
String prefix = (String) file.get("file_url_repo_prefix");
899+
String fileUrl = (String) file.get("file_url"); // Required property, guaranteed by ETL
900+
901+
// Compose downloadUrl, handling extra slashes
902+
String url = cloudFrontUrl.endsWith("/") ? cloudFrontUrl.substring(0, cloudFrontUrl.length() - 1) : cloudFrontUrl;
903+
url += "/" + (prefix != null ? prefix : "");
904+
if (!url.endsWith("/") && !fileUrl.startsWith("/")) {
905+
url += "/";
906+
}
907+
url += fileUrl;
908+
909+
file.put("downloadUrl", url);
910+
file.remove("file_url_repo_prefix");
911+
file.remove("file_url");
912+
}
913+
914+
return files;
915+
}
916+
829917
/**
830918
* Gets the details for a single Program record
831919
*

src/main/resources/application.properties

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ spring.mvc.view.suffix=.jsp
1212
error.redirect_url=http://localhost/error.html
1313

1414
#Neo4j
15-
neo4j.url = bolt://10.208.1.7:7687
16-
neo4j.user = neo4j1
17-
neo4j.password = DJA8JU@1oQVk9
15+
#neo4j.url=
16+
#neo4j.user=
17+
#neo4j.password=
1818

1919
#GraphQL
2020
graphql.schema=graphql/ins.graphql
@@ -36,7 +36,7 @@ redis.port=6379
3636
redis.ttl=-1
3737

3838
# Elasticsearch Filtering
39-
es.host=vpc-ccdi-sandbox-hub-opensearch-2qghwrh6n4r2t25m56ryso2lay.us-east-1.es.amazonaws.com
39+
#es.host=
4040
es.port=443
4141
es.scheme=https
4242
es.filter.enabled = true
@@ -45,5 +45,8 @@ es.sign.requests = false
4545
es.service_name = es
4646
es.region = us-east-1
4747

48+
# CloudFront URL
49+
#aws.cloudfront.url=
50+
4851
#Testing
4952
test.queries_file=placeholder

src/main/resources/application.properties.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,8 @@ es.sign.requests = true
4747
es.service_name = es
4848
es.region = us-east-1
4949

50+
# CloudFront URL
51+
#aws.cloudfront.url=
52+
5053
#Testing
5154
test.queries_file=placeholder

src/main/resources/graphql/ins-private-es.graphql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ type ProgramInfo {
152152
num_subjects: Int
153153
}
154154

155+
type DatasetFile {
156+
access_level: String!
157+
downloadUrl: String!
158+
file_id: String!
159+
file_name: String!
160+
file_type: String
161+
}
162+
155163
type DatasetDetails {
156164
dataset_maximum_age_at_baseline: Int
157165
dataset_minimum_age_at_baseline: Int
@@ -380,6 +388,7 @@ type QueryType {
380388

381389
programInfo: [ProgramInfo]
382390
datasetDetails(dataset_source_id: String): DatasetDetails
391+
getDatasetFiles(dataset_source_id: String!, accessTypes: [String!]!): [DatasetFile]
383392
programDetails(program_id: String): ProgramDetails
384393
projectDetails(project_id: String): ProjectDetails
385394
subjectDetail(subject_id: String): SubjectDetail

0 commit comments

Comments
 (0)