@universis/evaluations 1.0.2
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/.eslintignore +1 -0
- package/.eslintrc +34 -0
- package/.gitlab-ci.yml +22 -0
- package/LICENSE +163 -0
- package/README.md +38 -0
- package/babel.config.js +3 -0
- package/dist/EvaluationSchemaLoader.js +33 -0
- package/dist/EvaluationSchemaLoader.js.map +1 -0
- package/dist/EvaluationService.js +56 -0
- package/dist/EvaluationService.js.map +1 -0
- package/dist/config/models/AccessToken.json +76 -0
- package/dist/config/models/ClassInstructorEvaluationEvent.json +76 -0
- package/dist/config/models/CourseClassEvaluationEvent.json +57 -0
- package/dist/config/models/EvaluationAccessToken.json +101 -0
- package/dist/config/models/EvaluationDocument.json +72 -0
- package/dist/config/models/EvaluationEvent.json +50 -0
- package/dist/config/scope.access.json +11 -0
- package/dist/evaluationRouter.js +118 -0
- package/dist/evaluationRouter.js.map +1 -0
- package/dist/handlers/evaluation-key-handler.js +45 -0
- package/dist/handlers/evaluation-key-handler.js.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/listeners/class-instructor-event-listener.js +27 -0
- package/dist/listeners/class-instructor-event-listener.js.map +1 -0
- package/dist/listeners/force-set-state-listener.js +47 -0
- package/dist/listeners/force-set-state-listener.js.map +1 -0
- package/dist/models/access-token-model.d.ts +37 -0
- package/dist/models/access-token-model.js +39 -0
- package/dist/models/access-token-model.js.map +1 -0
- package/dist/models/evaluation-access-token-model.d.ts +17 -0
- package/dist/models/evaluation-access-token-model.js +40 -0
- package/dist/models/evaluation-access-token-model.js.map +1 -0
- package/dist/models/evaluation-document-model.d.ts +13 -0
- package/dist/models/evaluation-document-model.js +150 -0
- package/dist/models/evaluation-document-model.js.map +1 -0
- package/dist/models/evaluation-event-model.d.ts +13 -0
- package/dist/models/evaluation-event-model.js +318 -0
- package/dist/models/evaluation-event-model.js.map +1 -0
- package/package.json +53 -0
- package/spec/CourseEvaluationSampleForm.json +1046 -0
- package/spec/EvaluationService.spec.js +9 -0
- package/spec/helpers/babel.js +1 -0
- package/spec/helpers/env.js +7 -0
- package/spec/helpers/reporter.js +11 -0
- package/spec/support/jasmine.json +13 -0
- package/src/EvaluationSchemaLoader.js +35 -0
- package/src/EvaluationService.js +57 -0
- package/src/config/models/AccessToken.json +76 -0
- package/src/config/models/ClassInstructorEvaluationEvent.json +76 -0
- package/src/config/models/CourseClassEvaluationEvent.json +57 -0
- package/src/config/models/EvaluationAccessToken.json +101 -0
- package/src/config/models/EvaluationDocument.json +72 -0
- package/src/config/models/EvaluationEvent.json +50 -0
- package/src/config/scope.access.json +11 -0
- package/src/evaluationRouter.js +117 -0
- package/src/handlers/evaluation-key-handler.js +45 -0
- package/src/index.js +2 -0
- package/src/listeners/class-instructor-event-listener.js +27 -0
- package/src/listeners/force-set-state-listener.js +46 -0
- package/src/models/access-token-model.d.ts +37 -0
- package/src/models/access-token-model.js +38 -0
- package/src/models/evaluation-access-token-model.d.ts +17 -0
- package/src/models/evaluation-access-token-model.js +39 -0
- package/src/models/evaluation-document-model.d.ts +13 -0
- package/src/models/evaluation-document-model.js +149 -0
- package/src/models/evaluation-event-model.d.ts +13 -0
- package/src/models/evaluation-event-model.js +317 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";var _data = require("@themost/data");var _dec, _class;
|
|
2
|
+
let AccessToken = require('./access-token-model');
|
|
3
|
+
/**
|
|
4
|
+
* @class
|
|
5
|
+
|
|
6
|
+
* @property {string} access_token
|
|
7
|
+
* @augments {DataObject}
|
|
8
|
+
*/let
|
|
9
|
+
|
|
10
|
+
EvaluationAccessToken = (_dec = _data.EdmMapping.entityType('EvaluationAccessToken'), _dec(_class = class EvaluationAccessToken extends AccessToken {
|
|
11
|
+
/**
|
|
12
|
+
* @constructor
|
|
13
|
+
*/
|
|
14
|
+
constructor() {
|
|
15
|
+
super();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static async inspect(context, access_token) {
|
|
19
|
+
const token = await context.model('EvaluationAccessToken').
|
|
20
|
+
where('access_token').equal(access_token).
|
|
21
|
+
silent().
|
|
22
|
+
getTypedItem();
|
|
23
|
+
if (token == null) {
|
|
24
|
+
return {
|
|
25
|
+
active: false };
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
active: !token.isExpired(),
|
|
30
|
+
username: token.user_id,
|
|
31
|
+
client_id: token.client_id,
|
|
32
|
+
access_token: token.access_token,
|
|
33
|
+
refresh_token: token.refresh_token,
|
|
34
|
+
scope: token.scope,
|
|
35
|
+
sub: token.evaluationEvent };
|
|
36
|
+
|
|
37
|
+
}}) || _class);
|
|
38
|
+
|
|
39
|
+
module.exports = EvaluationAccessToken;
|
|
40
|
+
//# sourceMappingURL=evaluation-access-token-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/models/evaluation-access-token-model.js"],"names":["AccessToken","require","EvaluationAccessToken","EdmMapping","entityType","constructor","inspect","context","access_token","token","model","where","equal","silent","getTypedItem","active","isExpired","username","user_id","client_id","refresh_token","scope","sub","evaluationEvent","module","exports"],"mappings":"aAAA,qC;AACA,IAAIA,WAAW,GAAGC,OAAO,CAAC,sBAAD,CAAzB;AACA;AACA;AACA;AACA;AACA;AACA,G;;AAEMC,qB,WADLC,iBAAWC,UAAX,CAAsB,uBAAtB,C,gBAAD,MACMF,qBADN,SACoCF,WADpC,CACgD;AAC5C;AACJ;AACA;AACIK,EAAAA,WAAW,GAAG;AACV;AACH;;AAEmB,eAAPC,OAAO,CAACC,OAAD,EAAUC,YAAV,EAAwB;AACxC,UAAMC,KAAK,GAAG,MAAMF,OAAO,CAACG,KAAR,CAAc,uBAAd;AACjBC,IAAAA,KADiB,CACX,cADW,EACKC,KADL,CACWJ,YADX;AAEjBK,IAAAA,MAFiB;AAGjBC,IAAAA,YAHiB,EAApB;AAIA,QAAIL,KAAK,IAAI,IAAb,EAAmB;AACjB,aAAO;AACLM,QAAAA,MAAM,EAAE,KADH,EAAP;;AAGD;AACD,WAAO;AACLA,MAAAA,MAAM,EAAE,CAACN,KAAK,CAACO,SAAN,EADJ;AAELC,MAAAA,QAAQ,EAAER,KAAK,CAACS,OAFX;AAGLC,MAAAA,SAAS,EAAEV,KAAK,CAACU,SAHZ;AAILX,MAAAA,YAAY,EAAEC,KAAK,CAACD,YAJf;AAKLY,MAAAA,aAAa,EAAEX,KAAK,CAACW,aALhB;AAMLC,MAAAA,KAAK,EAAEZ,KAAK,CAACY,KANR;AAOLC,MAAAA,GAAG,EAAEb,KAAK,CAACc,eAPN,EAAP;;AASD,GA3ByC,C;;AA6BhDC,MAAM,CAACC,OAAP,GAAiBvB,qBAAjB","sourcesContent":["import {EdmMapping} from '@themost/data';\nlet AccessToken = require('./access-token-model');\n/**\n * @class\n \n * @property {string} access_token\n * @augments {DataObject}\n */\n@EdmMapping.entityType('EvaluationAccessToken')\nclass EvaluationAccessToken extends AccessToken {\n /**\n * @constructor\n */\n constructor() {\n super();\n }\n\n static async inspect(context, access_token) {\n const token = await context.model('EvaluationAccessToken')\n .where('access_token').equal(access_token)\n .silent()\n .getTypedItem();\n if (token == null) {\n return {\n active: false\n }\n }\n return {\n active: !token.isExpired(),\n username: token.user_id,\n client_id: token.client_id,\n access_token: token.access_token,\n refresh_token: token.refresh_token,\n scope: token.scope,\n sub: token.evaluationEvent\n };\n }\n}\nmodule.exports = EvaluationAccessToken;\n"],"file":"evaluation-access-token-model.js"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";var _data = require("@themost/data");
|
|
2
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
3
|
+
var _contentService = require("../../../../server/services/content-service");
|
|
4
|
+
var _path = _interopRequireDefault(require("path"));
|
|
5
|
+
var _utils = require("@themost/common/utils");
|
|
6
|
+
var _errors = require("@themost/common/errors");
|
|
7
|
+
var _enableAttachmentModel = require("../../../../server/models/enable-attachment-model");var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _class, _class2;function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {var desc = {};Object.keys(descriptor).forEach(function (key) {desc[key] = descriptor[key];});desc.enumerable = !!desc.enumerable;desc.configurable = !!desc.configurable;if ('value' in desc || desc.initializer) {desc.writable = true;}desc = decorators.slice().reverse().reduce(function (desc, decorator) {return decorator(target, property, desc) || desc;}, desc);if (context && desc.initializer !== void 0) {desc.value = desc.initializer ? desc.initializer.call(context) : void 0;desc.initializer = undefined;}if (desc.initializer === void 0) {Object.defineProperty(target, property, desc);desc = null;}return desc;}
|
|
8
|
+
/**
|
|
9
|
+
* @class
|
|
10
|
+
* @property {number} id
|
|
11
|
+
* @augments {DataObject}
|
|
12
|
+
*/let
|
|
13
|
+
|
|
14
|
+
EvaluationDocument = (_dec = _data.EdmMapping.entityType('EvaluationDocument'), _dec2 =
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
_data.EdmMapping.param('extraAttributes', 'Object', true, true), _dec3 =
|
|
39
|
+
_data.EdmMapping.param('file', _data.EdmType.EdmStream, false), _dec4 =
|
|
40
|
+
_data.EdmMapping.action('Add', 'EvaluationDocument'), _dec5 =
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
_data.EdmMapping.param('attachment', 'EvaluationDocument', true, true), _dec6 =
|
|
52
|
+
_data.EdmMapping.action('RemoveAttachment', 'EvaluationDocument'), _dec(_class = (_class2 = class EvaluationDocument extends _data.DataObject {/**
|
|
53
|
+
* @constructor
|
|
54
|
+
*/constructor() {super();}static async next(context) {return await new Promise((resolve, reject) => {context.db.nextIdentity('EvaluationDocument', 'documentNumber', (err, value) => {if (err) {return reject(err);}return resolve(value);});});} /**
|
|
55
|
+
* Adds an attachment
|
|
56
|
+
* @param {*} file
|
|
57
|
+
* @param {*=} extraAttributes
|
|
58
|
+
*/static async add(context, file, extraAttributes) {const attachment = Object.assign({ name: file.contentFileName }, file, extraAttributes);return await EvaluationDocument._addAttachment(context, attachment);} /**
|
|
59
|
+
* Removes an attachment
|
|
60
|
+
* @param {*} attachment
|
|
61
|
+
*/static async removeAttachment(context, attachment) {return await EvaluationDocument._removeAttachment(context, attachment.id);}static _addAttachment(context, file) {let finalResult;return new Promise((resolve, reject) => {context.db.executeInTransaction((callback) => {if (typeof file.originalname === 'string') {
|
|
62
|
+
file.name = file.originalname.replace(/\.[A-Z0-9]+$/ig, function (x) {
|
|
63
|
+
return x.toLowerCase();
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const mime = file.mimetype || file.contentType;
|
|
67
|
+
if (_lodash.default.isNil(mime)) {
|
|
68
|
+
return reject(new _enableAttachmentModel.MimeTypeError('The specified file type is not supported by the system.'));
|
|
69
|
+
}
|
|
70
|
+
const addAttributes = {};
|
|
71
|
+
_lodash.default.forEach(context.model('EvaluationDocument').attributeNames, (attribute) => {
|
|
72
|
+
if (Object.prototype.hasOwnProperty.call(file, attribute)) {
|
|
73
|
+
addAttributes[attribute] = file[attribute];
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
const newAttachment = _lodash.default.assign(addAttributes, { contentType: mime });
|
|
77
|
+
const svc = context.getApplication().getService(function PrivateContentService() {});
|
|
78
|
+
//add attachment to attachments
|
|
79
|
+
let filePath;
|
|
80
|
+
if (file.destination && file.filename) {
|
|
81
|
+
filePath = _path.default.resolve(file.destination, file.filename);
|
|
82
|
+
} else {
|
|
83
|
+
filePath = file.path;
|
|
84
|
+
}
|
|
85
|
+
newAttachment.additionalType = 'EvaluationDocument';
|
|
86
|
+
svc.copyFrom(context, filePath, newAttachment, function (err) {
|
|
87
|
+
if (err) {
|
|
88
|
+
_utils.TraceUtils.error(err);
|
|
89
|
+
return callback(new _errors.HttpServerError());
|
|
90
|
+
}
|
|
91
|
+
svc.resolveUrl(context, newAttachment, function (err, url) {
|
|
92
|
+
if (err) {
|
|
93
|
+
return callback(err);
|
|
94
|
+
} else {
|
|
95
|
+
finalResult = _lodash.default.assign({}, newAttachment, {
|
|
96
|
+
url: url,
|
|
97
|
+
name: newAttachment.filename });
|
|
98
|
+
|
|
99
|
+
return callback();
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
});
|
|
104
|
+
}, (err) => {
|
|
105
|
+
if (err) {
|
|
106
|
+
return reject(err);
|
|
107
|
+
}
|
|
108
|
+
return resolve(finalResult);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
removeAttachment(context, id) {
|
|
115
|
+
let result;
|
|
116
|
+
return new Promise((resolve, reject) => {
|
|
117
|
+
context.db.executeInTransaction((callback) => {
|
|
118
|
+
//get attachment
|
|
119
|
+
return context.model('Attachment').where('id').equal(id).getItem().then((attachment) => {
|
|
120
|
+
if (attachment) {
|
|
121
|
+
//remove attachment connection
|
|
122
|
+
return self.property('attachments').remove(attachment, (err) => {
|
|
123
|
+
//remove attachment
|
|
124
|
+
if (err) {
|
|
125
|
+
return callback(err);
|
|
126
|
+
}
|
|
127
|
+
return context.model('Attachment').silent().remove(attachment).then(() => {
|
|
128
|
+
result = attachment;
|
|
129
|
+
return callback();
|
|
130
|
+
}).catch((err) => {
|
|
131
|
+
return callback(err);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
return callback(new _errors.DataNotFoundError());
|
|
136
|
+
}).catch((err) => {
|
|
137
|
+
return callback(err);
|
|
138
|
+
});
|
|
139
|
+
}, (err) => {
|
|
140
|
+
if (err) {
|
|
141
|
+
return reject(err);
|
|
142
|
+
}
|
|
143
|
+
return resolve(result);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
}}, (_applyDecoratedDescriptor(_class2, "add", [_dec2, _dec3, _dec4], Object.getOwnPropertyDescriptor(_class2, "add"), _class2), _applyDecoratedDescriptor(_class2, "removeAttachment", [_dec5, _dec6], Object.getOwnPropertyDescriptor(_class2, "removeAttachment"), _class2)), _class2)) || _class);
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
module.exports = EvaluationDocument;
|
|
150
|
+
//# sourceMappingURL=evaluation-document-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/models/evaluation-document-model.js"],"names":["EvaluationDocument","EdmMapping","entityType","param","EdmType","EdmStream","action","DataObject","constructor","next","context","Promise","resolve","reject","db","nextIdentity","err","value","add","file","extraAttributes","attachment","Object","assign","name","contentFileName","_addAttachment","removeAttachment","_removeAttachment","id","finalResult","executeInTransaction","callback","originalname","replace","x","toLowerCase","mime","mimetype","contentType","_","isNil","MimeTypeError","addAttributes","forEach","model","attributeNames","attribute","prototype","hasOwnProperty","call","newAttachment","svc","getApplication","getService","PrivateContentService","filePath","destination","filename","path","additionalType","copyFrom","TraceUtils","error","HttpServerError","resolveUrl","url","result","where","equal","getItem","then","self","property","remove","silent","catch","DataNotFoundError","module","exports"],"mappings":"aAAA;AACA;AACA;AACA;AACA;AACA;AACA,0F;AACA;AACA;AACA;AACA;AACA,G;;AAEMA,kB,WADLC,iBAAWC,UAAX,CAAsB,oBAAtB,C;;;;;;;;;;;;;;;;;;;;;;;;AAyBID,iBAAWE,KAAX,CAAiB,iBAAjB,EAAoC,QAApC,EAA8C,IAA9C,EAAoD,IAApD,C;AACAF,iBAAWE,KAAX,CAAiB,MAAjB,EAAyBC,cAAQC,SAA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EdmType} from '@themost/data';\nimport _ from \"lodash\";\nimport {PrivateContentService} from \"../../../../server/services/content-service\";\nimport path from \"path\";\nimport {TraceUtils} from \"@themost/common/utils\";\nimport {DataNotFoundError, HttpServerError} from \"@themost/common/errors\";\nimport {MimeTypeError} from \"../../../../server/models/enable-attachment-model\";\n/**\n * @class\n * @property {number} id\n * @augments {DataObject}\n */\n@EdmMapping.entityType('EvaluationDocument')\nclass EvaluationDocument extends DataObject {\n /**\n * @constructor\n */\n constructor() {\n super();\n }\n\n static async next(context) {\n return await new Promise((resolve, reject) => {\n context.db.nextIdentity('EvaluationDocument', 'documentNumber', (err, value) => {\n if (err) {\n return reject(err);\n }\n return resolve(value);\n });\n });\n }\n\n /**\n * Adds an attachment\n * @param {*} file\n * @param {*=} extraAttributes\n */\n @EdmMapping.param('extraAttributes', 'Object', true, true)\n @EdmMapping.param('file', EdmType.EdmStream, false)\n @EdmMapping.action('Add', 'EvaluationDocument')\n static async add(context, file, extraAttributes) {\n const attachment = Object.assign({\n name: file.contentFileName\n }, file, extraAttributes);\n return await EvaluationDocument._addAttachment(context, attachment);\n }\n /**\n * Removes an attachment\n * @param {*} attachment\n */\n @EdmMapping.param('attachment', 'EvaluationDocument', true, true)\n @EdmMapping.action('RemoveAttachment', 'EvaluationDocument')\n static async removeAttachment(context, attachment) {\n return await EvaluationDocument._removeAttachment(context,attachment.id);\n }\n\n static _addAttachment(context, file) {\n let finalResult;\n return new Promise((resolve, reject)=> {\n context.db.executeInTransaction((callback)=> {\n if (typeof file.originalname === 'string') {\n file.name = file.originalname.replace(/\\.[A-Z0-9]+$/ig, function (x) {\n return x.toLowerCase();\n });\n }\n const mime = file.mimetype || file.contentType;\n if (_.isNil(mime)) {\n return reject(new MimeTypeError('The specified file type is not supported by the system.'))\n }\n const addAttributes = {};\n _.forEach(context.model('EvaluationDocument').attributeNames, (attribute) => {\n if (Object.prototype.hasOwnProperty.call(file, attribute)) {\n addAttributes[attribute] = file[attribute];\n }\n });\n const newAttachment = _.assign(addAttributes, {contentType: mime});\n const svc = context.getApplication().getService(function PrivateContentService(){});\n //add attachment to attachments\n let filePath;\n if (file.destination && file.filename) {\n filePath = path.resolve(file.destination, file.filename);\n } else {\n filePath = file.path;\n }\n newAttachment.additionalType = 'EvaluationDocument';\n svc.copyFrom(context, filePath, newAttachment, function (err) {\n if (err) {\n TraceUtils.error(err);\n return callback(new HttpServerError());\n }\n svc.resolveUrl(context, newAttachment, function (err, url) {\n if (err) {\n return callback(err);\n } else {\n finalResult = _.assign({}, newAttachment, {\n url: url,\n name: newAttachment.filename\n });\n return callback();\n }\n });\n\n });\n }, (err)=> {\n if (err) {\n return reject(err);\n }\n return resolve(finalResult);\n });\n })\n\n }\n\n removeAttachment(context, id) {\n let result;\n return new Promise((resolve, reject)=> {\n context.db.executeInTransaction((callback)=> {\n //get attachment\n return context.model('Attachment').where('id').equal(id).getItem().then((attachment)=> {\n if (attachment) {\n //remove attachment connection\n return self.property('attachments').remove(attachment,(err)=> {\n //remove attachment\n if (err) {\n return callback(err);\n }\n return context.model('Attachment').silent().remove(attachment).then(()=> {\n result = attachment;\n return callback();\n }).catch((err)=> {\n return callback(err);\n });\n });\n }\n return callback(new DataNotFoundError());\n }).catch((err)=> {\n return callback(err);\n });\n }, (err)=> {\n if (err) {\n return reject(err);\n }\n return resolve(result);\n });\n });\n }\n\n}\nmodule.exports = EvaluationDocument;\n"],"file":"evaluation-document-model.js"}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
"use strict";var _common = require("@themost/common");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _data = require("@themost/data");
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
var _web = require("@themost/web");
|
|
16
|
+
var _formInspector = require("@themost/form-inspector");
|
|
17
|
+
var _evaluationDocumentModel = _interopRequireDefault(require("./evaluation-document-model"));
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
var _semver = require("semver");
|
|
21
|
+
var _util = _interopRequireDefault(require("util"));
|
|
22
|
+
var _fs = _interopRequireDefault(require("fs"));var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec10, _class, _class2;function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {var desc = {};Object.keys(descriptor).forEach(function (key) {desc[key] = descriptor[key];});desc.enumerable = !!desc.enumerable;desc.configurable = !!desc.configurable;if ('value' in desc || desc.initializer) {desc.writable = true;}desc = decorators.slice().reverse().reduce(function (desc, decorator) {return decorator(target, property, desc) || desc;}, desc);if (context && desc.initializer !== void 0) {desc.value = desc.initializer ? desc.initializer.call(context) : void 0;desc.initializer = undefined;}if (desc.initializer === void 0) {Object.defineProperty(target, property, desc);desc = null;}return desc;}const EvaluationAccessToken = require('./evaluation-access-token-model');
|
|
23
|
+
/**
|
|
24
|
+
* @class
|
|
25
|
+
|
|
26
|
+
* @property {string} id
|
|
27
|
+
* @augments {DataObject}
|
|
28
|
+
*/let
|
|
29
|
+
|
|
30
|
+
EvaluationEvent = (_dec = _data.EdmMapping.entityType('EvaluationEvent'), _dec2 =
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
_data.EdmMapping.func('Current', 'EvaluationEvent'), _dec3 =
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
_data.EdmMapping.func('form', 'Object'), _dec4 =
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
_data.EdmMapping.func('Results', _data.EdmType.CollectionOf('Object')), _dec5 =
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
_data.EdmMapping.func('Tokens', _data.EdmType.CollectionOf('EvaluationAccessToken')), _dec6 =
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
_data.EdmMapping.func('FormAttributes', _data.EdmType.CollectionOf('Object')), _dec7 =
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
_data.EdmMapping.param('data', 'Object', false, true), _dec8 =
|
|
217
|
+
_data.EdmMapping.action('Evaluate', 'Object'), _dec9 =
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
_data.EdmMapping.param('data', 'Object', false, true), _dec10 =
|
|
272
|
+
_data.EdmMapping.action('GenerateTokens', 'Object'), _dec(_class = (_class2 = class EvaluationEvent extends _data.DataObject {/**
|
|
273
|
+
* @constructor
|
|
274
|
+
*/constructor() {super();} /**
|
|
275
|
+
* Get current evaluation based on the evaluation key contained in Evaluation-Key HTTP header
|
|
276
|
+
* @param {HttpContext} context
|
|
277
|
+
*/static async getCurrent(context) {// get evaluation key
|
|
278
|
+
const token = await EvaluationAccessToken.inspect(context, context.user && context.user.authenticationToken);if (token.active === false) {throw new _common.HttpTokenExpiredError('Evaluation access token has been expired or is invalid.');} // get evaluation event
|
|
279
|
+
const evaluationEvent = await context.model('EvaluationEvent').find(token.sub).silent().getTypedItem();if (evaluationEvent == null) {throw new _common.HttpNotFoundError('The specified evaluation cannot be found');}if (evaluationEvent.additionalType !== 'EvaluationEvent') {return await evaluationEvent.getAdditionalObject();}return evaluationEvent;}async getForm() {const form = await this.property('evaluationDocument').getItem();const service = this.context.getApplication().getService(function PrivateContentService() {}); /**
|
|
280
|
+
* @type {string}
|
|
281
|
+
*/const formPath = await new Promise((resolve, reject) => {service.resolvePhysicalPath(this.context, form, (err, physicalPath) => {if (err) {return reject(err);}return resolve(physicalPath);});});const readFileAsync = _util.default.promisify(_fs.default.readFile);let content = await readFileAsync(formPath);if (content == null) {throw new _common.HttpNotFoundError('Evaluation form cannot be found');}let buffer = Buffer.from(content, 'base64');let result;result = JSON.parse(buffer.toString('utf8'));try {result.properties = result.properties || {};Object.assign(result.properties, { name: form.resultType, _id: form.id, _event: this.id }); // post-processing
|
|
282
|
+
let shouldUpgrade = true;let model = this.context.model(form.resultType);if (model != null) {shouldUpgrade = (0, _semver.lt)(model.version, form.version);}if (shouldUpgrade) {// load for inspector
|
|
283
|
+
const inspector = new _formInspector.JsonFormInspector();model = inspector.inspect(result); // post processing steps
|
|
284
|
+
Object.assign(model, { source: form.resultType, // add source from evaluation document e.g. Evaluation1
|
|
285
|
+
view: form.resultType, // add view from evaluation document e.g. Evaluation1
|
|
286
|
+
version: model.version, // set version (follow updates)
|
|
287
|
+
hidden: true }); // add evaluation event and evaluation document associations
|
|
288
|
+
// for further processing of evaluation results
|
|
289
|
+
model.fields.push.apply(model.fields, [{ name: 'evaluationEvent', type: this.getModel().name, editable: false, nullable: false, indexed: true }]); // reset privileges
|
|
290
|
+
/**
|
|
291
|
+
* @type {DataConfigurationStrategy|*}
|
|
292
|
+
*/const dataConfiguration = this.context.getApplication().getConfiguration().getStrategy(_data.DataConfigurationStrategy);model.privileges.splice(0); // get resultPrivileges
|
|
293
|
+
const thisModel = dataConfiguration.model(this.getModel().name);model.privileges.push.apply(model.privileges, [{ "mask": 15, "type": "global" }, { "mask": 1, "type": "global", "account": "Administrators" }]); // add extra privileges
|
|
294
|
+
if (Array.isArray(thisModel.resultPrivileges)) {model.privileges.push.apply(model.privileges, thisModel.resultPrivileges);}dataConfiguration.setModelDefinition(model); // add entity set
|
|
295
|
+
const builder = this.context.getApplication().getService(_data.ODataModelBuilder);builder.addEntitySet(model.name, model.name);if (model.hidden) {builder.removeEntitySet(model.name);} // update version
|
|
296
|
+
form.version = model.version;await this.context.model('EvaluationDocument').silent().save(form);}return result;} catch (err) {_common.TraceUtils.error(`Error while decoding evaluation form ${form.id} content.`);_common.TraceUtils.error(err);throw new _common.HttpServerError('An error occurred while decoding evaluation form.');}}async getResults() {const form = await this.getForm();return this.context.model(form.properties.name).where('evaluationEvent').equal(this.id).prepare();}async getAccessTokens() {return this.context.model('EvaluationAccessToken').where('evaluationEvent').equal(this.id).prepare();}async getFormAttributes() {const result = [];const form = await this.getForm(); // get model attributes
|
|
297
|
+
/**
|
|
298
|
+
* @type {DataConfigurationStrategy|*}
|
|
299
|
+
*/const dataConfiguration = this.context.getApplication().getConfiguration().getStrategy(_data.DataConfigurationStrategy);const model = dataConfiguration.model(form.properties.name);const attributes = model.fields;attributes.forEach((attribute) => {const key = this.findByKey(form.components, attribute.name);if (key) {attribute = Object.assign(attribute, { name: attribute.name, label: key.label });result.push(attribute);}});return result;}findByKey(array, key) {for (let index = 0; index < array.length; index++) {const element = array[index];if (element.key === key) {return element;} else {if (element.components) {const found = this.findByKey(element.components, key);if (found) {return found;}}}}}async evaluate(data) {const token = await EvaluationAccessToken.inspect(this.context, this.context.user.authenticationToken);if (token.active === false) {throw new _common.HttpTokenExpiredError('Evaluation access token has been expired or is invalid.');}if (this.id !== token.sub) {throw new _common.HttpBadRequestError('Evaluation access token is invalid');} // get evaluation form
|
|
300
|
+
const form = await this.getForm(); // get evaluation document
|
|
301
|
+
if (form == null) {throw new _common.HttpNotFoundError('Evaluation form cannot be found');} // get evaluation document
|
|
302
|
+
const evaluationDocument = await this.context.model(_evaluationDocumentModel.default).where('id').equal(form.properties._id).silent().getItem();if (evaluationDocument == null) {throw new _common.HttpNotFoundError('Evaluation document cannot be found');} // assign defaults
|
|
303
|
+
Object.assign(data, { evaluationEvent: this.id, evaluationDocument: evaluationDocument.id }); // and finally append evaluation
|
|
304
|
+
await this.context.model(evaluationDocument.resultType).on('after.save', (event, callback) => {const context = event.model.context;context.model(EvaluationAccessToken).where('access_token').equal(context.user && context.user.authenticationToken).silent().getItem().then((token) => {if (token == null) {throw new _common.HttpTokenExpiredError('Evaluation token is required');}return context.model(EvaluationAccessToken).silent().save({ access_token: token.access_token, expires: new Date(0) // set epoch date
|
|
305
|
+
});}).then(() => {return callback();}).catch((err) => {_common.TraceUtils.error('An error occurred while submitting evaluation');return callback(err);});}).silent().save(data);return data;} /**
|
|
306
|
+
* Generates a number of access tokens for the given event
|
|
307
|
+
* @param {DataContext} context
|
|
308
|
+
* @param {{evaluationEvent: number, n: number, expires?: DateTime}|*} generateOptions
|
|
309
|
+
*/static async generateTokens(context, generateOptions) {let items = [];if (Array.isArray(generateOptions)) {let n = 0;let newItems; // eslint-disable-next-line no-unused-vars
|
|
310
|
+
for (let itemGenerateOptions of generateOptions) {newItems = await EvaluationEvent.generateManyTokens(context, itemGenerateOptions);n += newItems.length;items.push.apply(items, newItems);}await context.model('EvaluationAccessToken').save(items);return n;} else {items = await EvaluationEvent.generateManyTokens(context, generateOptions);await context.model('EvaluationAccessToken').save(items);return items.length;}} /**
|
|
311
|
+
* Generates a number of access tokens for the given event
|
|
312
|
+
* @param {DataContext} context
|
|
313
|
+
* @param {{evaluationEvent: number, n: number, expires?: DateTime}} generateOptions
|
|
314
|
+
*/static async generateManyTokens(context, generateOptions) {const n = generateOptions.n;_common.Args.check(typeof n === 'number', 'Expected a number greater than zero');_common.Args.check(n > 0, 'The number of access tokens must be greater than zero');let maximumGenerateTokens = _common.LangUtils.parseInt(context.getConfiguration().getSourceAt('settings/evaluation/maximumGenerateTokens'));if (maximumGenerateTokens === 0) {maximumGenerateTokens = 128;}_common.Args.check(n < maximumGenerateTokens, `The specified number of tokens exceeded the maximum allowed (${maximumGenerateTokens})`);const items = []; // generate tokens
|
|
315
|
+
for (let index = 0; index < n; index++) {items.push({ evaluationEvent: generateOptions.evaluationEvent, expires: generateOptions.expires });}return items;}}, (_applyDecoratedDescriptor(_class2, "getCurrent", [_dec2], Object.getOwnPropertyDescriptor(_class2, "getCurrent"), _class2), _applyDecoratedDescriptor(_class2.prototype, "getForm", [_dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "getForm"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getResults", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "getResults"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getAccessTokens", [_dec5], Object.getOwnPropertyDescriptor(_class2.prototype, "getAccessTokens"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getFormAttributes", [_dec6], Object.getOwnPropertyDescriptor(_class2.prototype, "getFormAttributes"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "evaluate", [_dec7, _dec8], Object.getOwnPropertyDescriptor(_class2.prototype, "evaluate"), _class2.prototype), _applyDecoratedDescriptor(_class2, "generateTokens", [_dec9, _dec10], Object.getOwnPropertyDescriptor(_class2, "generateTokens"), _class2)), _class2)) || _class);
|
|
316
|
+
|
|
317
|
+
module.exports = EvaluationEvent;
|
|
318
|
+
//# sourceMappingURL=evaluation-event-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/models/evaluation-event-model.js"],"names":["EvaluationAccessToken","require","EvaluationEvent","EdmMapping","entityType","func","EdmType","CollectionOf","param","action","DataObject","constructor","getCurrent","context","token","inspect","user","authenticationToken","active","HttpTokenExpiredError","evaluationEvent","model","find","sub","silent","getTypedItem","HttpNotFoundError","additionalType","getAdditionalObject","getForm","form","property","getItem","service","getApplication","getService","PrivateContentService","formPath","Promise","resolve","reject","resolvePhysicalPath","err","physicalPath","readFileAsync","util","promisify","fs","readFile","content","buffer","Buffer","from","result","JSON","parse","toString","properties","Object","assign","name","resultType","_id","id","_event","shouldUpgrade","version","inspector","JsonFormInspector","source","view","hidden","fields","push","apply","type","getModel","editable","nullable","indexed","dataConfiguration","getConfiguration","getStrategy","DataConfigurationStrategy","privileges","splice","thisModel","Array","isArray","resultPrivileges","setModelDefinition","builder","ODataModelBuilder","addEntitySet","removeEntitySet","save","TraceUtils","error","HttpServerError","getResults","where","equal","prepare","getAccessTokens","getFormAttributes","attributes","forEach","attribute","key","findByKey","components","label","array","index","length","element","found","evaluate","data","HttpBadRequestError","evaluationDocument","EvaluationDocument","on","event","callback","then","access_token","expires","Date","catch","generateTokens","generateOptions","items","n","newItems","itemGenerateOptions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,EAAEI,eAAe,CAACJ,OAFlB,EAAX,EAIH,CACD,OAAOK,KAAP,CACH,CA7RoC,C;;AA+RzCW,MAAM,CAACC,OAAP,GAAiB9I,eAAjB","sourcesContent":["import { HttpNotFoundError, HttpTokenExpiredError, HttpServerError,\n TraceUtils, \n HttpBadRequestError,\n Args,\n LangUtils} from '@themost/common';\n\nimport {\n DataConfigurationStrategy,\n DataContext,\n DataObject,\n EdmMapping,\n EdmType,\n ODataModelBuilder\n} from '@themost/data';\nimport { HttpContext } from '@themost/web';\nimport { JsonFormInspector } from '@themost/form-inspector';\nimport EvaluationDocument from './evaluation-document-model';\n\nconst EvaluationAccessToken = require('./evaluation-access-token-model');\nimport {lt} from 'semver';\nimport util from \"util\";\nimport fs from \"fs\";\n/**\n * @class\n \n * @property {string} id\n * @augments {DataObject}\n */\n@EdmMapping.entityType('EvaluationEvent')\nclass EvaluationEvent extends DataObject {\n /**\n * @constructor\n */\n constructor() {\n super();\n }\n\n /**\n * Get current evaluation based on the evaluation key contained in Evaluation-Key HTTP header\n * @param {HttpContext} context \n */\n @EdmMapping.func('Current', 'EvaluationEvent')\n static async getCurrent(context) {\n // get evaluation key\n const token = await EvaluationAccessToken.inspect(context, context.user && context.user.authenticationToken);\n if (token.active === false) {\n throw new HttpTokenExpiredError('Evaluation access token has been expired or is invalid.');\n }\n // get evaluation event\n const evaluationEvent = await context.model('EvaluationEvent').find(token.sub).silent().getTypedItem();\n if (evaluationEvent == null) {\n throw new HttpNotFoundError('The specified evaluation cannot be found');\n }\n if (evaluationEvent.additionalType !== 'EvaluationEvent') {\n return await evaluationEvent.getAdditionalObject();\n }\n return evaluationEvent;\n }\n\n @EdmMapping.func('form', 'Object')\n async getForm() {\n const form = await this.property('evaluationDocument').getItem();\n const service = this.context.getApplication().getService(function PrivateContentService(){});\n /**\n * @type {string}\n */\n const formPath = await new Promise((resolve, reject) => {\n service.resolvePhysicalPath(this.context, form, (err, physicalPath) => {\n if (err) {\n return reject(err);\n }\n return resolve(physicalPath);\n })\n });\n const readFileAsync = util.promisify(fs.readFile);\n let content = await readFileAsync(formPath);\n if (content == null) {\n throw new HttpNotFoundError('Evaluation form cannot be found');\n }\n let buffer = Buffer.from(content,'base64');\n let result;\n result = JSON.parse(buffer.toString('utf8'));\n\n try {\n result.properties = result.properties || {};\n Object.assign(result.properties, {\n name: form.resultType,\n _id: form.id,\n _event: this.id\n });\n // post-processing\n let shouldUpgrade = true;\n let model = this.context.model(form.resultType);\n if (model != null) {\n shouldUpgrade = lt(model.version, form.version)\n }\n if (shouldUpgrade) {\n // load for inspector\n const inspector = new JsonFormInspector();\n model = inspector.inspect(result);\n // post processing steps\n Object.assign(model, {\n source: form.resultType, // add source from evaluation document e.g. Evaluation1\n view: form.resultType, // add view from evaluation document e.g. Evaluation1\n version: model.version ,// set version (follow updates)\n hidden: true\n });\n // add evaluation event and evaluation document associations\n // for further processing of evaluation results\n model.fields.push.apply(model.fields, [\n {\n name: 'evaluationEvent',\n type: this.getModel().name,\n editable: false,\n nullable: false,\n indexed: true,\n }\n ]);\n // reset privileges\n /**\n * @type {DataConfigurationStrategy|*}\n */\n const dataConfiguration = this.context.getApplication()\n .getConfiguration().getStrategy(DataConfigurationStrategy);\n\n model.privileges.splice(0);\n // get resultPrivileges\n const thisModel = dataConfiguration.model(this.getModel().name);\n\n model.privileges.push.apply(model.privileges, [\n {\n \"mask\": 15,\n \"type\": \"global\"\n },\n {\n \"mask\": 1,\n \"type\": \"global\",\n \"account\": \"Administrators\"\n }\n ]);\n // add extra privileges\n if (Array.isArray(thisModel.resultPrivileges)) {\n model.privileges.push.apply(model.privileges, thisModel.resultPrivileges);\n }\n dataConfiguration.setModelDefinition(model);\n // add entity set\n const builder = this.context.getApplication().getService(ODataModelBuilder);\n builder.addEntitySet(model.name, model.name);\n if (model.hidden) {\n builder.removeEntitySet(model.name);\n }\n // update version\n form.version= model.version;\n await this.context.model('EvaluationDocument').silent().save(form);\n }\n return result;\n } catch (err) {\n TraceUtils.error(`Error while decoding evaluation form ${form.id} content.`);\n TraceUtils.error(err);\n throw new HttpServerError('An error occurred while decoding evaluation form.');\n }\n }\n\n @EdmMapping.func('Results', EdmType.CollectionOf('Object'))\n async getResults() {\n const form = await this.getForm();\n return this.context.model(form.properties.name).where('evaluationEvent').equal(this.id).prepare();\n }\n\n @EdmMapping.func('Tokens', EdmType.CollectionOf('EvaluationAccessToken'))\n async getAccessTokens() {\n return this.context.model('EvaluationAccessToken').where('evaluationEvent').equal(this.id).prepare();\n }\n\n @EdmMapping.func('FormAttributes', EdmType.CollectionOf('Object'))\n async getFormAttributes() {\n const result = [];\n const form = await this.getForm();\n // get model attributes\n /**\n * @type {DataConfigurationStrategy|*}\n */\n const dataConfiguration = this.context.getApplication()\n .getConfiguration().getStrategy(DataConfigurationStrategy);\n\n const model = dataConfiguration.model(form.properties.name);\n const attributes = model.fields;\n attributes.forEach(attribute => {\n const key = this.findByKey(form.components, attribute.name);\n if (key) {\n attribute = Object.assign(attribute,{\n name: attribute.name, label: key.label\n });\n result.push(attribute);\n }\n });\n return result;\n }\n\n findByKey(array, key) {\n for (let index = 0; index < array.length; index++) {\n const element = array[index];\n if (element.key === key) {\n return element;\n } else {\n if (element.components) {\n const found = this.findByKey(element.components, key);\n if (found) {\n return found;\n }\n }\n }\n }\n }\n\n @EdmMapping.param('data', 'Object', false, true)\n @EdmMapping.action('Evaluate', 'Object')\n async evaluate(data) {\n const token = await EvaluationAccessToken.inspect(this.context, this.context.user.authenticationToken);\n if (token.active === false) {\n throw new HttpTokenExpiredError('Evaluation access token has been expired or is invalid.');\n }\n if (this.id !== token.sub) {\n throw new HttpBadRequestError('Evaluation access token is invalid');\n }\n // get evaluation form\n const form = await this.getForm();\n // get evaluation document\n if (form == null) {\n throw new HttpNotFoundError('Evaluation form cannot be found');\n }\n // get evaluation document\n const evaluationDocument = await this.context.model(EvaluationDocument)\n .where('id').equal(form.properties._id)\n .silent().getItem();\n if (evaluationDocument == null) {\n throw new HttpNotFoundError('Evaluation document cannot be found');\n }\n // assign defaults\n Object.assign(data, {\n evaluationEvent: this.id,\n evaluationDocument: evaluationDocument.id\n });\n // and finally append evaluation\n await this.context.model(evaluationDocument.resultType).on('after.save', (event, callback) => {\n const context = event.model.context;\n context.model(EvaluationAccessToken).where('access_token').equal(context.user && context.user.authenticationToken)\n .silent().getItem().then((token) => {\n if (token == null) {\n throw new HttpTokenExpiredError('Evaluation token is required');\n }\n return context.model(EvaluationAccessToken).silent().save({\n access_token: token.access_token,\n expires: new Date(0) // set epoch date\n });\n }).then(() => {\n return callback();\n }).catch((err) => {\n TraceUtils.error('An error occurred while submitting evaluation');\n return callback(err);\n });\n }).silent().save(data);\n return data;\n }\n\n /**\n * Generates a number of access tokens for the given event\n * @param {DataContext} context\n * @param {{evaluationEvent: number, n: number, expires?: DateTime}|*} generateOptions\n */\n @EdmMapping.param('data', 'Object', false, true)\n @EdmMapping.action('GenerateTokens', 'Object')\n static async generateTokens(context, generateOptions) {\n let items = [];\n if (Array.isArray(generateOptions)) {\n let n = 0;\n let newItems;\n // eslint-disable-next-line no-unused-vars\n for(let itemGenerateOptions of generateOptions) {\n newItems = await EvaluationEvent.generateManyTokens(context, itemGenerateOptions);\n n += newItems.length;\n items.push.apply(items, newItems);\n }\n await context.model('EvaluationAccessToken').save(items);\n return n\n } else {\n items = await EvaluationEvent.generateManyTokens(context, generateOptions);\n await context.model('EvaluationAccessToken').save(items);\n return items.length;\n } \n }\n /**\n * Generates a number of access tokens for the given event \n * @param {DataContext} context\n * @param {{evaluationEvent: number, n: number, expires?: DateTime}} generateOptions\n */\n static async generateManyTokens(context, generateOptions) {\n const n = generateOptions.n;\n Args.check(typeof n === 'number', 'Expected a number greater than zero');\n Args.check(n > 0, 'The number of access tokens must be greater than zero');\n let maximumGenerateTokens = LangUtils.parseInt(context.getConfiguration().getSourceAt('settings/evaluation/maximumGenerateTokens'));\n if (maximumGenerateTokens === 0) {\n maximumGenerateTokens = 128;\n }\n Args.check(n < maximumGenerateTokens, `The specified number of tokens exceeded the maximum allowed (${maximumGenerateTokens})`);\n const items = [];\n // generate tokens\n for (let index = 0; index < n; index++) {\n items.push({\n evaluationEvent: generateOptions.evaluationEvent,\n expires: generateOptions.expires\n });\n }\n return items;\n }\n}\nmodule.exports = EvaluationEvent;\n"],"file":"evaluation-event-model.js"}
|