@izara_project/izara-core-generate-service-code 1.0.66 → 1.0.68
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/.prettierrc +11 -0
- package/docs/TriggeredCache Flow.drawio +193 -0
- package/docs/TriggeredCacheFlow.mmd +47 -0
- package/package.json +16 -12
- package/scripts/format-ejs.js +105 -0
- package/src/compile/compileProject.js +16 -1
- package/src/compile/loadSchemas.js +108 -1
- package/src/emit/crud/emitCrudApplicationArtifacts.js +9 -5
- package/src/emit/crud/emitDynamicCrudFlowSchemas.js +1 -2
- package/src/emit/crud/templates/CreateEndpoint_Main.ejs +300 -109
- package/src/emit/crud/templates/DeleteEndpoint_Main.ejs +221 -143
- package/src/emit/crud/templates/FlowEndpointBeforeLogical_Main.ejs +22 -6
- package/src/emit/crud/templates/FlowEndpointComplete_Main.ejs +150 -38
- package/src/emit/crud/templates/FlowEndpoint_HdrWbs.ejs +51 -31
- package/src/emit/crud/templates/FlowHandler_HdrApi.ejs +57 -31
- package/src/emit/crud/templates/FlowHandler_HdrInv.ejs +28 -26
- package/src/emit/crud/templates/FlowHandler_HdrSqs.ejs +15 -11
- package/src/emit/crud/templates/FlowMain_Wbs.ejs +53 -38
- package/src/emit/crud/templates/GetEndpoint_Main.ejs +6 -3
- package/src/emit/crud/templates/GetRangeEndpoint_Main.ejs +2 -2
- package/src/emit/crud/templates/UpdateEndpoint_Main.ejs +407 -252
- package/src/emit/custom/customFlows.js +112 -31
- package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +89 -77
- package/src/emit/custom/templates/FlowEndpoint_Main.ejs +49 -37
- package/src/emit/custom/templates/FlowStep_Main.ejs +7 -9
- package/src/emit/custom/templates/s3/ConfirmReserved_HdrSqs.ejs +59 -54
- package/src/emit/custom/templates/s3/ConfirmReserved_Main.ejs +33 -23
- package/src/emit/custom/templates/s3/CreateObject_HdrWbs.ejs +30 -23
- package/src/emit/custom/templates/s3/CreateObject_Main.ejs +56 -39
- package/src/emit/custom/templates/s3/CreatePreSignUrl_HdrSqs.ejs +56 -51
- package/src/emit/custom/templates/s3/CreatePreSignUrl_Main.ejs +112 -75
- package/src/emit/custom/templates/s3/FlowHandler_HdrS3.ejs +12 -7
- package/src/emit/custom/templates/s3/ProcessS3File_Main.ejs +11 -8
- package/src/emit/custom/templates/s3/ReservedLimit_HdrSqs.ejs +64 -55
- package/src/emit/custom/templates/s3/ReservedLimit_Main.ejs +74 -52
- package/src/emit/custom/templates/triggerCache/CheckTriggerCache_HdrSqs.ejs +58 -14
- package/src/emit/custom/templates/triggerCache/CheckTriggerCache_Main.ejs +12 -17
- package/src/emit/custom/templates/triggerCache/TriggerCacheComplete_Main.ejs +20 -13
- package/src/emit/custom/templates/triggerCache/TriggerCache_Main.ejs +4 -1
- package/src/emit/function/functionYamlArtifact.js +46 -12
- package/src/emit/rbac/emitDynamicRbacFlowSchemas.js +28 -15
- package/src/emit/rbac/emitRbacApplicationArtifacts.js +179 -66
- package/src/emit/rbac/templates/CreateTargetRole_HdrSqs.ejs +41 -18
- package/src/emit/rbac/templates/CreateTargetRole_Main.ejs +23 -3
- package/src/emit/rbac/templates/ListRbac_HdrApi.ejs +27 -5
- package/src/emit/rbac/templates/ListRbac_HdrSqs.ejs +41 -8
- package/src/emit/rbac/templates/ListRbac_Main.ejs +26 -6
- package/src/emit/rbac/templates/RbacMutation_Main.ejs +23 -3
- package/src/emit/rbac/templates/UserRbacFlow_HdrSqs.ejs +46 -0
- package/src/emit/rbac/templates/UserRbacFlow_Main.ejs +152 -33
- package/src/emit/rbac/templates/UserRoleMutation_Main.ejs +24 -4
- package/src/emit/relationship/emitDynamicRelationshipFlowSchemas.js +1 -2
- package/src/emit/relationship/emitRelationshipApplicationArtifacts.js +6 -5
- package/src/emit/relationship/templates/ChangeRelationshipComplete_Main.ejs +64 -37
- package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +260 -144
- package/src/emit/relationship/templates/CreateRelationshipComplete_Main.ejs +68 -43
- package/src/emit/relationship/templates/CreateRelationship_Main.ejs +315 -171
- package/src/emit/relationship/templates/DeleteRelationshipComplete_Main.ejs +67 -41
- package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +226 -115
- package/src/emit/relationship/templates/FlowHandler_HdrApi.ejs +41 -33
- package/src/emit/relationship/templates/FlowHandler_HdrDsq.ejs +15 -11
- package/src/emit/relationship/templates/FlowHandler_HdrInv.ejs +28 -26
- package/src/emit/relationship/templates/FlowHandler_HdrSqs.ejs +15 -11
- package/src/emit/relationship/templates/GetRelationshipComplete_Main.ejs +46 -26
- package/src/emit/relationship/templates/GetRelationship_Main.ejs +233 -126
- package/src/emit/relationship/templates/MoveRelationshipComplete_Main.ejs +72 -44
- package/src/emit/relationship/templates/MoveRelationship_Main.ejs +266 -150
- package/src/emit/relationship/templates/UpdateRelationshipComplete_Main.ejs +74 -45
- package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +285 -152
- package/src/emit/resource/emitResourceArtifacts.js +499 -108
- package/src/emit/resource/templates/DynamoDBTable_Yaml.ejs +18 -18
- package/src/emit/resource/templates/FlowOut_Yaml.ejs +5 -5
- package/src/emit/resource/templates/GeneratedLambdaRoleServiceConfig.ejs +138 -0
- package/src/emit/resource/templates/ResourceBeforeLogicalYaml.ejs +44 -44
- package/src/emit/resource/templates/ResourceSqsYaml.ejs +36 -36
- package/src/emit/resource/templates/ResourceYaml.ejs +48 -48
- package/src/emit/resource/templates/S3Bucket_Yaml.ejs +19 -0
- package/src/emit/resource/templates/SharedResource_Yaml.ejs +11 -11
- package/src/emit/resource/templates/SystemDynamoDB_Yaml.ejs +105 -105
- package/src/emit/system/emitSystemWebSocketArtifacts.js +2 -1
- package/src/generate.js +8 -4
- package/test/createTargetRoleHandler.test.js +63 -14
- package/test/crudApplicationArtifacts.test.js +1 -1
- package/test/customFlowApplicationArtifacts.test.js +71 -43
- package/test/dynamicCrudFlowSchemas.test.js +6 -6
- package/test/dynamicRbacFlowSchemas.test.js +8 -12
- package/test/dynamicRelationshipFlowSchemas.test.js +3 -3
- package/test/publicApi.test.js +11 -13
- package/test/resourceArtifacts.test.js +13 -3
- package/src/emit/rbac/templates/UserRbacFlow_HdrInv.ejs +0 -10
|
@@ -15,14 +15,17 @@ You should have received a copy of the GNU Affero General Public License
|
|
|
15
15
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
objectHash as hash,
|
|
20
|
+
identifierUuid
|
|
21
|
+
} from '@izara_project/izara-shared-core';
|
|
19
22
|
|
|
20
23
|
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
21
|
-
import lambdaSharedLib from
|
|
22
|
-
import snsSharedLib from
|
|
23
|
-
import asyncFlowSharedLib from
|
|
24
|
+
import lambdaSharedLib from '@izara_project/izara-core-library-lambda';
|
|
25
|
+
import snsSharedLib from '@izara_project/izara-core-library-sns';
|
|
26
|
+
import asyncFlowSharedLib from '@izara_project/izara-core-library-asynchronous-flow';
|
|
24
27
|
|
|
25
|
-
import { sns } from
|
|
28
|
+
import { sns } from '@izara_project/izara-core-library-external-request';
|
|
26
29
|
|
|
27
30
|
import {
|
|
28
31
|
getObjectSchema,
|
|
@@ -32,7 +35,8 @@ import {
|
|
|
32
35
|
relSchemaLib
|
|
33
36
|
} from '@izara_project/izara-core-library-service-schemas';
|
|
34
37
|
|
|
35
|
-
const { getRelationshipSchemaWithCache, getObjSchemaS3WithHierarchy } =
|
|
38
|
+
const { getRelationshipSchemaWithCache, getObjSchemaS3WithHierarchy } =
|
|
39
|
+
getObjectSchema;
|
|
36
40
|
|
|
37
41
|
const { createLinkTypeId } = utils;
|
|
38
42
|
|
|
@@ -40,11 +44,7 @@ const { getGraphServiceTagWithCache } = serviceConfig;
|
|
|
40
44
|
|
|
41
45
|
const { findLinksByObjTypes } = relSchemaLib;
|
|
42
46
|
|
|
43
|
-
const {
|
|
44
|
-
PREFIX,
|
|
45
|
-
TOPIC_NAME_GENERATE_CODE,
|
|
46
|
-
TOPIC_NAME_GRAPH_HANDLER
|
|
47
|
-
} = consts;
|
|
47
|
+
const { PREFIX, TOPIC_NAME_GENERATE_CODE, TOPIC_NAME_GRAPH_HANDLER } = consts;
|
|
48
48
|
|
|
49
49
|
import { consts as coreConsts } from '@izara_project/izara-core-library-core';
|
|
50
50
|
|
|
@@ -61,25 +61,30 @@ import { consts as coreConsts } from '@izara_project/izara-core-library-core';
|
|
|
61
61
|
*
|
|
62
62
|
* @returns {object} description of return value
|
|
63
63
|
*/
|
|
64
|
-
export default async function <%- functionName %>
|
|
64
|
+
export default async function <%- functionName %>(
|
|
65
65
|
_izContext,
|
|
66
66
|
requestParams,
|
|
67
|
-
callingFlowConfig = {}
|
|
67
|
+
callingFlowConfig = {}
|
|
68
68
|
//(<additionalParams>)
|
|
69
69
|
//(</additionalParams>)
|
|
70
70
|
) {
|
|
71
71
|
try {
|
|
72
72
|
_izContext.logger.debug('<%- functionName %> _izContext: ', _izContext);
|
|
73
73
|
_izContext.logger.debug('<%- functionName %> requestParams: ', requestParams);
|
|
74
|
-
_izContext.logger.debug(
|
|
74
|
+
_izContext.logger.debug(
|
|
75
|
+
'<%- functionName %> callingFlowConfig: ',
|
|
76
|
+
callingFlowConfig
|
|
77
|
+
);
|
|
75
78
|
|
|
76
79
|
let originTimestamp = Date.now();
|
|
77
|
-
let changedByUserId = _izContext.correlationIds.get(
|
|
80
|
+
let changedByUserId = _izContext.correlationIds.get(
|
|
81
|
+
coreConsts.BASE_USER_ID
|
|
82
|
+
);
|
|
78
83
|
const {
|
|
79
84
|
firstObject,
|
|
80
85
|
secondObject,
|
|
81
86
|
oldRelTypeAndDirection,
|
|
82
|
-
newRelType
|
|
87
|
+
newRelType
|
|
83
88
|
//(<requestParamCreateRel>)
|
|
84
89
|
//(</requestParamCreateRel>)
|
|
85
90
|
} = requestParams;
|
|
@@ -89,54 +94,89 @@ export default async function <%- functionName %> (
|
|
|
89
94
|
//(<beforeValidateChangeRel>)
|
|
90
95
|
//(</beforeValidateChangeRel>).
|
|
91
96
|
// validate object and identifiers
|
|
92
|
-
async function validateIdentifiersExists(
|
|
93
|
-
|
|
97
|
+
async function validateIdentifiersExists(
|
|
98
|
+
_izContext,
|
|
99
|
+
objType,
|
|
100
|
+
identifiersObject
|
|
101
|
+
) {
|
|
94
102
|
const objTypeString = `objType:{ serviceTag:${objType.serviceTag}, objectType:${objType.objectType} }`;
|
|
95
|
-
const objectSchema = await getObjSchemaS3WithHierarchy(
|
|
103
|
+
const objectSchema = await getObjSchemaS3WithHierarchy(
|
|
104
|
+
_izContext,
|
|
105
|
+
objType
|
|
106
|
+
);
|
|
96
107
|
|
|
97
108
|
if (!objectSchema) {
|
|
98
|
-
errorsFound.push(
|
|
109
|
+
errorsFound.push(
|
|
110
|
+
`validateIdentifiers, not found schema of ${objTypeString}`
|
|
111
|
+
);
|
|
99
112
|
}
|
|
100
113
|
|
|
101
114
|
for (const schemaIdentifier of objectSchema.identifiers) {
|
|
102
|
-
let identifierNames = schemaIdentifier.fieldNames || [
|
|
115
|
+
let identifierNames = schemaIdentifier.fieldNames || [
|
|
116
|
+
schemaIdentifier.fieldName
|
|
117
|
+
];
|
|
103
118
|
for (const identifierName of identifierNames) {
|
|
104
119
|
if (!identifiersObject.hasOwnProperty(identifierName)) {
|
|
105
|
-
errorsFound.push(
|
|
120
|
+
errorsFound.push(
|
|
121
|
+
`validateIdentifiers, ${objTypeString} property:${identifierName} not exists`
|
|
122
|
+
);
|
|
106
123
|
} else {
|
|
107
124
|
if (
|
|
108
|
-
typeof
|
|
109
|
-
typeof
|
|
125
|
+
typeof identifiersObject[identifierName] !== 'string' &&
|
|
126
|
+
typeof identifiersObject[identifierName] !== 'number'
|
|
110
127
|
) {
|
|
111
|
-
errorsFound.push(
|
|
128
|
+
errorsFound.push(
|
|
129
|
+
`validateIdentifiers, ${objTypeString} property:${identifierName} should be string or number`
|
|
130
|
+
);
|
|
112
131
|
}
|
|
113
132
|
}
|
|
114
133
|
}
|
|
115
134
|
}
|
|
116
135
|
}
|
|
117
136
|
|
|
118
|
-
await validateIdentifiersExists(
|
|
119
|
-
|
|
137
|
+
await validateIdentifiersExists(
|
|
138
|
+
_izContext,
|
|
139
|
+
firstObject.objType,
|
|
140
|
+
firstObject.identifiers
|
|
141
|
+
);
|
|
142
|
+
await validateIdentifiersExists(
|
|
143
|
+
_izContext,
|
|
144
|
+
secondObject.objType,
|
|
145
|
+
secondObject.identifiers
|
|
146
|
+
);
|
|
120
147
|
// finished validate object and identifiers
|
|
121
148
|
|
|
122
149
|
//(<afterValidateChangeRel>)
|
|
123
150
|
//(</afterValidateChangeRel>)
|
|
124
151
|
|
|
125
152
|
// check old relType canChangeToRelType
|
|
126
|
-
const oldRelationshipSchema = await getRelationshipSchemaWithCache(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
_izContext.logger.debug(
|
|
153
|
+
const oldRelationshipSchema = await getRelationshipSchemaWithCache(
|
|
154
|
+
_izContext,
|
|
155
|
+
oldRelTypeAndDirection.relType
|
|
156
|
+
);
|
|
157
|
+
_izContext.logger.debug('oldRelationshipSchema ', oldRelationshipSchema);
|
|
158
|
+
|
|
159
|
+
const newRelationshipSchema = await getRelationshipSchemaWithCache(
|
|
160
|
+
_izContext,
|
|
161
|
+
newRelType.relType
|
|
162
|
+
);
|
|
163
|
+
_izContext.logger.debug('newRelationshipSchema: ', newRelationshipSchema);
|
|
131
164
|
if (!oldRelationshipSchema.hasOwnProperty('canChangeToRelTypes')) {
|
|
132
|
-
errorsFound.push(
|
|
165
|
+
errorsFound.push(
|
|
166
|
+
`${oldRelTypeAndDirection.relType} not have property to change to another relType`
|
|
167
|
+
);
|
|
133
168
|
} else {
|
|
134
169
|
if (!newRelationshipSchema) {
|
|
135
|
-
errorsFound.push(
|
|
170
|
+
errorsFound.push(
|
|
171
|
+
`${newRelationshipSchema} not exists can't changeToRelType`
|
|
172
|
+
);
|
|
136
173
|
} else {
|
|
137
|
-
oldRelationshipSchema.canChangeToRelTypes.find(canChangeToRelType => {
|
|
138
|
-
if (
|
|
139
|
-
canChangeToRelType.relType.
|
|
174
|
+
oldRelationshipSchema.canChangeToRelTypes.find((canChangeToRelType) => {
|
|
175
|
+
if (
|
|
176
|
+
canChangeToRelType.relType.serviceTag === newRelType.serviceTag &&
|
|
177
|
+
canChangeToRelType.relType.relationshipTag ===
|
|
178
|
+
newRelType.relationshipTag
|
|
179
|
+
) {
|
|
140
180
|
// check changeBy
|
|
141
181
|
// ? Legacy Code:
|
|
142
182
|
/*
|
|
@@ -151,114 +191,152 @@ export default async function <%- functionName %> (
|
|
|
151
191
|
*/
|
|
152
192
|
// ? [Fix]: The legacy logic incorrectly blocked "user" from regular execution and allowed non-user values.
|
|
153
193
|
// ? It has been corrected to require changeBy === "user" for normal execution.
|
|
154
|
-
if (canChangeToRelType.changeBy !==
|
|
194
|
+
if (canChangeToRelType.changeBy !== 'user') {
|
|
155
195
|
errorsFound.push(`CanChangeToRelType changeBy is not user`);
|
|
156
196
|
}
|
|
157
197
|
}
|
|
158
198
|
});
|
|
159
|
-
}
|
|
160
|
-
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
161
201
|
|
|
162
|
-
const links = await findLinksByObjTypes(
|
|
163
|
-
|
|
202
|
+
const links = await findLinksByObjTypes(
|
|
203
|
+
_izContext,
|
|
204
|
+
[firstObject.objType, secondObject.objType],
|
|
205
|
+
newRelationshipSchema.links
|
|
206
|
+
);
|
|
207
|
+
_izContext.logger.debug('links', links);
|
|
164
208
|
if (!links.length) {
|
|
165
|
-
errorsFound.push(
|
|
166
|
-
|
|
209
|
+
errorsFound.push(
|
|
210
|
+
`not found link between ${JSON.stringify({ firstObject: firstObject.objType })} ${JSON.stringify({ secondObject: secondObject.objType })}`
|
|
211
|
+
);
|
|
212
|
+
}
|
|
167
213
|
|
|
168
214
|
let checkCorrectLink = false;
|
|
169
215
|
for (let link of links) {
|
|
170
|
-
const { serviceTag: fromServiceTag, objectType: fromObjectType } =
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
216
|
+
const { serviceTag: fromServiceTag, objectType: fromObjectType } =
|
|
217
|
+
link.from.objType;
|
|
218
|
+
const { serviceTag: toServiceTag, objectType: toObjType } =
|
|
219
|
+
link.to.objType;
|
|
220
|
+
|
|
221
|
+
const { serviceTag: firstServiceTag, objectType: firstObjectType } =
|
|
222
|
+
firstObject.objType;
|
|
223
|
+
const { serviceTag: secondServiceTag, objectType: secondObjectType } =
|
|
224
|
+
secondObject.objType;
|
|
225
|
+
|
|
226
|
+
const matchFromTo =
|
|
227
|
+
fromServiceTag === firstServiceTag &&
|
|
228
|
+
fromObjectType === firstObjectType &&
|
|
229
|
+
toServiceTag === secondServiceTag &&
|
|
230
|
+
toObjType === secondObjectType;
|
|
231
|
+
|
|
232
|
+
const matchToFrom =
|
|
233
|
+
fromServiceTag === secondServiceTag &&
|
|
234
|
+
fromObjectType === secondObjectType &&
|
|
235
|
+
toServiceTag === firstServiceTag &&
|
|
236
|
+
toObjType === firstObjectType;
|
|
237
|
+
|
|
238
|
+
if (
|
|
239
|
+
(oldRelTypeAndDirection.relationshipDirection === 'from' &&
|
|
240
|
+
matchFromTo) ||
|
|
241
|
+
(oldRelTypeAndDirection.relationshipDirection === 'to' && matchToFrom)
|
|
242
|
+
) {
|
|
243
|
+
checkCorrectLink = true;
|
|
185
244
|
break;
|
|
186
245
|
}
|
|
187
|
-
}
|
|
246
|
+
}
|
|
188
247
|
|
|
189
248
|
if (checkCorrectLink == false) {
|
|
190
|
-
errorsFound.push(`Wrong Relationship Direction`)
|
|
191
|
-
}
|
|
249
|
+
errorsFound.push(`Wrong Relationship Direction`);
|
|
250
|
+
}
|
|
192
251
|
|
|
193
252
|
let targetStorageResources = [];
|
|
194
253
|
|
|
195
254
|
if (newRelationshipSchema) {
|
|
196
255
|
// find targetStorageResources and validate each storageResources
|
|
197
256
|
await Promise.all(
|
|
198
|
-
newRelationshipSchema.links.map(
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
257
|
+
newRelationshipSchema.links.map(
|
|
258
|
+
async ({ from, to, storageResourceTags }) => {
|
|
259
|
+
const { serviceTag: fromServiceTag, objectType: fromObjectType } =
|
|
260
|
+
from.objType;
|
|
261
|
+
const { serviceTag: toServiceTag, objectType: toObjectType } =
|
|
262
|
+
to.objType;
|
|
263
|
+
|
|
264
|
+
const { serviceTag: firstServiceTag, objectType: firstObjectType } =
|
|
265
|
+
firstObject.objType;
|
|
266
|
+
const {
|
|
267
|
+
serviceTag: secondServiceTag,
|
|
268
|
+
objectType: secondObjectType
|
|
269
|
+
} = secondObject.objType;
|
|
270
|
+
|
|
271
|
+
// find exists link
|
|
272
|
+
if (
|
|
273
|
+
(firstServiceTag === fromServiceTag &&
|
|
274
|
+
firstObjectType === fromObjectType &&
|
|
275
|
+
secondServiceTag === toServiceTag &&
|
|
276
|
+
secondObjectType === toObjectType) ||
|
|
277
|
+
(firstServiceTag === toServiceTag &&
|
|
278
|
+
firstObjectType === toObjectType &&
|
|
279
|
+
secondServiceTag === fromServiceTag &&
|
|
280
|
+
secondObjectType === fromObjectType)
|
|
281
|
+
) {
|
|
282
|
+
// check founded storageResource of link and collect used storageResources
|
|
283
|
+
await Promise.all(
|
|
284
|
+
storageResourceTags.map(async (storageResourceTag) => {
|
|
285
|
+
const usedStorageResource =
|
|
286
|
+
newRelationshipSchema.storageResources[storageResourceTag];
|
|
287
|
+
|
|
288
|
+
if (
|
|
289
|
+
usedStorageResource.storageType ===
|
|
290
|
+
consts.STORAGE_TYPES.graph
|
|
291
|
+
) {
|
|
292
|
+
const graphServiceTag = await getGraphServiceTagWithCache(
|
|
293
|
+
_izContext,
|
|
294
|
+
usedStorageResource.graphServerTag
|
|
295
|
+
);
|
|
296
|
+
if (!graphServiceTag) {
|
|
297
|
+
errorsFound.push(
|
|
298
|
+
`storageResourceTag: ${storageResourceTag} invalid, not found graph serviceTag from graphServerTag: ${usedStorageResource.graphServerTag}`
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
targetStorageResources.push({
|
|
303
|
+
...usedStorageResource,
|
|
304
|
+
graphServiceTag: graphServiceTag
|
|
305
|
+
});
|
|
306
|
+
} else {
|
|
307
|
+
targetStorageResources.push(usedStorageResource);
|
|
308
|
+
}
|
|
309
|
+
})
|
|
310
|
+
);
|
|
311
|
+
}
|
|
235
312
|
}
|
|
236
|
-
|
|
313
|
+
)
|
|
237
314
|
);
|
|
238
315
|
//(<afterGetRelChangeRel>)
|
|
239
316
|
//(</afterGetRelChangeRel>)
|
|
240
|
-
_izContext.logger.debug(
|
|
317
|
+
_izContext.logger.debug(
|
|
318
|
+
'targetStorageResources: ',
|
|
319
|
+
targetStorageResources
|
|
320
|
+
);
|
|
241
321
|
|
|
242
322
|
if (!targetStorageResources.length) {
|
|
243
323
|
errorsFound.push(`Not found link from relationship schema`);
|
|
244
324
|
}
|
|
245
325
|
|
|
246
|
-
|
|
247
326
|
// validate properties exists with schema
|
|
248
327
|
for (const propKey in oldRelTypeAndDirection.fieldNames) {
|
|
249
328
|
if (!newRelationshipSchema.fieldNames.hasOwnProperty(propKey)) {
|
|
250
|
-
errorsFound.push(
|
|
329
|
+
errorsFound.push(
|
|
330
|
+
`property: ${propKey} not exists in relationshipSchema`
|
|
331
|
+
);
|
|
251
332
|
}
|
|
252
333
|
}
|
|
253
|
-
|
|
254
334
|
} else {
|
|
255
335
|
errorsFound.push(`relationshipSchema not exists`);
|
|
256
336
|
}
|
|
257
337
|
|
|
258
|
-
|
|
259
338
|
// if found errors will stop processing
|
|
260
339
|
if (errorsFound.length) {
|
|
261
|
-
|
|
262
340
|
let changeRelCompleteMsg = {
|
|
263
341
|
firstObject,
|
|
264
342
|
secondObject,
|
|
@@ -274,35 +352,60 @@ export default async function <%- functionName %> (
|
|
|
274
352
|
};
|
|
275
353
|
|
|
276
354
|
// if have callingFlow will send to message complete
|
|
277
|
-
if (
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
355
|
+
if (
|
|
356
|
+
callingFlowConfig[callingFlowSharedLib.consts.CALLINGFLOW_PROPERTYNAME]
|
|
357
|
+
) {
|
|
358
|
+
_izContext.logger.debug('HAVE CallingFlow');
|
|
359
|
+
|
|
360
|
+
changeRelCompleteMsg =
|
|
361
|
+
callingFlowSharedLib.addPassBackPropertiesToSnsResponseMessageObject(
|
|
362
|
+
callingFlowConfig,
|
|
363
|
+
changeRelCompleteMsg
|
|
364
|
+
);
|
|
365
|
+
let messageAttributes =
|
|
366
|
+
callingFlowSharedLib.addCallingFlowToSnsResponseMessageAttributes(
|
|
367
|
+
callingFlowConfig,
|
|
368
|
+
{}
|
|
369
|
+
);
|
|
282
370
|
|
|
283
371
|
let messageParams = {
|
|
284
372
|
Message: JSON.stringify(changeRelCompleteMsg),
|
|
285
|
-
MessageAttributes: sns.createStringMessageAttributes(
|
|
286
|
-
|
|
373
|
+
MessageAttributes: sns.createStringMessageAttributes(
|
|
374
|
+
_izContext,
|
|
375
|
+
messageAttributes
|
|
376
|
+
),
|
|
377
|
+
TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
|
|
378
|
+
_izContext,
|
|
379
|
+
TOPIC_NAME_GENERATE_CODE.outChangeRelationshipComplete
|
|
380
|
+
)
|
|
287
381
|
};
|
|
288
382
|
|
|
289
|
-
_izContext.logger.debug(
|
|
383
|
+
_izContext.logger.debug(
|
|
384
|
+
'messageParams OutCreateRelationshipComplete ::::::: ',
|
|
385
|
+
messageParams
|
|
386
|
+
);
|
|
290
387
|
await sns.publishAsync(_izContext, messageParams);
|
|
291
388
|
}
|
|
292
389
|
|
|
293
390
|
return changeRelCompleteMsg;
|
|
294
391
|
}
|
|
295
392
|
|
|
296
|
-
|
|
297
393
|
// before create awaitingStepId per graph storageResource
|
|
298
|
-
const linkTypeId = createLinkTypeId(
|
|
394
|
+
const linkTypeId = createLinkTypeId(
|
|
395
|
+
_izContext,
|
|
396
|
+
firstObject.objType,
|
|
397
|
+
secondObject.objType,
|
|
398
|
+
newRelType,
|
|
399
|
+
oldRelTypeAndDirection.relationshipDirection
|
|
400
|
+
);
|
|
299
401
|
|
|
300
402
|
let usedGraphServiceTag = []; // collect used graph serviceTag, use to check duplicate graph serviceTag across graph serverTag
|
|
301
403
|
let targetGraphStorageResources = []; // collect used graph storageResources, filtered duplicate graphServiceTag from graphServerTag out
|
|
302
404
|
let awaitingStepIds = [];
|
|
303
405
|
|
|
304
406
|
for (const targetStorageResource of targetStorageResources) {
|
|
305
|
-
if (
|
|
407
|
+
if (
|
|
408
|
+
targetStorageResource.storageType === consts.STORAGE_TYPES.graph &&
|
|
306
409
|
!usedGraphServiceTag.includes(targetStorageResource.graphServiceTag)
|
|
307
410
|
) {
|
|
308
411
|
usedGraphServiceTag.push(targetStorageResource.graphServiceTag);
|
|
@@ -322,11 +425,12 @@ export default async function <%- functionName %> (
|
|
|
322
425
|
// save awaiting
|
|
323
426
|
await asyncFlowSharedLib.createAwaitingMultipleSteps(
|
|
324
427
|
_izContext,
|
|
325
|
-
|
|
326
|
-
|
|
428
|
+
asyncFlowSharedLib.createPendingStepId(
|
|
429
|
+
// pendingStepId
|
|
327
430
|
_izContext.uniqueRequestId, // hash id
|
|
328
431
|
PREFIX.changeRel // prefix, use constant further
|
|
329
|
-
)
|
|
432
|
+
),
|
|
433
|
+
awaitingStepIds // awaitingStepIds
|
|
330
434
|
);
|
|
331
435
|
|
|
332
436
|
// prepare message body
|
|
@@ -337,43 +441,57 @@ export default async function <%- functionName %> (
|
|
|
337
441
|
newRelType,
|
|
338
442
|
originTimestamp,
|
|
339
443
|
changedByUserId,
|
|
340
|
-
parentFlowId
|
|
444
|
+
parentFlowId
|
|
341
445
|
//(<messageBodyChangeRel>)
|
|
342
446
|
//(</messageBodyChangeRel>)
|
|
343
447
|
|
|
344
448
|
// assign originTimestamp if not exists in relationshipProperties
|
|
345
|
-
}
|
|
449
|
+
};
|
|
346
450
|
_izContext.logger.debug('changeRelMessageBody: ', changeRelMessageBody);
|
|
347
451
|
|
|
348
452
|
await Promise.all(
|
|
349
453
|
targetGraphStorageResources.map(async (storageResource) => {
|
|
350
454
|
if (storageResource.storageType === consts.STORAGE_TYPES.graph) {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
455
|
+
changeRelMessageBody =
|
|
456
|
+
callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
|
|
457
|
+
changeRelMessageBody,
|
|
458
|
+
callingFlowSharedLib.addParentCallingFlowConfig(
|
|
459
|
+
callingFlowConfig, // receive parent callingFlowConfig.
|
|
460
|
+
callingFlowSharedLib.createCallingFlowConfig(
|
|
461
|
+
// calling flow own service
|
|
462
|
+
//(<callingFlowProperties>)
|
|
463
|
+
await lambdaSharedLib.lambdaFunctionName(
|
|
464
|
+
_izContext,
|
|
465
|
+
TOPIC_NAME_GENERATE_CODE.changeRelationshipComplete
|
|
466
|
+
),
|
|
467
|
+
//(</callingFlowProperties>)
|
|
468
|
+
{
|
|
469
|
+
graphServiceTag: storageResource.graphServiceTag
|
|
470
|
+
}
|
|
471
|
+
)
|
|
363
472
|
)
|
|
364
|
-
)
|
|
473
|
+
);
|
|
474
|
+
_izContext.logger.debug(
|
|
475
|
+
'messageObject before send message:',
|
|
476
|
+
changeRelMessageBody
|
|
365
477
|
);
|
|
366
|
-
_izContext.logger.debug("messageObject before send message:", changeRelMessageBody)
|
|
367
478
|
|
|
368
479
|
let messageToInChangeRelationship = {
|
|
369
480
|
Message: JSON.stringify(changeRelMessageBody),
|
|
370
|
-
TopicArn:
|
|
481
|
+
TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
|
|
482
|
+
_izContext,
|
|
483
|
+
TOPIC_NAME_GRAPH_HANDLER.inChangeRelationship,
|
|
484
|
+
storageResource.graphServiceTag
|
|
485
|
+
)
|
|
371
486
|
};
|
|
372
|
-
_izContext.logger.debug(
|
|
487
|
+
_izContext.logger.debug(
|
|
488
|
+
'RequestParams before send to sqs messageToInUpdateRelationship ::::::: ',
|
|
489
|
+
messageToInChangeRelationship
|
|
490
|
+
);
|
|
373
491
|
await sns.publishAsync(_izContext, messageToInChangeRelationship);
|
|
374
492
|
}
|
|
375
493
|
})
|
|
376
|
-
)
|
|
494
|
+
);
|
|
377
495
|
}
|
|
378
496
|
|
|
379
497
|
return {
|
|
@@ -383,12 +501,10 @@ export default async function <%- functionName %> (
|
|
|
383
501
|
newRelType,
|
|
384
502
|
originTimestamp,
|
|
385
503
|
changedByUserId,
|
|
386
|
-
status:
|
|
504
|
+
status: 'complete'
|
|
387
505
|
};
|
|
388
|
-
|
|
389
|
-
|
|
390
506
|
} catch (err) {
|
|
391
|
-
_izContext.logger.error('error ChangeRelationship: ', err)
|
|
392
|
-
throw
|
|
507
|
+
_izContext.logger.error('error ChangeRelationship: ', err);
|
|
508
|
+
throw err;
|
|
393
509
|
}
|
|
394
510
|
}
|