Name

sn_ppt_export.PPTRequestHandler

Description

Content-Generation This file is the entry point for BR s in order to perform different operation on ppt. Warning Customers should not modify this file.

Script

var PPTRequestHandler = Class.create();
PPTRequestHandler.prototype = {
  initialize: function(templateRecordSysID) {
  	this.commonUtil = new PPTCommonUtil();
  	this.operationStatusID = '';
  	try {
  		this.extensionPointUtil = new global.PPTGenerationExtensionPointGlobal(GeneratePPTConstants.TEMPLATE_TABLENAME, templateRecordSysID);
  		if (global.JSUtil.nil(templateRecordSysID))
  			throw new Error(gs.getMessage("There was an error loading your file. You can upload the template again or try with a new template."));
  		this.operationStatusID = this.commonUtil.initializeLogRecord(templateRecordSysID);
  	} catch (e) {
  		gs.info("LOG: PPTRequestHandler "+e.message);
  		this.extensionPointUtil = null;
  	}
      this.templateRecordSysID = templateRecordSysID;
      this.responseMessage = "Client side error: Bad Request";
      this.statusCode = 400;
  },

  //returns parsed Json string on success or null in case of failure
  runTemplateParser: function() {
  	try {
  		if (global.JSUtil.nil(this.extensionPointUtil))
  			throw new Error(gs.getMessage("Initialisation failed. For more information, check log records."));
  	} catch(e) {
  		gs.info("LOG: PPTRequestHandler "+e.message);
  		this.responseMessage = e.message;
  		return null;
  	}
      var response = this.extensionPointUtil.post(GeneratePPTConstants.PARSE_URL_PATTERN, GeneratePPTConstants.PARSE);
      this.statusCode = response["status_code"];
      if (!response["is_error"]) {
  		this.commonUtil.updateLogRecord(this.operationStatusID, 'parse', response);
  		this.responseMessage = "success";
  		return response["response_body"];
  	}
  	if(response.response_body == "POI connection is not established")
  			response.response_body = gs.getMessage("The PowerPoint generation service is not available. Please try after some time.");
      this.commonUtil.updateLogRecord(this.operationStatusID, 'parse', response);
      this.responseMessage = response["response_body"];
      return null;
  	
  },

  //returns attachment sys id on success or null in case of failure
  runPPTGenerator: function(baseTableName, baseRecordSysID, outputTableName, outputRecordSysID,outputfilename) {
      try {
  		if (global.JSUtil.nil(this.extensionPointUtil))
  			throw new Error(gs.getMessage("Initialisation failed. For more information, check log records."));
  	} catch(e) {
  		gs.info("LOG: PPTRequestHandler "+e.message);
  		this.responseMessage = e.message;
  		return null;
  	}
  	try {
  		var pptGeneratorHelper = new GeneratePPTProcessorHelper(baseTableName, baseRecordSysID, this.templateRecordSysID);
  		pptGeneratorHelper.runAllStage();
  		var dataString = pptGeneratorHelper.getDataJSONString();
  		var stepString = pptGeneratorHelper.getStepJSONString();

  		var body = {
  			'outputTableName': outputTableName,
  			'outputRecordSysID': outputRecordSysID,
  			'dataString': dataString,
  			'stepString': stepString,
  			'fileName': 'output_ppt.pptx'
  		};

  		if(typeof outputfilename != "undefined")
  			body.fileName = outputfilename;
  	} catch (e) {
  		this.commonUtil.updateLogRecord(this.operationStatusID, 'generate', {'is_error':true,'response_body':e.message});
  		gs.info("LOG: PPTRequestHandler "+e.message);
  		this.responseMessage = e.message;
  		return null;
  	}
  	
      this.extensionPointUtil.initializeGenerateRequest(body);
      var response = this.extensionPointUtil.post(GeneratePPTConstants.GENERATE_URL_PATTERN,GeneratePPTConstants.GENERATE);
      this.statusCode = response["status_code"];
      if (!response["is_error"]) {
  		this.commonUtil.updateLogRecord(this.operationStatusID, 'generate', response);
  		this.responseMessage = "success";
          return response["response_body"];
  	}
  	if(response.response_body == "POI connection is not established")
  		response.response_body = gs.getMessage("The PowerPoint generation service is not available. Please try after some time.");
  	this.commonUtil.updateLogRecord(this.operationStatusID, 'generate', response);
      this.responseMessage = response["response_body"];
      return null;
  },

  getResponseMessage: function() {
      return this.responseMessage;
  },

  getStatusCode: function() {
      return this.statusCode;
  },

  type: 'PPTRequestHandler'
};

Sys ID

16cfddd153820110b595ddeeff7b1257

Offical Documentation

Official Docs: