Search in sources :

Example 26 with Cacheable

use of org.springframework.cache.annotation.Cacheable in project ORCID-Source by ORCID.

the class RecordCorrectionsManagerReadOnlyImpl method getInvalidRecordDataChangesAscending.

@Override
@Cacheable(value = "invalid-record-data-change-page-asc", key = "(#lastElement == null ? 'none' : #lastElement.toString()).concat('-').concat(#pageSize.toString())")
public RecordCorrectionsPage getInvalidRecordDataChangesAscending(Long lastElement, Long pageSize) {
    List<InvalidRecordDataChangeEntity> entities = dao.getByDateCreated(lastElement, pageSize, ASCENDING);
    if (entities == null || entities.isEmpty()) {
        throw new IllegalArgumentException("Unable to find a page with the following params: lastElement=" + lastElement + " pageSize: " + pageSize + " ascending order");
    }
    List<RecordCorrection> elements = adapter.toInvalidRecordDataChanges(entities);
    Long first = null;
    Long last = null;
    for (RecordCorrection element : elements) {
        if (first == null || element.getSequence() < first) {
            first = element.getSequence();
        }
        if (last == null || element.getSequence() > last) {
            last = element.getSequence();
        }
    }
    Boolean haveNext = dao.haveNext(last, ASCENDING);
    Boolean havePrevious = dao.havePrevious(first, ASCENDING);
    RecordCorrectionsPage page = new RecordCorrectionsPage();
    page.setFirstElementId(first);
    page.setLastElementId(last);
    page.setHaveNext(haveNext);
    page.setHavePrevious(havePrevious);
    page.setRecordCorrections(elements);
    return page;
}
Also used : InvalidRecordDataChangeEntity(org.orcid.persistence.jpa.entities.InvalidRecordDataChangeEntity) RecordCorrectionsPage(org.orcid.model.record_correction.RecordCorrectionsPage) RecordCorrection(org.orcid.model.record_correction.RecordCorrection) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 27 with Cacheable

use of org.springframework.cache.annotation.Cacheable in project ORCID-Source by ORCID.

the class IdentifierTypeManagerImpl method queryByPrefix.

/**
     * Queries the identifier name and description fields for words that START WITH query.
     * Returns an immutable list of matching types.
     * Null locale will result in Locale.ENGLISH
     * 
     */
@Override
@Cacheable("identifier-types-map-prefix")
public List<IdentifierType> queryByPrefix(String query, Locale loc) {
    Map<String, IdentifierType> results = new HashMap<String, IdentifierType>();
    Map<String, IdentifierType> types = fetchIdentifierTypesByAPITypeName(loc);
    //stick them in a trie so we can do a deep prefix search
    PatriciaTrie<Set<IdentifierType>> trie = new PatriciaTrie<Set<IdentifierType>>();
    for (String type : types.keySet()) {
        IdentifierType t = types.get(type);
        if (!trie.containsKey(t.getName().toLowerCase()))
            trie.put(t.getName().toLowerCase(), new HashSet<IdentifierType>());
        trie.get(t.getName().toLowerCase()).add(t);
        for (String s : t.getDescription().toLowerCase().split(" ")) {
            if (!trie.containsKey(s))
                trie.put(s, new HashSet<IdentifierType>());
            trie.get(s).add(t);
        }
    }
    //dedupe and sort
    SortedMap<String, Set<IdentifierType>> sorted = trie.prefixMap(query.toLowerCase());
    for (Set<IdentifierType> set : sorted.values()) {
        for (IdentifierType t : set) {
            if (!results.containsKey(t.getDescription().toLowerCase()))
                results.put(t.getDescription().toLowerCase(), t);
        }
    }
    //put anything that starts with query at the top of the list.
    Builder<IdentifierType> builder = new Builder<IdentifierType>();
    for (IdentifierType t : results.values()) {
        if (t.getDescription().toLowerCase().startsWith(query.toLowerCase())) {
            builder.add(t);
        }
    }
    for (IdentifierType t : results.values()) {
        if (!t.getDescription().toLowerCase().startsWith(query.toLowerCase())) {
            builder.add(t);
        }
    }
    return builder.build();
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) PatriciaTrie(org.apache.commons.collections4.trie.PatriciaTrie) Builder(com.google.common.collect.ImmutableList.Builder) IdentifierType(org.orcid.pojo.IdentifierType) HashSet(java.util.HashSet) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 28 with Cacheable

use of org.springframework.cache.annotation.Cacheable in project ORCID-Source by ORCID.

the class CountryManagerImpl method retrieveCountriesAndIsoCodes.

@Override
@Cacheable("iso-countries")
public Map<String, String> retrieveCountriesAndIsoCodes() {
    List<CountryIsoEntity> countries = isoCountryReferenceDataDao.getAll();
    Collections.sort(countries, new Comparator<CountryIsoEntity>() {

        public int compare(CountryIsoEntity country1, CountryIsoEntity country2) {
            return ((String) country1.getCountryName()).compareToIgnoreCase((String) country2.getCountryName());
        }
    });
    Map<String, String> countriesMap = new LinkedHashMap<String, String>();
    for (CountryIsoEntity country : countries) {
        countriesMap.put(country.getCountryIsoCode(), country.getCountryName());
    }
    return countriesMap;
}
Also used : CountryIsoEntity(org.orcid.persistence.jpa.entities.CountryIsoEntity) LinkedHashMap(java.util.LinkedHashMap) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 29 with Cacheable

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

the class HbaseApiMetaDataDao method getApiMetaData.

@Override
@Cacheable(value = "apiMetaData", key = SPEL_KEY)
public List<ApiMetaDataBo> getApiMetaData(String agentId, long time, int apiId) {
    if (agentId == null) {
        throw new NullPointerException("agentId must not be null");
    }
    ApiMetaDataBo apiMetaDataBo = new ApiMetaDataBo(agentId, time, apiId);
    byte[] sqlId = getDistributedKey(apiMetaDataBo.toRowKey());
    Get get = new Get(sqlId);
    get.addFamily(HBaseTables.API_METADATA_CF_API);
    return hbaseOperations2.get(HBaseTables.API_METADATA, get, apiMetaDataMapper);
}
Also used : Get(org.apache.hadoop.hbase.client.Get) ApiMetaDataBo(com.navercorp.pinpoint.common.server.bo.ApiMetaDataBo) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 30 with Cacheable

use of org.springframework.cache.annotation.Cacheable in project ocvn by devgateway.

the class ExcelChartGenerator method getExcelChart.

/**
     * Generate an Excel Chart based on (categories, values)
     */
@Cacheable
public byte[] getExcelChart(final ChartType type, final String title, final List<String> seriesTitle, final List<?> categories, final List<List<? extends Number>> values) throws IOException {
    final ExcelChart excelChart = new ExcelChartDefault(title, type, categories, values);
    excelChart.configureSeriesTitle(seriesTitle);
    final Workbook workbook = excelChart.createWorkbook();
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    workbook.write(baos);
    return baos.toByteArray();
}
Also used : ExcelChart(org.devgateway.toolkit.web.excelcharts.ExcelChart) ExcelChartDefault(org.devgateway.toolkit.web.excelcharts.ExcelChartDefault) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Workbook(org.apache.poi.ss.usermodel.Workbook) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

Cacheable (org.springframework.cache.annotation.Cacheable)33 Query (javax.persistence.Query)8 LinkedHashMap (java.util.LinkedHashMap)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 HashMap (java.util.HashMap)4 TypedQuery (javax.persistence.TypedQuery)4 Workbook (org.apache.poi.ss.usermodel.Workbook)4 IdentifierType (org.orcid.pojo.IdentifierType)3 PageRequest (org.springframework.data.domain.PageRequest)3 ArrayList (java.util.ArrayList)2 ResourceBundle (java.util.ResourceBundle)2 Release (org.devgateway.ocds.persistence.mongo.Release)2 ExcelFile (org.devgateway.ocds.persistence.mongo.excel.ExcelFile)2 ReleaseExportFile (org.devgateway.ocds.persistence.mongo.excel.ReleaseExportFile)2 ExcelChart (org.devgateway.toolkit.web.excelcharts.ExcelChart)2 ExcelChartDefault (org.devgateway.toolkit.web.excelcharts.ExcelChartDefault)2 RecordCorrection (org.orcid.model.record_correction.RecordCorrection)2 RecordCorrectionsPage (org.orcid.model.record_correction.RecordCorrectionsPage)2 IdentifierTypeEntity (org.orcid.persistence.jpa.entities.IdentifierTypeEntity)2 InvalidRecordDataChangeEntity (org.orcid.persistence.jpa.entities.InvalidRecordDataChangeEntity)2