123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- 'use strict';
- /*
- * +------------------------------------------------------------------------+
- * | Licensed Materials - Property of IBM
- * | IBM Cognos Products: Dashboard
- * | (C) Copyright IBM Corp. 2017
- * |
- * | US Government Users Restricted Rights - Use, duplication or disclosure
- * | restricted by GSA ADP Schedule Contract with IBM Corp.
- * +------------------------------------------------------------------------+
- */
- define(['underscore'], function (_) {
- /**
- *@constructor
- */
- var DeploymentReferencesUtil = {};
- DeploymentReferencesUtil.updateIds = function (spec, deploymentReferences) {
- if (!spec || !deploymentReferences || deploymentReferences.length === 0) {
- return;
- }
- DeploymentReferencesUtil.updateWidgetIds(spec, deploymentReferences);
- DeploymentReferencesUtil.updateDatasetShaping(spec, deploymentReferences);
- DeploymentReferencesUtil.updateDataSources(spec, deploymentReferences);
- DeploymentReferencesUtil.updateDrillThrough(spec, deploymentReferences);
- };
- DeploymentReferencesUtil.updateWidgetIds = function (spec, deploymentReferences) {
- if (!spec || !spec.widgets) {
- return;
- }
- _.keys(spec.widgets).forEach(function (key) {
- var widget = spec.widgets[key];
- if (widget.dataSet) {
- var reference = DeploymentReferencesUtil.findReference(widget.dataSet.id, deploymentReferences);
- if (reference) {
- widget.dataSet.id = reference.id;
- widget.dataSet.type = reference.type;
- widget.dataSet.name = reference.defaultName;
- widget.dataSet.exists = true;
- var ancestors = reference.ancestors;
- if (ancestors && ancestors.length > 0) {
- widget.dataSet.ancestors = reference.ancestors;
- widget.dataSet.parentFolderURL = ancestors[ancestors.length - 1]._meta.links.self.url;
- }
- }
- }
- });
- };
- DeploymentReferencesUtil.updateDatasetShaping = function (spec, deploymentReferences) {
- if (!spec || !spec.datasetShaping) {
- return;
- }
- spec.datasetShaping.forEach(function (datasetShaping) {
- var reference = DeploymentReferencesUtil.findReference(datasetShaping.id, deploymentReferences);
- if (reference) {
- datasetShaping.id = reference.id;
- }
- });
- };
- DeploymentReferencesUtil.updateDataSources = function (spec, deploymentReferences) {
- if (!spec || !spec.dataSources || !spec.dataSources.sources) {
- return;
- }
- spec.dataSources.sources.forEach(function (source) {
- var ref = DeploymentReferencesUtil.findReference(source.assetId, deploymentReferences);
- if (ref) {
- source.assetId = ref.id;
- }
- ref = DeploymentReferencesUtil.findReference(source.assetId, deploymentReferences, true /*ignoreIdMatchCheck*/);
- if (ref) {
- source.searchPath = ref.searchPath;
- }
- if (source.shaping) {
- DeploymentReferencesUtil.updateShaping(source.shaping, deploymentReferences);
- }
- });
- };
- DeploymentReferencesUtil.updateShaping = function (shaping, deploymentReferences) {
- if (!shaping) {
- return;
- }
- if (shaping.moserJSON) {
- var ref = DeploymentReferencesUtil.findReference(shaping.moserJSON.useSpec[0].storeID, deploymentReferences);
- if (ref) {
- shaping.moserJSON.useSpec[0].storeID = ref.id;
- }
- }
- if (shaping.embeddedModuleId) {
- var embededModuleRef = DeploymentReferencesUtil.findReference(shaping.embeddedModuleId, deploymentReferences);
- if (embededModuleRef) {
- shaping.embeddedModuleId = embededModuleRef.id;
- }
- }
- };
- DeploymentReferencesUtil.updateDrillThrough = function (spec, deploymentReferences) {
- if (!spec || !spec.drillThrough || !spec.drillThrough.length) {
- return;
- }
- spec.drillThrough.forEach(function (drillThroughDefinition) {
- var drillEntryRef = DeploymentReferencesUtil.findReference(drillThroughDefinition.assetId, deploymentReferences);
- if (drillEntryRef) {
- drillThroughDefinition.assetId = drillEntryRef.id;
- }
- });
- };
- DeploymentReferencesUtil.findReference = function (id, deploymentReferences, ignoreIdMatchCheck) {
- if (!deploymentReferences) {
- return null;
- }
- for (var i = 0; i < deploymentReferences.length; i++) {
- var ref = deploymentReferences[i];
- var refNameKey = ref.name && _.keys(ref.name)[0] || 'en-us';
- if (ref.objects && ref.objects.length > 0 && ref.name[refNameKey] === id) {
- if (ignoreIdMatchCheck || ref.objects[0].id !== id) {
- return ref.objects[0];
- }
- return null;
- }
- }
- return null;
- };
- return DeploymentReferencesUtil;
- });
- //# sourceMappingURL=DeploymentReferencesUtil.js.map
|