Search in sources :

Example 41 with Cacheable

use of org.springframework.cache.annotation.Cacheable in project nextprot-api by calipho-sib.

the class SeoTagsServiceImpl method getNewsSeoTags.

@Override
@Cacheable(value = "seo-github-news")
public SeoTags getNewsSeoTags(String url) {
    String[] urlElements = RelativeUrlUtils.getPathElements(url);
    List<NextProtNews> allNews = gitHubService.getNews();
    if (urlElements.length > 1) {
        String pageUrl = urlElements[1];
        for (NextProtNews oneNews : allNews) {
            if (pageUrl.equals(oneNews.getUrl())) {
                return getOneNewsSeoTags(oneNews);
            }
        }
    } else {
        NextProtNews mostRecentNews = allNews.get(allNews.size() - 1);
        return getOneNewsSeoTags(mostRecentNews);
    }
    return null;
}
Also used : NextProtNews(org.nextprot.api.web.domain.NextProtNews) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 42 with Cacheable

use of org.springframework.cache.annotation.Cacheable in project cloudbreak by hortonworks.

the class ResourceDefinitionService method getResourceDefinition.

@Cacheable("resourceDefinitionCache")
public String getResourceDefinition(String cloudPlatform, String resource) {
    LOGGER.debug("Sending request for {} {} resource property definition", cloudPlatform, resource);
    CloudPlatformVariant platformVariant = new CloudPlatformVariant(Platform.platform(cloudPlatform), Variant.EMPTY);
    ResourceDefinitionRequest request = new ResourceDefinitionRequest(platformVariant, resource);
    eventBus.notify(request.selector(), eventFactory.createEvent(request));
    try {
        ResourceDefinitionResult result = request.await();
        LOGGER.info("Resource property definition: {}", result);
        return result.getDefinition();
    } catch (InterruptedException e) {
        LOGGER.error("Error while sending resource definition request", e);
        throw new OperationException(e);
    }
}
Also used : CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) ResourceDefinitionResult(com.sequenceiq.cloudbreak.cloud.event.platform.ResourceDefinitionResult) ResourceDefinitionRequest(com.sequenceiq.cloudbreak.cloud.event.platform.ResourceDefinitionRequest) OperationException(com.sequenceiq.cloudbreak.service.stack.connector.OperationException) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 43 with Cacheable

use of org.springframework.cache.annotation.Cacheable in project goci by EBISPOT.

the class DiseaseTraitService method similaritySearch.

@Cacheable(value = "diseaseTraitAnalysis", key = "#analysisId")
public AnalysisCacheDto similaritySearch(List<AnalysisDTO> diseaseTraitAnalysisDTOS, String analysisId, double threshold) {
    LevenshteinDistance lv = new LevenshteinDistance();
    CosineDistance cd = new CosineDistance();
    List<DiseaseTrait> diseaseTraits = diseaseTraitRepository.findAll();
    List<AnalysisDTO> analysisReport = new ArrayList<>();
    diseaseTraitAnalysisDTOS.forEach(diseaseTraitAnalysisDTO -> diseaseTraits.forEach(diseaseTrait -> {
        String trait = diseaseTrait.getTrait();
        String userTerm = diseaseTraitAnalysisDTO.getUserTerm();
        double cosineDistance = cd.apply(userTerm, trait);
        double levenshteinDistance = ((double) lv.apply(userTerm, trait)) / Math.max(userTerm.length(), trait.length());
        double cosineSimilarityPercent = Math.round((1 - cosineDistance) * 100);
        double levenshteinSimilarityPercent = Math.round((1 - levenshteinDistance) * 100);
        double chosen = Math.max(cosineSimilarityPercent, levenshteinSimilarityPercent);
        if (chosen >= threshold) {
            AnalysisDTO report = AnalysisDTO.builder().userTerm(userTerm).similarTerm(trait).degree(chosen).build();
            analysisReport.add(report);
        }
    }));
    return AnalysisCacheDto.builder().uniqueId(analysisId).analysisResult(analysisReport).build();
}
Also used : DataIntegrityException(uk.ac.ebi.spot.goci.curation.exception.DataIntegrityException) java.util(java.util) Logger(org.slf4j.Logger) Cacheable(org.springframework.cache.annotation.Cacheable) LoggerFactory(org.slf4j.LoggerFactory) LevenshteinDistance(org.apache.commons.text.similarity.LevenshteinDistance) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) DiseaseTrait(uk.ac.ebi.spot.goci.model.DiseaseTrait) Service(org.springframework.stereotype.Service) CosineDistance(org.apache.commons.text.similarity.CosineDistance) Study(uk.ac.ebi.spot.goci.model.Study) StudyRepository(uk.ac.ebi.spot.goci.repository.StudyRepository) Pageable(org.springframework.data.domain.Pageable) EntityType(uk.ac.ebi.spot.goci.curation.constants.EntityType) AnalysisDTO(uk.ac.ebi.spot.goci.curation.dto.AnalysisDTO) DiseaseTraitRepository(uk.ac.ebi.spot.goci.repository.DiseaseTraitRepository) AnalysisCacheDto(uk.ac.ebi.spot.goci.curation.dto.AnalysisCacheDto) DiseaseTraitDto(uk.ac.ebi.spot.goci.curation.dto.DiseaseTraitDto) DiseaseTrait(uk.ac.ebi.spot.goci.model.DiseaseTrait) LevenshteinDistance(org.apache.commons.text.similarity.LevenshteinDistance) AnalysisDTO(uk.ac.ebi.spot.goci.curation.dto.AnalysisDTO) CosineDistance(org.apache.commons.text.similarity.CosineDistance) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 44 with Cacheable

use of org.springframework.cache.annotation.Cacheable in project pinpoint by naver.

the class ApplicationCache method findApplicationId.

@Cacheable(cacheNames = "applicationId", key = SPEL_KEY, cacheManager = FlinkCacheConfiguration.APPLICATION_ID_CACHE_NAME)
public String findApplicationId(ApplicationKey application) {
    final String agentId = application.getAgentId();
    final long agentStartTimestamp = application.getAgentStartTime();
    final byte[] rowKey = rowKeyEncoder.encodeRowKey(agentId, agentStartTimestamp);
    Get get = new Get(rowKey);
    get.addColumn(AGENTINFO_INFO.getName(), AGENTINFO_INFO.QUALIFIER_IDENTIFIER);
    AgentInfo agentInfo = null;
    try {
        TableName tableName = tableNameProvider.getTableName(AGENTINFO_INFO.getTable());
        agentInfo = hbaseTemplate2.get(tableName, get, agentInfoMapper);
    } catch (Exception e) {
        logger.error("can't found application id({}). {}", agentId, e.getMessage());
    }
    return getApplicationId(agentInfo, agentId);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Get(org.apache.hadoop.hbase.client.Get) AgentInfo(com.navercorp.pinpoint.web.vo.AgentInfo) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 45 with Cacheable

use of org.springframework.cache.annotation.Cacheable in project disconf by knightliao.

the class RoleResourceMgrImpl method getAllAsMap.

/**
 * @return
 */
@Override
@Cacheable(value = "${role_res_cache_name}")
public Map<String, Map<RequestMethod, List<Integer>>> getAllAsMap() {
    Map<String, Map<RequestMethod, List<Integer>>> infoMap = new HashMap<String, Map<RequestMethod, List<Integer>>>();
    LOG.info("Querying role_resource table to get all...");
    List<RoleResource> roleResList = roleResDao.findAll();
    // 遍历列表,把数据按<url, <method, List<roleId>>>的形式加到infoMap
    for (RoleResource roleRes : roleResList) {
        String urlPattern = roleRes.getUrlPattern();
        if (!urlPattern.endsWith(RoleResourceConstant.URL_SPLITOR)) {
            urlPattern += RoleResourceConstant.URL_SPLITOR;
        }
        // LOG.info(urlPattern);
        Map<RequestMethod, List<Integer>> value = infoMap.get(urlPattern);
        if (value == null) {
            value = new HashMap<RequestMethod, List<Integer>>();
            infoMap.put(urlPattern, value);
        }
        updateMethodMap(value, roleRes.getRoleId(), roleRes.getMethodMask());
    }
    return infoMap;
}
Also used : HashMap(java.util.HashMap) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) RoleResource(com.baidu.disconf.web.service.roleres.bo.RoleResource) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

Cacheable (org.springframework.cache.annotation.Cacheable)142 ArrayList (java.util.ArrayList)35 HashMap (java.util.HashMap)25 Query (javax.persistence.Query)13 HashSet (java.util.HashSet)11 SystemOptions (org.kuali.kfs.sys.businessobject.SystemOptions)10 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)7 List (java.util.List)7 IOException (java.io.IOException)6 LinkedHashMap (java.util.LinkedHashMap)6 Set (java.util.Set)6 NextProtException (org.nextprot.api.commons.exception.NextProtException)6 AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)5 TypedQuery (javax.persistence.TypedQuery)5 PageRequest (org.springframework.data.domain.PageRequest)5 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)4 QRoleMenu (com.github.liuweijw.business.admin.domain.QRoleMenu)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 Map (java.util.Map)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4