Commit f7d23706 authored by Matija Obreza's avatar Matija Obreza

SGSVUpdate: include accession names by alias (TWN001)

parent d072460b
......@@ -151,4 +151,9 @@ public class AccessionAlias extends BusinessModel {
public void setUsedBy(String usedBy) {
this.usedBy = usedBy;
}
@Override
public String toString() {
return "name=" + name + " instCode=" + instCode + " type=" + aliasType;
}
}
......@@ -35,4 +35,7 @@ public interface AccessionAliasRepository extends JpaRepository<AccessionAlias,
@Modifying
@Query("delete from AccessionAlias aa where aa.accession in (from Accession a where a.id in ( :ids ))")
void deleteForAccessions(@Param("ids") Collection<Long> accessionIds);
@Query("select aa.accession from AccessionAlias aa where aa.usedBy=?1 and aa.name=?2 and aa.aliasType=?3 and aa.accession.institute.code=?1")
Accession findAccession(String instCode, String name, int aliasType);
}
......@@ -220,14 +220,30 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
final List<Accession> result = new ArrayList<Accession>(accns.size());
for (final AccessionIdentifier3 aid3 : accns) {
final Accession accn = accessionRepository.findOne(aid3.getHoldingInstitute(), aid3.getAccessionName(), aid3.getGenus());
// Including null's
result.add(accn);
if (accn == null) {
// FaoInstitute inst =
// instituteRepository.findByCode(aid3.getHoldingInstitute());
if (LOG.isDebugEnabled()) {
// Only log full miss
LOG.debug("No accession " + aid3);
if (accn != null) {
result.add(accn);
} else {
Accession accnByAlias = accessionAliasRepository.findAccession(aid3.getHoldingInstitute(), aid3.getAccessionName(),
AccessionAlias.AliasType.OTHERNUMB.getId());
if (accnByAlias != null) {
LOG.info("Found accession by alias " + accnByAlias);
// Genus must match
if (StringUtils.equalsIgnoreCase(aid3.getGenus(), accnByAlias.getTaxonomy().getGenus()))
result.add(accnByAlias);
else {
LOG.info("... but genus doesn't match");
result.add(null);
}
} else {
result.add(null);
if (LOG.isDebugEnabled()) {
// Only log full miss
LOG.debug("No accession " + aid3);
}
}
}
}
......
......@@ -141,7 +141,6 @@ public class SGSVUpdate {
void importSGSVStream(final InputStream str, final String source) throws IOException {
int counter = 0;
CSVReader reader = null;
try {
reader = new CSVReader(new BufferedReader(new InputStreamReader(str)), '\t', '"', false);
......@@ -167,6 +166,10 @@ public class SGSVUpdate {
}
}
if (line.length > SGSV_HEADERS.length) {
LOG.warn("Funny line length " + line);
}
bulk.add(line);
counter++;
......@@ -210,9 +213,10 @@ public class SGSVUpdate {
}
void workIt(final List<String[]> bulk) {
// Need copy!
final ArrayList<String[]> bulkCopy = new ArrayList<String[]>(bulk);
taskExecutor.execute(new Runnable() {
// Need copy!
final ArrayList<String[]> bulkCopy = new ArrayList<String[]>(bulk);
@Override
public void run() {
......@@ -277,37 +281,23 @@ public class SGSVUpdate {
final Accession accn = accessions.get(i);
final SGSVEntry entry = accns.get(i);
if (accn == null || entry == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("No such accession in the database. Skipping");
}
if (accn == null) {
LOG.debug("No such accession in the database. Skipping " + entry);
continue;
} else {
LOG.info("Updating " + accn);
}
if (accn.getAccessionName().equalsIgnoreCase(entry.acceNumb) && accn.getInstituteCode().equals(entry.instCode)) {
// NOTE Removed acceNumb check because of aliases
// if (accn.getAccessionName().equalsIgnoreCase(entry.acceNumb) &&
// accn.getInstituteCode().equals(entry.instCode)) {
if (accn.getInstituteCode().equals(entry.instCode)) {
if (!Boolean.TRUE.equals(accn.getInSvalbard())) {
accn.setInSvalbard(true);
updateAccession = true;
}
// // Doesn't have taxonomy due to no species
// if (accn.getTaxonomy() == null &&
// StringUtils.isNotBlank(entry.species)) {
// accn.setTaxonomy(taxonomyService.ensureTaxonomy(entry.genus,
// entry.species));
// updateAccession = true;
// }
//
// if (entry.origCty != null &&
// StringUtils.isBlank(accn.getOrigin()) &&
// !StringUtils.equals(accn.getOrigin(),
// entry.origCty)) {
// accn.setOrigin(entry.origCty);
// accn.setCountryOfOrigin(geoService.getCountry(entry.origCty));
// updateAccession = true;
// }
SvalbardData svalbardData = svalbardRepository.findOne(accn.getId());
if (svalbardData == null) {
svalbardData = new SvalbardData();
......
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