Skip to content

Commit

Permalink
[ALS-5056] Create sumtype for QueryRequest
Browse files Browse the repository at this point in the history
- Interface, implementations for general use, GIC
  • Loading branch information
Luke Sikina committed Oct 11, 2023
1 parent 8221ff9 commit 6ae209c
Show file tree
Hide file tree
Showing 29 changed files with 369 additions and 240 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public Map<UUID,String> resources(@Context HttpHeaders headers){
@Consumes("*/*")
public PaginatedSearchResult<?> searchGenomicConceptValues(
@PathParam("resourceId") UUID resourceId,
QueryRequest searchQueryRequest,
GeneralQueryRequest searchQueryRequest,
@QueryParam("genomicConceptPath") String genomicConceptPath,
@QueryParam("query") String query,
@QueryParam("page") Integer page,
Expand Down Expand Up @@ -155,10 +155,11 @@ public QueryStatus query(

@Context SecurityContext context
) {
if (isInstitutionQuery == null || !isInstitutionQuery) {
if (dataQueryRequest instanceof GeneralQueryRequest) {
return queryService.query(dataQueryRequest, headers);
} else {
return queryService.institutionalQuery(dataQueryRequest, headers, context.getUserPrincipal().getName());
String email = context.getUserPrincipal().getName();
return queryService.institutionalQuery((GICQueryRequest) dataQueryRequest, headers, email);
}
}

Expand Down Expand Up @@ -187,7 +188,7 @@ public QueryStatus queryStatus(
UUID queryId,

@Parameter
QueryRequest credentialsQueryRequest,
GeneralQueryRequest credentialsQueryRequest,

@Context
HttpHeaders headers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import edu.harvard.dbmi.avillach.data.entity.AuthUser;
import edu.harvard.dbmi.avillach.data.repository.QueryRepository;
import edu.harvard.dbmi.avillach.data.repository.ResourceRepository;
import edu.harvard.dbmi.avillach.domain.QueryRequest;
import edu.harvard.dbmi.avillach.domain.GeneralQueryRequest;
import edu.harvard.dbmi.avillach.service.ResourceWebClient;
import edu.harvard.dbmi.avillach.util.exception.ApplicationException;
import edu.harvard.dbmi.avillach.util.response.PICSUREResponse;
Expand Down Expand Up @@ -204,7 +204,7 @@ private AuthUser callTokenIntroEndpoint(ContainerRequestContext requestContext,
edu.harvard.dbmi.avillach.data.entity.Resource resource = resourceRepo.getById(resourceUUID);
//logger.info("resource obj: " + resource + " path: " + resource.getResourceRSPath());
if (resource != null && resource.getResourceRSPath() != null){
QueryRequest queryRequest = new QueryRequest();
GeneralQueryRequest queryRequest = new GeneralQueryRequest();
queryRequest.getResourceCredentials().put(ResourceWebClient.BEARER_TOKEN_KEY, resource.getToken());
queryRequest.setResourceUUID(resourceUUID);
queryRequest.setQuery(((Map)queryObject).get("query"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import edu.harvard.dbmi.avillach.data.entity.Resource;
import edu.harvard.dbmi.avillach.data.repository.ResourceRepository;
import edu.harvard.dbmi.avillach.domain.GeneralQueryRequest;
import edu.harvard.dbmi.avillach.domain.QueryRequest;
import edu.harvard.dbmi.avillach.domain.ResourceInfo;
import edu.harvard.dbmi.avillach.util.Utilities;
Expand Down Expand Up @@ -46,7 +47,7 @@ public ResourceInfo info(UUID resourceId, QueryRequest credentialsQueryRequest,
throw new ApplicationException(ApplicationException.MISSING_RESOURCE_PATH);
}
if (credentialsQueryRequest == null){
credentialsQueryRequest = new QueryRequest();
credentialsQueryRequest = new GeneralQueryRequest();
}
if (credentialsQueryRequest.getResourceCredentials() == null){
credentialsQueryRequest.setResourceCredentials(new HashMap<String, String>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
import edu.harvard.dbmi.avillach.data.entity.Resource;
import edu.harvard.dbmi.avillach.data.repository.QueryRepository;
import edu.harvard.dbmi.avillach.data.repository.ResourceRepository;
import edu.harvard.dbmi.avillach.domain.GICQueryRequest;
import edu.harvard.dbmi.avillach.domain.GeneralQueryRequest;
import edu.harvard.dbmi.avillach.domain.QueryRequest;
import edu.harvard.dbmi.avillach.domain.QueryStatus;
import edu.harvard.dbmi.avillach.security.JWTFilter;
import edu.harvard.dbmi.avillach.util.Utilities;
import edu.harvard.dbmi.avillach.util.exception.ApplicationException;
import edu.harvard.dbmi.avillach.util.exception.ProtocolException;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -93,7 +94,7 @@ public QueryStatus query(QueryRequest dataQueryRequest, HttpHeaders headers) {
* @return {@link QueryStatus}
*/
@Transactional
public QueryStatus queryStatus(UUID queryId, QueryRequest credentialsQueryRequest, HttpHeaders headers) {
public QueryStatus queryStatus(UUID queryId, GeneralQueryRequest credentialsQueryRequest, HttpHeaders headers) {
if (queryId == null){
throw new ProtocolException(ProtocolException.MISSING_QUERY_ID);
}
Expand Down Expand Up @@ -282,7 +283,7 @@ public QueryStatus queryMetadata(UUID queryId, HttpHeaders headers){
* and resource specific query (could be a string or a json object)
* @return {@link QueryStatus}
*/
public QueryStatus institutionalQuery(QueryRequest dataQueryRequest, HttpHeaders headers, String email) {
public QueryStatus institutionalQuery(GICQueryRequest dataQueryRequest, HttpHeaders headers, String email) {
String siteCode = siteParsingService.parseSiteOfOrigin(email).orElseThrow(() -> new RuntimeException("Bad email"));
dataQueryRequest.setInstitutionOfOrigin(siteCode);
Resource resource = verifyQueryRequest(dataQueryRequest, headers);
Expand Down Expand Up @@ -314,19 +315,16 @@ private Query copyQuery(QueryRequest dataQueryRequest, Resource resource, QueryS
throw new ProtocolException(ProtocolException.INCORRECTLY_FORMATTED_REQUEST);
}
}

Map<String, Object> metaData = response.getResultMetadata();
metaData = metaData == null ? new HashMap<>() : metaData;
if (dataQueryRequest.getCommonAreaUUID() != null) {
metaData.put("commonAreaUUID", dataQueryRequest.getCommonAreaUUID());
}

if (!StringUtils.isEmpty(dataQueryRequest.getInstitutionOfOrigin())) {
metaData.put("site", dataQueryRequest.getInstitutionOfOrigin());
if (dataQueryRequest instanceof GICQueryRequest) {
GICQueryRequest gicRequest = (GICQueryRequest) dataQueryRequest;
metaData.put("commonAreaUUID", gicRequest.getCommonAreaUUID());
metaData.put("site", gicRequest.getInstitutionOfOrigin());
metaData.put("sharingStatus", DataSharingStatus.Unknown);
}

metaData.put("sharingStatus", DataSharingStatus.Unknown);

queryEntity.setQuery(queryJson);

if (!metaData.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import edu.harvard.dbmi.avillach.data.entity.Resource;
import edu.harvard.dbmi.avillach.data.repository.ResourceRepository;
import edu.harvard.dbmi.avillach.domain.PaginatedSearchResult;
import edu.harvard.dbmi.avillach.domain.GeneralQueryRequest;
import edu.harvard.dbmi.avillach.domain.QueryRequest;
import edu.harvard.dbmi.avillach.domain.SearchResults;
import edu.harvard.dbmi.avillach.util.Utilities;
Expand Down Expand Up @@ -33,7 +34,7 @@ public class PicsureSearchService {
* Executes a concept search against a target resource
*
* @param resourceId - UUID of target resource
* @param searchQueryRequest - {@link QueryRequest} containing resource specific credentials object
* @param searchQueryRequest - {@link GeneralQueryRequest} containing resource specific credentials object
* and resource specific query (could be a string or a json object)
* @param headers
* @return {@link SearchResults}
Expand Down Expand Up @@ -65,7 +66,7 @@ public SearchResults search(UUID resourceId, QueryRequest searchQueryRequest, Ht
return resourceWebClient.search(resource.getResourceRSPath(), searchQueryRequest);
}

public PaginatedSearchResult<?> searchGenomicConceptValues(UUID resourceId, QueryRequest queryRequest, String conceptPath, String query, Integer page, Integer size
public PaginatedSearchResult<?> searchGenomicConceptValues(UUID resourceId, GeneralQueryRequest queryRequest, String conceptPath, String query, Integer page, Integer size
, HttpHeaders headers) {
Resource resource = resourceRepo.getById(resourceId);
if (resource == null){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import edu.harvard.dbmi.avillach.PicSureWarInit;
import edu.harvard.dbmi.avillach.data.entity.Resource;
import edu.harvard.dbmi.avillach.data.repository.ResourceRepository;
import edu.harvard.dbmi.avillach.domain.QueryRequest;
import edu.harvard.dbmi.avillach.domain.GeneralQueryRequest;
import edu.harvard.dbmi.avillach.domain.ResourceInfo;
import edu.harvard.dbmi.avillach.util.exception.ApplicationException;

Expand Down Expand Up @@ -126,7 +126,7 @@ private boolean testPSAMAResponds() throws UnsupportedOperationException, IOExce

private boolean testResourcesRespond(List<Resource> resourcesToTest) {
for(Resource resource : resourcesToTest) {
ResourceInfo info = new ResourceWebClient().info(resource.getResourceRSPath(), new QueryRequest());
ResourceInfo info = new ResourceWebClient().info(resource.getResourceRSPath(), new GeneralQueryRequest());
if(info==null) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import edu.harvard.dbmi.avillach.data.entity.Resource;
import edu.harvard.dbmi.avillach.data.repository.ResourceRepository;
import edu.harvard.dbmi.avillach.domain.QueryRequest;
import edu.harvard.dbmi.avillach.domain.GeneralQueryRequest;
import edu.harvard.dbmi.avillach.domain.ResourceInfo;
import edu.harvard.dbmi.avillach.service.PicsureInfoService;
import edu.harvard.dbmi.avillach.service.ResourceWebClient;
Expand Down Expand Up @@ -60,7 +60,7 @@ public void setUp() {

@Test
public void testInfoEndpoints() {
QueryRequest infoRequest = new QueryRequest();
GeneralQueryRequest infoRequest = new GeneralQueryRequest();
Map<String, String> clientCredentials = new HashMap<String, String>();
infoRequest.setResourceCredentials(clientCredentials);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.nio.charset.StandardCharsets;
import java.util.*;

import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
Expand All @@ -32,7 +31,7 @@
import edu.harvard.dbmi.avillach.data.entity.Resource;
import edu.harvard.dbmi.avillach.data.repository.QueryRepository;
import edu.harvard.dbmi.avillach.data.repository.ResourceRepository;
import edu.harvard.dbmi.avillach.domain.QueryRequest;
import edu.harvard.dbmi.avillach.domain.GeneralQueryRequest;
import edu.harvard.dbmi.avillach.domain.QueryStatus;
import edu.harvard.dbmi.avillach.service.PicsureQueryService;
import edu.harvard.dbmi.avillach.service.ResourceWebClient;
Expand Down Expand Up @@ -111,7 +110,7 @@ public void testQueryEmptyRequest() {
@Test
public void testQueryMissingResourceId() {

QueryRequest dataQueryRequest = new QueryRequest();
GeneralQueryRequest dataQueryRequest = new GeneralQueryRequest();
// At this level we don't check the credentials themselves, just that the map
// exists
Map<String, String> clientCredentials = new HashMap<String, String>();
Expand All @@ -134,7 +133,7 @@ public void testQueryMissingResourceId() {
@Test
public void testQueryInvalidResourceId() {

QueryRequest dataQueryRequest = new QueryRequest();
GeneralQueryRequest dataQueryRequest = new GeneralQueryRequest();
// At this level we don't check the credentials themselves, just that the map
// exists
Map<String, String> clientCredentials = new HashMap<String, String>();
Expand All @@ -155,7 +154,7 @@ public void testQueryInvalidResourceId() {

@Test
public void testQueryValidRequest() {
QueryRequest dataQueryRequest = new QueryRequest();
GeneralQueryRequest dataQueryRequest = new GeneralQueryRequest();
// At this level we don't check the credentials themselves, just that the map exists
Map<String, String> clientCredentials = new HashMap<String, String>();
dataQueryRequest.setResourceCredentials(clientCredentials);
Expand Down Expand Up @@ -184,7 +183,7 @@ public void testQueryValidRequest() {
@Test
public void testQueryStatusNoId() {

QueryRequest statusRequest = new QueryRequest();
GeneralQueryRequest statusRequest = new GeneralQueryRequest();
Map<String, String> clientCredentials = new HashMap<String, String>();
statusRequest.setResourceCredentials(clientCredentials);
try {
Expand All @@ -201,7 +200,7 @@ public void testQueryStatusNoId() {
@Test
public void testQueryStatusInvalidId() {

QueryRequest statusRequest = new QueryRequest();
GeneralQueryRequest statusRequest = new GeneralQueryRequest();
Map<String, String> clientCredentials = new HashMap<String, String>();
statusRequest.setResourceCredentials(clientCredentials);

Expand All @@ -220,7 +219,7 @@ public void testQueryStatusInvalidId() {
@Test
public void testQueryStatusValid() {

QueryRequest statusRequest = new QueryRequest();
GeneralQueryRequest statusRequest = new GeneralQueryRequest();
Map<String, String> clientCredentials = new HashMap<String, String>();
statusRequest.setResourceCredentials(clientCredentials);
// Setup a pre-existing query Entity
Expand Down Expand Up @@ -253,7 +252,7 @@ public void testQueryStatusValid() {
public void testQueryResultNoId() {


QueryRequest resultRequest = new QueryRequest();
GeneralQueryRequest resultRequest = new GeneralQueryRequest();
Map<String, String> clientCredentials = new HashMap<String, String>();
resultRequest.setResourceCredentials(clientCredentials);
try {
Expand All @@ -271,7 +270,7 @@ public void testQueryResultNoId() {
public void testQueryResultInvalidId() {


QueryRequest resultRequest = new QueryRequest();
GeneralQueryRequest resultRequest = new GeneralQueryRequest();
Map<String, String> clientCredentials = new HashMap<String, String>();
resultRequest.setResourceCredentials(clientCredentials);
try {
Expand All @@ -290,7 +289,7 @@ public void testQueryResultInvalidId() {
public void testQueryResultValid() {


QueryRequest resultRequest = new QueryRequest();
GeneralQueryRequest resultRequest = new GeneralQueryRequest();
Map<String, String> clientCredentials = new HashMap<String, String>();
resultRequest.setResourceCredentials(clientCredentials);

Expand Down Expand Up @@ -331,7 +330,7 @@ public void testQuerySyncNoQuery() {
@Test
public void testQuerySyncNoResourceId() {

QueryRequest dataQueryRequest = new QueryRequest();
GeneralQueryRequest dataQueryRequest = new GeneralQueryRequest();
// At this level we don't check the credentials themselves, just that the map
// exists
Map<String, String> clientCredentials = new HashMap<String, String>();
Expand All @@ -353,7 +352,7 @@ public void testQuerySyncNoResourceId() {
@Test
public void testQuerySyncInvalidResourceId() {

QueryRequest dataQueryRequest = new QueryRequest();
GeneralQueryRequest dataQueryRequest = new GeneralQueryRequest();
// At this level we don't check the credentials themselves, just that the map
// exists
Map<String, String> clientCredentials = new HashMap<String, String>();
Expand All @@ -374,7 +373,7 @@ public void testQuerySyncInvalidResourceId() {
@Test
public void testQuerySyncValidNoResponseId() {

QueryRequest dataQueryRequest = new QueryRequest();
GeneralQueryRequest dataQueryRequest = new GeneralQueryRequest();
// At this level we don't check the credentials themselves, just that the map
// exists
Map<String, String> clientCredentials = new HashMap<String, String>();
Expand Down Expand Up @@ -446,7 +445,7 @@ public void testShouldQueryMetadata() {
@Test
public void testQuerySyncValidWithResponseId() {

QueryRequest dataQueryRequest = new QueryRequest();
GeneralQueryRequest dataQueryRequest = new GeneralQueryRequest();
// At this level we don't check the credentials themselves, just that the map
// exists
Map<String, String> clientCredentials = new HashMap<String, String>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.UUID;

import edu.harvard.dbmi.avillach.data.entity.Resource;
import edu.harvard.dbmi.avillach.domain.QueryRequest;
import edu.harvard.dbmi.avillach.domain.GeneralQueryRequest;
import org.junit.runner.RunWith;
import org.mockito.ArgumentMatchers;
import org.mockito.InjectMocks;
Expand Down Expand Up @@ -58,7 +58,7 @@ public void setUp() {

@Test
public void testSearch() {
QueryRequest searchQueryRequest = new QueryRequest();
GeneralQueryRequest searchQueryRequest = new GeneralQueryRequest();
Map<String, String> clientCredentials = new HashMap<String, String>();
clientCredentials.put("bearer key", "bearer token");
searchQueryRequest.setResourceCredentials(clientCredentials);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ public void testQuery() throws IOException {


//Create multiple queries and add them to a main query as a list
QueryRequest queryRequest1 = new QueryRequest();
QueryRequest queryRequest2 = new QueryRequest();
QueryRequest queryRequest1 = new GeneralQueryRequest();
QueryRequest queryRequest2 = new GeneralQueryRequest();
Map<String, String> credentials = new HashMap<String, String>();
queryRequest1.setResourceCredentials(credentials);
queryRequest1.setQuery(queryString);
Expand All @@ -136,7 +136,7 @@ public void testQuery() throws IOException {
queryList.add(queryRequest1);
queryList.add(queryRequest2);

QueryRequest topQuery = new QueryRequest();
QueryRequest topQuery = new GeneralQueryRequest();
topQuery.setQuery(queryList);
topQuery.setResourceUUID(aggregateUUID);

Expand Down Expand Up @@ -234,7 +234,7 @@ public void testQueryStatus() throws IOException {
.withStatus(200)
.withBody(objectMapper.writeValueAsString(resourceResponse))));

QueryRequest request = new QueryRequest();
QueryRequest request = new GeneralQueryRequest();
Map<String, String> credentials = new HashMap<String, String>();
request.setResourceCredentials(credentials);
String body = objectMapper.writeValueAsString(request);
Expand Down Expand Up @@ -309,12 +309,12 @@ public void testResult() throws IOException, InterruptedException {
.withStatus(200)
.withBody(objectMapper.writeValueAsString(resultResponse))));

QueryRequest resultRequest = new QueryRequest();
QueryRequest resultRequest = new GeneralQueryRequest();

Map<String, String> credentials = new HashMap<String, String>();
credentials.put(IRCTResourceRS.IRCT_BEARER_TOKEN_KEY, token);

QueryRequest request = new QueryRequest();
QueryRequest request = new GeneralQueryRequest();
request.setResourceCredentials(credentials);
String body = objectMapper.writeValueAsString(request);

Expand Down
Loading

0 comments on commit 6ae209c

Please sign in to comment.