Last active
April 27, 2017 04:39
-
-
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
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
{ | |
displayName: 'Genders', | |
choices: | |
[ { value: 'Female', displayName: 'Female' }, | |
{ value: 'Male', displayName: 'Male' }, | |
{ value: 'Other', displayName: 'Other' } ], | |
} |
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
// 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); |
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
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 | |
} |
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
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')); | |
}); |
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
{ | |
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' | |
} | |
} |
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
{ | |
externalDataIdentifier: 'NodeEDS', | |
properties: [ | |
{ | |
symbolicName: 'TST_ExternalProperty1', | |
value: 'Sat Apr 08 2017', | |
displayMode: 'readonly' | |
} | |
] | |
} |
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
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