-
Notifications
You must be signed in to change notification settings - Fork 0
/
datasetUpload.js
51 lines (44 loc) · 1.06 KB
/
datasetUpload.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const createDbReader = require('./dbReader');
const createUploader = require('./uploader');
const orgsUpload = require('./orgUpload');
function readDatasets(handle) {
return read(handle, 'readDatasets');
}
function readRevisions(handle) {
return read(handle, 'readMetadata');
}
function read(handle, methodName) {
let reader = createDbReader();
let errors = [];
return reader
.init()
.then(() => reader[methodName]())
.then(cursor => {
return cursor.eachAsync((item) => {
return handle(item)
.catch((err) => {
errors.push(err);
console.log(err);
});
})
})
.catch((err) => {console.log(err)})
.then(() => {
return reader.finish();
});
}
function datasetsUpload() {
let ckan = createUploader();
return readDatasets((revision) => {
return ckan.createDataset(revision);
})
.then(() => {
return readRevisions(revision => {
return ckan.createResource(revision);
});
});
}
module.exports = datasetsUpload;
orgsUpload().then(() => {
return datasetsUpload();
})