Commit 6b5655ec authored by Matija Obreza's avatar Matija Obreza

Merge branch '107-upload-support-for-doi' into 'master'

Resolve "Upload support for DOI"

Closes #107

See merge request !44
parents 92d07c8c 49b89ef9
/**
* Copyright 2014 Global Crop Diversity Trust
/*
* Copyright 2017 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -17,9 +17,12 @@
package org.genesys2.server.model.impl;
public interface AccessionIdentifier3 {
String getDoi();
String getHoldingInstitute();
String getAccessionName();
String getAccessionNumber();
String getGenus();
}
......@@ -17,13 +17,16 @@
package org.genesys2.server.persistence.domain;
import java.util.List;
import java.util.Set;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.impl.AccessionIdentifier3;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.service.impl.NonUniqueAccessionException;
public interface AccessionCustomRepository {
List<Accession> find(FaoInstitute institute, List<String> acceNumbs, List<String> genera) throws NonUniqueAccessionException;
List<Accession> find(FaoInstitute institute, Set<? extends AccessionIdentifier3> accessionIds) throws NonUniqueAccessionException;
Accession findOne(FaoInstitute institute, String doi, String acceNumb, String genus);
}
......@@ -35,7 +35,7 @@ import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
public interface AccessionRepository extends JpaRepository<Accession, Long> {
public interface AccessionRepository extends JpaRepository<Accession, Long>, AccessionCustomRepository {
@Query("select a.id from Accession a")
public List<Long> listAccessionsIds(Pageable pageable);
......@@ -55,14 +55,14 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
long countByOrigin(Country country);
/**
* Return the number of active ({@link Accession#historic} == false) accession records where holding institute is in the specified country
* Return the number of active ({@link Accession#historic} == false) accession records where holding institute is in the specified country
*/
@Query("select count(a) from Accession a where a.institute.country = ?1 and a.historic = false")
long countByLocation(Country country);
@Query(value = "select a.cropName, count(a.id) from Accession a where a.institute = ?1 and a.historic = false group by a.cropName order by count(a) desc", countQuery = "select count(distinct a.cropName) from Accession a where a.institute = ?1")
Page<Object[]> statisticsCropNameInInstitute(FaoInstitute institute, Pageable pageable);
@Query(value = "select t.genus, count(a.id) from Accession a inner join a.taxonomy t where a.institute = ?1 and a.historic = false group by t.genus order by count(a) desc", countQuery = "select count(distinct a.taxonomy.taxGenus) from Accession a where a.institute = ?1")
Page<Object[]> statisticsGenusInInstitute(FaoInstitute institute, Pageable pageable);
......@@ -92,11 +92,8 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
@Query("select a from Accession a where a.institute.code = ?1 and a.accessionName = ?2")
Accession findByInstituteCodeAndAccessionName(String instCode, String accessionName);
@Query("select distinct a from Accession a where a.accessionName=?2 and (a.institute.code=?1 or a.institute.codeSGSV=?1) and a.taxonomy.genus=?3")
Accession findOneSGSV(String instCode, String acceNumb, String genus);
@Query("select a from Accession a where a.institute.code=:instCode and a.accessionName=:acceNumb and a.taxonomy.genus=:genus")
Accession findOne(@Param("instCode") String holdingInstitute, @Param("acceNumb") String accessionName, @Param("genus") String genus);
@Query("select distinct a from Accession a where a.accessionName=?2 and (a.institute.code=?1 or a.institute.codeSGSV=?1) and a.taxonomy.genus=?3")
Accession findOneSGSV(String instCode, String acceNumb, String genus);
@Query("select count(a.id) from Accession a where a.id in ( ?1 ) and a.historic = false and (a.availability is null or a.availability = true) and a.institute.allowMaterialRequests = true")
long countAvailableForDistribution(Set<Long> accessionIds);
......@@ -114,20 +111,20 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
public List<Long> listAccessionsIds(Taxonomy2 taxonomy);
@Modifying
@Query(nativeQuery=true, value="delete from accession where id = ?1")
@Query(nativeQuery = true, value = "delete from accession where id = ?1")
public void deleteActive(long id);
@Query("select a from Accession a where a.accessionId.uuid = ?1")
public Accession findOneByUuid(UUID uuid);
public List<Accession> findByAccessionName(String acceNumb);
@Query("select a from Accession a")
Stream<Accession> streamAll();
public long countByHistoric(boolean historic);
@Query(nativeQuery=true, value="update accession a inner join sgsvdeposit sd on sd.acceId=a.id set a.inSGSV=true where sd.id in (?1)")
@Query(nativeQuery = true, value = "update accession a inner join sgsvdeposit sd on sd.acceId=a.id set a.inSGSV=true where sd.id in (?1)")
@Modifying
public void setInSvalbard(List<Long> sgsvId);
......
/**
* Copyright 2014 Global Crop Diversity Trust
/*
* Copyright 2017 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -20,6 +20,7 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
......@@ -30,20 +31,21 @@ import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.Taxonomy2;
import org.genesys2.server.model.impl.AccessionIdentifier3;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.service.impl.NonUniqueAccessionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
@Repository
@Transactional(readOnly = true)
public class AccessionCustomRepositoryImpl implements AccessionCustomRepository, InitializingBean {
public static final Log LOG = LogFactory.getLog(AccessionCustomRepositoryImpl.class);
public class AccessionRepositoryCustomImpl implements AccessionCustomRepository, InitializingBean {
public static final Logger LOG = LoggerFactory.getLogger(AccessionRepositoryCustomImpl.class);
@PersistenceContext
private EntityManager em;
......@@ -51,11 +53,17 @@ public class AccessionCustomRepositoryImpl implements AccessionCustomRepository,
private CriteriaBuilder criteriaBuilder;
@Override
public List<Accession> find(FaoInstitute institute, List<String> acceNumbs, List<String> genera) throws NonUniqueAccessionException {
public void afterPropertiesSet() throws Exception {
this.criteriaBuilder = em.getCriteriaBuilder();
}
@Override
public List<Accession> find(FaoInstitute institute, Set<? extends AccessionIdentifier3> accessionIds) throws NonUniqueAccessionException {
boolean uniqueAcceNumbs = institute.hasUniqueAcceNumbs();
CriteriaQuery<Accession> cq = criteriaBuilder.createQuery(Accession.class);
Root<Accession> root = cq.from(Accession.class);
cq.distinct(true);
cq.select(root);
root.fetch("stoRage", JoinType.LEFT);
......@@ -65,19 +73,26 @@ public class AccessionCustomRepositoryImpl implements AccessionCustomRepository,
}
List<Predicate> restrictions = new ArrayList<Predicate>();
Set<String> uniqueDois = accessionIds.stream().map(aid -> aid.getDoi()).filter(doi -> doi != null).distinct().collect(Collectors.toSet());
Set<String> acceNumbs = accessionIds.stream().map(aid -> aid.getAccessionNumber()).filter(acceNumb -> acceNumb != null).distinct().collect(Collectors.toSet());
if (uniqueDois.size() > 0) {
restrictions.add(root.get("doi").in(uniqueDois));
LOG.debug("*** {} dois={}", institute.getCode(), uniqueDois);
}
if (uniqueAcceNumbs) {
restrictions.add(root.get("accessionName").in(acceNumbs));
if (LOG.isDebugEnabled())
LOG.debug("*** " + institute.getCode() + " " + acceNumbs);
LOG.debug("*** {} accenumbs={}", institute.getCode(), acceNumbs);
} else {
// A lot of .. (acceNumb=? and genus=?)
for (int i = 0; i < acceNumbs.size(); i++) {
restrictions.add(criteriaBuilder.and(criteriaBuilder.equal(root.get("accessionName"), acceNumbs.get(i)),
criteriaBuilder.equal(tax.get("genus"), genera.get(i))));
for (AccessionIdentifier3 ah : accessionIds) {
restrictions.add(criteriaBuilder.and(criteriaBuilder.equal(root.get("accessionName"), ah.getAccessionNumber()), criteriaBuilder.equal(tax.get("genus"), ah.getGenus())));
}
}
cq.where(criteriaBuilder.and(criteriaBuilder.equal(root.get("institute"), institute), criteriaBuilder.or(restrictions.toArray(new Predicate[] {}))));
cq.distinct(true);
List<Accession> res = em.createQuery(cq).getResultList();
if (LOG.isDebugEnabled())
......@@ -100,7 +115,26 @@ public class AccessionCustomRepositoryImpl implements AccessionCustomRepository,
}
@Override
public void afterPropertiesSet() throws Exception {
this.criteriaBuilder = em.getCriteriaBuilder();
public Accession findOne(FaoInstitute institute, String doi, String acceNumb, String genus) {
CriteriaQuery<Accession> cq = criteriaBuilder.createQuery(Accession.class);
Root<Accession> root = cq.from(Accession.class);
cq.distinct(true);
cq.select(root);
root.fetch("stoRage", JoinType.LEFT);
Join<Object, Object> tax = root.join("taxonomy");
List<Predicate> restrictions = new ArrayList<Predicate>();
if (doi != null) {
restrictions.add(criteriaBuilder.equal(root.get("doi"), doi));
} else if (institute.hasUniqueAcceNumbs()) {
restrictions.add(criteriaBuilder.equal(root.get("accessionName"), acceNumb));
} else {
restrictions.add(criteriaBuilder.and(criteriaBuilder.equal(root.get("accessionName"), acceNumb), criteriaBuilder.equal(tax.get("genus"), genus)));
}
cq.where(criteriaBuilder.and(criteriaBuilder.equal(root.get("institute"), institute), criteriaBuilder.or(restrictions.toArray(new Predicate[] {}))));
return em.createQuery(cq).getSingleResult();
}
}
......@@ -115,7 +115,7 @@ public interface GenesysService {
Accession getAccession(AccessionIdentifier3 aid3) throws NonUniqueAccessionException;
Accession getAccession(String instCode, String acceNumb, String genus) throws NonUniqueAccessionException;
Accession getAccession(String instCode, String doi, String acceNumb, String genus) throws NonUniqueAccessionException;
Page<Object[]> statisticsCropNameByInstitute(FaoInstitute faoInstitute, Pageable pageRequest);
......
......@@ -74,8 +74,8 @@ public class DownloadServiceImpl implements DownloadService {
public static final Logger LOG = LoggerFactory.getLogger(DownloadServiceImpl.class);
private static final int COL_DOI = 0;
private static final int COL_INSTCODE = 1;
private static final int COL_INSTCODE = 0;
private static final int COL_DOI = 1;
private static final int COL_ACCENUMB = 2;
private static final int COL_COLLNUMB = 3;
private static final int COL_COLLCODE = 4;
......
......@@ -283,7 +283,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
public Page<AccessionDetails> listAccessionsDetails(Collection<Long> accessionIds, Pageable pageable) {
if (! accessionIds.isEmpty()) {
if (!accessionIds.isEmpty()) {
Page<Accession> data = accessionRepository.findById(accessionIds, pageable);
return new PageImpl<AccessionDetails>(getAccessionDetails(data.getContent().stream().map(a -> a.getId()).collect(Collectors.toList())), pageable, data.getTotalElements());
} else {
......@@ -294,11 +294,11 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
public Accession getAccession(AccessionIdentifier3 aid3) throws NonUniqueAccessionException {
try {
Accession accession = accessionRepository.findOne(aid3.getHoldingInstitute(), aid3.getAccessionName(), aid3.getGenus());
Accession accession = accessionRepository.findOne(instituteRepository.findByCode(aid3.getHoldingInstitute()), aid3.getDoi(), aid3.getAccessionNumber(), aid3.getGenus());
return lazyLoadAccession(accession);
} catch (IncorrectResultSizeDataAccessException e) {
LOG.error("Duplicate accession name instCode=" + aid3.getHoldingInstitute() + " acceNumb=" + aid3.getAccessionName() + " genus=" + aid3.getGenus());
throw new NonUniqueAccessionException(aid3.getHoldingInstitute(), aid3.getAccessionName(), aid3.getGenus());
LOG.error("Duplicate accession name instCode=" + aid3.getHoldingInstitute() + " acceNumb=" + aid3.getAccessionNumber() + " genus=" + aid3.getGenus());
throw new NonUniqueAccessionException(aid3.getHoldingInstitute(), aid3.getAccessionNumber(), aid3.getGenus());
}
}
......@@ -314,12 +314,9 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
}
@Override
public Accession getAccession(String instCode, String acceNumb, String genus) throws NonUniqueAccessionException {
if (genus == null) {
throw new NullPointerException("Genus is required to load accession by instCode, acceNumb and genus");
}
public Accession getAccession(String instCode, String doi, String acceNumb, String genus) throws NonUniqueAccessionException {
try {
Accession accession = accessionRepository.findOne(instCode, acceNumb, genus);
Accession accession = accessionRepository.findOne(instituteRepository.findByCode(instCode), doi, acceNumb, genus);
return lazyLoadAccession(accession);
} catch (IncorrectResultSizeDataAccessException e) {
LOG.error("Duplicate accession name instCode=" + instCode + " acceNumb=" + acceNumb);
......@@ -330,14 +327,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
public Accession getAccession(long accessionId) {
Accession accession = accessionRepository.findOne(accessionId);
if (accession != null) {
accession.getStoRage().size();
if (accession.getCountryOfOrigin() != null)
accession.getCountryOfOrigin().getId();
if (accession.getCrop() != null)
accession.getCrop().getId();
}
return accession;
return lazyLoadAccession(accession);
}
@Override
......@@ -347,8 +337,13 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
}
private Accession lazyLoadAccession(Accession accession) {
if (accession != null)
if (accession != null) {
accession.getStoRage().size();
if (accession.getCountryOfOrigin() != null)
accession.getCountryOfOrigin().getId();
if (accession.getCrop() != null)
accession.getCrop().getId();
}
return accession;
}
......@@ -854,8 +849,8 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
}
/**
* Update {@link SvalbardDeposit} data and link with Genesys accessions. The primary key for {@link SvalbardDeposit}
* is the <code>sgsv_id</code> as provided by NordGen.
* Update {@link SvalbardDeposit} data and link with Genesys accessions. The primary key for {@link SvalbardDeposit} is the <code>sgsv_id</code> as provided by
* NordGen.
*
* Any existing SGSV records are first deleted. Inserted and linked with accessions in this method.
*
......@@ -1180,7 +1175,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
final BufferedWriter osw = new BufferedWriter(new OutputStreamWriter(zos));
osw.write("<?xml version='1.0' encoding='utf-8'?>\n");
osw.write(
"<archive xmlns=\"http://rs.tdwg.org/dwc/text/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://rs.tdwg.org/dwc/text/ http://rs.tdwg.org/dwc/text/tdwg_dwc_text.xsd\">\n");
"<archive xmlns=\"http://rs.tdwg.org/dwc/text/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://rs.tdwg.org/dwc/text/ http://rs.tdwg.org/dwc/text/tdwg_dwc_text.xsd\">\n");
osw.write("<core encoding=\"UTF-8\" fieldsTerminatedBy=\",\" linesTerminatedBy=\"\\n\" fieldsEnclosedBy=\"&quot;\" ignoreHeaderLines=\"0\">\n");
osw.write("\t<files><location>core.csv</location></files>\n");
osw.write("\t<id index=\"0\" />\n");
......@@ -1276,8 +1271,8 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
private void writeAccessionsCore(final AppliedFilters filters, ZipOutputStream zos) throws IOException {
@SuppressWarnings("resource")
final CSVWriter csv = new CSVWriter(new BufferedWriter(new OutputStreamWriter(zos)), ',', '"', '\\', "\n");
csv.writeNext(new String[] { "genesysId", "uuid", "instCode", "acceNumb", "genus", "species", "fullTaxa", "orgCty", "acqSrc", "acqDate", "mlsStat", "available", "historic", "storage",
"sampStat", "duplSite", "createdBy", "createdDate", "lastModifiedBy", "lastModifiedDate", "doi" });
csv.writeNext(new String[] { "genesysId", "uuid", "instCode", "acceNumb", "genus", "species", "fullTaxa", "orgCty", "acqSrc", "acqDate", "mlsStat", "available", "historic",
"storage", "sampStat", "duplSite", "createdBy", "createdDate", "lastModifiedBy", "lastModifiedDate", "doi" });
final ResultSetHelper csvResultsetHelper = new CSVResultSetHelper();
......@@ -1448,7 +1443,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
final BufferedWriter osw = new BufferedWriter(new OutputStreamWriter(zos));
osw.write("<?xml version='1.0' encoding='utf-8'?>\n");
osw.write(
"<archive xmlns=\"http://rs.tdwg.org/dwc/text/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://rs.tdwg.org/dwc/text/ http://rs.tdwg.org/dwc/text/tdwg_dwc_text.xsd\">\n");
"<archive xmlns=\"http://rs.tdwg.org/dwc/text/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://rs.tdwg.org/dwc/text/ http://rs.tdwg.org/dwc/text/tdwg_dwc_text.xsd\">\n");
osw.write("<core encoding=\"UTF-8\" fieldsTerminatedBy=\",\" linesTerminatedBy=\"\\n\" fieldsEnclosedBy=\"&quot;\" ignoreHeaderLines=\"0\">\n");
osw.write("\t<files><location>core.csv</location></files>\n");
osw.write("\t<id index=\"0\" />\n");
......
......@@ -212,7 +212,8 @@ public class AccessionController extends BaseController {
throw new ResourceNotFoundException();
}
try {
final Accession accession = genesysService.getAccession(holdingInstitute, accessionName, genus);
final String doi = null;
final Accession accession = genesysService.getAccession(holdingInstitute, doi, accessionName, genus);
if (accession == null) {
throw new ResourceNotFoundException();
} else {
......
......@@ -49,6 +49,8 @@ import org.genesys2.server.service.impl.SearchException;
import org.genesys2.server.servlet.controller.rest.model.AccessionHeaderJson;
import org.genesys2.server.servlet.controller.rest.model.AccessionNamesJson;
import org.genesys2.spring.ResourceNotFoundException;
import org.genesys2.util.DOIUtils;
import org.genesys2.util.InvalidDOIException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.CannotAcquireLockException;
import org.springframework.data.domain.Page;
......@@ -109,13 +111,13 @@ public class AccessionController extends RestController {
* @throws NonUniqueAccessionException
*/
@RequestMapping(value = "/exists/{instCode}/{genus:.+}", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody boolean exists(@PathVariable("instCode") String instCode, @PathVariable("genus") String genus,
@RequestParam("acceNumb") String acceNumb) throws NonUniqueAccessionException {
public @ResponseBody boolean exists(@PathVariable("instCode") String instCode, @PathVariable("genus") String genus, @RequestParam("acceNumb") String acceNumb) throws NonUniqueAccessionException {
if (LOG.isDebugEnabled()) {
LOG.debug("Checking if accn exists " + instCode + "." + acceNumb + " genus=" + genus);
}
final Accession accession = genesysService.getAccession(instCode, acceNumb, genus);
final String doi = null;
final Accession accession = genesysService.getAccession(instCode, doi, acceNumb, genus);
if (accession == null) {
LOG.warn("No accession " + instCode + "." + acceNumb + " genus=" + genus);
......@@ -195,8 +197,7 @@ public class AccessionController extends RestController {
* @throws RESTApiException
*/
@RequestMapping(value = "/{instCode}/upsert", method = { RequestMethod.POST, RequestMethod.PUT }, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody Object upsertInstituteAccession(@PathVariable("instCode") String instCode, @RequestBody String content)
throws JsonProcessingException, IOException, RESTApiException {
public @ResponseBody Object upsertInstituteAccession(@PathVariable("instCode") String instCode, @RequestBody String content) throws JsonProcessingException, IOException, RESTApiException {
// User's permission to WRITE to this WIEWS institute are checked in
// BatchRESTService.
......@@ -210,18 +211,26 @@ public class AccessionController extends RestController {
if (json.isArray()) {
for (final JsonNode j : json) {
final AccessionHeaderJson dataJson = readAid3(j);
if (!instCode.equals(dataJson.instCode)) {
throw new RuntimeException("Accession does not belong to instCode=" + instCode + " acn=" + dataJson);
try {
final AccessionHeaderJson dataJson = readAid3(j);
if (!instCode.equals(dataJson.instCode)) {
throw new RuntimeException("Accession does not belong to instCode=" + instCode + " acn=" + dataJson);
}
batch.put(dataJson, (ObjectNode) j);
} catch (InvalidDOIException e) {
throw new RESTApiException("Invalid DOI", e);
}
batch.put(dataJson, (ObjectNode) j);
}
} else {
final AccessionHeaderJson dataJson = readAid3(json);
if (!instCode.equals(dataJson.instCode)) {
throw new RuntimeException("Accession does not belong to instCode=" + instCode + " acn=" + dataJson);
try {
final AccessionHeaderJson dataJson = readAid3(json);
if (!instCode.equals(dataJson.instCode)) {
throw new RuntimeException("Accession does not belong to instCode=" + instCode + " acn=" + dataJson);
}
batch.put(dataJson, (ObjectNode) json);
} catch (InvalidDOIException e) {
throw new RESTApiException("Invalid DOI", e);
}
batch.put(dataJson, (ObjectNode) json);
}
Throwable cause = null;
......@@ -295,10 +304,8 @@ public class AccessionController extends RestController {
* @throws IOException
* @throws JsonProcessingException
*/
@RequestMapping(value = "/{instCode}/names", method = { RequestMethod.POST, RequestMethod.PUT }, consumes = {
MediaType.APPLICATION_JSON_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody List<AccessionOpResponse> upsertAccessionNames(@PathVariable("instCode") String instCode, @RequestBody List<AccessionNamesJson> batch)
throws RESTApiException {
@RequestMapping(value = "/{instCode}/names", method = { RequestMethod.POST, RequestMethod.PUT }, consumes = { MediaType.APPLICATION_JSON_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody List<AccessionOpResponse> upsertAccessionNames(@PathVariable("instCode") String instCode, @RequestBody List<AccessionNamesJson> batch) throws RESTApiException {
// User's permission to WRITE to this WIEWS institute are checked in
// BatchRESTService.
final FaoInstitute institute = instituteService.getInstitute(instCode);
......@@ -357,10 +364,9 @@ public class AccessionController extends RestController {
* @throws IOException
* @throws JsonProcessingException
*/
@RequestMapping(value = "/{instCode}/delete-named", method = { RequestMethod.POST, RequestMethod.PUT }, consumes = {
MediaType.APPLICATION_JSON_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody List<AccessionOpResponse> deleteAccessions(@PathVariable("instCode") String instCode, @RequestBody List<AccessionHeaderJson> batch)
throws RESTApiException {
@RequestMapping(value = "/{instCode}/delete-named", method = { RequestMethod.POST, RequestMethod.PUT }, consumes = { MediaType.APPLICATION_JSON_VALUE }, produces = {
MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody List<AccessionOpResponse> deleteAccessions(@PathVariable("instCode") String instCode, @RequestBody List<AccessionHeaderJson> batch) throws RESTApiException {
// User's permission to WRITE to this WIEWS institute are checked in
// BatchRESTService.
final FaoInstitute institute = instituteService.getInstitute(instCode);
......@@ -422,8 +428,7 @@ public class AccessionController extends RestController {
* @throws IOException
* @throws JsonProcessingException
*/
@RequestMapping(value = "/{instCode}/delete", method = { RequestMethod.POST }, consumes = { MediaType.APPLICATION_JSON_VALUE }, produces = {
MediaType.APPLICATION_JSON_VALUE })
@RequestMapping(value = "/{instCode}/delete", method = { RequestMethod.POST }, consumes = { MediaType.APPLICATION_JSON_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody int deleteAccessionsById(@PathVariable("instCode") String instCode, @RequestBody List<Long> batch) throws RESTApiException {
// User's permission to WRITE to this WIEWS institute are checked in
// BatchRESTService.
......@@ -445,8 +450,7 @@ public class AccessionController extends RestController {
// FIXME Not using institute...
@RequestMapping(value = "/{instCode}/list", method = { RequestMethod.GET }, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody Page<AccessionDetails> list(@PathVariable("instCode") String instCode, @RequestParam("page") int page,
@RequestParam("query") String query) throws SearchException {
public @ResponseBody Page<AccessionDetails> list(@PathVariable("instCode") String instCode, @RequestParam("page") int page, @RequestParam("query") String query) throws SearchException {
FaoInstitute institute = instituteService.getInstitute(instCode);
if (institute == null) {
throw new ResourceNotFoundException();
......@@ -484,8 +488,7 @@ public class AccessionController extends RestController {
LOG.debug(appliedFilters.toString());
}
Page<Accession> accessions = filterService.listAccessions(appliedFilters,
new PageRequest(jsonData.startAt - 1, Integer.min(jsonData.maxRecords, maxPageSize), new Sort("acceNumb")));
Page<Accession> accessions = filterService.listAccessions(appliedFilters, new PageRequest(jsonData.startAt - 1, Integer.min(jsonData.maxRecords, maxPageSize), new Sort("acceNumb")));
return accessions;
}
......@@ -496,9 +499,15 @@ public class AccessionController extends RestController {
public String otherOptions;
}
private AccessionHeaderJson readAid3(JsonNode json) {
private AccessionHeaderJson readAid3(JsonNode json) throws InvalidDOIException {
final AccessionHeaderJson dataJson = new AccessionHeaderJson();
dataJson.doi = json.has(Api1Constants.Accession.DOI) ? json.get(Api1Constants.Accession.DOI).textValue() : null;
if (dataJson.doi != null) {
DOIUtils.validateDoi(dataJson.doi);
}
dataJson.instCode = json.has(Api1Constants.Accession.INSTCODE) ? json.get(Api1Constants.Accession.INSTCODE).textValue() : null;
dataJson.acceNumb = json.has(Api1Constants.Accession.ACCENUMB) ? json.get(Api1Constants.Accession.ACCENUMB).textValue() : null;
dataJson.genus = json.has(Api1Constants.Accession.GENUS) ? json.get(Api1Constants.Accession.GENUS).textValue() : null;
......
......@@ -219,6 +219,8 @@ public class DatasetController extends RestController {
if (Api1Constants.Accession.INSTCODE.equals(key)) {
dataJson.instCode = value.asText();
} else if (Api1Constants.Accession.DOI.equals(key)) {
dataJson.doi = value.asText();
} else if (Api1Constants.Accession.ACCENUMB.equals(key)) {
dataJson.acceNumb = value.asText();
} else if (Api1Constants.Accession.GENUS.equals(key)) {
......@@ -270,6 +272,7 @@ public class DatasetController extends RestController {
public static class DataJson implements AccessionIdentifier3 {
public String instCode;
public String doi;
public String acceNumb;
public String genus;
private final Map<Long, List<Object>> methodValues = new HashMap<Long, List<Object>>();
......@@ -292,7 +295,12 @@ public class DatasetController extends RestController {
}
@Override
public String getAccessionName() {
public String getDoi() {
return doi;
}
@Override
public String getAccessionNumber() {
return acceNumb;
}
......@@ -305,6 +313,7 @@ public class DatasetController extends RestController {
public String toString() {
return MessageFormat.format("AID3 instCode={0} acceNumb={1} genus={2}", instCode, acceNumb, genus);
}
}
public static class MetadataJson {
......
......@@ -21,17 +21,23 @@ import java.text.MessageFormat;
import org.genesys2.server.model.impl.AccessionIdentifier3;
public class AccessionHeaderJson implements AccessionIdentifier3 {
public String doi;
public String instCode;
public String acceNumb;
public String genus;
@Override
public String getDoi() {
return doi;
}
@Override
public String getHoldingInstitute() {
return instCode;
}
@Override
public String getAccessionName() {
public String getAccessionNumber() {
return acceNumb;
}
......@@ -42,6 +48,6 @@ public class AccessionHeaderJson implements AccessionIdentifier3 {
@Override
public String toString() {
return MessageFormat.format("AID3 instCode={0} acceNumb={1} genus={2}", instCode, acceNumb, genus);
return MessageFormat.format("AID3 doi={0} instCode={1} acceNumb={2} genus={3}", doi, instCode, acceNumb, genus);
}
}
/*
* Copyright 2017 Global Crop Diversity Trust