Skip to content

Commit

Permalink
Add support for Web Optimized Image Delivery (part of Next Generation…
Browse files Browse the repository at this point in the history
… Dynamic Media)
  • Loading branch information
stefanseifert committed Jan 15, 2024
1 parent 7575b83 commit ed1f965
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<body>

<release version="2.0.0" date="not released">
<action type="add" dev="sseifert">
Add support for Web Optimized Image Delivery (part of Next Generation Dynamic Media) - rendering asset renditions from AEM Sites instance on the edge. Active by default, can be disabled.
</action>
<action type="remove" dev="sseifert" issue="27">
Remove deprecated functionality.
</action>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.junit5</artifactId>
<version>5.4.4</version>
<version>5.5.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* #%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.dynamicmedia;

/**
* Supports rendering asset renditions from stored in AEMaaCS sites instance via Next Generation Dynamic Media
* "Web Optimized Image Delivery", rendering the renditions on the edge.
* This is not available in AEM 6.5 or AEMaaCS SDK.
*/
public interface WebOptimizedImageDeliveryService {

/**
* @return Whether AEM AssetDelivery service is available and the support is enabled.
*/
boolean isEnabled();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* #%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.dynamicmedia;

import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicyOption;
import org.osgi.service.metatype.annotations.AttributeDefinition;
import org.osgi.service.metatype.annotations.Designate;
import org.osgi.service.metatype.annotations.ObjectClassDefinition;

import com.adobe.cq.wcm.spi.AssetDelivery;

/**
* Implements {@link WebOptimizedImageDeliveryService}.
*/
@Component(service = WebOptimizedImageDeliveryService.class, immediate = true)
@Designate(ocd = WebOptimizedImageDeliveryServiceImpl.Config.class)
public class WebOptimizedImageDeliveryServiceImpl implements WebOptimizedImageDeliveryService {

@ObjectClassDefinition(
name = "wcm.io Web Optimized Image Delivery Support",
description = "Support for Next Generation Dynamic Media Web Optimized Image Delivery capabilites.")
@interface Config {

@AttributeDefinition(
name = "Enabled",
description = "Enable support for Web Optimized Delivery (if available).")
boolean enabled() default true;

}

@Reference(cardinality = ReferenceCardinality.OPTIONAL, policyOption = ReferencePolicyOption.GREEDY)
private AssetDelivery assetDelivery;

private boolean enabled;

@Activate
private void activate(Config config) {
this.enabled = config.enabled();
}

@Override
public boolean isEnabled() {
return enabled && this.assetDelivery != null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* #%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.dynamicmedia;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import io.wcm.handler.media.testcontext.AppAemContext;
import io.wcm.testing.mock.aem.dam.MockAssetDelivery;
import io.wcm.testing.mock.aem.junit5.AemContext;
import io.wcm.testing.mock.aem.junit5.AemContextExtension;

@ExtendWith(AemContextExtension.class)
class WebOptimizedImageDeliveryServiceImplTest {

private final AemContext context = AppAemContext.newAemContext();

@Test
void testEnabled_AssetDeliveryNotPresent() {
WebOptimizedImageDeliveryService underTest = context.registerInjectActivateService(WebOptimizedImageDeliveryServiceImpl.class);
assertFalse(underTest.isEnabled());
}

@Test
void testEnabled_AssetDeliveryPresent() {
context.registerInjectActivateService(MockAssetDelivery.class);
WebOptimizedImageDeliveryService underTest = context.registerInjectActivateService(WebOptimizedImageDeliveryServiceImpl.class);
assertTrue(underTest.isEnabled());
}

@Test
void testEnabled_AssetDeliveryPresent_Disabled() {
context.registerInjectActivateService(MockAssetDelivery.class);
WebOptimizedImageDeliveryService underTest = context.registerInjectActivateService(WebOptimizedImageDeliveryServiceImpl.class,
"enabled", false);
assertFalse(underTest.isEnabled());
}

}

0 comments on commit ed1f965

Please sign in to comment.