Name

sn_hr_mobile.MobileIconAndContentSectionMigrationTools

Description

No description available

Script

var MobileIconAndContentSectionMigrationTools = Class.create();
MobileIconAndContentSectionMigrationTools.prototype = {
  TABLE: {
      SYS_SG_ICON_SECTION: "sys_sg_icon_section",
      SYS_SG_NAVIGATION_SECTION: "sys_sg_navigation_section",
      SYS_SG_CONTENT_SECTION: "sys_sg_content_section",
      SYS_SG_ITEM_SECTION: "sys_sg_item_section",
      SYS_SG_APPLET_LAUNCHER_M2M_SECTION: "sys_sg_applet_launcher_m2m_section",
      SYS_SG_MASTER_ITEM: "sys_sg_master_item",
      SYS_SG_CONTENT_SECTION_M2M_ITEM_STREAM_CONTAINER: "sys_sg_content_section_m2m_item_stream_container",
      SYS_SG_ITEM_STREAM_CONTAINER_M2M_ITEM_STREAM: "sys_sg_item_stream_container_m2m_item_stream",
      SYS_SG_ITEM_STREAM_CONTAINER: "sys_sg_item_stream_container",
      SYS_SG_ITEM_STREAM: "sys_sg_item_stream"
  },
  FIELD: {
      ACTIVE: "active",
      SECTION: "section"
  },

  SYS_SG_ICON_SECTION_MAP: {
      "0c4ae0ae53c22010003cddeeff7b1292": {
          "sys_sg_navigation_section": "de470f746bc3111024ca2421ee44af2d",
          "sys_sg_applet_launcher_m2m_section": "9af9ac6e53c22010003cddeeff7b1293"
      }
  },

  SYS_SG_CONTENT_SECTION_MAP: {
      "3c63b96fc35620105f973e5f2b40ddab": {
          "sys_sg_item_section": "d504fb476b43111024ca2421ee44afdd",
          "sys_sg_applet_launcher_m2m_section": "ea1471afc35620105f973e5f2b40dd72",
          "sys_sg_content_section_m2m_item_stream_container": "5905f9afc35620105f973e5f2b40dda8",
          "sys_sg_item_stream_container_m2m_item_stream": "f70af563c39620105f973e5f2b40ddc2",
          "sys_sg_item_stream_container": "dfc479afc35620105f973e5f2b40dd32",
          "sys_sg_item_stream": "ccb9f163c39620105f973e5f2b40dd78"
      }
  },

  initialize: function() {
      this.mobileUtahUpgradeCommonTool = new sn_hr_mobile.MobileUtahUpgradeCommonTools();
  },

  cleanUpgrade: function() {
      this.cleanUpgradeIconSection();
      this.cleanUpgradeContentSection();
  },

  cleanUpgradeIconSection: function() {
      var iconSectionMap = this.SYS_SG_ICON_SECTION_MAP;
      for (var iconSection in iconSectionMap) {
          var iconSectionGr = this.mobileUtahUpgradeCommonTool.getGlideRecord(this.TABLE.SYS_SG_ICON_SECTION, iconSection);
          var navigationSectionGr = this.mobileUtahUpgradeCommonTool.getGlideRecord(this.TABLE.SYS_SG_NAVIGATION_SECTION, iconSectionMap[iconSection][this.TABLE.SYS_SG_NAVIGATION_SECTION]);
          if (!iconSectionGr || !iconSectionGr.isValidRecord()) {
              gs.info("MobileIconSectionMigrationTools: cleanUpgrade: Skipping revert as sys_sg_icon_section Record {0} not found", iconSection);
          } else if (!navigationSectionGr || !navigationSectionGr.isValidRecord()) {
              if (this.getAssociatedLauncherSections(iconSectionGr).length == 0) {
                  this.deActivateRecord(iconSectionGr);
              }
              gs.info("MobileIconSectionMigrationTools: cleanUpgrade: Skipping revert as sys_sg_navigation_section Record {0} not found", navigationSectionGr.getUniqueValue());
          } else if (this.isIconSectionFlowCustom(iconSectionGr, iconSectionMap)) {
              this.deActivateRecord(navigationSectionGr);
          } else {
              gs.info("MobileIconSectionMigrationTools: cleanUpgrade: Deactivate legacy icon section as Record {0} not customized", iconSection);
              this.deActivateRecord(iconSectionGr);
          }
      }
  },

  cleanUpgradeContentSection: function() {
      var contentSectionMap = this.SYS_SG_CONTENT_SECTION_MAP;
      for (var contentSection in contentSectionMap) {
          var contentSectionGr = this.mobileUtahUpgradeCommonTool.getGlideRecord(this.TABLE.SYS_SG_CONTENT_SECTION, contentSection);
          var itemSectionGr = this.mobileUtahUpgradeCommonTool.getGlideRecord(this.TABLE.SYS_SG_ITEM_SECTION, contentSectionMap[contentSection][this.TABLE.SYS_SG_ITEM_SECTION]);
          if (!contentSectionGr || !contentSectionGr.isValidRecord()) {
              gs.info("MobileContentSectionMigrationTools: cleanUpgrade: Skipping revert as sys_sg_content_section Record {0} not found", contentSection);
          } else if (!itemSectionGr || !itemSectionGr.isValidRecord()) {
              if (this.getAssociatedLauncherSections(contentSectionGr).length == 0) {
                  this.deActivateRecord(contentSectionGr);
              }
              gs.info("MobileContentSectionMigrationTools: cleanUpgrade: Skipping revert as sys_sg_item_section Record {0} not found", itemSectionGr.getUniqueValue());
          } else if (this.isContentSectionFlowCustom(contentSectionGr, contentSectionMap)) {
              this.deActivateRecord(itemSectionGr);
          } else {
              gs.info("MobileContentSectionMigrationTools: cleanUpgrade: Deactivate legacy content section as Record {0} not customized", contentSection);
              this.deActivateRecord(contentSectionGr);
          }
      }
  },

  isIconSectionFlowCustom: function(sectionGr, sectionMap) {

      if (this.mobileUtahUpgradeCommonTool.isRecordCustomized(sectionGr.getValue("sys_update_name"))) {
          return true;
      }
      var associatedLauncherSections = this.getAssociatedLauncherSections(sectionGr);
      var expectedLauncherSections = sectionMap[sectionGr.getUniqueValue()][this.TABLE.SYS_SG_APPLET_LAUNCHER_M2M_SECTION].split(",");
      var arrayUtil = new global.ArrayUtil();
      if (
          associatedLauncherSections.length != expectedLauncherSections.length || 
          arrayUtil.diff(associatedLauncherSections, expectedLauncherSections).length != 0 || 
          arrayUtil.diff(expectedLauncherSections, associatedLauncherSections).length != 0) 
      {
          return true;
      }
  },

  isContentSectionFlowCustom: function(sectionGr, sectionMap) {

      var section = sectionMap[sectionGr.getUniqueValue()]
      if (this.mobileUtahUpgradeCommonTool.isRecordCustomized(sectionGr.getValue("sys_update_name"))) {
          gs.info("MobileContentSectionMigrationTools: reverting to old view as {0} sys_sg_content_section Record is customized", sectionGr.getUniqueValue());
          return true;
      }
      var associatedLauncherSections = this.getAssociatedLauncherSections(sectionGr);
      var expectedLauncherSections = section[this.TABLE.SYS_SG_APPLET_LAUNCHER_M2M_SECTION].split(",");

      var arrayUtil = new global.ArrayUtil();
      if (
          associatedLauncherSections.length != expectedLauncherSections.length || 
          arrayUtil.diff(associatedLauncherSections, expectedLauncherSections).length != 0 || 
          arrayUtil.diff(expectedLauncherSections, associatedLauncherSections).length != 0) 
      {
          gs.info("MobileContentSectionMigrationTools: reverting to old view as {0} SYS_SG_APPLET_LAUNCHER_M2M_SECTION Record is customized", sectionGr.getUniqueValue());
          return true;
      }

      var associatedItemStreamContainers = this.getAssociatedStreamContainer(sectionGr.getUniqueValue());
      var expectedItemStreamContainers = section[this.TABLE.SYS_SG_CONTENT_SECTION_M2M_ITEM_STREAM_CONTAINER].split(",");

      if (
          associatedItemStreamContainers.length != expectedItemStreamContainers.length || 
          arrayUtil.diff(associatedItemStreamContainers, expectedItemStreamContainers).length != 0 || 
          arrayUtil.diff(expectedItemStreamContainers, associatedItemStreamContainers).length != 0) 
      {
          gs.info("MobileContentSectionMigrationTools: reverting to old view as {0} SYS_SG_CONTENT_SECTION_M2M_ITEM_STREAM_CONTAINER Record is customized", sectionGr.getUniqueValue());
          return true;
      }

      var itemStreamContainerGr = this.mobileUtahUpgradeCommonTool.getGlideRecord(this.TABLE.SYS_SG_ITEM_STREAM_CONTAINER, section[this.TABLE.SYS_SG_ITEM_STREAM_CONTAINER]);
      if (this.mobileUtahUpgradeCommonTool.isRecordCustomized(itemStreamContainerGr.getValue("sys_update_name"))) {
          gs.info("MobileContentSectionMigrationTools: reverting to old view as {0} SYS_SG_ITEM_STREAM_CONTAINER Record is customized", sectionGr.getUniqueValue());
          return true;
      }

      var associatedItemStreamContainersM2MItemStreams = this.getAssociatedItemStreamContainer(section[this.TABLE.SYS_SG_ITEM_STREAM_CONTAINER]);
      var expectedItemStreamContainersM2MItemStreams = section[this.TABLE.SYS_SG_ITEM_STREAM_CONTAINER_M2M_ITEM_STREAM].split(",");

      if (
          associatedItemStreamContainersM2MItemStreams.length != expectedItemStreamContainersM2MItemStreams.length || 
          arrayUtil.diff(associatedItemStreamContainersM2MItemStreams, expectedItemStreamContainersM2MItemStreams).length != 0 || 
          arrayUtil.diff(expectedItemStreamContainersM2MItemStreams, associatedItemStreamContainersM2MItemStreams).length != 0) 
      {
          gs.info("MobileContentSectionMigrationTools: reverting to old view as {0} SYS_SG_ITEM_STREAM_CONTAINER_M2M_ITEM_STREAM Record is customized", sectionGr.getUniqueValue());
          return true;
      }

      return false;
  },

  getAssociatedLauncherSections: function(sectionGr) {
      var gr = new GlideRecord(this.TABLE.SYS_SG_APPLET_LAUNCHER_M2M_SECTION);
      gr.addQuery(this.FIELD.SECTION, sectionGr.getUniqueValue());
      gr.query();
      var associatedSections = [];
      while (gr.next()) {
          associatedSections.push(gr.getUniqueValue());
      }
      return associatedSections;
  },

  getAssociatedStreamContainer: function(contentSection) {
      var gr = new GlideRecord(this.TABLE.SYS_SG_CONTENT_SECTION_M2M_ITEM_STREAM_CONTAINER);
      gr.addQuery("content_section", contentSection);
      gr.query();
      var associatedContainers = [];
      while (gr.next()) {
          associatedContainers.push(gr.getUniqueValue());
      }
      return associatedContainers;
  },

  getAssociatedItemStreamContainer: function(itemStream) {
      var gr = new GlideRecord(this.TABLE.SYS_SG_ITEM_STREAM_CONTAINER_M2M_ITEM_STREAM);
      gr.addQuery("item_stream_container", itemStream);
      gr.query();
      var associatedStreams = [];
      while (gr.next()) {
          associatedStreams.push(gr.getUniqueValue());
      }
      return associatedStreams;
  },

  deActivateRecord: function(gr) {
      if (gr && gr.isValidRecord() && gr.getValue(this.FIELD.ACTIVE) == 1 && !this.mobileUtahUpgradeCommonTool.isRecordCustomized(gr.getValue("sys_update_name"))) {
          gr.setValue(this.FIELD.ACTIVE, 0);
          gr.update();
          gs.info("MobileIconAndContentSectionMigrationTools: deActivateRecord: {0} Record {1} deactivated", gr.getTableName(), gr.getUniqueValue());
      } else {
          gs.info("MobileIconAndContentSectionMigrationTools: deActivateRecord: Skipped deactivation because Record {0} not found or already deactivated", gr.getUniqueValue());
      }

  },

  type: 'MobileIconAndContentSectionMigrationTools'
};

Sys ID

f0f3270b6b03111024ca2421ee44afed

Offical Documentation

Official Docs: