Skip to content

Commit

Permalink
respect also in listener service
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Aug 27, 2024
1 parent eac0709 commit 50f1954
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 50f1954

Please sign in to comment.