diff --git a/app/components/dashboard/AdminDashboard.jsx b/app/components/dashboard/AdminDashboard.jsx index 3920ccfbda070d34ebb37c5034aa1e8202a20025..a6941461c398396684e2f423e5d08a02ad0b0b34 100755 --- a/app/components/dashboard/AdminDashboard.jsx +++ b/app/components/dashboard/AdminDashboard.jsx @@ -17,8 +17,8 @@ const ListTable = styled(Table)` ` const HelpdeskQueue = { 'needs submission QA': ['submitted'], - 'needs xml QA': ['xml-qa'], - 'xml error reported': ['xml-triage'], + 'needs XML QA': ['xml-qa'], + 'XML errors': ['xml-triage'], 'needs citation': ['xml-complete'], } diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index fe4536943ae81f2610a57d35ba4e4eb6b65766f0..d8076206c4a24048a8131a2cbf7c0d987d8efdbf 100755 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -4,13 +4,13 @@ services: app: volumes: # remember to replace /folder_on_disk/ with the path to where you want to store the files on the host machine - "ftpdata:/home/xpub/ftpdata/" - ports: - - "80:80" environment: NODE_ENV: production PORT: "80" env_file: - .env.prod + expose: + - "80" postgres: ports: diff --git a/server/ncbi-integration/fromNcbi.js b/server/ncbi-integration/fromNcbi.js index 3093dfc95a9741ec1ddf4351a2103e7c2b8e7063..e05676b6da4511b4de9a420c3d124c55aa9c70ac 100644 --- a/server/ncbi-integration/fromNcbi.js +++ b/server/ncbi-integration/fromNcbi.js @@ -4,55 +4,69 @@ const fs = require('fs') const os = require('os') const Dom = require('xmldom').DOMParser const logger = require('@pubsweet/logger') -const ManuscriptManager = require('../xpub-model/entities/manuscript') +const lodash = require('lodash') const ManuscriptAccess = require('../xpub-model/entities/manuscript/data-access') +const { + dManuscriptUpdate, + gManuscript, +} = require('../xpub-model/entities/manuscript/helpers/transform') const NCBI_RESPONSE_EXT = new RegExp(/\S+.ld.response.xml$/i) ;(async () => { const beforeUpdate = Date.now() await fromNcbi() - logger.info(`Published check was finished in ${Date.now() - beforeUpdate} ms`) + logger.info(`from ncbi check was finished in ${Date.now() - beforeUpdate} ms`) })() +function close(c) { + c.end() + ManuscriptAccess.knex().destroy() + c = null + process.exit() +} + async function fromNcbi() { let c = new Client() c.on('ready', () => { - c.list(`/${config.get('ncbi-ftp')['send-folder']}`, false, (err, list) => { - if (err) { - c = null - return - } - const responseFiles = list.filter(file => - NCBI_RESPONSE_EXT.test(file.name), - ) - if (!responseFiles.length) { - c.end() - } - responseFiles.forEach((file, index, array) => { - const remoteFilePath = `/${config.get('ncbi-ftp')['send-folder']}/${ - file.name - }` - c.get(remoteFilePath, (err, stream) => { - if (err) return - const path = `${os.tmpdir()}/${file.name}` - stream.pipe(fs.createWriteStream(path)) - processFile(path).then(response => { - updateManuscriptNcbiStatus(file.name, response).then(() => { - c.rename(remoteFilePath, `${remoteFilePath}.processed`, err => { - if (err) { - logger.info(err) - } - if (index === array.length - 1) { - c.end() - c = null - } + c.list( + `/${config.get('ncbi-ftp')['receive-folder']}`, + false, + (err, list) => { + if (err) { + c = null + return + } + const responseFiles = list.filter(file => + NCBI_RESPONSE_EXT.test(file.name), + ) + if (!responseFiles.length) { + close(c) + } + responseFiles.forEach((file, index, array) => { + const remoteFilePath = `/${ + config.get('ncbi-ftp')['receive-folder'] + }/${file.name}` + c.get(remoteFilePath, (err, stream) => { + if (err) return + const path = `${os.tmpdir()}/${file.name}` + stream.pipe(fs.createWriteStream(path)) + processFile(path).then(response => { + updateManuscriptNcbiStatus(file.name, response).then(() => { + c.rename(remoteFilePath, `${remoteFilePath}.processed`, err => { + if (err) { + logger.info(err) + } + if (index === array.length - 1) { + close(c) + } + }) }) }) }) }) - }) - }) + }, + ) }) const { host, user, password } = config.get('ncbi-ftp') c.connect({ host, user, password }) @@ -88,7 +102,7 @@ async function updateManuscriptNcbiStatus(fileName, response) { if (!response.status && response.pmcid) { newIds.push({ pubIdType: 'pmcid', id: response.pmcid }) } - return ManuscriptManager.update({ + return updateManuscript({ id: manuscriptId, status: response.status ? config.get('ncbiFailedState') @@ -97,3 +111,15 @@ async function updateManuscriptNcbiStatus(fileName, response) { 'meta,articleIds': response.pmcid ? newIds : manuscript['meta,articleIds'], }) } + +async function updateManuscript(input) { + const originalMan = await ManuscriptAccess.selectById(input.id) + if (!originalMan) { + throw new Error('Manuscript not found') + } + const manuscriptUpdate = dManuscriptUpdate(input) + lodash.assign(originalMan, manuscriptUpdate) + await originalMan.save() + const updatedMan = await ManuscriptAccess.selectById(input.id, true) + return gManuscript(updatedMan) +} diff --git a/server/ncbi-integration/toNcbi.js b/server/ncbi-integration/toNcbi.js index 52c1aad159fb5a9730f3e043eee56dcb634e0b9e..7a1a9a48de8d8ac0dadcc4d281a538cb499d4154 100644 --- a/server/ncbi-integration/toNcbi.js +++ b/server/ncbi-integration/toNcbi.js @@ -7,41 +7,56 @@ const os = require('os') const config = require('config') const md5File = require('md5-file') const Client = require('ftp') +const lodash = require('lodash') const pubsweetServer = config.get('pubsweet-server.baseUrl') // const ftpLocation = '/home/mselim/test' const ncbiFileTypes = config.get('ncbiFileTypes') -const ManuscriptManager = require('../xpub-model/entities/manuscript') +// const ManuscriptManager = require('../xpub-model/entities/manuscript') +const ManuscriptAccess = require('../xpub-model/entities/manuscript/data-access') +const { + dManuscriptUpdate, + gManuscript, +} = require('../xpub-model/entities/manuscript/helpers/transform') const NCBI_PACKAGE_EXT = '.ld' ;(async () => { const beforeUpdate = Date.now() await toNcbi() - logger.info(`Published check was finished in ${Date.now() - beforeUpdate} ms`) + logger.info(`ncbi check in ${Date.now() - beforeUpdate} ms`) })() async function toNcbi() { - ManuscriptManager.findNcbiReady().then(manuscripts => { - manuscripts.forEach(manuscript => { - logger.info(`Sending package ${manuscript.id} to ncbi FTP location.`) - createTempDir(manuscript).then(tmpPath => - getFiles(tmpPath, manuscript).then(() => - getFunderInfo(manuscript).then(funders => - createManifest(tmpPath, manuscript, funders).then(() => - compress(tmpPath, manuscript).then(destination => { - send(destination, manuscript).then(() => { - tidyUp(tmpPath) - updateManuscriptNcbiStatus(manuscript) - }) - }), + ManuscriptAccess.findNcbiReady() + .then(manuscripts => { + manuscripts.forEach(manuscript => { + logger.info(`Sending package ${manuscript.id} to ncbi FTP location.`) + createTempDir(manuscript).then(tmpPath => + getFiles(tmpPath, manuscript).then(() => + getFunderInfo(manuscript).then(funders => + createManifest(tmpPath, manuscript, funders).then(() => + compress(tmpPath, manuscript).then(destination => { + send(destination, manuscript).then(() => { + tidyUp(tmpPath) + updateManuscriptNcbiStatus(manuscript).then(() => { + ManuscriptAccess.knex().destroy() + process.exit() + }) + }) + }), + ), ), ), - ), - ) + ) + }) + if (!manuscripts.length) { + ManuscriptAccess.knex().destroy() + process.exit() + } }) - }) + .catch(e => logger.error(e)) } function createTempDir(manuscript) { @@ -198,7 +213,7 @@ function send(dest, manuscript) { c.on('ready', () => { c.put( dest, - `/${config.get('ncbi-ftp')['receive-folder']}/${path.basename(dest)}`, + `/${config.get('ncbi-ftp')['send-folder']}/${path.basename(dest)}`, err => { if (err) { reject(err) @@ -247,7 +262,7 @@ function getFileMd5(filePath) { } function updateManuscriptNcbiStatus(manuscript) { - ManuscriptManager.update( + updateManuscript( { id: manuscript.id, status: config.get('ncbiSentState'), @@ -258,3 +273,15 @@ function updateManuscriptNcbiStatus(manuscript) { logger.info(`Created package ${manuscript.id} to ncbi FTP location.`), ) } + +async function updateManuscript(input) { + const originalMan = await ManuscriptAccess.selectById(input.id) + if (!originalMan) { + throw new Error('Manuscript not found') + } + const manuscriptUpdate = dManuscriptUpdate(input) + lodash.assign(originalMan, manuscriptUpdate) + await originalMan.save() + const updatedMan = await ManuscriptAccess.selectById(input.id, true) + return gManuscript(updatedMan) +} diff --git a/server/privacyNotice/privacyNoticeCheck.js b/server/privacyNotice/privacyNoticeCheck.js index 092923259ef56c1a47b5d814122461408dbd734a..6c745868c85416f36c5a4fedefae8cd84d57ea88 100644 --- a/server/privacyNotice/privacyNoticeCheck.js +++ b/server/privacyNotice/privacyNoticeCheck.js @@ -2,7 +2,7 @@ const https = require('https') const PrivacyNotice = require('../xpub-model/entities/privacyNotice/data-access') -const privacyNoticeCheck = () => { +const privacyNoticeCheck = async () => { PrivacyNotice.selectLastVersion().then(privacyNotice => { getLatestVersion().then(data => { const privacyNotesData = data.nodes[0].node @@ -13,11 +13,13 @@ const privacyNoticeCheck = () => { privacyNotesData.changed.split('-')[0].trim(), ), } - PrivacyNotice.insert(latestPrivacyNotice).then(() => - PrivacyNotice.knex().destroy(), - ) + PrivacyNotice.insert(latestPrivacyNotice).then(() => { + PrivacyNotice.knex().destroy() + process.exit() + }) } else { PrivacyNotice.knex().destroy() + process.exit() } }) }) diff --git a/server/xpub-model/entities/manuscript/index.js b/server/xpub-model/entities/manuscript/index.js index 25eeb10cf007a8f5a52b9b9545aff7c232545691..1a6553de207f6c642993f3a1767b0f6906b9c2a0 100755 --- a/server/xpub-model/entities/manuscript/index.js +++ b/server/xpub-model/entities/manuscript/index.js @@ -547,7 +547,6 @@ const Manuscript = { } return true }, - modelName: 'Manuscript', model: ManuscriptAccess, diff --git a/server/xpub-model/entities/team/data-access.js b/server/xpub-model/entities/team/data-access.js index b4be60f968ba75a60499806e0a1bce52774be542..939006c22ce3af09827a815e11e423ad9dc26d57 100755 --- a/server/xpub-model/entities/team/data-access.js +++ b/server/xpub-model/entities/team/data-access.js @@ -16,8 +16,8 @@ class Team extends EpmcBaseModel { // static idColumn = ['article_id', 'member_id']; static get idColumn() { - return ['manuscript_id', 'user_id', 'role_name'] - // return 'id' + // return ['manuscript_id', 'user_id', 'role_name'] + return 'id' } /* diff --git a/wrapperScript.sh b/wrapperScript.sh index 486dda96720c4b0803f8cedf65f135abb46f980e..c170cbd3866f65c727e72a3c16abb9c6433160c4 100755 --- a/wrapperScript.sh +++ b/wrapperScript.sh @@ -9,7 +9,7 @@ echo "Wait up to 3 minutes for server to respond, check every 20 seconds" COUNTER=0 while [ $COUNTER -lt 15 ]; do - RUNNING=$(curl --silent --connect-timeout 20 "$PUBSWEET_URL" | grep "/assets/") + RUNNING=$(curl --silent --connect-timeout 20 "http://localhost:$PORT" | grep "/assets/") if [ -n "$RUNNING" ] ; then echo "xPub is running" #echo "Creating the Users"