Skip to content

Commit

Permalink
feat(openchallenges): filter challenges by Operation (backend) (#2665)
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaffter authored May 10, 2024
1 parent d19da69 commit 6faa151
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 237 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ src/main/java/org/sagebionetworks/openchallenges/challenge/service/model/dto/Eda
src/main/java/org/sagebionetworks/openchallenges/challenge/service/model/dto/EdamConceptSearchQueryDto.java
src/main/java/org/sagebionetworks/openchallenges/challenge/service/model/dto/EdamConceptSortDto.java
src/main/java/org/sagebionetworks/openchallenges/challenge/service/model/dto/EdamConceptsPageDto.java
src/main/java/org/sagebionetworks/openchallenges/challenge/service/model/dto/EdamOperationDto.java
src/main/java/org/sagebionetworks/openchallenges/challenge/service/model/dto/EdamSectionDto.java
src/main/java/org/sagebionetworks/openchallenges/challenge/service/model/dto/PageMetadataDto.java
src/main/java/org/sagebionetworks/openchallenges/challenge/service/model/dto/SimpleChallengePlatformDto.java
Expand Down
4 changes: 4 additions & 0 deletions apps/openchallenges/challenge-service/requests.http
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ GET {{basePath}}/challenges?searchTerms=mortality%20dream

GET {{basePath}}/challenges?minStartDate=2017-01-01&maxStartDate=2017-12-31

### List the challenges that have their operation ID set to 2230.

GET {{basePath}}/challenges?operations=2230

### Get the challenges whose input data types include the EDAM concept ID 2 or 18

GET {{basePath}}/challenges?inputDataTypes=2,18
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ default ResponseEntity<ChallengeDto> getChallenge(Long challengeId) {
for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
String exampleString =
"{ \"avatarUrl\" : \"https://openchallenges.io\", \"endDate\" : \"2017-07-21T00:00:00.000+00:00\", \"description\" : \"This is an example description of the challenge.\", \"platform\" : { \"name\" : \"name\", \"id\" : 1, \"slug\" : \"example-challenge-platform\" }, \"starredCount\" : 100, \"createdAt\" : \"2022-07-04T22:19:11Z\", \"incentives\" : [ \"publication\", \"publication\" ], \"submissionTypes\" : [ \"container_image\", \"container_image\" ], \"websiteUrl\" : \"https://openchallenges.io\", \"name\" : \"name\", \"id\" : 1, \"categories\" : [ \"featured\", \"featured\" ], \"headline\" : \"Example challenge headline\", \"operation\" : { \"classId\" : \"http://edamontology.org/operation_0230\", \"preferredLabel\" : \"Sequence generation\" }, \"slug\" : \"awesome-challenge\", \"startDate\" : \"2017-07-21T00:00:00.000+00:00\", \"doi\" : \"https://doi.org/123/abc\", \"status\" : \"active\", \"inputDataTypes\" : [ { \"classId\" : \"http://edamontology.org/data_0850\", \"preferredLabel\" : \"Sequence set\", \"id\" : 1 }, { \"classId\" : \"http://edamontology.org/data_0850\", \"preferredLabel\" : \"Sequence set\", \"id\" : 1 } ], \"updatedAt\" : \"2022-07-04T22:19:11Z\" }";
"{ \"avatarUrl\" : \"https://openchallenges.io\", \"endDate\" : \"2017-07-21T00:00:00.000+00:00\", \"description\" : \"This is an example description of the challenge.\", \"platform\" : { \"name\" : \"name\", \"id\" : 1, \"slug\" : \"example-challenge-platform\" }, \"starredCount\" : 100, \"createdAt\" : \"2022-07-04T22:19:11Z\", \"incentives\" : [ \"publication\", \"publication\" ], \"submissionTypes\" : [ \"container_image\", \"container_image\" ], \"websiteUrl\" : \"https://openchallenges.io\", \"name\" : \"name\", \"id\" : 1, \"categories\" : [ \"featured\", \"featured\" ], \"headline\" : \"Example challenge headline\", \"operation\" : { \"classId\" : \"http://edamontology.org/data_0850\", \"preferredLabel\" : \"Sequence set\", \"id\" : 1 }, \"slug\" : \"awesome-challenge\", \"startDate\" : \"2017-07-21T00:00:00.000+00:00\", \"doi\" : \"https://doi.org/123/abc\", \"status\" : \"active\", \"inputDataTypes\" : [ { \"classId\" : \"http://edamontology.org/data_0850\", \"preferredLabel\" : \"Sequence set\", \"id\" : 1 }, { \"classId\" : \"http://edamontology.org/data_0850\", \"preferredLabel\" : \"Sequence set\", \"id\" : 1 } ], \"updatedAt\" : \"2022-07-04T22:19:11Z\" }";
ApiUtil.setExampleResponse(request, "application/json", exampleString);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class ChallengeDto {
private Integer starredCount = 0;

@JsonProperty("operation")
private EdamOperationDto operation = null;
private EdamConceptDto operation = null;

@JsonProperty("createdAt")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
Expand Down Expand Up @@ -510,7 +510,7 @@ public void setStarredCount(Integer starredCount) {
this.starredCount = starredCount;
}

public ChallengeDto operation(EdamOperationDto operation) {
public ChallengeDto operation(EdamConceptDto operation) {
this.operation = operation;
return this;
}
Expand All @@ -522,11 +522,11 @@ public ChallengeDto operation(EdamOperationDto operation) {
*/
@Valid
@Schema(name = "operation", required = false)
public EdamOperationDto getOperation() {
public EdamConceptDto getOperation() {
return operation;
}

public void setOperation(EdamOperationDto operation) {
public void setOperation(EdamConceptDto operation) {
this.operation = operation;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public class ChallengeSearchQueryDto {
@Valid
private List<Long> inputDataTypes = null;

@JsonProperty("operations")
@Valid
private List<Long> operations = null;

@JsonProperty("categories")
@Valid
private List<ChallengeCategoryDto> categories = null;
Expand Down Expand Up @@ -413,6 +417,36 @@ public void setInputDataTypes(List<Long> inputDataTypes) {
this.inputDataTypes = inputDataTypes;
}

public ChallengeSearchQueryDto operations(List<Long> operations) {
this.operations = operations;
return this;
}

public ChallengeSearchQueryDto addOperationsItem(Long operationsItem) {
if (this.operations == null) {
this.operations = new ArrayList<>();
}
this.operations.add(operationsItem);
return this;
}

/**
* An array of EDAM concept ID used to filter the results.
*
* @return operations
*/
@Schema(
name = "operations",
description = "An array of EDAM concept ID used to filter the results.",
required = false)
public List<Long> getOperations() {
return operations;
}

public void setOperations(List<Long> operations) {
this.operations = operations;
}

public ChallengeSearchQueryDto categories(List<ChallengeCategoryDto> categories) {
this.categories = categories;
return this;
Expand Down Expand Up @@ -489,6 +523,7 @@ public boolean equals(Object o) {
&& Objects.equals(this.status, challengeSearchQuery.status)
&& Objects.equals(this.submissionTypes, challengeSearchQuery.submissionTypes)
&& Objects.equals(this.inputDataTypes, challengeSearchQuery.inputDataTypes)
&& Objects.equals(this.operations, challengeSearchQuery.operations)
&& Objects.equals(this.categories, challengeSearchQuery.categories)
&& Objects.equals(this.searchTerms, challengeSearchQuery.searchTerms);
}
Expand All @@ -509,6 +544,7 @@ public int hashCode() {
status,
submissionTypes,
inputDataTypes,
operations,
categories,
searchTerms);
}
Expand All @@ -530,6 +566,7 @@ public String toString() {
sb.append(" status: ").append(toIndentedString(status)).append("\n");
sb.append(" submissionTypes: ").append(toIndentedString(submissionTypes)).append("\n");
sb.append(" inputDataTypes: ").append(toIndentedString(inputDataTypes)).append("\n");
sb.append(" operations: ").append(toIndentedString(operations)).append("\n");
sb.append(" categories: ").append(toIndentedString(categories)).append("\n");
sb.append(" searchTerms: ").append(toIndentedString(searchTerms)).append("\n");
sb.append("}");
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ public class ChallengeEntity {

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "operation_id", nullable = true)
@IndexedEmbedded(includePaths = {"class_id", "preferred_label"})
@IndexedEmbedded(includePaths = {"id", "class_id", "preferred_label"})
@IndexingDependency(reindexOnUpdate = ReindexOnUpdate.SHALLOW)
private EdamOperationEntity operation;
private EdamConceptEntity operation;

@Column(name = "created_at")
@GenericField(name = "created_at", sortable = Sortable.YES)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class ChallengeMapper extends BaseMapper<ChallengeEntity, ChallengeDto> {
private static final Logger LOG = LoggerFactory.getLogger(ChallengeMapper.class);

private SimpleChallengePlatformMapper platformMapper = new SimpleChallengePlatformMapper();
private EdamOperationMapper edamOperationMapper = new EdamOperationMapper();
private EdamConceptMapper edamConceptMapper = new EdamConceptMapper();

@Override
Expand All @@ -38,7 +37,7 @@ public ChallengeDto convertToDto(ChallengeEntity entity, Object... args) {
dto.setStatus(ChallengeStatusDto.fromValue(entity.getStatus()));
dto.setPlatform(platformMapper.convertToDto(entity.getPlatform()));
if (entity.getOperation() != null) {
dto.setOperation(edamOperationMapper.convertToDto(entity.getOperation()));
dto.setOperation(edamConceptMapper.convertToDto(entity.getOperation()));
}
dto.submissionTypes(
entity.getSubmissionTypes().stream()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ private SearchResult<ChallengeEntity> getSearchResult(
if (query.getCategories() != null && !query.getCategories().isEmpty()) {
predicates.add(getCategoriesPredicate(pf, query));
}
if (query.getOperations() != null && !query.getOperations().isEmpty()) {
predicates.add(getChallengeOperationPredicate(pf, query));
}

SearchSort sort = getSearchSort(sf, query);
SearchPredicate sortPredicate = getSearchSortPredicate(pf, query);
Expand Down Expand Up @@ -150,6 +153,17 @@ private SearchPredicate getChallengePlatformPredicate(
.toPredicate();
}

private SearchPredicate getChallengeOperationPredicate(
SearchPredicateFactory pf, ChallengeSearchQueryDto query) {
return pf.bool(
b -> {
for (Long operation : query.getOperations()) {
b.should(pf.match().field("operation.id").matching(operation));
}
})
.toPredicate();
}

/**
* Matches the challenges whose at least one of their submission types is in the list of
* submission types specified.
Expand Down
Loading

0 comments on commit 6faa151

Please sign in to comment.