From 44df15d2fc66544489986ee8e79424ce84db52ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Berkefeld?= Date: Thu, 25 May 2023 18:06:55 +0200 Subject: [PATCH 1/2] #12: refactoring --- docs/dist/documentation.md | 8 +++---- lib/metadataTypes/Automation.js | 37 +++++++++++++++++---------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/docs/dist/documentation.md b/docs/dist/documentation.md index 586655ff7..c331a7158 100644 --- a/docs/dist/documentation.md +++ b/docs/dist/documentation.md @@ -1212,7 +1212,7 @@ Automation MetadataType * [.update(metadata, metadataBefore)](#Automation.update) ⇒ Promise * [.preDeployTasks(metadata)](#Automation.preDeployTasks) ⇒ Promise.<TYPE.AutomationItem> * [.validateDeployMetadata(metadata)](#Automation.validateDeployMetadata) ⇒ boolean - * [.postDeployTasks(metadata, originalMetadata)](#Automation.postDeployTasks) ⇒ Promise.<void> + * [.postDeployTasks(metadataMap, originalMetadataMap)](#Automation.postDeployTasks) ⇒ Promise.<void> * [.setFolderPath(metadata)](#Automation.setFolderPath) * [.setFolderId(metadata)](#Automation.setFolderId) * [.parseMetadata(metadata)](#Automation.parseMetadata) ⇒ TYPE.AutomationItem \| void @@ -1345,7 +1345,7 @@ Whitelisted Activites are deployed but require configuration -### Automation.postDeployTasks(metadata, originalMetadata) ⇒ Promise.<void> +### Automation.postDeployTasks(metadataMap, originalMetadataMap) ⇒ Promise.<void> Gets executed after deployment of metadata type **Kind**: static method of [Automation](#Automation) @@ -1353,8 +1353,8 @@ Gets executed after deployment of metadata type | Param | Type | Description | | --- | --- | --- | -| metadata | TYPE.AutomationMap | metadata mapped by their keyField | -| originalMetadata | TYPE.AutomationMap | metadata to be updated (contains additioanl fields) | +| metadataMap | TYPE.AutomationMap | metadata mapped by their keyField | +| originalMetadataMap | TYPE.AutomationMap | metadata to be updated (contains additioanl fields) | diff --git a/lib/metadataTypes/Automation.js b/lib/metadataTypes/Automation.js index 83d6b54d3..31c0edcee 100644 --- a/lib/metadataTypes/Automation.js +++ b/lib/metadataTypes/Automation.js @@ -397,23 +397,23 @@ class Automation extends MetadataType { /** * Gets executed after deployment of metadata type * - * @param {TYPE.AutomationMap} metadata metadata mapped by their keyField - * @param {TYPE.AutomationMap} originalMetadata metadata to be updated (contains additioanl fields) + * @param {TYPE.AutomationMap} metadataMap metadata mapped by their keyField + * @param {TYPE.AutomationMap} originalMetadataMap metadata to be updated (contains additioanl fields) * @returns {Promise.} - */ - static async postDeployTasks(metadata, originalMetadata) { - for (const key in metadata) { + static async postDeployTasks(metadataMap, originalMetadataMap) { + for (const key in metadataMap) { // need to put schedule on here if status is scheduled - if (originalMetadata[key]?.type === 'scheduled') { + if (originalMetadataMap[key]?.type === 'scheduled') { // Starting Source == 'Schedule': Try starting the automation - if (originalMetadata[key].status === 'Scheduled') { + if (originalMetadataMap[key].status === 'Scheduled') { let schedule = null; try { - schedule = this._buildSchedule(originalMetadata[key].schedule); + schedule = this._buildSchedule(originalMetadataMap[key].schedule); } catch (ex) { Util.logger.error( - `- Could not create schedule for automation ${originalMetadata[key].name} to start it: ${ex.message}` + `- Could not create schedule for automation ${originalMetadataMap[key].name} to start it: ${ex.message}` ); } if (schedule !== null) { @@ -431,7 +431,7 @@ class Automation extends MetadataType { schedule, { Interaction: { - ObjectID: metadata[key].id, + ObjectID: metadataMap[key].id, }, }, 'start', @@ -445,31 +445,32 @@ class Automation extends MetadataType { (schedule_interval > 1 ? 's' : '')); Util.logger.warn( ` - scheduled automation '${ - originalMetadata[key].name + originalMetadataMap[key].name }' deployed Active: runs every ${intervalString} starting ${ schedule_StartDateTime.split('T').join(' ').split('.')[0] } ${schedule_timezoneString}` ); } catch (ex) { Util.logger.error( - `- Could not start scheduled automation '${originalMetadata[key].name}': ${ex.message}` + `- Could not start scheduled automation '${originalMetadataMap[key].name}': ${ex.message}` ); } } } else { Util.logger.warn( - ` - scheduled automation '${originalMetadata[key].name}' deployed Paused` + ` - scheduled automation '${originalMetadataMap[key].name}' deployed Paused` ); } } - if (metadata[key].startSource) { - metadata[key].schedule = metadata[key].startSource.schedule; + if (metadataMap[key].startSource) { + metadataMap[key].schedule = metadataMap[key].startSource.schedule; - delete metadata[key].startSource; + delete metadataMap[key].startSource; + } + if (metadataMap[key].schedule) { + metadataMap[key].schedule.typeId = metadataMap[key].schedule.scheduleTypeId; + delete metadataMap[key].schedule.scheduleTypeId; } - if (metadata[key].schedule) { - metadata[key].schedule.typeId = metadata[key].schedule.scheduleTypeId; - delete metadata[key].schedule.scheduleTypeId; } } } From c51a7150a3e141a1f8ca6b6df1d98bb3a12bd832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Berkefeld?= Date: Thu, 25 May 2023 18:07:28 +0200 Subject: [PATCH 2/2] #12: re-retrieve automation after deployment to get accurate json --- lib/metadataTypes/Automation.js | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/metadataTypes/Automation.js b/lib/metadataTypes/Automation.js index 31c0edcee..50e114595 100644 --- a/lib/metadataTypes/Automation.js +++ b/lib/metadataTypes/Automation.js @@ -70,18 +70,19 @@ class Automation extends MetadataType { }) ) : []; - const parsed = this.parseResponseBody({ items: details }); - - // * retrieveDir is mandatory in this method as it is not used for caching (there is a seperate method for that) - const savedMetadata = await this.saveResults(parsed, retrieveDir, null, null); - Util.logger.info( - `Downloaded: ${this.definition.type} (${Object.keys(savedMetadata).length})` + - Util.getKeysString(key) - ); - if (this.properties.metaDataTypes.documentOnRetrieve.includes(this.definition.type)) { - await this.document(savedMetadata); + let metadataMap = this.parseResponseBody({ items: details }); + // * retrieveDir can be empty when we use it in the context of postDeployTasks + if (retrieveDir) { + metadataMap = await this.saveResults(metadataMap, retrieveDir, null, null); + Util.logger.info( + `Downloaded: ${this.definition.type} (${Object.keys(metadataMap).length})` + + Util.getKeysString(key) + ); + if (this.properties.metaDataTypes.documentOnRetrieve.includes(this.definition.type)) { + await this.document(metadataMap); + } } - return { metadata: savedMetadata, type: this.definition.type }; + return { metadata: metadataMap, type: this.definition.type }; } /** * Retrieves Metadata of Automation @@ -471,6 +472,16 @@ class Automation extends MetadataType { metadataMap[key].schedule.typeId = metadataMap[key].schedule.scheduleTypeId; delete metadataMap[key].schedule.scheduleTypeId; } + + // re-retrieve deployed items because the API does not return any info for them except the new id (api key) + try { + const { metadata } = await this.retrieve(null, null, null, key); + metadataMap[key] = Object.values(metadata)[0]; + // postRetrieveTasks will be run automatically on this via super.saveResult + } catch (ex) { + throw new Error( + `Could not get details for new ${this.definition.type} ${key} from server (${ex.message})` + ); } } }