@izara_project/izara-core-generate-service-code 1.0.73 → 1.0.75
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/emit/coreFunction/emitCoreFunctionArtifacts.js +3 -0
- package/src/emit/coreFunction/templates/InitialSetupConfig.ejs +100 -28
- package/src/emit/coreFunction/templates/InitialSetupRunner_uploadSchema.ejs +2 -0
- package/src/emit/coreFunction/templates/UploadSchema_Main.ejs +2 -0
- package/src/emit/crud/emitCrudApplicationArtifacts.js +2 -2
- package/src/emit/crud/emitDynamicCrudFlowSchemas.js +43 -2
- package/src/emit/crud/templates/CreateComplete_HdrSqs.ejs +99 -0
- package/src/emit/crud/templates/CreateComplete_Main.ejs +188 -0
- package/src/emit/crud/templates/DeleteComplete_HdrSqs.ejs +99 -0
- package/src/emit/crud/templates/DeleteComplete_Main.ejs +188 -0
- package/src/emit/crud/templates/FlowEndpointComplete_Main.ejs +1 -1
- package/src/emit/crud/templates/UpdateComplete_HdrSqs.ejs +99 -0
- package/src/emit/crud/templates/UpdateComplete_Main.ejs +188 -0
- package/src/emit/custom/customFlows.js +56 -0
- package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +24 -9
- package/src/emit/custom/templates/FlowEndpoint_Main.ejs +1 -1
- package/src/emit/custom/templates/triggerCache/CheckTriggerCache_HdrSqs.ejs +2 -1
- package/src/emit/function/functionYamlArtifact.js +8 -3
- package/src/emit/relationship/emitDynamicRelationshipFlowSchemas.js +21 -1
- package/src/emit/relationship/emitRelationshipApplicationArtifacts.js +1 -1
- package/src/emit/relationship/templates/ChangeRelationshipComplete_HdrSqs.ejs +99 -0
- package/src/emit/relationship/templates/ChangeRelationshipComplete_Main.ejs +99 -100
- package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +5 -14
- package/src/emit/relationship/templates/CreateRelationshipComplete_HdrSqs.ejs +99 -0
- package/src/emit/relationship/templates/CreateRelationshipComplete_Main.ejs +98 -99
- package/src/emit/relationship/templates/CreateRelationship_Main.ejs +7 -16
- package/src/emit/relationship/templates/DeleteRelationshipComplete_HdrSqs.ejs +99 -0
- package/src/emit/relationship/templates/DeleteRelationshipComplete_Main.ejs +93 -85
- package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +6 -24
- package/src/emit/relationship/templates/GetRelationshipComplete_HdrSqs.ejs +99 -0
- package/src/emit/relationship/templates/GetRelationshipComplete_Main.ejs +10 -4
- package/src/emit/relationship/templates/GetRelationship_Main.ejs +2 -20
- package/src/emit/relationship/templates/MoveRelationshipComplete_HdrSqs.ejs +99 -0
- package/src/emit/relationship/templates/MoveRelationshipComplete_Main.ejs +101 -104
- package/src/emit/relationship/templates/MoveRelationship_Main.ejs +6 -15
- package/src/emit/relationship/templates/UpdateRelationshipComplete_HdrSqs.ejs +99 -0
- package/src/emit/relationship/templates/UpdateRelationshipComplete_Main.ejs +92 -110
- package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +6 -15
- package/src/emit/resource/emitResourceArtifacts.js +25 -1
- package/src/emit/resource/templates/DynamoDBTable_Yaml.ejs +3 -0
- package/src/emit/shared/templates/FindData_Main.ejs +1 -1
- package/src/emit/shared/templates/FlowHandler_HdrApi.ejs +1 -1
- package/src/emit/shared/templates/FlowHandler_HdrDsq.ejs +2 -1
- package/src/emit/shared/templates/FlowHandler_HdrInv.ejs +1 -1
- package/src/emit/shared/templates/FlowHandler_HdrSqs.ejs +2 -1
- package/src/emit/system/emitSystemWebSocketArtifacts.js +54 -2
- package/src/emit/system/templates/RegisterComplete_HdrSqs.ejs +64 -0
- package/src/emit/system/templates/RegisterComplete_Main.ejs +154 -0
- package/src/emit/system/templates/RegisterComplete_Yaml.ejs +17 -0
- package/src/emit/system/templates/RegisterWbs_Yaml.ejs +7 -0
- package/src/emit/system/templates/Register_HdrWbs.ejs +56 -0
- package/src/emit/system/templates/Register_Main.ejs +148 -0
- package/src/emit/system/templates/WebSocketComplete_Yaml.ejs +2 -0
- package/test/crudApplicationArtifacts.test.js +22 -0
- package/test/customFlowApplicationArtifacts.test.js +147 -1
- package/test/functionYamlArtifact.test.js +5 -2
- package/test/publicApi.test.js +50 -0
- package/test/relationshipApplicationArtifacts.test.js +42 -8
- package/test/resourceArtifacts.test.js +54 -16
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { middlewareHandler as middleware } from '@izara_project/izara-middleware';
|
|
2
|
+
import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
|
|
3
|
+
import Logger from '@izara_project/izara-core-library-logger';
|
|
4
|
+
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
5
|
+
import GetRelationshipComplete from './GetRelationshipComplete_Main.js';
|
|
6
|
+
|
|
7
|
+
//(<optionalRequire>)
|
|
8
|
+
//(</optionalRequire>)
|
|
9
|
+
|
|
10
|
+
// validate event properties in body.Message of sqs event
|
|
11
|
+
let perRecordsValidatorSchema = {
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
returnValue: {
|
|
15
|
+
type: 'object'
|
|
16
|
+
},
|
|
17
|
+
parentFlowId: {
|
|
18
|
+
type: 'string'
|
|
19
|
+
},
|
|
20
|
+
status: {
|
|
21
|
+
type: 'string'
|
|
22
|
+
},
|
|
23
|
+
errorsFound: {
|
|
24
|
+
type: 'array'
|
|
25
|
+
},
|
|
26
|
+
graphServiceTag: {
|
|
27
|
+
type: 'string'
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
required: [
|
|
31
|
+
'returnValue',
|
|
32
|
+
'parentFlowId',
|
|
33
|
+
'status',
|
|
34
|
+
'errorsFound',
|
|
35
|
+
'graphServiceTag'
|
|
36
|
+
]
|
|
37
|
+
//(<validatorSchema>)
|
|
38
|
+
//(</validatorSchema>)
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
let messageAttributeValidatorSchema = null;
|
|
42
|
+
middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
43
|
+
|
|
44
|
+
export const main = middleware.wrap(async (event, context) => {
|
|
45
|
+
try {
|
|
46
|
+
let recordPromises = [];
|
|
47
|
+
|
|
48
|
+
// loop each record and send to mainFunction
|
|
49
|
+
await Promise.all(
|
|
50
|
+
event.Records.map(async (record) => {
|
|
51
|
+
let passOnProperties = [];
|
|
52
|
+
record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
|
|
53
|
+
|
|
54
|
+
//validate message (and MessageAttributes)
|
|
55
|
+
await recordHandlerSharedLib.validateRecord(
|
|
56
|
+
record, // one record will send to mainFunction
|
|
57
|
+
'GetRelationshipCompleteHdrSqs', // queue name that need to retry or send to dlq
|
|
58
|
+
perRecordsValidatorSchema, // schema for record.Message
|
|
59
|
+
messageAttributeValidatorSchema
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
// add argument (to invoke lambda) to passOnProperties[]
|
|
63
|
+
passOnProperties.push(record.body.Message);
|
|
64
|
+
passOnProperties.push(
|
|
65
|
+
callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(
|
|
66
|
+
record.body.Message
|
|
67
|
+
)
|
|
68
|
+
);
|
|
69
|
+
//(<additionalParams>)
|
|
70
|
+
//(</additionalParams>)
|
|
71
|
+
record._izContext.logger.debug(
|
|
72
|
+
'passOnProperties in handler',
|
|
73
|
+
passOnProperties
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
77
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
78
|
+
record, // one record will send to mainFunction
|
|
79
|
+
GetRelationshipComplete, // mainFunction that need to invoke.
|
|
80
|
+
'GetRelationshipCompleteHdrSqs', // queue name that need to retry or send to dlq
|
|
81
|
+
passOnProperties // all parameters that mainFunction needed.
|
|
82
|
+
);
|
|
83
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
84
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
try {
|
|
88
|
+
await Promise.all(recordPromises);
|
|
89
|
+
return event.Records;
|
|
90
|
+
} catch {
|
|
91
|
+
Logger.debug(
|
|
92
|
+
'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
} catch (error) {
|
|
96
|
+
Logger.error('Unhandled Error, GetRelationshipComplete_HdrSqs: ', error);
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
@@ -36,15 +36,21 @@ const { TOPIC_NAME_GENERATE_CODE, PREFIX } = consts;
|
|
|
36
36
|
|
|
37
37
|
export default async function getRelationshipComplete(
|
|
38
38
|
_izContext,
|
|
39
|
-
|
|
40
|
-
status,
|
|
41
|
-
errorsFound,
|
|
42
|
-
graphServiceTag,
|
|
39
|
+
requestParams,
|
|
43
40
|
passBackProperties = {}
|
|
44
41
|
) {
|
|
45
42
|
try {
|
|
43
|
+
const {
|
|
44
|
+
returnValue,
|
|
45
|
+
parentFlowId,
|
|
46
|
+
status,
|
|
47
|
+
errorsFound,
|
|
48
|
+
graphServiceTag
|
|
49
|
+
} = requestParams;
|
|
50
|
+
|
|
46
51
|
_izContext.logger.debug('Function:getRelationshipComplete', {
|
|
47
52
|
returnValue: returnValue,
|
|
53
|
+
parentFlowId: parentFlowId,
|
|
48
54
|
status: status,
|
|
49
55
|
errorsFound: errorsFound,
|
|
50
56
|
graphServiceTag: graphServiceTag,
|
|
@@ -162,24 +162,6 @@ export default async function getRelationship(
|
|
|
162
162
|
);
|
|
163
163
|
_izContext.logger.debug('relationshipSchema: ', relationshipSchema);
|
|
164
164
|
|
|
165
|
-
const links = await findLinksByObjTypes(
|
|
166
|
-
_izContext,
|
|
167
|
-
[firstObject.objType, secondObject.objType],
|
|
168
|
-
relationshipSchema.links
|
|
169
|
-
);
|
|
170
|
-
_izContext.logger.debug('links', links);
|
|
171
|
-
if (!links.length) {
|
|
172
|
-
const firstTypeStr = JSON.stringify({
|
|
173
|
-
firstObject: firstObject.objType
|
|
174
|
-
});
|
|
175
|
-
const secondTypeStr = JSON.stringify({
|
|
176
|
-
secondObject: secondObject.objType
|
|
177
|
-
});
|
|
178
|
-
errorsFound.push(
|
|
179
|
-
`not found link between ${firstTypeStr} ${secondTypeStr}`
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
165
|
let targetStorageResources = [];
|
|
184
166
|
|
|
185
167
|
if (relationshipSchema) {
|
|
@@ -213,11 +195,11 @@ export default async function getRelationship(
|
|
|
213
195
|
const {
|
|
214
196
|
serviceTag: firstServiceTag,
|
|
215
197
|
objectType: firstObjectType
|
|
216
|
-
} = firstObjectHie
|
|
198
|
+
} = firstObjectHie?.extendObjType || firstObject?.objType || {};
|
|
217
199
|
const {
|
|
218
200
|
serviceTag: secondServiceTag,
|
|
219
201
|
objectType: secondObjectType
|
|
220
|
-
} = secondObjectHie
|
|
202
|
+
} = secondObjectHie?.extendObjType || secondObject?.objType || {};
|
|
221
203
|
|
|
222
204
|
// find exists link
|
|
223
205
|
if (
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { middlewareHandler as middleware } from '@izara_project/izara-middleware';
|
|
2
|
+
import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
|
|
3
|
+
import Logger from '@izara_project/izara-core-library-logger';
|
|
4
|
+
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
5
|
+
import MoveRelationshipComplete from './MoveRelationshipComplete_Main.js';
|
|
6
|
+
|
|
7
|
+
//(<optionalRequire>)
|
|
8
|
+
//(</optionalRequire>)
|
|
9
|
+
|
|
10
|
+
// validate event properties in body.Message of sqs event
|
|
11
|
+
let perRecordsValidatorSchema = {
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
returnValue: {
|
|
15
|
+
type: 'object'
|
|
16
|
+
},
|
|
17
|
+
parentFlowId: {
|
|
18
|
+
type: 'string'
|
|
19
|
+
},
|
|
20
|
+
status: {
|
|
21
|
+
type: 'string'
|
|
22
|
+
},
|
|
23
|
+
errorsFound: {
|
|
24
|
+
type: 'array'
|
|
25
|
+
},
|
|
26
|
+
graphServiceTag: {
|
|
27
|
+
type: 'string'
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
required: [
|
|
31
|
+
'returnValue',
|
|
32
|
+
'parentFlowId',
|
|
33
|
+
'status',
|
|
34
|
+
'errorsFound',
|
|
35
|
+
'graphServiceTag'
|
|
36
|
+
]
|
|
37
|
+
//(<validatorSchema>)
|
|
38
|
+
//(</validatorSchema>)
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
let messageAttributeValidatorSchema = null;
|
|
42
|
+
middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
43
|
+
|
|
44
|
+
export const main = middleware.wrap(async (event, context) => {
|
|
45
|
+
try {
|
|
46
|
+
let recordPromises = [];
|
|
47
|
+
|
|
48
|
+
// loop each record and send to mainFunction
|
|
49
|
+
await Promise.all(
|
|
50
|
+
event.Records.map(async (record) => {
|
|
51
|
+
let passOnProperties = [];
|
|
52
|
+
record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
|
|
53
|
+
|
|
54
|
+
//validate message (and MessageAttributes)
|
|
55
|
+
await recordHandlerSharedLib.validateRecord(
|
|
56
|
+
record, // one record will send to mainFunction
|
|
57
|
+
'MoveRelationshipCompleteHdrSqs', // queue name that need to retry or send to dlq
|
|
58
|
+
perRecordsValidatorSchema, // schema for record.Message
|
|
59
|
+
messageAttributeValidatorSchema
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
// add argument (to invoke lambda) to passOnProperties[]
|
|
63
|
+
passOnProperties.push(record.body.Message);
|
|
64
|
+
passOnProperties.push(
|
|
65
|
+
callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(
|
|
66
|
+
record.body.Message
|
|
67
|
+
)
|
|
68
|
+
);
|
|
69
|
+
//(<additionalParams>)
|
|
70
|
+
//(</additionalParams>)
|
|
71
|
+
record._izContext.logger.debug(
|
|
72
|
+
'passOnProperties in handler',
|
|
73
|
+
passOnProperties
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
77
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
78
|
+
record, // one record will send to mainFunction
|
|
79
|
+
MoveRelationshipComplete, // mainFunction that need to invoke.
|
|
80
|
+
'MoveRelationshipCompleteHdrSqs', // queue name that need to retry or send to dlq
|
|
81
|
+
passOnProperties // all parameters that mainFunction needed.
|
|
82
|
+
);
|
|
83
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
84
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
try {
|
|
88
|
+
await Promise.all(recordPromises);
|
|
89
|
+
return event.Records;
|
|
90
|
+
} catch {
|
|
91
|
+
Logger.debug(
|
|
92
|
+
'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
} catch (error) {
|
|
96
|
+
Logger.error('Unhandled Error, MoveRelationshipComplete_HdrSqs: ', error);
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
@@ -19,7 +19,7 @@ import { objectHash as hash } from '@izara_project/izara-shared-core';
|
|
|
19
19
|
|
|
20
20
|
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
21
21
|
import snsSharedLib from '@izara_project/izara-core-library-sns';
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
import asyncFlowSharedLib from '@izara_project/izara-core-library-asynchronous-flow';
|
|
24
24
|
|
|
25
25
|
import { sns } from '@izara_project/izara-core-library-external-request';
|
|
@@ -36,128 +36,125 @@ const { TOPIC_NAME_GENERATE_CODE, PREFIX } = consts;
|
|
|
36
36
|
|
|
37
37
|
export default async function <%- functionName %>(
|
|
38
38
|
_izContext,
|
|
39
|
-
|
|
40
|
-
status,
|
|
41
|
-
errorsFound,
|
|
42
|
-
graphServiceTag,
|
|
39
|
+
requestParams,
|
|
43
40
|
passBackProperties = {}
|
|
44
41
|
) {
|
|
45
42
|
try {
|
|
43
|
+
const {
|
|
44
|
+
returnValue,
|
|
45
|
+
parentFlowId,
|
|
46
|
+
status,
|
|
47
|
+
errorsFound,
|
|
48
|
+
graphServiceTag
|
|
49
|
+
} = requestParams;
|
|
50
|
+
|
|
46
51
|
_izContext.logger.debug('Function:<%- functionName %>', {
|
|
47
52
|
returnValue: returnValue,
|
|
53
|
+
parentFlowId: parentFlowId,
|
|
48
54
|
status: status,
|
|
49
55
|
errorsFound: errorsFound,
|
|
50
56
|
graphServiceTag: graphServiceTag,
|
|
51
57
|
passBackProperties: passBackProperties
|
|
52
58
|
});
|
|
53
59
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
_izContext,
|
|
57
|
-
returnValue.requestParams.firstObject.objType,
|
|
58
|
-
returnValue.requestParams.secondObject.objType,
|
|
59
|
-
returnValue.requestParams.relType,
|
|
60
|
-
returnValue.requestParams.relationshipProperties,
|
|
61
|
-
returnValue.requestParams.relationshipDirection,
|
|
62
|
-
returnValue.requestParams.moveObject
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
let awaitingStepId = asyncFlowSharedLib.createAwaitingStepId(
|
|
66
|
-
returnValue.parentFlowId, // hash id
|
|
60
|
+
const awaitingStepId = asyncFlowSharedLib.createAwaitingStepId(
|
|
61
|
+
parentFlowId || returnValue?.parentFlowId, // hash id
|
|
67
62
|
PREFIX.changeRel // prefix, use constant further
|
|
68
63
|
);
|
|
69
64
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
65
|
+
const pending =
|
|
66
|
+
await asyncFlowSharedLib.findPendingStepAwaitingMultipleSteps(
|
|
67
|
+
_izContext,
|
|
68
|
+
awaitingStepId
|
|
69
|
+
);
|
|
70
|
+
_izContext.logger.debug('[<%- functionName %>] awaiting step', {
|
|
71
|
+
awaitingStepId,
|
|
72
|
+
pending
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
if (!pending) {
|
|
76
|
+
_izContext.logger.warn(
|
|
77
|
+
`No pending step found for awaitingStepId: ${awaitingStepId}`
|
|
78
|
+
);
|
|
79
|
+
return { returnValue, status, errorsFound };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const result =
|
|
83
|
+
await asyncFlowSharedLib.checkAllAwaitingStepsFinishedWithReturnParams(
|
|
84
|
+
_izContext,
|
|
85
|
+
pending.pendingStepId,
|
|
86
|
+
awaitingStepId,
|
|
87
|
+
errorsFound
|
|
88
|
+
);
|
|
89
|
+
_izContext.logger.debug(
|
|
90
|
+
'[<%- functionName %>] all awaiting steps result',
|
|
73
91
|
{
|
|
74
|
-
|
|
92
|
+
isComplete: result.isComplete,
|
|
93
|
+
awaitingStepId,
|
|
94
|
+
pendingStepId: pending.pendingStepId
|
|
75
95
|
}
|
|
76
96
|
);
|
|
77
|
-
_izContext.logger.debug(
|
|
78
|
-
'record of moveRelPendingObjects ::',
|
|
79
|
-
moveRelPendingObjects
|
|
80
|
-
);
|
|
81
97
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
status: status,
|
|
104
|
-
parentFlowId: returnValue.parentFlowId,
|
|
105
|
-
errorsFound: errorsFound
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
moveRelCompleteMsg =
|
|
109
|
-
callingFlowSharedLib.addParentPassBackPropertiesToSnsResponseMessageObject(
|
|
110
|
-
passBackProperties,
|
|
111
|
-
moveRelCompleteMsg
|
|
112
|
-
);
|
|
113
|
-
_izContext.logger.debug(
|
|
114
|
-
'After addCallingFlowToSnsResponseMessageObject',
|
|
115
|
-
moveRelCompleteMsg
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
let messageAttributes =
|
|
119
|
-
callingFlowSharedLib.addParentPassBackCallingFlowToSnsResponseMessageAttributes(
|
|
120
|
-
passBackProperties,
|
|
121
|
-
{}
|
|
122
|
-
);
|
|
123
|
-
_izContext.logger.debug(
|
|
124
|
-
'After addCallingFlowToSnsResponseMessageAttributes',
|
|
125
|
-
moveRelCompleteMsg
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
let sendMessageToOutMoveRelationshipComplete = {
|
|
129
|
-
Message: JSON.stringify(moveRelCompleteMsg),
|
|
130
|
-
MessageAttributes: sns.createStringMessageAttributes(
|
|
131
|
-
_izContext,
|
|
132
|
-
messageAttributes
|
|
133
|
-
),
|
|
134
|
-
TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
|
|
135
|
-
_izContext,
|
|
136
|
-
TOPIC_NAME_GENERATE_CODE.outMoveRelComplete
|
|
137
|
-
)
|
|
138
|
-
};
|
|
139
|
-
_izContext.logger.debug(
|
|
140
|
-
'Send message to OutCreateRelationshipComplete :::>',
|
|
141
|
-
sendMessageToOutMoveRelationshipComplete
|
|
142
|
-
);
|
|
143
|
-
await sns.publishAsync(
|
|
144
|
-
_izContext,
|
|
145
|
-
sendMessageToOutMoveRelationshipComplete
|
|
146
|
-
);
|
|
147
|
-
|
|
148
|
-
//(<afterCheckAwaitingStep>)
|
|
149
|
-
//(</afterCheckAwaitingStep>)
|
|
150
|
-
} // check pendingStepId finished
|
|
151
|
-
|
|
152
|
-
// remove awaitingMultipleStep after finished
|
|
153
|
-
await asyncFlowSharedLib.removeAwaitingMultipleStep(
|
|
154
|
-
_izContext,
|
|
155
|
-
awaitingStepId,
|
|
156
|
-
pendingStepId,
|
|
157
|
-
errorsFound
|
|
98
|
+
if (result.isComplete) {
|
|
99
|
+
_izContext.logger.debug('finished all awaitingStep');
|
|
100
|
+
|
|
101
|
+
let moveRelCompleteMsg = {
|
|
102
|
+
firstObject: returnValue.requestParams.firstObject,
|
|
103
|
+
secondObject: returnValue.requestParams.secondObject,
|
|
104
|
+
relType: returnValue.requestParams.relType,
|
|
105
|
+
relationshipProperties:
|
|
106
|
+
returnValue.requestParams.relationshipProperties,
|
|
107
|
+
relationshipDirection:
|
|
108
|
+
returnValue.requestParams.relationshipDirection,
|
|
109
|
+
moveObject: returnValue.requestParams.moveObject,
|
|
110
|
+
status: status,
|
|
111
|
+
parentFlowId: parentFlowId || returnValue?.parentFlowId,
|
|
112
|
+
errorsFound: errorsFound
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
moveRelCompleteMsg =
|
|
116
|
+
callingFlowSharedLib.addParentPassBackPropertiesToSnsResponseMessageObject(
|
|
117
|
+
passBackProperties,
|
|
118
|
+
moveRelCompleteMsg
|
|
158
119
|
);
|
|
159
|
-
|
|
160
|
-
|
|
120
|
+
_izContext.logger.debug(
|
|
121
|
+
'After addCallingFlowToSnsResponseMessageObject',
|
|
122
|
+
moveRelCompleteMsg
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
let messageAttributes =
|
|
126
|
+
callingFlowSharedLib.addParentPassBackCallingFlowToSnsResponseMessageAttributes(
|
|
127
|
+
passBackProperties,
|
|
128
|
+
{}
|
|
129
|
+
);
|
|
130
|
+
_izContext.logger.debug(
|
|
131
|
+
'After addCallingFlowToSnsResponseMessageAttributes',
|
|
132
|
+
moveRelCompleteMsg
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
let sendMessageToOutMoveRelationshipComplete = {
|
|
136
|
+
Message: JSON.stringify(moveRelCompleteMsg),
|
|
137
|
+
MessageAttributes: sns.createStringMessageAttributes(
|
|
138
|
+
_izContext,
|
|
139
|
+
messageAttributes
|
|
140
|
+
),
|
|
141
|
+
TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
|
|
142
|
+
_izContext,
|
|
143
|
+
TOPIC_NAME_GENERATE_CODE.outMoveRelComplete
|
|
144
|
+
)
|
|
145
|
+
};
|
|
146
|
+
_izContext.logger.debug(
|
|
147
|
+
'Send message to OutCreateRelationshipComplete :::>',
|
|
148
|
+
sendMessageToOutMoveRelationshipComplete
|
|
149
|
+
);
|
|
150
|
+
await sns.publishAsync(
|
|
151
|
+
_izContext,
|
|
152
|
+
sendMessageToOutMoveRelationshipComplete
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
//(<afterCheckAwaitingStep>)
|
|
156
|
+
//(</afterCheckAwaitingStep>)
|
|
157
|
+
} // check isComplete finished
|
|
161
158
|
|
|
162
159
|
//(<afterCheckAllAwaitingStep>)
|
|
163
160
|
//(</afterCheckAllAwaitingStep>)
|
|
@@ -382,15 +382,6 @@ export default async function moveRelationship(
|
|
|
382
382
|
return moveRelCompleteMsg;
|
|
383
383
|
}
|
|
384
384
|
|
|
385
|
-
// before create awaitingStepId per graph storageResource
|
|
386
|
-
const linkTypeId = createLinkTypeId(
|
|
387
|
-
_izContext,
|
|
388
|
-
firstObject.objType,
|
|
389
|
-
secondObject.objType,
|
|
390
|
-
relType,
|
|
391
|
-
relationshipDirection
|
|
392
|
-
);
|
|
393
|
-
|
|
394
385
|
let usedGraphServiceTag = []; // collect used graph serviceTag, use to check duplicate graph serviceTag across graph serverTag
|
|
395
386
|
let targetGraphStorageResources = []; // collect used graph storageResources, filtered duplicate graphServiceTag from graphServerTag out
|
|
396
387
|
let awaitingStepIds = [];
|
|
@@ -404,12 +395,12 @@ export default async function moveRelationship(
|
|
|
404
395
|
targetGraphStorageResources.push(targetStorageResource);
|
|
405
396
|
|
|
406
397
|
// awaitingStepId per graphServiceTag
|
|
407
|
-
awaitingStepIds.push(
|
|
408
|
-
asyncFlowSharedLib.createAwaitingStepId(
|
|
398
|
+
awaitingStepIds.push({
|
|
399
|
+
awaitingStepId: asyncFlowSharedLib.createAwaitingStepId(
|
|
409
400
|
parentFlowId, // hash id
|
|
410
401
|
PREFIX.changeRel // prefix, use constant further
|
|
411
402
|
)
|
|
412
|
-
);
|
|
403
|
+
});
|
|
413
404
|
}
|
|
414
405
|
}
|
|
415
406
|
|
|
@@ -417,12 +408,12 @@ export default async function moveRelationship(
|
|
|
417
408
|
// save awaiting
|
|
418
409
|
await asyncFlowSharedLib.createAwaitingMultipleSteps(
|
|
419
410
|
_izContext,
|
|
420
|
-
awaitingStepIds, // awaitingStepIds
|
|
421
411
|
asyncFlowSharedLib.createPendingStepId(
|
|
422
|
-
// pendingStepId
|
|
423
412
|
_izContext.uniqueRequestId, // hash id
|
|
424
413
|
PREFIX.changeRel // prefix, use constant further
|
|
425
|
-
)
|
|
414
|
+
),
|
|
415
|
+
awaitingStepIds,
|
|
416
|
+
{}
|
|
426
417
|
);
|
|
427
418
|
|
|
428
419
|
// prepare message body
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { middlewareHandler as middleware } from '@izara_project/izara-middleware';
|
|
2
|
+
import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
|
|
3
|
+
import Logger from '@izara_project/izara-core-library-logger';
|
|
4
|
+
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
5
|
+
import UpdateRelationshipComplete from './UpdateRelationshipComplete_Main.js';
|
|
6
|
+
|
|
7
|
+
//(<optionalRequire>)
|
|
8
|
+
//(</optionalRequire>)
|
|
9
|
+
|
|
10
|
+
// validate event properties in body.Message of sqs event
|
|
11
|
+
let perRecordsValidatorSchema = {
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
returnValue: {
|
|
15
|
+
type: 'object'
|
|
16
|
+
},
|
|
17
|
+
parentFlowId: {
|
|
18
|
+
type: 'string'
|
|
19
|
+
},
|
|
20
|
+
status: {
|
|
21
|
+
type: 'string'
|
|
22
|
+
},
|
|
23
|
+
errorsFound: {
|
|
24
|
+
type: 'array'
|
|
25
|
+
},
|
|
26
|
+
graphServiceTag: {
|
|
27
|
+
type: 'string'
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
required: [
|
|
31
|
+
'returnValue',
|
|
32
|
+
'parentFlowId',
|
|
33
|
+
'status',
|
|
34
|
+
'errorsFound',
|
|
35
|
+
'graphServiceTag'
|
|
36
|
+
]
|
|
37
|
+
//(<validatorSchema>)
|
|
38
|
+
//(</validatorSchema>)
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
let messageAttributeValidatorSchema = null;
|
|
42
|
+
middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
43
|
+
|
|
44
|
+
export const main = middleware.wrap(async (event, context) => {
|
|
45
|
+
try {
|
|
46
|
+
let recordPromises = [];
|
|
47
|
+
|
|
48
|
+
// loop each record and send to mainFunction
|
|
49
|
+
await Promise.all(
|
|
50
|
+
event.Records.map(async (record) => {
|
|
51
|
+
let passOnProperties = [];
|
|
52
|
+
record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
|
|
53
|
+
|
|
54
|
+
//validate message (and MessageAttributes)
|
|
55
|
+
await recordHandlerSharedLib.validateRecord(
|
|
56
|
+
record, // one record will send to mainFunction
|
|
57
|
+
'UpdateRelationshipCompleteHdrSqs', // queue name that need to retry or send to dlq
|
|
58
|
+
perRecordsValidatorSchema, // schema for record.Message
|
|
59
|
+
messageAttributeValidatorSchema
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
// add argument (to invoke lambda) to passOnProperties[]
|
|
63
|
+
passOnProperties.push(record.body.Message);
|
|
64
|
+
passOnProperties.push(
|
|
65
|
+
callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(
|
|
66
|
+
record.body.Message
|
|
67
|
+
)
|
|
68
|
+
);
|
|
69
|
+
//(<additionalParams>)
|
|
70
|
+
//(</additionalParams>)
|
|
71
|
+
record._izContext.logger.debug(
|
|
72
|
+
'passOnProperties in handler',
|
|
73
|
+
passOnProperties
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
77
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
78
|
+
record, // one record will send to mainFunction
|
|
79
|
+
UpdateRelationshipComplete, // mainFunction that need to invoke.
|
|
80
|
+
'UpdateRelationshipCompleteHdrSqs', // queue name that need to retry or send to dlq
|
|
81
|
+
passOnProperties // all parameters that mainFunction needed.
|
|
82
|
+
);
|
|
83
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
84
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
try {
|
|
88
|
+
await Promise.all(recordPromises);
|
|
89
|
+
return event.Records;
|
|
90
|
+
} catch {
|
|
91
|
+
Logger.debug(
|
|
92
|
+
'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
} catch (error) {
|
|
96
|
+
Logger.error('Unhandled Error, UpdateRelationshipComplete_HdrSqs: ', error);
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
});
|