Name

sn_capi.CloudAPIUpdateSetExporter

Description

No description available

Script

var CloudAPIUpdateSetExporter = Class.create();
CloudAPIUpdateSetExporter.prototype = Object.extendsObject(global.CMPExporterUtil, {
  capiObject : '',
  updateSetList : [],
  capiDeletedRecordList:[],
  capiExporterLog: [],
  CAPI_EXPORTER_LABEL: '[CloudAPI Exporter LOG] ',

  initialize: function() {
  	this.updateSetList = [];
  	this.capiDeletedRecordList = [];
  	this.capiExporterLog = [];
  	this.capiObject = '';
  },

  populateEntriesForUpdateSet : function(sysId, tableName) {
  	var recordGR = new GlideRecord(tableName);
  	if(recordGR.get(sysId)) 
  		this.addRecordsToUpdateSetList(recordGR, this.updateSetList);
  },

  initializeUpdateSet: function() {
  	this.exporterlogger.init(this.CAPI_EXPORTER_LABEL, this.capiExporterLog);
  },

  getCloudAPI : function (cloudAPIId) {
  	var grObject;
  	var capiGR = new GlideRecord("sn_capi_cloud_api");
  	if (capiGR.get(cloudAPIId)) {
  		grObject = capiGR;
  		
  		this.exporterlogger.log('Exporting Cloud API - '+capiGR.getValue('cloud_api_name')+' '+capiGR.getValue('version'));
  		this.populateEntriesForUpdateSet(capiGR.sys_id, capiGR.sys_class_name);
  	}
  	return grObject;
  },
  
  createUpdateSet : function(params) {
  	var cloudAPIName = params.capiName;
  	var cloudAPIId = params.id;
  	this.initializeUpdateSet();

  	if (!gs.nil(cloudAPIName) && !gs.nil(cloudAPIId)) {
  		//Cloud API Record
  		this.capiObject = this.getCloudAPI(cloudAPIId);
  		
  		//Cloud API Product and Category
  		this.getCAPIProductAndCategory();

  		//Interface, Operation, Attribute
  		this.getCAPIInterface();

  		//Connector, Endpoint, Endpoint Operation, Endpoint Options
  		this.getConnector();

  		//Cloud API Method Mapper and Parameter Mapper
  		this.getCAPIMethodMappers(cloudAPIId);
  		this.getCAPIConfigOverrides(cloudAPIId);

  		//Add Deleted records
  		this.getAllDeletedRecordsFromCAPIChildTables(cloudAPIId);
  		
  		//1 is for Basic and 2 is for Advance
  		if (params.exportType == '2') {
  			if (params.selectedScripts) {
  				var selectedScripts = JSON.parse(params.selectedScripts);
  				
  				var selectedMIDScriptFileIds = [];
  				if (selectedScripts.midServerScriptFiles) {
  					selectedMIDScriptFileIds =  selectedScripts.midServerScriptFiles.map(function(obj) {
  						return obj.sys_id;
  					});
  					
  					if (selectedMIDScriptFileIds.length > 0)
  						this._addMIDScriptRecordsToUpdateSet(selectedMIDScriptFileIds, 'ecc_agent_script_file');
  				}
  				
  				var selectedMIDScriptIncludeIds = [];
  				if (selectedScripts.midServerScriptIncludes) {
  					selectedMIDScriptIncludeIds = selectedScripts.midServerScriptIncludes.map(function(obj){
  						return obj.sys_id;
  					});
  					
  					if (selectedMIDScriptIncludeIds.length > 0)
  						this._addMIDScriptRecordsToUpdateSet(selectedMIDScriptIncludeIds, 'ecc_agent_script_include');
  				}
  			}	
  		}
  		var output = this.generateUpdateSet(cloudAPIName, this.updateSetList, this.capiDeletedRecordList);
  		output.updateSetXMLIdList = output.sysIdList;
  		output.log = this.capiExporterLog;
  		return output;
  	}
  },
  
  getAllDeletedRecordsFromCAPIChildTables : function (cloudAPIId) {
  	var capiChildTables = ["sn_capi_product","sn_capi_provider","sn_capi_provider_property", "sn_capi_interface","sn_capi_connector","sn_capi_method_mapper","sn_capi_config_overrides"];

  	for (var i in capiChildTables){
  		this.addDeletedRecordsToUpdateSet(cloudAPIId,capiChildTables[i]);
  	}
  },
  
  getCAPIProduct : function(capiProduct){
  	//product
  	var capiProductGR = new GlideRecord("sn_capi_product");
  	capiProductGR.addQuery("sys_id", capiProduct);
  	capiProductGR.query();

  	if (capiProductGR.next()) {
  		this.exporterlogger.log('Exporting Cloud API Product - '+capiProductGR.name);
  		this.populateEntriesForUpdateSet(capiProductGR.sys_id, capiProductGR.sys_class_name);
  	}
  },

  getCAPIProductAndCategory : function () {
  	if (this.capiObject) {
  		//provider
  		var capiProviderGR = new GlideRecord("sn_capi_provider");
  		if (capiProviderGR.get(this.capiObject.provider.provider)) {
  			this.exporterlogger.log('Exporting Cloud API Provider - '+capiProviderGR.name);
  			this.populateEntriesForUpdateSet(capiProviderGR.sys_id, capiProviderGR.sys_class_name);
  		}
  		
  		this.getCAPIProduct(this.capiObject.provider);

  		//category
  		var capiCategoryGR = new GlideRecord("sn_capi_service_category");
  		if (capiCategoryGR.get(this.capiObject.category)) {
  			this.exporterlogger.log('Exporting Cloud API Category - '+capiCategoryGR.name);
  			this.populateEntriesForUpdateSet(capiCategoryGR.sys_id, capiCategoryGR.sys_class_name);
  		}
  		
  		//provider properties
  		var capiProviderPropertyGR = new GlideRecord("sn_capi_provider_property");
  		capiProviderPropertyGR.addQuery("provider", this.capiObject.provider.provider);
  		capiProviderPropertyGR.query();
  		while (capiProviderPropertyGR.next()) {
  			this.exporterlogger.log('Exporting Cloud API Provider Property - '+capiProviderPropertyGR.key);
  			this.populateEntriesForUpdateSet(capiProviderPropertyGR.sys_id, capiProviderPropertyGR.sys_class_name);
  		}
  	}
  },

  getCAPIInterface : function () {
  	if (this.capiObject) {
  		var capiInterfaceGR = new GlideRecord("sn_capi_interface");

  		if (capiInterfaceGR.get(this.capiObject.cloud_api_interface)){
  			this.exporterlogger.log('Exporting Cloud API Interface - '+capiInterfaceGR.interface_name);
  			this.populateEntriesForUpdateSet(capiInterfaceGR.sys_id, capiInterfaceGR.sys_class_name);
  		}

  		this.getCAPIInterfaceOperations(this.capiObject.cloud_api_interface);
  		this.addDeletedRecordsToUpdateSet(this.capiObject.cloud_api_interface,'sn_capi_interface_operation');
  	}
  },

  getCAPIInterfaceOperations : function (capiInterface) {
  	var capiInterfaceOperationGR = new GlideRecord("sn_capi_interface_operation");
  	capiInterfaceOperationGR.addQuery("cloud_api_interface", capiInterface);
  	capiInterfaceOperationGR.query();

  	while (capiInterfaceOperationGR.next()) {
  		this.exporterlogger.log('Exporting Cloud API Interface Operation - '+capiInterfaceOperationGR.operation_name);
  		this.populateEntriesForUpdateSet(capiInterfaceOperationGR.sys_id, capiInterfaceOperationGR.sys_class_name);

  		this.getCAPIInterfaceOperationAttributes(capiInterfaceOperationGR);
  		this.addDeletedRecordsToUpdateSet(capiInterfaceOperationGR.sys_id,'sn_capi_interface_op_parameter');
  	}
  },

  getCAPIInterfaceOperationAttributes : function (capiInterfaceOperationGR) {
  	var capiInterfaceOpAttributeGR = new GlideRecord("sn_capi_interface_op_parameter");
  	capiInterfaceOpAttributeGR.addQuery("capi_interface_operation", capiInterfaceOperationGR.sys_id);
  	capiInterfaceOpAttributeGR.query();

  	while (capiInterfaceOpAttributeGR.next()) {
  		this.exporterlogger.log('Exporting Cloud API Interface Operation Attribute - '+capiInterfaceOpAttributeGR.parameter_name);
  		this.populateEntriesForUpdateSet(capiInterfaceOpAttributeGR.sys_id, capiInterfaceOpAttributeGR.sys_class_name);
  	}
  },

  getConnector : function () {
  	if (this.capiObject) {
  		//connector type
  		this.getCAPIConnectorType(this.capiObject.connector);

  		//connector
  		var capiConnectorGR = new GlideRecord("sn_capi_connector");
  		if (capiConnectorGR.get(this.capiObject.connector)) {
  			this.exporterlogger.log('Exporting Cloud API Connector - '+capiConnectorGR.connector_name);
  			this.populateEntriesForUpdateSet(capiConnectorGR.sys_id, capiConnectorGR.sys_class_name);
  		}

  		//endpoint
  		this.getCAPIEndpoint(this.capiObject.connector);
  		this.addDeletedRecordsToUpdateSet(this.capiObject.connector,'sn_capi_endpoint');
  	}
  },

  getCAPIConnectorType : function (connector) {
  	var capiConnectorGR = new GlideRecord("sn_capi_connector");

  	if (capiConnectorGR.get(connector)) {
  		var connectorTypeGR = new GlideRecord("sn_capi_connector_type");
  		connectorTypeGR.addQuery("sys_id", capiConnectorGR.connector_type);
  		connectorTypeGR.query();

  		if (connectorTypeGR.next()) {
  			this.exporterlogger.log('Exporting Cloud API Connector Type - '+connectorTypeGR.connector_type_name);
  			this.populateEntriesForUpdateSet(connectorTypeGR.sys_id, connectorTypeGR.sys_class_name);
  		}
  	}
  },

  getCAPIEndpoint : function (connector) {
  	var capiEndpointGR = new GlideRecord("sn_capi_endpoint");
  	capiEndpointGR.addQuery("connector", connector);
  	capiEndpointGR.query();

  	while (capiEndpointGR.next()) {
  		this.exporterlogger.log('Exporting Cloud API Connector Endpoint - '+capiEndpointGR.endpoint_name);
  		this.populateEntriesForUpdateSet(capiEndpointGR.sys_id, capiEndpointGR.sys_class_name);

  		//endpoint operations
  		this.getCAPIEndpointOperations(capiEndpointGR);
  		this.addDeletedRecordsToUpdateSet(capiEndpointGR.sys_id,'sn_capi_endpoint_operation');
  	}
  },

  getCAPIEndpointOperations : function (capiEndpointGR) {
  	//endpoint direction
  	this.getEndpointDirection(capiEndpointGR.sys_id);

  	var capiEndpointOperationGR = new GlideRecord("sn_capi_endpoint_operation");
  	capiEndpointOperationGR.addQuery("endpoint", capiEndpointGR.sys_id);
  	capiEndpointOperationGR.query();

  	while (capiEndpointOperationGR.next()) {
  		this.exporterlogger.log('Exporting Cloud API Connector Endpoint Operations - '+capiEndpointOperationGR.operation_name);
  		this.populateEntriesForUpdateSet(capiEndpointOperationGR.sys_id, capiEndpointOperationGR.sys_class_name);

  		this.getCAPIEndpointOperationAttributes(capiEndpointOperationGR);
  		this.addDeletedRecordsToUpdateSet(capiEndpointOperationGR.sys_id,'sn_capi_endpoint_op_parameter');
  	}

  	//config parameters
  	this.getEndpointConfigParameters(capiEndpointGR.sys_id);
  	this.addDeletedRecordsToUpdateSet(this.capiObject.getValue('sys_id'),'sn_capi_config_parameter');
  },

  getEndpointDirection : function (endpoint) {
  	var capiEndpointGR = new GlideRecord("sn_capi_endpoint");

  	if (capiEndpointGR.get(endpoint)) {
  		var endpointDirectionGR = new GlideRecord("sn_capi_endpoint_direction");
  		endpointDirectionGR.addQuery("sys_id", capiEndpointGR.direction);
  		endpointDirectionGR.query();

  		if (endpointDirectionGR.next()) {
  			this.exporterlogger.log('Exporting Cloud API Endpoint Direction - '+ endpointDirectionGR.direction_name);
  			this.populateEntriesForUpdateSet(endpointDirectionGR.sys_id, endpointDirectionGR.sys_class_name);
  		}
  	}
  },

  getCAPIEndpointOperationAttributes : function (capiEndpointOperationGR) {
  	var capiEndpointOpAttributeGR = new GlideRecord("sn_capi_endpoint_op_parameter");
  	capiEndpointOpAttributeGR.addQuery("endpoint_operation", capiEndpointOperationGR.sys_id);
  	capiEndpointOpAttributeGR.query();

  	while (capiEndpointOpAttributeGR.next()) {
  		this.exporterlogger.log('Exporting Cloud API Endpoint Operation Attribute - ' + capiEndpointOpAttributeGR.parameter_name);
  		this.populateEntriesForUpdateSet(capiEndpointOpAttributeGR.sys_id, capiEndpointOpAttributeGR.sys_class_name);
  	}
  },

  getEndpointConfigParameters : function (endpoint){
  	var capiConfigParameterGR = new GlideRecord("sn_capi_config_parameter");
  	capiConfigParameterGR.addQuery("endpoint", endpoint);
  	capiConfigParameterGR.query();

  	while (capiConfigParameterGR.next()) {
  		this.exporterlogger.log('Exporting Cloud API Connector Endpoint Config Parameter - '+ capiConfigParameterGR.config_parameter_name);
  		this.populateEntriesForUpdateSet(capiConfigParameterGR.sys_id, capiConfigParameterGR.sys_class_name);
  	}
  },

  getCAPIMethodMappers : function (cloudAPIId) {
  	var capiMethodMapperGR = new GlideRecord("sn_capi_method_mapper");
  	capiMethodMapperGR.addQuery("cloud_api", cloudAPIId);
  	capiMethodMapperGR.query();

  	while (capiMethodMapperGR.next()) {
  		this.populateEntriesForUpdateSet(capiMethodMapperGR.sys_id, capiMethodMapperGR.sys_class_name);

  		//parameter mappers
  		this.getCAPIParameterMappers(capiMethodMapperGR);
  		this.addDeletedRecordsToUpdateSet(cloudAPIId,'sn_capi_parameter_mapper');
  		this.addDeletedRecordsToUpdateSet(cloudAPIId,'sn_capi_response_processor');
  	}
  },

  getCAPIParameterMappers : function (capiMethodMapperGR) {
  		//parameter mappers
  		var capiParameterMapperGR = new GlideRecord("sn_capi_parameter_mapper");
  		capiParameterMapperGR.addQuery("capi_method_mapper", capiMethodMapperGR.sys_id);
  		capiParameterMapperGR.query();

  		while (capiParameterMapperGR.next()) {
  			this.exporterlogger.log('Exporting Cloud API Parameter Mapper - ' + capiParameterMapperGR.endpoint_operation_parameter);
  			this.populateEntriesForUpdateSet(capiParameterMapperGR.sys_id, capiParameterMapperGR.sys_class_name);
  		}

  		//Response Processors
  		var capiResponseProcessorGR = new GlideRecord("sn_capi_response_processor");
  		capiResponseProcessorGR.addQuery("capi_method_mapper", capiMethodMapperGR.sys_id);
  		capiResponseProcessorGR.query();

  		while (capiResponseProcessorGR.next()) {
  			this.exporterlogger.log('Exporting Method Mapper Response Processor - ' + capiResponseProcessorGR.processor_name);
  			this.populateEntriesForUpdateSet(capiResponseProcessorGR.sys_id, capiResponseProcessorGR.sys_class_name);
  		}

  		//Request Scripts. Find the script type and retrieve the appropriate script based on the script type.
  		if (capiMethodMapperGR.script_table) {
  			var requestScriptGR = new GlideRecord(capiMethodMapperGR.script_table);
  			requestScriptGR.addQuery("sys_id", capiMethodMapperGR.request_script);
  			requestScriptGR.query();

  			while (requestScriptGR.next()) {
  				this.exporterlogger.log('Export Cloud API Request Script - ' + requestScriptGR.name);
  				this.populateEntriesForUpdateSet(requestScriptGR.sys_id, requestScriptGR.sys_class_name);
  			}
  		}
  },

  getCAPIConfigOverrides : function (cloudAPIId) {
  	var capiConfigOverrideGR = new GlideRecord("sn_capi_config_overrides");
  	capiConfigOverrideGR.addQuery("cloud_api", cloudAPIId);
  	capiConfigOverrideGR.query();

  	while (capiConfigOverrideGR.next()) {
  		this.populateEntriesForUpdateSet(capiConfigOverrideGR.sys_id, capiConfigOverrideGR.sys_class_name);
  		var capiConfigOverrideParamGR = new GlideRecord("sn_capi_config_parameter");
  		capiConfigOverrideParamGR.query();
  		while(capiConfigOverrideParamGR.next()){
  			if(capiConfigOverrideParamGR.sys_id == capiConfigOverrideGR.config_parameter){
  				this.exporterlogger.log('Exporting Cloud API Config Override Parameter - ' + capiConfigOverrideParamGR.config_parameter_name);
  				this.populateEntriesForUpdateSet(capiConfigOverrideParamGR.sys_id, capiConfigOverrideParamGR.sys_class_name);

  			}
  		}
  	}
  },
  
  _addMIDScriptRecordsToUpdateSet: function(sysIdList, table) {
  	this.exporterlogger.log('Exporting selected scripts form table ' + table);
  	var midScriptGr = new GlideRecord(table);
  	midScriptGr.addQuery("sys_id", 'IN', sysIdList);
  	midScriptGr.query();

  	while (midScriptGr.next()) {
  		this.populateEntriesForUpdateSet(midScriptGr.sys_id, midScriptGr.sys_class_name);
  	}
  },

  getMIDScriptRecord : function (midServerScript) {
  	this.exporterlogger.log('Export MID Script');
  	var midScript = new GlideRecord(midServerScript.table);
  	midScript.addQuery("sys_id", midServerScript.sys_id);
  	midScript.query();

  	while (midScript.next()) {
  		this.populateEntriesForUpdateSet(midScript.sys_id, midScript.sys_class_name);
  	}
  },
  
  addDeletedRecordsToUpdateSet : function(parentSysId,childTableName) {
     this.addDeletedRecordsXMLToUpdateSet(parentSysId,childTableName,this.capiDeletedRecordList);
  },
  
  type: 'CloudAPIUpdateSetExporter'
});

Sys ID

d6ff23a90b230300bd20812f15673a55

Offical Documentation

Official Docs: