Skip to content

Commit

Permalink
feat(openchallenges): create endpoint to search EDAM concepts (#2622)
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaffter authored Apr 10, 2024
1 parent ad72df8 commit d503473
Show file tree
Hide file tree
Showing 37 changed files with 1,658 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
.permitAll().pathMatchers("/api/v1/challengeInputDataTypes/**")
.permitAll().pathMatchers("/api/v1/challengePlatforms/**")
.permitAll().pathMatchers("/api/v1/challenges/**")
.permitAll().pathMatchers("/api/v1/edamConcepts/**")
.permitAll().pathMatchers("/api/v1/images/**")
.permitAll().pathMatchers("/api/v1/organizations/**")
.permitAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ src/main/java/org/sagebionetworks/openchallenges/challenge/service/api/Challenge
src/main/java/org/sagebionetworks/openchallenges/challenge/service/api/ChallengePlatformApi.java
src/main/java/org/sagebionetworks/openchallenges/challenge/service/api/ChallengePlatformApiController.java
src/main/java/org/sagebionetworks/openchallenges/challenge/service/api/ChallengePlatformApiDelegate.java
src/main/java/org/sagebionetworks/openchallenges/challenge/service/api/EdamConceptApi.java
src/main/java/org/sagebionetworks/openchallenges/challenge/service/api/EdamConceptApiController.java
src/main/java/org/sagebionetworks/openchallenges/challenge/service/api/EdamConceptApiDelegate.java
src/main/java/org/sagebionetworks/openchallenges/challenge/service/configuration/EnumConverterConfiguration.java
src/main/java/org/sagebionetworks/openchallenges/challenge/service/configuration/HomeController.java
src/main/java/org/sagebionetworks/openchallenges/challenge/service/configuration/SpringDocConfiguration.java
Expand All @@ -35,6 +38,9 @@ src/main/java/org/sagebionetworks/openchallenges/challenge/service/model/dto/Cha
src/main/java/org/sagebionetworks/openchallenges/challenge/service/model/dto/ChallengeSubmissionTypeDto.java
src/main/java/org/sagebionetworks/openchallenges/challenge/service/model/dto/ChallengesPageDto.java
src/main/java/org/sagebionetworks/openchallenges/challenge/service/model/dto/ChallengesPerYearDto.java
src/main/java/org/sagebionetworks/openchallenges/challenge/service/model/dto/EdamConceptDto.java
src/main/java/org/sagebionetworks/openchallenges/challenge/service/model/dto/EdamConceptSearchQueryDto.java
src/main/java/org/sagebionetworks/openchallenges/challenge/service/model/dto/EdamConceptsPageDto.java
src/main/java/org/sagebionetworks/openchallenges/challenge/service/model/dto/EdamDataDto.java
src/main/java/org/sagebionetworks/openchallenges/challenge/service/model/dto/EdamOperationDto.java
src/main/java/org/sagebionetworks/openchallenges/challenge/service/model/dto/PageMetadataDto.java
Expand Down
30 changes: 30 additions & 0 deletions apps/openchallenges/challenge-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,43 @@ jacocoTestReport {
reports {
xml.required = true
}

afterEvaluate {
// A single star (*) selects files AND subdirectories.
// Exclude Java classes from the JaCoCo report. These files must be excluded from SonarCloud
// report separatedly (see SonarCloud config)
def autoGeneratedFiles = [
'**/api/*.*',
'**/configuration/EnumConverterConfiguration*.*',
'**/configuration/HomeController*.*',
'**/configuration/SpringDocConfiguration*.*',
'**/model/dto/**',
'**/RFC3339DateFormat.*'
]
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: autoGeneratedFiles
)
}))
}
}

sonar {
// A single star (*) only selects files, not subdirectories.
def autoGeneratedFiles = [
'**/api/*',
'**/configuration/EnumConverterConfiguration*.*',
'**/configuration/HomeController*.*',
'**/configuration/SpringDocConfiguration*.*',
'**/model/dto/**',
'**/RFC3339DateFormat.*'
]
properties {
property("sonar.host.url", "https://sonarcloud.io")
property("sonar.organization", "sage-bionetworks")
property("sonar.projectKey", "${project.name}")
// We still scan the auto-generated files to be aware of the bugs and code smells they include.
// property("sonar.exclusions", autoGeneratedFiles.join(","))
property("sonar.coverage.exclusions", autoGeneratedFiles.join(","))
// Include the pull request number (ignored if not set)
property("sonar.pullrequest.key", System.getenv('SONAR_PULL_REQUEST_NUMBER'))
}
Expand Down
10 changes: 9 additions & 1 deletion apps/openchallenges/challenge-service/requests.http
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,12 @@ GET {{basePath}}/challenges/1/contributions

### Get the number of challenges tracked per year.

GET {{basePath}}/challengeAnalytics/challengesPerYear
GET {{basePath}}/challengeAnalytics/challengesPerYear

### List the EDAM concepts

GET {{basePath}}/edamConcepts

### List the EDAM concepts that match the space-separated search terms "sequence".

GET {{basePath}}/edamConcepts?searchTerms=sequence
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (6.2.1).
* https://openapi-generator.tech Do not edit the class manually.
*/
package org.sagebionetworks.openchallenges.challenge.service.api;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import javax.annotation.Generated;
import javax.validation.Valid;
import javax.validation.constraints.*;
import org.sagebionetworks.openchallenges.challenge.service.model.dto.BasicErrorDto;
import org.sagebionetworks.openchallenges.challenge.service.model.dto.EdamConceptSearchQueryDto;
import org.sagebionetworks.openchallenges.challenge.service.model.dto.EdamConceptsPageDto;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
@Validated
@Tag(name = "EdamConcept", description = "Operations about EDAM concepts.")
public interface EdamConceptApi {

default EdamConceptApiDelegate getDelegate() {
return new EdamConceptApiDelegate() {};
}

/**
* GET /edamConcepts : List EDAM concepts List EDAM concepts
*
* @param edamConceptSearchQuery The search query used to find EDAM concepts. (optional)
* @return Success (status code 200) or Invalid request (status code 400) or The request cannot be
* fulfilled due to an unexpected server error (status code 500)
*/
@Operation(
operationId = "listEdamConcepts",
summary = "List EDAM concepts",
tags = {"EdamConcept"},
responses = {
@ApiResponse(
responseCode = "200",
description = "Success",
content = {
@Content(
mediaType = "application/json",
schema = @Schema(implementation = EdamConceptsPageDto.class)),
@Content(
mediaType = "application/problem+json",
schema = @Schema(implementation = EdamConceptsPageDto.class))
}),
@ApiResponse(
responseCode = "400",
description = "Invalid request",
content = {
@Content(
mediaType = "application/json",
schema = @Schema(implementation = BasicErrorDto.class)),
@Content(
mediaType = "application/problem+json",
schema = @Schema(implementation = BasicErrorDto.class))
}),
@ApiResponse(
responseCode = "500",
description = "The request cannot be fulfilled due to an unexpected server error",
content = {
@Content(
mediaType = "application/json",
schema = @Schema(implementation = BasicErrorDto.class)),
@Content(
mediaType = "application/problem+json",
schema = @Schema(implementation = BasicErrorDto.class))
})
})
@RequestMapping(
method = RequestMethod.GET,
value = "/edamConcepts",
produces = {"application/json", "application/problem+json"})
default ResponseEntity<EdamConceptsPageDto> listEdamConcepts(
@Parameter(
name = "edamConceptSearchQuery",
description = "The search query used to find EDAM concepts.")
@Valid
EdamConceptSearchQueryDto edamConceptSearchQuery) {
return getDelegate().listEdamConcepts(edamConceptSearchQuery);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.sagebionetworks.openchallenges.challenge.service.api;

import java.util.Optional;
import javax.annotation.Generated;
import javax.validation.constraints.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
@Controller
@RequestMapping("${openapi.openChallengesChallengeREST.base-path:/v1}")
public class EdamConceptApiController implements EdamConceptApi {

private final EdamConceptApiDelegate delegate;

public EdamConceptApiController(@Autowired(required = false) EdamConceptApiDelegate delegate) {
this.delegate = Optional.ofNullable(delegate).orElse(new EdamConceptApiDelegate() {});
}

@Override
public EdamConceptApiDelegate getDelegate() {
return delegate;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.sagebionetworks.openchallenges.challenge.service.api;

import java.util.Optional;
import javax.annotation.Generated;
import org.sagebionetworks.openchallenges.challenge.service.model.dto.EdamConceptSearchQueryDto;
import org.sagebionetworks.openchallenges.challenge.service.model.dto.EdamConceptsPageDto;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.context.request.NativeWebRequest;

/**
* A delegate to be called by the {@link EdamConceptApiController}}. Implement this interface with a
* {@link org.springframework.stereotype.Service} annotated class.
*/
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
public interface EdamConceptApiDelegate {

default Optional<NativeWebRequest> getRequest() {
return Optional.empty();
}

/**
* GET /edamConcepts : List EDAM concepts List EDAM concepts
*
* @param edamConceptSearchQuery The search query used to find EDAM concepts. (optional)
* @return Success (status code 200) or Invalid request (status code 400) or The request cannot be
* fulfilled due to an unexpected server error (status code 500)
* @see EdamConceptApi#listEdamConcepts
*/
default ResponseEntity<EdamConceptsPageDto> listEdamConcepts(
EdamConceptSearchQueryDto edamConceptSearchQuery) {
getRequest()
.ifPresent(
request -> {
for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
String exampleString = "null";
ApiUtil.setExampleResponse(request, "application/json", exampleString);
break;
}
if (mediaType.isCompatibleWith(MediaType.valueOf("application/problem+json"))) {
String exampleString =
"Custom MIME type example not yet supported: application/problem+json";
ApiUtil.setExampleResponse(request, "application/problem+json", exampleString);
break;
}
}
});
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.sagebionetworks.openchallenges.challenge.service.api;

import org.sagebionetworks.openchallenges.challenge.service.model.dto.EdamConceptSearchQueryDto;
import org.sagebionetworks.openchallenges.challenge.service.model.dto.EdamConceptsPageDto;
import org.sagebionetworks.openchallenges.challenge.service.service.EdamConceptService;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

@Component
public class EdamConceptApiDelegateImpl implements EdamConceptApiDelegate {

private final EdamConceptService edamConceptService;

public EdamConceptApiDelegateImpl(EdamConceptService edamConceptService) {
this.edamConceptService = edamConceptService;
}

@Override
public ResponseEntity<EdamConceptsPageDto> listEdamConcepts(EdamConceptSearchQueryDto query) {
return ResponseEntity.ok(edamConceptService.listEdamConcepts(query));
}
}
Loading

0 comments on commit d503473

Please sign in to comment.