Search in sources :

Example 6 with CachePut

use of org.springframework.cache.annotation.CachePut in project entando-core by entando.

the class ResourceDAO method loadResourceVo.

/**
 * Carica un record di risorse in funzione dell'id Risorsa. Questo record รจ
 * necessario per l'estrazione della risorse in oggetto tipo
 * AbstractResource da parte del ResourceManager.
 *
 * @param id L'identificativo della risorsa.
 * @return Il record della risorsa.
 */
@Override
@CachePut(value = ICacheInfoManager.DEFAULT_CACHE_NAME, key = "'jacms_resource_'.concat(#id)", condition = "null != #id")
public ResourceRecordVO loadResourceVo(String id) {
    Connection conn = null;
    ResourceRecordVO resourceVo = null;
    PreparedStatement stat = null;
    ResultSet res = null;
    try {
        conn = this.getConnection();
        stat = conn.prepareStatement(LOAD_RESOURCE_VO);
        stat.setString(1, id);
        res = stat.executeQuery();
        if (res.next()) {
            resourceVo = new ResourceRecordVO();
            resourceVo.setId(id);
            resourceVo.setResourceType(res.getString(1));
            resourceVo.setDescr(res.getString(2));
            resourceVo.setMainGroup(res.getString(3));
            resourceVo.setXml(res.getString(4));
            resourceVo.setMasterFileName(res.getString(5));
            resourceVo.setCreationDate(res.getDate(6));
            resourceVo.setLastModified(res.getDate(7));
        }
    } catch (Throwable t) {
        _logger.error("Errore loading resource {}", id, t);
        throw new RuntimeException("Errore loading resource" + id, t);
    } finally {
        closeDaoResources(res, stat, conn);
    }
    return resourceVo;
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ResourceRecordVO(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceRecordVO) PreparedStatement(java.sql.PreparedStatement) CachePut(org.springframework.cache.annotation.CachePut)

Example 7 with CachePut

use of org.springframework.cache.annotation.CachePut in project entando-core by entando.

the class CacheInfoManager method aroundCacheableMethod.

@Around("@annotation(cacheableInfo)")
public Object aroundCacheableMethod(ProceedingJoinPoint pjp, CacheableInfo cacheableInfo) throws Throwable {
    Object result = pjp.proceed();
    if (cacheableInfo.expiresInMinute() < 0 && (cacheableInfo.groups() == null || cacheableInfo.groups().trim().length() == 0)) {
        return result;
    }
    try {
        MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
        Method targetMethod = methodSignature.getMethod();
        Class targetClass = pjp.getTarget().getClass();
        Method effectiveTargetMethod = targetClass.getMethod(targetMethod.getName(), targetMethod.getParameterTypes());
        Cacheable cacheable = effectiveTargetMethod.getAnnotation(Cacheable.class);
        if (null == cacheable) {
            CachePut cachePut = effectiveTargetMethod.getAnnotation(CachePut.class);
            if (null == cachePut) {
                return result;
            }
            String[] cacheNames = cachePut.value();
            Object key = this.evaluateExpression(cachePut.key().toString(), targetMethod, pjp.getArgs(), effectiveTargetMethod, targetClass);
            for (String cacheName : cacheNames) {
                if (cacheableInfo.groups() != null && cacheableInfo.groups().trim().length() > 0) {
                    Object groupsCsv = this.evaluateExpression(cacheableInfo.groups().toString(), targetMethod, pjp.getArgs(), effectiveTargetMethod, targetClass);
                    if (null != groupsCsv && groupsCsv.toString().trim().length() > 0) {
                        String[] groups = groupsCsv.toString().split(",");
                        this.putInGroup(cacheName, key.toString(), groups);
                    }
                }
                if (cacheableInfo.expiresInMinute() > 0) {
                    this.setExpirationTime(cacheName, key.toString(), cacheableInfo.expiresInMinute());
                }
            }
        } else {
            String[] cacheNames = cacheable.value();
            Object key = this.evaluateExpression(cacheable.key().toString(), targetMethod, pjp.getArgs(), effectiveTargetMethod, targetClass);
            for (String cacheName : cacheNames) {
                if (cacheableInfo.groups() != null && cacheableInfo.groups().trim().length() > 0) {
                    Object groupsCsv = this.evaluateExpression(cacheableInfo.groups().toString(), targetMethod, pjp.getArgs(), effectiveTargetMethod, targetClass);
                    if (null != groupsCsv && groupsCsv.toString().trim().length() > 0) {
                        String[] groups = groupsCsv.toString().split(",");
                        this.putInGroup(cacheName, key.toString(), groups);
                    }
                }
                if (cacheableInfo.expiresInMinute() > 0) {
                    this.setExpirationTime(cacheName, key.toString(), cacheableInfo.expiresInMinute());
                }
            }
        }
    } catch (Throwable t) {
        logger.error("Error while evaluating cacheableInfo annotation", t);
        throw new ApsSystemException("Error while evaluating cacheableInfo annotation", t);
    }
    return result;
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) Cacheable(org.springframework.cache.annotation.Cacheable) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) Method(java.lang.reflect.Method) CachePut(org.springframework.cache.annotation.CachePut) Around(org.aspectj.lang.annotation.Around)

Example 8 with CachePut

use of org.springframework.cache.annotation.CachePut in project entando-core by entando.

the class GuiFragmentManager method getGuiFragmentCodesByWidgetType.

@Override
@CachePut(value = ICacheInfoManager.DEFAULT_CACHE_NAME, key = "'GuiFragment_codesByWidgetType_'.concat(#widgetTypeCode)")
// TODO improve group handling
@CacheableInfo(groups = "'GuiFragment_codesByWidgetTypeGroup'")
public List<String> getGuiFragmentCodesByWidgetType(String widgetTypeCode) throws ApsSystemException {
    List<String> codes = null;
    try {
        FieldSearchFilter filter = new FieldSearchFilter("widgettypecode", widgetTypeCode, false);
        filter.setOrder(FieldSearchFilter.Order.ASC);
        FieldSearchFilter[] filters = { filter };
        codes = this.searchGuiFragments(filters);
    } catch (Throwable t) {
        logger.error("Error loading fragments code by widget '{}'", widgetTypeCode, t);
        throw new ApsSystemException("Error loading fragment codes by widget " + widgetTypeCode, t);
    }
    return codes;
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) CacheableInfo(org.entando.entando.aps.system.services.cache.CacheableInfo) CachePut(org.springframework.cache.annotation.CachePut)

Example 9 with CachePut

use of org.springframework.cache.annotation.CachePut in project sailfish-mfa by picos-io.

the class PasscodeRequestManagerImpl method requestPasscode.

@CachePut(key = "#requestId")
@Override
public PasscodeRequest requestPasscode(String requestId, int bits, long timeToLive) {
    PasscodeRequest passcodeRequest = findById(requestId);
    if (passcodeRequest != null) {
        return passcodeRequest;
    }
    passcodeRequest = new PasscodeRequest();
    passcodeRequest.setId(requestId);
    passcodeRequest.setCode(passcodeGenerator.generate(bits < 4 ? 4 : bits));
    passcodeRequest.setCreatedAt(new Date());
    passcodeRequest.setExpiredAt(new Date(System.currentTimeMillis() + timeToLive));
    return passcodeRequest;
}
Also used : PasscodeRequest(io.picos.sailfish.mfa.passcode.model.PasscodeRequest) Date(java.util.Date) LocalDate(java.time.LocalDate) CachePut(org.springframework.cache.annotation.CachePut)

Example 10 with CachePut

use of org.springframework.cache.annotation.CachePut in project entando-core by entando.

the class BaseContentListHelper method getContentsId.

@Override
@CachePut(value = ICacheInfoManager.DEFAULT_CACHE_NAME, key = "T(com.agiletec.plugins.jacms.aps.system.services.content.helper.BaseContentListHelper).buildCacheKey(#bean, #user)", condition = "#bean.cacheable")
@CacheableInfo(groups = "T(com.agiletec.plugins.jacms.aps.system.JacmsSystemConstants).CONTENTS_ID_CACHE_GROUP_PREFIX.concat(#bean.contentType)", expiresInMinute = 30)
public List<String> getContentsId(IContentListBean bean, UserDetails user) throws Throwable {
    this.releaseCache(bean, user);
    List<String> contentsId = null;
    try {
        if (null == bean.getContentType()) {
            throw new ApsSystemException("Content type not defined");
        }
        // this.getAllowedGroups(user);
        Collection<String> userGroupCodes = getAllowedGroupCodes(user);
        contentsId = this.getContentManager().loadPublicContentsId(bean.getContentType(), bean.getCategories(), bean.getFilters(), userGroupCodes);
    } catch (Throwable t) {
        _logger.error("Error extracting contents id", t);
        throw new ApsSystemException("Error extracting contents id", t);
    }
    return contentsId;
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) CacheableInfo(org.entando.entando.aps.system.services.cache.CacheableInfo) CachePut(org.springframework.cache.annotation.CachePut)

Aggregations

CachePut (org.springframework.cache.annotation.CachePut)12 CacheableInfo (org.entando.entando.aps.system.services.cache.CacheableInfo)8 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)7 IUserProfile (org.entando.entando.aps.system.services.userprofile.model.IUserProfile)3 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)2 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)1 ResourceRecordVO (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceRecordVO)1 PasscodeRequest (io.picos.sailfish.mfa.passcode.model.PasscodeRequest)1 Method (java.lang.reflect.Method)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 LocalDate (java.time.LocalDate)1 Date (java.util.Date)1 Property (me.ruslanys.vkmusic.entity.Property)1 Around (org.aspectj.lang.annotation.Around)1 MethodSignature (org.aspectj.lang.reflect.MethodSignature)1 UserProfileRecord (org.entando.entando.aps.system.services.userprofile.model.UserProfileRecord)1 ActivityStreamComment (org.entando.entando.apsadmin.system.services.activitystream.model.ActivityStreamComment)1 ActivityStreamLikeInfo (org.entando.entando.apsadmin.system.services.activitystream.model.ActivityStreamLikeInfo)1