diff --git a/dotCMS/src/main/java/com/dotcms/publisher/util/dependencies/PushPublishigDependencyProcesor.java b/dotCMS/src/main/java/com/dotcms/publisher/util/dependencies/PushPublishigDependencyProcesor.java index a918cbd64ffa..392cf1ed89bf 100644 --- a/dotCMS/src/main/java/com/dotcms/publisher/util/dependencies/PushPublishigDependencyProcesor.java +++ b/dotCMS/src/main/java/com/dotcms/publisher/util/dependencies/PushPublishigDependencyProcesor.java @@ -1045,7 +1045,7 @@ private synchronized TryToAddResult tryToAdd(final PusheableAsset pusheableA return new TryToAddResult(TryToAddResult.Result.EXCLUDE, ManifestReason.EXCLUDE_SYSTEM_OBJECT); } - if (isExcludeByFilter(pusheableAsset)) { + if (!isTemplateLayout(asset) && isExcludeByFilter(pusheableAsset)) { config.exclude(asset, pusheableAsset, ManifestReason.EXCLUDE_BY_FILTER.getMessage()); return new TryToAddResult(TryToAddResult.Result.EXCLUDE, ManifestReason.EXCLUDE_BY_FILTER); } @@ -1073,6 +1073,17 @@ private synchronized TryToAddResult tryToAdd(final PusheableAsset pusheableA } } + /** + * Determines if the provided asset is a template layout. + * We can identify it by the title, it always contains the acronym Template.ANONYMOUS_PREFIX + * @param asset The asset to check + * @return If the Asset is a {@link Template} object and the title + * contains {@code Template.ANONYMOUS_PREFIX}, return {@code true}. + */ + private boolean isTemplateLayout(final Object asset){ + return asset instanceof Template && ((Template) asset).getTitle().contains(Template.ANONYMOUS_PREFIX); + } + private boolean isExcludeByFilter(final PusheableAsset pusheableAsset) { return !isRelationshipObject(pusheableAsset) && (!publisherFilter.isDependencies() || publisherFilter.doesExcludeDependencyClassesContainsType(pusheableAsset.getType())); diff --git a/dotcms-integration/src/test/java/com/dotcms/publisher/util/DependencyManagerTest.java b/dotcms-integration/src/test/java/com/dotcms/publisher/util/DependencyManagerTest.java index 074db8668227..c9ebc02cf526 100644 --- a/dotcms-integration/src/test/java/com/dotcms/publisher/util/DependencyManagerTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/publisher/util/DependencyManagerTest.java @@ -461,6 +461,39 @@ public void test_Page_with_FileTemplateAdvanced_as_Dependencies() } + /** + * Method to test: {@link DependencyManager#setDependencies()}

+ * Given Scenario: A Page using a Template as a File Advanced

+ * ExpectedResult: Should include the template files as dependencies + * @throws DotSecurityException + * @throws DotBundleException + * @throws DotDataException + */ + private void createBundle(final PushPublisherConfig config, final Contentlet contentlet, final String bundleFilterKey) + throws DotDataException { + final String bundleName = "testDependencyManagerBundle" + System.currentTimeMillis(); + Bundle bundle = new Bundle(bundleName, new Date(), null, user.getUserId()); + bundle.setFilterKey(bundleFilterKey); + bundleAPI.saveBundle(bundle); + bundle = bundleAPI.getBundleByName(bundleName); + + final PublishQueueElement publishQueueElement = new PublishQueueElement(); + publishQueueElement.setId(1); + publishQueueElement.setOperation(Operation.PUBLISH.ordinal()); + publishQueueElement.setAsset(contentlet.getInode()); + publishQueueElement.setEnteredDate(new Date()); + publishQueueElement.setPublishDate(new Date()); + publishQueueElement.setBundleId(bundle.getId()); + publishQueueElement.setType(PusheableAsset.CONTENTLET.getType()); + + config.setAssets(Lists.newArrayList(publishQueueElement)); + config.setId(bundle.getId()); + config.setOperation(Operation.PUBLISH); + config.setDownloading(true); + config.setLuceneQueries(Lists.newArrayList("+identifier:" + contentlet.getIdentifier())); + } + + /** * Creates a bundle with one contentlet */ @@ -524,10 +557,6 @@ private ContentType getContentTypeWithSelfJoinRelationship() return contentType; } - - - - private static void createFilter(){ final Map filtersMap = ImmutableMap.of("dependencies",true,"relationships",true,"forcePush",false); @@ -536,4 +565,49 @@ private static void createFilter(){ APILocator.getPublisherAPI().addFilterDescriptor(filterDescriptor); } + /** + * Method to test: PushPublishigDependencyProcesor.tryToAdd(PusheableAsset, Object, String)

+ * Given Scenario: Push publish a page with the filter 'Only Selected Items' selected.

+ * ExpectedResult: The template should not be included in the dependencies. + * @throws DotSecurityException + * @throws DotBundleException + * @throws DotDataException + */ + @Test + public void test_PP_page_should_not_contain_template_in_dependencies_when_filter_set() throws DotDataException, DotBundleException, DotSecurityException { + final PushPublisherConfig config = new PushPublisherConfig(); + final Template template = new TemplateDataGen().nextPersisted(); + final Host host = new SiteDataGen().nextPersisted(); + final HTMLPageAsset htmlPageAsset = new HTMLPageDataGen(host, template).nextPersisted(); + //Create a bundle with filter 'Only Selected Items' + createBundle(config, htmlPageAsset, "ShallowPush.yml"); + DependencyManager dependencyManager = new DependencyManager(DependencyManagerTest.user, config); + dependencyManager.setDependencies(); + + assertFalse(dependencyManager.getTemplates().contains(template.getIdentifier())); + } + + /** + * Method to test: PushPublishigDependencyProcesor.tryToAdd(PusheableAsset, Object, String)

+ * Given Scenario: Custom templates be should considered part of the page.

+ * ExpectedResult: The layout should be included in the dependencies regardless of the selected filter. + * @throws DotSecurityException + * @throws DotBundleException + * @throws DotDataException + */ + @Test + public void test_PP_page_should_contains_layout_in_dependencies() throws DotDataException, DotBundleException, DotSecurityException { + final PushPublisherConfig config = new PushPublisherConfig(); + //Layout templates are identified by the prefix 'anonymous_layout_' + final Template template = new TemplateDataGen().title(Template.ANONYMOUS_PREFIX+"shouldBeIncluded").nextPersisted(); + final Host host = new SiteDataGen().nextPersisted(); + final HTMLPageAsset htmlPageAsset = new HTMLPageDataGen(host, template).nextPersisted(); + //Create a bundle with filter 'Only Selected Items' + createBundle(config, htmlPageAsset, "ShallowPush.yml"); + DependencyManager dependencyManager = new DependencyManager(DependencyManagerTest.user, config); + dependencyManager.setDependencies(); + + assertTrue(dependencyManager.getTemplates().contains(template.getIdentifier())); + } + }