@izara_project/izara-market-library-service-schemas 1.0.62 → 1.0.63

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.
Files changed (49) hide show
  1. package/package.json +1 -1
  2. package/src/GenerateCodeLibs/src/Consts.js +7 -3
  3. package/src/MainLibs/src/Consts.js +5 -1
  4. package/src/reStructure/GenerateCode.js +1 -1
  5. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/template.ejs +8 -8
  6. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/update/template.ejs +114 -83
  7. package/src/reStructure/TemplateData/externalService/lambdaRole/data.js +8 -0
  8. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/data.js +11 -1
  9. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/handler/template.ejs +13 -9
  10. package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +3 -2
  11. package/src/reStructure/TemplateData/flowSchema/register/complete/handler/template.ejs +1 -0
  12. package/src/reStructure/TemplateData/flowSchema/register/complete/mainFunction/template.ejs +3 -1
  13. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/api/data.js +123 -0
  14. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/api/template.ejs +20 -0
  15. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/dsq/data.js +122 -0
  16. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/dsq/template.ejs +17 -0
  17. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/inv/data.js +123 -0
  18. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/inv/template.ejs +13 -0
  19. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/sqs/data.js +123 -0
  20. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/sqs/template.ejs +17 -0
  21. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/api/data.js +57 -0
  22. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/api/request.json +0 -0
  23. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/api/template.ejs +155 -0
  24. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/dsq/data.js +58 -0
  25. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/dsq/request.json +0 -0
  26. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/dsq/template.ejs +202 -0
  27. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/inv/data.js +59 -0
  28. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/inv/request.json +0 -0
  29. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/inv/template.ejs +144 -0
  30. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/sqs/data.js +59 -0
  31. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/sqs/request.json +0 -0
  32. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/sqs/template.ejs +181 -0
  33. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/mainFunction/data.js +59 -0
  34. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/mainFunction/template.ejs +382 -0
  35. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/sns-in-sqs/data.js +77 -0
  36. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/sns-in-sqs/snsTemplate.ejs +59 -0
  37. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/sns-in-sqs/sqsTemplate.ejs +43 -0
  38. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/functionYaml/data.js +121 -0
  39. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/functionYaml/template.ejs +20 -0
  40. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/handler/sqs/data.js +60 -0
  41. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/handler/sqs/template.ejs +129 -0
  42. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/mainFunction/data.js +55 -0
  43. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/mainFunction/template.ejs +154 -0
  44. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/sns-in-sqs/data.js +71 -0
  45. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/sns-in-sqs/template.ejs +46 -0
  46. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/sns-out/data.js +71 -0
  47. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/sns-out/template.ejs +10 -0
  48. package/src/reStructure/TemplateData/relationshipPerAction/create/complete/handler/sqs/template.ejs +2 -2
  49. package/src/reStructure/TemplateData/relationshipPerAction/generateTemplateData.js +55 -2
@@ -0,0 +1,59 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+ const path = require('path');
20
+
21
+ const { ACTIONS, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
22
+
23
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, firstLetterUpperCase } = require("../../../../../../MainLibs/index.js").utils;
24
+ const { SOURCE_PATH, FUNCTION_NAME } = require("../../../../../../MainLibs/index.js").consts;
25
+
26
+
27
+ const templatePath = path.join(__dirname, "./template.ejs")
28
+
29
+ /**
30
+ * receive objectSchema
31
+ * create data for hdrInv template
32
+ *
33
+ * @param {Object} objectSchema
34
+ * @return {{ templatePath, templateData, setting } }
35
+ */
36
+ function data(_izContext, srcPath) {
37
+ const createSourceParams = createParamForCreateSource(srcPath)
38
+ return [createSourceParams];
39
+ }
40
+
41
+
42
+ function createParamForCreateSource(srcPath) {
43
+ let functionName = FUNCTION_NAME.changeRel
44
+ return {
45
+ templatePath: templatePath,
46
+ templateData: {
47
+ functionName
48
+ },
49
+ setting: {
50
+ savePath: path.join(srcPath, SOURCE_PATH.relationshipPerAction),
51
+ saveFileName: `${upperCase(FUNCTION_NAME.changeRel)}_Main`,
52
+ fileExtension: '.js',
53
+ isAppend: false
54
+ }
55
+ }
56
+ }
57
+
58
+
59
+ module.exports = data;
@@ -0,0 +1,382 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ const hash = require('@izara_project/izara-shared-core').objectHash;
21
+
22
+ const callingFlowSharedLib = require('@izara_project/izara-core-library-calling-flow');
23
+ const lambdaSharedLib = require("@izara_project/izara-core-library-lambda");
24
+ const snsSharedLib = require("@izara_project/izara-core-library-sns");
25
+ const dynamodbSharedLib = require("@izara_project/izara-core-library-dynamodb");
26
+ const asyncFlowSharedLib = require("@izara_project/izara-core-library-asynchronous-flow");
27
+
28
+ const sns = require("@izara_project/izara-core-library-external-request/src/resources/Sns");
29
+
30
+ const identifiersObject = require('@izara_project/izara-core-library-service-schemas/src/IdentifiersObject');
31
+
32
+ // const NoRetryError = require('@izara_project/izara-core-library-core/src/NoRetryError');
33
+
34
+ const { findLinksByObjTypes } = require("@izara_project/izara-core-library-service-schemas/src/libs/RelSchemaLib");
35
+
36
+
37
+
38
+ const {
39
+ getRelationshipSchemaWithCache,
40
+ getObjSchemaS3WithHierarchy
41
+ } = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
42
+
43
+ const {
44
+ createLinkTypeId
45
+ } = require('@izara_project/izara-core-library-service-schemas/src/Utils');
46
+
47
+ const {
48
+ getGraphServiceTagWithCache
49
+ } = require('@izara_project/izara-core-library-service-schemas/src/ServiceConfig');
50
+
51
+ const consts = require('@izara_project/izara-core-library-service-schemas/src/Consts');
52
+ const {
53
+ PREFIX,
54
+ TOPIC_NAME_GENERATE_CODE,
55
+ TOPIC_NAME_GRAPH_HANDLER
56
+ } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts');
57
+ const coreConsts = require('@izara_project/izara-core-library-core/src/Consts');
58
+
59
+ //(<optionalRequire>)
60
+ //(</optionalRequire>)
61
+ /**
62
+ * update relationship endpoint
63
+ *
64
+ * @param {Object} _izContext
65
+ * @param {CorrelationIds} _izContext.correlationIds - property of _izContext
66
+ * @param {Logger} _izContext.logger - property of _izContext
67
+ * @param {Object} requestParams - request params
68
+ * @param {Object} callingFlowConfig
69
+ *
70
+ * @returns {object} description of return value
71
+ */
72
+ module.exports.<%- functionName %> = async (
73
+ _izContext,
74
+ requestParams,
75
+ callingFlowConfig = {},
76
+ //(<additionalParams>)
77
+ //(</additionalParams>)
78
+ ) => {
79
+ try {
80
+ _izContext.logger.debug('<%- functionName %> _izContext: ', _izContext);
81
+ _izContext.logger.debug('<%- functionName %> requestParams: ', requestParams);
82
+ _izContext.logger.debug('<%- functionName %> callingFlowConfig: ', callingFlowConfig);
83
+
84
+ let originTimestamp = Date.now();
85
+ let changedByUserId = _izContext.correlationIds.get(coreConsts.BASE_USER_ID)
86
+ const {
87
+ firstObject,
88
+ secondObject,
89
+ oldReltypeAndDirection,
90
+ newRelType,
91
+ //(<requestParamCreateRel>)
92
+ //(</requestParamCreateRel>)
93
+ } = requestParams;
94
+
95
+ let errorsFound = [];
96
+
97
+ //(<beforeValidateChangeRel>)
98
+ //(</beforeValidateChangeRel>).
99
+ // validate object and identifiers
100
+ async function validateIdentifiersExists(_izContext, objType, identifiersObject) {
101
+
102
+ const objTypeString = `objType:{ serviceTag:${objType.serviceTag}, objectType:${objType.objectType} }`;
103
+ const objectSchema = await getObjSchemaS3WithHierarchy(_izContext, objType);
104
+
105
+ if (!objectSchema) {
106
+ errorsFound.push(`validateIdentifiers, not found schema of ${objTypeString}`);
107
+ }
108
+
109
+ for (const schemaIdentifier of objectSchema.identifiers) {
110
+ let identifierNames = schemaIdentifier.fieldNames || [schemaIdentifier.fieldName];
111
+ for (const identifierName of identifierNames) {
112
+ if (!identifiersObject.hasOwnProperty(identifierName)) {
113
+ errorsFound.push(`validateIdentifiers, ${objTypeString} property:${identifierName} not exists`);
114
+ } else {
115
+ if (
116
+ typeof (identifiersObject[identifierName]) !== "string" &&
117
+ typeof (identifiersObject[identifierName]) !== "number"
118
+ ) {
119
+ errorsFound.push(`validateIdentifiers, ${objTypeString} property:${identifierName} should be string or number`);
120
+ }
121
+ }
122
+ }
123
+ }
124
+ }
125
+
126
+ await validateIdentifiersExists(_izContext, firstObject.objType, firstObject.identifiers);
127
+ await validateIdentifiersExists(_izContext, secondObject.objType, secondObject.identifiers);
128
+ // finished validate object and identifiers
129
+
130
+ //(<afterValidateChangeRel>)
131
+ //(</afterValidateChangeRel>)
132
+
133
+ const relationshipSchema = await getRelationshipSchemaWithCache(_izContext, newRelType);
134
+ _izContext.logger.debug("relationshipSchema: ", relationshipSchema);
135
+
136
+ const links = await findLinksByObjTypes(_izContext, [firstObject.objType, secondObject.objType], relationshipSchema.links)
137
+ _izContext.logger.debug("links", links)
138
+ if (!links.length) {
139
+ errorsFound.push(`not found link between ${JSON.stringify({ firstObject: firstObject.objType })} ${JSON.stringify({ secondObject: secondObject.objType })}`)
140
+ };
141
+
142
+ let checkCorrectLink = false;
143
+ for (let link of links) {
144
+ const { serviceTag: fromServiceTag, objectType: fromObjectType } = link.from.objType;
145
+ const { serviceTag: toServiceTag, objectType: toObjType } = link.to.objType;
146
+
147
+ const { serviceTag: firstServiceTag, objectType: firstObjectType } = firstObject.objType
148
+ const { serviceTag: secondServiceTag, objectType: secondObjectType } = secondObject.objType
149
+
150
+ const matchFromTo = fromServiceTag === firstServiceTag && fromObjectType === firstObjectType &&
151
+ toServiceTag === secondServiceTag && toObjType === secondObjectType;
152
+
153
+ const matchToFrom = fromServiceTag === secondServiceTag && fromObjectType === secondObjectType &&
154
+ toServiceTag === firstServiceTag && toObjType === firstObjectType;
155
+
156
+ if ((oldReltypeAndDirection.relationshipDirection === "from" && matchFromTo) ||
157
+ (oldReltypeAndDirection.relationshipDirection === "to" && matchToFrom)) {
158
+ checkCorrectLink = true
159
+ break;
160
+ }
161
+ };
162
+
163
+ if (checkCorrectLink == false) {
164
+ errorsFound.push(`Wrong Relationship Direction`)
165
+ };
166
+
167
+ let targetStorageResources = [];
168
+
169
+ if (relationshipSchema) {
170
+ // find targetStorageResources and validate each storageResources
171
+ await Promise.all(
172
+ relationshipSchema.links.map(async ({ from, to, storageResourceTags }) => {
173
+ const { serviceTag: fromServiceTag, objectType: fromObjectType } = from.objType
174
+ const { serviceTag: toServiceTag, objectType: toObjectType } = to.objType
175
+
176
+ const { serviceTag: firstServiceTag, objectType: firstObjectType } = firstObject.objType;
177
+ const { serviceTag: secondServiceTag, objectType: secondObjectType } = secondObject.objType;
178
+
179
+ // find exists link
180
+ if (
181
+ (
182
+ (firstServiceTag === fromServiceTag && firstObjectType === fromObjectType) &&
183
+ (secondServiceTag === toServiceTag && secondObjectType === toObjectType)
184
+ ) ||
185
+ (
186
+ (firstServiceTag === toServiceTag && firstObjectType === toObjectType) &&
187
+ (secondServiceTag === fromServiceTag && secondObjectType === fromObjectType)
188
+ )
189
+ ) {
190
+
191
+ // check founded storageResource of link and collect used storageResources
192
+ await Promise.all(storageResourceTags.map(async storageResourceTag => {
193
+ const usedStorageResource = relationshipSchema.storageResources[storageResourceTag];
194
+
195
+ if (usedStorageResource.storageType === consts.STORAGE_TYPES.graph) {
196
+ const graphServiceTag = await getGraphServiceTagWithCache(_izContext, usedStorageResource.graphServerTag);
197
+ if (!graphServiceTag) {
198
+ errorsFound.push(`storageResourceTag: ${storageResourceTag} invalid, not found graph serviceTag from graphServerTag: ${usedStorageResource.graphServerTag}`)
199
+ }
200
+
201
+ targetStorageResources.push({
202
+ ...usedStorageResource,
203
+ graphServiceTag: graphServiceTag
204
+ });
205
+ } else {
206
+ targetStorageResources.push(usedStorageResource);
207
+ }
208
+ }));
209
+ }
210
+ })
211
+ );
212
+ //(<afterGetRelChangeRel>)
213
+ //(</afterGetRelChangeRel>)
214
+ _izContext.logger.debug("targetStorageResources: ", targetStorageResources);
215
+
216
+ if (!targetStorageResources.length) {
217
+ errorsFound.push(`Not found link from relationship schema`);
218
+ }
219
+
220
+
221
+ // validate properties exists with schema
222
+ for (const propKey in oldReltypeAndDirection.relationshipProperties) {
223
+ if (!relationshipSchema.fieldNames.hasOwnProperty(propKey)) {
224
+ errorsFound.push(`property: ${propKey} not exists in relationshipSchema`);
225
+ }
226
+ }
227
+
228
+ } else {
229
+ errorsFound.push(`relationshipSchema not exists`);
230
+ }
231
+
232
+
233
+ // if found errors will stop processing
234
+ if (errorsFound.length) {
235
+
236
+ let changeRelCompleteMsg = {
237
+ fromObject: firstObject,
238
+ toObject: secondObject,
239
+ oldReltypeAndDirection,
240
+ newRelType,
241
+ originTimestamp,
242
+ changedByUserId,
243
+ //(<inChangeRelCompleteMsg>)
244
+ //(</inChangeRelCompleteMsg>)
245
+ status: 'error',
246
+ errorsFound: errorsFound
247
+ };
248
+
249
+ // if have callingFlow will send to message complete
250
+ if (callingFlowConfig[callingFlowSharedLib.consts.CALLINGFLOW_PROPERTYNAME]) {
251
+ _izContext.logger.debug("HAVE CallingFlow");
252
+
253
+ changeRelCompleteMsg = callingFlowSharedLib.addPassBackPropertiesToSnsResponseMessageObject(callingFlowConfig, changeRelCompleteMsg);
254
+ let messageAttributes = callingFlowSharedLib.addCallingFlowToSnsResponseMessageAttributes(callingFlowConfig, {});
255
+
256
+ let messageParams = {
257
+ Message: JSON.stringify(changeRelCompleteMsg),
258
+ MessageAttributes: sns.createStringMessageAttributes(_izContext, messageAttributes),
259
+ TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, TOPIC_NAME_GENERATE_CODE.outCreateRelComplete),
260
+ };
261
+
262
+ _izContext.logger.debug("messageParams OutCreateRelationshipComplete ::::::: ", messageParams);
263
+ await sns.publishAsync(_izContext, messageParams);
264
+ }
265
+
266
+ return changeRelCompleteMsg;
267
+ }
268
+
269
+
270
+ // before create awaitingStepId per graph storageResource
271
+ const linkTypeId = createLinkTypeId(_izContext, firstObject.objType, secondObject.objType, newRelType, oldReltypeAndDirection.relationshipDirection);
272
+
273
+ let usedGraphServiceTag = []; // collect used graph serviceTag, use to check duplicate graph serviceTag across graph serverTag
274
+ let targetGraphStorageResources = []; // collect used graph storageResources, filtered duplicate graphServiceTag from graphServerTag out
275
+ let awaitingStepIds = [];
276
+
277
+ for (const targetStorageResource of targetStorageResources) {
278
+ if (targetStorageResource.storageType === consts.STORAGE_TYPES.graph &&
279
+ !usedGraphServiceTag.includes(targetStorageResource.graphServiceTag)
280
+ ) {
281
+ usedGraphServiceTag.push(targetStorageResource.graphServiceTag);
282
+ targetGraphStorageResources.push(targetStorageResource);
283
+
284
+ // awaitingStepId per graphServiceTag
285
+ awaitingStepIds.push(
286
+ asyncFlowSharedLib.createAwaitingStepId(
287
+ hash({
288
+ linkTypeId,
289
+ graphServiceTag: targetStorageResource.graphServiceTag,
290
+ callingFlowProperties: callingFlowConfig.callingFlowProperties || {},
291
+ firstObject,
292
+ secondObject,
293
+ oldReltypeAndDirection,
294
+ newRelType,
295
+ }), // hash id
296
+ PREFIX.changeRel // prefix, use constant further
297
+ )
298
+ );
299
+ }
300
+ }
301
+
302
+ if (awaitingStepIds.length) {
303
+ // save awaiting
304
+ await asyncFlowSharedLib.createAwaitingMultipleSteps(
305
+ _izContext,
306
+ awaitingStepIds, // awaitingStepIds
307
+ asyncFlowSharedLib.createPendingStepId( // pendingStepId
308
+ hash({
309
+ linkTypeId,
310
+ correlationId: _izContext.correlationIds.get("id"),
311
+ callingFlowProperties: callingFlowConfig.callingFlowProperties || {},
312
+ firstObject,
313
+ secondObject,
314
+ oldReltypeAndDirection,
315
+ newRelType,
316
+ }), // hash id
317
+ PREFIX.changeRel // prefix, use constant further
318
+ )
319
+ );
320
+
321
+ // prepare message body
322
+ let changeRelMessageBody = {
323
+ fromObject: firstObject,
324
+ toObject: secondObject,
325
+ oldReltypeAndDirection,
326
+ newRelType,
327
+ originTimestamp,
328
+ changedByUserId,
329
+ //(<messageBodyChangeRel>)
330
+ //(</messageBodyChangeRel>)
331
+
332
+ // assign originTimestamp if not exists in relationshipProperties
333
+ }
334
+ _izContext.logger.debug('changeRelMessageBody: ', changeRelMessageBody);
335
+
336
+ await Promise.all(
337
+ targetGraphStorageResources.map(async (storageResource) => {
338
+ if (storageResource.storageType === consts.STORAGE_TYPES.graph) {
339
+
340
+ changeRelMessageBody = callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
341
+ changeRelMessageBody,
342
+ callingFlowSharedLib.addParentCallingFlowConfig(
343
+ callingFlowConfig, // receive parent callingFlowConfig.
344
+ callingFlowSharedLib.createCallingFlowConfig( // calling flow own service
345
+ //(<callingFlowProperties>)
346
+ await lambdaSharedLib.lambdaFunctionName(_izContext, TOPIC_NAME_GENERATE_CODE.changeRelationshipComplete),
347
+ //(</callingFlowProperties>)
348
+ {
349
+ graphServiceTag: storageResource.graphServiceTag
350
+ }
351
+ )
352
+ )
353
+ );
354
+ _izContext.logger.debug("messageObject before send message:", changeRelMessageBody)
355
+
356
+ let messageToInChangeRelationship = {
357
+ Message: JSON.stringify(changeRelMessageBody),
358
+ TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, TOPIC_NAME_GRAPH_HANDLER.inChangeRelationship, storageResource.graphServiceTag),
359
+ };
360
+ _izContext.logger.debug("RequestParams before send to sqs messageToInUpdateRelationship ::::::: ", messageToInChangeRelationship);
361
+ await sns.publishAsync(_izContext, messageToInChangeRelationship);
362
+ }
363
+ })
364
+ )
365
+ }
366
+
367
+ return {
368
+ fromObject: firstObject,
369
+ toObject: secondObject,
370
+ oldReltypeAndDirection,
371
+ newRelType,
372
+ originTimestamp,
373
+ changedByUserId,
374
+ status: "complete"
375
+ };
376
+
377
+
378
+ } catch (err) {
379
+ _izContext.logger.error('error ChangeRelationship: ', err)
380
+ throw (err)
381
+ }
382
+ }
@@ -0,0 +1,77 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ const path = require("path")
21
+
22
+ const {
23
+ HANDLER,
24
+ } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
25
+
26
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../MainLibs/index.js").utils;
27
+ const { SOURCE_PATH, SAVE_FILE_NAME, FUNCTION_NAME } = require("../../../../../../MainLibs/index.js").consts;
28
+ const snsTemplatePath = path.join(__dirname, "./snsTemplate.ejs")
29
+ const sqsTemplatePath = path.join(__dirname, "./sqsTemplate.ejs")
30
+
31
+ /**
32
+ * create data for dynamoDbYaml tempalte from objectSchema
33
+ *
34
+ * @param {Object} _izContext
35
+ * @param {String} saveFilePath
36
+ * @returns {Object[]} - data of multiple dynamoDb template
37
+ */
38
+
39
+ function createRelationshipSnsInSqs(_izContext, srcPath) {
40
+ let resultForCreateRelationshipSnsAndSqs = [];
41
+ const setting = {
42
+ initialData: "Resources:\n",
43
+ savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
44
+ saveFileName: SAVE_FILE_NAME.snsInSqsYaml,
45
+ fileExtension: ".yml",
46
+ isAppend: true
47
+ }
48
+ const createRelationshipQueueNames = [
49
+ {
50
+ queueName: upperCase(FUNCTION_NAME.changeRel)
51
+ },
52
+ {
53
+ queueName: upperCase(FUNCTION_NAME.changeRel) + upperCase(HANDLER.hdrDsq)
54
+ }
55
+ ]
56
+ for (let createRelationshipQueueName of createRelationshipQueueNames) {
57
+ if (createRelationshipQueueName.queueName.includes("HdrDsq")) {
58
+ resultForCreateRelationshipSnsAndSqs.push({
59
+ templatePath: sqsTemplatePath,
60
+ templateData: createRelationshipQueueName,
61
+ setting: setting
62
+ }
63
+ )
64
+ } else {
65
+ resultForCreateRelationshipSnsAndSqs.push(
66
+ {
67
+ templatePath: snsTemplatePath,
68
+ templateData: createRelationshipQueueName,
69
+ setting: setting
70
+ }
71
+ )
72
+ }
73
+ }
74
+ return resultForCreateRelationshipSnsAndSqs
75
+ }
76
+
77
+ module.exports = createRelationshipSnsInSqs
@@ -0,0 +1,59 @@
1
+ ##===== [Create topic in]
2
+ In<%- queueName %>:
3
+ Type: AWS::SNS::Topic
4
+ Properties:
5
+ DisplayName: "SNS Message in"
6
+ TopicName: ${self:custom.iz_serviceTag}_${self:custom.iz_stage}_<%- queueName %>_In
7
+ ##===== SNS Subscription
8
+ ##===== [Topic In]
9
+ SubscriptionIn<%- queueName %>:
10
+ Type: AWS::SNS::Subscription
11
+ Properties:
12
+ TopicArn: !Ref In<%- queueName %>
13
+ Endpoint: "arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- queueName %>HdrSqs"
14
+ Protocol: "sqs"
15
+ ##===== [Queue]
16
+ <%- queueName %>HdrSqs:
17
+ Type: "AWS::SQS::Queue"
18
+ Properties:
19
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>HdrSqs
20
+ RedrivePolicy:
21
+ deadLetterTargetArn:
22
+ # !GetAtt
23
+ Fn::GetAtt:
24
+ - <%- queueName %>HdrSqsDLQ
25
+ - Arn
26
+ maxReceiveCount: 3
27
+ VisibilityTimeout: 120
28
+ ##==== [QueueDLQ]
29
+ <%- queueName %>HdrSqsDLQ:
30
+ Type: AWS::SQS::Queue
31
+ Properties:
32
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>HdrSqsDLQ
33
+ ##==== [QueuePolicy]
34
+ <%- queueName %>HdrSqsPolicy:
35
+ Type: AWS::SQS::QueuePolicy
36
+ Properties:
37
+ PolicyDocument:
38
+ Version: "2012-10-17"
39
+ Statement:
40
+ - Sid: "allow-sns-messages"
41
+ Effect: Allow
42
+ Principal: "*"
43
+ Resource:
44
+ # !GetAtt
45
+ Fn::GetAtt:
46
+ - <%- queueName %>HdrSqs
47
+ - Arn
48
+ Action: "SQS:SendMessage"
49
+ Queues:
50
+ - Ref: <%- queueName %>HdrSqs
51
+ #<#<%- firstLetterUpperCase(queueName) %>QueueSetting#>
52
+ #<#/<%- firstLetterUpperCase(queueName) %>QueueSetting#>
53
+
54
+ <%_ function firstLetterUpperCase(text){
55
+ return text.charAt(0).toUpperCase() + text.slice(1)
56
+ } _%>
57
+ <%_ function firstLetterLowerCase(str) {
58
+ return str.charAt(0).toLowerCase() + str.slice(1)
59
+ } _%>
@@ -0,0 +1,43 @@
1
+ #------- queue ---------
2
+ <%- queueName %>:
3
+ Type: "AWS::SQS::Queue"
4
+ Properties:
5
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>
6
+ RedrivePolicy:
7
+ deadLetterTargetArn: #!GetAtt
8
+ Fn::GetAtt:
9
+ - <%- queueName %>DLQ
10
+ - Arn
11
+ maxReceiveCount: 3
12
+ VisibilityTimeout: 120
13
+
14
+ <%- queueName %>DLQ:
15
+ Type: AWS::SQS::Queue
16
+ Properties:
17
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>DLQ
18
+
19
+ <%- queueName %>Policy:
20
+ Type: AWS::SQS::QueuePolicy
21
+ Properties:
22
+ PolicyDocument:
23
+ Version: "2012-10-17"
24
+ Statement:
25
+ - Sid: "allow-sns-messages"
26
+ Effect: Allow
27
+ Principal: "*"
28
+ Resource: #!GetAtt
29
+ Fn::GetAtt:
30
+ - <%- queueName %>
31
+ - Arn
32
+ Action: "SQS:SendMessage"
33
+ Queues:
34
+ - Ref: <%- queueName %>
35
+ #<#<%- firstLetterUpperCase(queueName) %>QueueSetting#>
36
+ #<#/<%- firstLetterUpperCase(queueName) %>QueueSetting#>
37
+
38
+ <%_ function firstLetterUpperCase(text){
39
+ return text.charAt(0).toUpperCase() + text.slice(1)
40
+ } _%>
41
+ <%_ function firstLetterLowerCase(str) {
42
+ return str.charAt(0).toLowerCase() + str.slice(1)
43
+ } _%>