From 50f19543c21cf7ccae7aebd2e33c511ba5d823c1 Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Tue, 27 Aug 2024 13:14:50 +0200 Subject: [PATCH] respect also in listener service --- .../metadata/RenditionMetadataGenerator.java | 6 ++++++ .../RenditionMetadataListenerServiceTest.java | 20 ++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/wcm/handler/mediasource/dam/impl/metadata/RenditionMetadataGenerator.java b/src/main/java/io/wcm/handler/mediasource/dam/impl/metadata/RenditionMetadataGenerator.java index 5fb40ff9..dc5d4915 100644 --- a/src/main/java/io/wcm/handler/mediasource/dam/impl/metadata/RenditionMetadataGenerator.java +++ b/src/main/java/io/wcm/handler/mediasource/dam/impl/metadata/RenditionMetadataGenerator.java @@ -185,6 +185,12 @@ public boolean renditionAddedOrUpdated(String renditionPath) throws PersistenceE log.debug("Skip non-image rendition {}", renditionPath); return false; } + + // skip renditions where AEMaaCS asset compute already provided metadata + if (hasAemRenditionMetadata(renditionPath)) { + log.debug("Skip rendition with existing AEM rendition metadata {}", renditionPath); + return false; + } } // Compare timestamps of rendition and rendition metadata diff --git a/src/test/java/io/wcm/handler/mediasource/dam/impl/metadata/RenditionMetadataListenerServiceTest.java b/src/test/java/io/wcm/handler/mediasource/dam/impl/metadata/RenditionMetadataListenerServiceTest.java index 9bccec1b..00ae874b 100644 --- a/src/test/java/io/wcm/handler/mediasource/dam/impl/metadata/RenditionMetadataListenerServiceTest.java +++ b/src/test/java/io/wcm/handler/mediasource/dam/impl/metadata/RenditionMetadataListenerServiceTest.java @@ -19,8 +19,12 @@ */ package io.wcm.handler.mediasource.dam.impl.metadata; +import static com.day.cq.commons.jcr.JcrConstants.JCR_CONTENT; import static com.day.cq.commons.jcr.JcrConstants.JCR_LASTMODIFIED; import static com.day.cq.commons.jcr.JcrConstants.JCR_LAST_MODIFIED_BY; +import static com.day.cq.dam.api.DamConstants.METADATA_FOLDER; +import static com.day.cq.dam.api.DamConstants.TIFF_IMAGELENGTH; +import static com.day.cq.dam.api.DamConstants.TIFF_IMAGEWIDTH; import static io.wcm.handler.mediasource.dam.impl.metadata.RenditionMetadataNameConstants.NN_RENDITIONS_METADATA; import static io.wcm.handler.mediasource.dam.impl.metadata.RenditionMetadataNameConstants.PN_IMAGE_HEIGHT; import static io.wcm.handler.mediasource.dam.impl.metadata.RenditionMetadataNameConstants.PN_IMAGE_WIDTH; @@ -78,6 +82,14 @@ void testAddRendition_Metadata() { assertRenditionMetadata("test.jpg", 215, 102, true); } + @Test + void testAddRendition_Metadata_ExistingAemRenditionMetadata() { + underTest = context.registerInjectActivateService(new RenditionMetadataListenerService(), + "threadPoolSize", 0); + addRenditionWithAemRenditionMetadata("test.jpg"); + assertNoRenditionMetadata("test.jpg"); + } + @Test @SuppressWarnings("null") void testAddRendition_Metadata_createMetadataNode() throws PersistenceException { @@ -208,6 +220,13 @@ private void addRendition(String renditionName) { underTest.handleEvent(DamEvent.renditionUpdated(assetResource.getPath(), null, rendition.getPath()).toEvent()); } + private void addRenditionWithAemRenditionMetadata(String renditionName) { + Resource rendition = context.load().binaryFile("/sample_image_215x102.jpg", RENDITIONS_PATH + "/" + renditionName); + context.create().resource(rendition, JCR_CONTENT + "/" + METADATA_FOLDER, + TIFF_IMAGEWIDTH, 215, TIFF_IMAGELENGTH, 102); + underTest.handleEvent(DamEvent.renditionUpdated(assetResource.getPath(), null, rendition.getPath()).toEvent()); + } + @SuppressWarnings("null") private void updateRendition(String renditionName) throws PersistenceException { String renditionPath = RENDITIONS_PATH + "/" + renditionName; @@ -233,7 +252,6 @@ private void sendRenditionRemovedEvent(String renditionName) { underTest.handleEvent(DamEvent.renditionRemoved(assetResource.getPath(), null, renditionPath).toEvent()); } - @SuppressWarnings("null") private void assertRenditionMetadata(String renditionName, int width, int height, boolean withLastModified) { String path = RENDITIONS_METADATA_PATH + "/" + renditionName; Resource metadata = context.resourceResolver().getResource(path);