Search in sources :

Example 61 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 62 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 63 with Cacheable

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();
}
Also used : Query(javax.persistence.Query) TypedQuery(javax.persistence.TypedQuery) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 64 with Cacheable

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;
}
Also used : DelegateForm(org.orcid.pojo.DelegateForm) ArrayList(java.util.ArrayList) GivenPermissionByEntity(org.orcid.persistence.jpa.entities.GivenPermissionByEntity) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 65 with Cacheable

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;
}
Also used : GivenPermissionToEntity(org.orcid.persistence.jpa.entities.GivenPermissionToEntity) DelegateForm(org.orcid.pojo.DelegateForm) ArrayList(java.util.ArrayList) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

Cacheable (org.springframework.cache.annotation.Cacheable)94 HashMap (java.util.HashMap)17 ArrayList (java.util.ArrayList)16 Query (javax.persistence.Query)11 HashSet (java.util.HashSet)10 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)7 LinkedHashMap (java.util.LinkedHashMap)6 NextProtException (org.nextprot.api.commons.exception.NextProtException)6 AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)5 IOException (java.io.IOException)5 List (java.util.List)5 Set (java.util.Set)5 TypedQuery (javax.persistence.TypedQuery)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4 Workbook (org.apache.poi.ss.usermodel.Workbook)4 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)3 Region (com.sequenceiq.cloudbreak.cloud.model.Region)3 VmType (com.sequenceiq.cloudbreak.cloud.model.VmType)3 Application (ai.elimu.model.admin.Application)2