Name
sn_mab_api.ConfigResponse
Description
Used to store the output of the ConfigRetrievalService
Script
var ConfigResponse = Class.create();
ConfigResponse.prototype = {
initialize: function(externalNodes) {
this.nodes = {};
this.nodeLinks = [];
this.alerts = [];
this.errorHandler = new sn_mab_api.ErrorHandler();
this.externalParentNodes = externalNodes;
this.floorNodes = [];
},
addConfigNode: function(tableName, sysId, configNode) {
if (!tableName || !sysId || !configNode)
return;
if (this.exists(tableName, sysId, configNode))
this.errorHandler.throwInternalError('Configuration Node already exists in response: ' + tableName + ', id: ' + sysId);
var tableEntries = this.nodes[tableName];
if (!tableEntries) {
tableEntries = {};
this.nodes[tableName] = tableEntries;
}
tableEntries[sysId] = configNode;
},
exists: function(tableName, sysId) {
return (this.nodes[tableName] && this.nodes[tableName][sysId]) ? true : false;
},
preSerialize: function() {
delete this.externalParentNodes; // avoid serialization
delete this.errorHandler;
},
existsInNodeList: function(tableName, sysId, nodeList) {
if (!nodeList)
return false;
for (var i = 0; i < nodeList.length; i++) {
var node = nodeList[i];
if (sysId === node.sys_id && tableName === node.sys_class_name)
return true;
}
return false;
},
getConfigNode: function(tableName, sysId) {
return this.nodes[tableName] ? this.nodes[tableName][sysId] : undefined;
},
// If nodes is null, we will consider this ConfigResponse as empty.
isEmpty: function() {
return !this.nodes || this.nodes.length === 0;
},
validateNodeLinkParent: function(parentNodeTableName, parentNodeSysId) {
if (!this.exists(parentNodeTableName, parentNodeSysId)) {
// parent node may be provided by the externalParentNodes data during a partial tree retrieval
if (!this.existsInNodeList(parentNodeTableName, parentNodeSysId, this.externalParentNodes)){
this.errorHandler.throwInternalError('Trying to add node link to non existent node: ' + parentNodeTableName + ', id: ' + parentNodeSysId);
}
}
},
validateStandardNodeLink: function(parentNodeTableName, parentNodeSysId, childNodeTableName, childNodeSysId) {
this.validateNodeLinkParent(parentNodeTableName, parentNodeSysId);
if (!this.exists(childNodeTableName, childNodeSysId)){
this.errorHandler.throwInternalError('Trying to add node link to non existent node: ' + childNodeTableName + ', id: ' + childNodeSysId);
}
if (this.nodeLinkExists(parentNodeTableName, parentNodeSysId, childNodeTableName, childNodeSysId))
return false;
return true;
},
addAlert: function(alert) {
this.alerts.push(alert);
},
validateAndAddNodeLink: function(parentNodeTableName, parentNodeSysId, childNodeTableName, childNodeSysId, isFloor) {
var validNodeLink = this.validateStandardNodeLink(parentNodeTableName, parentNodeSysId, childNodeTableName, childNodeSysId);
if(validNodeLink)
this.addNodeLink(parentNodeTableName, parentNodeSysId, childNodeTableName, childNodeSysId, isFloor);
},
addNodeLink: function(parentNodeTableName, parentNodeSysId, childNodeTableName, childNodeSysId, isFloor) {
if (isFloor === undefined)
isFloor = false;
this.nodeLinks.push({
'parentNode': {
'tableName': parentNodeTableName,
'sysId': parentNodeSysId
},
'childNode': {
'isFloor': isFloor,
'tableName': childNodeTableName,
'sysId': childNodeSysId
}
});
},
addFloorNode: function(parentNodeTableName, parentNodeSysId, childNodeTableName, childNodeSysId) {
if (this.floorNodes.length > 0) {
for (var i = 0; i < this.floorNodes.length; i++) {
var currentNode = this.floorNodes[i];
if (currentNode['parentNode']['tableName'] === parentNodeTableName &&
currentNode['parentNode']['sysId'] === parentNodeSysId) {
currentNode['childNodes'].push(
{'tableName': childNodeTableName, 'sysId': childNodeSysId}
);
return;
}
}
this.floorNodes.push(this.createFloorNode(parentNodeTableName, parentNodeSysId, childNodeTableName, childNodeSysId));
} else {
this.floorNodes.push(this.createFloorNode(parentNodeTableName, parentNodeSysId, childNodeTableName, childNodeSysId));
}
},
createFloorNode: function(parentNodeTableName, parentNodeSysId, childNodeTableName, childNodeSysId) {
return {
'parentNode': {
'tableName': parentNodeTableName,
'sysId': parentNodeSysId
},
'childNodes': [{
'tableName': childNodeTableName,
'sysId': childNodeSysId
}]
};
},
nodeLinkExists: function(parentNodeTableName, parentNodeSysId, childNodeTableName, childNodeSysId) {
var linkExists;
this.nodeLinks.forEach(function(currLink) {
if (linkExists)
return;
if (currLink.parentNode.tableName == parentNodeTableName && currLink.parentNode.sysId == parentNodeSysId &&
currLink.childNode.tableName == childNodeTableName && currLink.childNode.sysId == childNodeSysId)
linkExists = true;
});
return linkExists;
},
type: 'ConfigResponse'
};
Sys ID
5db508a753222010c722ddeeff7b1241