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;
}
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();
}
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;
}
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;
}
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();
}
Aggregations