Skip to content

Commit

Permalink
Arena mobile files import: check file uuid is in record attribute val…
Browse files Browse the repository at this point in the history
…ues (#3130)

Co-authored-by: Stefano Ricci <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 6, 2023
1 parent c76aa4c commit db01e00
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export default class FilesImportJob extends Job {
const fileName = RecordFile.getName(fileSummary)
throw new Error(`Missing content for file ${fileUuid} (${fileName})`)
}

this.checkFileUuidIsInRecords(fileUuid)

file = RecordFile.assocContent(fileContent)(file)

await this.persistFile(file)
Expand All @@ -39,6 +42,13 @@ export default class FilesImportJob extends Job {
}
}

checkFileUuidIsInRecords(fileUuid) {
const { recordsFileUuids } = this.context
if (recordsFileUuids && !recordsFileUuids.includes(fileUuid)) {
throw new Error(`File UUID ${fileUuid} not found in records`)
}
}

async persistFile(file) {
const { surveyId } = this.context
const fileUuid = RecordFile.getUuid(file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import * as UserService from '@server/modules/user/service/userService'
export default class RecordsImportJob extends DataImportBaseJob {
constructor(params) {
super(RecordsImportJob.type, params)

this.recordsFileUuids = new Set() // used to check validity of file UUIDs in FilesImportJob
}

async execute() {
Expand Down Expand Up @@ -77,6 +79,14 @@ export default class RecordsImportJob extends DataImportBaseJob {
this.logWarn(`${messagePrefix} ${messageContent} ${messageSuffix}`)
delete nodes[nodeUuid]
}

// keep track of file uuids found in record attribute values
if (NodeDef.isFile(nodeDef)) {
const fileUuid = Node.getFileUuid(node)
if (fileUuid) {
this.recordsFileUuids.add(fileUuid)
}
}
})
// assoc nodes and build index from scratch
this.currentRecord = Record.assocNodes({ nodes, sideEffect: true })(record)
Expand Down Expand Up @@ -163,6 +173,11 @@ export default class RecordsImportJob extends DataImportBaseJob {
this.logDebug(`record insert complete (${nodesArray.length} nodes inserted)`)
}

async beforeSuccess() {
await super.beforeSuccess()
this.setContext({ recordsFileUuids: Array.from(this.recordsFileUuids) })
}

generateResult() {
const result = super.generateResult()
result['updatedRecordsUuids'] = Array.from(this.updatedRecordsUuids) // it will be used to refresh records in update threads
Expand Down

0 comments on commit db01e00

Please sign in to comment.