Skip to content

Instantly share code, notes, and snippets.

@rickx1
Last active April 27, 2017 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rickx1/1c3490e4e6f8a13a7b65da4f5b5aeaba to your computer and use it in GitHub Desktop.
Save rickx1/1c3490e4e6f8a13a7b65da4f5b5aeaba to your computer and use it in GitHub Desktop.
This is an example of an External Data Service Implementation for IBM Case Manager using Node.js
{
displayName: 'Genders',
choices:
[ { value: 'Female', displayName: 'Female' },
{ value: 'Male', displayName: 'Male' },
{ value: 'Other', displayName: 'Other' } ],
}
// Add this at the top of your file, with the rest of the requires:
var choicelist = require("./choicelist.js")
// Add this to your implementation:
var genders = choicelist.create("Genders");
// Add each value to the list
choicelist.addChoice(genders, "Female", "Female"); // Display name is optional
choicelist.addChoice(genders, "Male");
choicelist.addChoice(genders, "Other");
// Or add them all at once
choicelist.addChoices(genders, ["Female", "Male", "Other"] );
// And attach the choice list to the property
property.choiceList = genders;
dataResponse.properties.push(property);
var create = (displayName) => {
return {
displayName,
choices: []
}
}
var addChoice = (choiceList, value, displayName) => {
choiceList.choices.push(
{
value,
displayName: displayName || value
});
}
var addChoices = (choiceList, values) => {
values.forEach( (value) => addChoice(choiceList, value) );
}
module.exports = {
create,
addChoice,
addChoices
}
var express = require('express')
, bodyParser = require('body-parser')
, _= require("underscore")
, http = require('http')
, morgan = require('morgan');
var jsonParser = bodyParser.json();
var app = express();
app.use(morgan("dev")); // Change this for production code
app.set('port', process.env.PORT || 3000);
app.post('/type/:objectType', jsonParser, function(req, res) {
console.log(req.body); // Remove this for production code
var dataResponse = {
"externalDataIdentifier": "Node EDS",
"properties" : [ ]
};
// Add your implementation code here
console.log(dataResponse); // Remove this for production code
res.json(dataResponse);
});
function getProperty(req, name) {
return _.findWhere(req.body.properties, {"symbolicName" : name} );
}
http.createServer(app).listen(app.get('port'), function(){
console.log('Node EDS server listening on port ' + app.get('port'));
});
{
repositoryId: 'TARGET',
requestMode: 'initialNewObject',
properties: [
{
symbolicName: 'Creator',
value: null
},
{
symbolicName: 'DateCreated',
value: null
},
// A lot more system properties...
{
symbolicName: 'TST_TestProp',
value: null
},
{
symbolicName: 'TST_ExternalProperty1',
value: null
}],
clientContext: {
currentSolution: 'TestSolution',
role: 'TestRole'
}
}
{
externalDataIdentifier: 'NodeEDS',
properties: [
{
symbolicName: 'TST_ExternalProperty1',
value: 'Sat Apr 08 2017',
displayMode: 'readonly'
}
]
}
var dataResponse = {
"externalDataIdentifier": "Node EDS",
"properties" : []
};
var property = getProperty(req, "TST_ExternalProperty1");
if (property) {
property.value = (new Date()).toDateString();
property.displayMode = "readonly";
dataResponse.properties.push(property);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment