Skip to content

Commit

Permalink
Merge pull request #935 from Accenture/bugfix/12-upsert-response-not-…
Browse files Browse the repository at this point in the history
…equal-to-retrieve-automation-csclsroz-314

Bugfix/12 upsert response not equal to retrieve automation csclsroz 314
  • Loading branch information
JoernBerkefeld authored May 25, 2023
2 parents 5ffb804 + c51a715 commit dbb2036
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 33 deletions.
8 changes: 4 additions & 4 deletions docs/dist/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@ Automation MetadataType
* [.update(metadata, metadataBefore)](#Automation.update) ⇒ <code>Promise</code>
* [.preDeployTasks(metadata)](#Automation.preDeployTasks) ⇒ <code>Promise.&lt;TYPE.AutomationItem&gt;</code>
* [.validateDeployMetadata(metadata)](#Automation.validateDeployMetadata) ⇒ <code>boolean</code>
* [.postDeployTasks(metadata, originalMetadata)](#Automation.postDeployTasks) ⇒ <code>Promise.&lt;void&gt;</code>
* [.postDeployTasks(metadataMap, originalMetadataMap)](#Automation.postDeployTasks) ⇒ <code>Promise.&lt;void&gt;</code>
* [.setFolderPath(metadata)](#Automation.setFolderPath)
* [.setFolderId(metadata)](#Automation.setFolderId)
* [.parseMetadata(metadata)](#Automation.parseMetadata) ⇒ <code>TYPE.AutomationItem</code> \| <code>void</code>
Expand Down Expand Up @@ -1345,16 +1345,16 @@ Whitelisted Activites are deployed but require configuration

<a name="Automation.postDeployTasks"></a>

### Automation.postDeployTasks(metadata, originalMetadata) ⇒ <code>Promise.&lt;void&gt;</code>
### Automation.postDeployTasks(metadataMap, originalMetadataMap) ⇒ <code>Promise.&lt;void&gt;</code>
Gets executed after deployment of metadata type

**Kind**: static method of [<code>Automation</code>](#Automation)
**Returns**: <code>Promise.&lt;void&gt;</code> - -

| Param | Type | Description |
| --- | --- | --- |
| metadata | <code>TYPE.AutomationMap</code> | metadata mapped by their keyField |
| originalMetadata | <code>TYPE.AutomationMap</code> | metadata to be updated (contains additioanl fields) |
| metadataMap | <code>TYPE.AutomationMap</code> | metadata mapped by their keyField |
| originalMetadataMap | <code>TYPE.AutomationMap</code> | metadata to be updated (contains additioanl fields) |

<a name="Automation.setFolderPath"></a>

Expand Down
70 changes: 41 additions & 29 deletions lib/metadataTypes/Automation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -397,23 +398,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.<void>} -
*/
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) {
Expand All @@ -431,7 +432,7 @@ class Automation extends MetadataType {
schedule,
{
Interaction: {
ObjectID: metadata[key].id,
ObjectID: metadataMap[key].id,
},
},
'start',
Expand All @@ -445,31 +446,42 @@ 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;

// 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})`
);
}
}
}
Expand Down

0 comments on commit dbb2036

Please sign in to comment.