Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<groupId>org.entando.entando.plugins</groupId>
<artifactId>entando-plugin-jacms</artifactId>
<packaging>war</packaging>
<version>6.5.3</version>
<version>6.5.4</version>
<name>Entando Plugin: CMS</name>
<description>Allows registered users to manage dynamic contents and digital assets</description>
<url>http://www.entando.com/</url>
Expand Down Expand Up @@ -86,6 +86,28 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>test-jar</id>
<phase>package</phase>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
Expand Down Expand Up @@ -180,6 +202,11 @@
<!-- <groupId>com.drewnoakes</groupId>-->
<!-- <artifactId>metadata-extractor</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>3.1.8</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
Expand Down Expand Up @@ -267,6 +294,17 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package com.agiletec.plugins.jacms.aps.system.services.content;

import com.agiletec.aps.system.ApsSystemUtils;
import com.agiletec.aps.system.ApsSystemUtils.ApsDeepDebug;
import com.agiletec.aps.system.SystemConstants;
import com.agiletec.aps.system.common.entity.ApsEntityManager;
import com.agiletec.aps.system.common.entity.IEntityDAO;
Expand All @@ -33,6 +34,7 @@
import com.agiletec.plugins.jacms.aps.system.services.content.model.ContentRecordVO;
import com.agiletec.plugins.jacms.aps.system.services.content.model.SmallContentType;
import com.agiletec.plugins.jacms.aps.system.services.resource.ResourceUtilizer;
import com.github.benmanes.caffeine.cache.Cache;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -54,7 +56,7 @@
* the contents.
*/
public class ContentManager extends ApsEntityManager
implements IContentManager, GroupUtilizer<String>, PageUtilizer, ContentUtilizer, ResourceUtilizer, CategoryUtilizer {
implements IFContentLocalCache, IContentManager, GroupUtilizer<String>, PageUtilizer, ContentUtilizer, ResourceUtilizer, CategoryUtilizer {

private static final EntLogger logger = EntLogFactory.getSanitizedLogger(ContentManager.class);

Expand All @@ -72,6 +74,8 @@ public class ContentManager extends ApsEntityManager

private ICacheInfoManager cacheInfoManager;

private transient com.github.benmanes.caffeine.cache.Cache<String, Object> localCache;

@Override
protected String getConfigItemName() {
return JacmsSystemConstants.CONFIG_ITEM_CONTENT_TYPES;
Expand All @@ -91,8 +95,8 @@ public Content createContentType(String typeCode) {
}

/**
* Return a list of the of the content types in a 'small form'. 'Small form'
* mans that the contents returned are purged from all unnecessary
* Return a list of the content types in a 'small form'. 'Small form'
* means that the contents returned are purged from all unnecessary
* information (eg. attributes).
*
* @return The list of the types in a (small form).
Expand Down Expand Up @@ -187,6 +191,17 @@ public Content loadContent(String id, boolean onLine) throws EntException {
}
}

@Override
public Content loadAndCacheContent(String id, boolean onLine) throws EntException {
try {
ContentRecordVO contentVo = this.loadAndCacheContentVO(id);
return this.createContent(contentVo, onLine);
} catch (EntException e) {
logger.error("Error while loading content : id {}", id, e);
throw new EntException("Error while loading content : id " + id, e);
}
}

protected Content createContent(ContentRecordVO contentVo, boolean onLine) throws EntException {
Content content = null;
try {
Expand Down Expand Up @@ -238,7 +253,7 @@ protected Content createContent(ContentRecordVO contentVo, boolean onLine) throw

/**
* Return a {@link ContentRecordVO} (shortly: VO) containing the all content
* informations stored in the DB.
* information stored in the DB.
*
* @param id The id of the requested content.
* @return The VO object corresponding to the wanted content.
Expand All @@ -247,13 +262,35 @@ protected Content createContent(ContentRecordVO contentVo, boolean onLine) throw
@Override
public ContentRecordVO loadContentVO(String id) throws EntException {
try {
ApsDeepDebug.print("cms-local-cache", "cache IGNORE " + id);
return (ContentRecordVO) this.getContentDAO().loadEntityRecord(id);
} catch (Throwable t) {
logger.error("Error while loading content vo : id {}", id, t);
throw new EntException("Error while loading content vo : id " + id, t);
}
}

@Override
public ContentRecordVO loadAndCacheContentVO(String id) throws EntException {
try {
return IFContentLocalCache.loadAndCacheContentVO(id, localCache,
() -> (ContentRecordVO) this.getContentDAO().loadEntityRecord(id));
} catch (Exception t) {
logger.error("Error while loading content vo : id {}", id, t);
throw new EntException("Error while loading content vo : id " + id, t);
}
}

@Override
public void evict(String key) {
IFContentLocalCache.evict(key, localCache);
}

@Override
public void evict(List<String> keys) {
IFContentLocalCache.evict(keys, localCache);
}

/**
* Save a content in the DB.
*
Expand All @@ -271,7 +308,7 @@ public void saveContentAndContinue(Content content) throws EntException {
}

/**
* Save a content in the DB. Hopefully this method has no annotation
* Save a content in the DB. Hopefully, this method has no annotation
* attached
*/
@Override
Expand All @@ -280,6 +317,7 @@ public void addContent(Content content) throws EntException {
}

private void addUpdateContent(Content content, boolean updateDate) throws EntException {
IFContentLocalCache.evict(content, localCache);
try {
content.setLastModified(new Date());
if (updateDate) {
Expand Down Expand Up @@ -751,4 +789,11 @@ public void setCacheInfoManager(ICacheInfoManager cacheInfoManager) {
this.cacheInfoManager = cacheInfoManager;
}

public Cache<String, Object> getLocalCache() {
return localCache;
}

public void setLocalCache(Cache<String, Object> localCache) {
this.localCache = localCache;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public interface IContentManager extends IEntityManager {
*/
public Content loadContent(String id, boolean onLine) throws EntException;

Content loadAndCacheContent(String id, boolean onLine) throws EntException;

/**
* Restituisce un VO contenente le informazioni del record su db
* corrispondente al contenuto di cui all'id inserito.
Expand All @@ -111,6 +113,12 @@ public interface IContentManager extends IEntityManager {
*/
public ContentRecordVO loadContentVO(String id) throws EntException;

ContentRecordVO loadAndCacheContentVO(String id) throws EntException;

void evict(String key);

void evict(List<String> keys);

/**
* Salva un contenuto sul DB. Il metodo viene utilizzato sia nel caso di
* salvataggio di un nuovo contenuto (in tal caso l'id del contenuto nuovo
Expand Down
Loading
Loading