PIM整合的AEM Assets事件
瞭解如何將AEM Assets與協力廠商系統(例如產品資訊管理(PIM)或產品線管理(PLM)系統)整合,以使用原生AEM IO事件 更新資產中繼資料。 在收到AEM Assets事件後,可以根據業務需求在AEM、PIM或兩個系統中更新資產中繼資料。 不過,此範例示範如何在AEM中更新資產中繼資料。
若要在AEM 、Adobe I/O Runtime之外執行資產中繼資料更新 程式碼,使用的是無伺服器平台。
事件處理流程如下:
用於PIM整合的
- 當資產上傳完成且所有資產處理活動完成時,AEM作者服務會觸發 資產處理完成 事件。 等待處理完成可確保已完成任何現成的處理,例如中繼資料擷取。
- 事件已傳送至Adobe I/O事件服務。
- Adobe I/O事件服務會將事件傳遞至Adobe I/O Runtime動作進行處理。
- 「Adobe I/O Runtime動作」會呼叫PIM系統的API來擷取其他中繼資料,例如SKU、供應商資訊或其他詳細資訊。
- 從PIM擷取的其他中繼資料會在AEM Assets中使用Assets作者API更新。
先決條件
若要完成本教學課程,您需要:
-
已啟用AEM事件的AEM as a Cloud Service環境。 此外,必須在其上部署範例WKND Sites專案。
-
Adobe Developer CLI已安裝在您的本機電腦上。
開發步驟
高階開發步驟為:
- 在Adobe Developer Console (ADC)中建立專案
- 初始化專案以進行本機開發
- 在ADC中設定專案
- 設定AEM作者服務以啟用ADC專案通訊
- 開發執行階段動作來協調中繼資料的擷取和更新
- 將資產上傳至AEM作者服務,並確認中繼資料已更新
如需步驟1至2的詳細資訊,請參閱Adobe I/O Runtime動作和AEM事件範例;如需步驟3至6,請參閱下列章節。
在Adobe Developer Console (ADC)中設定專案
若要接收AEM Assets事件並執行上一步建立的Adobe I/O Runtime動作,請在ADC中設定專案。
-
在ADC中,導覽至專案。 選取
Stage
工作區,這是部署執行階段動作的位置。 -
按一下 新增服務 按鈕,然後選取 事件 選項。 在 新增事件 對話方塊中,選取 Experience Cloud > AEM Assets,然後按一下 下一步。 按照其他設定步驟操作,選取AEMCS執行個體、已完成資產處理 事件、OAuth伺服器對伺服器驗證型別,以及其他詳細資料。
-
最後,在 如何接收事件 步驟中,展開 執行階段動作 選項,並選取在上一步建立的 一般 動作。 按一下 儲存已設定的事件。
-
同樣地,按一下 新增服務 按鈕並選取 API 選項。 在 新增API 強制回應視窗中,選取 Experience Cloud > AEM as a Cloud Service API 並按一下 下一步。
-
然後選取 OAuth伺服器對伺服器 做為驗證型別,並按一下 下一步。
-
然後選取 AEM Administrators-XXX 產品設定檔,並按一下 儲存設定的API。 若要更新相關資產,選取的產品設定檔必須與產生事件的AEM Assets環境相關聯,且必須有足夠存取權在該處更新資產。
設定AEM作者服務以啟用ADC專案通訊
若要從上述ADC專案更新AEM中的資產中繼資料,請使用ADC專案的使用者端ID設定AEM Author服務。 已使用AdobeCloud Manager UI將 使用者端識別碼 新增為環境變數。
-
登入AdobeCloud Manager,選取 程式 > 環境 > 省略符號 > 檢視詳細資料 > 組態 標籤。
-
然後 新增組態 按鈕並輸入變數詳細資訊
table 0-row-4 1-row-4 名稱 值 AEM服務 類型 Adobe提供的CLIENT_ID <COPY_FROM_ADC_PROJECT_CREDENTIALS> 作者 變數 -
按一下 新增 和 儲存 組態。
開發執行階段動作
若要執行中繼資料擷取和更新,請先更新src/dx-excshell-1/actions/generic
資料夾中自動建立的 通用 動作代碼。
如需完整程式碼,請參閱附加的WKND-Assets-PIM-Integration.zip檔案,以下區段將重點說明重要檔案。
-
src/dx-excshell-1/actions/generic/mockPIMCommunicator.js
檔案會模擬PIM API呼叫,以擷取其他中繼資料,例如SKU和供應商名稱。 此檔案用於示範用途。 一旦您讓端對端流程正常運作,請以呼叫您真正的PIM系統來取代此函式,以擷取資產的中繼資料。code language-javascript /** * Mock PIM API to get the product data such as SKU, Supplier, etc. * * In a real-world scenario, this function would call the PIM API to get the product data. * For this example, we are returning mock data. * * @param {string} assetId - The assetId to get the product data. */ module.exports = { async getPIMData(assetId) { if (!assetId) { throw new Error('Invalid assetId'); } // Mock response data for demo purposes const data = { SKUID: 'MockSKU 123', SupplierName: 'mock-supplier', // ... other product data }; return data; }, };
-
src/dx-excshell-1/actions/generic/aemCommunicator.js
檔案會使用Assets作者API更新AEM中的資產中繼資料。code language-javascript const fetch = require('node-fetch'); ... /** * Get IMS Access Token using Client Credentials Flow * * @param {*} clientId - IMS Client ID from ADC project's OAuth Server-to-Server Integration * @param {*} clientSecret - IMS Client Secret from ADC project's OAuth Server-to-Server Integration * @param {*} scopes - IMS Meta Scopes from ADC project's OAuth Server-to-Server Integration as comma separated strings * @returns {string} - Returns the IMS Access Token */ async function getIMSAccessToken(clientId, clientSecret, scopes) { const adobeIMSV3TokenEndpointURL = 'https://ims-na1.adobelogin.com/ims/token/v3'; const options = { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, body: `grant_type=client_credentials&client_id=${clientId}&client_secret=${clientSecret}&scope=${scopes}`, }; const response = await fetch(adobeIMSV3TokenEndpointURL, options); const responseJSON = await response.json(); return responseJSON.access_token; } async function updateAEMAssetMetadata(metadataDetails, aemAssetEvent, params) { ... // Transform the metadata details to JSON Patch format, // see https://developer.adobe.com/experience-cloud/experience-manager-apis/api/experimental/assets/author/#operation/patchAssetMetadata const transformedMetadata = Object.keys(metadataDetails).map((key) => ({ op: 'add', path: `wknd-${key.toLowerCase()}`, value: metadataDetails[key], })); ... // Get ADC project's OAuth Server-to-Server Integration credentials const clientId = params.ADC_CECREDENTIALS_CLIENTID; const clientSecret = params.ADC_CECREDENTIALS_CLIENTSECRET; const scopes = params.ADC_CECREDENTIALS_METASCOPES; // Get IMS Access Token using Client Credentials Flow const access_token = await getIMSAccessToken(clientId, clientSecret, scopes); // Call AEM Author service to update the metadata using Assets Author API // See https://developer.adobe.com/experience-cloud/experience-manager-apis/api/experimental/assets/author/ const res = await fetch(`${aemAuthorHost}/adobe/assets/${assetId}/metadata`, { method: 'PATCH', headers: { 'Content-Type': 'application/json-patch+json', 'If-Match': '*', 'X-Adobe-Accept-Experimental': '1', 'X-Api-Key': 'aem-assets-management-api', // temporary value Authorization: `Bearer ${access_token}`, }, body: JSON.stringify(transformedMetadata), }); ... } module.exports = { updateAEMAssetMetadata };
.env
檔案儲存ADC專案的OAuth伺服器對伺服器認證詳細資料,並使用ext.config.yaml
檔案將這些資料作為引數傳遞給動作。 如需管理密碼和動作引數,請參閱App Builder組態檔。 -
src/dx-excshell-1/actions/model
資料夾包含aemAssetEvent.js
和errors.js
檔案,動作會使用這些檔案分別剖析收到的事件和處理錯誤。 -
src/dx-excshell-1/actions/generic/index.js
檔案使用先前提及的模組來協調中繼資料擷取和更新。code language-javascript ... let responseMsg; // handle the challenge probe request, they are sent by I/O to verify the action is valid if (params.challenge) { logger.info('Challenge probe request detected'); responseMsg = JSON.stringify({ challenge: params.challenge }); } else { logger.info('AEM Asset Event request received'); // create AEM Asset Event object from request parameters const aemAssetEvent = new AEMAssetEvent(params); // Call mock PIM API to get the product data such as SKU, Supplier, etc. const mockPIMData = await mockPIMAPI.getPIMData( aemAssetEvent.getAssetName(), ); logger.info('Mock PIM API response', mockPIMData); // Update PIM received data in AEM as Asset metadata const aemUpdateStatus = await updateAEMAssetMetadata( mockPIMData, aemAssetEvent, params, ); logger.info('AEM Asset metadata update status', aemUpdateStatus); if (aemUpdateStatus) { // create response message responseMsg = JSON.stringify({ message: 'AEM Asset Event processed successfully, updated the asset metadata with PIM data.', assetdata: { assetName: aemAssetEvent.getAssetName(), assetPath: aemAssetEvent.getAssetPath(), assetId: aemAssetEvent.getAssetId(), aemHost: aemAssetEvent.getAEMHost(), pimdata: mockPIMData, }, }); } // response object const response = { statusCode: 200, body: responseMsg, }; // Return the response to the caller return response; ... }
使用以下命令,將更新的動作部署到Adobe I/O Runtime:
$ aio app deploy
資產上傳和中繼資料驗證
若要驗證AEM Assets與PIM整合,請遵循下列步驟:
-
若要檢視模擬PIM提供的中繼資料,例如SKU和Supplier Name,請在AEM Assets中建立中繼資料結構描述,請參閱顯示SKU和供應商名稱中繼資料屬性的中繼資料結構描述。
-
在AEM作者服務中上傳資產,並驗證中繼資料更新。
概念與主要要領
企業通常需要在AEM和其他系統(例如PIM)之間同步資產中繼資料。 使用AEM Eventing可以達到此類要求。
- 資產中繼資料擷取程式碼會在AEM外部執行,避免AEM Author服務上的負載,因此事件導向架構可獨立擴展。
- 新推出的Assets Author API可用於更新AEM中的資產中繼資料。
- API驗證使用OAuth伺服器對伺服器(亦稱為使用者端認證流程),請參閱OAuth伺服器對伺服器認證實作指南。
- 與其使用Adobe I/O Runtime動作,其他Webhook或Amazon EventBridge可以用來接收AEM Assets事件和處理中繼資料更新。
- 透過AEM Eventing進行的資產事件可讓企業自動化及簡化關鍵程式,提升整個內容生態系統的效率及一致性。