Commit 9648bd26 authored by Matija Obreza's avatar Matija Obreza

Merge branch 'invalid-accession-lookups' into 'master'

Fix: AccessionId3 lookup with/without genus

See merge request genesys-pgr/genesys-server!351
parents 0c1d0c1f 2bda7037
...@@ -970,7 +970,7 @@ public class DatasetServiceImpl implements DatasetService { ...@@ -970,7 +970,7 @@ public class DatasetServiceImpl implements DatasetService {
Iterables.partition(accessionRefs, 500).forEach(batch -> { Iterables.partition(accessionRefs, 500).forEach(batch -> {
LOG.info("Batch {} with size {}", batchCounter.incrementAndGet(), batch.size()); LOG.info("Batch {} with size {}", batchCounter.incrementAndGet(), batch.size());
List<Accession> foundAccessions = accessionRepository.find(batch); List<Accession> foundAccessions = accessionRepository.find(true, batch);
LOG.info("Found {} matches for {} identifiers after {}ms", foundAccessions.size(), batch.size(), stopWatch.getTime()); LOG.info("Found {} matches for {} identifiers after {}ms", foundAccessions.size(), batch.size(), stopWatch.getTime());
// instCode / genus / acceNumb map // instCode / genus / acceNumb map
......
...@@ -53,10 +53,11 @@ public interface AccessionRepositoryCustom { ...@@ -53,10 +53,11 @@ public interface AccessionRepositoryCustom {
/** /**
* Find by id. * Find by id.
* *
* @param useGenus include genus in filter
* @param identifiers the identifiers * @param identifiers the identifiers
* @return the list * @return the list
*/ */
List<Accession> find(List<? extends AccessionIdentifier3> identifiers); List<Accession> find(boolean useGenus, List<? extends AccessionIdentifier3> identifiers);
/** /**
* Find one. * Find one.
......
...@@ -79,7 +79,7 @@ public class AccessionRepositoryCustomImpl implements AccessionRepositoryCustom, ...@@ -79,7 +79,7 @@ public class AccessionRepositoryCustomImpl implements AccessionRepositoryCustom,
} }
@Override @Override
public List<Accession> find(List<? extends AccessionIdentifier3> forUpdate) { public List<Accession> find(boolean useGenus, List<? extends AccessionIdentifier3> forUpdate) {
if (forUpdate == null || forUpdate.isEmpty()) { if (forUpdate == null || forUpdate.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
...@@ -113,8 +113,13 @@ public class AccessionRepositoryCustomImpl implements AccessionRepositoryCustom, ...@@ -113,8 +113,13 @@ public class AccessionRepositoryCustomImpl implements AccessionRepositoryCustom,
// A lot of .. (instCode=? and acceNumb=? and genus=?) // A lot of .. (instCode=? and acceNumb=? and genus=?)
for (AccessionIdentifier3 ah : sublist) { for (AccessionIdentifier3 ah : sublist) {
if (useGenus) {
restrictions.add(criteriaBuilder.and(criteriaBuilder.equal(theInstCode, ah.getHoldingInstitute()), criteriaBuilder.equal(theAcceNumb, ah.getAccessionNumber()),
criteriaBuilder.equal(theGenus, ah.getGenus())));
} else {
restrictions.add(criteriaBuilder.and(criteriaBuilder.equal(theInstCode, ah.getHoldingInstitute()), criteriaBuilder.equal(theAcceNumb, ah restrictions.add(criteriaBuilder.and(criteriaBuilder.equal(theInstCode, ah.getHoldingInstitute()), criteriaBuilder.equal(theAcceNumb, ah
.getAccessionNumber()), criteriaBuilder.equal(theGenus, ah.getGenus()))); .getAccessionNumber())));
}
} }
cq.where(criteriaBuilder.or(restrictions.toArray(EMPTY_PREDICATE_ARRAY))); cq.where(criteriaBuilder.or(restrictions.toArray(EMPTY_PREDICATE_ARRAY)));
......
...@@ -213,7 +213,7 @@ public class AccessionServiceImpl implements AccessionService { ...@@ -213,7 +213,7 @@ public class AccessionServiceImpl implements AccessionService {
final int chunkSize = 200; final int chunkSize = 200;
for (int fromIndex = 0; fromIndex < identifiers.size(); fromIndex += chunkSize) { for (int fromIndex = 0; fromIndex < identifiers.size(); fromIndex += chunkSize) {
List<Accession> foundAccessions = accessionRepository.find(identifiers.subList(fromIndex, Math.min(identifiers.size(), fromIndex + chunkSize))); List<Accession> foundAccessions = accessionRepository.find(true, identifiers.subList(fromIndex, Math.min(identifiers.size(), fromIndex + chunkSize)));
for (Accession accession : foundAccessions) { for (Accession accession : foundAccessions) {
Optional<? extends AccessionIdentifier3> toPut = identifiers.stream().filter(id -> id.getAccessionNumber().equals(accession.getAccessionNumber()) && id.getGenus() Optional<? extends AccessionIdentifier3> toPut = identifiers.stream().filter(id -> id.getAccessionNumber().equals(accession.getAccessionNumber()) && id.getGenus()
.equals(accession.getGenus()) && id.getHoldingInstitute().equals(accession.getInstCode())).findFirst(); .equals(accession.getGenus()) && id.getHoldingInstitute().equals(accession.getInstCode())).findFirst();
......
...@@ -653,7 +653,7 @@ public class SubsetServiceImpl implements SubsetService { ...@@ -653,7 +653,7 @@ public class SubsetServiceImpl implements SubsetService {
Iterables.partition(accessionRefs, 500).forEach(batch -> { Iterables.partition(accessionRefs, 500).forEach(batch -> {
LOG.info("Batch {} with size {}", batchCounter.incrementAndGet(), batch.size()); LOG.info("Batch {} with size {}", batchCounter.incrementAndGet(), batch.size());
List<Accession> foundAccessions = accessionRepository.find(batch); List<Accession> foundAccessions = accessionRepository.find(true, batch);
LOG.info("Found {} matches for {} identifiers after {}ms", foundAccessions.size(), batch.size(), stopWatch.getTime()); LOG.info("Found {} matches for {} identifiers after {}ms", foundAccessions.size(), batch.size(), stopWatch.getTime());
// instCode / genus / acceNumb map // instCode / genus / acceNumb map
......
...@@ -155,7 +155,7 @@ public class AccessionUploader implements InitializingBean { ...@@ -155,7 +155,7 @@ public class AccessionUploader implements InitializingBean {
LOG.debug("Processsed incoming JSON for {} accessions in {}ms", updates.size(), stopWatch.getTime()); LOG.debug("Processsed incoming JSON for {} accessions in {}ms", updates.size(), stopWatch.getTime());
List<Accession> existingAccessions = accessionRepository.find(accessions); List<Accession> existingAccessions = accessionRepository.find(! institute.hasUniqueAcceNumbs(), accessions);
LOG.debug("Have {} accessions for update and {} exist in {}ms", accessions.size(), existingAccessions.size(), stopWatch.getTime()); LOG.debug("Have {} accessions for update and {} exist in {}ms", accessions.size(), existingAccessions.size(), stopWatch.getTime());
for (int i = 0; i < accessions.size(); i++) { for (int i = 0; i < accessions.size(); i++) {
...@@ -174,6 +174,9 @@ public class AccessionUploader implements InitializingBean { ...@@ -174,6 +174,9 @@ public class AccessionUploader implements InitializingBean {
Accession accession = existingAccessions.stream().filter(existing -> { Accession accession = existingAccessions.stream().filter(existing -> {
return (existing.getDoi() != null && existing.getDoi().equals(updateA.getDoi())) return (existing.getDoi() != null && existing.getDoi().equals(updateA.getDoi()))
// or by pair
|| (institute.hasUniqueAcceNumbs() && (StringUtils.equalsIgnoreCase(existing.getInstituteCode(), updateA.getInstituteCode()) && StringUtils.equalsIgnoreCase(existing.getAccessionNumber(),
updateA.getAccessionNumber())))
// or by triplet // or by triplet
|| (StringUtils.equalsIgnoreCase(existing.getInstituteCode(), updateA.getInstituteCode()) && StringUtils.equalsIgnoreCase(existing.getAccessionNumber(), || (StringUtils.equalsIgnoreCase(existing.getInstituteCode(), updateA.getInstituteCode()) && StringUtils.equalsIgnoreCase(existing.getAccessionNumber(),
updateA.getAccessionNumber()) && StringUtils.equalsIgnoreCase(existing.getTaxonomy().getGenus(), updateA.getTaxonomy().getGenus())); updateA.getAccessionNumber()) && StringUtils.equalsIgnoreCase(existing.getTaxonomy().getGenus(), updateA.getTaxonomy().getGenus()));
...@@ -610,7 +613,8 @@ public class AccessionUploader implements InitializingBean { ...@@ -610,7 +613,8 @@ public class AccessionUploader implements InitializingBean {
} }
final List<AccessionOpResponse> responses = new ArrayList<>(identifiers.size()); final List<AccessionOpResponse> responses = new ArrayList<>(identifiers.size());
List<Accession> existingAccessions = accessionRepository.find(identifiers); // Require matching genus for deletion
List<Accession> existingAccessions = accessionRepository.find(true, identifiers);
List<Accession> toRemove = new ArrayList<>(identifiers.size()); List<Accession> toRemove = new ArrayList<>(identifiers.size());
for (int i = 0; i < identifiers.size(); i++) { for (int i = 0; i < identifiers.size(); i++) {
......
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