Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASSETS-14013: POC for using asset delivery url for connected asset. #2286

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -34,6 +34,7 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.jackrabbit.util.Text;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceMetadata;
import org.apache.sling.api.resource.ValueMap;
Expand Down Expand Up @@ -111,8 +112,11 @@ public class ImageImpl extends AbstractComponentImpl implements Image {

protected ValueMap properties;
protected String fileReference;
protected String urlReference;
protected String imageMimeType;
protected String alt;
protected String title;
protected Boolean isConnectedAsset;

protected String src;
protected String[] smartImages = new String[]{};
Expand Down Expand Up @@ -162,9 +166,11 @@ protected void initModel() {
properties = resource.getValueMap();
fileResource = resource.getChild(DownloadResource.NN_FILE);
fileReference = properties.get(DownloadResource.PN_REFERENCE, String.class);
urlReference = properties.get("urlReference", String.class);
imageMimeType = properties.get("imageMimeType", String.class);
alt = properties.get(ImageResource.PN_ALT, String.class);
title = properties.get(JcrConstants.JCR_TITLE, String.class);

isConnectedAsset = properties.get("isConnectedAsset", false);
mimeType = MIME_TYPE_IMAGE_JPEG;
displayPopupTitle = properties.get(PN_DISPLAY_POPUP_TITLE, currentStyle.get(PN_DISPLAY_POPUP_TITLE, false));
isDecorative = properties.get(PN_IS_DECORATIVE, currentStyle.get(PN_IS_DECORATIVE, false));
Expand All @@ -185,10 +191,19 @@ protected void initModel() {
useAssetDelivery = false;
LOGGER.error("Unable to adapt resource '{}' used by image '{}' to an asset.", fileReference, resource.getPath());
}
} else {
} else if(urlReference != null) {
mimeType = PropertiesUtil.toString(imageMimeType, MIME_TYPE_IMAGE_JPEG);
imageName = getImageNameFromDeliveryUrl(urlReference);
hasContent = true;
}
else {
useAssetDelivery = false;
LOGGER.error("Unable to find resource '{}' used by image '{}'.", fileReference, resource.getPath());
}
} else if(urlReference != null) {
mimeType = PropertiesUtil.toString(imageMimeType, MIME_TYPE_IMAGE_JPEG);
imageName = getImageNameFromDeliveryUrl(urlReference); // Should we send it?
hasContent = true;
} else {
useAssetDelivery = false;
if (fileResource != null) {
Expand Down Expand Up @@ -313,6 +328,24 @@ protected String getImageNameFromDam(String fileReference) {
.orElse(StringUtils.EMPTY);
}

/**
* Extracts the image name from the DAM resource
*
* @return image name from DAM
*/
protected String getImageNameFromDeliveryUrl(String urlReference) {
String defaultBaseUrl = "/adobe/dynamicmedia/deliver/";
String builtUrlWithoutBase = urlReference.substring(defaultBaseUrl.length());
String[] parts = builtUrlWithoutBase.split("/");
if(parts.length < 2) {
return "";
}
String seoNameWithFormatAndParams = parts[1];
String seoNameWithFormat = seoNameWithFormatAndParams.split("\\?")[0];
String seoName = seoNameWithFormat.split("\\.")[0];
return seoName;
}

/**
* Content editors can store DAM assets with white spaces in the name, this
* method makes the asset name SEO friendly, Translates the string into
Expand Down
Expand Up @@ -15,14 +15,15 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
package com.adobe.cq.wcm.core.components.internal.models.v2;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.*;

import javax.annotation.PostConstruct;

import com.day.cq.commons.jcr.JcrConstants;
import com.day.cq.wcm.api.NameConstants;
import com.day.cq.wcm.api.Template;
import org.apache.commons.lang3.StringUtils;
import org.apache.jackrabbit.util.Text;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Exporter;
Expand Down Expand Up @@ -216,9 +217,26 @@ protected void initModel() {
LOGGER.error("Unable to adapt resource '{}' used by image '{}' to an asset.", fileReference,
request.getResource().getPath());
}
} else if (urlReference != null) {
// send title, description from AEM and parse uuid from url
String imageTitle = properties.get("imageTitle", String.class);
if (!isDecorative && altValueFromDAM) {
String damDescription = properties.get("imageDescription", String.class);
if(StringUtils.isEmpty(damDescription)) {
damDescription = imageTitle;
}
if (StringUtils.isNotEmpty(damDescription)) {
alt = damDescription;
}
}
if (titleValueFromDAM) {
title = imageTitle;
}
} else {
LOGGER.error("Unable to find resource '{}' used by image '{}'.", fileReference, request.getResource().getPath());
}
} else if (urlReference != null) {
// send title, description from AEM and parse uuid from url
}
if (hasContent) {
disableLazyLoading = currentStyle.get(PN_DESIGN_LAZY_LOADING_ENABLED, true);
Expand Down