diff --git a/.github/workflows/ga-publication.yml b/.github/workflows/ga-publication.yml
index fb7e7f5a4d..4f266b64bb 100755
--- a/.github/workflows/ga-publication.yml
+++ b/.github/workflows/ga-publication.yml
@@ -46,7 +46,7 @@ jobs:
- name: "Configure GA Repository"
uses: actions/setup-java@v1
with:
- java-version: 11
+ java-version: 17
server-id: maven-central
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml
index e782e3fc85..7642c0021a 100755
--- a/.github/workflows/pr.yml
+++ b/.github/workflows/pr.yml
@@ -72,10 +72,10 @@ jobs:
--token "$ENTANDO_BOT_TOKEN" \
;
#~ JDK
- - name: "Set up JDK 11"
+ - name: "Set up JDK 17"
uses: actions/setup-java@v1
with:
- java-version: 11
+ java-version: 17
#~ MAVEN CACHE
- name: "Cache Maven packages"
uses: actions/cache@v2
@@ -119,10 +119,10 @@ jobs:
# ${{ secrets.ENTANDO_OPT_PPL_INSTALL_CMD }}
# ~/ppl-run checkout-branch pr --lcd "$LOCAL_CLONE_DIR"
# #~ JDK
-# - name: "Set up JDK 11"
+# - name: "Set up JDK 17"
# uses: actions/setup-java@v1
# with:
-# java-version: 11
+# java-version: 17
# #~ MAVEN CACHE
# - name: "Cache Maven packages"
# id: maven-cache
diff --git a/.github/workflows/publication.yml b/.github/workflows/publication.yml
index bcbc107a53..2dd993b034 100755
--- a/.github/workflows/publication.yml
+++ b/.github/workflows/publication.yml
@@ -10,17 +10,12 @@ env:
ENTANDO_BOT_TOKEN: ${{ secrets.ENTANDO_BOT_TOKEN }}
PR_CHECKER_PATH: ".github/pr-title-checker-config.json"
- JDK_VERSION: 11
+ JDK_VERSION: 17
BUILD_COMMANDS: mvn clean install;
- DOCKER_EAP_IMAGE_BASE_NAME: entando/entando-de-app-eap
DOCKER_TOMCAT_IMAGE_BASE_NAME: entando/entando-de-app-tomcat
- DOCKER_WILDFLY_IMAGE_BASE_NAME: entando/entando-de-app-wildfly
- DOCKER_EAP-WILDFLY_IMAGE_ARCHITECTURE: linux/amd64
DOCKER_TOMCAT_IMAGE_ARCHITECTURE: linux/amd64,linux/arm64
DOCKER_IMAGE_CONTEXT: .
- DOCKER_EAP_IMAGE_FILE: Dockerfile.eap
DOCKER_TOMCAT_IMAGE_FILE: Dockerfile.tomcat
- DOCKER_WILDFLY_IMAGE_FILE: Dockerfile.wildfly
DOCKER_IMAGE_PUSH: true
jobs:
@@ -58,23 +53,6 @@ jobs:
- name: Build with Maven
run: ${{ env.BUILD_COMMANDS }}
- - name: Docker meta-eap
- id: meta-eap
- uses: docker/metadata-action@v4
- with:
- images: |
- ${{ env.DOCKER_EAP_IMAGE_BASE_NAME }}
- tags: |
- type=schedule
- type=ref,event=branch
- type=ref,event=pr,value={{base_ref}}
- type=ref,event=tag
- type=semver,pattern={{version}}
- type=semver,pattern={{major}}.{{minor}}
- type=semver,pattern={{major}}
- type=sha
- type=raw,event=pr,value={{base_ref}}
-
- name: Docker meta-tomcat
id: meta-tomcat
uses: docker/metadata-action@v4
@@ -92,23 +70,6 @@ jobs:
type=sha
type=raw,event=pr,value={{base_ref}}
- - name: Docker meta-wildfly
- id: meta-wildfly
- uses: docker/metadata-action@v4
- with:
- images: |
- ${{ env.DOCKER_WILDFLY_IMAGE_BASE_NAME }}
- tags: |
- type=schedule
- type=ref,event=branch
- type=ref,event=pr,value={{base_ref}}
- type=ref,event=tag
- type=semver,pattern={{version}}
- type=semver,pattern={{major}}.{{minor}}
- type=semver,pattern={{major}}
- type=sha
- type=raw,event=pr,value={{base_ref}}
-
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
@@ -130,16 +91,6 @@ jobs:
username: ${{ secrets.ENTANDO_RHT_DOCKER_USERNAME }}
password: ${{ secrets.ENTANDO_RHT_DOCKER_PASSWORD }}
- - name: Build and push eap Docker image
- uses: docker/build-push-action@v4
- with:
- context: ${{ env.DOCKER_IMAGE_CONTEXT }}
- file: ${{ env.DOCKER_EAP_IMAGE_FILE }}
- push: ${{ env.DOCKER_IMAGE_PUSH }}
- tags: ${{ steps.meta-eap.outputs.tags }}
- labels: ${{ steps.meta-eap.outputs.labels }}
- platforms: ${{ env.DOCKER_EAP-WILDFLY_IMAGE_ARCHITECTURE }}
-
- name: Build tomcat Docker image for amd64
uses: docker/build-push-action@v4
with:
@@ -168,14 +119,4 @@ jobs:
push: ${{ env.DOCKER_IMAGE_PUSH }}
tags: ${{ steps.meta-tomcat.outputs.tags }}
labels: ${{ steps.meta-tomcat.outputs.labels }}
- platforms: ${{ env.DOCKER_TOMCAT_IMAGE_ARCHITECTURE }}
-
- - name: Build and push wildfly Docker image
- uses: docker/build-push-action@v4
- with:
- context: ${{ env.DOCKER_IMAGE_CONTEXT }}
- file: ${{ env.DOCKER_WILDFLY_IMAGE_FILE }}
- push: ${{ env.DOCKER_IMAGE_PUSH }}
- tags: ${{ steps.meta-wildfly.outputs.tags }}
- labels: ${{ steps.meta-wildfly.outputs.labels }}
- platforms: ${{ env.DOCKER_EAP-WILDFLY_IMAGE_ARCHITECTURE }}
\ No newline at end of file
+ platforms: ${{ env.DOCKER_TOMCAT_IMAGE_ARCHITECTURE }}
\ No newline at end of file
diff --git a/Dockerfile.eap b/Dockerfile.eap
deleted file mode 100644
index df815cde69..0000000000
--- a/Dockerfile.eap
+++ /dev/null
@@ -1,20 +0,0 @@
-FROM registry.hub.docker.com/entando/entando-eap73-clustered-base:7.2.0
-ARG VERSION
-
-### Required OpenShift Labels
-LABEL name="Entando App" \
- maintainer="dev@entando.com" \
- vendor="Entando Inc." \
- version="${VERSION}" \
- release="7.3.0" \
- summary="Entando Application" \
- description="This Entando app engine application provides APIs and composition for Entando applications"
-
-COPY target/generated-resources/licenses /licenses
-COPY target/generated-resources/licenses.xml /
-
-COPY webapp/target/*.war /opt/eap/standalone/deployments/
-
-RUN $ENTANDO_COMMON_PATH/init-derby-from-war.sh
-
-RUN rm -rf /tmp/*.jpg
diff --git a/Dockerfile.tomcat b/Dockerfile.tomcat
index ddd8d6463a..8eb796f981 100644
--- a/Dockerfile.tomcat
+++ b/Dockerfile.tomcat
@@ -1,4 +1,4 @@
-FROM registry.hub.docker.com/entando/entando-tomcat-base:7.3.0
+FROM registry.hub.docker.com/entando/entando-tomcat-base:v7.3.1-ENG-5347-PR-29-BB-release-2F-7.3
ARG VERSION
### Required OpenShift Labels
@@ -6,7 +6,7 @@ LABEL name="Entando App" \
maintainer="dev@entando.com" \
vendor="Entando Inc." \
version="${VERSION}" \
- release="7.3.0" \
+ release="7.3.1" \
summary="Entando Application" \
description="This Entando app engine application provides APIs and composition for Entando applications"
diff --git a/Dockerfile.wildfly b/Dockerfile.wildfly
deleted file mode 100644
index ee27854dce..0000000000
--- a/Dockerfile.wildfly
+++ /dev/null
@@ -1,21 +0,0 @@
-FROM registry.hub.docker.com/entando/entando-wildfly17-base:7.2.0
-
-ARG VERSION
-
-### Required OpenShift Labels
-LABEL name="Entando App" \
- maintainer="dev@entando.com" \
- vendor="Entando Inc." \
- version="${VERSION}" \
- release="7.3.0" \
- summary="Entando Application" \
- description="This Entando app engine application provides APIs and composition for Entando applications"
-
-COPY target/generated-resources/licenses /licenses
-COPY target/generated-resources/licenses.xml /
-
-COPY webapp/target/*.war /wildfly/standalone/deployments/
-
-RUN $ENTANDO_COMMON_PATH/init-derby-from-war.sh
-
-RUN rm -rf /tmp/*.jpg
diff --git a/admin-console/pom.xml b/admin-console/pom.xml
index b8cb5051bf..4054735eb6 100644
--- a/admin-console/pom.xml
+++ b/admin-console/pom.xml
@@ -4,7 +4,7 @@
org.entando
app-engine
- 7.3.0
+ 7.3.1
org.entando.entando
entando-admin-console
diff --git a/admin-console/src/main/webapp/404.jsp b/admin-console/src/main/webapp/404.jsp
deleted file mode 100644
index 7788f7683e..0000000000
--- a/admin-console/src/main/webapp/404.jsp
+++ /dev/null
@@ -1 +0,0 @@
-<%@ page isErrorPage="true" %>
diff --git a/admin-console/src/main/webapp/META-INF/MANIFEST.MF b/admin-console/src/main/webapp/META-INF/MANIFEST.MF
deleted file mode 100644
index 5e9495128c..0000000000
--- a/admin-console/src/main/webapp/META-INF/MANIFEST.MF
+++ /dev/null
@@ -1,3 +0,0 @@
-Manifest-Version: 1.0
-Class-Path:
-
diff --git a/admin-console/src/main/webapp/META-INF/context.xml b/admin-console/src/main/webapp/META-INF/context.xml
deleted file mode 100644
index 5bee3dc30f..0000000000
--- a/admin-console/src/main/webapp/META-INF/context.xml
+++ /dev/null
@@ -1,2 +0,0 @@
-
-
diff --git a/admin-console/src/main/webapp/error.jsp b/admin-console/src/main/webapp/error.jsp
index 8bec65d6fd..dfa5b9dfd5 100644
--- a/admin-console/src/main/webapp/error.jsp
+++ b/admin-console/src/main/webapp/error.jsp
@@ -12,14 +12,14 @@
- Entando - Error
+ Error
administration/bootstrap/css/bootstrap.min.css" media="screen" />
-
Entando - Error
+
Error
Go to Home
diff --git a/admin-console/src/main/webapp/index.jsp b/admin-console/src/main/webapp/index.jsp
deleted file mode 100644
index 5e557b0dca..0000000000
--- a/admin-console/src/main/webapp/index.jsp
+++ /dev/null
@@ -1,4 +0,0 @@
-<%@ taglib uri="/aps-core" prefix="wp" %>
-
-
-
\ No newline at end of file
diff --git a/admin-console/src/main/webapp/logout.jsp b/admin-console/src/main/webapp/logout.jsp
index 5e4db796a1..5e557b0dca 100644
--- a/admin-console/src/main/webapp/logout.jsp
+++ b/admin-console/src/main/webapp/logout.jsp
@@ -1,3 +1,4 @@
<%@ taglib uri="/aps-core" prefix="wp" %>
-
-
\ No newline at end of file
+
+
+
\ No newline at end of file
diff --git a/cds-plugin/pom.xml b/cds-plugin/pom.xml
index 9932ad875e..3e8185da63 100644
--- a/cds-plugin/pom.xml
+++ b/cds-plugin/pom.xml
@@ -5,7 +5,7 @@
org.entando
app-engine
- 7.3.0
+ 7.3.1
entando-plugin-jpcds
org.entando.entando.plugins
diff --git a/cds-plugin/src/main/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsConfiguration.java b/cds-plugin/src/main/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsConfiguration.java
index 331f74992e..e812a28b97 100644
--- a/cds-plugin/src/main/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsConfiguration.java
+++ b/cds-plugin/src/main/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsConfiguration.java
@@ -26,7 +26,7 @@
@Component
@CdsActive(true)
public class CdsConfiguration {
-
+
@Value("${resourceRootURL}")
private String baseURL;
@Value("${resourceDiskRootFolder}")
@@ -39,6 +39,10 @@ public class CdsConfiguration {
private boolean enabled;
@Value("${CDS_PUBLIC_URL:https://cds.entando.org}")
private String cdsPublicUrl;
+ @Value("${CDS_PUBLIC_PATH:}")
+ private String cdsPublicPath;
+ @Value("${CDS_INTERNAL_PUBLIC_SECTION:}")
+ private String cdsInternalPublicSection;
@Value("${CDS_PRIVATE_URL:https://cds.entando.org}")
private String cdsPrivateUrl;
@Value("${CDS_PATH:/api/v1}")
@@ -51,6 +55,5 @@ public class CdsConfiguration {
private String kcClientId;
@Value("${KEYCLOAK_CLIENT_SECRET:}")
private String kcClientSecret;
-
-
+
}
diff --git a/cds-plugin/src/main/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsRemoteCaller.java b/cds-plugin/src/main/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsRemoteCaller.java
index f017474496..17eba2842a 100644
--- a/cds-plugin/src/main/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsRemoteCaller.java
+++ b/cds-plugin/src/main/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsRemoteCaller.java
@@ -64,7 +64,8 @@ public class CdsRemoteCaller {
private Map tenantsToken = new WeakHashMap<>();
@Autowired
- public CdsRemoteCaller(@Qualifier("keycloakRestTemplate")RestTemplate restTemplate,@Qualifier("keycloakRestTemplateWithRedirect")RestTemplate restTemplateWithRedirect,
+ public CdsRemoteCaller(@Qualifier("keycloakRestTemplate")RestTemplate restTemplate,
+ @Qualifier("keycloakRestTemplateWithRedirect")RestTemplate restTemplateWithRedirect,
CdsConfiguration configuration) {
this.restTemplate = restTemplate;
this.restTemplateWithRedirect = restTemplateWithRedirect;
diff --git a/cds-plugin/src/main/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsStorageManager.java b/cds-plugin/src/main/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsStorageManager.java
index 9cb0c81c2b..55969f867e 100644
--- a/cds-plugin/src/main/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsStorageManager.java
+++ b/cds-plugin/src/main/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsStorageManager.java
@@ -13,6 +13,7 @@
*/
package org.entando.entando.plugins.jpcds.aps.system.storage;
+import com.agiletec.aps.system.SystemConstants;
import com.agiletec.aps.util.ApsTenantApplicationUtils;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -23,6 +24,8 @@
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
+import lombok.AccessLevel;
+import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
@@ -41,17 +44,22 @@
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;
import org.entando.entando.aps.system.services.storage.CdsActive;
+import org.springframework.web.context.ContextLoader;
+import org.springframework.web.context.WebApplicationContext;
@Slf4j
-@Service("StorageManager")
+@Service(SystemConstants.STORAGE_MANAGER)
@CdsActive(true)
public class CdsStorageManager implements IStorageManager {
private static final String ERROR_VALIDATING_PATH_MSG = "Error validating path";
- private final transient ITenantManager tenantManager;
- private final transient CdsConfiguration configuration;
- private final transient CdsRemoteCaller caller;
-
+
+ @Getter(AccessLevel.PROTECTED)
+ private transient ITenantManager tenantManager;
+ @Getter(AccessLevel.PROTECTED)
+ private transient CdsConfiguration configuration;
+ @Getter(AccessLevel.PROTECTED)
+ private transient CdsRemoteCaller caller;
@Autowired
public CdsStorageManager(CdsRemoteCaller caller, ITenantManager tenantManager, CdsConfiguration configuration) {
@@ -73,21 +81,18 @@ public void saveFile(String subPath, boolean isProtectedResource, InputStream is
private void create(String subPath, boolean isProtectedResource, Optional fileInputStream) {
try {
- Optional config = getTenantConfig();
+ Optional config = this.getTenantConfig();
if(StringUtils.isBlank(subPath)){
throw new EntRuntimeException(ERROR_VALIDATING_PATH_MSG);
}
-
- this.validateAndReturnResourcePath(config, subPath, isProtectedResource);
-
+ this.validateAndReturnResourcePath(config, subPath, false, isProtectedResource);
URI apiUrl = CdsUrlUtils.buildCdsInternalApiUrl(config, configuration, "/upload/");
- CdsCreateResponseDto response = caller.executePostCall(apiUrl,
+ CdsCreateResponseDto response = this.caller.executePostCall(apiUrl,
subPath,
isProtectedResource,
fileInputStream,
config,
false);
-
if (!response.isStatusOk()) {
throw new EntRuntimeException("Invalid status - Response " + response.isStatusOk());
}
@@ -106,22 +111,18 @@ public void deleteDirectory(String subPath, boolean isProtectedResource) throws
@Override
public boolean deleteFile(String subPath, boolean isProtectedResource) {
try {
- Optional config = getTenantConfig();
- if(StringUtils.isBlank(subPath)){
+ Optional config = this.getTenantConfig();
+ if (StringUtils.isBlank(subPath)){
throw new EntRuntimeException(ERROR_VALIDATING_PATH_MSG);
}
-
- this.validateAndReturnResourcePath(config, subPath, isProtectedResource);
-
+ this.validateAndReturnResourcePath(config, subPath, true, isProtectedResource);
URI apiUrl = EntUrlBuilder.builder()
.url(CdsUrlUtils.buildCdsInternalApiUrl(config, configuration))
.path("/delete/")
- .path(CdsUrlUtils.getInternalSection(isProtectedResource))
+ .path(CdsUrlUtils.getSection(isProtectedResource, config, this.configuration, true))
.path(subPath)
.build();
-
- return caller.executeDeleteCall(apiUrl, config, false);
-
+ return this.caller.executeDeleteCall(apiUrl, config, false);
} catch (EntRuntimeException ert) {
throw ert;
} catch (Exception e) {
@@ -134,32 +135,31 @@ public InputStream getStream(String subPath, boolean isProtectedResource) throws
final String ERROR_EXTRACTING_FILE = "Error extracting file";
URI url = null;
try {
- Optional config = getTenantConfig();
- if(StringUtils.isBlank(subPath)){
+ Optional config = this.getTenantConfig();
+ if (StringUtils.isBlank(subPath)) {
throw new EntRuntimeException(ERROR_VALIDATING_PATH_MSG);
}
-
- this.validateAndReturnResourcePath(config, subPath, isProtectedResource);
-
+ if (!this.exists(subPath, isProtectedResource)) {
+ throw new EntResourceNotFoundException(
+ String.format("File \"%s\", protected \"%s\", Not Found", subPath, isProtectedResource));
+ }
+ this.validateAndReturnResourcePath(config, subPath, true, isProtectedResource);
url = (isProtectedResource) ?
CdsUrlUtils.buildCdsInternalApiUrl(config, configuration) :
CdsUrlUtils.buildCdsExternalPublicResourceUrl(config, configuration);
-
url = EntUrlBuilder.builder()
.url(url)
- .path(CdsUrlUtils.getInternalSection(isProtectedResource))
+ .path(CdsUrlUtils.getSection(isProtectedResource, config, this.configuration, true))
.path(subPath).build();
-
Optional is = caller.getFile(url, config, isProtectedResource);
- return is.orElseThrow(IOException::new);
-
- } catch (EntRuntimeException ert) {
+ return is.orElse(new ByteArrayInputStream(new byte[0]));
+ } catch (EntResourceNotFoundException | EntRuntimeException ert) {
throw ert;
} catch (HttpClientErrorException e) {
if (e.getStatusCode().equals(HttpStatus.NOT_FOUND)) {
log.info("File Not found - uri {}", url);
return null;
- }
+ }
throw new EntResourceNotFoundException(ERROR_EXTRACTING_FILE, e);
} catch (Exception e) {
throw new EntResourceNotFoundException(ERROR_EXTRACTING_FILE, e);
@@ -169,8 +169,8 @@ public InputStream getStream(String subPath, boolean isProtectedResource) throws
@Override
public String getResourceUrl(String subPath, boolean isProtectedResource) {
try {
- Optional config = getTenantConfig();
- return this.validateAndReturnResourcePath(config, subPath, isProtectedResource);
+ Optional config = this.getTenantConfig();
+ return this.validateAndReturnResourcePath(config, subPath, false, isProtectedResource);
} catch (Exception e) {
throw new EntRuntimeException("Error extracting resource url", e);
}
@@ -185,7 +185,7 @@ public boolean exists(String subPath, boolean isProtectedResource) {
// when frontend wants to retrieve public or protected folder contents it gets request with an empty subpath
private boolean isSubPathPresent(String[] filenames, String subPath){
- if(StringUtils.isEmpty(subPath)) {
+ if (StringUtils.isEmpty(subPath)) {
return filenames.length > 0;
} else {
return Arrays.asList(filenames).contains(subPath);
@@ -240,15 +240,15 @@ public BasicFileAttributeView[] listFileAttributes(String subPath, boolean isPro
private List listAttributes(String subPath, boolean isProtectedResource, CdsFilter filter) {
Optional config = this.getTenantConfig();
- this.validateAndReturnResourcePath(config, subPath, isProtectedResource);
+ this.validateAndReturnResourcePath(config, subPath, true, isProtectedResource);
URI apiUrl = EntUrlBuilder.builder()
.url(CdsUrlUtils.buildCdsInternalApiUrl(config, configuration).toString())
.path("/list/")
- .path(CdsUrlUtils.getInternalSection(isProtectedResource))
+ .path(CdsUrlUtils.getSection(isProtectedResource, config, this.configuration, true))
.path(subPath)
.build();
-
+
Optional cdsFileList = caller.getFileAttributeView(apiUrl, config);
return remapAndSort(cdsFileList, filter);
@@ -310,22 +310,19 @@ private Optional getTenantConfig() {
}
- private String validateAndReturnResourcePath(Optional config, String resourceRelativePath, boolean privateUrl) {
+ private String validateAndReturnResourcePath(Optional config, String resourceRelativePath, boolean privateCall, boolean privateUrl) {
try {
String baseUrl = EntUrlBuilder.builder()
.url(CdsUrlUtils.fetchBaseUrl(config, configuration, privateUrl))
- .path(CdsUrlUtils.getInternalSection(privateUrl)) // << this is part of base url because we want check path traversal!!
+ .path(CdsUrlUtils.getSection(privateUrl, config, this.configuration, privateCall))
.build().toString();
-
String fullPath = EntUrlBuilder.builder()
.url(baseUrl)
.path(resourceRelativePath)
.build().toString();
-
if (!StorageManagerUtil.doesPathContainsPath(baseUrl, fullPath, true)) {
throw mkPathValidationErr(baseUrl, fullPath);
}
-
return fullPath;
} catch (IOException e) {
throw new EntRuntimeException(ERROR_VALIDATING_PATH_MSG, e);
@@ -355,4 +352,18 @@ public enum CdsFilter {
DIRECTORY,
ALL;
}
+
+ private void readObject(java.io.ObjectInputStream in)
+ throws IOException, ClassNotFoundException {
+ in.defaultReadObject();
+ WebApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext();
+ if (ctx == null) {
+ log.warn("Null WebApplicationContext during deserialization");
+ return;
+ }
+ this.tenantManager = ctx.getBean(ITenantManager.class);
+ this.configuration = ctx.getBean(CdsConfiguration.class);
+ this.caller = ctx.getBean(CdsRemoteCaller.class);
+ }
+
}
diff --git a/cds-plugin/src/main/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsUrlUtils.java b/cds-plugin/src/main/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsUrlUtils.java
index b62d3d5a47..8171c94549 100644
--- a/cds-plugin/src/main/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsUrlUtils.java
+++ b/cds-plugin/src/main/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsUrlUtils.java
@@ -29,28 +29,34 @@ public final class CdsUrlUtils {
private static final String CDS_PUBLIC_URL_TENANT_PARAM = "cdsPublicUrl";
private static final String CDS_PRIVATE_URL_TENANT_PARAM = "cdsPrivateUrl";
+ private static final String CDS_PUBLIC_PATH_TENANT_PARAM = "cdsPublicPath";
+ private static final String CDS_INTERNAL_PUBLIC_SECTION_TENANT_PARAM = "cdsInternalPublicSection";
private static final String CDS_PATH_TENANT_PARAM = "cdsPath";
private static final String URL_SEP = "/";
- private static final String SECTION_PUBLIC = "/public";
- private static final String SECTION_PRIVATE = "/protected";
+ private static final String DEFAULT_SECTION_PUBLIC = "";
+ private static final String DEFAULT_SECTION_PRIVATE = "/protected";
private CdsUrlUtils(){
}
-
- public static String getInternalSection(boolean isProtectedResource) {
- return (isProtectedResource) ? SECTION_PRIVATE : SECTION_PUBLIC;
+
+ public static String getSection(boolean isProtectedResource, Optional config, CdsConfiguration configuration, boolean internalCall) {
+ if (isProtectedResource) {
+ return DEFAULT_SECTION_PRIVATE;
+ }
+ if (internalCall) {
+ return config.map(c -> c.getProperty(CDS_INTERNAL_PUBLIC_SECTION_TENANT_PARAM).orElse(DEFAULT_SECTION_PUBLIC)).orElse(configuration.getCdsInternalPublicSection());
+ } else {
+ return config.map(c -> c.getProperty(CDS_PUBLIC_PATH_TENANT_PARAM).orElse(DEFAULT_SECTION_PUBLIC)).orElse(configuration.getCdsPublicPath());
+ }
}
-
+
public static URI buildCdsExternalPublicResourceUrl(Optional config, CdsConfiguration configuration, String ... paths){
log.debug("Trying to build CDS external public url with is tenant config empty:'{}', CDS primary configuration public url:'{}' and paths:'{}'",
config.isEmpty(),
configuration.getCdsPublicUrl(),
paths);
-
String publicUrl = config.flatMap(c -> c.getProperty(CDS_PUBLIC_URL_TENANT_PARAM)).orElse(configuration.getCdsPublicUrl());
-
return EntUrlBuilder.builder().url(publicUrl).paths(paths).build();
-
}
public static URI buildCdsInternalApiUrl(Optional config, CdsConfiguration configuration, String ... paths){
@@ -59,10 +65,8 @@ public static URI buildCdsInternalApiUrl(Optional config, CdsConfi
configuration.getCdsPrivateUrl(),
configuration.getCdsPath(),
paths);
-
String apiUrl = config.flatMap(c -> c.getProperty(CDS_PRIVATE_URL_TENANT_PARAM)).orElse(configuration.getCdsPrivateUrl());
String basePath = config.flatMap(c -> c.getProperty(CDS_PATH_TENANT_PARAM)).orElse(configuration.getCdsPath());
-
return EntUrlBuilder.builder().url(apiUrl).path(basePath).paths(paths).build();
}
diff --git a/cds-plugin/src/test/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsConfigurationTest.java b/cds-plugin/src/test/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsConfigurationTest.java
index 13a9e0f698..5fff824a7f 100644
--- a/cds-plugin/src/test/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsConfigurationTest.java
+++ b/cds-plugin/src/test/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsConfigurationTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2022-Present Entando S.r.l. (http://www.entando.com) All rights reserved.
+ * Copyright 2024-Present Entando S.r.l. (http://www.entando.com) All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
@@ -15,7 +15,6 @@
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
-import org.springframework.beans.factory.annotation.Value;
class CdsConfigurationTest {
diff --git a/cds-plugin/src/test/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsCreateRowResponseDtoTest.java b/cds-plugin/src/test/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsCreateRowResponseDtoTest.java
index 7cc7c9c467..f0819dc938 100644
--- a/cds-plugin/src/test/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsCreateRowResponseDtoTest.java
+++ b/cds-plugin/src/test/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsCreateRowResponseDtoTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2022-Present Entando S.r.l. (http://www.entando.com) All rights reserved.
+ * Copyright 2024-Present Entando S.r.l. (http://www.entando.com) All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
@@ -13,7 +13,6 @@
*/
package org.entando.entando.plugins.jpcds.aps.system.storage;
-
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
diff --git a/cds-plugin/src/test/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsFileAttributeViewDtoTest.java b/cds-plugin/src/test/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsFileAttributeViewDtoTest.java
index c87b6212a2..51f636938f 100644
--- a/cds-plugin/src/test/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsFileAttributeViewDtoTest.java
+++ b/cds-plugin/src/test/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsFileAttributeViewDtoTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2022-Present Entando S.r.l. (http://www.entando.com) All rights reserved.
+ * Copyright 2024-Present Entando S.r.l. (http://www.entando.com) All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
@@ -13,13 +13,11 @@
*/
package org.entando.entando.plugins.jpcds.aps.system.storage;
-
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
-import lombok.ToString;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
diff --git a/cds-plugin/src/test/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsRemoteCallerTest.java b/cds-plugin/src/test/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsRemoteCallerTest.java
index 3e3d392740..28c137c812 100644
--- a/cds-plugin/src/test/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsRemoteCallerTest.java
+++ b/cds-plugin/src/test/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsRemoteCallerTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015-Present Entando Inc. (http://www.entando.com) All rights reserved.
+ * Copyright 2024-Present Entando Inc. (http://www.entando.com) All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
@@ -31,10 +31,7 @@
import org.apache.commons.io.IOUtils;
import org.entando.entando.aps.system.services.tenants.TenantConfig;
import org.entando.entando.ent.exception.EntRuntimeException;
-import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
diff --git a/cds-plugin/src/test/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsStorageManagerTest.java b/cds-plugin/src/test/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsStorageManagerTest.java
index 3e4e0a483c..3323a9ed93 100644
--- a/cds-plugin/src/test/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsStorageManagerTest.java
+++ b/cds-plugin/src/test/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsStorageManagerTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015-Present Entando Inc. (http://www.entando.com) All rights reserved.
+ * Copyright 2024-Present Entando Inc. (http://www.entando.com) All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
@@ -35,6 +35,7 @@
import org.entando.entando.aps.system.services.tenants.ITenantManager;
import org.entando.entando.aps.system.services.tenants.TenantConfig;
import org.entando.entando.ent.exception.EntException;
+import org.entando.entando.ent.exception.EntResourceNotFoundException;
import org.entando.entando.ent.exception.EntRuntimeException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -226,6 +227,8 @@ void shouldManageErrorWhenCallGetStream() throws Exception {
final String baseUrl = "http://my-server/tenant1/cms-resources";
Map configMap = Map.of("cdsPublicUrl", baseUrl,
"cdsPrivateUrl","http://cds-kube-service:8081/",
+ "cdsPublicPath","/custom-path",
+ "cdsInternalPublicSection", "/custom-path",
"cdsPath","/mytenant/api/v1/");
TenantConfig tc = new TenantConfig(configMap);
Mockito.when(tenantManager.getConfig("my-tenant")).thenReturn(Optional.ofNullable(tc));
@@ -236,17 +239,22 @@ void shouldManageErrorWhenCallGetStream() throws Exception {
).isInstanceOf(EntRuntimeException.class).hasMessageStartingWith("Error validating path");
String testFilePath = "/testfolder/test.txt";
- URI testFile = URI.create( baseUrl + "/public" + testFilePath);
+
+ Assertions.assertThatThrownBy(
+ ()-> cdsStorageManager.getStream(testFilePath, false)
+ ).isInstanceOf(EntResourceNotFoundException.class).hasMessageStartingWith("File \"" + testFilePath);
+
+ URI testFile = URI.create( baseUrl + "/custom-path" + testFilePath);
+ this.mockExecuteListFolder("http://cds-kube-service:8081/mytenant/api/v1/list/protected/testfolder", "test.txt");
Mockito.when(cdsRemoteCaller.getFile(eq(testFile),
any(),
eq(false))).thenReturn(null);
Assertions.assertThatThrownBy(
()-> cdsStorageManager.getStream(testFilePath,false)
- ).isInstanceOf(EntException.class).hasMessageStartingWith("Error extracting file");
-
-
+ ).isInstanceOf(EntResourceNotFoundException.class).hasMessageStartingWith("Error extracting file");
+
String testFilePathBadGateway = "/testfolder/test-badgw.txt";
- URI testFileBadGateway = URI.create( baseUrl + "/public" + testFilePathBadGateway);
+ URI testFileBadGateway = URI.create( baseUrl + "/custom-path" + testFilePathBadGateway);
Mockito.when(cdsRemoteCaller.getFile(eq(testFileBadGateway),
any(),
eq(false))).thenThrow(new HttpClientErrorException(HttpStatus.BAD_GATEWAY));
@@ -255,15 +263,9 @@ void shouldManageErrorWhenCallGetStream() throws Exception {
()-> cdsStorageManager.getStream(testFilePathBadGateway,false)
).isInstanceOf(EntException.class).hasMessageStartingWith("Error extracting file");
-
String testFilePathNotFound = "/testfolder/test-notfound.txt";
- URI testFileNotFound = URI.create( baseUrl + "/public" + testFilePathNotFound);
- Mockito.when(cdsRemoteCaller.getFile(eq(testFileNotFound),
- any(),
- eq(false))).thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND));
-
- Assertions.assertThat(cdsStorageManager.getStream(testFilePathNotFound,false)).isNull();
-
+ Assertions.assertThatThrownBy(() -> cdsStorageManager.getStream(testFilePathNotFound,false))
+ .isInstanceOf(EntResourceNotFoundException.class).hasMessageStartingWith("Error extracting file");
}
@Test
@@ -275,32 +277,33 @@ void shouldReturnDataWhenCallGetStream() throws Exception {
"cdsPath","/mytenant/api/v1/");
TenantConfig tc = new TenantConfig(configMap);
Mockito.when(tenantManager.getConfig("my-tenant")).thenReturn(Optional.ofNullable(tc));
-
- Mockito.when(cdsRemoteCaller.getFile(eq(URI.create("http://my-server/tenant1/cms-resources/public/test-folder/test.txt")),
+
+ Mockito.when(cdsRemoteCaller.getFile(eq(URI.create("http://my-server/tenant1/cms-resources/test-folder/test.txt")),
any(),
eq(false))).thenReturn(Optional.ofNullable(new ByteArrayInputStream("text random".getBytes(StandardCharsets.UTF_8))));
-
+
+ this.mockExecuteListFolder("http://cds-kube-service:8081/mytenant/api/v1/list/test-folder", "test.txt");
ApsTenantApplicationUtils.setTenant("my-tenant");
InputStream is = cdsStorageManager.getStream(testFilePath,false);
Assertions.assertThat(new BufferedReader(new InputStreamReader(is))
.lines().collect(Collectors.joining(""))).isEqualTo("text random");
-
+
Mockito.when(cdsRemoteCaller.getFile(eq(URI.create("http://cds-kube-service:8081/mytenant/api/v1/protected/test-folder/test.txt")),
any(),
eq(true))).thenReturn(Optional.ofNullable(new ByteArrayInputStream("text random".getBytes(StandardCharsets.UTF_8))));
-
+
+ this.mockExecuteListFolder("http://cds-kube-service:8081/mytenant/api/v1/list/protected/test-folder", "test.txt");
is = cdsStorageManager.getStream(testFilePath,true);
Assertions.assertThat(new BufferedReader(new InputStreamReader(is))
.lines().collect(Collectors.joining(""))).isEqualTo("text random");
-
}
@Test
void shouldReturnRightUrlWhenCallGetResourceUrl() throws Exception {
String testFilePath = "/test-folder/test.txt";
-
Map configMap = Map.of("cdsPublicUrl","http://my-server/tenant1/cms-resources",
"cdsPrivateUrl","http://cds-tenant1-kube-service:8081/",
+ "cdsPublicPath","/public",
"cdsPath","/mytenant/api/v1/");
TenantConfig tc = new TenantConfig(configMap);
Mockito.when(tenantManager.getConfig("my-tenant")).thenReturn(Optional.ofNullable(tc));
@@ -314,7 +317,6 @@ void shouldReturnRightUrlWhenCallGetResourceUrl() throws Exception {
resourceUrl = cdsStorageManager.createFullPath(testFilePath,true);
Assertions.assertThat(resourceUrl).isEqualTo("http://cds-tenant1-kube-service:8081/protected/test-folder/test.txt");
-
}
@Test
@@ -359,15 +361,15 @@ void shouldWorkFineWhenCallExists() throws Exception {
"http://cds-tenant1-kube-service:8081/mytenant/api/v1/list/protected/test-folder")),
any())).thenReturn(Optional.ofNullable(new CdsFileAttributeViewDto[]{file}));
Assertions.assertThat(cdsStorageManager.exists(testFilePath,true)).isTrue();
-
}
@Test
void shouldWorkFineWhenCallExistsWithRootAsEmpty() throws Exception {
String testFilePath = "";
-
Map configMap = Map.of("cdsPublicUrl","http://my-server/tenant1/cms-resources",
"cdsPrivateUrl","http://cds-tenant1-kube-service:8081/",
+ "cdsPublicPath","/public",
+ "cdsInternalPublicSection", "/public",
"cdsPath","/mytenant/api/v1/");
TenantConfig tc = new TenantConfig(configMap);
Mockito.when(tenantManager.getConfig("my-tenant")).thenReturn(Optional.ofNullable(tc));
@@ -467,7 +469,7 @@ void shouldReadFile() throws Exception {
String testFilePath = "/testfolder/test.txt";
Map configMap = Map.of("cdsPublicUrl","http://my-server/tenant1/cms-resources",
- "cdsPrivateUrl","http://cds-kube-service:8081/",
+ "cdsPrivateUrl","http://cdsmaster-kube-service:8081/",
"cdsPath","/mytenant/api/v1/");
TenantConfig tc = new TenantConfig(configMap);
Mockito.when(tenantManager.getConfig("my-tenant")).thenReturn(Optional.ofNullable(tc));
@@ -475,8 +477,9 @@ void shouldReadFile() throws Exception {
Mockito.when(cdsRemoteCaller.getFile(any(),
any(),
eq(false))).thenReturn(Optional.ofNullable(new ByteArrayInputStream("text random".getBytes(StandardCharsets.UTF_8))));
-
-
+
+ this.mockExecuteListFolder("http://cdsmaster-kube-service:8081/mytenant/api/v1/list/testfolder", "test.txt");
+
ApsTenantApplicationUtils.setTenant("my-tenant");
Assertions.assertThat(cdsStorageManager.readFile(testFilePath,false))
.isEqualTo("text random");
@@ -484,7 +487,7 @@ void shouldReadFile() throws Exception {
@Test
void shouldManageExceptionWhenReadFile() throws Exception {
- String testFilePath = "/testfolder/test.txt";
+ String testFilePath = "/testfolder/subfolder/test.txt";
Map configMap = Map.of("cdsPublicUrl","http://my-server/tenant1/cms-resources",
"cdsPrivateUrl","http://cds-kube-service:8081/",
@@ -501,7 +504,7 @@ void shouldManageExceptionWhenReadFile() throws Exception {
try (MockedStatic ioUtils = Mockito.mockStatic(IOUtils.class)) {
ioUtils.when(() -> IOUtils.toString(any(InputStream.class), eq(StandardCharsets.UTF_8)))
.thenThrow(new IOException());
-
+ this.mockExecuteListFolder("http://cds-kube-service:8081/mytenant/api/v1/list/testfolder/subfolder", "test.txt");
Assertions.assertThatThrownBy(() -> cdsStorageManager.readFile(testFilePath, false))
.isInstanceOf(EntException.class)
.hasMessageStartingWith("Error extracting text");
@@ -586,5 +589,12 @@ void testListAttributes() throws Throwable {
}
assertTrue(containsCms);
}
+
+ private void mockExecuteListFolder(String uri, String filename) {
+ CdsFileAttributeViewDto file = new CdsFileAttributeViewDto();
+ file.setName(filename);
+ Mockito.when(cdsRemoteCaller.getFileAttributeView(eq(URI.create(uri)),
+ any())).thenReturn(Optional.ofNullable(new CdsFileAttributeViewDto[]{file}));
+ }
}
diff --git a/cds-plugin/src/test/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsStorageSerializationIntegrationTest.java b/cds-plugin/src/test/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsStorageSerializationIntegrationTest.java
new file mode 100644
index 0000000000..3cfd6d4236
--- /dev/null
+++ b/cds-plugin/src/test/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsStorageSerializationIntegrationTest.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2024-Present Entando Inc. (http://www.entando.com) All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ */
+package org.entando.entando.plugins.jpcds.aps.system.storage;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import org.entando.entando.aps.system.services.tenants.ITenantManager;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.web.client.RestTemplate;
+import org.springframework.web.context.ContextLoader;
+import org.springframework.web.context.WebApplicationContext;
+
+@ExtendWith(MockitoExtension.class)
+class CdsStorageSerializationIntegrationTest {
+
+ private CdsStorageManager cdsStorageManager;
+
+ @BeforeEach
+ public void init() {
+ CdsRemoteCaller cdsRemoteCaller = new CdsRemoteCaller(Mockito.mock(RestTemplate.class),
+ Mockito.mock(RestTemplate.class), Mockito.mock(CdsConfiguration.class));
+ cdsStorageManager = new CdsStorageManager(cdsRemoteCaller, Mockito.mock(ITenantManager.class), Mockito.mock(CdsConfiguration.class));
+ }
+
+ @Test
+ void testSerializeStorageManager() throws Exception {
+ Assertions.assertNotNull(this.cdsStorageManager.getCaller());
+ Assertions.assertNotNull(this.cdsStorageManager.getTenantManager());
+ Assertions.assertNotNull(this.cdsStorageManager.getConfiguration());
+ CdsStorageManager badProcessed = testSerializeAndDeserializeNullApplicationContext(cdsStorageManager);
+ Assertions.assertNull(badProcessed.getCaller());
+ Assertions.assertNull(badProcessed.getTenantManager());
+ Assertions.assertNull(badProcessed.getConfiguration());
+
+ CdsStorageManager processed = testSerializeAndDeserializeMockApplicationContext(cdsStorageManager);
+ Assertions.assertNotNull(processed.getCaller());
+ Assertions.assertNotNull(processed.getTenantManager());
+ Assertions.assertNotNull(processed.getConfiguration());
+ }
+
+ private T testSerializeAndDeserializeNullApplicationContext(T object) throws Exception {
+ try (MockedStatic contextLoader = Mockito.mockStatic(ContextLoader.class)) {
+ contextLoader.when(() -> ContextLoader.getCurrentWebApplicationContext()).thenReturn(null);
+ return testSerializeAndDeserialize(object);
+ }
+ }
+
+ private T testSerializeAndDeserializeMockApplicationContext(T object) throws Exception {
+ try (MockedStatic contextLoader = Mockito.mockStatic(ContextLoader.class)) {
+ WebApplicationContext ctx = Mockito.mock(WebApplicationContext.class);
+ contextLoader.when(() -> ContextLoader.getCurrentWebApplicationContext()).thenReturn(ctx);
+ Mockito.when(ctx.getBean(ITenantManager.class)).thenReturn(Mockito.mock(ITenantManager.class));
+ Mockito.when(ctx.getBean(CdsConfiguration.class)).thenReturn(Mockito.mock(CdsConfiguration.class));
+ Mockito.when(ctx.getBean(CdsRemoteCaller.class)).thenReturn(Mockito.mock(CdsRemoteCaller.class));
+ return testSerializeAndDeserialize(object);
+ }
+ }
+
+ private T testSerializeAndDeserialize(T object) throws Exception {
+ byte[] data;
+ try (ByteArrayOutputStream os = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(os)) {
+ objectOutputStream.writeObject(object);
+ data = os.toByteArray();
+ }
+ try (ByteArrayInputStream is = new ByteArrayInputStream(data); ObjectInputStream objectInputStream = new ObjectInputStream(is)) {
+ return (T) objectInputStream.readObject();
+ }
+ }
+
+}
diff --git a/cds-plugin/src/test/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsUtilsTest.java b/cds-plugin/src/test/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsUtilsTest.java
index 241852a10a..d80e050fad 100644
--- a/cds-plugin/src/test/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsUtilsTest.java
+++ b/cds-plugin/src/test/java/org/entando/entando/plugins/jpcds/aps/system/storage/CdsUtilsTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015-Present Entando Inc. (http://www.entando.com) All rights reserved.
+ * Copyright 2023-Present Entando Inc. (http://www.entando.com) All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
@@ -13,30 +13,24 @@
*/
package org.entando.entando.plugins.jpcds.aps.system.storage;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import org.entando.entando.aps.system.services.tenants.TenantConfig;
import org.entando.entando.plugins.jpcds.aps.system.storage.CdsUrlUtils.EntSubPath;
-import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
@ExtendWith(MockitoExtension.class)
class CdsUtilsTest {
- @BeforeEach
- private void init() throws Exception {
- }
-
- @AfterEach
- public void afterAll() throws Exception {
- }
-
@Test
void shouldExtractPathAndFilename() throws Exception {
EntSubPath subPath = CdsUrlUtils.extractPathAndFilename("/folder1/folder2/file.txt");
Assertions.assertEquals("file.txt", subPath.getFileName());
- //Assertions.assertEquals("folder1/folder2/", subPath.getPath());
Assertions.assertEquals("/folder1/folder2", subPath.getPath());
subPath = CdsUrlUtils.extractPathAndFilename("file.txt");
@@ -45,12 +39,10 @@ void shouldExtractPathAndFilename() throws Exception {
subPath = CdsUrlUtils.extractPathAndFilename("/folder/");
Assertions.assertEquals("", subPath.getFileName());
- //Assertions.assertEquals("folder/", subPath.getPath());
Assertions.assertEquals("/folder", subPath.getPath());
subPath = CdsUrlUtils.extractPathAndFilename("../../folder/file.txt");
Assertions.assertEquals("file.txt", subPath.getFileName());
- //Assertions.assertEquals("../../folder/", subPath.getPath());
Assertions.assertEquals("../../folder", subPath.getPath());
subPath = CdsUrlUtils.extractPathAndFilename("");
@@ -60,18 +52,34 @@ void shouldExtractPathAndFilename() throws Exception {
subPath = CdsUrlUtils.extractPathAndFilename(null);
Assertions.assertEquals("", subPath.getFileName());
Assertions.assertEquals("", subPath.getPath());
-
}
-
-
+
@Test
void shouldWorkFineWithToString() {
-
EntSubPath subPath1 = new EntSubPath("","my-filename");
-
EntSubPath subPath2 = new EntSubPath("","my-filename");
-
Assertions.assertEquals(subPath1.toString(),subPath2.toString());
}
+
+ @Test
+ void shouldExtractRigthSection() {
+ Assertions.assertEquals("/protected", CdsUrlUtils.getSection(true, null, null, true));
+ Assertions.assertEquals("/protected", CdsUrlUtils.getSection(true, null, Mockito.mock(CdsConfiguration.class), true));
+
+ CdsConfiguration cdsConfiguration = new CdsConfiguration();
+ cdsConfiguration.setCdsPublicPath("");
+ Assertions.assertEquals("", CdsUrlUtils.getSection(false, Optional.ofNullable(null), cdsConfiguration, false));
+
+ cdsConfiguration.setCdsPublicPath("/public");
+ Assertions.assertEquals("/public", CdsUrlUtils.getSection(false, Optional.ofNullable(null), cdsConfiguration, false));
+
+ Map tenantParams = new HashMap<>();
+ TenantConfig tenantConfig = new TenantConfig(tenantParams);
+ Assertions.assertEquals("", CdsUrlUtils.getSection(false, Optional.ofNullable(tenantConfig), cdsConfiguration, true));
+
+ tenantParams.put("cdsPublicPath", "/customPath");
+ Assertions.assertEquals("/customPath", CdsUrlUtils.getSection(false, Optional.ofNullable(tenantConfig), cdsConfiguration, false));
+ Assertions.assertEquals("/protected", CdsUrlUtils.getSection(true, Optional.ofNullable(tenantConfig), cdsConfiguration, true));
+ }
}
diff --git a/cms-plugin/README.md b/cms-plugin/README.md
index b7847bb84b..efc3b4bcf2 100644
--- a/cms-plugin/README.md
+++ b/cms-plugin/README.md
@@ -17,19 +17,6 @@ entando-plugin-jacms
CMS is a plugin that allows to registered users to manage in the Back Office dynamic contents and digital assets.
-**Installation**
-
-In order to install the CMS plugin, you must insert the following dependency in the pom.xml file of your project:
-
-```
-
- org.entando.entando.bundles.app-view
- entando-app-view-cms-default
- ${entando.version}
- war
-
-```
-
# Developing against local versions of upstream projects (e.g. admin-console, entando-engine).
Full instructions on how to develop against local versions of upstream projects are available in the
diff --git a/cms-plugin/pom.xml b/cms-plugin/pom.xml
index 632f6bf14d..3e1c51459c 100644
--- a/cms-plugin/pom.xml
+++ b/cms-plugin/pom.xml
@@ -5,7 +5,7 @@
org.entando
app-engine
- 7.3.0
+ 7.3.1
org.entando.entando.plugins
entando-plugin-jacms
diff --git a/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/content/ContentManager.java b/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/content/ContentManager.java
index b85fd127c4..1ec8ee3738 100644
--- a/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/content/ContentManager.java
+++ b/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/content/ContentManager.java
@@ -14,7 +14,6 @@
package com.agiletec.plugins.jacms.aps.system.services.content;
import com.agiletec.aps.system.ApsSystemUtils;
-import com.agiletec.aps.system.SystemConstants;
import com.agiletec.aps.system.common.entity.ApsEntityManager;
import com.agiletec.aps.system.common.entity.IEntityDAO;
import com.agiletec.aps.system.common.entity.IEntitySearcherDAO;
@@ -53,8 +52,9 @@
* Contents manager. This implements all the methods needed to create and manage
* the contents.
*/
-public class ContentManager extends ApsEntityManager
- implements IContentManager, GroupUtilizer, PageUtilizer, ContentUtilizer, ResourceUtilizer, CategoryUtilizer {
+public class ContentManager extends ApsEntityManager
+ implements IContentManager, GroupUtilizer, PageUtilizer,
+ ContentUtilizer, ResourceUtilizer, CategoryUtilizer {
private static final EntLogger logger = EntLogFactory.getSanitizedLogger(ContentManager.class);
@@ -615,7 +615,7 @@ public List getPageUtilizers(String pageCode) throws EntException {
}
@Override
- public List getContentUtilizers(String contentId) throws EntException {
+ public List getContentUtilizers(String contentId) throws EntException {
try {
return this.getContentDAO().getContentUtilizers(contentId);
} catch (Throwable t) {
@@ -633,7 +633,7 @@ public List getGroupUtilizers(String groupName) throws EntException {
}
@Override
- public List getResourceUtilizers(String resourceId) throws EntException {
+ public List getResourceUtilizers(String resourceId) throws EntException {
try {
return this.getContentDAO().getResourceUtilizers(resourceId);
} catch (Throwable t) {
@@ -642,7 +642,7 @@ public List getResourceUtilizers(String resourceId) throws EntException {
}
@Override
- public List getCategoryUtilizers(String resourceId) throws EntException {
+ public List getCategoryUtilizers(String resourceId) throws EntException {
try {
return this.getContentDAO().getCategoryUtilizers(resourceId);
} catch (Throwable t) {
@@ -661,7 +661,7 @@ public void reloadCategoryReferences(String categoryCode) {
@SuppressWarnings("rawtypes")
@Override
- public List getCategoryUtilizersForReloadReferences(String categoryCode) {
+ public List getCategoryUtilizersForReloadReferences(String categoryCode) {
List contentIdToReload = new ArrayList<>();
try {
Set contents = this.getContentUpdaterService().getContentsId(categoryCode);
diff --git a/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/content/ContentUtilizer.java b/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/content/ContentUtilizer.java
index 79528b0801..6b6faf7810 100644
--- a/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/content/ContentUtilizer.java
+++ b/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/content/ContentUtilizer.java
@@ -20,8 +20,9 @@
/**
* Basic interface for the services whose handled elements may have references to contents.
* @author E.Santoboni
+ * @param
*/
-public interface ContentUtilizer {
+public interface ContentUtilizer {
/**
* Return the ID of the utilizer service.
@@ -35,6 +36,6 @@ public interface ContentUtilizer {
* @return the list of the objects which reference the content.
* @throws EntException in case of error.
*/
- public List getContentUtilizers(String contentId) throws EntException;
+ public List getContentUtilizers(String contentId) throws EntException;
}
diff --git a/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/content/model/ContentDto.java b/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/content/model/ContentDto.java
index 67413eca75..7711a20c15 100644
--- a/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/content/model/ContentDto.java
+++ b/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/content/model/ContentDto.java
@@ -294,6 +294,7 @@ private void fillAbstractResourceAttribute(AttributeInterface attribute, EntityA
if (AbstractResourceAttribute.class.isAssignableFrom(attribute.getClass())) {
AbstractResourceAttribute resourceAttribute = (AbstractResourceAttribute) attribute;
for (Entry resourceEntry : attributeDto.getValues().entrySet()) {
+ @SuppressWarnings("unchecked")
Map resourceMap = (Map) resourceEntry.getValue();
this.setResourceAttribute(resourceAttribute, resourceMap, resourceEntry.getKey());
}
@@ -312,27 +313,27 @@ private void setResourceAttribute(AbstractResourceAttribute resourceAttribute, M
resourceInterface.setId(resourceId);
resourceInterface.setCorrelationCode(correlationCode);
resourceAttribute.setResource(resourceInterface, langCode);
+ @SuppressWarnings("unchecked")
Map values = (Map) resource.get("metadata");
if (values != null) {
- Map metadata = values.entrySet().stream()
- .collect(Collectors.toMap(Entry::getKey, e -> (String) e.getValue()));
- resourceAttribute.setMetadataMap(langCode, metadata);
+ values.entrySet().stream()
+ .forEach(e -> resourceAttribute.setMetadata(e.getKey(), langCode, (String) e.getValue()));
}
}
private Map getAdditionalLinkAttributes(final EntityAttributeDto attributeDto) {
final Map linkProperties = new HashMap<>();
- final String rel = (String) ((Map) attributeDto.getValue()).get("rel");
+ final String rel = (String) ((Map) attributeDto.getValue()).get(LinkAttribute.REL_ATTRIBUTE);
if (rel != null) {
- linkProperties.put("rel", rel);
+ linkProperties.put(LinkAttribute.REL_ATTRIBUTE, rel);
}
- final String target = (String) ((Map) attributeDto.getValue()).get("target");
+ final String target = (String) ((Map) attributeDto.getValue()).get(LinkAttribute.TARGET_ATTRIBUTE);
if (target != null) {
- linkProperties.put("target", target);
+ linkProperties.put(LinkAttribute.TARGET_ATTRIBUTE, target);
}
- final String hreflang = (String) ((Map) attributeDto.getValue()).get("hreflang");
+ final String hreflang = (String) ((Map) attributeDto.getValue()).get(LinkAttribute.HREFLANG_ATTRIBUTE);
if (hreflang != null) {
- linkProperties.put("hreflang", hreflang);
+ linkProperties.put(LinkAttribute.HREFLANG_ATTRIBUTE, hreflang);
}
return linkProperties;
}
@@ -341,7 +342,7 @@ private void fillLinkAttribute(AttributeInterface attribute, EntityAttributeDto
if (LinkAttribute.class.isAssignableFrom(attribute.getClass())) {
LinkAttribute linkAttribute = (LinkAttribute) attribute;
String defaultLangCode = linkAttribute.getDefaultLangCode();
- if (attributeDto.getValue() != null && attributeDto.getValue() instanceof SymbolicLink) {
+ if (attributeDto.getValue() instanceof SymbolicLink) {
linkAttribute.setSymbolicLink(defaultLangCode, (SymbolicLink) attributeDto.getValue());
} else {
SymbolicLink link = new SymbolicLink();
diff --git a/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/content/widget/UserFilterOptionBean.java b/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/content/widget/UserFilterOptionBean.java
index fbc772a0fb..065be8a49b 100644
--- a/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/content/widget/UserFilterOptionBean.java
+++ b/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/content/widget/UserFilterOptionBean.java
@@ -243,7 +243,7 @@ public EntitySearchFilter getEntityFilter() throws EntException {
AttributeInterface attribute = this.getAttribute();
if (attribute instanceof ITextAttribute) {
String text = this.getFormFieldValues().get(this.getFormFieldNames()[0]);
- filter = new EntitySearchFilter(attribute.getName(), true, text, true);
+ filter = new EntitySearchFilter(attribute.getName(), true, text, true);
if (attribute.isMultilingual()) {
filter.setLangCode(this.getCurrentLang().getCode());
}
@@ -252,7 +252,7 @@ public EntitySearchFilter getEntityFilter() throws EntException {
String end = this.getFormFieldValues().get(this.getFormFieldNames()[1]);
Date startDate = DateConverter.parseDate(start, this.getDateFormat());
Date endDate = DateConverter.parseDate(end, this.getDateFormat());
- filter = new EntitySearchFilter(attribute.getName(), true, startDate, endDate);
+ filter = new EntitySearchFilter(attribute.getName(), true, startDate, endDate);
} else if (attribute instanceof BooleanAttribute) {
String value = this.getFormFieldValues().get(this.getFormFieldNames()[0]);
String ignore = this.getFormFieldValues().get(this.getFormFieldNames()[1]);
@@ -263,7 +263,7 @@ public EntitySearchFilter getEntityFilter() throws EntException {
filter = new EntitySearchFilter(attribute.getName(), true);
filter.setNullOption(true);
} else {
- filter = new EntitySearchFilter(attribute.getName(), true, value, false);
+ filter = new EntitySearchFilter(attribute.getName(), true, value, false);
}
} else if (attribute instanceof NumberAttribute) {
String start = this.getFormFieldValues().get(this.getFormFieldNames()[0]);
@@ -278,7 +278,7 @@ public EntitySearchFilter getEntityFilter() throws EntException {
Integer endNumberInt = Integer.parseInt(end);
endNumber = new BigDecimal(endNumberInt);
} catch (Throwable t) {}
- filter = new EntitySearchFilter(attribute.getName(), true, startNumber, endNumber);
+ filter = new EntitySearchFilter(attribute.getName(), true, startNumber, endNumber);
}
} catch (Throwable t) {
_logger.error("Error extracting entity search filters", t);
@@ -308,45 +308,31 @@ public SearchEngineFilter extractFilter() {
if (!this.isAttributeFilter()) {
if (this.getKey().equals(KEY_FULLTEXT) && !StringUtils.isEmpty(value0)) {
//String[] fieldsSuffix = {"", "_option"};
- filter = new SearchEngineFilter(this.getCurrentLang().getCode(), value0, this.getOption(value1));
+ filter = new SearchEngineFilter<>(this.getCurrentLang().getCode(), value0, this.getOption(value1));
} else if (this.getKey().equals(KEY_CATEGORY) && !StringUtils.isEmpty(value0)) {
- filter = new SearchEngineFilter(IIndexerDAO.CONTENT_CATEGORY_FIELD_NAME, value0, SearchEngineFilter.TextSearchOption.EXACT);
+ filter = new SearchEngineFilter<>(IIndexerDAO.CONTENT_CATEGORY_FIELD_NAME, value0, SearchEngineFilter.TextSearchOption.EXACT);
}
} else {
AttributeInterface attribute = this.getAttribute();
if (attribute instanceof ITextAttribute && !StringUtils.isEmpty(value0)) {
- filter = new SearchEngineFilter(this.getIndexFieldName(), value0, SearchEngineFilter.TextSearchOption.EXACT);
+ filter = new SearchEngineFilter<>(this.getIndexFieldName(), value0, SearchEngineFilter.TextSearchOption.EXACT);
//String[] fieldsSuffix = {"_textFieldName"};
} else if (attribute instanceof DateAttribute &&
(!StringUtils.isEmpty(value0) || !StringUtils.isEmpty(value1))) {
- Date big0 = null;
- try {
- big0 = DateConverter.parseDate(value0, this.getDateFormat());
- } catch (Exception e) {}
- Date big1 = null;
- try {
- big1 = DateConverter.parseDate(value1, this.getDateFormat());
- } catch (Exception e) {}
+ Date big0 = DateConverter.parseDate(value0, this.getDateFormat());
+ Date big1 = DateConverter.parseDate(value1, this.getDateFormat());
//String[] fieldsSuffix = {"_dateStartFieldName", "_dateEndFieldName"};
- filter = new SearchEngineFilter(this.getIndexFieldName(), big0, big1);
+ filter = new SearchEngineFilter<>(this.getIndexFieldName(), big0, big1);
} else if (attribute instanceof BooleanAttribute &&
(!StringUtils.isEmpty(value0) && !StringUtils.isEmpty(value1))) {
- filter = new SearchEngineFilter(this.getIndexFieldName(), value0, SearchEngineFilter.TextSearchOption.EXACT);
+ filter = new SearchEngineFilter<>(this.getIndexFieldName(), value0, SearchEngineFilter.TextSearchOption.EXACT);
//String[] fieldsSuffix = {"_booleanFieldName", "_booleanFieldName_ignore", "_booleanFieldName_control"};
} else if (attribute instanceof NumberAttribute &&
(!StringUtils.isEmpty(value0) || !StringUtils.isEmpty(value1))) {
//String[] fieldsSuffix = {"_numberStartFieldName", "_numberEndFieldName"};
- BigDecimal big0 = null;
- try {
- big0 = new BigDecimal(value0);
- } catch (Exception e) {
- }
- BigDecimal big1 = null;
- try {
- big1 = new BigDecimal(value1);
- } catch (Exception e) {
- }
- filter = new SearchEngineFilter(this.getIndexFieldName(), big0, big1);
+ BigDecimal big0 = new BigDecimal(value0);
+ BigDecimal big1 = new BigDecimal(value1);
+ filter = new SearchEngineFilter<>(this.getIndexFieldName(), big0, big1);
}
}
return filter;
diff --git a/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/resource/ResourceManager.java b/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/resource/ResourceManager.java
index da3d4da41f..4e80457f7d 100644
--- a/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/resource/ResourceManager.java
+++ b/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/resource/ResourceManager.java
@@ -59,8 +59,8 @@
*
* @author W.Ambu - E.Santoboni
*/
-public class ResourceManager extends AbstractService implements IResourceManager, GroupUtilizer, CategoryUtilizer,
- RefreshableBeanTenantAware {
+public class ResourceManager extends AbstractService
+ implements IResourceManager, GroupUtilizer, CategoryUtilizer, RefreshableBeanTenantAware {
private final EntLogger logger = EntLogFactory.getSanitizedLogger(getClass());
@@ -603,7 +603,7 @@ public List getGroupUtilizers(String groupName) throws EntException {
}
@Override
- public List getCategoryUtilizers(String categoryCode) throws EntException {
+ public List getCategoryUtilizers(String categoryCode) throws EntException {
List resourcesId = null;
try {
resourcesId = this.getResourceDAO().searchResourcesId(null, null, null, categoryCode, null);
@@ -643,7 +643,7 @@ public void reloadCategoryReferences(String categoryCode) throws EntException {
}
@Override
- public List getCategoryUtilizersForReloadReferences(String categoryCode) throws EntException {
+ public List getCategoryUtilizersForReloadReferences(String categoryCode) throws EntException {
List resourcesId = null;
try {
resourcesId = this.getCategoryUtilizers(categoryCode);
diff --git a/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/resource/ResourceUtilizer.java b/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/resource/ResourceUtilizer.java
index 1c9d97a74d..d606c83a50 100644
--- a/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/resource/ResourceUtilizer.java
+++ b/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/resource/ResourceUtilizer.java
@@ -21,8 +21,9 @@
* Interfaccia base per i servizi, i cui elementi gestiti,
* possono presentare delle referenziazione con delle risorse.
* @author E.Santoboni
+ * @param
*/
-public interface ResourceUtilizer {
+public interface ResourceUtilizer {
/**
* Restituisce l'identificativo del servizio utilizzatore.
@@ -37,6 +38,6 @@ public interface ResourceUtilizer {
* @return La lista degli oggetti referenzianti la risorsa.
* @throws EntException in caso di errore.
*/
- public List getResourceUtilizers(String resourceId) throws EntException;
+ public List getResourceUtilizers(String resourceId) throws EntException;
}
diff --git a/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/resource/model/AbstractMonoInstanceResource.java b/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/resource/model/AbstractMonoInstanceResource.java
index 029bd8346d..b5b1ffca2d 100644
--- a/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/resource/model/AbstractMonoInstanceResource.java
+++ b/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/resource/model/AbstractMonoInstanceResource.java
@@ -21,6 +21,7 @@
import java.io.InputStream;
import org.entando.entando.ent.exception.EntResourceNotFoundException;
import org.entando.entando.ent.exception.EntResourceNotFoundRuntimeException;
+import org.entando.entando.ent.exception.EntRuntimeException;
import org.entando.entando.ent.util.EntLogging.EntLogFactory;
import org.entando.entando.ent.util.EntLogging.EntLogger;
@@ -60,7 +61,7 @@ public InputStream getResourceStream() {
throw new EntResourceNotFoundRuntimeException(ERROR_ON_EXTRACTING_RESOURCE_STREAM, e);
} catch (Throwable t) {
logger.error(ERROR_ON_EXTRACTING_RESOURCE_STREAM, t);
- throw new RuntimeException(ERROR_ON_EXTRACTING_RESOURCE_STREAM, t);
+ throw new EntRuntimeException(ERROR_ON_EXTRACTING_RESOURCE_STREAM, t);
}
}
diff --git a/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/resource/model/ImageResource.java b/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/resource/model/ImageResource.java
index 6e7df183ec..db308e390a 100644
--- a/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/resource/model/ImageResource.java
+++ b/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/resource/model/ImageResource.java
@@ -36,6 +36,7 @@
import org.entando.entando.ent.exception.EntException;
import org.entando.entando.ent.exception.EntResourceNotFoundException;
import org.entando.entando.ent.exception.EntResourceNotFoundRuntimeException;
+import org.entando.entando.ent.exception.EntRuntimeException;
import org.entando.entando.ent.util.EntLogging.EntLogFactory;
import org.entando.entando.ent.util.EntLogging.EntLogger;
import org.im4java.core.ConvertCmd;
@@ -81,7 +82,7 @@ public InputStream getResourceStream(int size, String langCode) {
throw new EntResourceNotFoundRuntimeException(ERROR_ON_EXTRACTING_FILE, e);
} catch (Throwable t) {
logger.error(ERROR_ON_EXTRACTING_FILE, t);
- throw new RuntimeException(ERROR_ON_EXTRACTING_FILE, t);
+ throw new EntRuntimeException(ERROR_ON_EXTRACTING_FILE, t);
}
}
diff --git a/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/resource/model/ResourceDataBean.java b/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/resource/model/ResourceDataBean.java
index 010e6d9225..23d571b89c 100644
--- a/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/resource/model/ResourceDataBean.java
+++ b/cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/resource/model/ResourceDataBean.java
@@ -108,7 +108,7 @@ public interface ResourceDataBean {
*
* @return La lista dei metadati della risorsa.
*/
- public Map getMetadata();
+ public Map getMetadata();
public void setMetadata(Map metadata);
diff --git a/cms-plugin/src/main/java/org/entando/entando/plugins/jacms/aps/system/services/content/ContentService.java b/cms-plugin/src/main/java/org/entando/entando/plugins/jacms/aps/system/services/content/ContentService.java
index 2eae9592f4..d204769efa 100644
--- a/cms-plugin/src/main/java/org/entando/entando/plugins/jacms/aps/system/services/content/ContentService.java
+++ b/cms-plugin/src/main/java/org/entando/entando/plugins/jacms/aps/system/services/content/ContentService.java
@@ -109,13 +109,13 @@
public class ContentService extends AbstractEntityService
implements IContentService,
GroupServiceUtilizer, CategoryServiceUtilizer,
- PageServiceUtilizer, ContentServiceUtilizer,
- ResourceServiceUtilizer,
- IComponentExistsService, IComponentUsageService,
+ PageServiceUtilizer, ContentServiceUtilizer,
+ ResourceServiceUtilizer,
+ IComponentExistsService, IComponentUsageService,
ApplicationContextAware {
private final EntLogger logger = EntLogFactory.getSanitizedLogger(getClass());
-
+
private ICategoryManager categoryManager;
private IContentManager contentManager;
private IContentModelManager contentModelManager;
@@ -305,10 +305,12 @@ private void convertResourceAttributeToDto(AbstractResourceAttribute contentAttr
AssetDto assetDto = resourcesService.convertResourceToDto((ResourceInterface) e.getValue());
if (contentAttr.getMetadatas() != null && ImageAssetDto.class
.isAssignableFrom(assetDto.getClass())) {
- ((ImageAssetDto) assetDto).setMetadata(contentAttr.getMetadatas().get(e.getKey()));
+ Map metadataByLang = contentAttr.getMetadatas().entrySet().stream()
+ .filter(entry -> entry.getKey() != null && entry.getValue().get(e.getKey()) != null)
+ .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().get(e.getKey())));
+ ((ImageAssetDto) assetDto).setMetadata(metadataByLang);
}
assetDto.setName(contentAttr.getTextForLang(e.getKey()));
-
return new AbstractMap.SimpleEntry<>(e.getKey(), assetDto);
}).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
}
@@ -326,7 +328,8 @@ protected void fillEntity(EntityDto request, Content entity, BindingResult bindi
@Override
public List getGroupUtilizer(String groupCode) {
try {
- List contentIds = ((GroupUtilizer) this.getContentManager()).getGroupUtilizers(groupCode);
+ @SuppressWarnings("unchecked")
+ List contentIds = ((GroupUtilizer) this.getContentManager()).getGroupUtilizers(groupCode);
return this.buildDtoList(contentIds);
} catch (EntException ex) {
logger.error("Error loading content references for group {}", groupCode, ex);
@@ -337,6 +340,7 @@ public List getGroupUtilizer(String groupCode) {
@Override
public List getCategoryUtilizer(String categoryCode) {
try {
+ @SuppressWarnings("unchecked")
List contentIds = ((CategoryUtilizer) this.getContentManager()).getCategoryUtilizers(categoryCode);
return this.buildDtoList(contentIds);
} catch (EntException ex) {
@@ -348,6 +352,7 @@ public List getCategoryUtilizer(String categoryCode) {
@Override
public List getPageUtilizer(String pageCode) {
try {
+ @SuppressWarnings("unchecked")
List contentIds = ((PageUtilizer) this.getContentManager()).getPageUtilizers(pageCode);
return this.buildDtoList(contentIds);
} catch (EntException ex) {
@@ -359,6 +364,7 @@ public List getPageUtilizer(String pageCode) {
@Override
public List getContentUtilizer(String contentId) {
try {
+ @SuppressWarnings("unchecked")
List contentIds = ((ContentUtilizer) this.getContentManager()).getContentUtilizers(contentId);
return this.buildDtoList(contentIds);
} catch (EntException ex) {
@@ -370,6 +376,7 @@ public List getContentUtilizer(String contentId) {
@Override
public List getResourceUtilizer(String resourceId) {
try {
+ @SuppressWarnings("unchecked")
List contentIds = ((ResourceUtilizer) this.getContentManager()).getResourceUtilizers(resourceId);
return this.buildDtoList(contentIds);
} catch (EntException ex) {
@@ -561,11 +568,9 @@ private PagedMetadata toPagedMetadata(RestContentListRequest request
public Integer countContentsByType(String contentType) {
try {
EntitySearchFilter[] filters = new EntitySearchFilter[]{
- new EntitySearchFilter("typeCode", false, contentType, false)
+ new EntitySearchFilter<>("typeCode", false, contentType, false)
};
-
List userGroupCodes = Collections.singletonList("administrators");
-
return getContentManager().countWorkContents(null, false, filters, userGroupCodes);
} catch (Exception t) {
logger.error("error in contents count by type", t);
@@ -714,13 +719,13 @@ public ContentDto updateContent(ContentDto request, UserDetails user, BindingRes
request.setRestriction(ContentRestriction.getRestrictionValue(request.getMainGroup()));
return super.updateEntity(JacmsSystemConstants.CONTENT_MANAGER, request, bindingResult);
}
-
+
@Override
public void deleteContent(String code, UserDetails user) {
this.checkContentAuthorization(user, code, false, true, null);
this.deleteContent(code);
}
-
+
private void deleteContent(String code) {
try {
Content content = this.getContentManager().loadContent(code, false);
@@ -749,7 +754,7 @@ public ContentDto updateContentStatus(String code, String status, UserDetails us
return updateContentStatus(code, status, user, bindingResult, false);
}
- private ContentDto updateContentStatus(String code, String status,
+ private ContentDto updateContentStatus(String code, String status,
UserDetails user, BeanPropertyBindingResult bindingResult, boolean forceUnpublish) {
try {
this.checkContentExists(code);
@@ -841,16 +846,16 @@ public PagedMetadata> getContentReferences(String code, String managerName, Us
logger.warn("no content found with code {}", code);
throw new ResourceNotFoundException(ERRCODE_CONTENT_NOT_FOUND, ComponentUsageEntity.TYPE_CONTENT, code);
}
- ContentServiceUtilizer> utilizer = this.getContentServiceUtilizer(managerName);
+ ContentServiceUtilizer utilizer = this.getContentServiceUtilizer(managerName);
if (null == utilizer) {
logger.warn("no references found for {}", managerName);
throw new ResourceNotFoundException(ERRCODE_CONTENT_REFERENCES, "reference", managerName);
}
- List> dtoList = utilizer.getContentUtilizer(code);
- List> subList = requestList.getSublist(dtoList);
- SearcherDaoPaginatedResult> pagedResult = new SearcherDaoPaginatedResult(dtoList.size(), subList);
- PagedMetadata