use of org.springframework.cache.annotation.Cacheable in project ORCID-Source by ORCID.
the class AddressManagerReadOnlyImpl method getPrimaryAddress.
@Override
@Cacheable(value = "primary-address", key = "#orcid.concat('-').concat(#lastModified)")
public Address getPrimaryAddress(String orcid, long lastModified) {
List<AddressEntity> addresses = addressDao.getAddresses(orcid, getLastModified(orcid));
Address address = null;
if (addresses != null) {
// Look for the address with the largest display index
for (AddressEntity entity : addresses) {
if (address == null || address.getDisplayIndex() < entity.getDisplayIndex()) {
address = adapter.toAddress(entity);
}
}
}
return address;
}
use of org.springframework.cache.annotation.Cacheable in project ORCID-Source by ORCID.
the class BaseController method getStaticCdnPath.
/**
* Return the path where the static content will be. If there is a cdn path
* configured, it will return the cdn path; if it is not a cdn path it will
* return a reference to the static folder "/static"
*
* @return the path to the CDN or the path to the local static content
*/
@ModelAttribute("staticCdn")
@Cacheable("staticContent")
public String getStaticCdnPath(HttpServletRequest request) {
if (StringUtils.isEmpty(this.cdnConfigFile)) {
return getStaticContentPath(request);
}
ClassPathResource configFile = new ClassPathResource(this.cdnConfigFile);
if (configFile.exists()) {
try (InputStream is = configFile.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
String uri = br.readLine();
if (uri != null) {
String releaseVersion = ReleaseNameUtils.getReleaseName();
if (!uri.contains(releaseVersion)) {
if (!uri.endsWith("/")) {
uri += '/';
}
uri += releaseVersion;
}
this.staticCdnPath = uri;
}
} catch (IOException e) {
e.printStackTrace();
}
}
if (StringUtils.isBlank(this.staticCdnPath))
return getStaticContentPath(request);
return staticCdnPath;
}
use of org.springframework.cache.annotation.Cacheable in project nextprot-api by calipho-sib.
the class ChromosomeReportServiceImpl method reportChromosome.
@Cacheable("chromosome-reports")
@Override
public ChromosomeReport reportChromosome(String chromosome) {
// TODO: if chromosome is not found throw an http error 404
if (!Chromosome.exists(chromosome)) {
throw new ChromosomeNotFoundException(chromosome);
}
ChromosomeReport report = new ChromosomeReport();
report.setDataRelease(releaseInfoService.findReleaseVersions().getDatabaseRelease());
List<String> allEntriesOnChromosome = masterIdentifierService.findUniqueNamesOfChromosome(chromosome);
List<EntryReport> entryReports = allEntriesOnChromosome.stream().map(entryAccession -> entryGeneReportService.reportEntry(entryAccession)).flatMap(Collection::stream).filter(er -> er.getChromosome().equals(chromosome)).sorted(EntryReport.newByChromosomalPositionComparator()).collect(Collectors.toList());
report.setEntryReports(entryReports);
ChromosomeReport.Summary summary = newSummary(chromosome, entryReports);
setByProteinEvidenceEntryCount(allEntriesOnChromosome, summary);
report.setSummary(summary);
return report;
}
use of org.springframework.cache.annotation.Cacheable in project nextprot-api by calipho-sib.
the class MasterIsoformMappingServiceImpl method findMasterIsoformMappingByEntryName.
@Override
@Cacheable("master-isoform-mapping")
public List<IsoformSpecificity> findMasterIsoformMappingByEntryName(String entryName) {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// build a map between isoform unique name and isoform main name
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
List<Isoform> isoforms = isoformService.findIsoformsByEntryName(entryName);
Map<String, String> unique2mainName = new HashMap<String, String>();
for (Isoform iso : isoforms) {
String mainName = iso.getMainEntityName().getValue();
unique2mainName.put(iso.getUniqueName(), mainName);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// group partial mappings obtained from DAO by isoform and set isoform name
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Map<String, IsoformSpecificity> map = new HashMap<String, IsoformSpecificity>();
List<IsoformSpecificity> specs = masterIsoformMappingDao.findIsoformMappingByMaster(entryName);
for (IsoformSpecificity tmpSpec : specs) {
String ac = tmpSpec.getIsoformAc();
if (!map.containsKey(ac))
map.put(ac, new IsoformSpecificity(null, ac));
IsoformSpecificity spec = map.get(ac);
// replace unique name with main name
spec.setIsoformMainName(unique2mainName.get(ac));
spec.addPosition(tmpSpec.getPositions().get(0));
}
List<IsoformSpecificity> list = new ArrayList<IsoformSpecificity>(map.values());
Collections.sort(list);
// returns a immutable list when the result is cacheable (this prevents modifying the cache, since the cache returns a reference) copy on read and copy on write is too much time consuming
return new ImmutableList.Builder<IsoformSpecificity>().addAll(list).build();
}
use of org.springframework.cache.annotation.Cacheable in project nextprot-api by calipho-sib.
the class OverviewServiceImpl method findOverviewByEntry.
@Override
@Cacheable("overview")
public Overview findOverviewByEntry(String uniqueName) {
Overview overview = new Overview();
List<History> history = this.historyDao.findHistoryByEntry(uniqueName);
if (history != null && history.size() != 0)
overview.setHistory(history.get(0));
List<EntityName> entityNames = this.entryNameDao.findNames(uniqueName);
entityNames.addAll(entryNameDao.findAlternativeChainNames(uniqueName));
setNamesInOverview(entityNames, overview);
overview.setFamilies(this.familyService.findFamilies(uniqueName));
overview.setIsoformNames(convertIsoNamestoOverviewName(isoformService.findIsoformsByEntryName(uniqueName)));
overview.setProteinExistences(proteinExistenceService.getProteinExistences(uniqueName));
return overview;
}
Aggregations