Skip to content
Snippets Groups Projects
Commit c834517e authored by Sebastian Mihalache's avatar Sebastian Mihalache :hammer_pick:
Browse files

feat(mts-package): finalized setReviewers and Editors

parent 5496e1ea
No related branches found
No related tags found
3 merge requests!160Update staging with master features,!156Develop,!148Hin 1098
const { get, remove } = require('lodash')
const config = require('config')
const User = require('./User')
const { recommendations: confRecommendations } = config
class Fragment {
constructor({ fragment }) {
this.fragment = fragment
......@@ -146,6 +149,50 @@ class Fragment {
rec => rec.recommendationType === 'review' && rec.submittedOn,
)
}
async getReviewersAndEditorsData({ collection, UserModel }) {
const { recommendations } = this.fragment
const revAndEditorData = await Promise.all(
recommendations.map(async rec => {
const user = await UserModel.find(rec.userId)
let assignmentDate, submissionDate, isReviewer
if (rec.recommendationType === confRecommendations.type.editor) {
if (user.id === collection.handlingEditor.id) {
const editorInvitation = collection.invitations.find(
inv => inv.userId === user.id,
)
assignmentDate = editorInvitation.respondedOn
} else {
assignmentDate = this.fragment.submitted
}
isReviewer = false
} else {
const reviewerInvitation = this.fragment.invitations.find(
inv => inv.userId === user.id,
)
assignmentDate = reviewerInvitation.respondedOn
submissionDate = rec.createdOn
isReviewer = true
}
return {
isReviewer,
submissionDate,
assignmentDate,
email: user.email,
title: user.title,
recommendation: rec,
lastName: user.lastName,
firstName: user.firstName,
}
}),
)
return revAndEditorData
}
}
module.exports = Fragment
......@@ -13,10 +13,10 @@ const { features = {} } = config
const sendMTSPackage = async (collection, fragment) => {
const s3Config = get(config, 'pubsweet-component-aws-s3', {})
const mtsConfig = get(config, 'mts-service', {})
const MTSService = require('pubsweet-component-mts-package')
const { sendPackage } = require('pubsweet-component-mts-package')
const { journal, xmlParser, ftp } = mtsConfig
const MTS = new MTSService(journal, xmlParser, s3Config, ftp)
// const MTS = new MTSService(journal, xmlParser, s3Config, ftp)
const packageFragment = {
...fragment,
metadata: {
......@@ -25,7 +25,14 @@ const sendMTSPackage = async (collection, fragment) => {
},
}
await MTS.sendPackage({ fragment: packageFragment })
// await MTS.sendPackage({ fragment: packageFragment })
await sendPackage({
s3Config,
ftpConfig: ftp,
config: journal,
options: xmlParser,
fragment: packageFragment,
})
}
module.exports = models => async (req, res) => {
......
......@@ -51,13 +51,13 @@ module.exports = models => async (req, res) => {
error: 'Unauthorized.',
})
const fragmentHelper = new Fragment({ fragment })
if (
recommendation === recommendations.publish &&
recommendationType === recommendations.type.editor &&
collection.handlingEditor &&
collection.handlingEditor.id === req.user
) {
const fragmentHelper = new Fragment({ fragment })
if (!fragmentHelper.hasReviewReport()) {
return res
.status(400)
......@@ -94,7 +94,17 @@ module.exports = models => async (req, res) => {
// the manuscript has not yet passed through the EQA process so we need to upload it to the FTP server
if (isEditorInChief && recommendation === 'publish' && !hasEQA) {
if (features.mts) {
await sendMTSPackage({ collection, fragment, isEQA: true })
const fragmentUsers = await fragmentHelper.getReviewersAndEditorsData({
collection,
UserModel: models.User,
})
await sendMTSPackage({
collection,
fragment,
isEQA: true,
fragmentUsers,
})
}
collection.status = 'inQA'
......@@ -168,7 +178,12 @@ module.exports = models => async (req, res) => {
return res.status(200).json(newRecommendation)
}
const sendMTSPackage = async ({ collection, fragment, isEQA = false }) => {
const sendMTSPackage = async ({
fragment,
collection,
isEQA = false,
fragmentUsers = [],
}) => {
const s3Config = get(config, 'pubsweet-component-aws-s3', {})
const mtsConfig = get(config, 'mts-service', {})
const { sendPackage } = require('pubsweet-component-mts-package')
......@@ -185,6 +200,7 @@ const sendMTSPackage = async ({ collection, fragment, isEQA = false }) => {
await sendPackage({
isEQA,
s3Config,
fragmentUsers,
ftpConfig: ftp,
config: journal,
options: xmlParser,
......
......@@ -15,12 +15,19 @@ module.exports = {
sendPackage({
fragment = {},
isEQA = false,
fragmentUsers = [],
config = defaultConfig,
s3Config = defaultS3Config,
ftpConfig = defaultFTPConfig,
options = defaultParseXmlOptions,
}) {
const composedJson = composeJson({ fragment, config, options })
const composedJson = composeJson({
isEQA,
config,
options,
fragment,
fragmentUsers,
})
const xmlFile = convertToXML({
options,
json: composedJson,
......
......@@ -8,6 +8,7 @@ const {
setHistory,
setMetadata,
setQuestions,
setReviewers,
createFileName,
setContributors,
} = require('./templateSetters')
......@@ -26,7 +27,13 @@ module.exports = {
content,
}
},
composeJson: ({ fragment = {}, config, options }) => {
composeJson: ({
config,
options,
isEQA = false,
fragment = {},
fragmentUsers = [],
}) => {
const {
authors = [],
files = [],
......@@ -36,18 +43,29 @@ module.exports = {
} = fragment
const jsonTemplate = getJsonTemplate(config)
return {
const fileName = createFileName({
id: metadata.customId,
prefix: config.prefix,
})
let composedJson = {
...jsonTemplate,
...setMetadata({
options,
metadata,
fileName,
jsonTemplate,
prefix: config.prefix,
}),
...setContributors(authors, jsonTemplate),
...setHistory(submitted, jsonTemplate),
...setFiles(files, jsonTemplate),
...setQuestions(conflicts, jsonTemplate),
}
if (isEQA) {
composedJson = setReviewers(fragmentUsers, jsonTemplate)
}
return composedJson
},
}
......@@ -8,8 +8,7 @@ const manuscriptTypes = config.get('journalConfig.manuscriptTypes')
// const { defaultConfig, defaultParseXmlOptions } = require('../config/default')
module.exports = {
setMetadata({ metadata, jsonTemplate, prefix, options }) {
const fileName = this.createFileName({ id: metadata.customId, prefix })
setMetadata: ({ metadata, jsonTemplate, options, fileName }) => {
const titleGroup = {
'article-title': parseHtml(metadata.title, options),
}
......@@ -227,48 +226,90 @@ module.exports = {
return jsonTemplate
},
createFileName: ({ id = Date.now(), prefix }) => `${prefix}${id}`,
setReviewers: (reviewers = [], jsonTemplate) => {
const contrib = reviewers.map((rev, i) => ({
_attributes: {
'rev-type': 'reviewer',
},
name: {
surname: {
_text: rev.lastName,
setReviewers: (users = [], jsonTemplate) => {
const xmlReviewers = users.map((user, i) => {
const assigmentDate = new Date(user.assignmentDate)
const revType = user.isReviewer ? 'reviewer' : 'editor'
const revObj = {
_attributes: {
'rev-type': revType,
},
'given-names': {
_text: rev.firstName,
name: {
surname: {
_text: user.lastName,
},
'given-names': {
_text: user.firstName,
},
prefix: {
_text: user.title || 'Dr.',
},
},
prefix: {
_text: rev.title || 'Dr.',
email: {
_text: user.email,
},
},
email: {
_text: rev.email,
},
xref: {
_attributes: {
'ref-type': 'aff',
rid: `aff${i + 1}`,
xref: {
_attributes: {
'ref-type': 'aff',
rid: `aff${i + 1}`,
},
},
},
}))
const aff = reviewers.map((rev, i) => ({
date: [
{
_attributes: {
'date-type': 'assignment',
},
day: {
_text: assigmentDate.getDate(),
},
month: {
_text: assigmentDate.getMonth() + 1,
},
year: {
_text: assigmentDate.getFullYear(),
},
},
],
}
if (user.recommendation) {
const submissionDate = new Date(user.submissionDate)
revObj.date.push({
_attributes: {
'date-type': 'submission',
},
day: {
_text: submissionDate.getDate(),
},
month: {
_text: submissionDate.getMonth() + 1,
},
year: {
_text: submissionDate.getFullYear(),
},
})
revObj.comment = user.recommendation.comments.map(comm => ({
_attributes: {
'comment-type': comm.public ? 'comment' : 'Confidential',
},
_text: comm.content,
}))
}
return revObj
})
const aff = users.map((user, i) => ({
_attributes: {
id: `aff${i + 1}`,
},
country: rev.country || 'UK',
country: user.country || 'UK',
'addr-line': {
_text: rev.affiliation || '',
_text: user.affiliation || '',
},
}))
set(
jsonTemplate,
'article.front.article-meta.contrib-group.contrib',
contrib,
)
set(jsonTemplate, 'article.front.article-meta.contrib-group.aff', aff)
set(jsonTemplate, 'article.front.rev-group.rev', xmlReviewers)
set(jsonTemplate, 'article.front.rev-group.aff', aff)
return jsonTemplate
},
......
......@@ -50,7 +50,7 @@
</abstract>
<funding-group></funding-group>
</article-meta>
<rev-group>
<rev-group>
<rev rev-type="reviewer">
<name>
......
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