You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by dk...@apache.org on 2020/08/27 21:04:11 UTC
[sling-org-apache-sling-app-cms] 03/05: Fixing error when
retrieving a publishable resource with an unset / invalid publication type
This is an automated email from the ASF dual-hosted git repository.
dklco pushed a commit to branch SLING-8913-multiple-instance-types
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-app-cms.git
commit 6ef991849f48af1fa1bcb4992acfb8c9e3029995
Author: Dan Klco <dk...@apache.org>
AuthorDate: Thu Aug 27 17:02:19 2020 -0400
Fixing error when retrieving a publishable resource with an unset / invalid publication type
---
.../core/internal/models/PublishableResourceImpl.java | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/core/src/main/java/org/apache/sling/cms/core/internal/models/PublishableResourceImpl.java b/core/src/main/java/org/apache/sling/cms/core/internal/models/PublishableResourceImpl.java
index bd1366f..043646e 100644
--- a/core/src/main/java/org/apache/sling/cms/core/internal/models/PublishableResourceImpl.java
+++ b/core/src/main/java/org/apache/sling/cms/core/internal/models/PublishableResourceImpl.java
@@ -31,6 +31,8 @@ import org.apache.sling.cms.SiteManager;
import org.apache.sling.cms.publication.PublicationType;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.Self;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Implementation of the publishable resource interface and adaptable from a
@@ -39,6 +41,10 @@ import org.apache.sling.models.annotations.injectorspecific.Self;
@Model(adaptables = Resource.class, adapters = PublishableResource.class)
public class PublishableResourceImpl implements PublishableResource {
+ private static final Logger log = LoggerFactory.getLogger(PublishableResourceImpl.class);
+
+ public static final String LEGACY_PUBLISHED_PROPERTY = "published";
+
private final Resource contentResource;
private final Calendar created;
@@ -72,7 +78,8 @@ public class PublishableResourceImpl implements PublishableResource {
this.lastPublication = properties.get(CMSConstants.PN_LAST_PUBLICATION, Calendar.class);
this.lastPublicationBy = properties.get(NodeTypeConstants.JCR_LASTMODIFIEDBY, String.class);
this.lastPublicationType = properties.get(CMSConstants.PN_LAST_PUBLICATION_TYPE, String.class);
- this.published = properties.get(CMSConstants.PN_PUBLISHED, false);
+ this.published = properties.get(CMSConstants.PN_PUBLISHED,
+ properties.get(LEGACY_PUBLISHED_PROPERTY, false));
} else {
this.lastModified = null;
this.lastModifiedBy = null;
@@ -110,7 +117,14 @@ public class PublishableResourceImpl implements PublishableResource {
@Override
public PublicationType getLastPublicationType() {
- return PublicationType.valueOf(lastPublicationType);
+ if (lastPublicationType != null) {
+ try {
+ return PublicationType.valueOf(lastPublicationType);
+ } catch (IllegalArgumentException iae) {
+ log.warn("Invalid publication type: {}", lastPublicationType, iae);
+ }
+ }
+ return null;
}
@Override