Commit 9b1fc4fe authored by Matija Obreza's avatar Matija Obreza
Browse files

Evict "statistics" cache on update

parent e60a4093
......@@ -90,6 +90,7 @@ import org.genesys2.server.service.TaxonomyService;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.genesys2.spring.SecurityContextUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
......@@ -105,8 +106,6 @@ import au.com.bytecode.opencsv.CSVWriter;
import au.com.bytecode.opencsv.ResultSetHelper;
import au.com.bytecode.opencsv.ResultSetHelperService;
import com.fasterxml.jackson.databind.ObjectMapper;
@Service
@Transactional(readOnly = true)
public class GenesysServiceImpl implements GenesysService, DatasetService {
......@@ -159,8 +158,6 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Autowired
private AccessionRemarkRepository accessionRemarkRepository;
private final ObjectMapper mapper = new ObjectMapper();
@Autowired
private CropService cropService;
......@@ -523,6 +520,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
public void updateAccessionCountryRefs() {
genesysLowlevelRepository.updateCountryRefs();
}
......@@ -530,12 +528,14 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
public void updateAccessionInstitueRefs() {
genesysLowlevelRepository.updateFaoInstituteRefs();
}
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
public void updateAccessionCount(FaoInstitute institute) {
long accessionCount = accessionRepository.countByInstitute(institute);
institute.setAccessionCount(accessionCount);
......@@ -544,6 +544,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
public void setInSvalbard(List<Accession> matching) {
if (matching.size() > 0) {
accessionRepository.setInSvalbard(matching);
......@@ -556,12 +557,14 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Deprecated
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
public void addAccessions(List<Accession> accessions) {
accessionRepository.save(accessions);
}
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
public List<Accession> saveAccessions(FaoInstitute institute, List<Accession> accessions) {
if (LOG.isDebugEnabled()) {
LOG.debug("Saving " + accessions.size() + " accessions");
......@@ -573,6 +576,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
public List<Accession> saveAccession(Accession... accession) {
List<Accession> list = new ArrayList<Accession>();
for (final Accession a : accession) {
......@@ -587,6 +591,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#institute, 'DELETE') or hasPermission(#institute, 'MANAGE')")
@CacheEvict(value = "statistics", allEntries = true)
public List<Accession> removeAccessions(FaoInstitute institute, List<Accession> toDelete) {
if (toDelete.size() > 0) {
final Set<Long> accessionIds = new HashSet<Long>();
......@@ -619,6 +624,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
// Worker threads don't carry this information
// @PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
public List<SvalbardData> saveSvalbards(List<SvalbardData> svalbards) {
svalbardRepository.save(svalbards);
return svalbards;
......@@ -626,6 +632,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
public List<AccessionCollect> saveCollecting(List<AccessionCollect> all) {
accessionCollectRepository.save(all);
return all;
......@@ -633,6 +640,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
public List<AccessionCollect> removeCollecting(List<AccessionCollect> all) {
accessionCollectRepository.delete(all);
return all;
......@@ -640,6 +648,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
public List<AccessionGeo> saveGeo(List<AccessionGeo> all) {
accessionGeoRepository.save(all);
return all;
......@@ -647,6 +656,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
public List<AccessionGeo> removeGeo(List<AccessionGeo> all) {
accessionGeoRepository.delete(all);
return all;
......@@ -654,6 +664,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
public List<AccessionBreeding> saveBreeding(List<AccessionBreeding> all) {
accessionBreedingRepository.save(all);
return all;
......@@ -661,6 +672,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
public List<AccessionBreeding> removeBreeding(List<AccessionBreeding> all) {
accessionBreedingRepository.delete(all);
return all;
......@@ -668,6 +680,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
public List<AccessionExchange> saveExchange(List<AccessionExchange> all) {
accessionExchangeRepository.save(all);
return all;
......@@ -675,6 +688,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
public List<AccessionExchange> removeExchange(List<AccessionExchange> all) {
accessionExchangeRepository.delete(all);
return all;
......@@ -682,6 +696,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
public List<AccessionRemark> saveRemarks(List<AccessionRemark> toSaveRemarks) {
accessionRemarkRepository.save(toSaveRemarks);
return toSaveRemarks;
......@@ -689,6 +704,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
public List<AccessionRemark> removeRemarks(List<AccessionRemark> toRemoveRemarks) {
accessionRemarkRepository.delete(toRemoveRemarks);
return toRemoveRemarks;
......@@ -729,6 +745,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#institute, 'WRITE') or hasPermission(#institute, 'CREATE')")
@CacheEvict(value = "statistics", allEntries = true)
public Metadata addDataset(FaoInstitute institute, String title, String description) {
final Metadata metadata = new Metadata();
metadata.setInstituteCode(institute.getCode());
......@@ -756,6 +773,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#metadata, 'WRITE')")
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
public void upsertAccessionData(Metadata metadata, Accession accession, Map<Long, List<Object>> methodValues) {
// // Load all existing records for metadata+accession
// List<AccessionTrait> existingEntries =
......@@ -1204,12 +1222,14 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR')")
@CacheEvict(value = "statistics", allEntries = true)
public void refreshMetadataMethods() {
genesysLowlevelRepository.refreshMetadataMethods();
}
@Override
@Transactional
@CacheEvict(value = "statistics", allEntries = true)
public List<AccessionAlias> saveAliases(List<AccessionAlias> aliases) {
if (aliases.size() > 0) {
accessionAliasRepository.save(aliases);
......@@ -1219,6 +1239,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional
@CacheEvict(value = "statistics", allEntries = true)
public List<AccessionAlias> removeAliases(List<AccessionAlias> aliases) {
if (aliases.size() > 0) {
accessionAliasRepository.delete(aliases);
......@@ -1229,6 +1250,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR')")
@CacheEvict(value = "statistics", allEntries = true)
public void upsertAliases(long accessionId, String acceNames, String otherIds) {
final Accession accession = getAccession(accessionId);
if (accession == null) {
......@@ -1320,6 +1342,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional
@CacheEvict(value = "statistics", allEntries = true)
public Set<Long> removeAliases(Set<Long> toRemove) {
for (final Long id : toRemove) {
this.accessionAliasRepository.delete(id);
......
......@@ -39,6 +39,7 @@ import org.genesys2.server.persistence.domain.ITPGRFAStatusRepository;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.GeoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -197,6 +198,7 @@ public class GeoServiceImpl implements GeoService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
public void updateCountryData() throws IOException {
// update current countries
updateGeoNamesCountries();
......
......@@ -41,6 +41,7 @@ import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.InstituteService;
import org.genesys2.spring.SecurityContextUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
......@@ -125,6 +126,7 @@ public class InstituteServiceImpl implements InstituteService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
public void update(Collection<FaoInstitute> institutes) {
instituteRepository.save(institutes);
}
......@@ -197,6 +199,7 @@ public class InstituteServiceImpl implements InstituteService {
@Override
@PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
public void updateCountryRefs() {
genesysLowlevelRepository.updateFaoInstituteCountries();
}
......@@ -212,6 +215,7 @@ public class InstituteServiceImpl implements InstituteService {
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR')")
@CacheEvict(value = "statistics", allEntries = true)
public void delete(String instCode) {
final FaoInstitute institute = getInstitute(instCode);
if (institute != null) {
......
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