From 095342ffefcaa651bc4cae86b557eba0bbaf527c Mon Sep 17 00:00:00 2001 From: dmeidlin <14339308+dmeidlin@users.noreply.github.com> Date: Wed, 20 Nov 2024 09:51:38 -0500 Subject: [PATCH] revert GET list data objects from ListController --- .../brapi/v2/BrAPIGermplasmController.java | 24 ++-- .../brapi/v2/BrAPIListController.java | 124 +----------------- .../brapi/v2/dao/BrAPIListDAO.java | 31 ++--- .../v2/services/BrAPIGermplasmService.java | 14 +- .../brapi/v2/services/BrAPIListService.java | 5 - .../model/delta/DeltaEntityFactory.java | 57 +------- .../delta/DeltaGermplasmListDetails.java | 62 --------- .../delta/DeltaGermplasmListSummary.java | 16 --- .../model/delta/DeltaListDetails.java | 78 ----------- .../model/delta/DeltaListSummary.java | 20 --- .../breedinginsight/utilities/Utilities.java | 2 - 11 files changed, 40 insertions(+), 393 deletions(-) delete mode 100644 src/main/java/org/breedinginsight/model/delta/DeltaGermplasmListDetails.java delete mode 100644 src/main/java/org/breedinginsight/model/delta/DeltaGermplasmListSummary.java delete mode 100644 src/main/java/org/breedinginsight/model/delta/DeltaListDetails.java delete mode 100644 src/main/java/org/breedinginsight/model/delta/DeltaListSummary.java diff --git a/src/main/java/org/breedinginsight/brapi/v2/BrAPIGermplasmController.java b/src/main/java/org/breedinginsight/brapi/v2/BrAPIGermplasmController.java index 57ead5bd3..94cf9c9fc 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/BrAPIGermplasmController.java +++ b/src/main/java/org/breedinginsight/brapi/v2/BrAPIGermplasmController.java @@ -1,5 +1,6 @@ package org.breedinginsight.brapi.v2; +import com.drew.lang.annotations.Nullable; import io.micronaut.context.annotation.Property; import io.micronaut.http.HttpHeaders; import io.micronaut.http.HttpResponse; @@ -19,10 +20,11 @@ import org.brapi.v2.model.BrAPIIndexPagination; import org.brapi.v2.model.BrAPIMetadata; import org.brapi.v2.model.BrAPIStatus; -import org.brapi.v2.model.core.BrAPITrial; import org.brapi.v2.model.germ.*; import org.brapi.v2.model.germ.request.BrAPIGermplasmSearchRequest; -import org.brapi.v2.model.germ.response.*; +import org.brapi.v2.model.germ.response.BrAPIGermplasmListResponse; +import org.brapi.v2.model.germ.response.BrAPIGermplasmPedigreeResponse; +import org.brapi.v2.model.germ.response.BrAPIGermplasmProgenyResponse; import org.breedinginsight.api.auth.ProgramSecured; import org.breedinginsight.api.auth.ProgramSecuredRoleGroup; import org.breedinginsight.api.model.v1.request.query.SearchRequest; @@ -33,27 +35,25 @@ import org.breedinginsight.brapi.v2.constants.BrAPIAdditionalInfoFields; import org.breedinginsight.brapi.v2.dao.BrAPIGermplasmDAO; import org.breedinginsight.brapi.v2.model.request.query.GermplasmQuery; -import org.breedinginsight.brapps.importer.services.ExternalReferenceSource; -import org.breedinginsight.model.Program; -import org.breedinginsight.services.ProgramService; -import org.breedinginsight.utilities.Utilities; -import org.breedinginsight.utilities.response.mappers.GermplasmQueryMapper; import org.breedinginsight.brapi.v2.services.BrAPIGermplasmService; import org.breedinginsight.brapps.importer.model.exports.FileType; import org.breedinginsight.daos.ProgramDAO; import org.breedinginsight.model.DownloadFile; import org.breedinginsight.model.GermplasmGenotype; +import org.breedinginsight.model.Program; +import org.breedinginsight.services.ProgramService; import org.breedinginsight.services.brapi.BrAPIEndpointProvider; import org.breedinginsight.services.exceptions.AuthorizationException; import org.breedinginsight.services.exceptions.DoesNotExistException; import org.breedinginsight.services.geno.GenotypeService; +import org.breedinginsight.utilities.Utilities; import org.breedinginsight.utilities.response.ResponseUtils; +import org.breedinginsight.utilities.response.mappers.GermplasmQueryMapper; import javax.inject.Inject; import javax.validation.Valid; import java.util.*; import java.util.regex.Pattern; -import java.util.stream.Collectors; @Slf4j @Controller("/${micronaut.bi.api.version}") @@ -222,15 +222,17 @@ public HttpResponse>>> getGermplasm( } } - @Get("/programs/{programId}/germplasm/export{?fileExtension}") + @Get("/programs/{programId}/germplasm/export{?fileExtension,list}") @Produces(value = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") @ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.PROGRAM_SCOPED_ROLES}) public HttpResponse germplasmExport( - @PathVariable("programId") UUID programId, @QueryValue(defaultValue = "XLSX") String fileExtension) { + @PathVariable("programId") UUID programId, + @QueryValue(defaultValue = "XLSX") String fileExtension, + @QueryValue Optional list) { String downloadErrorMessage = "An error occurred while generating the download file. Contact the development team at bidevteam@cornell.edu."; try { FileType extension = Enum.valueOf(FileType.class, fileExtension); - DownloadFile germplasmListFile = germplasmService.exportGermplasm(programId, extension); + DownloadFile germplasmListFile = list.isEmpty() ? germplasmService.exportGermplasm(programId, extension) : germplasmService.exportGermplasmList(programId, list.get(), extension); HttpResponse germplasmExport = HttpResponse.ok(germplasmListFile.getStreamedFile()).header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename="+germplasmListFile.getFileName()+extension.getExtension()); return germplasmExport; } diff --git a/src/main/java/org/breedinginsight/brapi/v2/BrAPIListController.java b/src/main/java/org/breedinginsight/brapi/v2/BrAPIListController.java index 2d3324a65..3cb73dbae 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/BrAPIListController.java +++ b/src/main/java/org/breedinginsight/brapi/v2/BrAPIListController.java @@ -1,10 +1,10 @@ package org.breedinginsight.brapi.v2; -import io.micronaut.core.beans.BeanIntrospection; -import io.micronaut.core.beans.BeanProperty; -import io.micronaut.http.*; +import io.micronaut.http.HttpRequest; +import io.micronaut.http.HttpResponse; +import io.micronaut.http.HttpStatus; +import io.micronaut.http.MediaType; import io.micronaut.http.annotation.*; -import io.micronaut.http.server.types.files.StreamedFile; import io.micronaut.security.annotation.Secured; import io.micronaut.security.rules.SecurityRule; import lombok.extern.slf4j.Slf4j; @@ -18,27 +18,19 @@ import org.breedinginsight.api.model.v1.response.Response; 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.brapi.v2.services.BrAPIListService; -import org.breedinginsight.brapps.importer.model.exports.FileType; -import org.breedinginsight.model.DownloadFile; import org.breedinginsight.model.Program; -import org.breedinginsight.model.delta.DeltaListDetails; import org.breedinginsight.services.ProgramService; import org.breedinginsight.services.exceptions.DoesNotExistException; import org.breedinginsight.utilities.response.ResponseUtils; -import org.breedinginsight.utilities.response.mappers.AbstractQueryMapper; import org.breedinginsight.utilities.response.mappers.ListQueryMapper; import javax.inject.Inject; -import javax.validation.ConstraintViolation; import javax.validation.Valid; import javax.validation.Validator; import java.util.List; -import java.util.Set; import java.util.UUID; -import java.util.stream.Collectors; @Slf4j @Controller("/${micronaut.bi.api.version}/programs/{programId}" + BrapiVersion.BRAPI_V2) @@ -105,7 +97,7 @@ public HttpResponse>> deleteListById( @PathVariable("programId") UUID programId, @PathVariable("listDbId") String listDbId, HttpRequest request - ) throws DoesNotExistException, ApiException { + ) { boolean hardDelete = false; if (request.getParameters().contains("hardDelete")) { String paramValue = request.getParameters().get("hardDelete"); @@ -119,110 +111,4 @@ public HttpResponse>> deleteListById( return HttpResponse.status(HttpStatus.INTERNAL_SERVER_ERROR, "Error retrieving germplasm list records"); } } - - @Get("/lists/{listDbId}") - @Produces(MediaType.APPLICATION_JSON) - @ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.PROGRAM_SCOPED_ROLES}) - @SuppressWarnings("unchecked") - public HttpResponse>>> getListById( - @PathVariable("programId") UUID programId, - @PathVariable("listDbId") String listDbId, - HttpRequest request) { - try { - // Get the list from the BrAPI service - DeltaListDetails details = brapiListService.getDeltaListDetails(listDbId, programId); - - // Get a new instance of BrAPI query matching the type of list contents - T queryParams = (T) details.getQuery(); - - // Bind query parameters to the object - bindQueryParams(queryParams, request); - - // Perform standard bean validation - Set> violations = validator.validate(queryParams); - if (!violations.isEmpty()) { - List errorMessages = violations.stream() - .map(ConstraintViolation::getMessage) - .collect(Collectors.toList()); - log.info(String.join(", ", errorMessages)); - return HttpResponse.status(HttpStatus.BAD_REQUEST, "Error with list contents search parameters"); - } - - // Fetch the list contents from the BrAPI service - List listContentsBrAPIObjects = (List) details.getDataObjects(); - - // Construct a search request for sorting the list contents - SearchRequest searchRequest = details.constructSearchRequest(queryParams); - - // Get the map used to connect query sorting keys to contents object values - AbstractQueryMapper contentsQueryMapper = details.getQueryMapper(); - - return ResponseUtils.getBrapiQueryResponse(listContentsBrAPIObjects, contentsQueryMapper, queryParams, searchRequest); - } catch (Exception e) { - log.info(e.getMessage(), e); - return HttpResponse.status(HttpStatus.INTERNAL_SERVER_ERROR, "Error retrieving list records"); - } - } - - @Get("/lists/{listDbId}/export{?fileExtension}") - @Produces(value = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") - @ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.PROGRAM_SCOPED_ROLES}) - public HttpResponse germplasmListExport( - @PathVariable("programId") UUID programId, @PathVariable("listDbId") String listDbId, @QueryValue(defaultValue = "XLSX") String fileExtension) { - String downloadErrorMessage = "An error occurred while generating the download file. Contact the development team at bidevteam@cornell.edu."; - try { - // Get the list from the BrAPI service - DeltaListDetails details = brapiListService.getDeltaListDetails(listDbId, programId); - - FileType extension = Enum.valueOf(FileType.class, fileExtension); - DownloadFile listContentsFile = details.exportListObjects(extension); - return HttpResponse.ok(listContentsFile.getStreamedFile()).header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename="+listContentsFile.getFileName()+extension.getExtension()); - } - catch (Exception e) { - log.info(e.getMessage(), e); - e.printStackTrace(); - HttpResponse response = HttpResponse.status(HttpStatus.INTERNAL_SERVER_ERROR, downloadErrorMessage).contentType(MediaType.TEXT_PLAIN).body(downloadErrorMessage); - return response; - } - } - - private void bindQueryParams(BrapiQuery queryParams, HttpRequest request) { - BeanIntrospection introspection = BeanIntrospection.getIntrospection(BrapiQuery.class); - for (BeanProperty property : introspection.getBeanProperties()) { - String paramName = property.getName(); - if (request.getParameters().contains(paramName)) { - String paramValue = request.getParameters().get(paramName); - Object convertedValue; - Class propertyType = property.getType(); - - if (propertyType.isEnum()) { - convertedValue = convertToEnum(paramValue, (Class>) propertyType); - } else { - convertedValue = convertValue(paramValue, propertyType); - } - - property.set(queryParams, convertedValue); - } - } - } - - private > T convertToEnum(String value, Class> enumClass) { - if (value == null) { - return null; - } - return Enum.valueOf((Class) enumClass, value.toUpperCase()); - } - - - // Convert, if necessary, the values of query parameters to match the type defined for the fields in the BrapiQuery class - private Object convertValue(String value, Class targetType) { - // Implement type conversion logic here - // Other list content types might need more complex logic - if (targetType == String.class) return value; - if (targetType == Integer.class) return Integer.parseInt(value); - if (targetType == Long.class) return Long.parseLong(value); - if (targetType == Boolean.class) return Boolean.parseBoolean(value); - // Add more type conversions as needed - return value; - } } diff --git a/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIListDAO.java b/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIListDAO.java index ed7db131c..55b395ea3 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIListDAO.java +++ b/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIListDAO.java @@ -25,7 +25,6 @@ import okhttp3.Request; import org.brapi.client.v2.ApiResponse; import org.brapi.client.v2.model.exceptions.ApiException; -import org.brapi.client.v2.model.queryParams.core.ListQueryParams; import org.brapi.client.v2.modules.core.ListsApi; import org.brapi.v2.model.BrAPIExternalReference; import org.brapi.v2.model.BrAPIResponse; @@ -34,15 +33,15 @@ import org.brapi.v2.model.core.BrAPIListTypes; import org.brapi.v2.model.core.request.BrAPIListNewRequest; import org.brapi.v2.model.core.request.BrAPIListSearchRequest; -import org.brapi.v2.model.core.response.*; -import org.brapi.v2.model.pheno.BrAPIObservation; +import org.brapi.v2.model.core.response.BrAPIListDetails; +import org.brapi.v2.model.core.response.BrAPIListsListResponse; +import org.brapi.v2.model.core.response.BrAPIListsListResponseResult; +import org.brapi.v2.model.core.response.BrAPIListsSingleResponse; import org.breedinginsight.brapi.v1.controller.BrapiVersion; import org.breedinginsight.brapps.importer.daos.ImportDAO; import org.breedinginsight.brapps.importer.model.ImportUpload; import org.breedinginsight.daos.ProgramDAO; import org.breedinginsight.model.ProgramBrAPIEndpoints; -import org.breedinginsight.model.delta.DeltaEntityFactory; -import org.breedinginsight.model.delta.DeltaListDetails; import org.breedinginsight.services.ProgramService; import org.breedinginsight.services.brapi.BrAPIEndpointProvider; import org.breedinginsight.services.exceptions.DoesNotExistException; @@ -52,7 +51,10 @@ import javax.inject.Inject; import javax.validation.constraints.NotNull; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.UUID; import java.util.concurrent.TimeUnit; @Slf4j @@ -62,16 +64,14 @@ public class BrAPIListDAO { private ImportDAO importDAO; private final BrAPIDAOUtil brAPIDAOUtil; private final BrAPIEndpointProvider brAPIEndpointProvider; - private final DeltaEntityFactory deltaEntityFactory; private final ProgramService programService; @Inject - public BrAPIListDAO(ProgramDAO programDAO, ImportDAO importDAO, BrAPIDAOUtil brAPIDAOUtil, BrAPIEndpointProvider brAPIEndpointProvider, DeltaEntityFactory deltaEntityFactory, ProgramService programService) { + public BrAPIListDAO(ProgramDAO programDAO, ImportDAO importDAO, BrAPIDAOUtil brAPIDAOUtil, BrAPIEndpointProvider brAPIEndpointProvider, ProgramService programService) { this.programDAO = programDAO; this.importDAO = importDAO; this.brAPIDAOUtil = brAPIDAOUtil; this.brAPIEndpointProvider = brAPIEndpointProvider; - this.deltaEntityFactory = deltaEntityFactory; this.programService = programService; } @@ -211,19 +211,8 @@ public List createBrAPILists(List brapiLi throw new ApiException("No response after creating list"); } - public DeltaListDetails getDeltaListDetailsByDbId(String listDbId, UUID programId) throws ApiException { - ListsApi api = brAPIEndpointProvider.get(programDAO.getCoreClient(programId), ListsApi.class); - ApiResponse response = api.listsListDbIdGet(listDbId); - if (Objects.isNull(response.getBody()) || Objects.isNull(response.getBody().getResult())) - { - throw new ApiException(); - } - - BrAPIListDetails details = response.getBody().getResult(); - return deltaEntityFactory.makeDeltaListDetailsBean(details); - } - public void deleteBrAPIList(String listDbId, UUID programId, boolean hardDelete) throws ApiException { + // TODO: Switch to using the ListsApi from the BrAPI client library once the delete endpoints are merged into it var programBrAPIBaseUrl = getProgramBrAPIBaseUrl(programId); var requestUrl = HttpUrl.parse(programBrAPIBaseUrl + "/lists/" + listDbId).newBuilder(); requestUrl.addQueryParameter("hardDelete", Boolean.toString(hardDelete)); diff --git a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java index 8023327d7..231978368 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java +++ b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java @@ -82,7 +82,7 @@ public Optional getGermplasmByDBID(UUID programId, String germpl return germplasmDAO.getGermplasmByDBID(germplasmId, programId); } - public List> processListData(List germplasm, BrAPIListDetails germplasmList, Program program){ + public List> processListData(List germplasm, List listData, Program program){ Map germplasmByName = new HashMap<>(); for (BrAPIGermplasm g: germplasm) { // Use the full, unique germplasmName with programKey and accessionNumber (GID) for 2 reasons: @@ -97,14 +97,14 @@ public List> processListData(List germplasm, // This holds the BrAPI list items or all germplasm in a program if the list is null. List orderedGermplasmNames = new ArrayList<>(); - if (germplasmList == null) { + if (listData == null) { orderedGermplasmNames = germplasm.stream().sorted((left, right) -> { Integer leftAccessionNumber = Integer.parseInt(left.getAccessionNumber()); Integer rightAccessionNumber = Integer.parseInt(right.getAccessionNumber()); return leftAccessionNumber.compareTo(rightAccessionNumber); }).map(BrAPIGermplasm::getGermplasmName).collect(Collectors.toList()); } else { - orderedGermplasmNames = germplasmList.getData(); + orderedGermplasmNames = listData; } // For export, assign entry number sequentially based on BrAPI list order. @@ -124,7 +124,7 @@ public List> processListData(List germplasm, row.put("Source", source); // Use the entry number in the list map if generated - if(germplasmList == null) { + if(listData == null) { // Not downloading a real list, use GID (https://breedinginsight.atlassian.net/browse/BI-2266). row.put("Entry No", Integer.valueOf(germplasmEntry.getAccessionNumber())); } else { @@ -254,7 +254,9 @@ public DownloadFile exportGermplasm(UUID programId, FileType fileExtension) thro return new DownloadFile(fileName, downloadFile); } - public DownloadFile exportGermplasmList(UUID programId, String listId, FileType fileExtension) throws IllegalArgumentException, ApiException, IOException, DoesNotExistException { + public DownloadFile exportGermplasmList(UUID programId, + String listId, + FileType fileExtension) throws IllegalArgumentException, ApiException, IOException, DoesNotExistException { List columns = GermplasmFileColumns.getOrderedColumns(); //Retrieve germplasm list data @@ -270,7 +272,7 @@ public DownloadFile exportGermplasmList(UUID programId, String listId, FileType String fileName = createFileName(listData, listName); StreamedFile downloadFile; //Convert list data to List> data to pass into file writer - List> processedData = processListData(germplasm, listData, program); + List> processedData = processListData(germplasm, germplasmNames, program); if (fileExtension == FileType.CSV){ downloadFile = CSVWriter.writeToDownload(columns, processedData, fileExtension); diff --git a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIListService.java b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIListService.java index 7dd7c81c6..1ee77e310 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIListService.java +++ b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIListService.java @@ -12,7 +12,6 @@ import org.breedinginsight.brapi.v2.dao.BrAPIListDAO; import org.breedinginsight.brapps.importer.services.ExternalReferenceSource; import org.breedinginsight.model.Program; -import org.breedinginsight.model.delta.DeltaListDetails; import org.breedinginsight.services.exceptions.DoesNotExistException; import org.breedinginsight.utilities.Utilities; @@ -91,10 +90,6 @@ public List getListSummariesByTypeAndXref( return programLists; } - public DeltaListDetails getDeltaListDetails(String listDbId, UUID programId) throws ApiException { - return listDAO.getDeltaListDetailsByDbId(listDbId, programId); - } - public void deleteBrAPIList(String listDbId, UUID programId, boolean hardDelete) throws ApiException { listDAO.deleteBrAPIList(listDbId, programId, hardDelete); } diff --git a/src/main/java/org/breedinginsight/model/delta/DeltaEntityFactory.java b/src/main/java/org/breedinginsight/model/delta/DeltaEntityFactory.java index 8d473ce5a..f1724ef12 100644 --- a/src/main/java/org/breedinginsight/model/delta/DeltaEntityFactory.java +++ b/src/main/java/org/breedinginsight/model/delta/DeltaEntityFactory.java @@ -7,19 +7,16 @@ import lombok.NonNull; import org.brapi.v2.model.core.BrAPIListSummary; import org.brapi.v2.model.core.BrAPIListTypes; -import org.brapi.v2.model.core.response.BrAPIListDetails; -import org.breedinginsight.brapi.v2.dao.BrAPIGermplasmDAO; -import org.breedinginsight.brapi.v2.services.BrAPIGermplasmService; -import org.breedinginsight.brapps.importer.services.processors.experiment.service.ObservationUnitService; - import org.brapi.v2.model.core.BrAPIStudy; import org.brapi.v2.model.core.BrAPITrial; +import org.brapi.v2.model.core.response.BrAPIListDetails; import org.brapi.v2.model.germ.BrAPIGermplasm; import org.brapi.v2.model.pheno.BrAPIObservation; import org.brapi.v2.model.pheno.BrAPIObservationUnit; import org.brapi.v2.model.pheno.BrAPIObservationVariable; +import org.breedinginsight.brapi.v2.services.BrAPIGermplasmService; +import org.breedinginsight.brapps.importer.services.processors.experiment.service.ObservationUnitService; import org.breedinginsight.model.ProgramLocation; -import org.breedinginsight.utilities.Utilities; import javax.inject.Inject; @@ -27,16 +24,10 @@ public class DeltaEntityFactory { private final ObservationUnitService observationUnitService; - private final BrAPIGermplasmService germplasmService; - private final String applicationReferenceSourceBase; @Inject - public DeltaEntityFactory(ObservationUnitService observationUnitService, - BrAPIGermplasmService germplasmService, - @Property(name = "brapi.server.reference-source") String applicationReferenceSourceBase) { + public DeltaEntityFactory(ObservationUnitService observationUnitService) { this.observationUnitService = observationUnitService; - this.germplasmService = germplasmService; - this.applicationReferenceSourceBase = applicationReferenceSourceBase; } private Experiment makeExperiment(BrAPITrial brAPIObject) { @@ -67,46 +58,6 @@ private DeltaObservationVariable makeDeltaObservationVariable(BrAPIObservationVa return new DeltaObservationVariable(brAPIObject); } - private DeltaGermplasmListSummary makeDeltaGermplasmListSummary(BrAPIListSummary brAPIObject) { - return new DeltaGermplasmListSummary(brAPIObject); - } - - private DeltaGermplasmListDetails makeDeltaGermplasmListDetails(BrAPIListDetails brAPIObject, String referenceSourceBase, BrAPIGermplasmService germplasmService) { - return new DeltaGermplasmListDetails(brAPIObject, referenceSourceBase, germplasmService); - } - - @Bean - @Prototype - public DeltaListSummary makeDeltaListSummaryBean(@NonNull BrAPIListSummary brAPIObject) { - BrAPIListTypes listType = brAPIObject.getListType(); - switch (listType) { - case GERMPLASM: return makeDeltaGermplasmListSummary(brAPIObject); - default: return null; - } - } - - @Bean - @Prototype - public DeltaListDetails makeDeltaListDetailsBean(@NonNull BrAPIListDetails brAPIObject) { - BrAPIListTypes listType = brAPIObject.getListType(); - switch (listType) { - case GERMPLASM: return makeDeltaGermplasmListDetailsBean(brAPIObject); - default: return null; - } - } - - @Bean - @Prototype - public DeltaGermplasmListSummary makeDeltaGermplasmListSummaryBean(@NonNull BrAPIListSummary brAPIObject) { - return makeDeltaGermplasmListSummary(brAPIObject); - } - - @Bean - @Prototype - public DeltaGermplasmListDetails makeDeltaGermplasmListDetailsBean(@NonNull BrAPIListDetails brAPIObject) { - return makeDeltaGermplasmListDetails(brAPIObject, applicationReferenceSourceBase, germplasmService); - } - @Bean @Prototype public Experiment makeExperimentBean(@NonNull BrAPITrial brAPIObject) { diff --git a/src/main/java/org/breedinginsight/model/delta/DeltaGermplasmListDetails.java b/src/main/java/org/breedinginsight/model/delta/DeltaGermplasmListDetails.java deleted file mode 100644 index 1f8ea3d9c..000000000 --- a/src/main/java/org/breedinginsight/model/delta/DeltaGermplasmListDetails.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.breedinginsight.model.delta; - -import io.micronaut.context.annotation.Prototype; -import org.brapi.client.v2.model.exceptions.ApiException; -import org.brapi.v2.model.core.response.BrAPIListDetails; -import org.brapi.v2.model.germ.BrAPIGermplasm; -import org.breedinginsight.api.model.v1.request.query.SearchRequest; -import org.breedinginsight.brapi.v1.model.request.query.BrapiQuery; -import org.breedinginsight.brapi.v2.model.request.query.GermplasmQuery; -import org.breedinginsight.brapi.v2.services.BrAPIGermplasmService; -import org.breedinginsight.brapps.importer.model.exports.FileType; -import org.breedinginsight.model.DownloadFile; -import org.breedinginsight.services.exceptions.DoesNotExistException; -import org.breedinginsight.services.exceptions.UnprocessableEntityException; -import org.breedinginsight.utilities.response.mappers.AbstractQueryMapper; -import org.breedinginsight.utilities.response.mappers.GermplasmQueryMapper; - -import java.io.IOException; -import java.util.List; -import java.util.UUID; - - -@Prototype -public class DeltaGermplasmListDetails extends DeltaListDetails { - - private final BrAPIGermplasmService germplasmService; - - // Note: do not use @Inject, DeltaEntity are always constructed by DeltaEntityFactory. - DeltaGermplasmListDetails(BrAPIListDetails brAPIListDetails, - String referenceSourceBase, - BrAPIGermplasmService germplasmService) { - super(brAPIListDetails, referenceSourceBase); - this.germplasmService = germplasmService; - } - - @Override - public List getDataObjects() throws ApiException, UnprocessableEntityException { - UUID programId = getProgramId().orElseThrow(() -> new UnprocessableEntityException("Program Id not found for list " + getListName())); - return germplasmService.getGermplasmByList(programId, getListDbId()); - } - - @Override - public DownloadFile exportListObjects(FileType extension) throws IllegalArgumentException, ApiException, IOException, DoesNotExistException, UnprocessableEntityException { - UUID programId = getProgramId().orElseThrow(() -> new UnprocessableEntityException("Program Id not found for list " + getListName())); - return germplasmService.exportGermplasmList(programId, getListDbId(), extension); - } - - @Override - public AbstractQueryMapper getQueryMapper() { - return new GermplasmQueryMapper(); - } - - @Override - public BrapiQuery getQuery() { - return new GermplasmQuery(); - } - - @Override - public SearchRequest constructSearchRequest(BrapiQuery queryParams) { - return ((GermplasmQuery) queryParams).constructSearchRequest(); - } -} diff --git a/src/main/java/org/breedinginsight/model/delta/DeltaGermplasmListSummary.java b/src/main/java/org/breedinginsight/model/delta/DeltaGermplasmListSummary.java deleted file mode 100644 index 6ddd2518b..000000000 --- a/src/main/java/org/breedinginsight/model/delta/DeltaGermplasmListSummary.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.breedinginsight.model.delta; - -import io.micronaut.context.annotation.Prototype; -import lombok.Getter; -import lombok.Setter; -import org.brapi.v2.model.core.BrAPIListSummary; -import org.breedinginsight.brapps.importer.model.response.ImportObjectState; - - -@Prototype -public class DeltaGermplasmListSummary extends DeltaListSummary { - - // Note: do not use @Inject, DeltaEntity are always constructed by DeltaEntityFactory. - DeltaGermplasmListSummary(BrAPIListSummary brAPIListSummary) { super(brAPIListSummary); } - -} diff --git a/src/main/java/org/breedinginsight/model/delta/DeltaListDetails.java b/src/main/java/org/breedinginsight/model/delta/DeltaListDetails.java deleted file mode 100644 index 9f2c745bf..000000000 --- a/src/main/java/org/breedinginsight/model/delta/DeltaListDetails.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.breedinginsight.model.delta; - -import io.micronaut.context.annotation.Prototype; -import lombok.Getter; -import lombok.Setter; -import lombok.Value; -import org.brapi.client.v2.model.exceptions.ApiException; -import org.brapi.v2.model.BrAPIExternalReference; -import org.brapi.v2.model.core.BrAPIListTypes; -import org.brapi.v2.model.core.response.BrAPIListDetails; -import org.breedinginsight.api.model.v1.request.query.SearchRequest; -import org.breedinginsight.brapi.v1.model.request.query.BrapiQuery; -import org.breedinginsight.brapps.importer.model.exports.FileType; -import org.breedinginsight.brapps.importer.model.response.ImportObjectState; -import io.micronaut.context.annotation.Property; -import org.breedinginsight.brapps.importer.services.ExternalReferenceSource; -import org.breedinginsight.model.DownloadFile; -import org.breedinginsight.services.exceptions.DoesNotExistException; -import org.breedinginsight.services.exceptions.UnprocessableEntityException; -import org.breedinginsight.utilities.Utilities; -import org.breedinginsight.utilities.response.mappers.AbstractQueryMapper; - -import java.io.IOException; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.UUID; - - -@Prototype -public abstract class DeltaListDetails extends DeltaEntity { - private final String referenceSourceBase; - @Getter - @Setter - private ImportObjectState state; - - // Note: do not use @Inject, DeltaEntity are always constructed by DeltaEntityFactory. - DeltaListDetails(BrAPIListDetails brAPIListDetails, String referenceSourceBase) { - super(brAPIListDetails); - this.referenceSourceBase = referenceSourceBase; - } - - public abstract List getDataObjects() throws ApiException, UnprocessableEntityException; - public abstract DownloadFile exportListObjects(FileType extension) throws IllegalArgumentException, ApiException, IOException, DoesNotExistException, UnprocessableEntityException; - public abstract AbstractQueryMapper getQueryMapper(); - - public abstract BrapiQuery getQuery(); - - public abstract SearchRequest constructSearchRequest(BrapiQuery queryParams); - - public BrAPIListTypes getListType() { - return entity.getListType(); - } - - public Optional getListId() { - return getXrefId(ExternalReferenceSource.LISTS); - } - - public Optional getProgramId() { - return getXrefId(ExternalReferenceSource.PROGRAMS); - } - - public String getListDbId() { - return entity.getListDbId(); - } - - public String getListName() { - return entity.getListName(); - } - - private Optional getXrefId(ExternalReferenceSource source) { - // Get the external reference if it exists - Optional xrefOptional = Utilities.getExternalReference(entity.getExternalReferences(), referenceSourceBase, source); - - // Parse the Deltabreed ID from the xref - return xrefOptional.map(BrAPIExternalReference::getReferenceId).map(UUID::fromString); - } -} diff --git a/src/main/java/org/breedinginsight/model/delta/DeltaListSummary.java b/src/main/java/org/breedinginsight/model/delta/DeltaListSummary.java deleted file mode 100644 index 80569d077..000000000 --- a/src/main/java/org/breedinginsight/model/delta/DeltaListSummary.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.breedinginsight.model.delta; - -import io.micronaut.context.annotation.Prototype; -import lombok.Getter; -import lombok.Setter; -import org.brapi.v2.model.core.BrAPIListSummary; -import org.breedinginsight.brapps.importer.model.response.ImportObjectState; - - -@Prototype -public class DeltaListSummary extends DeltaEntity { - - @Getter - @Setter - private ImportObjectState state; - - // Note: do not use @Inject, DeltaEntity are always constructed by DeltaEntityFactory. - DeltaListSummary(BrAPIListSummary brAPIListSummary) { super(brAPIListSummary); } - -} diff --git a/src/main/java/org/breedinginsight/utilities/Utilities.java b/src/main/java/org/breedinginsight/utilities/Utilities.java index 7ed72cfef..20f3254d6 100644 --- a/src/main/java/org/breedinginsight/utilities/Utilities.java +++ b/src/main/java/org/breedinginsight/utilities/Utilities.java @@ -17,7 +17,6 @@ package org.breedinginsight.utilities; -import io.micronaut.context.annotation.Property; import org.apache.commons.lang3.StringUtils; import org.brapi.client.v2.model.exceptions.ApiException; import org.brapi.v2.model.BrAPIExternalReference; @@ -25,7 +24,6 @@ import org.breedinginsight.model.Program; import org.flywaydb.core.api.migration.Context; -import javax.inject.Inject; import java.lang.reflect.Field; import java.sql.ResultSet; import java.sql.Statement;