Search in sources :

Example 81 with Cacheable

use of org.springframework.cache.annotation.Cacheable in project fw-cloud-framework by liuweijw.

the class UserServiceImpl method findByUserId.

@Override
@Cacheable(value = AdminCacheKey.USER_INFO_USERID, key = AdminCacheKey.USER_INFO_USERID_KEY_USERID)
public AuthUser findByUserId(String userId) {
    User user = userRepository.findUserByUserId(Integer.valueOf(userId));
    if (null == user)
        return null;
    user.setRoleList(findRoleListByUserId(user.getUserId()));
    return buildAuthUserByUser(user);
}
Also used : User(com.github.liuweijw.business.admin.domain.User) QUser(com.github.liuweijw.business.admin.domain.QUser) AuthUser(com.github.liuweijw.core.beans.system.AuthUser) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 82 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 83 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 84 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)

Example 85 with Cacheable

use of org.springframework.cache.annotation.Cacheable in project ocvn by devgateway.

the class ExcelChartGenerator method getExcelChart.

/**
 * Generate an Excel Chart based on (categories, values)
 */
@Cacheable
public byte[] getExcelChart(final ChartType type, final String title, final List<String> seriesTitle, final List<?> categories, final List<List<? extends Number>> values) throws IOException {
    final ExcelChart excelChart = new ExcelChartDefault(title, type, categories, values);
    excelChart.configureSeriesTitle(seriesTitle);
    final Workbook workbook = excelChart.createWorkbook();
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    workbook.write(baos);
    return baos.toByteArray();
}
Also used : ExcelChart(org.devgateway.toolkit.web.excelcharts.ExcelChart) ExcelChartDefault(org.devgateway.toolkit.web.excelcharts.ExcelChartDefault) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Workbook(org.apache.poi.ss.usermodel.Workbook) 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