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

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);
......
......@@ -16,7 +16,7 @@
package org.genesys2.server.service.impl;
import static org.genesys2.util.NumberUtils.*;
import static org.genesys2.util.NumberUtils.areEqual;
import java.util.ArrayList;
import java.util.Date;
......@@ -26,6 +26,10 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.Predicate;
import org.apache.commons.lang.StringUtils;
......@@ -46,7 +50,7 @@ import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.json.Api1Constants;
import org.genesys2.server.persistence.domain.AccessionCustomRepository;
import org.genesys2.server.persistence.domain.AccessionRepository;
import org.genesys2.server.service.AccessionOpResponse;
import org.genesys2.server.service.AccessionOpResponse.UpsertResult;
import org.genesys2.server.service.BatchRESTService;
......@@ -60,15 +64,12 @@ import org.genesys2.server.servlet.controller.rest.PleaseRetryException;
import org.genesys2.server.servlet.controller.rest.model.AccessionAliasJson;
import org.genesys2.server.servlet.controller.rest.model.AccessionHeaderJson;
import org.genesys2.server.servlet.controller.rest.model.AccessionNamesJson;
import org.genesys2.util.DOIUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
@Service
public class BatchRESTServiceImpl implements BatchRESTService {
......@@ -93,11 +94,11 @@ public class BatchRESTServiceImpl implements BatchRESTService {
InstituteService instituteService;
@Autowired
AccessionCustomRepository accessionCustomRepository;
AccessionRepository accessionRepository;
@Autowired
private TaxonomyManager taxonomyManager;
@Override
// Read-only, everything happens in manager
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#institute, 'WRITE') or hasPermission(#institute, 'CREATE')")
......@@ -131,21 +132,17 @@ public class BatchRESTServiceImpl implements BatchRESTService {
Taxonomy2 ensuredTaxonomy = null;
try {
ensuredTaxonomy = taxonomyService.find(current.getGenus(), current.getSpecies(), current.getSpAuthor(), current.getSubtaxa(),
current.getSubtAuthor());
ensuredTaxonomy = taxonomyService.find(current.getGenus(), current.getSpecies(), current.getSpAuthor(), current.getSubtaxa(), current.getSubtAuthor());
} catch (Throwable e) {
LOG.warn("*** lower(t.genus)=lower(" + current.getGenus() + ") and lower(t.species)=lower(" + current.getSpecies()
+ ") and lower(t.spauthor)=lower(" + current.getSpAuthor() + ") and lower(t.subtaxa)=lower(" + current.getSubtaxa()
+ ") and lower(subtauthor)=lower(" + current.getSubtAuthor() + ")");
LOG.warn("*** lower(t.genus)=lower(" + current.getGenus() + ") and lower(t.species)=lower(" + current.getSpecies() + ") and lower(t.spauthor)=lower(" + current
.getSpAuthor() + ") and lower(t.subtaxa)=lower(" + current.getSubtaxa() + ") and lower(subtauthor)=lower(" + current.getSubtAuthor() + ")");
}
if (ensuredTaxonomy == null) {
LOG.warn("Adding new taxonomy: " + current);
ensuredTaxonomy = taxonomyManager.ensureTaxonomy2(current.getGenus(), current.getSpecies(), current.getSpAuthor(), current.getSubtaxa(),
current.getSubtAuthor());
ensuredTaxonomy = taxonomyManager.ensureTaxonomy2(current.getGenus(), current.getSpecies(), current.getSpAuthor(), current.getSubtaxa(), current.getSubtAuthor());
LOG.info("Registered: " + ensuredTaxonomy);
ensuredTaxonomy = taxonomyService.find(current.getGenus(), current.getSpecies(), current.getSpAuthor(), current.getSubtaxa(),
current.getSubtAuthor());
ensuredTaxonomy = taxonomyService.find(current.getGenus(), current.getSpecies(), current.getSpAuthor(), current.getSubtaxa(), current.getSubtAuthor());
if (ensuredTaxonomy == null) {
throw new PleaseRetryException("Something is wrong with taxonomyManager for " + current.toString());
......@@ -197,17 +194,10 @@ public class BatchRESTServiceImpl implements BatchRESTService {
final Map<AccessionId, ArrayNode> donorNumbs = new HashMap<AccessionId, ArrayNode>();
final Map<AccessionId, ArrayNode> collNumbs = new HashMap<AccessionId, ArrayNode>();
List<String> acceNumbs = new ArrayList<String>();
List<String> genera = new ArrayList<String>();
for (AccessionHeaderJson dataJson : batch.keySet()) {
acceNumbs.add(dataJson.acceNumb);
genera.add(dataJson.genus);
}
List<Accession> loaded = null;
try {
loaded = accessionCustomRepository.find(institute, acceNumbs, genera);
loaded = accessionRepository.find(institute, batch.keySet());
} catch (NonUniqueAccessionException e) {
LOG.warn(e.getMessage());
throw new RESTApiException(e.getMessage());
......@@ -226,10 +216,18 @@ public class BatchRESTServiceImpl implements BatchRESTService {
throw new RESTApiException("Accession does not belong to instCode=" + institute.getCode() + " acn=" + dataJson);
}
Accession accession = loaded.stream()
.filter(a -> useUniqueAcceNumbs ? (a.getAccessionName().equalsIgnoreCase(dataJson.acceNumb))
: (a.getAccessionName().equalsIgnoreCase(dataJson.acceNumb) && a.getTaxonomy().getGenus().equalsIgnoreCase(dataJson.genus)))
.findFirst().orElse(null);
Accession accession = loaded.stream().filter(a -> {
if (StringUtils.isNotBlank(a.getDoi())) {
if (a.getDoi().equals(dataJson.doi))
return true;
}
if (useUniqueAcceNumbs) {
return a.getAccessionName().equalsIgnoreCase(dataJson.acceNumb);
} else {
return a.getAccessionName().equalsIgnoreCase(dataJson.acceNumb) && a.getTaxonomy().getGenus().equalsIgnoreCase(dataJson.genus);
}
}).findFirst().orElse(null);
final ObjectNode accnJson = batch.get(dataJson);
......@@ -241,6 +239,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
accession.setAccessionId(new AccessionId());
accession.setInstitute(institute);
accession.setDoi(dataJson.doi);
accession.setAccessionName(dataJson.acceNumb);
if (accnJson.get(Api1Constants.Accession.GENUS) == null && accnJson.get(Api1Constants.Accession.GENUS_NEW) == null) {
......@@ -257,14 +256,18 @@ public class BatchRESTServiceImpl implements BatchRESTService {
upsertResult.setUUID(accession.getUuid());
}
if (accession.getAccessionId().isPersisted() || useUniqueAcceNumbs && accnJson.get(Api1Constants.Accession.GENUS) != null
|| accnJson.get(Api1Constants.Accession.GENUS_NEW) != null || accnJson.get(Api1Constants.Accession.SPECIES) != null
|| accnJson.get(Api1Constants.Accession.SPAUTHOR) != null || accnJson.get(Api1Constants.Accession.SUBTAXA) != null
|| accnJson.get(Api1Constants.Accession.SUBTAUTHOR) != null) {
if (accession.getAccessionId().isPersisted() || useUniqueAcceNumbs && accnJson.get(Api1Constants.Accession.GENUS) != null || accnJson.get(
Api1Constants.Accession.GENUS_NEW) != null || accnJson.get(Api1Constants.Accession.SPECIES) != null || accnJson.get(Api1Constants.Accession.SPAUTHOR) != null || accnJson
.get(Api1Constants.Accession.SUBTAXA) != null || accnJson.get(Api1Constants.Accession.SUBTAUTHOR) != null) {
updateTaxonomy(accession, accnJson);
}
updateDoi(accession, accnJson.get(Api1Constants.Accession.DOI));
if (accession.getDoi()!=null) {
// Update ACCENUMB if DOI is provided
accession.setAccessionName(dataJson.acceNumb);
}
updateCrop(accession, accnJson.get(Api1Constants.Accession.CROPNAME));
updateAcceNumb(accession, accnJson.get(Api1Constants.Accession.ACCENUMB_NEW));
updateOrgCty(accession, accnJson.get(Api1Constants.Accession.ORIGCTY));
......@@ -468,8 +471,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
}
}
if (accnJson.has(Api1Constants.Accession.DONORCODE) || accnJson.has(Api1Constants.Accession.DONORNUMB)
|| accnJson.has(Api1Constants.Accession.DONORNAME)) {
if (accnJson.has(Api1Constants.Accession.DONORCODE) || accnJson.has(Api1Constants.Accession.DONORNUMB) || accnJson.has(Api1Constants.Accession.DONORNAME)) {
AccessionExchange accnExch = genesysService.listAccessionExchange(accession.getAccessionId());
if (accnExch == null) {
accnExch = new AccessionExchange();
......@@ -514,7 +516,6 @@ public class BatchRESTServiceImpl implements BatchRESTService {
upsertResponse.setResult(upsertResult);
}
List<Accession> savedData = null;
if (toSave.size() > 0) {
......@@ -524,8 +525,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
// Iterate savedData to extract UUIDs
upsertResponses.stream().forEach(response -> {
Accession accession = saved.stream().filter(a -> useUniqueAcceNumbs ? (a.getAccessionName().equalsIgnoreCase(response.getAcceNumb()))
: (a.getAccessionName().equalsIgnoreCase(response.getAcceNumb()) && a.getTaxonomy().getGenus().equalsIgnoreCase(response.getGenus())))
.findFirst().orElse(null);
: (a.getAccessionName().equalsIgnoreCase(response.getAcceNumb()) && a.getTaxonomy().getGenus().equalsIgnoreCase(response.getGenus()))).findFirst().orElse(null);
UpsertResult result = response.getResult();
if (accession != null) {
......@@ -537,8 +537,8 @@ public class BatchRESTServiceImpl implements BatchRESTService {
result.setUUID(accession.getUuid());
}
});
savedData=saved;
savedData = saved;
}
if (toSaveColl.size() > 0) {
......@@ -582,13 +582,52 @@ public class BatchRESTServiceImpl implements BatchRESTService {
updateAccessionAliases(collNumbs, AliasType.COLLNUMB, false);
LOG.info("Done saving data");
// Update PDCI
genesysService.updatePDCI(savedData.stream().map(a -> a.getId()).collect(Collectors.toSet()));
return upsertResponses;
}
/**
* Update accession DOI in Genesys. If DOI exists in Genesys, it must be provided by the client and must match current value. If DOI does not exist in Genesys,
* it will be registered.
*
* @param accession
* @param value
* @return
* @throws RESTApiException
*/
private boolean updateDoi(AccessionData accession, JsonNode value) throws RESTApiException {
if (accession.getDoi() == null) {
// Genesys does not have DOI for the accession
if (value != null) {
if (value.isTextual()) {
if (DOIUtils.isValidDoi(value.textValue())) {
accession.setDoi(value.textValue());
return true;
} else {
throw new RESTApiException("Invalid DOI value " + value.textValue());
}
} else {
throw new RESTApiDataTypeException("DOI must be a string.");
}
}
return false;
} else {
// Genesys has DOI for the accession
if (value == null || !value.isTextual()) {
throw new RESTApiException("DOI must be resubmitted for accession with DOI " + accession.getDoi() + " ACCENUMB=" + accession.getAccessionName());
} else {
if (StringUtils.equals(accession.getDoi(), value.textValue())) {
return false;
} else {
throw new RESTApiException("Provided DOI does not match existing DOI " + accession.getDoi() + " ACCENUMB=" + accession.getAccessionName());
}
}
}
}
private boolean updateCrop(Accession accession, JsonNode value) throws RESTApiDataTypeException {
if (value != null) {
if (value.isNull()) {
......@@ -738,7 +777,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
private boolean updateAcceNumb(AccessionData accession, JsonNode value) throws RESTApiDataTypeException, RESTApiException {
if (value != null) {
// Rename is possible only if accession exists
if (! accession.getAccessionId().isPersisted()) {
if (!accession.getAccessionId().isPersisted()) {
throw new RESTApiException("Cannot rename a new accession entry");
}
......@@ -787,10 +826,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
private boolean updateUuid(AccessionData accession, JsonNode value) throws RESTApiValueException {
// We don't allow UUID updates
/*
* if (value != null) { final UUID uuid = value.isNull() ? null :
* UUID.fromString(value.textValue());
*
* if (accession.getUuid() == null && uuid != null) {
* if (value != null) { final UUID uuid = value.isNull() ? null : UUID.fromString(value.textValue()); if (accession.getUuid() == null && uuid != null) {
* accession.getAccessionId().setUuid(uuid); return true; } }
*/
// No change
......@@ -827,12 +863,10 @@ public class BatchRESTServiceImpl implements BatchRESTService {
Taxonomy2 ensuredTaxonomy = null;
try {
ensuredTaxonomy = taxonomyService.find(current.getGenus(), current.getSpecies(), current.getSpAuthor(), current.getSubtaxa(),
current.getSubtAuthor());
ensuredTaxonomy = taxonomyService.find(current.getGenus(), current.getSpecies(), current.getSpAuthor(), current.getSubtaxa(), current.getSubtAuthor());
} catch (Throwable e) {
LOG.warn("*** lower(t.genus)=lower(" + current.getGenus() + ") and lower(t.species)=lower(" + current.getSpecies()
+ ") and lower(t.spauthor)=lower(" + current.getSpAuthor() + ") and lower(t.subtaxa)=lower(" + current.getSubtaxa()
+ ") and lower(subtauthor)=lower(" + current.getSubtAuthor() + ")");
LOG.warn("*** lower(t.genus)=lower(" + current.getGenus() + ") and lower(t.species)=lower(" + current.getSpecies() + ") and lower(t.spauthor)=lower(" + current.getSpAuthor()
+ ") and lower(t.subtaxa)=lower(" + current.getSubtaxa() + ") and lower(subtauthor)=lower(" + current.getSubtAuthor() + ")");
}
if (ensuredTaxonomy == null) {
......@@ -973,7 +1007,6 @@ public class BatchRESTServiceImpl implements BatchRESTService {
public List<AccessionOpResponse> upsertAccessionNames(FaoInstitute institute, List<AccessionNamesJson> batch) throws RESTApiException {
LOG.info("Batch processing " + batch.size() + " entries for " + institute);
final boolean useUniqueAcceNumbs = institute.hasUniqueAcceNumbs();
final List<AccessionOpResponse> upsertResponses = new ArrayList<AccessionOpResponse>();
final List<AccessionAlias> toSave = new ArrayList<AccessionAlias>();
......@@ -990,11 +1023,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
Accession accession = null;
try {
if (useUniqueAcceNumbs) {
accession = genesysService.getAccession(institute.getCode(), dataJson.acceNumb);
} else {
accession = genesysService.getAccession(institute.getCode(), dataJson.acceNumb, dataJson.genus);
}
accession = genesysService.getAccession(dataJson);
} catch (NonUniqueAccessionException e) {
LOG.warn(e.getMessage());
throw new RESTApiException(e.getMessage());
......@@ -1047,6 +1076,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
// Find aliases to remove
for (final AccessionAlias aa : existingAliases) {
if (null == CollectionUtils.find(aliases, new Predicate<AccessionAliasJson>() {
@Override
public boolean evaluate(AccessionAliasJson alias) {
return StringUtils.equals(alias.name, aa.getName());
......@@ -1056,7 +1086,9 @@ public class BatchRESTServiceImpl implements BatchRESTService {
}
}
// Add or update
for (final AccessionAliasJson aa : aliases) {
for (
final AccessionAliasJson aa : aliases) {
AccessionAlias accessionAlias = CollectionUtils.find(existingAliases, new Predicate<AccessionAlias>() {
@Override
public boolean evaluate(AccessionAlias alias) {
......@@ -1086,7 +1118,6 @@ public class BatchRESTServiceImpl implements BatchRESTService {
final List<AccessionOpResponse> upsertResponses = new ArrayList<AccessionOpResponse>();
final List<Accession> toDelete = new ArrayList<Accession>(batch.size());
final boolean useUniqueAcceNumbs = institute.hasUniqueAcceNumbs();
for (final AccessionHeaderJson dataJson : batch) {