From 19eef19840fb3250c077c93bef9da764d7ec8294 Mon Sep 17 00:00:00 2001 From: "skory.uladzislau" Date: Fri, 13 Sep 2024 15:58:44 +0200 Subject: [PATCH 1/4] [ERM-4] - Fix Page replication with child --- .../core/services/PageReplicationService.java | 2 +- .../impl/PageReplicationServiceImpl.java | 31 ++++++++++++++----- .../core/servlets/RolloutServlet.java | 2 +- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/com/exadel/etoolbox/rolloutmanager/core/services/PageReplicationService.java b/core/src/main/java/com/exadel/etoolbox/rolloutmanager/core/services/PageReplicationService.java index 2c210c5..d078ee4 100644 --- a/core/src/main/java/com/exadel/etoolbox/rolloutmanager/core/services/PageReplicationService.java +++ b/core/src/main/java/com/exadel/etoolbox/rolloutmanager/core/services/PageReplicationService.java @@ -26,5 +26,5 @@ * the rollout manager tool. */ public interface PageReplicationService { - List replicateItems(ResourceResolver resourceResolver, RolloutItem[] items, PageManager pageManager); + List replicateItems(ResourceResolver resourceResolver, RolloutItem[] items, PageManager pageManager, boolean isDeep); } \ No newline at end of file diff --git a/core/src/main/java/com/exadel/etoolbox/rolloutmanager/core/services/impl/PageReplicationServiceImpl.java b/core/src/main/java/com/exadel/etoolbox/rolloutmanager/core/services/impl/PageReplicationServiceImpl.java index 3fe67a4..6b97529 100644 --- a/core/src/main/java/com/exadel/etoolbox/rolloutmanager/core/services/impl/PageReplicationServiceImpl.java +++ b/core/src/main/java/com/exadel/etoolbox/rolloutmanager/core/services/impl/PageReplicationServiceImpl.java @@ -39,6 +39,7 @@ import javax.jcr.Session; import java.util.Arrays; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Optional; @@ -74,23 +75,23 @@ public class PageReplicationServiceImpl implements PageReplicationService { @Reference private Replicator replicator; - public List replicateItems(ResourceResolver resourceResolver, RolloutItem[] items, PageManager pageManager) { + public List replicateItems(ResourceResolver resourceResolver, RolloutItem[] items, PageManager pageManager, boolean isDeep) { return Arrays.stream(items) .collect(Collectors.groupingBy(RolloutItem::getDepth)) .entrySet() .stream() .sorted(Map.Entry.comparingByKey()) .map(Map.Entry::getValue) - .flatMap(sortedByDepthItems -> replicateSortedByDepthItems(resourceResolver, sortedByDepthItems, pageManager)) + .flatMap(sortedByDepthItems -> replicateSortedByDepthItems(resourceResolver, sortedByDepthItems, pageManager, isDeep)) .collect(Collectors.toList()); } - private Stream replicateSortedByDepthItems(ResourceResolver resourceResolver, List items, PageManager pageManager) { + private Stream replicateSortedByDepthItems(ResourceResolver resourceResolver, List items, PageManager pageManager, boolean isDeep) { ExecutorService executorService = Executors.newFixedThreadPool(config.poolSize()); return items.stream() .filter(item -> StringUtils.isNotBlank(item.getTarget())) .filter(item -> !isBluePrintPage(item, resourceResolver)) - .map(item -> CompletableFuture.supplyAsync(() -> replicate(resourceResolver, item, pageManager), executorService)) + .map(item -> CompletableFuture.supplyAsync(() -> replicate(resourceResolver, item, pageManager, isDeep), executorService)) .collect(Collectors.toList()) .stream() .map(CompletableFuture::join); @@ -110,7 +111,7 @@ private boolean isBluePrintPage(RolloutItem item, ResourceResolver resourceResol return hasRelationships; } - private RolloutStatus replicate(ResourceResolver resourceResolver, RolloutItem targetItem, PageManager pageManager) { + private RolloutStatus replicate(ResourceResolver resourceResolver, RolloutItem targetItem, PageManager pageManager, boolean isDeep) { String targetPath = targetItem.getTarget(); RolloutStatus status = new RolloutStatus(targetPath); @@ -123,12 +124,28 @@ private RolloutStatus replicate(ResourceResolver resourceResolver, RolloutItem t return status; } try { - replicator.replicate(session, ReplicationActionType.ACTIVATE, targetPath); + if (isDeep) { + replicatePageAndChildren(session, targetPage.get()); + } else { + replicator.replicate(session, ReplicationActionType.ACTIVATE, targetPath); + } status.setSuccess(true); } catch (ReplicationException ex) { status.setSuccess(false); - LOG.error("Exception during page replication", ex); + LOG.error("Exception during page replication: {}", targetPath, ex); } return status; } + + private void replicatePageAndChildren(Session session, Page page) { + try { + replicator.replicate(session, ReplicationActionType.ACTIVATE, page.getPath()); + for (Iterator children = page.listChildren(); children.hasNext(); ) { + Page childPage = children.next(); + replicatePageAndChildren(session, childPage); + } + } catch (Exception ex) { + LOG.error("Exception during page replication: {}", page.getPath(), ex); + } + } } \ No newline at end of file diff --git a/core/src/main/java/com/exadel/etoolbox/rolloutmanager/core/servlets/RolloutServlet.java b/core/src/main/java/com/exadel/etoolbox/rolloutmanager/core/servlets/RolloutServlet.java index bae4a86..3eef622 100644 --- a/core/src/main/java/com/exadel/etoolbox/rolloutmanager/core/servlets/RolloutServlet.java +++ b/core/src/main/java/com/exadel/etoolbox/rolloutmanager/core/servlets/RolloutServlet.java @@ -116,7 +116,7 @@ protected void doPost(final SlingHttpServletRequest request, final SlingHttpServ LOG.debug("Should activate pages: {}", shouldActivate); List activationStatuses = new ArrayList<>(); if (shouldActivate) { - activationStatuses = pageReplicationService.replicateItems(request.getResourceResolver(), rolloutItems, request.getResourceResolver().adaptTo(PageManager.class)); + activationStatuses = pageReplicationService.replicateItems(request.getResourceResolver(), rolloutItems, request.getResourceResolver().adaptTo(PageManager.class), isDeepRollout); } writeStatusesIfFailed(Stream.concat(rolloutStatuses.stream(), activationStatuses.stream()) From 2b9de04a8c68f1d0e2a906d21e552bb696e4c2b7 Mon Sep 17 00:00:00 2001 From: "skory.uladzislau" Date: Wed, 2 Oct 2024 14:39:22 +0200 Subject: [PATCH 2/4] [TECH] - Switch version to SNAPSHOT --- all/pom.xml | 2 +- core/pom.xml | 2 +- pom.xml | 2 +- ui.apps.structure/pom.xml | 2 +- ui.apps/pom.xml | 2 +- ui.config/pom.xml | 2 +- ui.content/pom.xml | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/all/pom.xml b/all/pom.xml index 8e45c9a..cd9e0e6 100644 --- a/all/pom.xml +++ b/all/pom.xml @@ -22,7 +22,7 @@ com.exadel.etoolbox etoolbox-rollout-manager - 1.3.0-SNAPSHOT + 1.3.1-SNAPSHOT ../pom.xml diff --git a/core/pom.xml b/core/pom.xml index 68fe69d..c6e83a8 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -18,7 +18,7 @@ com.exadel.etoolbox etoolbox-rollout-manager - 1.3.0-SNAPSHOT + 1.3.1-SNAPSHOT ../pom.xml etoolbox-rollout-manager.core diff --git a/pom.xml b/pom.xml index 45e4f09..c337580 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ com.exadel.etoolbox etoolbox-rollout-manager pom - 1.3.0-SNAPSHOT + 1.3.1-SNAPSHOT EToolbox Rollout Manager EToolbox Rollout Manager diff --git a/ui.apps.structure/pom.xml b/ui.apps.structure/pom.xml index 73092b9..8db53af 100644 --- a/ui.apps.structure/pom.xml +++ b/ui.apps.structure/pom.xml @@ -21,7 +21,7 @@ com.exadel.etoolbox etoolbox-rollout-manager - 1.3.0-SNAPSHOT + 1.3.1-SNAPSHOT ../pom.xml diff --git a/ui.apps/pom.xml b/ui.apps/pom.xml index ff4ba79..64eb0a4 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -21,7 +21,7 @@ com.exadel.etoolbox etoolbox-rollout-manager - 1.3.0-SNAPSHOT + 1.3.1-SNAPSHOT ../pom.xml diff --git a/ui.config/pom.xml b/ui.config/pom.xml index 2a3a6f8..b160c38 100644 --- a/ui.config/pom.xml +++ b/ui.config/pom.xml @@ -21,7 +21,7 @@ com.exadel.etoolbox etoolbox-rollout-manager - 1.3.0-SNAPSHOT + 1.3.1-SNAPSHOT ../pom.xml diff --git a/ui.content/pom.xml b/ui.content/pom.xml index 1630426..e1a3de4 100644 --- a/ui.content/pom.xml +++ b/ui.content/pom.xml @@ -21,7 +21,7 @@ com.exadel.etoolbox etoolbox-rollout-manager - 1.3.0-SNAPSHOT + 1.3.1-SNAPSHOT ../pom.xml From 13adc0ba692f67037c98df3a3fe2fe564b724b4f Mon Sep 17 00:00:00 2001 From: "skory.uladzislau" Date: Thu, 3 Oct 2024 10:57:41 +0200 Subject: [PATCH 3/4] [TECH] - Add replication message --- .../clientlibs/rollout-manager-ui/js/console-ui.actions.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ui.apps/src/main/content/jcr_root/apps/etoolbox-rollout-manager/clientlibs/rollout-manager-ui/js/console-ui.actions.js b/ui.apps/src/main/content/jcr_root/apps/etoolbox-rollout-manager/clientlibs/rollout-manager-ui/js/console-ui.actions.js index cb45ca3..00b573e 100644 --- a/ui.apps/src/main/content/jcr_root/apps/etoolbox-rollout-manager/clientlibs/rollout-manager-ui/js/console-ui.actions.js +++ b/ui.apps/src/main/content/jcr_root/apps/etoolbox-rollout-manager/clientlibs/rollout-manager-ui/js/console-ui.actions.js @@ -86,6 +86,7 @@ const PROCESSING_ERROR_MSG = Granite.I18n.get('Rollout failed'); const PROCESSING_ERROR_FAILED_PATHS_MSG = Granite.I18n.get('Rollout failed for the following paths:'); const SUCCESS_MSG = Granite.I18n.get('Completed'); + const SUCCESS_REPLICATION_MSG = Granite.I18n.get('Rollout is completed. Publishing is in progress.'); function getProcessingErrorMsg(xhr) { if (xhr.status === 400 && xhr.responseJSON && xhr.responseJSON.failedTargets) { @@ -114,7 +115,7 @@ }).fail((xhr) => { logger.log(getProcessingErrorMsg(xhr), false); }).done(() => { - logger.log(SUCCESS_MSG, false); + data.shouldActivate ? logger.log(SUCCESS_REPLICATION_MSG, false) : logger.log(SUCCESS_MSG, false); }); }; } From 54c3e77165620e91bda26dc04b431b93362baeee Mon Sep 17 00:00:00 2001 From: "skory.uladzislau" Date: Mon, 7 Oct 2024 13:40:17 +0200 Subject: [PATCH 4/4] [TECH] - Update pom versions to prepare 1.3.1 release --- all/pom.xml | 2 +- core/pom.xml | 2 +- pom.xml | 2 +- ui.apps.structure/pom.xml | 2 +- ui.apps/pom.xml | 2 +- ui.config/pom.xml | 2 +- ui.content/pom.xml | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/all/pom.xml b/all/pom.xml index cd9e0e6..5f754e4 100644 --- a/all/pom.xml +++ b/all/pom.xml @@ -22,7 +22,7 @@ com.exadel.etoolbox etoolbox-rollout-manager - 1.3.1-SNAPSHOT + 1.3.1 ../pom.xml diff --git a/core/pom.xml b/core/pom.xml index c6e83a8..0ace7c7 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -18,7 +18,7 @@ com.exadel.etoolbox etoolbox-rollout-manager - 1.3.1-SNAPSHOT + 1.3.1 ../pom.xml etoolbox-rollout-manager.core diff --git a/pom.xml b/pom.xml index c337580..c218f45 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ com.exadel.etoolbox etoolbox-rollout-manager pom - 1.3.1-SNAPSHOT + 1.3.1 EToolbox Rollout Manager EToolbox Rollout Manager diff --git a/ui.apps.structure/pom.xml b/ui.apps.structure/pom.xml index 8db53af..3ad0b62 100644 --- a/ui.apps.structure/pom.xml +++ b/ui.apps.structure/pom.xml @@ -21,7 +21,7 @@ com.exadel.etoolbox etoolbox-rollout-manager - 1.3.1-SNAPSHOT + 1.3.1 ../pom.xml diff --git a/ui.apps/pom.xml b/ui.apps/pom.xml index 64eb0a4..d83e27a 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -21,7 +21,7 @@ com.exadel.etoolbox etoolbox-rollout-manager - 1.3.1-SNAPSHOT + 1.3.1 ../pom.xml diff --git a/ui.config/pom.xml b/ui.config/pom.xml index b160c38..a9a0e92 100644 --- a/ui.config/pom.xml +++ b/ui.config/pom.xml @@ -21,7 +21,7 @@ com.exadel.etoolbox etoolbox-rollout-manager - 1.3.1-SNAPSHOT + 1.3.1 ../pom.xml diff --git a/ui.content/pom.xml b/ui.content/pom.xml index e1a3de4..5a0d951 100644 --- a/ui.content/pom.xml +++ b/ui.content/pom.xml @@ -21,7 +21,7 @@ com.exadel.etoolbox etoolbox-rollout-manager - 1.3.1-SNAPSHOT + 1.3.1 ../pom.xml