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 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 ResearcherUrlDaoImpl method getResearcherUrls.
/**
* Return the list of researcher urls associated to a specific profile
* @param orcid
* @return
* the list of researcher urls associated with the orcid profile
*/
@Override
@SuppressWarnings("unchecked")
@Cacheable(value = "researcher-urls", key = "#orcid.concat('-').concat(#lastModified)")
public List<ResearcherUrlEntity> getResearcherUrls(String orcid, long lastModified) {
Query query = entityManager.createQuery("FROM ResearcherUrlEntity WHERE orcid = :orcid order by displayIndex desc, dateCreated asc");
query.setParameter("orcid", orcid);
return query.getResultList();
}
use of org.springframework.cache.annotation.Cacheable in project ORCID-Source by ORCID.
the class GivenPermissionToManagerReadOnlyImpl method findByReceiver.
@Override
@Cacheable(value = "delegates-by-receiver", key = "#receiverOrcid.concat('-').concat(#lastModified)")
public List<DelegateForm> findByReceiver(String receiverOrcid, long lastModified) {
List<DelegateForm> delegates = new ArrayList<DelegateForm>();
List<GivenPermissionByEntity> list = givenPermissionToDaoReadOnly.findByReceiver(receiverOrcid);
for (GivenPermissionByEntity element : list) {
DelegateForm form = new DelegateForm();
form.setApprovalDate(DateUtils.convertToXMLGregorianCalendar(element.getApprovalDate()));
form.setLastModifiedDate(DateUtils.convertToXMLGregorianCalendar(element.getGiver().getLastModified()));
form.setGiverName(Text.valueOf(element.getGiver().getDisplayName()));
form.setGiverOrcid(orcidIdentifierUtils.buildOrcidIdentifier(element.getGiver().getId()));
form.setReceiverOrcid(orcidIdentifierUtils.buildOrcidIdentifier(element.getReceiver()));
delegates.add(form);
}
return delegates;
}
use of org.springframework.cache.annotation.Cacheable in project ORCID-Source by ORCID.
the class GivenPermissionToManagerReadOnlyImpl method findByGiver.
@Override
@Cacheable(value = "delegates-by-giver", key = "#giverOrcid.concat('-').concat(#lastModified)")
public List<DelegateForm> findByGiver(String giverOrcid, long lastModified) {
List<DelegateForm> delegates = new ArrayList<DelegateForm>();
List<GivenPermissionToEntity> list = givenPermissionToDaoReadOnly.findByGiver(giverOrcid);
for (GivenPermissionToEntity element : list) {
DelegateForm form = new DelegateForm();
form.setApprovalDate(DateUtils.convertToXMLGregorianCalendar(element.getApprovalDate()));
form.setGiverOrcid(orcidIdentifierUtils.buildOrcidIdentifier(element.getGiver()));
form.setReceiverOrcid(orcidIdentifierUtils.buildOrcidIdentifier(element.getReceiver().getId()));
form.setReceiverName(Text.valueOf(element.getReceiver().getDisplayName()));
delegates.add(form);
}
return delegates;
}
Aggregations