Search in sources :

Example 96 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 97 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)

Example 98 with Cacheable

use of org.springframework.cache.annotation.Cacheable in project herd by FINRAOS.

the class SecurityFunctionDaoImpl method getUnrestrictedSecurityFunctions.

@Override
@Cacheable(DaoSpringModuleConfig.HERD_CACHE_NAME)
public List<String> getUnrestrictedSecurityFunctions() {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<String> criteria = builder.createQuery(String.class);
    // The criteria root is the security function.
    Root<SecurityFunctionEntity> securityFunctionEntityRoot = criteria.from(SecurityFunctionEntity.class);
    // Build a subquery to eliminate security functions that are mapped to security roles.
    Subquery<SecurityFunctionEntity> subquery = criteria.subquery(SecurityFunctionEntity.class);
    Root<SecurityRoleFunctionEntity> subSecurityRoleFunctionEntityRoot = subquery.from(SecurityRoleFunctionEntity.class);
    subquery.select(subSecurityRoleFunctionEntityRoot.get(SecurityRoleFunctionEntity_.securityFunction)).where(builder.equal(subSecurityRoleFunctionEntityRoot.get(SecurityRoleFunctionEntity_.securityFunction), securityFunctionEntityRoot));
    // Get the security function code column.
    Path<String> functionCodeColumn = securityFunctionEntityRoot.get(SecurityFunctionEntity_.code);
    // Add the clauses for the query.
    criteria.select(functionCodeColumn).where(builder.not(builder.exists(subquery))).orderBy(builder.asc(functionCodeColumn));
    // Run the query to get a list of unrestricted security functions.
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) SecurityRoleFunctionEntity(org.finra.herd.model.jpa.SecurityRoleFunctionEntity) SecurityFunctionEntity(org.finra.herd.model.jpa.SecurityFunctionEntity) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 99 with Cacheable

use of org.springframework.cache.annotation.Cacheable in project herd by FINRAOS.

the class SecurityFunctionDaoImpl method getSecurityFunctionsForRole.

@Override
@Cacheable(DaoSpringModuleConfig.HERD_CACHE_NAME)
public List<String> getSecurityFunctionsForRole(String roleCd) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<String> criteria = builder.createQuery(String.class);
    // The criteria root is the security role function mapping.
    Root<SecurityRoleFunctionEntity> securityRoleFunctionEntity = criteria.from(SecurityRoleFunctionEntity.class);
    // Join to the other tables we can filter on.
    Join<SecurityRoleFunctionEntity, SecurityRoleEntity> securityRoleEntity = securityRoleFunctionEntity.join(SecurityRoleFunctionEntity_.securityRole);
    Join<SecurityRoleFunctionEntity, SecurityFunctionEntity> securityFunctionEntity = securityRoleFunctionEntity.join(SecurityRoleFunctionEntity_.securityFunction);
    // Get the columns.
    Path<String> functionCodeColumn = securityFunctionEntity.get(SecurityFunctionEntity_.code);
    // Add the select clause.
    criteria.select(functionCodeColumn);
    // Add the where clause.
    criteria.where(builder.equal(builder.upper(securityRoleEntity.get(SecurityRoleEntity_.code)), roleCd.toUpperCase()));
    // Add the order by clause.
    criteria.orderBy(builder.asc(functionCodeColumn));
    // Run the query to get a list of functions.
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) SecurityRoleFunctionEntity(org.finra.herd.model.jpa.SecurityRoleFunctionEntity) SecurityFunctionEntity(org.finra.herd.model.jpa.SecurityFunctionEntity) SecurityRoleEntity(org.finra.herd.model.jpa.SecurityRoleEntity) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 100 with Cacheable

use of org.springframework.cache.annotation.Cacheable in project openmrs-core by openmrs.

the class AdministrationServiceImpl method getSearchLocales.

@Override
@Cacheable(value = "userSearchLocales")
public List<Locale> getSearchLocales(Locale currentLocale, User user) throws APIException {
    Set<Locale> locales = new LinkedHashSet<>();
    // the currently used full locale
    locales.add(currentLocale);
    locales.add(new Locale(currentLocale.getLanguage()));
    if (user != null) {
        List<Locale> proficientLocales = user.getProficientLocales();
        if (proficientLocales != null) {
            locales.addAll(proficientLocales);
        }
    }
    // limit locales to only allowed locales
    List<Locale> allowedLocales = Context.getAdministrationService().getAllowedLocales();
    if (allowedLocales != null) {
        Set<Locale> retainLocales = new HashSet<>();
        for (Locale allowedLocale : allowedLocales) {
            retainLocales.add(allowedLocale);
            retainLocales.add(new Locale(allowedLocale.getLanguage()));
        }
        locales.retainAll(retainLocales);
    }
    return new ArrayList<>(locales);
}
Also used : Locale(java.util.Locale) LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

Cacheable (org.springframework.cache.annotation.Cacheable)142 ArrayList (java.util.ArrayList)35 HashMap (java.util.HashMap)25 Query (javax.persistence.Query)13 HashSet (java.util.HashSet)11 SystemOptions (org.kuali.kfs.sys.businessobject.SystemOptions)10 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)7 List (java.util.List)7 IOException (java.io.IOException)6 LinkedHashMap (java.util.LinkedHashMap)6 Set (java.util.Set)6 NextProtException (org.nextprot.api.commons.exception.NextProtException)6 AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)5 TypedQuery (javax.persistence.TypedQuery)5 PageRequest (org.springframework.data.domain.PageRequest)5 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)4 QRoleMenu (com.github.liuweijw.business.admin.domain.QRoleMenu)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 Map (java.util.Map)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4