Name

global.DownloadPatternsEntities

Description

No description available

Script

var DownloadPatternsEntities = Class.create();
DownloadPatternsEntities.prototype = {
  
  exporterlogger: {
      
      init: function() {
          this.exportlog = '';
      },
      
      log: function(logMessage) {
          var formattedMsg = 'LOG: ' + logMessage + '\n';
          this.exportlog = this.exportlog + formattedMsg; 
      },
      error: function(errorMessage){
          var formattedMsg = 'ERROR: ' + errorMessage + '\n';   
          this.exportlog = this.exportlog + formattedMsg; 
      },
      
      getLog: function(){
          return this.exportlog;
      }
      
  }, 
  
  initialize: function() {
  	this.tracker = SNC.GlideExecutionTracker.getLastRunning();
  	this.exporterlogger.init();
  	this.numberOfSteps = 19;
  	this.currentStep = 0;
  },
  
  process : function(patternList) {
  	var self = this;
  	
  	if (this.isSharedLibraryInList(patternList)){
  		this.exporterlogger.error("Cannot download Shared Libraries content. Select only Patterns that are not of Shared Library type");
  		this.tracker.fail("Cannot download Shared Libraries content. Select only Patterns that are not of Shared Library type");
  		this.tracker.updateResult(
  			{
  				log: self.exporterlogger.getLog()
  			});
  		return;
  	}
  	
  	try{
  		var arrPatternList = patternList.split(',');
  		this.pattRelatedItems = new PatternRelatedItems(arrPatternList);

  		var arrPatternsFilenames = this.pattRelatedItems.getFilenames('sa_pattern', arrPatternList);
  		this.exporterlogger.log("Got Patterns = " + JSON.stringify(arrPatternsFilenames));

  		this.exporterlogger.log("Getting basic data");
  		var arrBasic = this.getBasicPatternData();
  		this.exporterlogger.log("Getting advance data");
  		var arrAdvance = this.getAdvancePatternData();
  		this.exporterlogger.log("Getting large payload data");
  		var arrLargePayload = this.getLargePayloadPatternData();

  		var arrAllEntities = arrBasic.concat(arrAdvance,arrPatternsFilenames,arrLargePayload);
  		var numOfFiles = arrAllEntities.length;

  		this.exporterlogger.log("Finished collecting all entities (Got: " + numOfFiles + " files), now compressing to a ZIP file.");
  		this.tracker.success('success');
  		this.tracker.updateResult(
  			{
  				entities_ids: arrAllEntities.join(','),
  				log: self.exporterlogger.getLog()
  			});
  	} catch (e) {
  		var msg = "Something went wrong: ";
  		if (e.message)
  			msg += e.message;
  		if (e.stack)
  			msg += "\nStack:\n" + e.stack;
  		
  		this.exporterlogger.error(msg);
  		this.tracker.fail(msg);
  		this.tracker.updateResult(
  			{
  				log: self.exporterlogger.getLog()
  			});
  	}
  },
  
  isSharedLibraryInList : function (patternList){
  	var gr = new GlideRecord('sa_pattern');
  	gr.addQuery('cpattern_type', 2);
  	gr.addQuery('sys_id', 'IN', patternList);
  	gr.query();
  	if (gr.hasNext())
  		return true;
  	
  	return false;
  },
  
  getBasicPatternData : function() {
  	var arrLibs = this.pattRelatedItems.getSharedLibrariesFilenames();
  	this.exporterlogger.log("Got shared libraries for pattern = " + JSON.stringify(arrLibs));
  	this.incrementPercent();
  	
  	var arrExtensions = this.pattRelatedItems.getExtensionRecordsFilenames();
  	this.exporterlogger.log("Got Extension sections = " + JSON.stringify(arrExtensions));
  	this.incrementPercent();
  	
  	var arrCiToPattern = this.pattRelatedItems.getCiToPatternFiles();
  	this.exporterlogger.log("Got CIs to pattern = " + JSON.stringify(arrCiToPattern));
  	this.incrementPercent();
  	
  	var arrPrePost = this.pattRelatedItems.getPrePostRecordsFilenames();
  	this.exporterlogger.log("Got PrePost scripts = " + JSON.stringify(arrPrePost));
  	this.incrementPercent();
  	
  	var arrTriggerProbes = this.pattRelatedItems.getTriggerProbesFilenames();
  	this.exporterlogger.log("Got Trigger Probes = " + JSON.stringify(arrTriggerProbes));
  	this.incrementPercent();
  	
  	var arrDiscoClassy = this.pattRelatedItems.getDiscoveryClassyForTriggerProbesFilenames();
  	this.exporterlogger.log("Got Discovery Classy = " + JSON.stringify(arrDiscoClassy));
  	this.incrementPercent();
  	
  	var arrTrackedFiles = this.pattRelatedItems.getTrackedFileDefintionsFilenames();
  	this.exporterlogger.log("Got Track Definition files = " + JSON.stringify(arrTrackedFiles));
  	this.incrementPercent();
  	
  	var arrCustoms = this.pattRelatedItems.getCustomOperationsParsingStrategiesFilenames();
  	this.exporterlogger.log("Got Custom Operations, Strategies and Parameters = " + JSON.stringify(arrCustoms));
  	this.incrementPercent();
  	
  	var arrServerlessInputs = this.pattRelatedItems.getServerlessInputParametersFilenames();
  	this.exporterlogger.log("Got Serverless input parameters = " + JSON.stringify(arrServerlessInputs));
  	this.incrementPercent();
  	
  	var arrPreSmTasks = this.pattRelatedItems.getPreSmTaskDefinitionsFilenames();
  	this.exporterlogger.log("Got Service Mapping Pre Task scripts = " + JSON.stringify(arrPreSmTasks));
  	this.incrementPercent();
  	
  	var arr = arrExtensions.concat(arrLibs, arrCiToPattern ,arrPrePost,arrTriggerProbes,arrDiscoClassy,arrTrackedFiles,arrCustoms,arrServerlessInputs,arrPreSmTasks);
  	
  	return arr;
  },
  
  getAdvancePatternData : function() {
  	this.exporterlogger.log("Going to get Identifiers, hosting rules, containment rules and reconciliation definitions for the following CIs:");
  	this.exporterlogger.log("Patterns Main CIs: " + JSON.stringify(this.pattRelatedItems.getPatternsCis()));
  	this.exporterlogger.log("Patterns related CIs (sa_ci_to_pattern): " + JSON.stringify(this.pattRelatedItems.getPatternRelatedCis()));
  	
  	var arrIdentifiers = this.pattRelatedItems.getIdentifiersFilenames();
  	this.exporterlogger.log("Got CIs identifiers = " + JSON.stringify(arrIdentifiers));
  	this.incrementPercent();
  	
  	var arrHostingRules = this.pattRelatedItems.getHostingRulesFilenames();
  	this.exporterlogger.log("Got CIs Hosting rules = " + JSON.stringify(arrHostingRules));
  	this.incrementPercent();
  	
  	var arrContainmentRules = this.pattRelatedItems.getContainmentRulesFilenames();
  	this.exporterlogger.log("Got CIs Containment rules = " + JSON.stringify(arrContainmentRules));
  	this.incrementPercent();
  	
  	var arrRecDefs = this.pattRelatedItems.getReconciliationDefinitionFilenames();
  	this.exporterlogger.log("Got CIs Reconciliation Definitions = " + JSON.stringify(arrRecDefs));
  	this.incrementPercent();
  	
  	var arrDeltStrScripts = this.pattRelatedItems.getDeleteStrategyScripts();
  	this.exporterlogger.log("Got Delete Strategy Scripts = " + JSON.stringify(arrDeltStrScripts));
  	this.incrementPercent();
  	
  	var arrUploadedFiles = this.pattRelatedItems.getUploadedFilesFilenames();
  	this.exporterlogger.log("Got Uploaded files = " + JSON.stringify(arrUploadedFiles));
  	this.incrementPercent();
  	
  	return arrIdentifiers.concat(arrHostingRules, arrContainmentRules, arrRecDefs, arrDeltStrScripts, arrUploadedFiles);
  },
  
  getLargePayloadPatternData : function (){
  	var arrSnPatternTriggerRules = this.pattRelatedItems.getSnPetternTriggerRuleFilenames();
  	this.exporterlogger.log("Got Large Payload Pattern Trigger rules = " + JSON.stringify(arrSnPatternTriggerRules));
  	this.incrementPercent();
  	
  	var arrDiscoPatternLunchParams = this.pattRelatedItems.getDiscoPatternLunchParamDefExtFilenames();
  	this.exporterlogger.log("Got Large Payload Pattern Lunch Paramters Definition = " + JSON.stringify(arrDiscoPatternLunchParams));
  	this.incrementPercent();
  	
  	var arrPatternOutputFiles = this.pattRelatedItems.getSnPatternOutputsFilenames();
  	this.exporterlogger.log("Got Large Payload Pattern Output files = " + JSON.stringify(arrPatternOutputFiles));
  	this.incrementPercent();
  	
  	return arrSnPatternTriggerRules.concat(arrDiscoPatternLunchParams, arrPatternOutputFiles);
  },
  
  incrementPercent : function(){
  	this.currentStep++;
  	this.tracker.incrementPercentComplete(this.currentStep/this.numberOfSteps);
  },

  type: 'DownloadPatternsEntities'
};

Sys ID

ec37cd5153730010234dddeeff7b1242

Offical Documentation

Official Docs: