-
Notifications
You must be signed in to change notification settings - Fork 2
/
copy_data_source.js
36 lines (31 loc) · 1.1 KB
/
copy_data_source.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const UUID = Java.type('java.util.UUID');
const dataSourceService = services.dataSourceService;
const dataPointService = services.dataPointService;
const templateDataSourceXid = 'DS_XYZ';
const templateDataSource = dataSourceService.get(templateDataSourceXid);
const dataSourceCopy = copyDataSource(templateDataSource);
const dataPoints = services.dataPointService.buildQuery()
.equal('dataSourceId', templateDataSource.getId())
.query(point => {
copyDataPoint(dataSourceCopy, point);
});
console.log(dataSourceCopy);
function copyDataSource(dataSource) {
const copy = dataSource.copy();
copy.setId(-1);
copy.setXid(`DS_${UUID.randomUUID()}`);
copy.setName(dataSource.getName() + ' (copy)');
copy.setEnabled(false);
services.dataSourceService.insert(copy);
return copy;
}
function copyDataPoint(dataSource, dataPoint) {
const copy = dataPoint.copy();
copy.setId(-1);
copy.setSeriesId(-1);
copy.setXid(null);
copy.setDataSourceXid(dataSource.getXid());
copy.setDataSourceId(dataSource.getId());
dataPointService.insert(copy);
return copy;
}