DeploymentReferencesUtil.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. 'use strict';
  2. /*
  3. * +------------------------------------------------------------------------+
  4. * | Licensed Materials - Property of IBM
  5. * | IBM Cognos Products: Dashboard
  6. * | (C) Copyright IBM Corp. 2017
  7. * |
  8. * | US Government Users Restricted Rights - Use, duplication or disclosure
  9. * | restricted by GSA ADP Schedule Contract with IBM Corp.
  10. * +------------------------------------------------------------------------+
  11. */
  12. define(['underscore'], function (_) {
  13. /**
  14. *@constructor
  15. */
  16. var DeploymentReferencesUtil = {};
  17. DeploymentReferencesUtil.updateIds = function (spec, deploymentReferences) {
  18. if (!spec || !deploymentReferences || deploymentReferences.length === 0) {
  19. return;
  20. }
  21. DeploymentReferencesUtil.updateWidgetIds(spec, deploymentReferences);
  22. DeploymentReferencesUtil.updateDatasetShaping(spec, deploymentReferences);
  23. DeploymentReferencesUtil.updateDataSources(spec, deploymentReferences);
  24. DeploymentReferencesUtil.updateDrillThrough(spec, deploymentReferences);
  25. };
  26. DeploymentReferencesUtil.updateWidgetIds = function (spec, deploymentReferences) {
  27. if (!spec || !spec.widgets) {
  28. return;
  29. }
  30. _.keys(spec.widgets).forEach(function (key) {
  31. var widget = spec.widgets[key];
  32. if (widget.dataSet) {
  33. var reference = DeploymentReferencesUtil.findReference(widget.dataSet.id, deploymentReferences);
  34. if (reference) {
  35. widget.dataSet.id = reference.id;
  36. widget.dataSet.type = reference.type;
  37. widget.dataSet.name = reference.defaultName;
  38. widget.dataSet.exists = true;
  39. var ancestors = reference.ancestors;
  40. if (ancestors && ancestors.length > 0) {
  41. widget.dataSet.ancestors = reference.ancestors;
  42. widget.dataSet.parentFolderURL = ancestors[ancestors.length - 1]._meta.links.self.url;
  43. }
  44. }
  45. }
  46. });
  47. };
  48. DeploymentReferencesUtil.updateDatasetShaping = function (spec, deploymentReferences) {
  49. if (!spec || !spec.datasetShaping) {
  50. return;
  51. }
  52. spec.datasetShaping.forEach(function (datasetShaping) {
  53. var reference = DeploymentReferencesUtil.findReference(datasetShaping.id, deploymentReferences);
  54. if (reference) {
  55. datasetShaping.id = reference.id;
  56. }
  57. });
  58. };
  59. DeploymentReferencesUtil.updateDataSources = function (spec, deploymentReferences) {
  60. if (!spec || !spec.dataSources || !spec.dataSources.sources) {
  61. return;
  62. }
  63. spec.dataSources.sources.forEach(function (source) {
  64. var ref = DeploymentReferencesUtil.findReference(source.assetId, deploymentReferences);
  65. if (ref) {
  66. source.assetId = ref.id;
  67. }
  68. ref = DeploymentReferencesUtil.findReference(source.assetId, deploymentReferences, true /*ignoreIdMatchCheck*/);
  69. if (ref) {
  70. source.searchPath = ref.searchPath;
  71. }
  72. if (source.shaping) {
  73. DeploymentReferencesUtil.updateShaping(source.shaping, deploymentReferences);
  74. }
  75. });
  76. };
  77. DeploymentReferencesUtil.updateShaping = function (shaping, deploymentReferences) {
  78. if (!shaping) {
  79. return;
  80. }
  81. if (shaping.moserJSON) {
  82. var ref = DeploymentReferencesUtil.findReference(shaping.moserJSON.useSpec[0].storeID, deploymentReferences);
  83. if (ref) {
  84. shaping.moserJSON.useSpec[0].storeID = ref.id;
  85. }
  86. }
  87. if (shaping.embeddedModuleId) {
  88. var embededModuleRef = DeploymentReferencesUtil.findReference(shaping.embeddedModuleId, deploymentReferences);
  89. if (embededModuleRef) {
  90. shaping.embeddedModuleId = embededModuleRef.id;
  91. }
  92. }
  93. };
  94. DeploymentReferencesUtil.updateDrillThrough = function (spec, deploymentReferences) {
  95. if (!spec || !spec.drillThrough || !spec.drillThrough.length) {
  96. return;
  97. }
  98. spec.drillThrough.forEach(function (drillThroughDefinition) {
  99. var drillEntryRef = DeploymentReferencesUtil.findReference(drillThroughDefinition.assetId, deploymentReferences);
  100. if (drillEntryRef) {
  101. drillThroughDefinition.assetId = drillEntryRef.id;
  102. }
  103. });
  104. };
  105. DeploymentReferencesUtil.findReference = function (id, deploymentReferences, ignoreIdMatchCheck) {
  106. if (!deploymentReferences) {
  107. return null;
  108. }
  109. for (var i = 0; i < deploymentReferences.length; i++) {
  110. var ref = deploymentReferences[i];
  111. var refNameKey = ref.name && _.keys(ref.name)[0] || 'en-us';
  112. if (ref.objects && ref.objects.length > 0 && ref.name[refNameKey] === id) {
  113. if (ignoreIdMatchCheck || ref.objects[0].id !== id) {
  114. return ref.objects[0];
  115. }
  116. return null;
  117. }
  118. }
  119. return null;
  120. };
  121. return DeploymentReferencesUtil;
  122. });
  123. //# sourceMappingURL=DeploymentReferencesUtil.js.map