Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/main/java/org/breedinginsight/brapi/v2/BrAPIV2Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@
import org.breedinginsight.api.auth.ProgramSecured;
import org.breedinginsight.api.auth.ProgramSecuredRoleGroup;
import org.breedinginsight.api.auth.SecurityService;
import org.breedinginsight.api.model.v1.request.query.SearchRequest;
import org.breedinginsight.api.model.v1.validators.QueryValid;
import org.breedinginsight.brapi.v1.controller.BrapiVersion;
import org.breedinginsight.brapi.v1.model.request.query.BrapiQuery;
import org.breedinginsight.brapi.v2.model.request.query.ListQuery;
import org.breedinginsight.utilities.response.mappers.ListQueryMapper;
import org.breedinginsight.brapi.v2.services.BrAPIGermplasmService;
import org.breedinginsight.model.ProgramBrAPIEndpoints;
Expand Down Expand Up @@ -90,10 +92,24 @@ public BrAPIServerInfoResponse serverinfo() {
@Produces(MediaType.APPLICATION_JSON)
@ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.ALL})
public HttpResponse getLists(@PathVariable("programId") UUID programId, HttpRequest<String> request,
@QueryValue @QueryValid(using = ListQueryMapper.class) @Valid BrapiQuery queryParams
@QueryValue @QueryValid(using = ListQueryMapper.class) @Valid ListQuery queryParams
) throws DoesNotExistException, ApiException {
List<BrAPIListSummary> brapiLists = germplasmService.getGermplasmListsByProgramId(programId, request);
return ResponseUtils.getBrapiQueryResponse(brapiLists, listQueryMapper, queryParams);
List<BrAPIListSummary> brapiLists;

if (queryParams.getListType() == null) {
// TODO: in future return all list types but for now just return germplasm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just have this method return a 400 if the listType isn't specified?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't think the listType parameter was required but I can change it if it should be.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah...good point. Looked back at the spec, and you're spot on. I'll approve this!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool thanks!

brapiLists = germplasmService.getGermplasmListsByProgramId(programId, request);
} else {
// TODO: return appropriate lists by type, only germplasm currently
switch(queryParams.getListType()) {
case "germplasm":
default:
brapiLists = germplasmService.getGermplasmListsByProgramId(programId, request);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to above, maybe a 400 should be returned here.

Copy link
Member Author

@nickpalladino nickpalladino Jan 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could see the case for a 400 here if there is a listType specified but it's not one of the available ones.

}
}

SearchRequest searchRequest = queryParams.constructSearchRequest();
return ResponseUtils.getBrapiQueryResponse(brapiLists, listQueryMapper, queryParams, searchRequest);
}

@Get("/${micronaut.bi.api.version}/programs/{programId}" + BrapiVersion.BRAPI_V2 + "/{+path}")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.breedinginsight.brapi.v2.model.request.query;

import io.micronaut.core.annotation.Introspected;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.breedinginsight.api.model.v1.request.query.FilterRequest;
import org.breedinginsight.api.model.v1.request.query.SearchRequest;
import org.breedinginsight.brapi.v1.model.request.query.BrapiQuery;
import org.jooq.tools.StringUtils;

import java.util.ArrayList;
import java.util.List;

@Getter
@Introspected
public class ListQuery extends BrapiQuery {
private String listType;
private String name;
private String description;
private String size;
private String dateCreated;
private String ownerName;

public SearchRequest constructSearchRequest() {
List<FilterRequest> filters = new ArrayList<>();
if (!StringUtils.isBlank(getListType())) {
filters.add(constructFilterRequest("type", getListType()));
}
if (!StringUtils.isBlank(getName())) {
filters.add(constructFilterRequest("name", getName()));
}
if (!StringUtils.isBlank(getDescription())) {
filters.add(constructFilterRequest("description", getDescription()));
}
if (!StringUtils.isBlank(getSize())) {
filters.add(constructFilterRequest("size", getSize()));
}
if (!StringUtils.isBlank(getDateCreated())) {
filters.add(constructFilterRequest("dateCreated", getDateCreated()));
}
if (!StringUtils.isBlank(getOwnerName())) {
filters.add(constructFilterRequest("ownerName", getOwnerName()));
}
return new SearchRequest(filters);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Getter;
import org.brapi.v2.model.core.BrAPIListSummary;
import org.brapi.v2.model.core.BrAPITrial;
import org.breedinginsight.utilities.response.mappers.AbstractQueryMapper;

import javax.inject.Singleton;
Expand All @@ -15,7 +16,14 @@ public class ListQueryMapper extends AbstractQueryMapper {
private Map<String, Function<BrAPIListSummary, ?>> fields;

public ListQueryMapper() {
fields = Map.ofEntries();
fields = Map.ofEntries(
Map.entry("name", BrAPIListSummary::getListName),
Map.entry("description", BrAPIListSummary::getListDescription),
Map.entry("size", BrAPIListSummary::getListSize),
Map.entry("dateCreated", BrAPIListSummary::getDateCreated),
Map.entry("ownerName", BrAPIListSummary::getListOwnerName),
Map.entry("type", BrAPIListSummary::getListType)
);
}

@Override
Expand Down