Search in sources :

Example 66 with Cacheable

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;
}
Also used : Address(org.orcid.jaxb.model.v3.dev1.record.Address) AddressEntity(org.orcid.persistence.jpa.entities.AddressEntity) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 67 with Cacheable

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) ClassPathResource(org.springframework.core.io.ClassPathResource) Cacheable(org.springframework.cache.annotation.Cacheable) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute)

Example 68 with Cacheable

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;
}
Also used : ChromosomeNotFoundException(org.nextprot.api.commons.exception.ChromosomeNotFoundException) EntryReport(org.nextprot.api.core.domain.EntryReport) ChromosomeReport(org.nextprot.api.core.domain.ChromosomeReport) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 69 with Cacheable

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();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Isoform(org.nextprot.api.core.domain.Isoform) IsoformSpecificity(org.nextprot.api.core.domain.IsoformSpecificity) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 70 with Cacheable

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;
}
Also used : EntityName(org.nextprot.api.core.domain.EntityName) Overview(org.nextprot.api.core.domain.Overview) History(org.nextprot.api.core.domain.Overview.History) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

Cacheable (org.springframework.cache.annotation.Cacheable)94 HashMap (java.util.HashMap)17 ArrayList (java.util.ArrayList)16 Query (javax.persistence.Query)11 HashSet (java.util.HashSet)10 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)7 LinkedHashMap (java.util.LinkedHashMap)6 NextProtException (org.nextprot.api.commons.exception.NextProtException)6 AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)5 IOException (java.io.IOException)5 List (java.util.List)5 Set (java.util.Set)5 TypedQuery (javax.persistence.TypedQuery)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4 Workbook (org.apache.poi.ss.usermodel.Workbook)4 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)3 Region (com.sequenceiq.cloudbreak.cloud.model.Region)3 VmType (com.sequenceiq.cloudbreak.cloud.model.VmType)3 Application (ai.elimu.model.admin.Application)2