Skip to content

Commit

Permalink
Fix failing to resolve media when enforceVirtualRenditions is enabled…
Browse files Browse the repository at this point in the history
… and auto cropping is used at the same time (#49)
  • Loading branch information
stefanseifert authored Apr 16, 2024
1 parent 2105370 commit e346f6c
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 3 deletions.
6 changes: 6 additions & 0 deletions changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 http://maven.apache.org/plugins/maven-changes-plugin/xsd/changes-1.0.0.xsd">
<body>

<release version="2.0.4" date="not released">
<action type="fix" dev="sseifert" issue="49">
Fix failing to resolve media when enforceVirtualRenditions is enabled and auto cropping is used at the same time.
</action>
</release>

<release version="2.0.2" date="2024-03-13">
<action type="update" dev="sseifert" issue="44">
Next Generation Dynamic Media: Support non-image assets and SVG assets.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public RenditionMetadata getRendition(MediaArgs mediaArgs) {
return null;
}

private boolean enforceVirtualRendition(RenditionMetadata rendition, MediaArgs mediaArgs) {
protected boolean enforceVirtualRendition(RenditionMetadata rendition, MediaArgs mediaArgs) {
if (rendition.isImage() && !rendition.isVectorImage()) {
if (damContext.getMediaHandlerConfig().enforceVirtualRenditions()) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,10 @@ private VirtualTransformedRenditionMetadata getCropRendition(MediaArgs mediaArgs
mediaArgs.getEnforceOutputFileExtension(), cropDimension, rotation, mediaArgs.getImageQualityPercentage());
}

@Override
protected boolean enforceVirtualRendition(RenditionMetadata rendition, MediaArgs mediaArgs) {
// ignore this setting when already using transformed rendition handler
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class DummyMediaHandlerConfig extends MediaHandlerConfig {
InlineMediaSource.class,
NextGenDynamicMediaMediaSource.class);

private boolean enforceVirtualRenditions;

@Override
public @NotNull List<Class<? extends MediaSource>> getSources() {
return MEDIA_SOURCES;
Expand All @@ -50,4 +52,13 @@ public boolean includeAssetWebRenditionsByDefault() {
return true;
}

@Override
public boolean enforceVirtualRenditions() {
return enforceVirtualRenditions;
}

public void setEnforceVirtualRenditions(boolean enforceVirtualRenditions) {
this.enforceVirtualRenditions = enforceVirtualRenditions;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@
@ExtendWith(AemContextExtension.class)
class AutoCroppingMediaHandlerTest {

private final AemContext context = AppAemContext.newAemContext();
protected final AemContext context = AppAemContext.newAemContext();

private MediaHandler mediaHandler;
private Asset asset;
private Resource resource;

@BeforeEach
void setUp() {
protected void setUp() {
// register RenditionMetadataListenerService to generate rendition metadata
context.registerInjectActivateService(new AssetSynchonizationService());
context.registerInjectActivateService(new RenditionMetadataListenerService(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* #%L
* wcm.io
* %%
* Copyright (C) 2024 wcm.io
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package io.wcm.handler.mediasource.dam.impl;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.osgi.framework.Constants;

import io.wcm.handler.media.spi.MediaHandlerConfig;
import io.wcm.handler.media.testcontext.DummyMediaHandlerConfig;
import io.wcm.testing.mock.aem.junit5.AemContextExtension;

/**
* Same tests as in {@link AutoCroppingMediaHandlerTest}, but with forced
* virtual renditions enabled.
*/
@ExtendWith(AemContextExtension.class)
class AutoCroppingMediaHandler_EnforceVirtualRenditionsTest extends AutoCroppingMediaHandlerTest {

@Override
@BeforeEach
protected void setUp() {
DummyMediaHandlerConfig config = new DummyMediaHandlerConfig();
config.setEnforceVirtualRenditions(true);
context.registerService(MediaHandlerConfig.class, config,
Constants.SERVICE_RANKING, 500);

super.setUp();
}

}

0 comments on commit e346f6c

Please sign in to comment.