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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.breedinginsight.brapi.v2.model.request.query.GermplasmQuery;
import org.breedinginsight.brapi.v2.model.response.mappers.GermplasmQueryMapper;
import org.breedinginsight.brapi.v2.services.BrAPIGermplasmService;
import org.breedinginsight.brapps.importer.model.base.Germplasm;
import org.breedinginsight.brapps.importer.model.exports.FileType;
import org.breedinginsight.daos.ProgramDAO;
import org.breedinginsight.model.DownloadFile;
Expand Down Expand Up @@ -102,6 +103,23 @@ public HttpResponse<Response<DataResponse<List<BrAPIGermplasm>>>> getGermplasm(
}
}

@Get("/${micronaut.bi.api.version}/programs/{programId}/germplasm/lists/{listDbId}/records{?queryParams*}")
@Produces(MediaType.APPLICATION_JSON)
@ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.ALL})
public HttpResponse<Response<DataResponse<List<BrAPIGermplasm>>>> getGermplasmListRecords(
@PathVariable("programId") UUID programId,
@PathVariable("listDbId") String listId,
@QueryValue @QueryValid(using = GermplasmQueryMapper.class) @Valid GermplasmQuery queryParams) {
try {
List<BrAPIGermplasm> germplasm = germplasmService.getGermplasmByList(programId, listId);
SearchRequest searchRequest = queryParams.constructSearchRequest();
return ResponseUtils.getBrapiQueryResponse(germplasm, germplasmQueryMapper, queryParams, searchRequest);
} catch (Exception e) {
log.info(e.getMessage(), e);
return HttpResponse.status(HttpStatus.INTERNAL_SERVER_ERROR, "Error retrieving germplasm list records");
}
}

@Get("/${micronaut.bi.api.version}/programs/{programId}/germplasm/lists/{listDbId}/export{?fileExtension}")
@Produces(value = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
@ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.ALL})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@Getter
@Introspected
public class GermplasmQuery extends BrapiQuery {
private String importEntryNumber;
private String accessionNumber;
private String defaultDisplayName;
private String breedingMethod;
Expand All @@ -26,6 +27,9 @@ public class GermplasmQuery extends BrapiQuery {

public SearchRequest constructSearchRequest() {
List<FilterRequest> filters = new ArrayList<>();
if (!StringUtils.isBlank(getImportEntryNumber())) {
filters.add(constructFilterRequest("importEntryNumber", getImportEntryNumber()));
}
if (!StringUtils.isBlank(getAccessionNumber())) {
filters.add(constructFilterRequest("accessionNumber", getAccessionNumber()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public class GermplasmQueryMapper extends AbstractQueryMapper {

public GermplasmQueryMapper() {
fields = Map.ofEntries(
Map.entry("importEntryNumber", (germplasm) ->
germplasm.getAdditionalInfo() != null && germplasm.getAdditionalInfo().has(BrAPIAdditionalInfoFields.GERMPLASM_IMPORT_ENTRY_NUMBER) ?
germplasm.getAdditionalInfo().get(BrAPIAdditionalInfoFields.GERMPLASM_IMPORT_ENTRY_NUMBER).getAsString() :
null),
Map.entry("accessionNumber", BrAPIGermplasm::getAccessionNumber),
Map.entry("defaultDisplayName", BrAPIGermplasm::getDefaultDisplayName),
Map.entry("breedingMethod", (germplasm) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.brapi.v2.model.core.BrAPIListTypes;
import org.brapi.v2.model.core.response.BrAPIListDetails;
import org.brapi.v2.model.core.response.BrAPIListsListResponse;
import org.brapi.v2.model.core.response.BrAPIListsSingleResponse;
import org.brapi.v2.model.germ.BrAPIGermplasm;
import org.brapi.v2.model.germ.BrAPIGermplasmSynonyms;
import org.breedinginsight.brapi.v2.constants.BrAPIAdditionalInfoFields;
Expand Down Expand Up @@ -151,6 +152,16 @@ public List<Map<String, Object>> processData(List<BrAPIGermplasm> germplasm){
return processedData;
}

public List<BrAPIGermplasm> getGermplasmByList(UUID programId, String listId) throws ApiException {
// get list germplasm names
BrAPIListsSingleResponse listResponse = brAPIListDAO.getListById(listId, programId);
if(Objects.nonNull(listResponse) && Objects.nonNull(listResponse.getResult())) {
List<String> germplasmNames = listResponse.getResult().getData();

// get list BrAPI germplasm variables
return germplasmDAO.getGermplasmByRawName(germplasmNames, programId);
} else throw new ApiException();
}
public DownloadFile exportGermplasmList(UUID programId, String listId, FileType fileExtension) throws ApiException, IOException {
List<Column> columns = GermplasmFileColumns.getOrderedColumns();

Expand Down