diff --git a/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java b/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java index 59e4776c9..a90d46bc8 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java +++ b/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java @@ -18,18 +18,14 @@ package org.breedinginsight.brapi.v2.dao; import com.google.gson.JsonObject; -import io.micronaut.context.annotation.Context; import io.micronaut.context.annotation.Property; import io.micronaut.http.HttpStatus; import io.micronaut.http.server.exceptions.InternalServerException; -import io.micronaut.scheduling.annotation.Scheduled; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.tuple.Pair; import org.brapi.client.v2.ApiResponse; import org.brapi.client.v2.model.exceptions.ApiException; import org.brapi.client.v2.model.queryParams.germplasm.GermplasmQueryParams; import org.brapi.client.v2.modules.germplasm.GermplasmApi; -import org.brapi.v2.model.BrAPIAcceptedSearchResponse; import org.brapi.v2.model.BrAPIExternalReference; import org.brapi.v2.model.core.BrAPIProgram; import org.brapi.v2.model.germ.BrAPIGermplasm; @@ -41,10 +37,7 @@ import org.breedinginsight.brapi.v2.model.request.query.GermplasmQuery; import org.breedinginsight.brapps.importer.daos.ImportDAO; import org.breedinginsight.brapps.importer.model.ImportUpload; -import org.breedinginsight.brapps.importer.services.ExternalReferenceSource; import org.breedinginsight.daos.ProgramDAO; -import org.breedinginsight.daos.cache.ProgramCache; -import org.breedinginsight.daos.cache.ProgramCacheProvider; import org.breedinginsight.model.Program; import org.breedinginsight.services.brapi.BrAPIEndpointProvider; import org.breedinginsight.services.exceptions.DoesNotExistException; @@ -54,12 +47,10 @@ import javax.inject.Inject; import javax.inject.Singleton; import java.util.*; -import java.util.concurrent.Callable; import java.util.stream.Collectors; @Slf4j @Singleton -@Context public class BrAPIGermplasmDAO { private final ProgramDAO programDAO; @@ -69,17 +60,9 @@ public class BrAPIGermplasmDAO { @Property(name = "brapi.server.reference-source") private String referenceSource; - @Property(name = "micronaut.bi.api.run-scheduled-tasks") - private boolean runScheduledTasks; - - @Property(name = "brapi.paginate.germplasm") - private boolean paginateGermplasm; - @Property(name = "data-table.max-size") private int dataTableMaxSize; - private final ProgramCache programGermplasmCache; - private final BrAPIEndpointProvider brAPIEndpointProvider; private final int brapiMaxPageSize; @@ -88,30 +71,15 @@ public class BrAPIGermplasmDAO { public BrAPIGermplasmDAO(ProgramDAO programDAO, ImportDAO importDAO, BrAPIDAOUtil brAPIDAOUtil, - ProgramCacheProvider programCacheProvider, BrAPIEndpointProvider brAPIEndpointProvider, @Property(name = "brapi.cache.fetch-page-size") int brapiFetchPageSize) { this.programDAO = programDAO; this.importDAO = importDAO; this.brAPIDAOUtil = brAPIDAOUtil; - this.programGermplasmCache = programCacheProvider.getProgramCache(this::fetchProgramGermplasm, BrAPIGermplasm.class); this.brAPIEndpointProvider = brAPIEndpointProvider; this.brapiMaxPageSize = brapiFetchPageSize; } - @Scheduled(initialDelay = "${startup.delay.germplasm}") - public void setup() { - if(!runScheduledTasks) { - return; - } - // Populate germplasm cache for all programs on startup - log.debug("populating germplasm cache"); - List programs = programDAO.getActive(); - if(programs != null) { - programGermplasmCache.populate(programs.stream().map(Program::getId).collect(Collectors.toList())); - } - } - /** * Fetch the germplasm for this program, and process it to remove storage specific values * @param programId @@ -165,47 +133,6 @@ public List getRawGermplasm(UUID programId) throws ApiException }).collect(Collectors.toList()); } - - /** - * Fetch formatted germplasm for this program - * @param programId - * @return Map - * @throws ApiException - */ - private Map fetchProgramGermplasm(UUID programId) throws ApiException { - GermplasmApi api = brAPIEndpointProvider.get(programDAO.getCoreClient(programId), GermplasmApi.class); - // Get the program key - List programs = programDAO.get(programId); - if (programs.size() != 1) { - throw new InternalServerException("Program was not found for given key"); - } - Program program = programs.get(0); - - // Set query params and make call - BrAPIGermplasmSearchRequest germplasmSearch = new BrAPIGermplasmSearchRequest(); - germplasmSearch.externalReferenceIDs(List.of(programId.toString())); - germplasmSearch.externalReferenceSources(List.of(Utilities.generateReferenceSource(referenceSource, ExternalReferenceSource.PROGRAMS))); - - if (paginateGermplasm) { - log.debug("Fetching germplasm with pagination to BrAPI"); - return processGermplasmForDisplay(brAPIDAOUtil.search( - api::searchGermplasmPost, - api::searchGermplasmSearchResultsDbIdGet, - germplasmSearch), - program); - } else { - log.debug("Fetching germplasm without pagination to BrAPI"); - return processGermplasmForDisplay(brAPIDAOUtil.searchNoPaging( - api::searchGermplasmPost, - api::searchGermplasmSearchResultsDbIdGet, - germplasmSearch), - program); - } - } - - public void repopulateGermplasmCacheForProgram(UUID programId) { - programGermplasmCache.populate(programId); - } /** * Process germplasm into a format for display * @param programGermplasm @@ -487,11 +414,8 @@ public List updateBrAPIGermplasm(List putBrAPIGe var program = new Program(programDAO.fetchOneById(programId)); try { if (!putBrAPIGermplasmList.isEmpty()) { - Callable> postFunction = () -> { - List putResponse = putGermplasm(putBrAPIGermplasmList, api); - return processGermplasmForDisplay(putResponse, program); - }; - return programGermplasmCache.post(programId, postFunction); + List putResponse = putGermplasm(putBrAPIGermplasmList, api); + return new ArrayList<>(processGermplasmForDisplay(putResponse, program).values()); } return new ArrayList<>(); } catch (Exception e) { diff --git a/src/main/java/org/breedinginsight/brapps/importer/services/processors/germplasm/GermplasmProcessor.java b/src/main/java/org/breedinginsight/brapps/importer/services/processors/germplasm/GermplasmProcessor.java index e0eaf3c53..4ea4d7963 100644 --- a/src/main/java/org/breedinginsight/brapps/importer/services/processors/germplasm/GermplasmProcessor.java +++ b/src/main/java/org/breedinginsight/brapps/importer/services/processors/germplasm/GermplasmProcessor.java @@ -724,8 +724,6 @@ public void postBrapiData(Map mappedBrAPIImport, Program try { // Create germplasm list brAPIListDAO.createBrAPILists(List.of(importList), program.getId(), upload); - // Now that we have finished uploading, fetch all the data posted to BrAPI to the cache so it is up-to-date. - brAPIGermplasmDAO.repopulateGermplasmCacheForProgram(program.getId()); } catch (ApiException e) { throw new InternalServerException(e.toString(), e); } diff --git a/src/test/java/org/breedinginsight/brapps/importer/GermplasmFileImportTest.java b/src/test/java/org/breedinginsight/brapps/importer/GermplasmFileImportTest.java index 2673b0353..7916df3e1 100644 --- a/src/test/java/org/breedinginsight/brapps/importer/GermplasmFileImportTest.java +++ b/src/test/java/org/breedinginsight/brapps/importer/GermplasmFileImportTest.java @@ -1257,8 +1257,5 @@ private void seedExistingGermplasm(String accessionNumber, String displayName, S germplasm.setExternalReferences(externalReferences); germplasmDAO.createBrAPIGermplasm(List.of(germplasm), validProgram.getId(), null); - - //Refresh cache so importer lookup sees the seeded germplasm immediately. - germplasmDAO.repopulateGermplasmCacheForProgram(validProgram.getId()); } } diff --git a/src/test/java/org/breedinginsight/services/BrAPIGermplasmServiceUnitTest.java b/src/test/java/org/breedinginsight/services/BrAPIGermplasmServiceUnitTest.java index 127feb94c..7251b02e9 100644 --- a/src/test/java/org/breedinginsight/services/BrAPIGermplasmServiceUnitTest.java +++ b/src/test/java/org/breedinginsight/services/BrAPIGermplasmServiceUnitTest.java @@ -51,7 +51,6 @@ public class BrAPIGermplasmServiceUnitTest extends DatabaseTest { private BrAPIGermplasmService germplasmService; private BrAPIDAOUtil brAPIDAOUtil; private String referenceSource; - private ProgramCacheProvider cacheProvider; @SneakyThrows @BeforeEach @@ -61,8 +60,7 @@ void setup() { listDAO = mock(BrAPIListDAO.class); programDAO = mock(ProgramDAO.class); brAPIDAOUtil = mock(BrAPIDAOUtil.class); - cacheProvider = new ProgramCacheProvider(super.getRedisConnection()); - germplasmDAO = new BrAPIGermplasmDAO(programDAO, mock(ImportDAO.class), brAPIDAOUtil, cacheProvider, new BrAPIEndpointProvider(), 65000); + germplasmDAO = new BrAPIGermplasmDAO(programDAO, mock(ImportDAO.class), brAPIDAOUtil, new BrAPIEndpointProvider(), 65000); programService = mock(ProgramService.class); Field externalReferenceSource = BrAPIGermplasmDAO.class.getDeclaredField("referenceSource"); @@ -157,11 +155,6 @@ public void getGermplasmListExport() { any(GermplasmQueryParams.class))).thenReturn(germplasm); when(brAPIDAOUtil.getBrAPIProgramDbId(any())).thenReturn(brapiProgramDbId); - //Create germplasm cache of stub data - Method setupMethod = BrAPIGermplasmDAO.class.getDeclaredMethod("setup"); - setupMethod.setAccessible(true); - setupMethod.invoke(germplasmDAO); - //Create test instance of service, injecting spy- and mock-dependencies germplasmService = new BrAPIGermplasmService(brAPIListSpy, programSpy, germplasmDAO);