diff --git a/README.md b/README.md index 381e409..ba46500 100644 --- a/README.md +++ b/README.md @@ -84,15 +84,35 @@ ``` ## Le fichier query.json ### -TODO + +Le fichier conf/query.json contient l'ensemble des paramètres de recherche à utiliser pour l'interrogation de l'api HAL + +``` +{ + "fq": [""], // Liste des filtres a utiliser pour limiter les résultats retournés. + "fl": "", // La liste des champs a retourner dans la recherche, séparés par , + "q": "", // La requête. + "rows": "", // Le nombre de réponses à retourner. + "sort": "", // Pour trier les résultats. + "cursorMark": "*" // Curseur utilisé pour parcourir plusieurs milliers de résultats. +} +``` ## Le fichier conf.json ### -TODO + +Le fichier de configuration + +``` +{ + "halApi":"", // L'adresse url de l'api Hal + "max_retry":2 // Nombre des retries en cas d'échec lors de l'interrogation de l'api HAL +} +``` ### Codes d'erreur ### -| Code | Signification | Note(s) | -| -------- | ------------------------------------------------------| ------- | -| 1 | Harvest folder already exist. | -| 2 | API-HAL request error. | -| 3 | No result found. | +| Code | Signification | Note(s) | +| ----------------- | ------------------------------------------------------| ------- | +| FolderExistError | Harvest folder already exist. | +| FetchError | API-HAL request error. | +| NoResultFound | No result found to harvest. | diff --git a/index.js b/index.js index 2cca386..a9d421c 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ const fs = require('graceful-fs'); const xmlFormatter = require('xml-formatter'); -const utils = require('./lib/utils.js'); +const utils = require('./lib/utils'); const config = require('./conf/conf.json'); const business = {}; @@ -19,16 +19,6 @@ level2: 1 }; -business.finalJob = function (docObjects, cbFinalJob) { - const finalJobLogs = { - processLogs: [], - errLogs: [] - }; - finalJobLogs.processLogs.push(`Harvested TEI-XML file count : ${writtenFilesCount}`); - finalJobLogs.processLogs.push(`Harvest path : ${harvestPath}`); - return cbFinalJob(null, finalJobLogs); -}; - business.doTheJob = function (docObject, cb) { const dateBegin = docObject.halHarvestModifiedDateFrom; const dateEnd = docObject.halHarvestModifiedDateTo; @@ -42,8 +32,8 @@ if (fs.existsSync(harvestPath)) { const err = { - code: 1, - message: harvestPath + ' harvest folder already exist' + code: 'FolderExistError', + _errMsg: harvestPath + ' harvest folder already exist' }; docObject.error = err; return cb(err); @@ -58,6 +48,16 @@ requestByQuery(docObject, query, null, 0, cb); }; +business.finalJob = function (docObjects, cb) { + const finalJobLogs = { + processLogs: [], + errLogs: [] + }; + finalJobLogs.processLogs.push(`Harvested TEI-XML file count : ${writtenFilesCount}`); + finalJobLogs.processLogs.push(`Harvest path : ${harvestPath}`); + return cb(null, finalJobLogs); +}; + /** * requestByQuery : search XML-TEI files and harvest. * @param {Object} docObject : le docObject @@ -85,8 +85,8 @@ const totalResult = parseInt(res.response.numFound); if (totalResult === 0) { const _err = { - code: 3, - message: 'no result found' + code: 'NoResultFound', + _errMsg: 'no result found to harvest' }; docObject.error = _err; return cb(_err); @@ -130,8 +130,8 @@ requestByQuery(docObject, query, cursorMark, retryCount, cb); } else { const _err = { - code: 2, - message: err.message + code: 'FetchError', + _errMsg: err.message }; docObject.error = _err; return cb(_err); diff --git a/lib/utils.js b/lib/utils.js index 3ac3ce3..39b1c6f 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -64,7 +64,7 @@ * @param {String} halQueryUrl * @param {String} cursorMark */ -utils.getScrollUrl = function getScrollUrl (halQueryUrl, cursorMark) { +utils.getScrollUrl = function (halQueryUrl, cursorMark) { const href = halQueryUrl.href.split('?'); const urlBase = href[0]; const sp = new URLSearchParams(href[1]); @@ -73,11 +73,11 @@ return `${urlBase}/?${sp.toString()}`; }; -utils.getHarvestPath = function getHarvestPath (path) { +utils.getHarvestPath = function (path) { return (process.env.CORPUSES_ROOT ? process.env.CORPUSES_ROOT + '/' + path : path); }; -utils.getProxyAgent = function getProxyAgent () { +utils.getProxyAgent = function () { // Get proxy env vars const httpProxy = process.env.HTTP_PROXY ? process.env.HTTP_PROXY : process.env.http_proxy; const httpsProxy = process.env.HTTPS_PROXY ? process.env.HTTPS_PROXY : process.env.https_proxy;