Search in sources :

Example 21 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 22 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 23 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 24 with Cacheable

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

the class SecurityQuestionManagerImpl method retrieveSecurityQuestionsAsMap.

@Override
@Cacheable("security-questions")
public Map<String, String> retrieveSecurityQuestionsAsMap() {
    List<SecurityQuestionEntity> questions = securityQuestionDao.getAll();
    Map<String, String> map = new TreeMap<String, String>();
    for (SecurityQuestionEntity question : questions) {
        map.put(String.valueOf(question.getId()), question.getQuestion());
    }
    return map;
}
Also used : TreeMap(java.util.TreeMap) SecurityQuestionEntity(org.orcid.persistence.jpa.entities.SecurityQuestionEntity) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 25 with Cacheable

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

the class OrgDisambiguatedDaoImpl method getOrgs.

@SuppressWarnings("unchecked")
@Override
@Cacheable("orgs")
public List<OrgDisambiguatedEntity> getOrgs(String searchTerm, int firstResult, int maxResults) {
    String qStr = "select od.*, COUNT(*) as countAll from org_disambiguated od left join org_affiliation_relation oa on od.id = oa.org_id" + " where lower(name) like '%' || lower(:searchTerm) || '%' group by od.id " + " order by position(lower(:searchTerm) in lower(name)), char_length(name), countAll DESC, od.name";
    Query query = entityManager.createNativeQuery(qStr, OrgDisambiguatedEntity.class);
    query.setParameter("searchTerm", searchTerm);
    query.setFirstResult(firstResult);
    query.setMaxResults(maxResults);
    return query.getResultList();
}
Also used : TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

Cacheable (org.springframework.cache.annotation.Cacheable)27 Query (javax.persistence.Query)8 LinkedHashMap (java.util.LinkedHashMap)6 TypedQuery (javax.persistence.TypedQuery)4 HashMap (java.util.HashMap)3 IdentifierType (org.orcid.pojo.IdentifierType)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ResourceBundle (java.util.ResourceBundle)2 Workbook (org.apache.poi.ss.usermodel.Workbook)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 SecurityQuestionEntity (org.orcid.persistence.jpa.entities.SecurityQuestionEntity)2 UTF8Control (org.orcid.utils.UTF8Control)2 RoleResource (com.baidu.disconf.web.service.roleres.bo.RoleResource)1 Builder (com.google.common.collect.ImmutableList.Builder)1 ApiMetaDataBo (com.navercorp.pinpoint.common.server.bo.ApiMetaDataBo)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1