Commit 9396a52c authored by Matija Obreza's avatar Matija Obreza

Fix: AccessionRef serialization for Datasets, batch load in AccessionRepository#find()

parent d6cde111
......@@ -226,7 +226,7 @@ public class DatasetController extends ApiBaseController {
* @return the page
* @throws NotFoundElement
*/
@JsonView({ JsonViews.Minimal.class })
@JsonView({ JsonViews.Public.class })
@GetMapping(value = "/accessions/{uuid}", produces = { MediaType.APPLICATION_JSON_VALUE })
public Page<AccessionRef> listAccessions(@PathVariable("uuid") final UUID uuid, final Pagination page) throws NotFoundElement {
return datasetService.listAccessions(datasetService.loadDataset(uuid), page.toPageRequest(100));
......
......@@ -88,30 +88,36 @@ public class AccessionRepositoryCustomImpl implements AccessionRepositoryCustom,
cq.distinct(true);
cq.select(root.get("id"));
List<Predicate> restrictions = new ArrayList<Predicate>();
Set<String> uniqueDois = forUpdate.stream().map(aid -> aid.getDoi()).filter(doi -> doi != null).distinct().collect(Collectors.toSet());
List<Accession> res = new ArrayList<>(forUpdate.size());
Path<Object> theDoi = root.get("doi");
Path<Object> theInstCode = root.get("instituteCode");
Path<Object> theAcceNumb = root.get("accessionNumber");
Path<Object> theGenus = root.get("genus");
final int chunkSize = 200;
for (int fromIndex = 0; fromIndex < forUpdate.size(); fromIndex += chunkSize) {
List<? extends AccessionIdentifier3> sublist = forUpdate.subList(fromIndex, Math.min(forUpdate.size(), fromIndex + chunkSize));
if (uniqueDois.size() > 0) {
restrictions.add(theDoi.in(uniqueDois));
LOG.trace("*** {} dois={}", uniqueDois.size(), uniqueDois);
}
// A lot of .. (instCode=? and acceNumb=? and genus=?)
for (AccessionIdentifier3 ah : forUpdate) {
restrictions.add(criteriaBuilder.and(criteriaBuilder.equal(theInstCode, ah.getHoldingInstitute()), criteriaBuilder.equal(theAcceNumb, ah
.getAccessionNumber()), criteriaBuilder.equal(theGenus, ah.getGenus())));
List<Predicate> restrictions = new ArrayList<Predicate>();
Set<String> uniqueDois = sublist.stream().map(aid -> aid.getDoi()).filter(doi -> doi != null).distinct().collect(Collectors.toSet());
Path<Object> theDoi = root.get("doi");
Path<Object> theInstCode = root.get("instituteCode");
Path<Object> theAcceNumb = root.get("accessionNumber");
Path<Object> theGenus = root.get("genus");
if (uniqueDois.size() > 0) {
restrictions.add(theDoi.in(uniqueDois));
LOG.trace("*** {} dois={}", uniqueDois.size(), uniqueDois);
}
// A lot of .. (instCode=? and acceNumb=? and genus=?)
for (AccessionIdentifier3 ah : sublist) {
restrictions.add(criteriaBuilder.and(criteriaBuilder.equal(theInstCode, ah.getHoldingInstitute()), criteriaBuilder.equal(theAcceNumb, ah
.getAccessionNumber()), criteriaBuilder.equal(theGenus, ah.getGenus())));
}
cq.where(criteriaBuilder.or(restrictions.toArray(EMPTY_PREDICATE_ARRAY)));
res.addAll(jpaQueryFactory.selectFrom(QAccession.accession).where(QAccession.accession.id.in(em.createQuery(cq).getResultList())).fetch());
}
cq.where(criteriaBuilder.or(restrictions.toArray(EMPTY_PREDICATE_ARRAY)));
List<Accession> res = jpaQueryFactory.selectFrom(QAccession.accession).where(QAccession.accession.id.in(em.createQuery(cq).getResultList())).fetch();
if (LOG.isDebugEnabled())
LOG.trace("*** Loaded accessions {} of {}", res.size(), forUpdate.size());
......
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