-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '2.3.0' of http://10.73.97.24/oecloud.io/oe-service-pers…
- Loading branch information
Showing
20 changed files
with
3,369 additions
and
1,087 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* | ||
* ©2016-2020 EdgeVerve Systems Limited (a fully owned Infosys subsidiary), | ||
* Bangalore, India. All Rights Reserved. | ||
* | ||
*/ | ||
|
||
/** | ||
* This mixin will attach beforeRemote and afterRemote | ||
* hooks and decide if the data needs to be service | ||
* personalized. | ||
* | ||
* Therefore, it is necessary to enable the mixin | ||
* configuration on the corresponding model definition, | ||
* even if it does not directly participate in the | ||
* service personalization (viz is the case with any | ||
* form of relations - or related models). | ||
* | ||
* This will only personalize data for the remote endpoints. | ||
*/ | ||
|
||
|
||
const logger = require('oe-logger'); | ||
const log = logger('service-personalization-mixin'); | ||
const { runPersonalizations } = require('./../../lib/service-personalizer'); | ||
const { slice } = require('./../../lib/utils'); | ||
|
||
module.exports = function ServicePersonalizationMixin(TargetModel) { | ||
log.debug(log.defaultContext(), `Applying service personalization for ${TargetModel.definition.name}`); | ||
TargetModel.afterRemote('**', function ServicePersonalizationAfterRemoteHook() { | ||
let args = slice(arguments); | ||
let ctx = args[0]; | ||
let next = args[args.length - 1]; | ||
// let callCtx = ctx.req.callContext; | ||
log.debug(ctx, `afterRemote: (enter) MethodString: ${ctx.methodString}`); | ||
runPersonalizations(ctx, false, function (err) { | ||
log.debug(ctx, `afterRemote: (leave${err ? '- with error' : ''}) MethodString: ${ctx.methodString}`); | ||
next(err); | ||
}); | ||
}); | ||
|
||
TargetModel.beforeRemote('**', function ServicePersonalizationBeforeRemoteHook() { | ||
let args = slice(arguments); | ||
let ctx = args[0]; | ||
let next = args[args.length - 1]; | ||
|
||
log.debug(ctx, `beforeRemote: (enter) MethodString: ${ctx.methodString}`); | ||
|
||
// let ctxInfo = parseMethodString(ctx.methodString); | ||
runPersonalizations(ctx, true, function (err) { | ||
log.debug(ctx, `beforeRemote: (leave${err ? '- with error' : ''}) MethodString: ${ctx.methodString}`); | ||
next(err); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const { performServicePersonalizations, applyServicePersonalization } = require('./service-personalizer'); | ||
module.exports = { | ||
/** | ||
* Standard api for personalization | ||
*/ | ||
performServicePersonalizations, | ||
|
||
/** | ||
* Api for personalization. Rules can | ||
* be manually passed as arguments to | ||
* this function. | ||
* | ||
* @param {string} modelName - the model name. | ||
* @param {*} data - object or array | ||
* @param {array} personalizationRecords - the personalization rule as an array. | ||
* @param {object} options - personalization options | ||
* @param {function} done - callback to signal completion. Takes only one argument - error. | ||
* @returns {undefined} - nothing | ||
*/ | ||
applyServicePersonalization: function applyServicePersonalizationWrapper(modelName, data, personalizationRecords, options, done) { | ||
let { context } = options; | ||
context._personalizationCache = {}; | ||
applyServicePersonalization(modelName, data, personalizationRecords, options, done); | ||
} | ||
}; |
Oops, something went wrong.