diff --git a/application/lib/transforms/add.js b/application/lib/transforms/add.js index fa90bdd..ae9c274 100644 --- a/application/lib/transforms/add.js +++ b/application/lib/transforms/add.js @@ -1,38 +1,19 @@ 'use strict'; const TinCan = require('tincanjs'); -const Microservices = require('../../configs/microservices'); - const xapi = require('../xapiUtil'); -const self = module.exports = { - - transform: function(activity) { - let statement = new TinCan.Statement({ +module.exports = { - verb: { - id: 'http://activitystrea.ms/schema/1.0/create', - display: { - en: 'created', - }, + transform: function (activity) { + let statementCfg = xapi.prepareStatement(activity); + statementCfg.verb = { + id: 'http://activitystrea.ms/schema/1.0/create', + display: { + en: 'created', }, - - actor: xapi.actor(activity.user), - - object: { - id: `${Microservices.platform.uri}/${activity.content_kind}/${activity.content_id}`, - definition: { - name: { - en: activity.content.title, - }, - description: { - en: activity.content.description || undefined, - }, - }, - }, - - }); - + }; + let statement = new TinCan.Statement(statementCfg); return statement; }, diff --git a/application/lib/transforms/comment.js b/application/lib/transforms/comment.js index fa14827..8b487c9 100644 --- a/application/lib/transforms/comment.js +++ b/application/lib/transforms/comment.js @@ -1,38 +1,18 @@ 'use strict'; const TinCan = require('tincanjs'); -const Microservices = require('../../configs/microservices'); - const xapi = require('../xapiUtil'); -const self = module.exports = { - - transform: function(activity) { - let statement = new TinCan.Statement({ - - verb: { - id: 'http://adlnet.gov/expapi/verbs/commented', - display: { - en: 'commented', - }, - }, - - actor: xapi.actor(activity.user), - - object: { - id: `${Microservices.platform.uri}/${activity.content_kind}/${activity.content_id}`, - definition: { - name: { - en: activity.content.title, - }, - description: { - en: activity.content.description || undefined, - }, - }, +module.exports = { + transform: function (activity) { + let statementCfg = xapi.prepareStatement(activity); + statementCfg.verb = { + id: 'http://adlnet.gov/expapi/verbs/commented', + display: { + en: 'commented', }, - - }); - + }; + let statement = new TinCan.Statement(statementCfg); return statement; }, diff --git a/application/lib/transforms/delete.js b/application/lib/transforms/delete.js index 79bb672..bebfbe1 100644 --- a/application/lib/transforms/delete.js +++ b/application/lib/transforms/delete.js @@ -5,9 +5,10 @@ const Microservices = require('../../configs/microservices'); const xapi = require('../xapiUtil'); -const self = module.exports = { +module.exports = { - transform: function(activity) { + transform: function (activity) { + console.log(JSON.stringify(activity)); let deleted = activity.delete_info; let platformPath = deleted.content_kind === 'deck' ? 'deck' : 'slideview'; @@ -31,9 +32,10 @@ const self = module.exports = { description: { en: deleted.content_name, }, + type: deleted.content_kind === 'deck' ? 'http://id.tincanapi.com/activitytype/slide-deck' : 'http://id.tincanapi.com/activitytype/slide', }, }, - + context: xapi.context(activity), }); return statement; diff --git a/application/lib/transforms/download.js b/application/lib/transforms/download.js index 7c747cc..a2be4e6 100644 --- a/application/lib/transforms/download.js +++ b/application/lib/transforms/download.js @@ -1,38 +1,18 @@ 'use strict'; const TinCan = require('tincanjs'); -const Microservices = require('../../configs/microservices'); - const xapi = require('../xapiUtil'); -const self = module.exports = { - - transform: function(activity) { - let statement = new TinCan.Statement({ - - verb: { - id: 'https://w3id.org/xapi/acrossx/verbs/downloaded', - display: { - en: 'downloaded', - }, - }, - - actor: xapi.actor(activity.user), - - object: { - id: `${Microservices.platform.uri}/${activity.content_kind}/${activity.content_id}`, - definition: { - name: { - en: activity.content.title, - }, - description: { - en: activity.content.description || undefined, - }, - }, +module.exports = { + transform: function (activity) { + let statementCfg = xapi.prepareStatement(activity); + statementCfg.verb = { + id: 'https://w3id.org/xapi/acrossx/verbs/downloaded', + display: { + en: 'downloaded', }, - - }); - + }; + let statement = new TinCan.Statement(statementCfg); return statement; }, diff --git a/application/lib/transforms/edit.js b/application/lib/transforms/edit.js index 416ca17..1f66b6e 100644 --- a/application/lib/transforms/edit.js +++ b/application/lib/transforms/edit.js @@ -1,38 +1,19 @@ 'use strict'; const TinCan = require('tincanjs'); -const Microservices = require('../../configs/microservices'); - const xapi = require('../xapiUtil'); -const self = module.exports = { - - transform: function(activity) { - let statement = new TinCan.Statement({ +module.exports = { - verb: { - id: 'https://w3id.org/xapi/acrossx/verbs/edited', - display: { - en: 'edited', - }, + transform: function (activity) { + let statementCfg = xapi.prepareStatement(activity); + statementCfg.verb = { + id: 'https://w3id.org/xapi/acrossx/verbs/edited', + display: { + en: 'edited', }, - - actor: xapi.actor(activity.user), - - object: { - id: `${Microservices.platform.uri}/${activity.content_kind}/${activity.content_id}`, - definition: { - name: { - en: activity.content.title, - }, - description: { - en: activity.content.description || undefined, - }, - }, - }, - - }); - + }; + let statement = new TinCan.Statement(statementCfg); return statement; }, diff --git a/application/lib/transforms/fork.js b/application/lib/transforms/fork.js index 3165ed0..96c2432 100644 --- a/application/lib/transforms/fork.js +++ b/application/lib/transforms/fork.js @@ -1,38 +1,19 @@ 'use strict'; const TinCan = require('tincanjs'); -const Microservices = require('../../configs/microservices'); - const xapi = require('../xapiUtil'); -const self = module.exports = { - - transform: function(activity) { - let statement = new TinCan.Statement({ +module.exports = { - verb: { - id: 'https://w3id.org/xapi/acrossx/verbs/forked', - display: { - en: 'forked', - }, + transform: function (activity) { + let statementCfg = xapi.prepareStatement(activity); + statementCfg.verb = { + id: 'https://w3id.org/xapi/acrossx/verbs/forked', + display: { + en: 'forked', }, - - actor: xapi.actor(activity.user), - - object: { - id: `${Microservices.platform.uri}/${activity.content_kind}/${activity.content_id}`, - definition: { - name: { - en: activity.content.title, - }, - description: { - en: activity.content.description || undefined, - }, - }, - }, - - }); - + }; + let statement = new TinCan.Statement(statementCfg); return statement; }, diff --git a/application/lib/transforms/react.js b/application/lib/transforms/react.js index 6a2d62f..534a9bc 100644 --- a/application/lib/transforms/react.js +++ b/application/lib/transforms/react.js @@ -3,44 +3,28 @@ const boom = require('boom'); const TinCan = require('tincanjs'); -const Microservices = require('../../configs/microservices'); - const xapi = require('../xapiUtil'); -const self = module.exports = { +module.exports = { - transform: function(activity) { + transform: function (activity) { // TODO support more reaction types ? if (activity.react_type !== 'like') { throw boom.badData(`Unsupported reaction type: ${activity.react_type}`); } - let statement = new TinCan.Statement({ - - verb: { - id: 'https://w3id.org/xapi/acrossx/verbs/liked', - display: { - en: 'liked', - }, - }, + let statementCfg = xapi.prepareStatement(activity); - actor: xapi.actor(activity.user), - - object: { - id: `${Microservices.platform.uri}/${activity.content_kind}/${activity.content_id}`, - definition: { - name: { - en: activity.content.title, - }, - description: { - en: activity.content.description || undefined, - }, - }, + statementCfg.verb = { + id: 'https://w3id.org/xapi/acrossx/verbs/liked', + display: { + en: 'liked', }, + }; - }); - + let statement = new TinCan.Statement(statementCfg); return statement; + }, }; diff --git a/application/lib/transforms/reply.js b/application/lib/transforms/reply.js index c6e6a55..6c4fb48 100644 --- a/application/lib/transforms/reply.js +++ b/application/lib/transforms/reply.js @@ -1,38 +1,19 @@ 'use strict'; const TinCan = require('tincanjs'); -const Microservices = require('../../configs/microservices'); - const xapi = require('../xapiUtil'); -const self = module.exports = { - - transform: function(activity) { - let statement = new TinCan.Statement({ +module.exports = { - verb: { - id: 'https://w3id.org/xapi/acrossx/verbs/replied', - display: { - en: 'replied', - }, + transform: function (activity) { + let statementCfg = xapi.prepareStatement(activity); + statementCfg.verb = { + id: 'https://w3id.org/xapi/acrossx/verbs/replied', + display: { + en: 'replied', }, - - actor: xapi.actor(activity.user), - - object: { - id: `${Microservices.platform.uri}/${activity.content_kind}/${activity.content_id}`, - definition: { - name: { - en: activity.content.title, - }, - description: { - en: activity.content.description || undefined, - }, - }, - }, - - }); - + }; + let statement = new TinCan.Statement(statementCfg); return statement; }, diff --git a/application/lib/transforms/share.js b/application/lib/transforms/share.js index 6557793..f44084c 100644 --- a/application/lib/transforms/share.js +++ b/application/lib/transforms/share.js @@ -1,38 +1,19 @@ 'use strict'; const TinCan = require('tincanjs'); -const Microservices = require('../../configs/microservices'); - const xapi = require('../xapiUtil'); -const self = module.exports = { - - transform: function(activity) { - let statement = new TinCan.Statement({ +module.exports = { - verb: { - id: 'https://w3id.org/xapi/acrossx/verbs/shared', - display: { - en: 'shared', - }, + transform: function (activity) { + let statementCfg = xapi.prepareStatement(activity); + statementCfg.verb = { + id: 'https://w3id.org/xapi/acrossx/verbs/shared', + display: { + en: 'shared', }, - - actor: xapi.actor(activity.user), - - object: { - id: `${Microservices.platform.uri}/${activity.content_kind}/${activity.content_id}`, - definition: { - name: { - en: activity.content.title, - }, - description: { - en: activity.content.description || undefined, - }, - }, - }, - - }); - + }; + let statement = new TinCan.Statement(statementCfg); return statement; }, diff --git a/application/lib/transforms/use.js b/application/lib/transforms/use.js index c05005c..644cb2e 100644 --- a/application/lib/transforms/use.js +++ b/application/lib/transforms/use.js @@ -1,38 +1,19 @@ 'use strict'; const TinCan = require('tincanjs'); -const Microservices = require('../../configs/microservices'); - const xapi = require('../xapiUtil'); -const self = module.exports = { - - transform: function(activity) { - let statement = new TinCan.Statement({ +module.exports = { - verb: { - id: 'https://w3id.org/xapi/acrossx/verbs/used', - display: { - en: 'used', - }, + transform: function (activity) { + let statementCfg = xapi.prepareStatement(activity); + statementCfg.verb = { + id: 'https://w3id.org/xapi/acrossx/verbs/used', + display: { + en: 'used', }, - - actor: xapi.actor(activity.user), - - object: { - id: `${Microservices.platform.uri}/${activity.content_kind}/${activity.content_id}`, - definition: { - name: { - en: activity.content.title, - }, - description: { - en: activity.content.description || undefined, - }, - }, - }, - - }); - + }; + let statement = new TinCan.Statement(statementCfg); return statement; }, diff --git a/application/lib/transforms/view.js b/application/lib/transforms/view.js index 26bb430..c666b5e 100644 --- a/application/lib/transforms/view.js +++ b/application/lib/transforms/view.js @@ -1,40 +1,20 @@ 'use strict'; const TinCan = require('tincanjs'); -const Microservices = require('../../configs/microservices'); - const xapi = require('../xapiUtil'); -const self = module.exports = { - - transform: function(activity) { - let lang = activity.content.language.replace(/_/g, '-'); +module.exports = { - let statement = new TinCan.Statement({ - - verb: { - id: 'http://adlnet.gov/expapi/verbs/experienced', - display: { - en: 'experienced', - }, + transform: function (activity) { + let statementCfg = xapi.prepareStatement(activity); + statementCfg.verb = { + id: 'http://adlnet.gov/expapi/verbs/experienced', + display: { + en: 'experienced', }, + }; - actor: xapi.actor(activity.user), - - object: { - id: `${Microservices.platform.uri}/${activity.content_kind}/${activity.content_id}`, - definition: { - name: { - [lang]: activity.content.title, - }, - description: { - [lang]: activity.content.description || undefined, - }, - }, - }, - - }); - + let statement = new TinCan.Statement(statementCfg); return statement; }, diff --git a/application/lib/xapiUtil.js b/application/lib/xapiUtil.js index 9cdefdd..8064d83 100644 --- a/application/lib/xapiUtil.js +++ b/application/lib/xapiUtil.js @@ -2,7 +2,16 @@ const Microservices = require('../configs/microservices'); -module.exports = { +const self = module.exports = { + + prepareStatement: function (activity) { + let statementCfg = { + actor: self.actor(activity.user), + object: self.object(activity), + context: self.context(activity) + }; + return statementCfg; + }, actor: function(user) { return { @@ -21,4 +30,43 @@ module.exports = { }; }, + object: function (activity) { + return { + id: `${Microservices.platform.uri}/${activity.content_kind}/${activity.content_id}`, + definition: { + name: { + en: activity.content.title, + }, + description: { + en: activity.content.description || undefined, + }, + type: activity.content_kind === 'deck' ? 'http://id.tincanapi.com/activitytype/slide-deck' : 'http://id.tincanapi.com/activitytype/slide', + }, + }; + }, + + context: function(activity) { + let context = { + language: activity.content.language, + }; + + let tags = activity.content.tags; + if (tags && tags.length > 0) { + let categories = tags.map((tag) => { + return { + id: `${Microservices.platform.uri}/deckfamily/${tag.tagName}`, + objectType: 'Activity', + definition: { + name: { + en: tag.defaultName + }, + type: 'http://id.tincanapi.com/activitytype/tag', + }, + }; + }); + context.contextActivities = {category: categories}; + } + return context; + }, + };