Skip to content
Open
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 @@ -69,17 +69,12 @@ 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<BrAPIGermplasm> programGermplasmCache;

private final BrAPIEndpointProvider brAPIEndpointProvider;

private final int brapiMaxPageSize;
Expand All @@ -88,30 +83,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<Program> 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
Expand Down Expand Up @@ -203,9 +183,6 @@ private Map<String, BrAPIGermplasm> fetchProgramGermplasm(UUID programId) throws
}
}

public void repopulateGermplasmCacheForProgram(UUID programId) {
programGermplasmCache.populate(programId);
}
/**
* Process germplasm into a format for display
* @param programGermplasm
Expand Down Expand Up @@ -487,11 +464,8 @@ public List<BrAPIGermplasm> updateBrAPIGermplasm(List<BrAPIGermplasm> putBrAPIGe
var program = new Program(programDAO.fetchOneById(programId));
try {
if (!putBrAPIGermplasmList.isEmpty()) {
Callable<Map<String, BrAPIGermplasm>> postFunction = () -> {
List<BrAPIGermplasm> putResponse = putGermplasm(putBrAPIGermplasmList, api);
return processGermplasmForDisplay(putResponse, program);
};
return programGermplasmCache.post(programId, postFunction);
List<BrAPIGermplasm> putResponse = putGermplasm(putBrAPIGermplasmList, api);
return new ArrayList<>(processGermplasmForDisplay(putResponse, program).values());
}
return new ArrayList<>();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,6 @@ public void postBrapiData(Map<Integer, PendingImport> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public class BrAPIGermplasmServiceUnitTest extends DatabaseTest {
private BrAPIGermplasmService germplasmService;
private BrAPIDAOUtil brAPIDAOUtil;
private String referenceSource;
private ProgramCacheProvider cacheProvider;

@SneakyThrows
@BeforeEach
Expand All @@ -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");
Expand Down Expand Up @@ -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);

Expand Down
Loading