Skip to content

Commit 08f97d2

Browse files
Merge pull request #2456 from Accenture/develop
8.3.1
2 parents 8246d53 + 81012fc commit 08f97d2

14 files changed

Lines changed: 106 additions & 36 deletions

@types/lib/metadataTypes/DataFilter.d.ts

Lines changed: 18 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

@types/lib/metadataTypes/DataFilter.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

@types/lib/metadataTypes/MetadataType.d.ts

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

@types/lib/metadataTypes/MetadataType.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/metadataTypes/DataFilter.js

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import File from '../util/file.js';
2020
* @typedef {import('../../types/mcdev.d.js').SoapRequestParams} SoapRequestParams
2121
* @typedef {import('../../types/mcdev.d.js').TemplateMap} TemplateMap
2222
* @typedef {import('../../types/mcdev.d.js').DataFilterItem} DataFilterItem
23+
* @typedef {import('../../types/mcdev.d.js').DataExtensionFieldMap} DataExtensionFieldMap
24+
* @typedef {import('../../types/mcdev.d.js').DataExtensionFieldItem} DataExtensionFieldItem
2325
* @typedef {import('../../types/mcdev.d.js').DataFilterMap} DataFilterMap
2426
* @typedef {import('../../types/mcdev.d.js').MultiMetadataTypeMap} MultiMetadataTypeMap
2527
* @typedef {import('../../types/mcdev.d.js').FilterConditionSet} FilterConditionSet
@@ -201,12 +203,18 @@ class DataFilter extends MetadataType {
201203
: Object.values(metadataTypeMap)
202204
.filter((item) => item.r__source_dataExtension_key)
203205
.map((item) => item.r__source_dataExtension_key)
206+
.filter(
207+
(deKey) =>
208+
!this.cache.dataExtensionField ||
209+
!this.cache.dataExtensionField[deKey]
210+
)
204211
.filter(Boolean);
205212
if (deKeys.length) {
213+
const deKeysUnique = [...new Set(deKeys)];
206214
Util.logger.info(' - Caching dependent Metadata: dataExtensionField');
207215
// only proceed with the download if we have dataExtension keys
208216
const fieldOptions = {};
209-
for (const deKey of deKeys) {
217+
for (const deKey of deKeysUnique) {
210218
fieldOptions.filter = fieldOptions.filter
211219
? {
212220
leftOperand: {
@@ -226,9 +234,32 @@ class DataFilter extends MetadataType {
226234
DataExtensionField.buObject = this.buObject;
227235
DataExtensionField.client = this.client;
228236
DataExtensionField.properties = this.properties;
229-
this.dataExtensionFieldCache = (
230-
await DataExtensionField.retrieveForCacheDE(fieldOptions, ['Name', 'ObjectID'])
231-
).metadata;
237+
this.saveDataExtensionFieldCacheToMap(
238+
(await DataExtensionField.retrieveForCacheDE(fieldOptions, ['Name', 'ObjectID']))
239+
.metadata
240+
);
241+
}
242+
}
243+
/**
244+
* helper for {@link DataFilter._cacheDeFields}
245+
*
246+
* @param {DataExtensionFieldMap} deFieldCache -
247+
*/
248+
static saveDataExtensionFieldCacheToMap(deFieldCache) {
249+
this.cache.dataExtensionField ||= {};
250+
251+
if (!deFieldCache) {
252+
return;
253+
}
254+
for (const field of Object.values(deFieldCache)) {
255+
if (!field?.DataExtension?.CustomerKey) {
256+
continue;
257+
}
258+
if (!this.cache.dataExtensionField[field.DataExtension.CustomerKey]) {
259+
/** @type {Object.<string, DataExtensionFieldItem[]>} */
260+
this.cache.dataExtensionField[field.DataExtension.CustomerKey] = [];
261+
}
262+
this.cache.dataExtensionField[field.DataExtension.CustomerKey].push(field);
232263
}
233264
}
234265
/**
@@ -399,7 +430,7 @@ class DataFilter extends MetadataType {
399430
*
400431
* @param {DataFilterItem} metadata -
401432
* @param {'postRetrieve'|'preDeploy'} mode -
402-
* @param {object[]} [fieldCache] -
433+
* @param {DataExtensionFieldItem[]} [fieldCache] -
403434
* @param {FilterConditionSet} [filter] -
404435
* @returns {void}
405436
*/
@@ -408,7 +439,7 @@ class DataFilter extends MetadataType {
408439
return this._resolveFields(
409440
metadata,
410441
mode,
411-
Object.values(this.dataExtensionFieldCache),
442+
this.cache.dataExtensionField[metadata.r__source_dataExtension_key],
412443
metadata.c__filterDefinition?.ConditionSet
413444
);
414445
}
@@ -418,11 +449,11 @@ class DataFilter extends MetadataType {
418449
: [filter.Condition];
419450
if (mode === 'postRetrieve') {
420451
for (const condition of conditionsArr) {
421-
this._postRetrieve_resolveFieldIdsCondition(condition, fieldCache);
452+
this._postRetrieve_resolveFieldIdsCondition(metadata, condition, fieldCache);
422453
}
423454
} else if (mode === 'preDeploy') {
424455
for (const condition of conditionsArr) {
425-
this._preDeploy_resolveFieldNamesCondition(condition, fieldCache);
456+
this._preDeploy_resolveFieldNamesCondition(metadata, condition, fieldCache);
426457
}
427458
}
428459
}
@@ -438,16 +469,21 @@ class DataFilter extends MetadataType {
438469
/**
439470
* helper for {@link _resolveFields}
440471
*
472+
* @param {DataFilterItem} metadata -
441473
* @param {FilterCondition} condition -
442-
* @param {object[]} fieldCache -
474+
* @param {DataExtensionFieldItem[]} fieldCache -
443475
* @returns {void}
444476
*/
445-
static _postRetrieve_resolveFieldIdsCondition(condition, fieldCache) {
477+
static _postRetrieve_resolveFieldIdsCondition(metadata, condition, fieldCache) {
446478
condition.r__dataExtensionField_name = fieldCache.find(
447479
(field) => field.ObjectID === condition['@_ID']
448480
)?.Name;
449481
if (condition.r__dataExtensionField_name) {
450482
delete condition['@_ID'];
483+
} else {
484+
Util.logger.warn(
485+
` - ${this.definition.type} ${metadata[this.definition.keyField]}: could not resolve dataExtensionField with ID ${condition['@_ID']} in condition`
486+
);
451487
}
452488
if (['IsEmpty', 'IsNotEmpty'].includes(condition['@_Operator'])) {
453489
delete condition.Value;
@@ -456,16 +492,21 @@ class DataFilter extends MetadataType {
456492
/**
457493
* helper for {@link _resolveFields}
458494
*
495+
* @param {DataFilterItem} metadata -
459496
* @param {FilterCondition} condition -
460-
* @param {object[]} fieldCache -
497+
* @param {DataExtensionFieldItem[]} fieldCache -
461498
* @returns {void}
462499
*/
463-
static _preDeploy_resolveFieldNamesCondition(condition, fieldCache) {
500+
static _preDeploy_resolveFieldNamesCondition(metadata, condition, fieldCache) {
464501
condition['@_ID'] = fieldCache.find(
465502
(field) => field.Name === condition.r__dataExtensionField_name
466503
)?.ObjectID;
467504
if (condition['@_ID']) {
468505
delete condition.r__dataExtensionField_name;
506+
} else {
507+
throw new Error(
508+
` - ${this.definition.type} ${metadata[this.definition.keyField]}: could not resolve dataExtensionField with Name ${condition.r__dataExtensionField_name} in condition`
509+
);
469510
}
470511
if (['IsEmpty', 'IsNotEmpty'].includes(condition['@_Operator'])) {
471512
condition.Value ||= '';

lib/metadataTypes/MetadataType.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,19 @@ class MetadataType {
753753
return false;
754754
}
755755

756+
/**
757+
* helper for {@link MetadataType.upsert} to enforce max key length
758+
*
759+
* @param {string} metadataKey key of metadata
760+
*/
761+
static enforceMaxKeyLength(metadataKey) {
762+
if (this.definition.maxKeyLength && metadataKey.length > this.definition.maxKeyLength) {
763+
throw new Error(
764+
`key exceeds maximum length of ${this.definition.maxKeyLength} characters for this type`
765+
);
766+
}
767+
}
768+
756769
/**
757770
* MetadataType upsert, after retrieving from target and comparing to check if create or update operation is needed.
758771
*
@@ -774,6 +787,7 @@ class MetadataType {
774787
// preDeployTasks parsing
775788
let deployableMetadata;
776789
try {
790+
this.enforceMaxKeyLength(metadataKey);
777791
metadataMap[metadataKey] = await this.validation(
778792
'deploy',
779793
metadataMap[metadataKey],

test/mockRoot/deploy/testInstance/testBU/asset/block/testExisting_asset_htmlblock-matchName-create.asset-block-meta.html renamed to test/mockRoot/deploy/testInstance/testBU/asset/block/testExisting_asset_html-matchNamFail.asset-block-meta.html

File renamed without changes.

test/mockRoot/deploy/testInstance/testBU/asset/block/testExisting_asset_htmlblock-matchName-fail.asset-block-meta.json renamed to test/mockRoot/deploy/testInstance/testBU/asset/block/testExisting_asset_html-matchNamFail.asset-block-meta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"customerKey": "testExisting_asset_htmlblock-matchName-fail",
2+
"customerKey": "testExisting_asset_html-matchNamFail",
33
"assetType": {
44
"name": "htmlblock",
55
"displayName": "HTML Block"

test/mockRoot/deploy/testInstance/testBU/asset/block/testExisting_asset_htmlblock-matchName-fail.asset-block-meta.html renamed to test/mockRoot/deploy/testInstance/testBU/asset/block/testExisting_asset_html-matchName.asset-block-meta.html

File renamed without changes.

test/mockRoot/deploy/testInstance/testBU/asset/block/testExisting_asset_htmlblock-matchName.asset-block-meta.json renamed to test/mockRoot/deploy/testInstance/testBU/asset/block/testExisting_asset_html-matchName.asset-block-meta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"customerKey": "testExisting_asset_htmlblock-matchName",
2+
"customerKey": "testExisting_asset_html-matchName",
33
"assetType": {
44
"name": "htmlblock",
55
"displayName": "HTML Block"

0 commit comments

Comments
 (0)