Search in sources :

Example 76 with Cacheable

use of org.springframework.cache.annotation.Cacheable in project nextprot-api by calipho-sib.

the class NextprotAuth0EndpointImpl method fetchUser.

@Cacheable("user-auth")
public Auth0User fetchUser(String accessToken) throws IOException, JSONException {
    Resty resty = new Resty();
    String userInfoUri = getUserInfoUri(accessToken);
    JSONResource json = resty.json(userInfoUri);
    return new Auth0User(json.toObject());
}
Also used : Auth0User(com.auth0.Auth0User) Resty(us.monoid.web.Resty) JSONResource(us.monoid.web.JSONResource) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 77 with Cacheable

use of org.springframework.cache.annotation.Cacheable in project nextprot-api by calipho-sib.

the class TerminologyDaoImpl method findTerminologyByAccession.

@Override
// SHOULD USE findTermByAccessionAndTerminology
@Cacheable("terminology-by-accession")
public CvTerm findTerminologyByAccession(String accession) {
    Set<String> acs = new HashSet<>();
    acs.add(accession);
    SqlParameterSource params = new MapSqlParameterSource("accessions", acs);
    List<CvTerm> terms = new NamedParameterJdbcTemplate(dsLocator.getDataSource()).query(sqlDictionary.getSQLQuery("terminology-by-acs"), params, new DbTermRowMapper());
    if (terms.size() == 0)
        return null;
    else if (terms.size() > 1) {
        throw new NextProtException("Found " + terms.size() + " terms that corresponds to the same accession. Use the method findTerminologyByAccessionForTerminology (accession, terminology) instead");
    }
    return terms.get(0);
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) SqlParameterSource(org.springframework.jdbc.core.namedparam.SqlParameterSource) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) CvTerm(org.nextprot.api.core.domain.CvTerm) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) HashSet(java.util.HashSet) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 78 with Cacheable

use of org.springframework.cache.annotation.Cacheable in project nextprot-api by calipho-sib.

the class EntryPageServiceImpl method hasContentForPageDisplay.

@Cacheable(value = "page-display", key = "#entryName")
@Override
public Map<String, Boolean> hasContentForPageDisplay(@ValidEntry String entryName) {
    Entry entry = entryBuilderService.build(EntryConfig.newConfig(entryName).withEverything());
    Map<String, Boolean> map = new HashMap<>();
    for (PageViewFactory page : PageViewFactory.values()) {
        PageView pv = page.getPageView();
        map.put(pv.getLabel(), pv.doDisplayPage(entry));
    }
    return map;
}
Also used : PageView(org.nextprot.api.core.domain.ui.page.PageView) Entry(org.nextprot.api.core.domain.Entry) ValidEntry(org.nextprot.api.core.service.annotation.ValidEntry) HashMap(java.util.HashMap) PageViewFactory(org.nextprot.api.core.domain.ui.page.PageViewFactory) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 79 with Cacheable

use of org.springframework.cache.annotation.Cacheable in project nextprot-api by calipho-sib.

the class GitHubServiceImpl method getTree.

@Override
@Cacheable(value = "github-tree")
public GHTree getTree() {
    try {
        GitHub github = getGitHubConnection();
        GHRepository repo = github.getRepository("calipho-sib/nextprot-docs");
        return repo.getTreeRecursive(githubDocBranch, 1);
    } catch (IOException e) {
        e.printStackTrace();
        throw new NextProtException("Documentation not available, sorry for the inconvenience");
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) GHRepository(org.kohsuke.github.GHRepository) GitHub(org.kohsuke.github.GitHub) IOException(java.io.IOException) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 80 with Cacheable

use of org.springframework.cache.annotation.Cacheable in project nextprot-api by calipho-sib.

the class GitHubServiceImpl method getPage.

@Override
@Cacheable(value = "github-pages")
public String getPage(String folder, String page) {
    String finalPage = page;
    if ("news".equalsIgnoreCase(folder)) {
        finalPage = getCorrespondingPageForNews(page);
    }
    try {
        GitHub github = getGitHubConnection();
        GHRepository repo = github.getRepository("calipho-sib/nextprot-docs");
        GHContent content = null;
        String extension = ".md";
        if (folder.contains("json")) {
            // if folder contains json
            extension = ".json";
        }
        content = repo.getFileContent(folder + "/" + finalPage + extension, githubDocBranch);
        return content.getContent();
    } catch (IOException e) {
        e.printStackTrace();
        throw new NextProtException("Documentation not available, sorry for the inconvenience");
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) GHRepository(org.kohsuke.github.GHRepository) GitHub(org.kohsuke.github.GitHub) GHContent(org.kohsuke.github.GHContent) IOException(java.io.IOException) 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