-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathretractPkg.js
72 lines (64 loc) · 1.84 KB
/
retractPkg.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const axios = require("axios");
const path = require("path");
const constants = require("./constants");
const qh = require("./utils/QueueHelper");
const sh = require("./utils/ServiceHelper");
const fh = require("./utils/FileHelper");
const ACTION = 'retract';
/**
* Delete attachments (if present) from the filesystem
*/
const deleteAtt = (iri) => {
return new Promise(function(resolve, reject) {
let arrIri = iri.split("/");
let subPath = arrIri.slice(1, arrIri.length - 1 ).join("/");
const attPath = path.join(constants.AKN_ATT_FOLDER(), subPath);
fh.fileExists(attPath)
.then(res => {
return res
? fh.removeFileFolder(attPath)
: resolve(true)
})
.then(res => resolve(true))
.catch(err => reject(err))
});
}
/**
* Delete package for IRI from gawati-data
*/
const deleteFromDB = (iri) => {
console.log(" IN: deleteFromDB");
const deletePkgApi = sh.getApi("xmlServer", "deletePkg");
const {url, method} = deletePkgApi;
const data = {iri};
return axios({
method: method,
url: url,
data: data
})
}
/**
* Delete package for IRI from gawati-data.
* Publish status of pkg deleted by the gawati-data.
*/
const toGawatiData = ({iri, action}) => {
console.log(" IN: toGawatiData");
const deletePkgApi = sh.getApi("xmlServer", "deletePkg");
const {url, method} = deletePkgApi;
const data = {iri};
deleteAtt(iri)
.then(res => {
return deleteFromDB(iri)
})
.then(res => {
console.log(res.data);
res.data.success
? qh.publishStatus(qh.formMsg(iri,'retracted','Retracted from Gawati-Data', ACTION))
: qh.publishStatus(qh.formMsg(iri,'failed','Error on Portal Publisher', ACTION));
})
.catch(err => {
qh.publishStatus(qh.formMsg(iri,'failed','Error on Portal Publisher', ACTION));
console.log(err);
})
};
module.exports.toGawatiData = toGawatiData;