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