@izara_project/izara-market-library-service-schemas 1.0.62 → 1.0.64
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/GenerateCodeLibs/src/Consts.js +7 -3
- package/src/MainLibs/src/Consts.js +6 -2
- package/src/reStructure/GenerateCode.js +1 -1
- package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/template.ejs +20 -8
- package/src/reStructure/TemplateData/EndpointPerService/mainFunction/update/template.ejs +114 -83
- package/src/reStructure/TemplateData/externalService/lambdaRole/data.js +8 -0
- package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/data.js +11 -1
- package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/handler/template.ejs +13 -7
- package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +3 -2
- package/src/reStructure/TemplateData/flowSchema/register/complete/handler/template.ejs +1 -0
- package/src/reStructure/TemplateData/flowSchema/register/complete/mainFunction/template.ejs +3 -1
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/api/data.js +123 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/api/template.ejs +20 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/dsq/data.js +122 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/dsq/template.ejs +17 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/inv/data.js +123 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/inv/template.ejs +13 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/sqs/data.js +123 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/sqs/template.ejs +17 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/api/data.js +57 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/api/request.json +0 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/api/template.ejs +155 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/dsq/data.js +58 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/dsq/request.json +0 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/dsq/template.ejs +202 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/inv/data.js +59 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/inv/request.json +0 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/inv/template.ejs +144 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/sqs/data.js +59 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/sqs/request.json +0 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/handler/sqs/template.ejs +181 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/mainFunction/data.js +59 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/mainFunction/template.ejs +382 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/sns-in-sqs/data.js +77 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/sns-in-sqs/snsTemplate.ejs +59 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/sns-in-sqs/sqsTemplate.ejs +43 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/functionYaml/data.js +121 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/functionYaml/template.ejs +20 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/handler/sqs/data.js +60 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/handler/sqs/template.ejs +129 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/mainFunction/data.js +55 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/mainFunction/template.ejs +154 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/sns-in-sqs/data.js +71 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/sns-in-sqs/template.ejs +46 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/sns-out/data.js +71 -0
- package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/complete/sns-out/template.ejs +10 -0
- package/src/reStructure/TemplateData/relationshipPerAction/create/complete/handler/sqs/template.ejs +2 -2
- package/src/reStructure/TemplateData/relationshipPerAction/generateTemplateData.js +55 -2
|
@@ -0,0 +1,181 @@
|
|
|
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 izara = require("@izara_project/izara-middleware");
|
|
20
|
+
const middleware = izara.middlewareHandler;
|
|
21
|
+
const callingFlowSharedLib = require('@izara_project/izara-core-library-calling-flow');
|
|
22
|
+
const {
|
|
23
|
+
validateSchemaMiddleware
|
|
24
|
+
} = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/GenerateCodeLibs');
|
|
25
|
+
const Logger = require('@izara_project/izara-core-library-logger');
|
|
26
|
+
const recordHandlerSharedLib = require('@izara_project/izara-core-library-record-handler');
|
|
27
|
+
|
|
28
|
+
const <%- functionName %> = require('./<%- firstLetterUpperCase(functionName) %>_Main');
|
|
29
|
+
|
|
30
|
+
middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
31
|
+
|
|
32
|
+
// validate event params in middleware before into function
|
|
33
|
+
let validatorSchema = {
|
|
34
|
+
type: "object",
|
|
35
|
+
required: [
|
|
36
|
+
'firstObject',
|
|
37
|
+
'secondObject',
|
|
38
|
+
'oldReltypeAndDirection',
|
|
39
|
+
'newRelType',
|
|
40
|
+
],
|
|
41
|
+
properties: {
|
|
42
|
+
firstObject: {
|
|
43
|
+
type: 'object',
|
|
44
|
+
required: ['objType', 'identifiers'],
|
|
45
|
+
properties: {
|
|
46
|
+
objType: {
|
|
47
|
+
type: 'object',
|
|
48
|
+
required: ['objectType', 'serviceTag'],
|
|
49
|
+
properties: {
|
|
50
|
+
serviceTag: izara.validatorSchema.stringNotEmpty(),
|
|
51
|
+
objectType: izara.validatorSchema.stringNotEmpty(),
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
identifiers: {
|
|
55
|
+
type: "object",
|
|
56
|
+
minProperties: 1
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
secondObject: {
|
|
61
|
+
type: 'object',
|
|
62
|
+
required: ['objType', 'identifiers'],
|
|
63
|
+
properties: {
|
|
64
|
+
objType: {
|
|
65
|
+
type: 'object',
|
|
66
|
+
required: ['objectType', 'serviceTag'],
|
|
67
|
+
properties: {
|
|
68
|
+
serviceTag: izara.validatorSchema.stringNotEmpty(),
|
|
69
|
+
objectType: izara.validatorSchema.stringNotEmpty(),
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
identifiers: {
|
|
73
|
+
type: "object",
|
|
74
|
+
minProperties: 1
|
|
75
|
+
},
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
oldReltypeAndDirection: {
|
|
79
|
+
type: 'object',
|
|
80
|
+
required: ['relType', 'relationshipDirection'],
|
|
81
|
+
properties: {
|
|
82
|
+
relType: {
|
|
83
|
+
type: 'object',
|
|
84
|
+
required: ['serviceTag', 'relationshipTag'],
|
|
85
|
+
properties: {
|
|
86
|
+
serviceTag: izara.validatorSchema.stringNotEmpty(),
|
|
87
|
+
relationshipTag: izara.validatorSchema.stringNotEmpty(),
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
relationshipProperties: {
|
|
91
|
+
type: 'object',
|
|
92
|
+
},
|
|
93
|
+
relationshipDirection: {
|
|
94
|
+
type: 'string',
|
|
95
|
+
enum: ['from', 'to']
|
|
96
|
+
|
|
97
|
+
},
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
newRelType: {
|
|
101
|
+
type: 'object',
|
|
102
|
+
required: ['serviceTag', 'relationshipTag'],
|
|
103
|
+
properties: {
|
|
104
|
+
serviceTag: izara.validatorSchema.stringNotEmpty(),
|
|
105
|
+
relationshipTag: izara.validatorSchema.stringNotEmpty(),
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
settings: {
|
|
109
|
+
type: 'object'
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
//(<globalVariable>
|
|
116
|
+
//</globalVariable>)
|
|
117
|
+
|
|
118
|
+
// validate event params in middleware before into main function
|
|
119
|
+
validatorSchema = callingFlowSharedLib.addOptionalCallingFlowToValidatorSchema(validatorSchema);
|
|
120
|
+
// if need to validate authorizer or additional params , add code to hook tag below
|
|
121
|
+
|
|
122
|
+
//(<afterValidateWith>)
|
|
123
|
+
//(</afterValidateWith>)
|
|
124
|
+
|
|
125
|
+
module.exports.main = middleware.wrap(async (event, context, callback) => {
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
|
|
129
|
+
let recordPromises = []; // final return
|
|
130
|
+
|
|
131
|
+
// loop each record and send to mainFunction
|
|
132
|
+
await Promise.all(event.Records.map(async record => { // promise.all for map() function
|
|
133
|
+
|
|
134
|
+
let passOnProperties = []
|
|
135
|
+
|
|
136
|
+
// --- validate message (and MessageAttributes)
|
|
137
|
+
await recordHandlerSharedLib.validateRecord(
|
|
138
|
+
record, // one record will send to mainFunction
|
|
139
|
+
"<%-firstLetterUpperCase(queueName) %>", // queue name that need to retry or send to dlq
|
|
140
|
+
validatorSchema, // schema for record.Message
|
|
141
|
+
// messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
// add argument (to invoke lambda) to passOnProperties[]
|
|
145
|
+
passOnProperties.push(record.body.Message)
|
|
146
|
+
passOnProperties.push(callingFlowSharedLib.addCallingFlowToPassOnProperties(record.body.Message));
|
|
147
|
+
//(<afterPutParamIntoMainFunction>)
|
|
148
|
+
//(</afterPutParamIntoMainFunction>)
|
|
149
|
+
|
|
150
|
+
record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
|
|
151
|
+
|
|
152
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
153
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
154
|
+
record, // one record will send to mainFunction
|
|
155
|
+
<%- functionName %>.<%- functionName %>, // mainFunction that need to invoke.
|
|
156
|
+
"<%-firstLetterUpperCase(queueName) %>", // queue name that need to retry or send to dlq
|
|
157
|
+
passOnProperties, // all parameters that mainFunction needed.
|
|
158
|
+
);
|
|
159
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
160
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
161
|
+
})) //end record
|
|
162
|
+
|
|
163
|
+
Logger.debug('before Promise.all(recordPromises) in handler');
|
|
164
|
+
try {
|
|
165
|
+
await Promise.all(recordPromises); // await all promises
|
|
166
|
+
return event.Records // return all for local test
|
|
167
|
+
} catch {
|
|
168
|
+
Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
|
|
169
|
+
}
|
|
170
|
+
Logger.debug('after Promise.all(recordPromises) in handler');
|
|
171
|
+
} catch (err) {
|
|
172
|
+
Logger.error('Unhandled Error, updateRelationshipHdrDsq:', err);
|
|
173
|
+
throw (err);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
<%_ function firstLetterUpperCase(text) {
|
|
177
|
+
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
178
|
+
} _%>
|
|
179
|
+
<%_ function firstLetterLowerCase(str) {
|
|
180
|
+
return str.charAt(0).toLowerCase() + str.slice(1)
|
|
181
|
+
} _%>
|
|
@@ -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
|
+
}
|