Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
obj.datasets.forEach((dataset: IDashboardDataset) => {
// when the datasource has an itemId is an external datasource
const itemId: string = common.getProp(dataset, "dataSource.itemId");
if (itemId) {
if (itemTemplate.dependencies.indexOf(itemId) < 0) {
itemTemplate.dependencies.push(itemId);
}
const layerId: number = common.getProp(dataset, "dataSource.layerId");
dataset.dataSource.itemId = common.templatizeTerm(
itemId,
itemId,
layerId !== undefined ? ".layer" + layerId + ".itemId" : ".itemId"
);
if (layerId !== undefined) {
dataset.dataSource.layerId = common.templatizeTerm(
itemId,
itemId,
".layer" + layerId + ".layerId"
);
}
}
});
}
keyProperties.forEach(p => {
if (common.getProp(data, p)) {
if (common.getProp(data[p], "serviceItemId")) {
// templatize properties with id and url
const id: string = data[p].serviceItemId;
let serviceItemIdSuffix: string = ".itemId";
if (common.getProp(data[p], "url")) {
const layerId = data[p].url.substr(
(data[p].url as string).lastIndexOf("/") + 1
);
data[p].url = common.templatizeTerm(
id,
id,
".layer" + layerId + ".url"
);
serviceItemIdSuffix = ".layer" + layerId + serviceItemIdSuffix;
}
data[p].serviceItemId = common.templatizeTerm(
id,
id,
serviceItemIdSuffix
);
} else {
// templatize simple id properties
data[p] = common.templatizeTerm(data[p], data[p], ".itemId");
}
}
obj.datasets.forEach((dataset: IDashboardDataset) => {
// when the datasource has an itemId is an external datasource
const itemId: string = common.getProp(dataset, "dataSource.itemId");
if (itemId) {
if (itemTemplate.dependencies.indexOf(itemId) < 0) {
itemTemplate.dependencies.push(itemId);
}
const layerId: number = common.getProp(dataset, "dataSource.layerId");
dataset.dataSource.itemId = common.templatizeTerm(
itemId,
itemId,
layerId !== undefined ? ".layer" + layerId + ".itemId" : ".itemId"
);
if (layerId !== undefined) {
dataset.dataSource.layerId = common.templatizeTerm(
itemId,
itemId,
".layer" + layerId + ".layerId"
);
}
}
});
}
return new Promise((resolve, reject) => {
// Init template
const itemTemplate: common.IItemTemplate = common.createInitializedGroupTemplate(
itemInfo
);
itemTemplate.estimatedDeploymentCostFactor = 2; // minimal set is starting, creating, done|failed
// Templatize item info property values
itemTemplate.item.id = common.templatizeTerm(
itemTemplate.item.id,
itemTemplate.item.id,
".itemId"
);
// Get the group's items--its dependencies
common.getGroupContents(itemInfo.id, authentication).then(
groupContents => {
itemTemplate.type = "Group";
itemTemplate.dependencies = groupContents;
common.getGroup(itemInfo.id, authentication).then(
groupResponse => {
groupResponse.id = itemTemplate.item.id;
itemTemplate.item = groupResponse;
// Request resources
// templatize properties with id and url
const id: string = data[p].serviceItemId;
let serviceItemIdSuffix: string = ".itemId";
if (common.getProp(data[p], "url")) {
const layerId = data[p].url.substr(
(data[p].url as string).lastIndexOf("/") + 1
);
data[p].url = common.templatizeTerm(
id,
id,
".layer" + layerId + ".url"
);
serviceItemIdSuffix = ".layer" + layerId + serviceItemIdSuffix;
}
data[p].serviceItemId = common.templatizeTerm(
id,
id,
serviceItemIdSuffix
);
} else {
// templatize simple id properties
data[p] = common.templatizeTerm(data[p], data[p], ".itemId");
}
}
});
paths.forEach(path => {
const id: any = common.getProp(itemTemplate, path);
common.setProp(
itemTemplate,
path,
common.templatizeTerm(id, id, ".itemId")
);
});
}
objs.forEach(obj => {
if (obj.type === "mapWidget") {
if (itemTemplate.dependencies.indexOf(obj.itemId) < 0) {
itemTemplate.dependencies.push(obj.itemId);
}
obj.itemId = common.templatizeTerm(obj.itemId, obj.itemId, ".itemId");
}
if (Array.isArray(obj.datasets)) {
_getDatasourceDependencies(obj, itemTemplate);
}
});
}
const layerId = layer.url.substr(
(layer.url as string).lastIndexOf("/") + 1
);
const hashId: any =
Object.keys(urlHash).indexOf(layer.url) > -1
? urlHash[layer.url]
: undefined;
const itemId: string = layer.itemId ? layer.itemId : hashId;
if (itemId) {
layer.url = common.templatizeTerm(
itemId,
itemId,
".layer" + layerId + ".url"
);
if (layer.itemId) {
layer.itemId = common.templatizeTerm(
itemId,
itemId,
".layer" + layerId + ".itemId"
);
}
}
}
});
}
ids.forEach(id => {
id = id.replace("itemID=", "");
item.urlTemplate = item.urlTemplate.replace(
id,
common.templatizeTerm(id, id, ".itemId")
);
});
}
layerList.forEach((layer: any) => {
if (layer.url) {
const layerId = layer.url.substr(
(layer.url as string).lastIndexOf("/") + 1
);
const hashId: any =
Object.keys(urlHash).indexOf(layer.url) > -1
? urlHash[layer.url]
: undefined;
const itemId: string = layer.itemId ? layer.itemId : hashId;
if (itemId) {
layer.url = common.templatizeTerm(
itemId,
itemId,
".layer" + layerId + ".url"
);
if (layer.itemId) {
layer.itemId = common.templatizeTerm(
itemId,
itemId,
".layer" + layerId + ".itemId"
);
}
}
}
});
}