Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Sep 27, 2022
2 parents 890a2b7 + d1f5144 commit cfbba87
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 4 deletions.
4 changes: 4 additions & 0 deletions changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
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="1.14.10" date="2022-09-27">
<action type="update" dev="sseifert">Dynamic Media Support: Introduce OSGi configuration parameter dmCapabilityDetection to switch from auto-detection to enable or disable Dynamic Media capability via configuration.</action>
</release>

<release version="1.14.8" date="2022-09-20">
<action type="fix" dev="sseifert">Dynamic Media Support: Make use of smart-cropped image rendition also in the case if the original image has same ratio as the requested ratio.</action>
</release>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<groupId>io.wcm</groupId>
<artifactId>io.wcm.handler.media</artifactId>
<version>1.14.8</version>
<version>1.14.10</version>
<packaging>jar</packaging>

<name>Media Handler</name>
Expand All @@ -49,7 +49,7 @@
<site.url.module.prefix>handler/media</site.url.module.prefix>

<!-- Enable reproducible builds -->
<project.build.outputTimestamp>2022-09-20T21:06:06Z</project.build.outputTimestamp>
<project.build.outputTimestamp>2022-09-27T12:44:41Z</project.build.outputTimestamp>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* #%L
* wcm.io
* %%
* Copyright (C) 2022 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.dynamicmedia;

/**
* Modes to detect if Dynamic Media capability is available on a author/publish instance.
*/
enum DynamicMediaCapabilityDetection {

/**
* Default: Auto-detect if Dynamic Media capability is available on author/publish instance by
* checking for the feature flag com.adobe.dam.asset.scene7.feature.flag.
*/
AUTO,

/**
* Assume Dynamic Media capability is not available without doing any auto-detection.
*/
OFF,

/**
* Assume Dynamic Media capability is available without doing any auto-detection.
*/
ON

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,15 @@ public class DynamicMediaSupportServiceImpl implements DynamicMediaSupportServic
@AttributeDefinition(
name = "Enabled",
description = "Enable support for dynamic media. "
+ "Only gets active when dynamic media is actually configured for the instance.")
+ "Only gets active when dynamic media is actually enabled for the instance.")
boolean enabled() default true;

@AttributeDefinition(
name = "Dynamic Media Capability",
description = "Whether to detect automatically if Dynamic Media is actually enabled for the instance. "
+ "Setting to ON disables the auto-detection via feature-flag and assumes it is enabled, setting to OFF assumes it is disabled.")
DynamicMediaCapabilityDetection dmCapabilityDetection() default DynamicMediaCapabilityDetection.AUTO;

@AttributeDefinition(
name = "Author Preview Mode",
description = "Loads dynamic media images via author instance - to allow previewing unpublished images. "
Expand Down Expand Up @@ -110,6 +116,7 @@ public class DynamicMediaSupportServiceImpl implements DynamicMediaSupportServic
private ResourceResolverFactory resourceResolverFactory;

private boolean enabled;
private DynamicMediaCapabilityDetection dmCapabilityDetection;
private boolean authorPreviewMode;
private boolean disableAemFallback;
private Dimension imageSizeLimit;
Expand All @@ -122,14 +129,34 @@ public class DynamicMediaSupportServiceImpl implements DynamicMediaSupportServic
@Activate
private void activate(Config config) {
this.enabled = config.enabled();
this.dmCapabilityDetection = config.dmCapabilityDetection();
this.authorPreviewMode = config.authorPreviewMode();
this.disableAemFallback = config.disableAemFallback();
this.imageSizeLimit = new Dimension(config.imageSizeLimitWidth(), config.imageSizeLimitHeight());

if (this.enabled && log.isInfoEnabled()) {
log.info("DynamicMediaSupport: enabled={}, capabilityEnabled={}, capabilityDetection={}, "
+ "authorPreviewMode={}, disableAemFallback={}, imageSizeLimit={}",
isDynamicMediaEnabled(), isDynamicMediaCapabilityEnabled(), this.dmCapabilityDetection,
this.authorPreviewMode, this.disableAemFallback, this.imageSizeLimit);
}
}

@Override
public boolean isDynamicMediaEnabled() {
return this.enabled && featureFlagService.isEnabled(ASSETS_SCENE7_FEATURE_FLAG_PID);
return this.enabled && isDynamicMediaCapabilityEnabled();
}

private boolean isDynamicMediaCapabilityEnabled() {
switch (dmCapabilityDetection) {
case AUTO:
return featureFlagService.isEnabled(ASSETS_SCENE7_FEATURE_FLAG_PID);
case ON:
return true;
case OFF:
default:
return false;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ void testDefaultConfig_FeatureDisabled() {
assertFalse(underTest.isDynamicMediaEnabled());
}

@Test
void testDefaultConfig_FeatureDisabled_EnabledViaConfig() {
DynamicMediaSupportService underTest = context.registerInjectActivateService(new DynamicMediaSupportServiceImpl(),
"dmCapabilityDetection", DynamicMediaCapabilityDetection.ON.toString());
assertTrue(underTest.isDynamicMediaEnabled());
}

@Test
void testDefaultConfig_FeatureEnabled_DisabledViaConfig() {
activateDynamicMediaFeature();
DynamicMediaSupportService underTest = context.registerInjectActivateService(new DynamicMediaSupportServiceImpl(),
"dmCapabilityDetection", DynamicMediaCapabilityDetection.OFF.toString());
assertFalse(underTest.isDynamicMediaEnabled());
}

@Test
void testDefaultConfig() {
activateDynamicMediaFeature();
Expand Down

0 comments on commit cfbba87

Please sign in to comment.