diff --git a/src/main/java/org/breedinginsight/brapps/importer/daos/BrAPITrialDAO.java b/src/main/java/org/breedinginsight/brapps/importer/daos/BrAPITrialDAO.java index 0a9180936..55e35f6e8 100644 --- a/src/main/java/org/breedinginsight/brapps/importer/daos/BrAPITrialDAO.java +++ b/src/main/java/org/breedinginsight/brapps/importer/daos/BrAPITrialDAO.java @@ -1,187 +1,31 @@ -/* - * See the NOTICE file distributed with this work for additional information - * regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package org.breedinginsight.brapps.importer.daos; -import io.micronaut.context.annotation.Property; import org.brapi.client.v2.model.exceptions.ApiException; -import org.brapi.client.v2.modules.core.TrialsApi; import org.brapi.v2.model.core.BrAPITrial; -import org.brapi.v2.model.core.request.BrAPITrialSearchRequest; import org.breedinginsight.brapps.importer.model.ImportUpload; -import org.breedinginsight.brapps.importer.services.ExternalReferenceSource; -import org.breedinginsight.daos.ProgramDAO; import org.breedinginsight.model.Program; -import org.breedinginsight.services.ProgramService; -import org.breedinginsight.services.brapi.BrAPIEndpointProvider; import org.breedinginsight.services.exceptions.DoesNotExistException; -import org.breedinginsight.utilities.BrAPIDAOUtil; -import org.breedinginsight.utilities.Utilities; -import javax.inject.Inject; -import javax.inject.Singleton; -import java.util.*; -import java.util.stream.Collectors; +import java.util.Collection; +import java.util.List; +import java.util.Optional; +import java.util.UUID; -@Singleton -public class BrAPITrialDAO { - @Property(name = "brapi.server.reference-source") - private String BRAPI_REFERENCE_SOURCE; +public interface BrAPITrialDAO { + List getTrialsByName(List trialNames, Program program) throws ApiException; - private final ProgramDAO programDAO; - private final ImportDAO importDAO; - private final BrAPIDAOUtil brAPIDAOUtil; - private final ProgramService programService; - private final BrAPIEndpointProvider brAPIEndpointProvider; + List createBrAPITrials(List brAPITrialList, UUID programId, ImportUpload upload) + throws ApiException; - private final String referenceSource; + BrAPITrial updateBrAPITrial(String trialDbId, BrAPITrial trial, UUID programId) throws ApiException; - @Inject - public BrAPITrialDAO(ProgramDAO programDAO, ImportDAO importDAO, BrAPIDAOUtil brAPIDAOUtil, ProgramService programService, @Property(name = "brapi.server.reference-source") String referenceSource, BrAPIEndpointProvider brAPIEndpointProvider) { - this.programDAO = programDAO; - this.importDAO = importDAO; - this.brAPIDAOUtil = brAPIDAOUtil; - this.programService = programService; - this.referenceSource = referenceSource; - this.brAPIEndpointProvider = brAPIEndpointProvider; - } + List getTrials(UUID programId) throws ApiException; - public List getTrialsByName(List trialNames, Program program) throws ApiException { - if(trialNames.isEmpty()) { - return Collections.emptyList(); - } + Optional getTrialById(UUID programId, UUID trialId) throws ApiException, DoesNotExistException; - BrAPITrialSearchRequest trialSearch = new BrAPITrialSearchRequest(); - trialSearch.programDbIds(List.of(program.getBrapiProgram().getProgramDbId())); - trialSearch.trialNames(trialNames); - TrialsApi api = brAPIEndpointProvider.get(programDAO.getCoreClient(program.getId()), TrialsApi.class); - return brAPIDAOUtil.search( - api::searchTrialsPost, - api::searchTrialsSearchResultsDbIdGet, - trialSearch - ); - } + Optional getTrialByDbId(String trialDbId, Program program) throws ApiException; - private List getTrialsByExRef(String referenceSource, String referenceId, Program program) throws ApiException { - BrAPITrialSearchRequest trialSearch = new BrAPITrialSearchRequest(); - trialSearch.programDbIds(List.of(program.getBrapiProgram().getProgramDbId())); - trialSearch.externalReferenceSources(List.of(referenceSource)); - trialSearch.externalReferenceIDs(List.of(referenceId)); - TrialsApi api = brAPIEndpointProvider.get(programDAO.getCoreClient(program.getId()), TrialsApi.class); - return brAPIDAOUtil.search( - api::searchTrialsPost, - api::searchTrialsSearchResultsDbIdGet, - trialSearch - ); - } - - public List createBrAPITrials(List brAPITrialList, UUID programId, ImportUpload upload) throws ApiException { - TrialsApi api = brAPIEndpointProvider.get(programDAO.getCoreClient(programId), TrialsApi.class); - return brAPIDAOUtil.post(brAPITrialList, upload, api::trialsPost, importDAO::update); - } - public BrAPITrial updateBrAPITrial(String trialDbId, BrAPITrial trial, UUID programId) throws ApiException { - TrialsApi api = brAPIEndpointProvider.get(programDAO.getCoreClient(programId), TrialsApi.class); - return brAPIDAOUtil.put(trialDbId, trial, api::trialsTrialDbIdPut); - } - /** - * Fetch formatted trials/experiments for this program - * @param programId - * @return List - * @throws ApiException - */ - public List getTrials(UUID programId) throws ApiException, DoesNotExistException { - BrAPITrialSearchRequest trialSearch = new BrAPITrialSearchRequest(); - //TODO check external references filter works once implemented in BI-1552 - trialSearch.externalReferenceSources(List.of(Utilities.generateReferenceSource(referenceSource, ExternalReferenceSource.PROGRAMS))); - trialSearch.externalReferenceIDs(List.of(programId.toString())); - - Program program = programService.getById(programId).orElseThrow(() -> new DoesNotExistException("Program id does not exist")); - trialSearch.programDbIds(List.of(program.getBrapiProgram().getProgramDbId())); - - TrialsApi api = brAPIEndpointProvider.get(programDAO.getCoreClient(program.getId()), TrialsApi.class); - return processExperimentsForDisplay(brAPIDAOUtil.search( - api::searchTrialsPost, - api::searchTrialsSearchResultsDbIdGet, - trialSearch), program.getKey(), programId, true); - } - - //Removes program key from trial name and adds dataset information - private List processExperimentsForDisplay(List trials, String programKey, UUID programId, boolean metadata) throws ApiException { - List displayExperiments = new ArrayList<>(); - for (BrAPITrial trial: trials) { - trial.setTrialName(Utilities.removeProgramKey(trial.getTrialName(), programKey, "")); - List datasets = new ArrayList<>(); - - if (metadata) { - //todo presumably BI-1193 replace dummy value with list of datasets once datasets implemented - datasets.add("Observation Dataset"); - trial.putAdditionalInfoItem("datasets", datasets); - } - - displayExperiments.add(trial); - } - return displayExperiments; - } - - public Optional getTrialById(UUID programId, UUID trialDbId) throws ApiException, DoesNotExistException { - Program program = programService.getById(programId).orElseThrow(() -> new DoesNotExistException("Program id does not exist")); - String refSoure = Utilities.generateReferenceSource(BRAPI_REFERENCE_SOURCE, ExternalReferenceSource.TRIALS); - List trials = getTrialsByExRef(refSoure, trialDbId.toString(), program); - - return Utilities.getSingleOptional(trials); - } - - public Optional getTrialByDbId(String trialDbId, Program program) throws ApiException { - List trials = getTrialsByDbIds(List.of(trialDbId), program); - return Utilities.getSingleOptional(trials); - } - public List getTrialsByDbIds(Collection trialDbIds, Program program) throws ApiException { - if(trialDbIds.isEmpty()) { - return Collections.emptyList(); - } - - BrAPITrialSearchRequest trialSearch = new BrAPITrialSearchRequest(); - trialSearch.programDbIds(List.of(program.getBrapiProgram().getProgramDbId())); - trialSearch.trialDbIds(new ArrayList<>(trialDbIds)); - TrialsApi api = brAPIEndpointProvider.get(programDAO.getCoreClient(program.getId()), TrialsApi.class); - return brAPIDAOUtil.search( - api::searchTrialsPost, - api::searchTrialsSearchResultsDbIdGet, - trialSearch - ); - } - - public List getTrialsByExperimentIds(Collection experimentIds, Program program) throws ApiException { - if(experimentIds.isEmpty()) { - return Collections.emptyList(); - } - - BrAPITrialSearchRequest trialSearch = new BrAPITrialSearchRequest(); - trialSearch.programDbIds(List.of(program.getBrapiProgram().getProgramDbId())); - //trialSearch.trialDbIds(experimentIds.stream().map(id -> id.toString()).collect(Collectors.toList())); - trialSearch.externalReferenceSources(List.of(referenceSource + "/" + ExternalReferenceSource.TRIALS.getName())); - trialSearch.externalReferenceIDs(experimentIds.stream().map(id -> id.toString()).collect(Collectors.toList())); - TrialsApi api = brAPIEndpointProvider.get(programDAO.getCoreClient(program.getId()), TrialsApi.class); - return brAPIDAOUtil.search( - api::searchTrialsPost, - api::searchTrialsSearchResultsDbIdGet, - trialSearch - ); - } + List getTrialsByDbIds(Collection trialDbIds, Program program) throws ApiException; + List getTrialsByExperimentIds(Collection experimentIds, Program program) throws ApiException; } - - diff --git a/src/main/java/org/breedinginsight/brapps/importer/daos/impl/BrAPITrialDAOImpl.java b/src/main/java/org/breedinginsight/brapps/importer/daos/impl/BrAPITrialDAOImpl.java new file mode 100644 index 000000000..f26d039ba --- /dev/null +++ b/src/main/java/org/breedinginsight/brapps/importer/daos/impl/BrAPITrialDAOImpl.java @@ -0,0 +1,282 @@ +/* + * See the NOTICE file distributed with this work for additional information + * regarding copyright ownership. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.breedinginsight.brapps.importer.daos.impl; + +import io.micronaut.context.annotation.Context; +import io.micronaut.context.annotation.Property; +import io.micronaut.http.server.exceptions.InternalServerException; +import io.micronaut.scheduling.annotation.Scheduled; +import lombok.extern.slf4j.Slf4j; +import org.brapi.client.v2.model.exceptions.ApiException; +import org.brapi.client.v2.modules.core.TrialsApi; +import org.brapi.v2.model.BrAPIExternalReference; +import org.brapi.v2.model.core.BrAPITrial; +import org.brapi.v2.model.core.request.BrAPITrialSearchRequest; +import org.breedinginsight.brapps.importer.daos.BrAPITrialDAO; +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.ProgramService; +import org.breedinginsight.services.brapi.BrAPIEndpointProvider; +import org.breedinginsight.services.exceptions.DoesNotExistException; +import org.breedinginsight.utilities.BrAPIDAOUtil; +import org.breedinginsight.utilities.Utilities; + +import javax.inject.Inject; +import javax.inject.Singleton; +import java.util.*; +import java.util.concurrent.Callable; +import java.util.stream.Collectors; + +@Slf4j +@Context +@Singleton +public class BrAPITrialDAOImpl implements BrAPITrialDAO { + private final ProgramCache programExperimentCache; + private final ProgramDAO programDAO; + private final ImportDAO importDAO; + private final BrAPIDAOUtil brAPIDAOUtil; + private final ProgramService programService; + private final BrAPIEndpointProvider brAPIEndpointProvider; + private final String referenceSource; + private final boolean runScheduledTasks; + + @Inject + public BrAPITrialDAOImpl(ProgramCacheProvider programCacheProvider, + ProgramDAO programDAO, + ImportDAO importDAO, + BrAPIDAOUtil brAPIDAOUtil, + ProgramService programService, + @Property(name = "brapi.server.reference-source") String referenceSource, + BrAPIEndpointProvider brAPIEndpointProvider, + @Property(name = "micronaut.bi.api.run-scheduled-tasks") boolean runScheduledTasks) { + this.programExperimentCache = programCacheProvider.getProgramCache(this::fetchProgramExperiments, BrAPITrial.class); + this.programDAO = programDAO; + this.importDAO = importDAO; + this.brAPIDAOUtil = brAPIDAOUtil; + this.programService = programService; + this.referenceSource = referenceSource; + this.brAPIEndpointProvider = brAPIEndpointProvider; + this.runScheduledTasks = runScheduledTasks; + } + + + @Scheduled(initialDelay = "2s") + public void setup() { + if(!runScheduledTasks) { + return; + } + + // Populate the experiment cache for all programs on startup + log.debug("populating experiment cache"); + List programs = programDAO.getActive(); + if (programs != null) { + programExperimentCache.populate(programs.stream().map(Program::getId).collect(Collectors.toList())); + } + } + + private Map fetchProgramExperiments(UUID programId) throws ApiException { + TrialsApi api = brAPIEndpointProvider.get(programDAO.getCoreClient(programId), TrialsApi.class); + + // Get the program + List programs = programDAO.get(programId); + if (programs.size() != 1) { + throw new InternalServerException("Program was not found for given key"); + } + Program program = programs.get(0); + + // Get the program experiments + BrAPITrialSearchRequest trialSearch = new BrAPITrialSearchRequest(); + trialSearch.externalReferenceIDs(List.of(programId.toString())); + trialSearch.externalReferenceSources( + List.of(Utilities.generateReferenceSource(referenceSource, ExternalReferenceSource.PROGRAMS)) + ); + List programExperiments = brAPIDAOUtil.search( + api::searchTrialsPost, + api::searchTrialsSearchResultsDbIdGet, + trialSearch + ); + + return experimentById(processExperimentsForDisplay(programExperiments, program.getKey())); + } + + private Map experimentById(List trials) { + Map experimentById = new HashMap<>(); + for (BrAPITrial experiment: trials) { + BrAPIExternalReference xref = experiment + .getExternalReferences() + .stream() + .filter(reference -> String.format("%s/%s", referenceSource, ExternalReferenceSource.TRIALS).equalsIgnoreCase(reference.getReferenceSource())) + .findFirst().orElseThrow(() -> new IllegalStateException("No BI external reference found")); + experimentById.put(xref.getReferenceID(), experiment); + } + return experimentById; + } + + @Override + public List getTrialsByName(List trialNames, Program program) throws ApiException { + Map cache = programExperimentCache.get(program.getId()); + List trials = new ArrayList<>(); + if (cache != null) { + + // TODO: replace with more performant cache search, e.g. RediSearch + trials.addAll(cache + .values() + .stream() + .filter(t -> trialNames.contains(t.getTrialName())) + .collect(Collectors.toList())); + } + + return trials; + } + + private List getTrialsByExRef(String referenceSource, String referenceId, Program program) throws ApiException { + Map cache = programExperimentCache.get(program.getId()); + List trials = new ArrayList<>(); + if (cache != null) { + trials.addAll(cache + .values() + .stream() + .filter(t -> { + BrAPIExternalReference xref = t + .getExternalReferences() + .stream() + .filter(reference -> String.format("%s/%s", referenceSource, ExternalReferenceSource.TRIALS) + .equalsIgnoreCase(reference.getReferenceSource())) + .findFirst().orElseThrow(() -> new IllegalStateException("No BI trial external reference found")); + return referenceId.equals(xref.getReferenceID()); + }) + .collect(Collectors.toList())); + } + + return trials; + } + + @Override + public List createBrAPITrials(List brAPITrialList, UUID programId, ImportUpload upload) + throws ApiException { + TrialsApi api = brAPIEndpointProvider.get(programDAO.getCoreClient(programId), TrialsApi.class); + List createdTrials = new ArrayList<>(); + try { + if (!brAPITrialList.isEmpty()) { + Callable> postCallback = () -> { + List postedTrials = brAPIDAOUtil + .post(brAPITrialList, upload, api::trialsPost, importDAO::update); + return experimentById(postedTrials); + }; + createdTrials.addAll(programExperimentCache.post(programId, postCallback)); + } + + return createdTrials; + } catch (Exception e) { + throw new InternalServerException("Unknown error has occurred: " + e.getMessage(), e); + } + } + @Override + public BrAPITrial updateBrAPITrial(String trialDbId, BrAPITrial trial, UUID programId) throws ApiException { + TrialsApi api = brAPIEndpointProvider.get(programDAO.getCoreClient(programId), TrialsApi.class); + BrAPITrial updatedTrial = null; + try { + if (trial != null && !trialDbId.isBlank()) { + Callable> putCallback = () -> { + BrAPITrial putTrial = brAPIDAOUtil.put(trialDbId, trial, api::trialsTrialDbIdPut); + return experimentById(List.of(putTrial)); + }; + List cachedUpdates = programExperimentCache.post(programId, putCallback); + if (cachedUpdates.isEmpty()) { + throw new Exception(); + } + updatedTrial = cachedUpdates.get(0); + } + + return updatedTrial; + } catch (Exception e) { + throw new InternalServerException("Unknown error has occurred: " + e.getMessage(), e); + } + } + + @Override + public List getTrials(UUID programId) throws ApiException { + return new ArrayList<>(programExperimentCache.get(programId).values()); + } + + //Removes program key from trial name + private List processExperimentsForDisplay( + List trials, + String programKey) throws ApiException { + List displayExperiments = new ArrayList<>(); + for (BrAPITrial trial: trials) { + trial.setTrialName(Utilities.removeProgramKey(trial.getTrialName(), programKey, "")); + displayExperiments.add(trial); + } + return displayExperiments; + } + + @Override + public Optional getTrialById(UUID programId, UUID trialId) throws ApiException, DoesNotExistException { + Map cache = programExperimentCache.get(programId); + BrAPITrial trial = null; + if (cache != null) { + trial = cache.get(trialId.toString()); + } + + return Optional.ofNullable(trial); + } + + @Override + public Optional getTrialByDbId(String trialDbId, Program program) throws ApiException { + List trials = getTrialsByDbIds(List.of(trialDbId), program); + return Utilities.getSingleOptional(trials); + } + + @Override + public List getTrialsByDbIds(Collection trialDbIds, Program program) throws ApiException { + Map cache = programExperimentCache.get(program.getId()); + List trials = new ArrayList<>(); + if (cache != null) { + trials.addAll(cache + .values() + .stream() + .filter(t -> trialDbIds.contains(t.getTrialDbId())) + .collect(Collectors.toList())); + } + + return trials; + } + @Override + public List getTrialsByExperimentIds(Collection experimentIds, Program program) throws ApiException { + if(experimentIds.isEmpty()) { + return Collections.emptyList(); + } + BrAPITrialSearchRequest trialSearch = new BrAPITrialSearchRequest(); + trialSearch.programDbIds(List.of(program.getBrapiProgram().getProgramDbId())); + trialSearch.externalReferenceSources(List.of(referenceSource + "/" + ExternalReferenceSource.TRIALS.getName())); + trialSearch.externalReferenceIDs(experimentIds.stream().map(id -> id.toString()).collect(Collectors.toList())); + TrialsApi api = brAPIEndpointProvider.get(programDAO.getCoreClient(program.getId()), TrialsApi.class); + return brAPIDAOUtil.search( + api::searchTrialsPost, + api::searchTrialsSearchResultsDbIdGet, + trialSearch + ); + } +} + + diff --git a/src/main/java/org/breedinginsight/brapps/importer/services/processors/ExperimentProcessor.java b/src/main/java/org/breedinginsight/brapps/importer/services/processors/ExperimentProcessor.java index f9c79bdd9..834394af1 100644 --- a/src/main/java/org/breedinginsight/brapps/importer/services/processors/ExperimentProcessor.java +++ b/src/main/java/org/breedinginsight/brapps/importer/services/processors/ExperimentProcessor.java @@ -1141,7 +1141,7 @@ private Map> initializeTrialByNameNoScop List uniqueTrialNames = experimentImportRows.stream() .filter(row -> StringUtils.isBlank(row.getObsUnitID())) - .map(experimentImport -> Utilities.appendProgramKey(experimentImport.getExpTitle(), programKey)) + .map(ExperimentObservation::getExpTitle) .distinct() .collect(Collectors.toList()); try { diff --git a/src/test/java/org/breedinginsight/brapps/importer/ExperimentFileImportTest.java b/src/test/java/org/breedinginsight/brapps/importer/ExperimentFileImportTest.java index d63a0a515..af194ee3a 100644 --- a/src/test/java/org/breedinginsight/brapps/importer/ExperimentFileImportTest.java +++ b/src/test/java/org/breedinginsight/brapps/importer/ExperimentFileImportTest.java @@ -304,7 +304,7 @@ public void importNewEnvExistingExpNoObsSuccess() { newExp.put(Columns.ROW, "1"); newExp.put(Columns.COLUMN, "1"); - importTestUtils.uploadAndFetch(writeDataToFile(List.of(newExp), null), null, true, client, program, mappingId); + JsonObject expResult = importTestUtils.uploadAndFetch(writeDataToFile(List.of(newExp), null), null, true, client, program, mappingId); Map newEnv = new HashMap<>(); newEnv.put(Columns.GERMPLASM_GID, "1"); @@ -634,7 +634,7 @@ public void importNewObsVarExisingOu() { importTestUtils.uploadAndFetch(writeDataToFile(List.of(newExp), null), null, true, client, program, mappingId); - BrAPITrial brAPITrial = brAPITrialDAO.getTrialsByName(List.of(Utilities.appendProgramKey((String)newExp.get(Columns.EXP_TITLE), program.getKey())), program).get(0); + BrAPITrial brAPITrial = brAPITrialDAO.getTrialsByName(List.of((String)newExp.get(Columns.EXP_TITLE)), program).get(0); Optional trialIdXref = Utilities.getExternalReference(brAPITrial.getExternalReferences(), String.format("%s/%s", BRAPI_REFERENCE_SOURCE, ExternalReferenceSource.TRIALS.getName())); assertTrue(trialIdXref.isPresent()); BrAPIStudy brAPIStudy = brAPIStudyDAO.getStudiesByExperimentID(UUID.fromString(trialIdXref.get().getReferenceID()), program).get(0); @@ -699,7 +699,7 @@ public void importNewObsExisingOu(boolean commit) { importTestUtils.uploadAndFetch(writeDataToFile(List.of(newExp), null), null, true, client, program, mappingId); - BrAPITrial brAPITrial = brAPITrialDAO.getTrialsByName(List.of(Utilities.appendProgramKey((String)newExp.get(Columns.EXP_TITLE), program.getKey())), program).get(0); + BrAPITrial brAPITrial = brAPITrialDAO.getTrialsByName(List.of((String)newExp.get(Columns.EXP_TITLE)), program).get(0); Optional trialIdXref = Utilities.getExternalReference(brAPITrial.getExternalReferences(), String.format("%s/%s", BRAPI_REFERENCE_SOURCE, ExternalReferenceSource.TRIALS.getName())); assertTrue(trialIdXref.isPresent()); BrAPIStudy brAPIStudy = brAPIStudyDAO.getStudiesByExperimentID(UUID.fromString(trialIdXref.get().getReferenceID()), program).get(0); @@ -766,7 +766,7 @@ public void verifyFailureImportNewObsExisingOuWithExistingObs(boolean commit) { importTestUtils.uploadAndFetch(writeDataToFile(List.of(newExp), traits), null, true, client, program, mappingId); - BrAPITrial brAPITrial = brAPITrialDAO.getTrialsByName(List.of(Utilities.appendProgramKey((String)newExp.get(Columns.EXP_TITLE), program.getKey())), program).get(0); + BrAPITrial brAPITrial = brAPITrialDAO.getTrialsByName(List.of((String)newExp.get(Columns.EXP_TITLE)), program).get(0); Optional trialIdXref = Utilities.getExternalReference(brAPITrial.getExternalReferences(), String.format("%s/%s", BRAPI_REFERENCE_SOURCE, ExternalReferenceSource.TRIALS.getName())); assertTrue(trialIdXref.isPresent()); BrAPIStudy brAPIStudy = brAPIStudyDAO.getStudiesByExperimentID(UUID.fromString(trialIdXref.get().getReferenceID()), program).get(0); @@ -866,7 +866,7 @@ public void importSecondExpAfterFirstExpWithObs() { private Map assertRowSaved(Map expected, Program program, List traits) throws ApiException { Map ret = new HashMap<>(); - List trials = brAPITrialDAO.getTrialsByName(List.of(Utilities.appendProgramKey((String)expected.get(Columns.EXP_TITLE), program.getKey())), program); + List trials = brAPITrialDAO.getTrialsByName(List.of((String)expected.get(Columns.EXP_TITLE)), program); assertFalse(trials.isEmpty()); BrAPITrial trial = trials.get(0); Optional trialIdXref = Utilities.getExternalReference(trial.getExternalReferences(), String.format("%s/%s", BRAPI_REFERENCE_SOURCE, ExternalReferenceSource.TRIALS.getName())); diff --git a/src/test/java/org/breedinginsight/services/geno/impl/GigwaGenotypeServiceImplIntegrationTest.java b/src/test/java/org/breedinginsight/services/geno/impl/GigwaGenotypeServiceImplIntegrationTest.java index 3ed181b75..69f21d272 100644 --- a/src/test/java/org/breedinginsight/services/geno/impl/GigwaGenotypeServiceImplIntegrationTest.java +++ b/src/test/java/org/breedinginsight/services/geno/impl/GigwaGenotypeServiceImplIntegrationTest.java @@ -45,6 +45,7 @@ import org.breedinginsight.brapps.importer.daos.BrAPITrialDAO; import org.breedinginsight.brapps.importer.daos.ImportDAO; import org.breedinginsight.brapps.importer.daos.ImportMappingDAO; +import org.breedinginsight.brapps.importer.daos.impl.BrAPITrialDAOImpl; import org.breedinginsight.brapps.importer.daos.impl.ImportMappingDAOImpl; import org.breedinginsight.brapps.importer.model.ImportProgress; import org.breedinginsight.brapps.importer.model.ImportUpload; @@ -186,11 +187,13 @@ ImportDAO importDAO() { return mock(ImportDAO.class); } - @MockBean(BrAPITrialDAO.class) + + @MockBean(BrAPITrialDAOImpl.class) BrAPITrialDAO trialDAO() { - return mock(BrAPITrialDAO.class); + return mock(BrAPITrialDAOImpl.class); } + @MockBean(BrAPIDAOUtil.class) BrAPIDAOUtil brAPIDAOUtil() { return spy(new BrAPIDAOUtil(1000, Duration.of(10, ChronoUnit.MINUTES), 1000, 100)); @@ -230,7 +233,7 @@ public GigwaGenotypeServiceImplIntegrationTest() { gigwa = new GenericContainer<>("breedinginsight/gigwa:develop") .withNetwork(super.getNetwork()) .withNetworkAliases("gigwa") - .withImagePullPolicy(PullPolicy.defaultPolicy()) + .withImagePullPolicy(PullPolicy.alwaysPull()) .withExposedPorts(8080) .withEnv("MONGO_IP", "gigwa_db") .withEnv("MONGO_PORT", "27017") @@ -285,7 +288,7 @@ public void setup() throws IllegalAccessException, NoSuchFieldException { storageService = applicationContext.getBean(SimpleStorageService.class, Qualifiers.byName("genotype")); storageService.createBucket(); - } + } @AfterAll public void teardown() { @@ -353,6 +356,8 @@ public void testFetchGermplasmGenotype() throws AuthorizationException, ApiExcep BrAPITrial trial = new BrAPITrial().externalReferences(List.of(new BrAPIExternalReference().referenceSource(Utilities.generateReferenceSource(referenceSource, ExternalReferenceSource.TRIALS)) .referenceID(UUID.randomUUID() .toString()))); + + doReturn(List.of(trial)).when(trialDAO).getTrials(any(UUID.class)); doAnswer(invocation -> {