Commit d4596c40 authored by Viacheslav Pavlov's avatar Viacheslav Pavlov Committed by Matija Obreza

Added endpoint for translating list of accession ids to UUIDs

- MO: Added batch loading
Signed-off-by: Matija Obreza's avatarMatija Obreza <matija.obreza@croptrust.org>
parent e089c7f8
......@@ -132,6 +132,11 @@ public class AccessionController {
return accessionService.uuidFromId(id);
}
@PostMapping(value = "/id", produces = { MediaType.APPLICATION_JSON_VALUE })
public List<UUID> uuidFromIds(@RequestBody List<Long> ids) {
return accessionService.uuidsFromIds(ids);
}
/**
* Gets the accession
*
......
......@@ -43,8 +43,22 @@ public interface AccessionService {
*/
long countAccessions(AccessionFilter filter);
/**
* Get accession#uuid from id.
*
* @param id the id
* @return the uuid
*/
UUID uuidFromId(long id);
/**
* Get accession#uuids from ids
*
* @param ids the ids
* @return the list
*/
List<UUID> uuidsFromIds(List<Long> ids);
/**
* List accessions by filter
*
......
......@@ -96,6 +96,8 @@ public class AccessionServiceImpl implements AccessionService {
@Autowired
private AuditTrailService auditService;
private static final int LOAD_CHUNK_SIZE = 200;
private <T extends AccessionData> T lazyLoad(T accession) {
if (accession != null) {
AccessionId accessionId = accession.getAccessionId();
......@@ -233,9 +235,8 @@ public class AccessionServiceImpl implements AccessionService {
List<UUID> uuidList = new ArrayList<>(uuids);
List<Accession> accessions = new ArrayList<>(uuids.size());
final int chunkSize = 200;
for (int fromIndex = 0; fromIndex < uuids.size(); fromIndex+= chunkSize){
List<UUID> chunk = uuidList.subList(fromIndex, Math.min(uuids.size(), fromIndex+chunkSize));
for (int fromIndex = 0; fromIndex < uuids.size(); fromIndex+= LOAD_CHUNK_SIZE){
List<UUID> chunk = uuidList.subList(fromIndex, Math.min(uuids.size(), fromIndex+LOAD_CHUNK_SIZE));
accessions.addAll((List<Accession>) accessionRepository.findAll(QAccession.accession.accessionId.uuid.in(chunk)));
}
......@@ -266,6 +267,23 @@ public class AccessionServiceImpl implements AccessionService {
return accession.getUuid();
}
/**
* Converts list of accession IDs to respective accession UUIDs in batches of
* 100.
*
* @see org.genesys2.server.service.AccessionService#uuidsFromIds(java.util.List)
*/
@Override
public List<UUID> uuidsFromIds(List<Long> ids) {
List<UUID> uuids = new ArrayList<>();
for (int fromIndex = 0; fromIndex < ids.size(); fromIndex += LOAD_CHUNK_SIZE) {
List<Accession> accessions = accessionRepository.findAll(ids.subList(fromIndex, Math.min(fromIndex + LOAD_CHUNK_SIZE, ids.size())));
uuids.addAll(accessions.stream().map(AccessionData::getAccessionId).map(AccessionId::getUuid).collect(Collectors.toList()));
}
return uuids;
}
@Override
public Set<Long> filterAvailableForDistributionByUuid(Set<UUID> accessionUuids) {
if (accessionUuids == null || accessionUuids.size() == 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment