Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Mar 13, 2024
2 parents 13acfe7 + c5ba119 commit ef34652
Show file tree
Hide file tree
Showing 42 changed files with 2,235 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
git config --global user.name "${{ secrets.GH_SITE_DEPLOY_NAME }}"
- name: Setup JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 11
Expand Down
17 changes: 16 additions & 1 deletion changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@
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.2" date="2024-03-13">
<action type="update" dev="sseifert" issue="44">
Next Generation Dynamic Media: Support non-image assets and SVG assets.
</action>
<action type="update" dev="sseifert" issue="45">
Next Generation Dynamic Media: Use latest NextGen Dynamic Media Asset URLs and make them configurable via OSGi config.
</action>
<action type="update" dev="sseifert" issue="47">
Next Generation Dynamic Media: Replace fileupload default pick/remote trigger with customized one to display the customized asset selector dialog.
</action>
<action type="update" dev="sseifert" issue="48">
Next Generation Dynamic Media: Optionally fetch metadata of NGDM asset reference to check for validity and maximum possible resolution.
</action>
</release>

<release version="2.0.0" date="2024-01-26">
<action type="update" dev="sseifert"><![CDATA[
Version 2.0.0 contains minor breaking API changes, see <a href=https://wcm-io.atlassian.net/wiki/x/AYBxsw">Migrate from wcm.io Handler 1.x to 2.x</a> for details.
Expand All @@ -32,7 +47,7 @@
<b>This feature is active by default on AEMaaCS cloud instances, can be disabled via OSGi configuration</b>.
]]></action>
<action type="add" dev="sseifert" issue="38">
Add support for Next Generation Dynamic Media remote assets. This is a first experimental support and will be improved in subsequent releases.
Add support for Next Generation Dynamic Media remote assets. This is a first experimental support and will be finalized in release 2.0.2.
</action>
<action type="add" dev="sseifert" issue="33">
Allow to set image quality per media request.
Expand Down
16 changes: 14 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>2.0.0</version>
<version>2.0.2</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>2024-01-26T19:10:03Z</project.build.outputTimestamp>
<project.build.outputTimestamp>2024-03-13T09:35:13Z</project.build.outputTimestamp>
</properties>

<dependencies>
Expand Down Expand Up @@ -98,6 +98,12 @@
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
Expand Down Expand Up @@ -207,6 +213,12 @@
<version>2.8.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<version>3.4.0</version>
<scope>test</scope>
</dependency>

<!-- Java ImageIO Support for TIFF -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ final class NextGenDynamicMediaAsset implements Asset {

@Override
public @NotNull UriTemplate getUriTemplate(@NotNull UriTemplateType type) {
if (type == UriTemplateType.SCALE_HEIGHT) {
throw new IllegalArgumentException("URI template type not supported: " + type);
}
return new NextGenDynamicMediaUriTemplate(context, type);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* #%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.ngdm;

import java.util.Map;
import java.util.TreeMap;

import javax.annotation.PostConstruct;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
import org.apache.sling.models.annotations.injectorspecific.OSGiService;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.osgi.annotation.versioning.ProviderType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.json.JsonMapper;

import io.wcm.handler.mediasource.ngdm.impl.NextGenDynamicMediaConfigService;

/**
* Prepares Next Generation Dynamic Media configuration for GraniteUI components (fileupload, pathfield).
*/
@Model(adaptables = SlingHttpServletRequest.class)
@ProviderType
public final class NextGenDynamicMediaConfigModel {

private static final JsonMapper MAPPER = JsonMapper.builder().build();
private static final Logger log = LoggerFactory.getLogger(NextGenDynamicMediaConfigModel.class);

@OSGiService(injectionStrategy = InjectionStrategy.OPTIONAL)
private NextGenDynamicMediaConfigService config;

private boolean enabled;
private String assetSelectorsJsUrl;
private String configJson;

@PostConstruct
private void activate() {
if (config != null) {
enabled = config.enabled();
assetSelectorsJsUrl = config.getAssetSelectorsJsUrl();
configJson = buildConfigJsonString(config);
}
}

private static String buildConfigJsonString(@NotNull NextGenDynamicMediaConfigService config) {
Map<String, Object> map = new TreeMap<>();
map.put("repositoryId", config.getRepositoryId());
map.put("apiKey", config.getApiKey());
map.put("env", config.getEnv());
try {
return MAPPER.writeValueAsString(map);
}
catch (JsonProcessingException ex) {
log.warn("Unable to serialize Next Generation Dynamic Media config to JSON.", ex);
return "{}";
}
}

/**
* @return true if Next Generation Dynamic Media is available and enabled.
*/
public boolean isEnabled() {
return this.enabled;
}

/**
* @return Asset Selectors URL
*/
public @Nullable String getAssetSelectorsJsUrl() {
return this.assetSelectorsJsUrl;
}

/**
* @return JSON string with configuration data required on the client-side.
*/
public @Nullable String getConfigJson() {
return this.configJson;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.osgi.annotation.versioning.ProviderType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.day.cq.wcm.api.WCMMode;
import com.day.cq.wcm.api.components.ComponentContext;
Expand All @@ -47,6 +49,8 @@
import io.wcm.handler.mediasource.ngdm.impl.NextGenDynamicMediaConfigService;
import io.wcm.handler.mediasource.ngdm.impl.NextGenDynamicMediaContext;
import io.wcm.handler.mediasource.ngdm.impl.NextGenDynamicMediaReference;
import io.wcm.handler.mediasource.ngdm.impl.metadata.NextGenDynamicMediaMetadata;
import io.wcm.handler.mediasource.ngdm.impl.metadata.NextGenDynamicMediaMetadataService;
import io.wcm.sling.models.annotations.AemObject;

/**
Expand All @@ -69,6 +73,8 @@ public final class NextGenDynamicMediaMediaSource extends MediaSource {
private MediaHandlerConfig mediaHandlerConfig;
@OSGiService(injectionStrategy = InjectionStrategy.OPTIONAL)
private NextGenDynamicMediaConfigService nextGenDynamicMediaConfig;
@OSGiService(injectionStrategy = InjectionStrategy.OPTIONAL)
private NextGenDynamicMediaMetadataService metadataService;
@OSGiService
private MimeTypeService mimeTypeService;

Expand All @@ -77,6 +83,8 @@ public final class NextGenDynamicMediaMediaSource extends MediaSource {
@AemObject(injectionStrategy = InjectionStrategy.OPTIONAL)
private ComponentContext componentContext;

private static final Logger log = LoggerFactory.getLogger(NextGenDynamicMediaMediaSource.class);

@Override
public @NotNull String getId() {
return ID;
Expand All @@ -88,7 +96,11 @@ public boolean accepts(@Nullable String mediaRef) {
}

private boolean isNextGenDynamicMediaEnabled() {
return nextGenDynamicMediaConfig != null && nextGenDynamicMediaConfig.enabled();
if (nextGenDynamicMediaConfig == null) {
log.debug("NGDM media source is disabled: com.adobe.cq.ui.wcm.commons.config.NextGenDynamicMediaConfig is not available.");
return false;
}
return nextGenDynamicMediaConfig.enabled();
}

@Override
Expand All @@ -113,13 +125,23 @@ private boolean isNextGenDynamicMediaEnabled() {
return media;
}

// If enabled: Fetch asset metadata to validate existence and get original dimensions
NextGenDynamicMediaMetadata metadata = null;
if (metadataService != null && metadataService.isEnabled()) {
metadata = metadataService.fetchMetadata(reference);
if (metadata == null) {
media.setMediaInvalidReason(MediaInvalidReason.MEDIA_REFERENCE_INVALID);
return media;
}
}

// Update media args settings from resource (e.g. alt. text setings)
Resource referencedResource = media.getMediaRequest().getResource();
if (referencedResource != null) {
updateMediaArgsFromResource(mediaArgs, referencedResource, mediaHandlerConfig);
}

NextGenDynamicMediaContext context = new NextGenDynamicMediaContext(reference, media, mediaArgs,
NextGenDynamicMediaContext context = new NextGenDynamicMediaContext(reference, metadata, media, mediaArgs,
nextGenDynamicMediaConfig, mediaHandlerConfig, mimeTypeService);
NextGenDynamicMediaAsset asset = new NextGenDynamicMediaAsset(context);
media.setAsset(asset);
Expand Down
Loading

0 comments on commit ef34652

Please sign in to comment.