pid-parser-service/parsers/ParserUtils.js

63 lines
1.8 KiB
JavaScript
Raw Normal View History

2024-11-20 10:34:15 +01:00
const Crossref = require("./Crossref");
const CROSSREF_endpoint = "api.crossref.org";
const CROSSREF = "crossref";
const Datacite = require("./Datacite");
const DATACITE_endpoint = "api.datacite.org";
const DATACITE = "datacite";
const N2t = require("./N2t");
const N2T_endpoint = "n2t.net";
const N2T = "n2t";
const Googleapis = require("./Googleapis");
const GOOGLEAPIS_endpoint = "www.googleapis.com";
const GOOGLEAPIS = "googleapis";
const Zenodo = require("./Zenodo");
const Zenodo_endpoint = "zenodo.org";
const ZENODOD = "zenodo";
const Arxiv = require("./Arxiv");
const Arxiv_endpoint = "export.arxiv.org";
class ParserUtils {
getSupportedParsers() {
return [CROSSREF_endpoint, DATACITE_endpoint, Zenodo_endpoint/*, Arxiv_endpoint, N2T_endpoint, GOOGLEAPIS_endpoint*/];
}
getXMLParsers() {
return [Arxiv_endpoint];
}
parseJSON(pid, endpoint, data) {
console.log("parse JSON", pid, endpoint)
if (endpoint == CROSSREF_endpoint) {
const parser = new Crossref();
return parser.parse(pid, data['message']);
} else if (endpoint == DATACITE_endpoint) {
const parser = new Datacite();
return parser.parse(pid, data['data']);
} else if (endpoint == N2T_endpoint) {
const parser = new N2t();
return parser.parse(pid, data);
} else if (endpoint == GOOGLEAPIS_endpoint) {
const parser = new Googleapis();
return parser.parse(pid, data.items[0]);
} else if (endpoint == Zenodo_endpoint) {
const parser = new Zenodo();
return parser.parse(pid, data);
}
}
async parseXML(pid, endpoint, data) {
console.log("parse XML", pid, endpoint)
if (endpoint == Arxiv_endpoint) {
const parser = new Arxiv();
return parser.parse(pid, data)
}
}
}
module.exports = ParserUtils;