Commit 7f5bd8dc authored by Matija Obreza's avatar Matija Obreza

Fix: Update accession count on startup

parent 0a79d0b1
......@@ -34,6 +34,7 @@ import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.persistence.domain.AccessionRepository;
import org.genesys2.server.service.BatchRESTService;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.GeoRegionService;
import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.InstituteService;
......@@ -83,6 +84,9 @@ public class FirstRunListener extends RunAsAdminListener {
@Autowired
BatchRESTService batchService;
@Autowired
private GenesysService genesysService;
@Override
protected void init() throws Exception {
if (!createContent) {
......@@ -167,6 +171,7 @@ public class FirstRunListener extends RunAsAdminListener {
LOG.warn("Upserting " + batch.size() + " accession records for " + instCode);
batchService.ensureTaxonomies(institute, batch);
batchService.upsertAccessionData(institute, batch);
genesysService.updateAccessionCount(institute);
}
} catch (JsonParseException e) {
......
......@@ -151,7 +151,7 @@ public interface GenesysService {
List<Accession> saveAccessions(Iterable<Accession> accession);
void updateAccessionCount(FaoInstitute institute);
FaoInstitute updateAccessionCount(FaoInstitute institute);
List<SvalbardDeposit> getSvalbardData(AccessionId accession);
......
/**
* 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.
......@@ -12,7 +12,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
*/
package org.genesys2.server.service.impl;
......@@ -248,12 +248,12 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
return accessionRepository.countByHistoric(true);
}
@Override
public long countByCrop(final Crop crop) {
return accessionRepository.countByCrop(crop);
}
@Override
public long countByCrop(final Crop crop) {
return accessionRepository.countByCrop(crop);
}
@Override
@Override
public long countByInstitute(FaoInstitute institute) {
return accessionRepository.countByInstitute(institute);
}
......@@ -401,7 +401,8 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
if (all.accession.getCrop() != null) {
ad.crops(all.accession.getCrop().getShortName());
} else {
// Ignore taxonomy crops: ad.crops(cropService.getCrops(all.accession.getTaxonomy()));
// Ignore taxonomy crops:
// ad.crops(cropService.getCrops(all.accession.getTaxonomy()));
}
return ad;
}
......@@ -755,14 +756,15 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
}
@Override
@Transactional(readOnly = false)
@Transactional
// @CacheEvict(value = "statistics", allEntries = true)
public void updateAccessionCount(FaoInstitute institute) {
public FaoInstitute updateAccessionCount(FaoInstitute institute) {
if (institute == null)
return;
return institute;
long accessionCount = accessionRepository.countByInstitute(institute);
institute = instituteRepository.getOne(institute.getId());
institute.setAccessionCount(accessionCount);
instituteRepository.save(institute);
return instituteRepository.save(institute);
}
/**
......@@ -811,7 +813,8 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
public List<Accession> saveAccessions(Iterable<Accession> accessions) {
Set<FaoInstitute> institutes = new HashSet<FaoInstitute>();
for (Accession accession : accessions) {
// System.out.println("Saving " + accession + " STO=" + accession.getStoRage() + " ST=" +
// System.out.println("Saving " + accession + " STO=" + accession.getStoRage() +
// " ST=" +
// accession.getStorage());
institutes.add(accession.getInstitute());
}
......@@ -863,10 +866,12 @@ 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.
* Any existing SGSV records are first deleted. Inserted and linked with
* accessions in this method.
*
* @param svalbardDeposits
* @return
......@@ -897,7 +902,8 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
LOG.debug("Linked " + updatedCount + " accessions by alias in set " + sgsvIds);
}
// link indirectly where INSTCODE matches alternative sgsvCode, GENUS and ACCENUMB match
// link indirectly where INSTCODE matches alternative sgsvCode, GENUS and
// ACCENUMB match
updatedCount = svalbardRepository.linkInDirectly(sgsvIds);
if (updatedCount > 0 && LOG.isDebugEnabled()) {
LOG.debug("Linked " + updatedCount + " accessions using alternate code in set " + sgsvIds);
......
[{
"instCode": "PER001",
"doi": "10.0155/43X~",
"acceNumb": "CIP 102081.28",
"genus": "Solanum",
"cropName": "Sweetpotato",
......
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