-
Notifications
You must be signed in to change notification settings - Fork 36
/
AttributeGroup.js
117 lines (104 loc) · 3.94 KB
/
AttributeGroup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
'use strict';
import MetadataType from './MetadataType.js';
import TYPE from '../../types/mcdev.d.js';
import { Util } from '../util/util.js';
import cache from '../util/cache.js';
/**
* AttributeGroup MetadataType
*
* @augments MetadataType
*/
class AttributeGroup extends MetadataType {
/**
* Retrieves Metadata of schema attribute groups.
*
* @param {string} retrieveDir Directory where retrieved metadata directory will be saved
* @param {void} [_] unused parameter
* @param {void} [__] unused parameter
* @param {string} [key] customer key of single item to retrieve
* @returns {Promise.<TYPE.MetadataTypeMapObj>} Promise of metadata
*/
static async retrieve(retrieveDir, _, __, key) {
return super.retrieveREST(
retrieveDir,
'/hub/v1/contacts/schema/attributeGroups',
null,
key
);
}
/**
* Retrieves Metadata of schema attribute groups for caching.
*
* @returns {Promise.<TYPE.MetadataTypeMapObj>} Promise of metadata
*/
static retrieveForCache() {
return super.retrieveREST(null, '/hub/v1/contacts/schema/attributeGroups');
}
/**
* manages post retrieve steps
*
* @param {TYPE.MetadataTypeItem} metadata a single metadata
* @returns {TYPE.MetadataTypeItem} metadata
*/
static postRetrieveTasks(metadata) {
// Member ID
delete metadata.mID;
// attributeSet
metadata.attributeSetIdentifiers = metadata.attributeSetIdentifiers.map((attributeSet) => {
try {
const key = cache.searchForField(
'attributeSet',
attributeSet.definitionID,
'definitionID',
'definitionKey'
);
if (key !== attributeSet.definitionKey) {
throw new Error(
`AttributeSet key mismatch. Found ${key} instead of ${attributeSet.definitionKey}`
);
}
return key;
} catch (ex) {
Util.logger.warn(
` - ${this.definition.type} ${metadata[this.definition.keyField]} (for ${
attributeSet.definitionKey
}): ${ex.message}`
);
return attributeSet;
}
});
// requiredRelationships
// TODO: implement
// description is not returned by API when empty. Set to empty string to propose the field as an option to users
metadata.description ||= '';
// applicationKey is only used by system generated attribute groups and otherwise it's empty.
if (metadata.applicationKey === '') {
// remove useless field
delete metadata.applicationKey;
}
// connectingID.identifierType seems to be always set to 'FullyQualifiedName' - to be sure we check it here and remove it if it's the case
if (metadata.connectingID?.identifierType === 'FullyQualifiedName') {
// remove useless field
delete metadata.connectingID;
}
// containsSchemaAttributes is only true for system generated attribute groups and otherwise it's false.
if (!metadata.containsSchemaAttributes) {
delete metadata.containsSchemaAttributes;
}
// isSystemDefined is only true for system generated attribute groups and cannot be deployed
if (!metadata.isSystemDefined) {
delete metadata.isSystemDefined;
}
return metadata;
}
/**
* prepares for deployment
*
* @param {TYPE.MetadataTypeItem} metadata a single item
* @returns {TYPE.MetadataTypeItem} Promise
*/
}
// Assign definition to static attributes
import MetadataTypeDefinitions from '../MetadataTypeDefinitions.js';
AttributeGroup.definition = MetadataTypeDefinitions.attributeGroup;
export default AttributeGroup;