Skip to content
Snippets Groups Projects
Commit 614e2f5e authored by Yogmatee Roochun's avatar Yogmatee Roochun
Browse files

Improvements/code review for XML validation

parent c4454414
No related branches found
No related tags found
2 merge requests!116Shared data model,!117Dev
...@@ -74,7 +74,7 @@ async function processFile(path) { ...@@ -74,7 +74,7 @@ async function processFile(path) {
try { try {
logger.info(`Processing tagged XML packages: ${path}`) logger.info(`Processing tagged XML packages: ${path}`)
const user = await getUser.getFTPUser() const user = await getUser.getTaggerUser()
const userId = user.id const userId = user.id
const tmpPath = await tar.createTempDir() const tmpPath = await tar.createTempDir()
const extractedFilePath = await tar.untar(path, tmpPath) const extractedFilePath = await tar.untar(path, tmpPath)
......
...@@ -2,7 +2,7 @@ const rfr = require('rfr') ...@@ -2,7 +2,7 @@ const rfr = require('rfr')
const User = rfr('server/xpub-model/entities/user/data-access') const User = rfr('server/xpub-model/entities/user/data-access')
module.exports.getFTPUser = function getFTPUser() { module.exports.getTaggerUser = function getTaggerUser() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
User.findByEmail('taggers@internal.ebi.ac.uk') User.findByEmail('taggers@internal.ebi.ac.uk')
.then(user => { .then(user => {
......
...@@ -5,7 +5,6 @@ const xslt4node = require('xslt4node') ...@@ -5,7 +5,6 @@ const xslt4node = require('xslt4node')
const fs = require('fs') const fs = require('fs')
const uuidv4 = require('uuid/v4') const uuidv4 = require('uuid/v4')
const tar = require('../utils/unTar.js') const tar = require('../utils/unTar.js')
const getUser = require('../utils/user.js')
const files = require('../utils/files.js') const files = require('../utils/files.js')
const db = require('../utils/db.js') const db = require('../utils/db.js')
const logger = require('@pubsweet/logger') const logger = require('@pubsweet/logger')
...@@ -20,10 +19,7 @@ xslt4node.addOptions('-Xmx1g') ...@@ -20,10 +19,7 @@ xslt4node.addOptions('-Xmx1g')
// pushXML(`/download/67551d6c-6ef0-446d-a04b-1d98dbc05915.xml`, 'EMS90000') // pushXML(`/download/67551d6c-6ef0-446d-a04b-1d98dbc05915.xml`, 'EMS90000')
module.exports.pushXML = async function pushXML(fileUrl, manuscriptId) { module.exports.pushXML = async function pushXML(fileUrl, manuscriptId, userId) {
const user = await getUser.getAdminUser()
const userId = user.id
try { try {
const downloadUrl = url + fileUrl.replace(/^\/+/g, '') // remove leading slash const downloadUrl = url + fileUrl.replace(/^\/+/g, '') // remove leading slash
const xml = await files.fetchFile(downloadUrl) const xml = await files.fetchFile(downloadUrl)
...@@ -123,10 +119,18 @@ module.exports.pushXML = async function pushXML(fileUrl, manuscriptId) { ...@@ -123,10 +119,18 @@ module.exports.pushXML = async function pushXML(fileUrl, manuscriptId) {
fs.writeFileSync(`${tmpPath}/${manuscriptId}.nxml`, nxml) fs.writeFileSync(`${tmpPath}/${manuscriptId}.nxml`, nxml)
filesArr.push( filesArr.push(
getFileInfo(`${tmpPath}/${manuscriptId}.html`, manuscriptId, user), getFileInfo(
`${tmpPath}/${manuscriptId}.html`,
manuscriptId,
userId,
),
) )
filesArr.push( filesArr.push(
getFileInfo(`${tmpPath}/${manuscriptId}.nxml`, manuscriptId, user), getFileInfo(
`${tmpPath}/${manuscriptId}.nxml`,
manuscriptId,
userId,
),
) )
const uuid = uuidv4() const uuid = uuidv4()
...@@ -185,7 +189,7 @@ module.exports.pushXML = async function pushXML(fileUrl, manuscriptId) { ...@@ -185,7 +189,7 @@ module.exports.pushXML = async function pushXML(fileUrl, manuscriptId) {
} }
} }
function getFileInfo(filepath, manuscriptId, user) { function getFileInfo(filepath, manuscriptId, userId) {
const filename = filepath.substring(filepath.lastIndexOf('/') + 1) const filename = filepath.substring(filepath.lastIndexOf('/') + 1)
const fileExt = path.extname(filepath) const fileExt = path.extname(filepath)
const fileSize = fs.statSync(filepath).size const fileSize = fs.statSync(filepath).size
...@@ -204,7 +208,7 @@ function getFileInfo(filepath, manuscriptId, user) { ...@@ -204,7 +208,7 @@ function getFileInfo(filepath, manuscriptId, user) {
extension: fileExt, extension: fileExt,
mimeType: `${mime.contentType(fileExt)}`, mimeType: `${mime.contentType(fileExt)}`,
manuscriptId, manuscriptId,
updatedBy: user.id, updatedBy: userId,
} }
return fileInfo return fileInfo
} }
......
...@@ -42,7 +42,7 @@ const resolvers = { ...@@ -42,7 +42,7 @@ const resolvers = {
async convertXML(_, { id }, { user }) { async convertXML(_, { id }, { user }) {
try { try {
const xmlFile = await FileManager.find(id) const xmlFile = await FileManager.find(id)
await pushXML(xmlFile.url, xmlFile.manuscriptId) await pushXML(xmlFile.url, xmlFile.manuscriptId, user)
} catch (error) { } catch (error) {
logger.error(error) logger.error(error)
return false return false
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment