Hello All,
Here is a requireJS module for invoking various Foundry services from an Iris application. This helps in performing all Foundry integrations from one place in an Iris application rather than having at multiple places in the Iris application.
In this requireJS module there are four functions,
- invokeIdentityService: In this function is responsible for invoking Foundry identity services.
- invokeIntegrationService: In this function is responsible for invoking Foundry integration services.
- invokeOrchestrationService: This function is responsible for invoking Foundry orchestration services.
- invokeObjectService: This function is responsible for invoking Foundry object services.
foundryIntegrationJS.js requireJS module:
define(['progressIndicatorJS'], function (progressIndicatorJS) {
successCallback = null;
failureCallback = null;
invokeIdentityService = function (serviceName, inputParameters, successCallback, failureCallback) {
voltmx.print("### Entering into invokeIdentityService ###");
voltmx.print("### ServiceName : "+serviceName+" \n inputParameters : "+JSON.stringify(inputParameters)+" ###");
this.successCallback = successCallback;
this.failureCallback = failureCallback;
let sdkDefaultInstance = voltmx.sdk.getDefaultInstance();
let idenityService = sdkDefaultInstance.getIdentityService(serviceName);
progressIndicatorJS.showProgressIndicator("Service call in progress");
idenityService.login(inputParameters, successCallbackHandler.bind(this), failureCallbackHandler.bind(this));
voltmx.print("### Exiting out of invokeIdentityService ###");
};
invokeIntegrationService = function (serviceName, operationName, headersParameters, inputParameters, successCallback, failureCallback) {
voltmx.print("### Entering into invokeIntegrationService ###");
voltmx.print("### ServiceName : "+serviceName+" \n operationName : "+operationName+" \n headersParameters : "+JSON.stringify(headersParameters)+" \n inputParameters : "+JSON.stringify(inputParameters)+" ###");
this.successCallback = successCallback;
this.failureCallback = failureCallback;
var sdkDefaultInstance = voltmx.sdk.getDefaultInstance();
var integrationService = sdkDefaultInstance.getIntegrationService(serviceName);
progressIndicatorJS.showProgressIndicator("Service call in progress");
integrationService.invokeOperation(operationName,
headersParameters,
inputParameters,
successCallbackHandler.bind(this),
failureCallbackHandler.bind(this));
voltmx.print("### Exiting out of invokeIntegrationService ###");
};
invokeOrchestrationService = function (serviceName, operationName, headerParameters, inputParameters, successCallback, failureCallback) {
voltmx.print("### Entering into invokeOrchestrationService ###");
voltmx.print("### serviceName : "+serviceName+" \n operationName : "+operationName+" \n headerParameters : "+JSON.stringify(headerParameters)+" \n inputParameters : "+JSON.stringify(inputParameters)+" ###");
this.successCallback = successCallback;
this.failureCallback = failureCallback;
var sdkDefaultInstance = voltmx.sdk.getDefaultInstance();
var orchestrationService = sdkDefaultInstance.getIntegrationService(serviceName);
progressIndicatorJS.showProgressIndicator("Service call in progress");
orchestrationService.invokeOperation(operationName,
headerParameters,
inputParameters,
successCallbackHandler.bind(this),
failureCallbackHandler.bind(this));
voltmx.print("### Exiting out of invokeOrchestrationService ###");
};
invokeObjectService = function (serviceName, objectName, operationName, headerParameters, inputParameters, successCallback, failureCallback) {
voltmx.print("### Entering into invokeObjectService ###");
voltmx.print("### serviceName : "+serviceName+" \n objectName : "+objectName+" \n operationName : "+operationName+" \n headerParameters : "+JSON.stringify(headerParameters)+" \n inputParameters : "+JSON.stringify(inputParameters)+" ###");
this.successCallback = successCallback;
this.failureCallback = failureCallback;
var sdkDefaultInstance = voltmx.sdk.getDefaultInstance();
var objectService = sdkDefaultInstance.getObjectService(serviceName);
var dataObject = new voltmx.sdk.dto.DataObject(objectName);
dataObject.addField(inputParameters[0][0],inputParameters[0][1]);
var options = {"dataObject":dataObject};
progressIndicatorJS.showProgressIndicator("Service call in progress");
objectService.customVerb(operationName,
options,
successCallbackHandler.bind(this),
failureCallbackHandler.bind(this));
voltmx.print("### Exiting out of invokeObjectService ###");
};
successCallbackHandler = function (successResponse) {
voltmx.print("### Entering into successCallbackHandler ###");
voltmx.print("successResponse : "+JSON.stringify(successResponse));
progressIndicatorJS.dismissLoadingIndicator();
if (checkFoundryOpstatus(successResponse)) {
this.successCallback(successResponse);
}
voltmx.print("### Exiting out of successCallbackHandler ###");
};
failureCallbackHandler = function (failureResponse) {
voltmx.print("### Entering into failureCallbackHandler ###");
voltmx.print("failureResponse : "+JSON.stringify(failureResponse));
progressIndicatorJS.dismissLoadingIndicator();
if (checkFoundryOpstatus(failureResponse)) {
this.failureCallback(failureResponse);
}
voltmx.print("### Exiting out of failureCallbackHandler ###");
};
checkFoundryOpstatus = function (foundryResponse) {
voltmx.print("### Entering into invokeObjectService ###");
if (null === foundryResponse.opstatus ||
undefined === foundryResponse.opstatus) {
return true;
} else if (foundryResponse.opstatus === 0) {
return true;
} else{
handleFoundryErrors(foundryResponse);
return false;
}
voltmx.print("### Exiting out of invokeObjectService ###");
};
handleFoundryErrors = function (foundryResponse) {
voltmx.print("### Entering into handleFoundryErrors ###");
voltmx.print("### Error occured in Foundry : "+JSON.stringify(foundryResponse)+" ###");
voltmx.print("### Exiting out of handleFoundryErrors ###");
};
return {
invokeIdentityService : this.invokeIdentityService,
invokeIntegrationService : this.invokeIntegrationService,
invokeOrchestrationService : this.invokeOrchestrationService,
invokeObjectService : this.invokeObjectService
};
});
How to use this foundryIntegrationJS.js requireJS module from a form controller where we want to invoke Foundry services?
Change the form controller code structure as shown below. This adds the “foundryIntegrationJS.js” requireJS module as a dependency to the form controller and ensures that the foundryIntegrationJS.js file is loaded into memory before the form controller is loaded. Then we can use the functions present in “foundryIntegrationJS.js” requireJS module from the form controller.
define(['foundryIntegrationJS'], function (foundryIntegrationJS) {
login = function () {
foundryIntegrationJS.invokeIdentityService("MyUserRepoIdentiyService",
{"userid":"myuser@hcl.com","password":"Volt@1234"},
function () {alert("Login Success");},
function () {alert("Login Failed");}
);
};
getNewsFromIntegrationService = function () {
foundryIntegrationJS.invokeIntegrationService("NYTNewsFeed",
"getNews",
{},
{"newsType":"World"},
function (news) {alert(JSON.stringify(news));},
function (error) {alert(JSON.stringify(error));}
);
};
getWeatherDetailsFromOrchestrationService = function () {
foundryIntegrationJS.invokeOrchestrationService("WeatherServices",
"getWeatherByLocation",
{},
{"lat":"47.60799140597074", "lon":"-122.3389692401529"},
function (weather) {alert(JSON.stringify(weather));},
function (error) {alert(JSON.stringify(error));}
);
};
getNewsFromObjectService = function () {
foundryIntegrationJS.invokeObjectService("MyNewsService",
"channel",
"getNews",
{},
[["newsType","World"]],
function (news) {alert(JSON.stringify(news));},
function (error) {alert(JSON.stringify(error));}
);
};
return {
login : this.login,
getNewsFromIntegrationService : this.getNewsFromIntegrationService,
getNewsFromObjectService : this.getNewsFromObjectService,
getWeatherDetailsFromOrchestrationService : this.getWeatherDetailsFromOrchestrationService
};
});
Attached “FoundryServicesInvocationUsingARequireJSModule.zip” zip file contains three JavaScript files.
- foundryIntegrationJS.js : RequireJS module having functions to invoke various Foundry services.
- Form3Controller.js : A form controller using functions from foundryIntegrationJS.js requireJS module.
- progressIndicatorJS.js : A requireJS module used in foundryIntegrationJS.js
Thanks and Regards,
Venkata Raju Bankapalli