Commit 0e17f67c authored by Matija Obreza's avatar Matija Obreza

Accession API updates

- /acn/filter uses sort by seqNo
- /acn/details by AID4 lists accession details
parent 552e6723
......@@ -52,11 +52,10 @@ import org.genesys2.server.model.impl.Organization;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.genesys2.server.service.impl.NoSuchAccessionException;
import org.genesys2.server.service.impl.NonUniqueAccessionException;
import org.genesys2.server.servlet.controller.rest.model.AccessionHeaderJson;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import javax.servlet.http.HttpServletResponse;
public interface GenesysService {
/**
......@@ -227,6 +226,8 @@ public interface GenesysService {
AccessionDetails getAccessionDetails(long accessionId);
List<AccessionDetails> getAccessionDetails(Set<AccessionHeaderJson> acceIds);
List<AccessionCollect> removeCollecting(List<AccessionCollect> toRemove);
List<AccessionGeo> removeGeo(List<AccessionGeo> toRemove);
......
......@@ -107,6 +107,7 @@ import org.genesys2.server.service.HtmlSanitizer;
import org.genesys2.server.service.OrganizationService;
import org.genesys2.server.service.TaxonomyService;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.genesys2.server.servlet.controller.rest.model.AccessionHeaderJson;
import org.genesys2.util.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -325,17 +326,17 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
}
}
/**
* {@inheritDoc}
*/
@Override
public List<Accession> listAccessions(final String acceNumb) {
List<Accession> accessions = new ArrayList<>();
for (final Accession accession : accessionRepository.findByAccessionName(acceNumb)) {
accessions.add(lazyLoadAccession(accession));
}
return accessions;
}
/**
* {@inheritDoc}
*/
@Override
public List<Accession> listAccessions(final String acceNumb) {
List<Accession> accessions = new ArrayList<>();
for (final Accession accession : accessionRepository.findByAccessionName(acceNumb)) {
accessions.add(lazyLoadAccession(accession));
}
return accessions;
}
@Override
public Accession getAccession(String instCode, String doi, String acceNumb, String genus) throws NonUniqueAccessionException {
......@@ -439,6 +440,23 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
return set;
}
@Override
public List<AccessionDetails> getAccessionDetails(Set<AccessionHeaderJson> acceIds) {
Set<Long> accessionIds = acceIds.stream().filter(id -> id != null)
// to Accession
.map(acceId -> accessionRepository.findOne(
// institute
instituteRepository.findByCode(acceId.getHoldingInstitute()),
// identifiers
acceId.getDoi(), acceId.getAccessionNumber(), acceId.getGenus()))
// to
.filter(accession -> accession != null)
// to id
.map(accession -> accession.getId()).collect(Collectors.toSet());
return getAccessionDetails(accessionIds);
}
@Override
public List<Accession> listAccessions(FaoInstitute faoInstitute, String accessionName) {
return accessionRepository.findByInstituteAndAccessionName(faoInstitute, accessionName);
......@@ -1908,7 +1926,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
public List<Object[]> getLastUpdatedStatistics(FaoInstitute faoInstitute) {
return accessionRepository.lastUpdatedStatistics(faoInstitute);
}
@Override
@Cacheable(value = "statistics", unless = "#result == null", key = "'stats.' + #root.methodName + '-' + #faoInstitute.code + '-' + #historic")
public List<Object[]> getLastUpdatedStatistics(FaoInstitute faoInstitute, boolean historic) {
......
......@@ -57,11 +57,13 @@ import org.springframework.dao.CannotAcquireLockException;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.http.MediaType;
import org.springframework.orm.hibernate4.HibernateOptimisticLockingFailureException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
......@@ -494,9 +496,18 @@ public class AccessionController extends RestController {
LOG.debug(appliedFilters.toString());
}
Page<AccessionDetails> accessions = filterService.listAccessionDetails(appliedFilters, new PageRequest(page, Integer.min(pageSize, maxPageSize)));
Page<AccessionDetails> accessions = filterService.listAccessionDetails(appliedFilters, new PageRequest(page, Integer.min(pageSize, maxPageSize), new Sort("seqNo")));
return accessions;
}
@PostMapping(value="/details", consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<AccessionDetails> getDetails(@RequestBody Set<AccessionHeaderJson> acceIds) throws RESTApiException {
if (acceIds.size() > 100) {
throw new RESTApiException("Can't request data for over 100 IDs at a time");
}
return genesysService.getAccessionDetails(acceIds);
}
public static class JsonData {
public String crop;
......
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