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