From b59cf7dfcc66a31b7ee6b15a6d0b25a98f80d791 Mon Sep 17 00:00:00 2001 From: "daniel.solis" <2894221+dsolistorres@users.noreply.github.com> Date: Fri, 20 Sep 2024 16:49:33 -0600 Subject: [PATCH] Always include dependency reference in PP manifest (#29823) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #28214 ### Proposed Changes * With this change the dependency reference is always included for all the files listed in the bundle manifest, even if the files were excluded from the bundle because of a filter or because the file wasn't changed after the last PP. * This allows to trace why every file was listed in the manifest even when the file was excluded from the bundle that was sent to the receiver ### Checklist - [x] Tests --------- Co-authored-by: freddyDOTCMS <147462678+freddyDOTCMS@users.noreply.github.com> Co-authored-by: Humberto Morera <31667212+hmoreras@users.noreply.github.com> Co-authored-by: Will Ezell Co-authored-by: Daniel Enrique Colina Rodríguez Co-authored-by: Nicolas Molina Monroy Co-authored-by: Victor Alfaro Co-authored-by: Kevin Davila <144152756+KevinDavilaDotCMS@users.noreply.github.com> Co-authored-by: Kevin Davila Co-authored-by: Jonathan Co-authored-by: Freddy Montes <751424+fmontes@users.noreply.github.com> Co-authored-by: Fabrizzio Araya <37148755+fabrizzio-dotCMS@users.noreply.github.com> Co-authored-by: spbolton Co-authored-by: Jalinson Diaz Co-authored-by: Jonathan Gamba Co-authored-by: Jose Castro Co-authored-by: Rafael Velazco Co-authored-by: Nollymar Longa Co-authored-by: Arcadio Quintero Co-authored-by: Valentino Giardino <77643678+valentinogiardino@users.noreply.github.com> Co-authored-by: Geronimo Ortiz Co-authored-by: erickgonzalez --- .../publisher/pusher/PushPublisherConfig.java | 61 +++++++-- .../PushPublishigDependencyProcesor.java | 72 ++++++++--- .../manifest/CSVManifestBuilder.java | 56 +++++++-- .../publishing/manifest/ManifestBuilder.java | 18 ++- .../remote/bundler/DependencyBundlerTest.java | 119 +++++++++++++++--- .../remote/bundler/TestManifestBuilder.java | 4 +- .../publishing/ManifestItemsMapTest.java | 70 ++++++++--- .../publishing/PublisherAPIImplTest.java | 44 +++++-- .../manifest/CSVManifestBuilderTest.java | 14 ++- .../manifest/CSVManifestReaderTest.java | 19 +-- 10 files changed, 367 insertions(+), 110 deletions(-) diff --git a/dotCMS/src/main/java/com/dotcms/publisher/pusher/PushPublisherConfig.java b/dotCMS/src/main/java/com/dotcms/publisher/pusher/PushPublisherConfig.java index 989bd3faf43e..ae700e670b0c 100755 --- a/dotCMS/src/main/java/com/dotcms/publisher/pusher/PushPublisherConfig.java +++ b/dotCMS/src/main/java/com/dotcms/publisher/pusher/PushPublisherConfig.java @@ -267,8 +267,16 @@ public BundleAssets dependencySet(){ return bundleAssets; } + /** + * Add an asset to the bundle. If the asset is already added, it will not be added again. + * It will be included in the dependency processor, so its dependencies are included too. + * @param asset The asset to be added + * @param pusheableAsset The object type of the asset + * @param evaluateReason The reason why the asset is being added + * @return true if the asset was added, false otherwise + */ public boolean addWithDependencies(final T asset, final PusheableAsset pusheableAsset, - final String reason) { + final String evaluateReason) { final String key = DependencyManager.getBundleKey(asset); final boolean added = bundleAssets.isAdded(key, pusheableAsset); final boolean isAlreadyAdded = bundleAssets.isDependenciesAdded(key, pusheableAsset); @@ -278,46 +286,73 @@ public boolean addWithDependencies(final T asset, final PusheableAsset pushe this.dependencyProcessor.addAsset(asset, pusheableAsset); if (!added) { - writeIncludeManifestItem(asset, reason); + writeIncludeManifestItem(asset, evaluateReason); } } return !isAlreadyAdded; } - public boolean add(final T asset, final PusheableAsset pusheableAsset, final String reason) { + /** + * Add an asset to the bundle. If the asset is already added, it will not be added again. + * @param asset The asset to be added + * @param pusheableAsset The object type of the asset + * @param evaluateReason The reason why the asset is being added + * @return true if the asset was added, false otherwise + */ + public boolean add(final T asset, final PusheableAsset pusheableAsset, final String evaluateReason) { final String key = DependencyManager.getBundleKey(asset); if(!bundleAssets.isAdded(key, pusheableAsset)) { bundleAssets.add(key, pusheableAsset); - writeIncludeManifestItem(asset, reason); + writeIncludeManifestItem(asset, evaluateReason); return true; } else { return false; } } + /** + * Returns true if the asset is already added to the bundle, false otherwise. + * @param asset The asset to be checked + * @param pusheableAsset The object type of the asset + * @return true if the asset is already added, false otherwise + */ public boolean contains(final T asset, final PusheableAsset pusheableAsset) { final String key = DependencyManager.getBundleKey(asset); return bundleAssets.isAdded(key, pusheableAsset); } - public boolean exclude(final T asset, final PusheableAsset pusheableAsset, final String reason) { + /** + * Add an asset to the list of assets that will be excluded from the bundle. + * If the asset is already excluded, it will not be excluded again. + * @param asset The asset to be excluded + * @param pusheableAsset The object type of the asset + * @param evaluateReason The reason why the asset is being evaluated + * @param excludeReason The reason why the asset is being excluded + * @return true if the asset was excluded, false otherwise + */ + public boolean exclude(final T asset, final PusheableAsset pusheableAsset, final String evaluateReason, final String excludeReason) { final String key = DependencyManager.getBundleKey(asset); if(!excludes.contains(key)) { excludes.add(key); - writeExcludeManifestItem(asset, reason); + writeExcludeManifestItem(asset, evaluateReason, excludeReason); return true; } else { return false; } } - public void writeIncludeManifestItem(final T asset, final String reason) { + /** + * Write a line to the manifest file as an included item. + * @param asset The asset to be included + * @param evaluateReason The reason why the asset is being included + */ + public void writeIncludeManifestItem(final T asset, final String evaluateReason) { if (ManifestItem.class.isAssignableFrom(asset.getClass())) { if (UtilMethods.isSet(manifestBuilder)) { - manifestBuilder.include((ManifestItem) asset, reason); + manifestBuilder.include((ManifestItem) asset, evaluateReason); } } else { Logger.warn(PushPublisherConfig.class, @@ -325,10 +360,16 @@ public void writeIncludeManifestItem(final T asset, final String reason) { } } - private void writeExcludeManifestItem(final T asset, final String reason) { + /** + * Write a line to the manifest file as an excluded item. + * @param asset The asset to be excluded + * @param evaluateReason The reason why the asset is being evaluated + * @param excludeReason The reason why the asset is being excluded + */ + private void writeExcludeManifestItem(final T asset, final String evaluateReason, final String excludeReason) { if (ManifestItem.class.isAssignableFrom(asset.getClass())) { if (UtilMethods.isSet(manifestBuilder)) { - manifestBuilder.exclude((ManifestItem) asset, reason); + manifestBuilder.exclude((ManifestItem) asset, evaluateReason, excludeReason); } } else { Logger.warn(PushPublisherConfig.class, 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 f4f7a54ca0e3..3579f2645404 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 @@ -906,8 +906,17 @@ public void waitUntilResolveAllDependencies() throws ExecutionException { dependencyProcessor.waitUntilResolveAllDependencies(); } - private boolean add(final PusheableAsset pusheableAsset, final T asset, final String reason) { - final boolean isAdded = config.add(asset, pusheableAsset, reason); + /** + * This method will add the specified dotCMS to the bundle if it has not been added already. + * If the asses was already added to the bundle, then {@code false} will be returned, + * otherwise, the asset will be added to the bundle and {@code true} will be returned. + * @param pusheableAsset The type of asset that is being added to the bundle. + * @param asset The actual dotCMS object that is being added. + * @param evaluateReason The reason why this asset is being added to the bundle. Refer to {@link ManifestReason} for more details. + * @return If the asset was added to the bundle, {@code true} will be returned. Otherwise, {@code false} will be returned. + */ + private boolean add(final PusheableAsset pusheableAsset, final T asset, final String evaluateReason) { + final boolean isAdded = config.add(asset, pusheableAsset, evaluateReason); if (isAdded) { pushedAssetUtil.savePushedAssetForAllEnv(asset, pusheableAsset); @@ -916,19 +925,34 @@ private boolean add(final PusheableAsset pusheableAsset, final T asset, fina return isAdded; } + /** + * This method tries to add the specified set of dotCMS asset to the bundle, + * it also processes the dependencies of the assets. + * @param pusheableAsset The type of asset that is being added to the bundle. + * @param assets The actual dotCMS objects that are being added. + * @param evaluateReason The reason why this set of assets is being added to the bundle. Refer to {@link ManifestReason} for more details. + */ private void tryToAddAllAndProcessDependencies( - final PusheableAsset pusheableAsset, final Iterable assets, final String reason) + final PusheableAsset pusheableAsset, final Iterable assets, final String evaluateReason) throws DotDataException, DotSecurityException { if (UtilMethods.isSet(assets)) { for (T asset : assets) { - tryToAddAndProcessDependencies(pusheableAsset, asset, reason); + tryToAddAndProcessDependencies(pusheableAsset, asset, evaluateReason); } } } + /** + * This method tries to add the specified set of dotCMS assets to the bundle. + * For assets that cannot be added to the bundle, a new entry will be added to the bundle's MANIFEST file indicating the reason why. + * @param pusheableAsset The type of asset that is being added to the bundle. + * @param assets The actual dotCMS objects that are being added. + * @param evaluateReason The reason why this set of assets is being added to the bundle. Refer to {@link ManifestReason} for more details. + * @return A collection of assets that were added to the bundle. + */ private Collection tryToAddAll(final PusheableAsset pusheableAsset, - final Collection assets, final String reason) + final Collection assets, final String evaluateReason) throws DotDataException, DotSecurityException { if (assets != null) { @@ -936,7 +960,7 @@ private Collection tryToAddAll(final PusheableAsset pusheableAsset, .filter(asset -> { try { final TryToAddResult tryToAddResult = tryToAdd(pusheableAsset, asset, - reason); + evaluateReason); return TryToAddResult.Result.INCLUDE == tryToAddResult.result; } catch (AssetExcludeException e) { return false; @@ -948,6 +972,14 @@ private Collection tryToAddAll(final PusheableAsset pusheableAsset, } } + /** + * This method tries to add the specified dotCMS asset dependency to the bundle. + * If the asset cannot be added to the bundle, a new entry will be added to the bundle's MANIFEST file indicating the reason why. + * Additionally, the very same asset will be added to the Dependency Processor queue in order to determine what other dependent assets might need to be added to the bundle as well. + * @param pusheableAsset The type of asset that is being added to the bundle. + * @param dependency The actual dotCMS object that is being added. + * @param from The asset that is including the dependency. + */ private void tryToAddAsDependency(final PusheableAsset pusheableAsset, final ManifestItem dependency, final ManifestItem from) throws DotDataException, DotSecurityException { @@ -964,14 +996,14 @@ private void tryToAddAsDependency(final PusheableAsset pusheableAsset, * * @param pusheableAsset The type of asset that is being added to the bundle. * @param asset The actual dotCMS object that is being added. - * @param reason The reason why this asset is being added to the bundle. Refer to {@link ManifestReason} for + * @param evaluateReason The reason why this asset is being added to the bundle. Refer to {@link ManifestReason} for * more details. */ private void tryToAddAndProcessDependencies(final PusheableAsset pusheableAsset, - final T asset, final String reason) { + final T asset, final String evaluateReason) { if (UtilMethods.isSet(asset)) { try { - final TryToAddResult tryToAddResult = tryToAdd(pusheableAsset, asset, reason); + final TryToAddResult tryToAddResult = tryToAdd(pusheableAsset, asset, evaluateReason); if (shouldIncludeDependency(tryToAddResult)) { dependencyProcessor.addAsset(asset, pusheableAsset); @@ -1000,19 +1032,19 @@ private static boolean shouldIncludeDependency(final TryToAddResult tryToAddResu * * @param pusheableAsset The type of asset that is being added to the bundle. * @param asset The actual dotCMS object that is being added. - * @param reason The reason why this asset is being added to the bundle. Refer to {@link ManifestReason} for + * @param evaluateReason The reason why this asset is being added to the bundle. Refer to {@link ManifestReason} for * more details. * * @return If the asset was added to the bundle, {@code true} will be returned. Otherwise, {@code false} will be * returned. */ private boolean tryToAddSilently ( - final PusheableAsset pusheableAsset, final T asset, final String reason) { + final PusheableAsset pusheableAsset, final T asset, final String evaluateReason) { if (null == asset) { return false; } try { - final TryToAddResult tryToAddResult = tryToAdd(pusheableAsset, asset, reason); + final TryToAddResult tryToAddResult = tryToAdd(pusheableAsset, asset, evaluateReason); return TryToAddResult.Result.INCLUDE == tryToAddResult.result; } catch (final AssetExcludeException e) { Logger.debug(PushPublishigDependencyProcesor.class, @@ -1027,7 +1059,7 @@ private boolean tryToAddSilently ( * * @param pusheableAsset The type of asset that is being added to the bundle. * @param asset The actual dotCMS object that is being added. - * @param reason The reason why this asset is being added to the bundle. Refer to {@link ManifestReason} for + * @param evaluateReason The reason why this asset is being added to the bundle. Refer to {@link ManifestReason} for * more details. * * @return An instance of the {@link TryToAddResult} class indicating if the asset was included, excluded, and the @@ -1036,7 +1068,7 @@ private boolean tryToAddSilently ( * @throws AssetExcludeException */ private synchronized TryToAddResult tryToAdd(final PusheableAsset pusheableAsset, final T asset, - final String reason) + final String evaluateReason) throws AssetExcludeException { if (config.contains(asset, pusheableAsset)) { return new TryToAddResult(TryToAddResult.Result.ALREADY_INCLUDE); @@ -1047,33 +1079,33 @@ private synchronized TryToAddResult tryToAdd(final PusheableAsset pusheableA } if (isSystemObject(asset)) { - config.exclude(asset, pusheableAsset, ManifestReason.EXCLUDE_SYSTEM_OBJECT.getMessage()); + config.exclude(asset, pusheableAsset, evaluateReason, ManifestReason.EXCLUDE_SYSTEM_OBJECT.getMessage()); return new TryToAddResult(TryToAddResult.Result.EXCLUDE, ManifestReason.EXCLUDE_SYSTEM_OBJECT); } if (!isTemplateLayout(asset) && isExcludeByFilter(pusheableAsset)) { - config.exclude(asset, pusheableAsset, ManifestReason.EXCLUDE_BY_FILTER.getMessage()); + config.exclude(asset, pusheableAsset, evaluateReason, ManifestReason.EXCLUDE_BY_FILTER.getMessage()); return new TryToAddResult(TryToAddResult.Result.EXCLUDE, ManifestReason.EXCLUDE_BY_FILTER); } if ( config.getOperation() != Operation.PUBLISH ) { - config.exclude(asset, pusheableAsset, ManifestReason.EXCLUDE_BY_OPERATION.getMessage(config.getOperation())); + config.exclude(asset, pusheableAsset, evaluateReason, ManifestReason.EXCLUDE_BY_OPERATION.getMessage(config.getOperation())); return new TryToAddResult(TryToAddResult.Result.EXCLUDE, ManifestReason.EXCLUDE_BY_OPERATION); } if (Contentlet.class.isInstance(asset) && !Contentlet.class.cast(asset).isHost() && publisherFilter.doesExcludeDependencyQueryContainsContentletId( ((Contentlet) asset).getIdentifier())) { - config.exclude(asset, pusheableAsset, ManifestReason.EXCLUDE_BY_FILTER.getMessage()); + config.exclude(asset, pusheableAsset, evaluateReason, ManifestReason.EXCLUDE_BY_FILTER.getMessage()); return new TryToAddResult(TryToAddResult.Result.EXCLUDE, ManifestReason.EXCLUDE_BY_FILTER); } if (!shouldCheckModDate(asset) || !dependencyModDateUtil.excludeByModDate(asset, pusheableAsset)) { - add(pusheableAsset, asset, reason); + add(pusheableAsset, asset, evaluateReason); return new TryToAddResult(TryToAddResult.Result.INCLUDE); } else { - config.exclude(asset, pusheableAsset, + config.exclude(asset, pusheableAsset, evaluateReason, ManifestReason.EXCLUDE_BY_MOD_DATE.getMessage(asset.getClass())); return new TryToAddResult(TryToAddResult.Result.EXCLUDE, ManifestReason.EXCLUDE_BY_MOD_DATE); } diff --git a/dotCMS/src/main/java/com/dotcms/publishing/manifest/CSVManifestBuilder.java b/dotCMS/src/main/java/com/dotcms/publishing/manifest/CSVManifestBuilder.java index d7977570c75a..088a0ba1f47f 100644 --- a/dotCMS/src/main/java/com/dotcms/publishing/manifest/CSVManifestBuilder.java +++ b/dotCMS/src/main/java/com/dotcms/publishing/manifest/CSVManifestBuilder.java @@ -36,7 +36,7 @@ public class CSVManifestBuilder implements ManifestBuilder { public final static String FILTER_METADATA_NAME = "Filter"; public final static String HEADERS_LINE = - "INCLUDED/EXCLUDED,object type, Id, inode, title, site, folder, excluded by, included by"; + "INCLUDED/EXCLUDED,object type, Id, inode, title, site, folder, excluded by, reason to be evaluated"; private FileWriter csvWriter; private File manifestFile; @@ -70,9 +70,14 @@ private void writeLine(String headersLine) throws IOException { csvWriter.append("\n"); } - public void include(final ManifestItem manifestItem, final String reason){ + /** + * Include an asset in the manifest file + * @param manifestItem Asset information + * @param evaluateReason Reason why the asset was evaluated to be included + */ + public void include(final ManifestItem manifestItem, final String evaluateReason){ final ManifestInfo manifestInfo = manifestItem.getManifestInfo(); - final String line = getManifestFileIncludeLine(manifestInfo, reason); + final String line = getManifestFileIncludeLine(manifestInfo, evaluateReason); try { writeLine(line); @@ -83,19 +88,40 @@ public void include(final ManifestItem manifestItem, final String reason){ } } + /** + * Get the line to include an asset in the manifest file + * @param manifestInfo Asset information + * @param evaluateReason Reason why the asset was evaluated to be included + * @return Line to include the asset in the manifest file + */ private String getManifestFileIncludeLine(final ManifestInfo manifestInfo, - final String includeReason) { - return getManifestFileLine("INCLUDED", manifestInfo, includeReason, StringPool.BLANK); + final String evaluateReason) { + return getManifestFileLine("INCLUDED", manifestInfo, evaluateReason, StringPool.BLANK); } + /** + * Get the line to exclude an asset in the manifest file + * @param manifestInfo Asset information + * @param evaluateReason Reason why the asset was evaluated to be included + * @param excludeReason Reason why the asset was excluded + * @return Line to exclude the asset in the manifest file + */ private String getManifestFileExcludeLine(final ManifestInfo manifestInfo, - final String excludeReason) { - return getManifestFileLine("EXCLUDED", manifestInfo, StringPool.BLANK, excludeReason); + final String evaluateReason, final String excludeReason) { + return getManifestFileLine("EXCLUDED", manifestInfo, evaluateReason, excludeReason); } + /** + * Get the line to include or exclude an asset in the manifest file + * @param includeExclude Include or Exclude + * @param manifestInfo Asset information + * @param evaluateReason Reason why the asset was evaluated to be included + * @param excludeReason Reason why the asset was excluded + * @return Line to include or exclude the asset in the manifest file + */ private String getManifestFileLine( final String includeExclude, final ManifestInfo manifestInfo, - final String includeReason, final String excludeReason) { + final String evaluateReason, final String excludeReason) { return list( includeExclude, @@ -106,12 +132,18 @@ private String getManifestFileLine( manifestInfo.site(), manifestInfo.folder(), excludeReason, - includeReason).stream().collect(Collectors.joining(",")); + evaluateReason).stream().collect(Collectors.joining(",")); } - public void exclude(final ManifestItem manifestItem, final String reason){ + /** + * Exclude an asset in the manifest file + * @param manifestItem Asset information + * @param evaluateReason Reason why the asset was evaluated to be included + * @param excludeReason Reason why the asset was excluded + */ + public void exclude(final ManifestItem manifestItem, final String evaluateReason, final String excludeReason){ final ManifestInfo manifestInfo = manifestItem.getManifestInfo(); - final String line = getManifestFileExcludeLine(manifestInfo, reason); + final String line = getManifestFileExcludeLine(manifestInfo, evaluateReason, excludeReason); try { writeLine(line); @@ -152,7 +184,7 @@ public void close() { * #first_header:This is the first header * #second_header:This is the second header * - * INCLUDED/EXCLUDED,object type, Id, inode, title, site, folder, excluded by, included by + * INCLUDED/EXCLUDED,object type, Id, inode, title, site, folder, excluded by, reason to be evaluated * ... * * @param name diff --git a/dotCMS/src/main/java/com/dotcms/publishing/manifest/ManifestBuilder.java b/dotCMS/src/main/java/com/dotcms/publishing/manifest/ManifestBuilder.java index eb7c282baafc..e6471e20ab0e 100644 --- a/dotCMS/src/main/java/com/dotcms/publishing/manifest/ManifestBuilder.java +++ b/dotCMS/src/main/java/com/dotcms/publishing/manifest/ManifestBuilder.java @@ -1,11 +1,7 @@ package com.dotcms.publishing.manifest; -import com.dotcms.publishing.manifest.ManifestItem.ManifestInfo; -import com.dotmarketing.exception.DotRuntimeException; import java.io.Closeable; import java.io.File; -import java.io.FileWriter; -import java.io.IOException; /** * Represent a Manifest Builder @@ -18,18 +14,20 @@ public interface ManifestBuilder extends Closeable { /** * Add a INCLUDE register into the Manifest * @param manifestItem Asset information - * @param reason Reason why the asset was include + * @param evaluateReason Reason why the asset was evaluated to be included * @param Asset's class */ - void include(final ManifestItem manifestItem, final String reason); + void include(final ManifestItem manifestItem, final String evaluateReason); /** * Add a EXCLUDE register into the Manifest - * @param manifestItem Asset information - * @param reason Reason why the asset was exclude - * @param Asset's class + * + * @param Asset's class + * @param manifestItem Asset information + * @param evaluateReason Reason why the asset was evaluated + * @param excludeReason Reason why the asset was excluded */ - void exclude(final ManifestItem manifestItem, final String reason); + void exclude(final ManifestItem manifestItem, String evaluateReason, final String excludeReason); /** diff --git a/dotcms-integration/src/test/java/com/dotcms/enterprise/publishing/remote/bundler/DependencyBundlerTest.java b/dotcms-integration/src/test/java/com/dotcms/enterprise/publishing/remote/bundler/DependencyBundlerTest.java index 79996ba95aca..621271baab34 100644 --- a/dotcms-integration/src/test/java/com/dotcms/enterprise/publishing/remote/bundler/DependencyBundlerTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/enterprise/publishing/remote/bundler/DependencyBundlerTest.java @@ -1,5 +1,6 @@ package com.dotcms.enterprise.publishing.remote.bundler; +import com.dotcms.LicenseTestUtil; import com.dotcms.contenttype.business.StoryBlockAPI; import com.dotcms.contenttype.model.field.Field; import com.dotcms.contenttype.model.field.ImageField; @@ -126,6 +127,7 @@ public class DependencyBundlerTest { public static void prepare() throws Exception { //Setting web app environment IntegrationTestInitService.getInstance().init(); + LicenseTestUtil.getLicense(); final Map> excludeSystemFolderMap = new HashMap<>(); excludeSystemFolderMap.put(EXCLUDE_SYSTEM_FOLDER_HOST, @@ -765,12 +767,19 @@ systemHostContentType, list(systemWorkflowScheme) new TestData(contentletWithRelationship, contentletWithRelationshipIncludes, excludeSystemFolder, filterDescriptorAllDependencies, "Contentlet with Relationship and filterDescriptorAllDependencies"), - new TestData(contentletWithRelationship, Map.of(contentTypeParent, list(relationship), contentletWithRelationship, list(relationship)), contentletWithRelationshipExcludes, filterDescriptorNotDependencies, "Contentlet with Relationship and filterDescriptorNotDependencies"), + new TestData(contentletWithRelationship, Map.of(contentTypeParent, list(relationship), contentletWithRelationship, list(relationship)), contentletWithRelationshipExcludes, + Map.of(contentTypeChild.getManifestInfo().id(), + list(getDependencyReason(relationship))), + filterDescriptorNotDependencies, + "Contentlet with Relationship and filterDescriptorNotDependencies"), new TestData(contentletWithRelationship, Map.of(contentletWithRelationship, list(host, contentTypeParent, language, relationship), contentTypeParent, list(systemWorkflowScheme, relationship), relationship, list(contentTypeChild)), Map.of(FILTER_EXCLUDE_REASON, list(), EXCLUDE_SYSTEM_FOLDER_HOST, list(systemFolder)), filterDescriptorNotRelationship, "Contentlet with Relationship and filterDescriptorNotRelationship"), new TestData(contentletWithRelationship, Map.of(contentletWithRelationship, list(relationship), contentTypeParent, list(relationship)), contentletWithRelationshipExcludes, - filterDescriptorNotDependenciesRelationship, "Contentlet with Relationship and filterDescriptorNotDependenciesRelationship"), + Map.of(contentTypeChild.getManifestInfo().id(), + list(getDependencyReason(relationship))), + filterDescriptorNotDependenciesRelationship, + "Contentlet with Relationship and filterDescriptorNotDependenciesRelationship"), new TestData(contentWithCategory, contentWithCategoryIncludes, excludeSystemFolder, filterDescriptorAllDependencies, "Contentlet with Category and filterDescriptorAllDependencies"), @@ -817,9 +826,9 @@ private static Collection createRuleTestCase() { new TestData(rule, new HashMap<>(), Map.of(FILTER_EXCLUDE_REASON, list(host)), filterDescriptorNotDependenciesRelationship, "Page with filterDescriptorNotDependenciesRelationship"), new TestData(ruleWithPage, Map.of(ruleWithPage, list(htmlPageAsset)), new HashMap<>(), filterDescriptorAllDependencies, "Rule with page and filterDescriptorAllDependencies"), - new TestData(ruleWithPage, new HashMap<>(), Map.of(FILTER_EXCLUDE_REASON, list(htmlPageAsset)), filterDescriptorNotDependencies, "Rule with page and filterDescriptorAllDependencies"), - new TestData(ruleWithPage, Map.of(ruleWithPage, list(htmlPageAsset)), new HashMap<>(), filterDescriptorNotRelationship, "Rule with page and filterDescriptorAllDependencies"), - new TestData(ruleWithPage, new HashMap<>(), Map.of(FILTER_EXCLUDE_REASON, list(htmlPageAsset)), filterDescriptorNotDependenciesRelationship, "Rule with page and filterDescriptorAllDependencies") + new TestData(ruleWithPage, new HashMap<>(), Map.of(FILTER_EXCLUDE_REASON, list(htmlPageAsset)), filterDescriptorNotDependencies, "Rule with page and filterDescriptorNotDependencies"), + new TestData(ruleWithPage, Map.of(ruleWithPage, list(htmlPageAsset)), new HashMap<>(), filterDescriptorNotRelationship, "Rule with page and filterDescriptorNotRelationship"), + new TestData(ruleWithPage, new HashMap<>(), Map.of(FILTER_EXCLUDE_REASON, list(htmlPageAsset)), filterDescriptorNotDependenciesRelationship, "Rule with page and filterDescriptorNotDependenciesRelationship") ); @@ -1318,13 +1327,23 @@ EXCLUDE_SYSTEM_FOLDER_HOST, list(systemFolder)), filterDescriptorNotDependencies EXCLUDE_SYSTEM_FOLDER_HOST, list(systemFolder)), filterDescriptorNotDependenciesRelationship, "Contentype with Category and filterDescriptorNotDependenciesRelationship"), new TestData(contentTypeParent, contentTypeParentIncludes, excludeSystemFolder, filterDescriptorAllDependencies, "Contentype with Relationship and filterDescriptorAllDependencies"), - new TestData(contentTypeParent, Map.of(contentTypeParent, list(relationship)), Map.of(FILTER_EXCLUDE_REASON, list(host, systemWorkflowScheme, contentTypeChild), - EXCLUDE_SYSTEM_FOLDER_HOST, list(systemFolder)), filterDescriptorNotDependencies, "Contentype with Relationship and filterDescriptorNotDependencies"), + new TestData(contentTypeParent, Map.of(contentTypeParent, list(relationship)), + Map.of(FILTER_EXCLUDE_REASON, list(host, systemWorkflowScheme, contentTypeChild), + EXCLUDE_SYSTEM_FOLDER_HOST, list(systemFolder)), + Map.of(contentTypeChild.getManifestInfo().id(), + list(getDependencyReason(relationship))), + filterDescriptorNotDependencies, + "Contentype with Relationship and filterDescriptorNotDependencies"), new TestData(contentTypeParent, Map.of(contentTypeParent, list(host, systemWorkflowScheme, relationship), relationship, list(contentTypeChild)), Map.of(FILTER_EXCLUDE_REASON, list(), EXCLUDE_SYSTEM_FOLDER_HOST, list(systemFolder)), filterDescriptorNotRelationship, "Contentype with Relationship and filterDescriptorNotRelationship"), - new TestData(contentTypeParent, Map.of(contentTypeParent, list(relationship)), Map.of(FILTER_EXCLUDE_REASON, list(host, systemWorkflowScheme, contentTypeChild), - EXCLUDE_SYSTEM_FOLDER_HOST, list(systemFolder)), filterDescriptorNotDependenciesRelationship, "Contentype with Relationship and filterDescriptorNotDependenciesRelationship") + new TestData(contentTypeParent, Map.of(contentTypeParent, list(relationship)), + Map.of(FILTER_EXCLUDE_REASON, list(host, systemWorkflowScheme, contentTypeChild), + EXCLUDE_SYSTEM_FOLDER_HOST, list(systemFolder)), + Map.of(contentTypeChild.getManifestInfo().id(), + list(getDependencyReason(relationship))), + filterDescriptorNotDependenciesRelationship, + "Contentype with Relationship and filterDescriptorNotDependenciesRelationship") ); } @@ -1436,6 +1455,12 @@ public void addLanguageVariableTestCaseInBundle() } + private static String getDependencyReason(final ManifestItem asset) { + return String.format( + "Dependency from: ID: %s Title: %s", asset.getManifestInfo().id(), + asset.getManifestInfo().title()); + } + @DataProvider(format = "%m: %p[0]") public static Object[] configs() throws Exception { return new ModDateTestData[] { @@ -1536,17 +1561,41 @@ contentTypeChild, list(APILocator.getWorkflowAPI().findSystemWorkflowScheme()) } else { final String excludeByOperation = FILTER_EXCLUDE_BY_OPERATION + modDateTestData.operation; - manifestLines.addExcludes(Map.of(excludeByOperation, - list(host, language, contentTypeParent, contentTypeChild, relationship, - APILocator.getWorkflowAPI().findSystemWorkflowScheme()))); + final List parentExcludeList = list( + host, language, contentTypeParent, relationship); + final List childExcludeList = list( + language, contentTypeChild); + manifestLines.addExcludes( + Map.of(excludeByOperation, parentExcludeList), contentParent); + manifestLines.addExcludes( + Map.of(excludeByOperation, childExcludeList), contentletChild); final List generalLangVarDependencies = list( PublisherAPIImplTest.getLanguageVariablesContentType(), APILocator.getWorkflowAPI().findSystemWorkflowScheme()); Stream.concat(PublisherAPIImplTest.getLanguagesVariableDependencies(), - languageVariables, generalLangVarDependencies).forEach(asset -> - manifestLines.addExclude((ManifestItem) asset, excludeByOperation)); + languageVariables, generalLangVarDependencies).forEach(asset -> { + final String dependencyReason = asset instanceof Contentlet && + !languageVariables.isEmpty() && languageVariables.contains((Contentlet) asset) ? + "Added Automatically by dotCMS" : + getDependencyReason(!languageVariables.isEmpty() ? + languageVariables.get(0) : (ManifestItem) asset); + manifestLines.addExclude((ManifestItem) asset, dependencyReason, excludeByOperation); + }); + + if (!languageVariables.isEmpty()) { + manifestLines.addExclude(APILocator.getFolderAPI().findSystemFolder(), + getDependencyReason(languageVariables.get(0)), + EXCLUDE_SYSTEM_FOLDER_HOST); + manifestLines.addExclude(APILocator.getHostAPI().findSystemHost(), + getDependencyReason(languageVariables.get(0).getContentType()), + EXCLUDE_SYSTEM_FOLDER_HOST); + manifestLines.addExclude( + APILocator.getWorkflowAPI().findSystemWorkflowScheme(), + getDependencyReason(languageVariables.get(0).getContentType()), + excludeByOperation); + } } dependencies.add(contentParent); @@ -1559,11 +1608,14 @@ contentTypeChild, list(APILocator.getWorkflowAPI().findSystemWorkflowScheme()) manifestLines.addDependencies(Map.of(contentletChild, list(language, contentTypeChild))); } else if (modDateTestData.operation == Operation.PUBLISH) { - manifestLines.addExclude(contentletChild, "Excluded by mod_date"); + manifestLines.addExclude(contentletChild, + getDependencyReason(relationship),"Excluded by mod_date"); manifestLines.addDependencies(Map.of(contentletChild, list(language, contentTypeChild))); } else { - manifestLines.addExclude(contentletChild, FILTER_EXCLUDE_BY_OPERATION + modDateTestData.operation); + manifestLines.addExclude(contentletChild, + getDependencyReason(relationship), + FILTER_EXCLUDE_BY_OPERATION + modDateTestData.operation); } manifestBuilder.close(); @@ -2358,6 +2410,7 @@ private static class TestData { Map> dependenciesToAssert; FilterDescriptor filterDescriptor; Map> excludes; + Map> evaluateReasons; String message; public TestData( @@ -2373,11 +2426,24 @@ public TestData( final Map> dependenciesToAssert, final Map> excludes, final FilterDescriptor filterDescriptor, - final String message) { + final String message) { + this(assetsToAddInBundle, dependenciesToAssert, excludes, + null, filterDescriptor, message); + } + + public TestData( + final ManifestItem assetsToAddInBundle, + final Map> dependenciesToAssert, + final Map> excludes, + final Map> evaluateReasons, + final FilterDescriptor filterDescriptor, + final String message) { + this.assetsToAddInBundle = assetsToAddInBundle; this.filterDescriptor = filterDescriptor; this.dependenciesToAssert = dependenciesToAssert; this.excludes = excludes; + this.evaluateReasons = evaluateReasons; this.message = message; } @@ -2395,7 +2461,24 @@ public ManifestItemsMapTest manifestLines() { manifestItemsMap.addDependencies(dependenciesToAssert); if (excludes != null) { - manifestItemsMap.addExcludes(excludes); + if (evaluateReasons == null) { + manifestItemsMap.addExcludes(excludes, assetManifestItem); + } else { + for (final Map.Entry> excludeEntry : excludes.entrySet()) { + final String excludeReason = excludeEntry.getKey(); + final List excludeList = excludeEntry.getValue(); + for (final ManifestItem excludeItem : excludeList) { + final String itemId = excludeItem.getManifestInfo().id(); + final List evaluateReasonList = evaluateReasons + .getOrDefault(itemId, + list(getDependencyReason(assetManifestItem))); + for (final String evaluateReason : evaluateReasonList) { + manifestItemsMap.addExclude(excludeItem, + evaluateReason, excludeReason); + } + } + } + } } return manifestItemsMap; diff --git a/dotcms-integration/src/test/java/com/dotcms/enterprise/publishing/remote/bundler/TestManifestBuilder.java b/dotcms-integration/src/test/java/com/dotcms/enterprise/publishing/remote/bundler/TestManifestBuilder.java index 503ec6dac3bd..eb39d2885b13 100644 --- a/dotcms-integration/src/test/java/com/dotcms/enterprise/publishing/remote/bundler/TestManifestBuilder.java +++ b/dotcms-integration/src/test/java/com/dotcms/enterprise/publishing/remote/bundler/TestManifestBuilder.java @@ -8,12 +8,12 @@ public class TestManifestBuilder implements ManifestBuilder { @Override - public void include(ManifestItem manifestItem, String reason) { + public void include(ManifestItem manifestItem, String evaluateReason) { } @Override - public void exclude(ManifestItem manifestItem, String reason) { + public void exclude(ManifestItem manifestItem, String evaluateReason, String excludeReason) { } diff --git a/dotcms-integration/src/test/java/com/dotcms/publishing/ManifestItemsMapTest.java b/dotcms-integration/src/test/java/com/dotcms/publishing/ManifestItemsMapTest.java index 898c1535d816..ea553ff15c61 100644 --- a/dotcms-integration/src/test/java/com/dotcms/publishing/ManifestItemsMapTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/publishing/ManifestItemsMapTest.java @@ -4,7 +4,8 @@ import com.dotcms.publishing.manifest.ManifestItem; import com.dotcms.publishing.manifest.ManifestItem.ManifestInfo; -import com.dotmarketing.portlets.contentlet.model.Contentlet; +import com.dotmarketing.util.StringUtils; +import com.dotmarketing.util.UtilMethods; import io.vavr.collection.Stream; import java.util.ArrayList; import java.util.Collection; @@ -19,19 +20,21 @@ public class ManifestItemsMapTest { private Map> includes = new HashMap<>(); private Map> excludes = new HashMap<>(); + private Map> evaluateResons = new HashMap<>(); private Set alreadyCheck; - private static String getIncludeLine(final ManifestItem asset, final String reason) { - return getLine("INCLUDED", asset, reason, ""); + private static String getIncludeLine(final ManifestItem asset, final String evaluateReason) { + return getLine("INCLUDED", asset, evaluateReason, ""); } - private static String getExcludeLine(final ManifestItem asset, final String reason) { - return getLine("EXCLUDED", asset, "", reason); + private static String getExcludeLine(final ManifestItem asset, + final String evaluateReason, final String excludeReason) { + return getLine("EXCLUDED", asset, evaluateReason, excludeReason); } private static String getLine(final String includeExclude, final ManifestItem asset, - final String reasonInclude, final String reasonExclude) { + final String reasonEvaluate, final String reasonExclude) { final ManifestInfo manifestInfo = asset.getManifestInfo(); return list( @@ -43,7 +46,7 @@ private static String getLine(final String includeExclude, final ManifestItem as manifestInfo.site(), manifestInfo.folder(), reasonExclude, - reasonInclude + reasonEvaluate ).stream().collect(Collectors.joining(",")); } @@ -61,13 +64,13 @@ public void addDependencies(final Map> de } } - public void add(final ManifestItem assetManifestItem, final List reasons) { - for (final String reason : reasons) { - add(assetManifestItem, reason); + public void add(final ManifestItem assetManifestItem, final List evaluateReasons) { + for (final String evaluateReason : evaluateReasons) { + add(assetManifestItem, evaluateReason); } } - public void add(final ManifestItem assetManifestItem, final String reason) { + public void add(final ManifestItem assetManifestItem, final String evaluateReason) { final String key = assetManifestItem.getManifestInfo().id(); if (excludes.containsKey(key)) { @@ -81,11 +84,22 @@ public void add(final ManifestItem assetManifestItem, final String reason) { includes.put(key, lines); } - lines.add(getIncludeLine(assetManifestItem, reason)); + lines.add(getIncludeLine(assetManifestItem, evaluateReason)); + final List evaluateReasons = evaluateResons + .computeIfAbsent(key, k -> new ArrayList<>()); + if (UtilMethods.isSet(evaluateReason) && !evaluateReasons.contains(evaluateReason)) { + evaluateReasons.add(evaluateReason); + } + + } + + public void addExclude(final ManifestItem assetManifestItem, final String excludeReason) { + addExclude(assetManifestItem, "", excludeReason); } - public void addExclude(final ManifestItem assetManifestItem, final String reason) { + public void addExclude(final ManifestItem assetManifestItem, + final String evaluateReason, final String excludeReason) { final String key = assetManifestItem.getManifestInfo().id(); if (includes.containsKey(key)) { @@ -99,7 +113,19 @@ public void addExclude(final ManifestItem assetManifestItem, final String reason excludes.put(key, lines); } - lines.add(getExcludeLine(assetManifestItem, reason)); + final List evaluateReasons = evaluateResons + .computeIfAbsent(key, k -> new ArrayList<>()); + if (UtilMethods.isSet(evaluateReason) && !evaluateReasons.contains(evaluateReason)) { + evaluateReasons.add(evaluateReason); + } + + if (!UtilMethods.isSet(evaluateReason)) { + lines.add(getExcludeLine(assetManifestItem, "", excludeReason)); + } else { + for (final String reason : evaluateReasons) { + lines.add(getExcludeLine(assetManifestItem, reason, excludeReason)); + } + } } public int size() { @@ -143,12 +169,26 @@ public String toString(){ } public void addExcludes(final Map> excludes) { + addExcludes(excludes, null); + } + + public void addExcludes( + final Map> excludes, + final ManifestItem dependencyFrom) { for (Entry> excludeEntry : excludes.entrySet()) { final List entryDependencies = excludeEntry.getValue(); for (ManifestItem assetExclude : entryDependencies) { - addExclude(assetExclude, excludeEntry.getKey()); + if (dependencyFrom != null) { + final String dependencyReeason = String.format( + "Dependency from: ID: %s Title: %s", + dependencyFrom.getManifestInfo().id(), + dependencyFrom.getManifestInfo().title()); + addExclude(assetExclude, dependencyReeason, excludeEntry.getKey()); + } else { + addExclude(assetExclude, excludeEntry.getKey()); + } } } } diff --git a/dotcms-integration/src/test/java/com/dotcms/publishing/PublisherAPIImplTest.java b/dotcms-integration/src/test/java/com/dotcms/publishing/PublisherAPIImplTest.java index 44263adf1079..c47e6898a466 100644 --- a/dotcms-integration/src/test/java/com/dotcms/publishing/PublisherAPIImplTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/publishing/PublisherAPIImplTest.java @@ -1,5 +1,6 @@ package com.dotcms.publishing; +import com.dotcms.LicenseTestUtil; import com.dotcms.contenttype.model.field.Field; import com.dotcms.contenttype.model.field.TextField; import com.dotcms.contenttype.model.type.ContentType; @@ -131,13 +132,14 @@ public class PublisherAPIImplTest { public static final String DEPENDENCY_FROM_TEMPLATE = "Dependency from: ID: %s Title: %s"; - private static String MANIFEST_HEADERS = "INCLUDED/EXCLUDED,object type, Id, inode, title, site, folder, excluded by, included by"; + private static String MANIFEST_HEADERS = "INCLUDED/EXCLUDED,object type, Id, inode, title, site, folder, excluded by, reason to be evaluated"; private static Contentlet languageVariableCreated; private static List manifestMetadataLines = list("#Bundle ID:", "#Operation", "#Filter:"); public static void prepare() throws Exception { //Setting web app environment IntegrationTestInitService.getInstance().init(); + LicenseTestUtil.getLicense(); } public static void removeLanguageVariable(){ @@ -231,7 +233,8 @@ private static TestAsset getExperimentWithSystemTemplate() throws DotDataExcepti experiment, list(variant, experimentPage, pageNewVersion), experimentPage, list(host, template, pageContentType, language) )), - "/bundlers-test/experiment/experiment.json", true, true); + "/bundlers-test/experiment/experiment.json", + true, true, experimentPage); } private static TestAsset getExperimentVariantDifferentLayout() @@ -714,8 +717,15 @@ public void generateBundle(final TestAsset testAsset) throws DotPublishingExcept final File manifestFile = new File(manifestFilePath); if (testAsset.addExcludeForSystemTemplate()) { - manifestLines.addExcludes(new HashMap<>(Map.of("Excluded System Folder/Host/Container/Template", - list(APILocator.getTemplateAPI().systemTemplate())))); + final ManifestItem dependsFrom = (ManifestItem) testAsset.systemTemplateDependsFrom; + final String evaluateTemplateReason = dependsFrom != null ? + String.format(DEPENDENCY_FROM_TEMPLATE, + dependsFrom.getManifestInfo().id(), + dependsFrom.getManifestInfo().title()) : ""; + + manifestLines.addExclude( + APILocator.getTemplateAPI().systemTemplate(), + evaluateTemplateReason,"Excluded System Folder/Host/Container/Template"); } assertManifestFile(manifestFile, manifestLines); @@ -762,10 +772,16 @@ public static void addLanguageVariableManifestItem( String.format(DEPENDENCY_FROM_TEMPLATE, languageVariablesContentType.id(), languageVariablesContentType.name())); final Host systemHost = APILocator.getHostAPI().findSystemHost(); - manifestLines.addExclude(systemHost, "Excluded System Folder/Host/Container/Template"); + manifestLines.addExclude(systemHost, + String.format(DEPENDENCY_FROM_TEMPLATE, languageVariablesContentType.id(), languageVariablesContentType.name()), + "Excluded System Folder/Host/Container/Template"); - manifestLines.addExclude(APILocator.getFolderAPI().findSystemFolder(), + final Contentlet languageVariable = languageVariablesAddInBundle.get(0); + final Folder systemFolder = APILocator.getFolderAPI().findSystemFolder(); + manifestLines.addExclude(systemFolder, + String.format(DEPENDENCY_FROM_TEMPLATE, languageVariable.getIdentifier(), languageVariable.getTitle()), "Excluded System Folder/Host/Container/Template"); + } } @@ -1206,6 +1222,7 @@ private static class TestAsset { boolean addLanguageVariableDependencies = true; Set otherVersions; private boolean excludeForSystemTemplate; + private ManifestItem systemTemplateDependsFrom; public TestAsset( final Object asset, @@ -1238,9 +1255,10 @@ public TestAsset( final Map> dependencies, final String fileExpectedPath, final boolean addLanguageVariableDependencies, - final boolean excludeForSystemTemplate) { + final boolean excludeForSystemTemplate, + final ManifestItem systemTemplateDependsFrom) { - this(asset, dependencies, null, fileExpectedPath, addLanguageVariableDependencies, excludeForSystemTemplate); + this(asset, dependencies, null, fileExpectedPath, addLanguageVariableDependencies, excludeForSystemTemplate, systemTemplateDependsFrom); } public TestAsset( @@ -1249,7 +1267,7 @@ public TestAsset( final Set otherVersions, final String fileExpectedPath, final boolean addLanguageVariableDependencies) { - this(asset, dependencies, otherVersions, fileExpectedPath, addLanguageVariableDependencies, false); + this(asset, dependencies, otherVersions, fileExpectedPath, addLanguageVariableDependencies, false, null); } public TestAsset( @@ -1258,7 +1276,8 @@ public TestAsset( final Set otherVersions, final String fileExpectedPath, final boolean addLanguageVariableDependencies, - final boolean excludeForSystemTemplate) { + final boolean excludeForSystemTemplate, + final ManifestItem systemTemplateDependsFrom) { this.asset = asset; this.dependencies = dependencies; @@ -1266,6 +1285,7 @@ public TestAsset( this.addLanguageVariableDependencies = addLanguageVariableDependencies; this.otherVersions = otherVersions != null ? otherVersions : Collections.EMPTY_SET; this.excludeForSystemTemplate = excludeForSystemTemplate; + this.systemTemplateDependsFrom = systemTemplateDependsFrom; } public ManifestItemsMapTest manifestLines() { @@ -1288,6 +1308,10 @@ public Collection getDependencies() { public boolean addExcludeForSystemTemplate() { return excludeForSystemTemplate; } + + public ManifestItem getSystemTemplateDependsFrom() { + return systemTemplateDependsFrom; + } } @NotNull diff --git a/dotcms-integration/src/test/java/com/dotcms/publishing/manifest/CSVManifestBuilderTest.java b/dotcms-integration/src/test/java/com/dotcms/publishing/manifest/CSVManifestBuilderTest.java index 0e339c289773..f87c15cc5af1 100644 --- a/dotcms-integration/src/test/java/com/dotcms/publishing/manifest/CSVManifestBuilderTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/publishing/manifest/CSVManifestBuilderTest.java @@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import com.dotcms.LicenseTestUtil; import com.dotcms.contenttype.model.type.ContentType; import com.dotcms.datagen.CategoryDataGen; import com.dotcms.datagen.ContainerAsFileDataGen; @@ -56,10 +57,11 @@ @RunWith(DataProviderRunner.class) public class CSVManifestBuilderTest { - private static String headers = "INCLUDED/EXCLUDED,object type, Id, inode, title, site, folder, excluded by, included by"; + private static String headers = "INCLUDED/EXCLUDED,object type, Id, inode, title, site, folder, excluded by, reason to be evaluated"; public static void prepare() throws Exception { IntegrationTestInitService.getInstance().init(); + LicenseTestUtil.getLicense(); } @DataProvider() @@ -279,17 +281,18 @@ public void include(final TestCase testCase) throws IOException { @Test @UseDataProvider("assets") public void exclude(final TestCase testCase) throws IOException { - final String exludeReason = "Exclude testing"; + final String excludeReason = "Exclude testing"; + final String evaluateReason = "Evaluate testing"; File manifestFile = null; try(final CSVManifestBuilder manifestBuilder = new CSVManifestBuilder()) { - manifestBuilder.exclude(testCase.asset, exludeReason); + manifestBuilder.exclude(testCase.asset, evaluateReason, excludeReason); manifestFile = manifestBuilder.getManifestFile(); } final List expected = list(headers); - expected.add("EXCLUDED," + testCase.lineExpected + "," + exludeReason + ","); + expected.add("EXCLUDED," + testCase.lineExpected + "," + excludeReason + "," + evaluateReason); assertManifestLines(manifestFile, expected); } @@ -400,10 +403,11 @@ public void callAddHeaderAfterInclude(){ @Test(expected = IllegalStateException.class) public void callAddHeaderAfterExclude(){ final String excludedReason = "exclude testing"; + final String evaluateReason = "evaluate testing"; final ContentType contentType = new ContentTypeDataGen().nextPersisted(); try(final CSVManifestBuilder manifestBuilder = new CSVManifestBuilder()) { - manifestBuilder.exclude(contentType, excludedReason); + manifestBuilder.exclude(contentType, evaluateReason, excludedReason); manifestBuilder.addMetadata("header_1", "first test header"); } } diff --git a/dotcms-integration/src/test/java/com/dotcms/publishing/manifest/CSVManifestReaderTest.java b/dotcms-integration/src/test/java/com/dotcms/publishing/manifest/CSVManifestReaderTest.java index 97325e149957..725950ff464f 100644 --- a/dotcms-integration/src/test/java/com/dotcms/publishing/manifest/CSVManifestReaderTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/publishing/manifest/CSVManifestReaderTest.java @@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import com.dotcms.LicenseTestUtil; import com.dotcms.contenttype.model.type.ContentType; import com.dotcms.datagen.CategoryDataGen; import com.dotcms.datagen.ContainerAsFileDataGen; @@ -44,16 +45,13 @@ import com.tngtech.java.junit.dataprovider.DataProvider; import com.tngtech.java.junit.dataprovider.DataProviderRunner; import com.tngtech.java.junit.dataprovider.UseDataProvider; -import java.io.BufferedReader; + import java.io.File; -import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; import java.util.Collection; -import java.util.List; import java.util.stream.Collectors; import org.apache.commons.io.FileUtils; import org.junit.Test; @@ -61,10 +59,11 @@ @RunWith(DataProviderRunner.class) public class CSVManifestReaderTest { - private static String headers = "INCLUDED/EXCLUDED,object type, Id, inode, title, site, folder, excluded by, included by"; + private static String headers = "INCLUDED/EXCLUDED,object type, Id, inode, title, site, folder, excluded by, reason to be evaluated"; public static void prepare() throws Exception { IntegrationTestInitService.getInstance().init(); + LicenseTestUtil.getLicense(); } @DataProvider() @@ -259,7 +258,8 @@ public void include(final CSVManifestReaderTest.TestCase testCase) throws IOExce try(final CSVManifestBuilder manifestBuilder = new CSVManifestBuilder()) { manifestBuilder.include(testCase.asset, includeReason); - manifestBuilder.exclude(systemHost, ManifestReason.EXCLUDE_SYSTEM_OBJECT.getMessage()); + manifestBuilder.exclude(systemHost, includeReason, + ManifestReason.EXCLUDE_SYSTEM_OBJECT.getMessage()); manifestFile = manifestBuilder.getManifestFile(); } @@ -344,13 +344,16 @@ public void createCSVManifestReaderWithInputStream() throws FileNotFoundExceptio @Test @UseDataProvider("assets") public void exclude(final CSVManifestReaderTest.TestCase testCase) throws IOException { + final String includeReason = ManifestReason.INCLUDE_BY_USER.getMessage(); + File manifestFile = null; final Language language = new LanguageDataGen().nextPersisted(); try(final CSVManifestBuilder manifestBuilder = new CSVManifestBuilder()) { - manifestBuilder.exclude(testCase.asset, ManifestReason.EXCLUDE_BY_FILTER.getMessage()); - manifestBuilder.include(language, ManifestReason.INCLUDE_AUTOMATIC_BY_DOTCMS.getMessage()); + manifestBuilder.exclude(testCase.asset, includeReason, + ManifestReason.EXCLUDE_BY_FILTER.getMessage()); + manifestBuilder.include(language, includeReason); manifestFile = manifestBuilder.getManifestFile(); }