From cf530dbd5af483b73bc45e86c57d3dfaae9d11be Mon Sep 17 00:00:00 2001 From: david g Date: Thu, 4 Jan 2024 10:30:58 -0500 Subject: [PATCH] Added OSGi configuration for Adobe Embed PDF API client ID --- all/pom.xml | 2 +- core.cloud/pom.xml | 2 +- core/pom.xml | 2 +- .../components/details/impl/PdfImpl.java | 32 ++++++--- .../assetshare/util/AdobePdfEmbedApi.java | 31 +++++++++ .../util/impl/AdobePdfEmbedApiImpl.java | 68 +++++++++++++++++++ .../commons/assetshare/util/package-info.java | 2 +- dispatcher/pom.xml | 2 +- pom.xml | 2 +- ui.apps.structure/pom.xml | 2 +- ui.apps/pom.xml | 2 +- .../pdf/_cq_design_dialog/.content.xml | 4 +- ui.config/pom.xml | 2 +- ui.content.sample/pom.xml | 2 +- ui.content/pom.xml | 2 +- ui.frontend.theme.dark/pom.xml | 2 +- ui.frontend.theme.light/pom.xml | 2 +- 17 files changed, 137 insertions(+), 24 deletions(-) create mode 100644 core/src/main/java/com/adobe/aem/commons/assetshare/util/AdobePdfEmbedApi.java create mode 100644 core/src/main/java/com/adobe/aem/commons/assetshare/util/impl/AdobePdfEmbedApiImpl.java diff --git a/all/pom.xml b/all/pom.xml index aa5f8c023..e8cda56c2 100644 --- a/all/pom.xml +++ b/all/pom.xml @@ -22,7 +22,7 @@ com.adobe.aem.commons assetshare - 3.7.3-SNAPSHOT + 3.8.0-SNAPSHOT ../pom.xml diff --git a/core.cloud/pom.xml b/core.cloud/pom.xml index 04f398587..0ba1bb320 100644 --- a/core.cloud/pom.xml +++ b/core.cloud/pom.xml @@ -23,7 +23,7 @@ com.adobe.aem.commons assetshare - 3.7.3-SNAPSHOT + 3.8.0-SNAPSHOT ../pom.xml diff --git a/core/pom.xml b/core/pom.xml index 9905cf1e5..a85b3eea7 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -23,7 +23,7 @@ com.adobe.aem.commons assetshare - 3.7.3-SNAPSHOT + 3.8.0-SNAPSHOT ../pom.xml diff --git a/core/src/main/java/com/adobe/aem/commons/assetshare/components/details/impl/PdfImpl.java b/core/src/main/java/com/adobe/aem/commons/assetshare/components/details/impl/PdfImpl.java index 709b17f0c..dd7a1a6dd 100644 --- a/core/src/main/java/com/adobe/aem/commons/assetshare/components/details/impl/PdfImpl.java +++ b/core/src/main/java/com/adobe/aem/commons/assetshare/components/details/impl/PdfImpl.java @@ -4,6 +4,7 @@ import com.adobe.aem.commons.assetshare.content.AssetModel; import com.adobe.aem.commons.assetshare.content.renditions.AssetRenditionParameters; import com.adobe.aem.commons.assetshare.content.renditions.AssetRenditions; +import com.adobe.aem.commons.assetshare.util.AdobePdfEmbedApi; import com.adobe.aem.commons.assetshare.util.RequireAem; import com.adobe.aem.commons.assetshare.util.UrlUtil; import com.adobe.cq.export.json.ComponentExporter; @@ -13,10 +14,7 @@ import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.resource.ValueMap; import org.apache.sling.api.wrappers.ValueMapDecorator; -import org.apache.sling.models.annotations.DefaultInjectionStrategy; -import org.apache.sling.models.annotations.Exporter; -import org.apache.sling.models.annotations.Model; -import org.apache.sling.models.annotations.Required; +import org.apache.sling.models.annotations.*; import org.apache.sling.models.annotations.injectorspecific.OSGiService; import org.apache.sling.models.annotations.injectorspecific.ScriptVariable; import org.apache.sling.models.annotations.injectorspecific.Self; @@ -58,6 +56,10 @@ public class PdfImpl extends AbstractEmptyTextComponent implements Pdf { @Required private RequireAem requireAem; + @OSGiService + @Optional + private AdobePdfEmbedApi adobePdfEmbedApi; + @ValueMapValue private String renditionName; @@ -68,6 +70,8 @@ public class PdfImpl extends AbstractEmptyTextComponent implements Pdf { private String viewerId = null; + private String clientId = null; + private ValueMap properties = new ValueMapDecorator(new HashMap<>()); @PostConstruct @@ -109,12 +113,22 @@ public String getFileName() { @Override public String getClientId() { - // "clientId" property is the legacy value before we added support for author and publish clientIds. - if (RequireAem.ServiceType.AUTHOR.equals(requireAem.getServiceType())) { - return currentStyle.get("authorClientId", currentStyle.get("clientId", String.class)); - } else { - return currentStyle.get("publishClientId", currentStyle.get("clientId", String.class)); + + if (clientId == null) { + // "clientId" property is the legacy value before we added support for author and publish clientIds. + if (RequireAem.ServiceType.AUTHOR.equals(requireAem.getServiceType())) { + clientId = currentStyle.get("authorClientId", currentStyle.get("clientId", String.class)); + } else { + clientId = currentStyle.get("publishClientId", currentStyle.get("clientId", String.class)); + } + + // Fallback to the AdobePdfEmbedApi OSGi service defined Adobe PDF Embed API Client ID + if (StringUtils.isBlank(clientId) && adobePdfEmbedApi != null) { + clientId = adobePdfEmbedApi.getClientId(); + } } + + return clientId; } @Override diff --git a/core/src/main/java/com/adobe/aem/commons/assetshare/util/AdobePdfEmbedApi.java b/core/src/main/java/com/adobe/aem/commons/assetshare/util/AdobePdfEmbedApi.java new file mode 100644 index 000000000..eb5e34af1 --- /dev/null +++ b/core/src/main/java/com/adobe/aem/commons/assetshare/util/AdobePdfEmbedApi.java @@ -0,0 +1,31 @@ +/* + * Asset Share Commons + * + * Copyright (C) 2024 Adobe + * + * 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. + * + */ + +package com.adobe.aem.commons.assetshare.util; + +import org.osgi.annotation.versioning.ProviderType; + +@ProviderType +public interface AdobePdfEmbedApi { + + /** + * @return the Adobe PDF Embed API Client ID. + */ + String getClientId(); +} diff --git a/core/src/main/java/com/adobe/aem/commons/assetshare/util/impl/AdobePdfEmbedApiImpl.java b/core/src/main/java/com/adobe/aem/commons/assetshare/util/impl/AdobePdfEmbedApiImpl.java new file mode 100644 index 000000000..8af0732be --- /dev/null +++ b/core/src/main/java/com/adobe/aem/commons/assetshare/util/impl/AdobePdfEmbedApiImpl.java @@ -0,0 +1,68 @@ +/* + * Asset Share Commons + * + * Copyright (C) 2024 Adobe + * + * 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. + * + */ + +package com.adobe.aem.commons.assetshare.util.impl; + +import com.adobe.aem.commons.assetshare.util.AdobePdfEmbedApi; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.ConfigurationPolicy; +import org.osgi.service.component.annotations.Modified; +import org.osgi.service.metatype.annotations.Designate; +import org.osgi.service.metatype.annotations.AttributeDefinition; +import org.osgi.service.metatype.annotations.ObjectClassDefinition; +import org.osgi.service.metatype.annotations.Option; + +/** + * Allows for Git-based managed Adobe PDF Embed API Client ID used for the Asset Share Commons PDF details. + * + * https://acrobatservices.adobe.com/dc-integration-creation-app-cdn/main.html?api=pdf-embed-api + */ +@Component( + configurationPolicy = ConfigurationPolicy.REQUIRE +) +@Designate(ocd = AdobePdfEmbedApiImpl.Config.class) +public class AdobePdfEmbedApiImpl implements AdobePdfEmbedApi { + private Config cfg; + + @Override + public String getClientId() { + return cfg.client_id(); + } + + @ObjectClassDefinition( + name = "Asset Share Commons - Adobe PDF Embed API Configuration", + description = "Configuration for the Adobe PDF Embed API. Each domain requires a unique Client ID." + ) + @interface Config { + @AttributeDefinition( + name = "Adobe PDF Embed API Client ID", + description = "Get free Adobe PDF Embed API Client ID from: https://acrobatservices.adobe.com/dc-integration-creation-app-cdn/main.html?api=pdf-embed-api" + ) + String client_id(); + } + + @Activate + @Modified + protected void activate(Config cfg) { + this.cfg = cfg; + } + + +} diff --git a/core/src/main/java/com/adobe/aem/commons/assetshare/util/package-info.java b/core/src/main/java/com/adobe/aem/commons/assetshare/util/package-info.java index 9361a1f3e..3caf9ae1c 100644 --- a/core/src/main/java/com/adobe/aem/commons/assetshare/util/package-info.java +++ b/core/src/main/java/com/adobe/aem/commons/assetshare/util/package-info.java @@ -17,7 +17,7 @@ * */ -@Version("1.15.0") +@Version("1.16.0") package com.adobe.aem.commons.assetshare.util; import org.osgi.annotation.versioning.Version; diff --git a/dispatcher/pom.xml b/dispatcher/pom.xml index ac271df1c..671f496d7 100644 --- a/dispatcher/pom.xml +++ b/dispatcher/pom.xml @@ -7,7 +7,7 @@ com.adobe.aem.commons assetshare - 3.7.3-SNAPSHOT + 3.8.0-SNAPSHOT ../pom.xml diff --git a/pom.xml b/pom.xml index c4172946b..7b6faea77 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ com.adobe.aem.commons assetshare pom - 3.7.3-SNAPSHOT + 3.8.0-SNAPSHOT Asset Share Commons - Reactor Project asset-share-commons diff --git a/ui.apps.structure/pom.xml b/ui.apps.structure/pom.xml index 78c11f245..e02762306 100644 --- a/ui.apps.structure/pom.xml +++ b/ui.apps.structure/pom.xml @@ -8,7 +8,7 @@ com.adobe.aem.commons assetshare - 3.7.3-SNAPSHOT + 3.8.0-SNAPSHOT ../pom.xml diff --git a/ui.apps/pom.xml b/ui.apps/pom.xml index 16137ab5f..fc5b64a18 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -23,7 +23,7 @@ com.adobe.aem.commons assetshare - 3.7.3-SNAPSHOT + 3.8.0-SNAPSHOT ../pom.xml diff --git a/ui.apps/src/main/content/jcr_root/apps/asset-share-commons/components/details/pdf/_cq_design_dialog/.content.xml b/ui.apps/src/main/content/jcr_root/apps/asset-share-commons/components/details/pdf/_cq_design_dialog/.content.xml index 248ec2ac8..855faa374 100644 --- a/ui.apps/src/main/content/jcr_root/apps/asset-share-commons/components/details/pdf/_cq_design_dialog/.content.xml +++ b/ui.apps/src/main/content/jcr_root/apps/asset-share-commons/components/details/pdf/_cq_design_dialog/.content.xml @@ -30,7 +30,7 @@ jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/form/textfield" emptyText="Enter your Adobe Document Cloud client ID." - fieldDescription="Enter the client ID for your Adobe Document Cloud account registered with your Adobe Acrobat Viewer." + fieldDescription="Enter the client ID for your Adobe Document Cloud account registered with your Adobe Acrobat Viewer. This supersedes the any client ID defined in the Adobe PDF Embed API client ID via OSGi configuration." fieldLabel="Client ID for AEM Publish domain" name="./publishClientId"/> @@ -38,7 +38,7 @@ jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/form/textfield" emptyText="Enter your Adobe Document Cloud client ID." - fieldDescription="Enter the client ID for your Adobe Document Cloud account registered with your Adobe Acrobat Viewer." + fieldDescription="Enter the client ID for your Adobe Document Cloud account registered with your Adobe Acrobat Viewer. This supersedes the any client ID defined in the Adobe PDF Embed API client ID via OSGi configuration." fieldLabel="Client ID for AEM Author domain" name="./authorClientId"/> diff --git a/ui.config/pom.xml b/ui.config/pom.xml index 08813f709..718349e7a 100644 --- a/ui.config/pom.xml +++ b/ui.config/pom.xml @@ -23,7 +23,7 @@ com.adobe.aem.commons assetshare - 3.7.3-SNAPSHOT + 3.8.0-SNAPSHOT ../pom.xml diff --git a/ui.content.sample/pom.xml b/ui.content.sample/pom.xml index f1932fbca..162b0c7ce 100644 --- a/ui.content.sample/pom.xml +++ b/ui.content.sample/pom.xml @@ -23,7 +23,7 @@ com.adobe.aem.commons assetshare - 3.7.3-SNAPSHOT + 3.8.0-SNAPSHOT ../pom.xml diff --git a/ui.content/pom.xml b/ui.content/pom.xml index 8534e7b2f..4171594fe 100644 --- a/ui.content/pom.xml +++ b/ui.content/pom.xml @@ -22,7 +22,7 @@ com.adobe.aem.commons assetshare - 3.7.3-SNAPSHOT + 3.8.0-SNAPSHOT ../pom.xml diff --git a/ui.frontend.theme.dark/pom.xml b/ui.frontend.theme.dark/pom.xml index c112e5fcb..271367c6b 100644 --- a/ui.frontend.theme.dark/pom.xml +++ b/ui.frontend.theme.dark/pom.xml @@ -23,7 +23,7 @@ com.adobe.aem.commons assetshare - 3.7.3-SNAPSHOT + 3.8.0-SNAPSHOT ../pom.xml diff --git a/ui.frontend.theme.light/pom.xml b/ui.frontend.theme.light/pom.xml index 7822518b2..33a8ebf26 100644 --- a/ui.frontend.theme.light/pom.xml +++ b/ui.frontend.theme.light/pom.xml @@ -23,7 +23,7 @@ com.adobe.aem.commons assetshare - 3.7.3-SNAPSHOT + 3.8.0-SNAPSHOT ../pom.xml