@natlibfi/melinda-rest-api-commons 5.0.3 → 5.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/amqp.js +235 -0
- package/dist/amqp.js.map +7 -0
- package/dist/constants.js +49 -0
- package/dist/constants.js.map +7 -0
- package/dist/{conversion.js.map → helpers/conversion.js.map} +1 -1
- package/dist/{fix-constants.js.map → helpers/fix-constants.js.map} +1 -1
- package/dist/{fix-handle-tempurns.js.map → helpers/fix-handle-tempurns.js.map} +1 -1
- package/dist/{fix-strip-f884s.js.map → helpers/fix-strip-f884s.js.map} +1 -1
- package/dist/{fix-utils.js.map → helpers/fix-utils.js.map} +1 -1
- package/dist/{fix.js.map → helpers/fix.js.map} +1 -1
- package/dist/{validation.js.map → helpers/validation.js.map} +1 -1
- package/dist/index.js +10 -0
- package/dist/index.js.map +7 -0
- package/dist/mongo.js +486 -0
- package/dist/mongo.js.map +7 -0
- package/dist/mongoLog.js +184 -0
- package/dist/mongoLog.js.map +7 -0
- package/dist/utils.js +102 -0
- package/dist/utils.js.map +7 -0
- package/package.json +2 -2
- /package/dist/{conversion.js → helpers/conversion.js} +0 -0
- /package/dist/{fix-constants.js → helpers/fix-constants.js} +0 -0
- /package/dist/{fix-handle-tempurns.js → helpers/fix-handle-tempurns.js} +0 -0
- /package/dist/{fix-strip-f884s.js → helpers/fix-strip-f884s.js} +0 -0
- /package/dist/{fix-utils.js → helpers/fix-utils.js} +0 -0
- /package/dist/{fix.js → helpers/fix.js} +0 -0
- /package/dist/{validation.js → helpers/validation.js} +0 -0
package/dist/mongo.js
ADDED
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
import { MongoClient, GridFSBucket, MongoDriverError } from "mongodb";
|
|
2
|
+
import moment from "moment";
|
|
3
|
+
import httpStatus from "http-status";
|
|
4
|
+
import sanitize from "mongo-sanitize";
|
|
5
|
+
import createDebugLogger from "debug";
|
|
6
|
+
import { createLogger } from "@natlibfi/melinda-backend-commons";
|
|
7
|
+
import { Error as ApiError, parseBoolean } from "@natlibfi/melinda-commons";
|
|
8
|
+
import { QUEUE_ITEM_STATE, IMPORT_JOB_STATE, OPERATIONS } from "./constants.js";
|
|
9
|
+
import { logError } from "./utils.js";
|
|
10
|
+
export default async function(MONGO_URI, collection, db = "rest-api") {
|
|
11
|
+
const logger = createLogger();
|
|
12
|
+
const debug = createDebugLogger("@natlibfi/melinda-rest-api-commons/mongo");
|
|
13
|
+
const debugDev = debug.extend(":dev");
|
|
14
|
+
const client = await MongoClient.connect(MONGO_URI);
|
|
15
|
+
const dbConnection = client.db(db);
|
|
16
|
+
const gridFSBucket = new GridFSBucket(dbConnection, { bucketName: collection });
|
|
17
|
+
const operator = dbConnection.collection(collection);
|
|
18
|
+
debugDev(`mongo: ${MONGO_URI}, db: ${db}, collection: ${collection}`);
|
|
19
|
+
return { createPrio, createBulk, checkAndSetState, checkAndSetImportJobState, query, createProjection, queryById, checkTimeOut, remove, readContent, removeContent, getOne, getStream, setState, setImportJobState, pushIds, pushMessages, setOperation, setOperations, addBlobSize, setBlobSize };
|
|
20
|
+
async function createPrio({ correlationId, cataloger, oCatalogerIn, operation, operationSettings }) {
|
|
21
|
+
debugDev("createPrio");
|
|
22
|
+
const time = moment().toDate();
|
|
23
|
+
const newQueueItem = {
|
|
24
|
+
correlationId,
|
|
25
|
+
cataloger,
|
|
26
|
+
operation,
|
|
27
|
+
operations: [operation],
|
|
28
|
+
oCatalogerIn,
|
|
29
|
+
operationSettings: {
|
|
30
|
+
prio: true,
|
|
31
|
+
...operationSettings
|
|
32
|
+
},
|
|
33
|
+
queueItemState: QUEUE_ITEM_STATE.VALIDATOR.PENDING_VALIDATION,
|
|
34
|
+
blobSize: 1,
|
|
35
|
+
importJobState: {
|
|
36
|
+
CREATE: IMPORT_JOB_STATE.EMPTY,
|
|
37
|
+
UPDATE: IMPORT_JOB_STATE.EMPTY,
|
|
38
|
+
FIX: IMPORT_JOB_STATE.EMPTY
|
|
39
|
+
},
|
|
40
|
+
records: [],
|
|
41
|
+
errorMessage: "",
|
|
42
|
+
errorStatus: "",
|
|
43
|
+
creationTime: time,
|
|
44
|
+
modificationTime: time
|
|
45
|
+
};
|
|
46
|
+
try {
|
|
47
|
+
debugDev(`Inserting: ${JSON.stringify(newQueueItem)} to ${collection}}`);
|
|
48
|
+
const result = await operator.insertOne(newQueueItem);
|
|
49
|
+
debugDev(JSON.stringify(result));
|
|
50
|
+
if (result.acknowledged) {
|
|
51
|
+
logger.info(`New PRIO queue item for ${operation} ${correlationId} has been made in ${collection}`);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
const errorMessage = error.payload || error.message || "";
|
|
57
|
+
logError(error);
|
|
58
|
+
throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async function createBulk({ correlationId, cataloger, oCatalogerIn, operation, contentType, recordLoadParams, stream, operationSettings }) {
|
|
62
|
+
const time = moment().toDate();
|
|
63
|
+
const newQueueItem = {
|
|
64
|
+
correlationId,
|
|
65
|
+
cataloger,
|
|
66
|
+
oCatalogerIn,
|
|
67
|
+
operation,
|
|
68
|
+
operations: [operation],
|
|
69
|
+
operationSettings: {
|
|
70
|
+
prio: false,
|
|
71
|
+
...operationSettings
|
|
72
|
+
},
|
|
73
|
+
contentType,
|
|
74
|
+
recordLoadParams,
|
|
75
|
+
queueItemState: stream ? QUEUE_ITEM_STATE.VALIDATOR.UPLOADING : QUEUE_ITEM_STATE.VALIDATOR.WAITING_FOR_RECORDS,
|
|
76
|
+
blobSize: 0,
|
|
77
|
+
importJobState: {
|
|
78
|
+
CREATE: IMPORT_JOB_STATE.EMPTY,
|
|
79
|
+
UPDATE: IMPORT_JOB_STATE.EMPTY,
|
|
80
|
+
FIX: IMPORT_JOB_STATE.EMPTY
|
|
81
|
+
},
|
|
82
|
+
records: [],
|
|
83
|
+
errorMessage: "",
|
|
84
|
+
errorStatus: "",
|
|
85
|
+
creationTime: time,
|
|
86
|
+
modificationTime: time
|
|
87
|
+
};
|
|
88
|
+
if (stream) {
|
|
89
|
+
debug(`Creating streamBulk`);
|
|
90
|
+
try {
|
|
91
|
+
await new Promise((resolve, reject) => {
|
|
92
|
+
const outputStream = gridFSBucket.openUploadStream(correlationId);
|
|
93
|
+
stream.on("error", reject).on("data", (chunk) => outputStream.write(chunk)).on("end", () => outputStream.end(void 0, void 0, () => {
|
|
94
|
+
resolve(correlationId);
|
|
95
|
+
}));
|
|
96
|
+
});
|
|
97
|
+
logger.info(`New BULK queue item for ${operation} ${correlationId} has been made in ${collection}!`);
|
|
98
|
+
debug(`New BULK queue item for ${operation} ${correlationId} has been made in ${collection}!`);
|
|
99
|
+
return operator.insertOne(newQueueItem);
|
|
100
|
+
} catch (error) {
|
|
101
|
+
const errorMessage = error.payload || error.message || "";
|
|
102
|
+
logError(error);
|
|
103
|
+
throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
logger.debug(`No stream`);
|
|
107
|
+
debug(`Creating noStreamBulk`);
|
|
108
|
+
if (!stream) {
|
|
109
|
+
try {
|
|
110
|
+
const result = await operator.insertOne(newQueueItem);
|
|
111
|
+
if (result.acknowledged) {
|
|
112
|
+
logger.info(`New noStream BULK queue item for ${operation} ${correlationId} has been made in ${collection}`);
|
|
113
|
+
debug(`New noStream BULK queue item for ${operation} ${correlationId} has been made in ${collection}`);
|
|
114
|
+
return { correlationId, queueItemState: QUEUE_ITEM_STATE.VALIDATOR.WAITING_FOR_RECORDS };
|
|
115
|
+
}
|
|
116
|
+
throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);
|
|
117
|
+
} catch (error) {
|
|
118
|
+
const errorMessage = error.payload || error.message || "";
|
|
119
|
+
logError(error);
|
|
120
|
+
throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async function checkAndSetState({ correlationId, state, errorMessage = void 0, errorStatus = void 0 }) {
|
|
125
|
+
const timeOut = await checkTimeOut({ correlationId });
|
|
126
|
+
if (timeOut) {
|
|
127
|
+
return setState({ correlationId, state, errorMessage, errorStatus });
|
|
128
|
+
}
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
async function checkAndSetImportJobState({ correlationId, operation, importJobState }) {
|
|
132
|
+
logger.debug(`${correlationId}, ${importJobState}, ${operation}`);
|
|
133
|
+
const timeOut = await checkTimeOut({ correlationId, operation, importJobState });
|
|
134
|
+
if (timeOut) {
|
|
135
|
+
return setImportJobState({ correlationId, operation, importJobState });
|
|
136
|
+
}
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
async function query(params, showParams = {}) {
|
|
140
|
+
logger.debug(`Querying: ${JSON.stringify(params)}, ${JSON.stringify(showParams)}`);
|
|
141
|
+
debug(`Querying: ${JSON.stringify(params)}, ${JSON.stringify(showParams)}`);
|
|
142
|
+
const { limit = 1e3, skip = 0, ...rest } = params;
|
|
143
|
+
const result = await operator.find(rest, { projection: createProjection(showParams) }).limit(parseInt(limit, 10)).skip(parseInt(skip, 10)).toArray();
|
|
144
|
+
logger.debug(`Query result: ${result.length > 0 ? "Found!" : "Not found!"}`);
|
|
145
|
+
logger.silly(`${JSON.stringify(result)}`);
|
|
146
|
+
debug(`${JSON.stringify(result)}`);
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
function createProjection(showParams = {}) {
|
|
150
|
+
logger.silly(`Creating projection for query: ${JSON.stringify(showParams)}`);
|
|
151
|
+
debug(`Creating projection for query: ${JSON.stringify(showParams)}`);
|
|
152
|
+
const { showAll = 0, showOperations = 0, showOperationSettings = 0, showRecordLoadParams = 0, showImportJobState = 0 } = showParams;
|
|
153
|
+
const combinedShowParams = {
|
|
154
|
+
showAll,
|
|
155
|
+
showOperations,
|
|
156
|
+
showOperationSettings,
|
|
157
|
+
showRecordLoadParams,
|
|
158
|
+
showImportJobState
|
|
159
|
+
};
|
|
160
|
+
logger.debug(`showAll: ${showAll}, showOperations: ${showOperations}, showOperationSettings: ${showOperationSettings}, showRecordLoadParams: ${showRecordLoadParams}, showImportJobState: ${showImportJobState}`);
|
|
161
|
+
debug(`showAll: ${showAll}, showOperations: ${showOperations}, showOperationSettings: ${showOperationSettings}, showRecordLoadParams: ${showRecordLoadParams}, showImportJobState: ${showImportJobState}`);
|
|
162
|
+
debug(`${JSON.stringify(combinedShowParams)}`);
|
|
163
|
+
if (parseBoolean(showAll)) {
|
|
164
|
+
debug(`ShowAll: ${showAll}`);
|
|
165
|
+
return {
|
|
166
|
+
_id: 0
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
const showParamToField = {
|
|
170
|
+
"showOperations": "operations",
|
|
171
|
+
"showOperationSettings": "operationSettings",
|
|
172
|
+
"showRecordLoadParams": "recordLoadParams",
|
|
173
|
+
"showImportJobState": "importJobState"
|
|
174
|
+
};
|
|
175
|
+
const result = Object.keys(combinedShowParams).filter((param) => param !== "showAll" && !parseBoolean(combinedShowParams[param])).filter((param) => showParamToField[param]).map((param) => showParamToField[param]);
|
|
176
|
+
logger.silly(`We want to exclude from projection: ${JSON.stringify(result)}`);
|
|
177
|
+
debug(`We want to exclude from projection: ${JSON.stringify(result)}`);
|
|
178
|
+
const excludeObject = Object.fromEntries(result.map((param) => [param, 0]));
|
|
179
|
+
logger.silly(`We want to exclude from projection: ${JSON.stringify(excludeObject)}`);
|
|
180
|
+
debug(`We want to exclude from projection: ${JSON.stringify(excludeObject)}`);
|
|
181
|
+
return {
|
|
182
|
+
_id: 0,
|
|
183
|
+
...excludeObject
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
async function queryById({ correlationId, checkModTime = false }) {
|
|
187
|
+
if (checkModTime) {
|
|
188
|
+
debug(`queryById checkModTime: ${checkModTime}`);
|
|
189
|
+
await checkTimeOut({ correlationId });
|
|
190
|
+
return queryById({ correlationId });
|
|
191
|
+
}
|
|
192
|
+
const result = await operator.findOne({ correlationId }, { projection: { _id: 0 } });
|
|
193
|
+
return result;
|
|
194
|
+
}
|
|
195
|
+
async function checkTimeOut({ correlationId }) {
|
|
196
|
+
const { modificationTime, queueItemState: oldState, importJobState } = await operator.findOne({ correlationId });
|
|
197
|
+
if ([QUEUE_ITEM_STATE.ABORT, QUEUE_ITEM_STATE.ERROR, QUEUE_ITEM_STATE.DONE].includes(oldState)) {
|
|
198
|
+
logger.silly(`${correlationId} has already state: ${oldState}`);
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
const timeoutTime = moment(modificationTime).add(1, "m");
|
|
202
|
+
logger.silly(`${correlationId} timeOut @ ${timeoutTime}`);
|
|
203
|
+
if (timeoutTime.isBefore()) {
|
|
204
|
+
const finalImportJobStates = [IMPORT_JOB_STATE.ABORT, IMPORT_JOB_STATE.DONE, IMPORT_JOB_STATE.EMPTY, IMPORT_JOB_STATE.ERROR];
|
|
205
|
+
if (!finalImportJobStates.includes(importJobState.CREATE)) {
|
|
206
|
+
await setImportJobState({ correlationId, operation: "CREATE", importJobState: IMPORT_JOB_STATE.ABORT });
|
|
207
|
+
}
|
|
208
|
+
if (!finalImportJobStates.includes(importJobState.UPDATE)) {
|
|
209
|
+
await setImportJobState({ correlationId, operation: "UPDATE", importJobState: IMPORT_JOB_STATE.ABORT });
|
|
210
|
+
}
|
|
211
|
+
if (!finalImportJobStates.includes(importJobState.FIX)) {
|
|
212
|
+
await setImportJobState({ correlationId, operation: "FIX", importJobState: IMPORT_JOB_STATE.ABORT });
|
|
213
|
+
}
|
|
214
|
+
await setState({ correlationId, state: QUEUE_ITEM_STATE.ABORT, errorStatus: httpStatus.REQUEST_TIMEOUT, errorMessage: `Timeout in ${oldState}` });
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
async function remove(params) {
|
|
220
|
+
logger.silly(`${JSON.stringify(params)}`);
|
|
221
|
+
logger.info(`Removing from Mongo (${collection}) id: ${params.correlationId}`);
|
|
222
|
+
debug(`${JSON.stringify(params)}`);
|
|
223
|
+
debug(`Removing from Mongo (${collection}) id: ${params.correlationId}`);
|
|
224
|
+
const clean = sanitize(params.correlationId);
|
|
225
|
+
logger.silly(`mongo/remove: clean: ${JSON.stringify(clean)}`);
|
|
226
|
+
debug(`mongo/remove: clean: ${JSON.stringify(clean)}`);
|
|
227
|
+
try {
|
|
228
|
+
const noContent = await removeContent({ correlationId: params.correlationId });
|
|
229
|
+
debug(`noContent (removeContent result): ${JSON.stringify(noContent)}`);
|
|
230
|
+
if (noContent) {
|
|
231
|
+
const deleteResult = await operator.deleteOne({ correlationId: clean });
|
|
232
|
+
debug(`deleteResult: ${JSON.stringify(deleteResult)}`);
|
|
233
|
+
return true;
|
|
234
|
+
}
|
|
235
|
+
} catch (err) {
|
|
236
|
+
if (err instanceof MongoDriverError) {
|
|
237
|
+
debug(err);
|
|
238
|
+
if (err.message.indexOf("File not found for id") !== -1) {
|
|
239
|
+
logger.silly(`mongo/remove: File not found, removing queueItem ${JSON.stringify(clean)} from ${collection}`);
|
|
240
|
+
debug(`mongo/remove: File not found, removing queueItem ${JSON.stringify(clean)} from ${collection}`);
|
|
241
|
+
await operator.deleteOne({ correlationId: clean });
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
244
|
+
logger.error(err.message);
|
|
245
|
+
throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, err.message);
|
|
246
|
+
}
|
|
247
|
+
throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, err.message);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
async function readContent(correlationId) {
|
|
251
|
+
logger.info(`Reading content from mongo for id: ${correlationId} in ${collection}`);
|
|
252
|
+
debug(`Reading content from mongo for id: ${correlationId} in ${collection}`);
|
|
253
|
+
const clean = sanitize(correlationId);
|
|
254
|
+
debug(clean);
|
|
255
|
+
const result = await operator.findOne({ correlationId: clean });
|
|
256
|
+
debug(result);
|
|
257
|
+
if (result) {
|
|
258
|
+
const { operationSettings } = result;
|
|
259
|
+
if (operationSettings.prio === false && operationSettings.noStream === false) {
|
|
260
|
+
return {
|
|
261
|
+
contentType: result.contentType,
|
|
262
|
+
readStream: gridFSBucket.openDownloadStreamByName(clean)
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
logger.debug(`OperationSettings for ${correlationId}: ${JSON.stringify(operationSettings)}`);
|
|
266
|
+
debug(`OperationSettings for ${correlationId}: ${JSON.stringify(operationSettings)}`);
|
|
267
|
+
debug(`Content is only available for streamBulk jobs. ${correlationId} is not a streamBulk job.`);
|
|
268
|
+
throw new ApiError(httpStatus.BAD_REQUEST, { message: `Content is only available for streamBulk jobs. ${correlationId} is not a streamBulk job.` });
|
|
269
|
+
}
|
|
270
|
+
throw new ApiError(httpStatus.NOT_FOUND, { message: `Job ${correlationId} not found.` });
|
|
271
|
+
}
|
|
272
|
+
async function removeContent(params) {
|
|
273
|
+
logger.info(`Removing content from mongo for id: ${params.correlationId} in ${collection}`);
|
|
274
|
+
debug(`Removing content from mongo for id: ${params.correlationId} in ${collection}`);
|
|
275
|
+
const clean = sanitize(params.correlationId);
|
|
276
|
+
const result = await gridFSBucket.find({ filename: clean }).toArray();
|
|
277
|
+
debug(`mongo/removeContent: find bucket result ${JSON.stringify(result)}`);
|
|
278
|
+
if (result.length > 0) {
|
|
279
|
+
const [firstBucketResult] = result;
|
|
280
|
+
const fileId = firstBucketResult._id;
|
|
281
|
+
await gridFSBucket.delete(fileId);
|
|
282
|
+
return true;
|
|
283
|
+
}
|
|
284
|
+
logger.debug(`No files for ${params.correlationId} to delete`);
|
|
285
|
+
return true;
|
|
286
|
+
}
|
|
287
|
+
function getOne({ queueItemState, importJobState = void 0 }) {
|
|
288
|
+
logger.silly(`queueItemState: ${queueItemState}, importJobState: ${JSON.stringify(importJobState)}`);
|
|
289
|
+
const cleanQueueItemState = queueItemState ? { queueItemState: sanitize(queueItemState) } : void 0;
|
|
290
|
+
const options = { projection: { _id: 0 } };
|
|
291
|
+
try {
|
|
292
|
+
if (queueItemState && importJobState === void 0) {
|
|
293
|
+
logger.silly(`Checking DB ${collection} for just ${JSON.stringify(cleanQueueItemState.queueItemState)}`);
|
|
294
|
+
return operator.findOne({ ...cleanQueueItemState }, options);
|
|
295
|
+
}
|
|
296
|
+
if (importJobState && queueItemState === void 0) {
|
|
297
|
+
logger.silly(`Checking DB ${collection} for ${JSON.stringify(importJobState)}`);
|
|
298
|
+
return operator.findOne({ ...importJobState }, options);
|
|
299
|
+
}
|
|
300
|
+
if (importJobState && queueItemState) {
|
|
301
|
+
logger.silly(`Checking DB ${collection} for ${queueItemState} and ${JSON.stringify(importJobState)}`);
|
|
302
|
+
return operator.findOne({ ...cleanQueueItemState, ...importJobState }, options);
|
|
303
|
+
}
|
|
304
|
+
logger.debug(`getOne not working!`);
|
|
305
|
+
throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, "Missing parameters, cannot get queueItem");
|
|
306
|
+
} catch (error) {
|
|
307
|
+
const errorMessage = error.payload || error.message || "";
|
|
308
|
+
logError(error);
|
|
309
|
+
throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
function getStream(correlationId) {
|
|
313
|
+
logger.info(`Forming stream from mongo for ${correlationId} in ${collection}`);
|
|
314
|
+
const clean = sanitize(correlationId);
|
|
315
|
+
try {
|
|
316
|
+
return gridFSBucket.openDownloadStreamByName(clean);
|
|
317
|
+
} catch (error) {
|
|
318
|
+
const errorMessage = error.payload || error.message || "";
|
|
319
|
+
logError(error);
|
|
320
|
+
throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
async function pushIds({ correlationId, handledIds, rejectedIds }) {
|
|
324
|
+
logger.verbose(`Push ids (${handledIds.length}) and rejectedIds (${rejectedIds.length}) ${correlationId} to ${collection}`);
|
|
325
|
+
logger.debug(`ids (${handledIds.length}): ${JSON.stringify(handledIds)}, rejectedIds ${rejectedIds.length}: ${JSON.stringify(rejectedIds)}`);
|
|
326
|
+
const clean = sanitize(correlationId);
|
|
327
|
+
await operator.updateOne({
|
|
328
|
+
correlationId: clean
|
|
329
|
+
}, {
|
|
330
|
+
$set: {
|
|
331
|
+
modificationTime: moment().toDate()
|
|
332
|
+
},
|
|
333
|
+
$push: {
|
|
334
|
+
handledIds: { $each: handledIds },
|
|
335
|
+
rejectedIds: { $each: rejectedIds }
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
async function pushMessages({ correlationId, messages, messageField = "messages" }) {
|
|
340
|
+
logger.verbose(`Push messages (${messages.length}) to ${messageField} ${correlationId} to ${collection}`);
|
|
341
|
+
logger.silly(`Messages (${messages.length}): ${JSON.stringify(messages)}}`);
|
|
342
|
+
const clean = sanitize(correlationId);
|
|
343
|
+
const cleanMessageField = sanitize(messageField);
|
|
344
|
+
debug(`${messageField} -> ${cleanMessageField}`);
|
|
345
|
+
await operator.updateOne({
|
|
346
|
+
correlationId: clean
|
|
347
|
+
}, {
|
|
348
|
+
$set: {
|
|
349
|
+
modificationTime: moment().toDate()
|
|
350
|
+
},
|
|
351
|
+
$push: {
|
|
352
|
+
[cleanMessageField]: { $each: messages }
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
function setState({ correlationId, state, errorMessage = void 0, errorStatus = void 0 }) {
|
|
357
|
+
const errorString = errorMessage || errorStatus ? `, Error message: '${JSON.stringify(errorMessage) || ""}', Error status: '${errorStatus || ""}'` : "";
|
|
358
|
+
logger.info(`Setting queue-item state ${state} for ${correlationId}${errorString} to ${collection}`);
|
|
359
|
+
const stateInQueueItemStates = Object.values(QUEUE_ITEM_STATE).indexOf(state) > -1;
|
|
360
|
+
const stateInQueueItemStatesValidator = Object.values(QUEUE_ITEM_STATE.VALIDATOR).indexOf(state) > -1;
|
|
361
|
+
const stateInQueueItemStatesImporter = Object.values(QUEUE_ITEM_STATE.IMPORTER).indexOf(state) > -1;
|
|
362
|
+
if (!stateInQueueItemStates && !stateInQueueItemStatesValidator && !stateInQueueItemStatesImporter) {
|
|
363
|
+
debug(`Trying to set invalid state ${state}`);
|
|
364
|
+
throw new ApiError(httpStatus.BAD_REQUEST, "Trying to set invalid state");
|
|
365
|
+
}
|
|
366
|
+
const clean = sanitize(correlationId);
|
|
367
|
+
const updateValues = {
|
|
368
|
+
queueItemState: state,
|
|
369
|
+
modificationTime: moment().toDate(),
|
|
370
|
+
errorMessage,
|
|
371
|
+
errorStatus
|
|
372
|
+
};
|
|
373
|
+
Object.keys(updateValues).forEach((key) => updateValues[key] === void 0 && delete updateValues[key]);
|
|
374
|
+
return operator.findOneAndUpdate(
|
|
375
|
+
{ correlationId: clean },
|
|
376
|
+
{ $set: updateValues },
|
|
377
|
+
{ projection: { _id: 0 }, returnDocument: "after" }
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
function setImportJobState({ correlationId, operation, importJobState }) {
|
|
381
|
+
logger.info(`Setting queue-item importJobState: {${operation}: ${importJobState}} for ${correlationId}`);
|
|
382
|
+
debug(`Setting queue-item importJobState: {${operation}: ${importJobState}} for ${correlationId}`);
|
|
383
|
+
const cleanCorrelationId = sanitize(correlationId);
|
|
384
|
+
const cleanImportJobState = sanitize(importJobState);
|
|
385
|
+
if (!(operation in OPERATIONS)) {
|
|
386
|
+
debug(`Error: ${operation} is not in ${JSON.stringify(OPERATIONS)}`);
|
|
387
|
+
throw new ApiError(httpStatus.BAD_REQUEST, "Invalid operation for import job state");
|
|
388
|
+
}
|
|
389
|
+
if (!(cleanImportJobState in IMPORT_JOB_STATE)) {
|
|
390
|
+
debug(`Error: ${cleanImportJobState} is not in ${JSON.stringify(IMPORT_JOB_STATE)}`);
|
|
391
|
+
throw new ApiError(httpStatus.BAD_REQUEST, "Invalid import job state");
|
|
392
|
+
}
|
|
393
|
+
const newJobState = getNewJobState(operation, cleanImportJobState);
|
|
394
|
+
function getNewJobState(operation2, cleanImportJobState2) {
|
|
395
|
+
if (operation2 === OPERATIONS.CREATE) {
|
|
396
|
+
return { "importJobState.CREATE": cleanImportJobState2 };
|
|
397
|
+
}
|
|
398
|
+
if (operation2 === OPERATIONS.UPDATE) {
|
|
399
|
+
return { "importJobState.UPDATE": cleanImportJobState2 };
|
|
400
|
+
}
|
|
401
|
+
if (operation2 === OPERATIONS.FIX) {
|
|
402
|
+
return { "importJobState.FIX": cleanImportJobState2 };
|
|
403
|
+
}
|
|
404
|
+
throw new ApiError("400", "Invalid operation for import job state");
|
|
405
|
+
}
|
|
406
|
+
return operator.findOneAndUpdate({
|
|
407
|
+
correlationId: cleanCorrelationId
|
|
408
|
+
}, {
|
|
409
|
+
$set: {
|
|
410
|
+
...newJobState,
|
|
411
|
+
modificationTime: moment().toDate()
|
|
412
|
+
}
|
|
413
|
+
}, { projection: { _id: 0 }, returnDocument: "after" });
|
|
414
|
+
}
|
|
415
|
+
async function setOperation({ correlationId, operation }) {
|
|
416
|
+
const newOperation = operation;
|
|
417
|
+
const { operation: oldOperation } = await operator.findOne({ correlationId });
|
|
418
|
+
logger.info(`Setting queue-item operation from ${oldOperation} to ${newOperation} for ${correlationId} to ${collection}`);
|
|
419
|
+
const cleanCorrelationId = sanitize(correlationId);
|
|
420
|
+
const cleanNewOperation = sanitize(newOperation);
|
|
421
|
+
const result = await operator.findOneAndUpdate({
|
|
422
|
+
correlationId: cleanCorrelationId
|
|
423
|
+
}, {
|
|
424
|
+
$set: {
|
|
425
|
+
operation: cleanNewOperation,
|
|
426
|
+
modificationTime: moment().toDate()
|
|
427
|
+
}
|
|
428
|
+
}, { projection: { _id: 0 }, returnDocument: "after" });
|
|
429
|
+
debugDev(`${JSON.stringify(result)}`);
|
|
430
|
+
return result.ok || result;
|
|
431
|
+
}
|
|
432
|
+
async function setOperations({ correlationId, addOperation, removeOperation = void 0 }) {
|
|
433
|
+
const cleanCorrelationId = sanitize(correlationId);
|
|
434
|
+
const queueItem = await operator.findOne({ correlationId: cleanCorrelationId });
|
|
435
|
+
logger.silly(`We found a queueItem: ${JSON.stringify(queueItem)}`);
|
|
436
|
+
const oldOperations = queueItem.operations;
|
|
437
|
+
logger.info(`Setting queue-item operations from ${JSON.stringify(oldOperations)} by adding ${addOperation} and removing ${removeOperation} for ${correlationId} to ${collection}`);
|
|
438
|
+
const operationsAfterRemove = oldOperations.filter((operation) => operation !== removeOperation);
|
|
439
|
+
const operationsAfterRemoveAndAdd = operationsAfterRemove.includes(addOperation) ? operationsAfterRemove : [...operationsAfterRemove, addOperation];
|
|
440
|
+
logger.silly(`operationsAfterRemove: ${operationsAfterRemove}`);
|
|
441
|
+
logger.silly(`operationAfterRemoveAndAdd: ${operationsAfterRemoveAndAdd}`);
|
|
442
|
+
const result = await operator.findOneAndUpdate({
|
|
443
|
+
correlationId: cleanCorrelationId
|
|
444
|
+
}, {
|
|
445
|
+
$set: {
|
|
446
|
+
operations: operationsAfterRemoveAndAdd,
|
|
447
|
+
modificationTime: moment().toDate()
|
|
448
|
+
}
|
|
449
|
+
}, { projection: { _id: 0 }, returnDocument: "after" });
|
|
450
|
+
debugDev(`${JSON.stringify(result)}`);
|
|
451
|
+
return result.ok || result;
|
|
452
|
+
}
|
|
453
|
+
async function addBlobSize({ correlationId }) {
|
|
454
|
+
const cleanCorrelationId = sanitize(correlationId);
|
|
455
|
+
const result = await operator.findOneAndUpdate({
|
|
456
|
+
correlationId: cleanCorrelationId,
|
|
457
|
+
queueItemState: QUEUE_ITEM_STATE.VALIDATOR.WAITING_FOR_RECORDS
|
|
458
|
+
}, {
|
|
459
|
+
$inc: {
|
|
460
|
+
blobSize: 1
|
|
461
|
+
},
|
|
462
|
+
$set: {
|
|
463
|
+
modificationTime: moment().toDate()
|
|
464
|
+
}
|
|
465
|
+
}, { projection: { _id: 0 }, returnDocument: "after" });
|
|
466
|
+
logger.verbose(`AddBlobSizeResult in mongo: ${JSON.stringify(result)}`);
|
|
467
|
+
debugDev(`${JSON.stringify(result)}`);
|
|
468
|
+
return result;
|
|
469
|
+
}
|
|
470
|
+
async function setBlobSize({ correlationId, blobSize }) {
|
|
471
|
+
const cleanCorrelationId = sanitize(correlationId);
|
|
472
|
+
const cleanBlobSize = sanitize(blobSize);
|
|
473
|
+
const result = await operator.findOneAndUpdate({
|
|
474
|
+
correlationId: cleanCorrelationId
|
|
475
|
+
}, {
|
|
476
|
+
$set: {
|
|
477
|
+
blobSize: cleanBlobSize,
|
|
478
|
+
modificationTime: moment().toDate()
|
|
479
|
+
}
|
|
480
|
+
}, { projection: { _id: 0 }, returnDocument: "after" });
|
|
481
|
+
logger.verbose(`SetBlobSizeResult in mongo: ${JSON.stringify(result)}`);
|
|
482
|
+
debugDev(`${JSON.stringify(result)}`);
|
|
483
|
+
return result;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
//# sourceMappingURL=mongo.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/mongo.js"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable max-lines */\n\nimport {MongoClient, GridFSBucket, MongoDriverError} from 'mongodb';\nimport moment from 'moment';\nimport httpStatus from 'http-status';\nimport sanitize from 'mongo-sanitize';\nimport createDebugLogger from 'debug';\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\nimport {Error as ApiError, parseBoolean} from '@natlibfi/melinda-commons';\nimport {QUEUE_ITEM_STATE, IMPORT_JOB_STATE, OPERATIONS} from './constants.js';\nimport {logError} from './utils.js';\n\n//import isDeepStrictEqual from 'util';\n\n/* QueueItem:\n{\n \"correlationId\":\"FOO\",\n \"cataloger\":\"xxx0000\",\n \"oCatalogerIn\":\"xxx0000\"\n \"operation\":\"UPDATE\",\n \"operations\":[\"UPDATE\", \"CREATE\"]\n \"contentType\":\"application/json\",\n \"recordLoadParams\": {\n \"pActiveLibrary\": \"XXX00\",\n \"pInputFile\": \"filename.seq\",\n \"pRejectFile\": \"filename.rej\",\n \"pLogFile\": \"filename.syslog\",\n \"pOldNew\": \"NEW\"\n },\n \"queueItemState\":\"PENDING_QUEUING\",\n \"importJobState\": {\n \"CREATE\": \"EMPTY\",\n \"UPDATE\": \"EMPTY\"\n },\n blobSize: 1,\n records: [],\n errorMessage: '',\n errorStatus: '',\n \"creationTime\":\"2020-01-01T00:00:00.000Z\",\n \"modificationTime\":\"2020-01-01T00:00:01.000Z\",\n}\n*/\n\nexport default async function (MONGO_URI, collection, db = 'rest-api') {\n const logger = createLogger();\n const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo');\n const debugDev = debug.extend(':dev');\n\n // Connect to mongo (MONGO)\n const client = await MongoClient.connect(MONGO_URI);\n const dbConnection = client.db(db);\n const gridFSBucket = new GridFSBucket(dbConnection, {bucketName: collection});\n const operator = dbConnection.collection(collection);\n debugDev(`mongo: ${MONGO_URI}, db: ${db}, collection: ${collection}`);\n\n return {createPrio, createBulk, checkAndSetState, checkAndSetImportJobState, query, createProjection, queryById, checkTimeOut, remove, readContent, removeContent, getOne, getStream, setState, setImportJobState, pushIds, pushMessages, setOperation, setOperations, addBlobSize, setBlobSize};\n\n async function createPrio({correlationId, cataloger, oCatalogerIn, operation, operationSettings}) {\n debugDev('createPrio');\n const time = moment().toDate();\n const newQueueItem = {\n correlationId,\n cataloger,\n operation,\n operations: [operation],\n oCatalogerIn,\n operationSettings: {\n prio: true,\n ...operationSettings\n },\n queueItemState: QUEUE_ITEM_STATE.VALIDATOR.PENDING_VALIDATION,\n blobSize: 1,\n importJobState: {\n CREATE: IMPORT_JOB_STATE.EMPTY,\n UPDATE: IMPORT_JOB_STATE.EMPTY,\n FIX: IMPORT_JOB_STATE.EMPTY\n },\n records: [],\n errorMessage: '',\n errorStatus: '',\n creationTime: time,\n modificationTime: time\n };\n try {\n debugDev(`Inserting: ${JSON.stringify(newQueueItem)} to ${collection}}`);\n const result = await operator.insertOne(newQueueItem);\n debugDev(JSON.stringify(result));\n if (result.acknowledged) {\n logger.info(`New PRIO queue item for ${operation} ${correlationId} has been made in ${collection}`);\n return;\n }\n // TEST-COVERAGE: this error is not (currently) tested\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);\n } catch (error) {\n // TEST-COVERAGE: this error is not (currently) tested\n const errorMessage = error.payload || error.message || '';\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);\n }\n }\n\n async function createBulk({correlationId, cataloger, oCatalogerIn, operation, contentType, recordLoadParams, stream, operationSettings}) {\n const time = moment().toDate();\n const newQueueItem = {\n correlationId,\n cataloger,\n oCatalogerIn,\n operation,\n operations: [operation],\n operationSettings: {\n prio: false,\n ...operationSettings\n },\n contentType,\n recordLoadParams,\n queueItemState: stream ? QUEUE_ITEM_STATE.VALIDATOR.UPLOADING : QUEUE_ITEM_STATE.VALIDATOR.WAITING_FOR_RECORDS,\n blobSize: 0,\n importJobState: {\n CREATE: IMPORT_JOB_STATE.EMPTY,\n UPDATE: IMPORT_JOB_STATE.EMPTY,\n FIX: IMPORT_JOB_STATE.EMPTY\n },\n records: [],\n errorMessage: '',\n errorStatus: '',\n creationTime: time,\n modificationTime: time\n };\n\n if (stream) {\n debug(`Creating streamBulk`);\n try {\n await new Promise((resolve, reject) => {\n const outputStream = gridFSBucket.openUploadStream(correlationId);\n\n stream\n .on('error', reject)\n .on('data', chunk => outputStream.write(chunk))\n .on('end', () => outputStream.end(undefined, undefined, () => {\n resolve(correlationId);\n }));\n });\n logger.info(`New BULK queue item for ${operation} ${correlationId} has been made in ${collection}!`);\n debug(`New BULK queue item for ${operation} ${correlationId} has been made in ${collection}!`);\n return operator.insertOne(newQueueItem);\n } catch (error) {\n const errorMessage = error.payload || error.message || '';\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);\n }\n }\n\n logger.debug(`No stream`);\n debug(`Creating noStreamBulk`);\n if (!stream) {\n try {\n const result = await operator.insertOne(newQueueItem);\n if (result.acknowledged) {\n logger.info(`New noStream BULK queue item for ${operation} ${correlationId} has been made in ${collection}`);\n debug(`New noStream BULK queue item for ${operation} ${correlationId} has been made in ${collection}`);\n return {correlationId, queueItemState: QUEUE_ITEM_STATE.VALIDATOR.WAITING_FOR_RECORDS};\n }\n // TEST-COVERAGE: this error is not (currently) tested\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);\n } catch (error) {\n // TEST-COVERAGE: this error is not (currently) tested\n const errorMessage = error.payload || error.message || '';\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);\n }\n }\n }\n\n // Check state that the queueItem has not waited too long and set state\n // Optionally set also queueItems errorStatus & errorMessage\n async function checkAndSetState({correlationId, state, errorMessage = undefined, errorStatus = undefined}) {\n // checkTimeOut returns true, if queueItem is fresher than 1 minute and it's state is not ABORT/ERROR/DONE\n // otherwise it sets queueItem and importJobStates to state ABORT and add errorStatus and errorMessage (408, 'Timeout')\n const timeOut = await checkTimeOut({correlationId});\n if (timeOut) {\n return setState({correlationId, state, errorMessage, errorStatus});\n }\n return false;\n }\n\n // Check state that the queueItem has not waited too long and set importJobState\n // Note: checkAndSetImportJobState cannot be used to set queueItems errorStatus & errorMessage (expect in case of a TimeOut)\n async function checkAndSetImportJobState({correlationId, operation, importJobState}) {\n // checkTimeOut returns true, if queueItem is fresher than 1 minute and it's state is not ABORT/ERROR/DONE\n // otherwise it sets queueItem and importJobStates to state ABORT and errorStatue and errorMessage (408, 'Timeout')\n logger.debug(`${correlationId}, ${importJobState}, ${operation}`);\n const timeOut = await checkTimeOut({correlationId, operation, importJobState});\n if (timeOut) {\n return setImportJobState({correlationId, operation, importJobState});\n }\n return false;\n }\n\n async function query(params, showParams = {}) {\n logger.debug(`Querying: ${JSON.stringify(params)}, ${JSON.stringify(showParams)}`);\n debug(`Querying: ${JSON.stringify(params)}, ${JSON.stringify(showParams)}`);\n const {limit = 1000, skip = 0, ...rest} = params;\n\n const result = await operator.find(rest, {projection: createProjection(showParams)})\n .limit(parseInt(limit, 10))\n .skip(parseInt(skip, 10))\n .toArray();\n logger.debug(`Query result: ${result.length > 0 ? 'Found!' : 'Not found!'}`);\n logger.silly(`${JSON.stringify(result)}`);\n debug(`${JSON.stringify(result)}`);\n return result;\n }\n\n // We default to NOT showing operations, operationSettings, recordLoadParams and importJobState when a queueItem is queried\n // These can all be shown with showAll\n // Single fields can be shown by showOperation, showOperationSettings, showRecordLoadParams and showImportJobState\n\n function createProjection(showParams = {}) {\n logger.silly(`Creating projection for query: ${JSON.stringify(showParams)}`);\n debug(`Creating projection for query: ${JSON.stringify(showParams)}`);\n const {showAll = 0, showOperations = 0, showOperationSettings = 0, showRecordLoadParams = 0, showImportJobState = 0} = showParams;\n const combinedShowParams = {\n showAll,\n showOperations,\n showOperationSettings,\n showRecordLoadParams,\n showImportJobState\n };\n logger.debug(`showAll: ${showAll}, showOperations: ${showOperations}, showOperationSettings: ${showOperationSettings}, showRecordLoadParams: ${showRecordLoadParams}, showImportJobState: ${showImportJobState}`);\n debug(`showAll: ${showAll}, showOperations: ${showOperations}, showOperationSettings: ${showOperationSettings}, showRecordLoadParams: ${showRecordLoadParams}, showImportJobState: ${showImportJobState}`);\n debug(`${JSON.stringify(combinedShowParams)}`);\n\n // NOTE: parseBoolean parses any non-empty, non-\"false\" string as true!\n if (parseBoolean(showAll)) {\n //if (showAll === true || showAll === '1' || showAll === 1) {\n debug(`ShowAll: ${showAll}`);\n return {\n _id: 0\n };\n }\n\n const showParamToField = {\n 'showOperations': 'operations',\n 'showOperationSettings': 'operationSettings',\n 'showRecordLoadParams': 'recordLoadParams',\n 'showImportJobState': 'importJobState'\n };\n\n const result = Object.keys(combinedShowParams)\n //.filter(param => param !== 'showAll' && combinedShowParams[param] !== true && combinedShowParams[param] !== 1 && combinedShowParams[param] !== '1')\n .filter(param => param !== 'showAll' && !parseBoolean(combinedShowParams[param]))\n .filter(param => showParamToField[param])\n .map((param) => showParamToField[param]);\n logger.silly(`We want to exclude from projection: ${JSON.stringify(result)}`);\n debug(`We want to exclude from projection: ${JSON.stringify(result)}`);\n\n\n const excludeObject = Object.fromEntries(result.map(param => [param, 0]));\n logger.silly(`We want to exclude from projection: ${JSON.stringify(excludeObject)}`);\n debug(`We want to exclude from projection: ${JSON.stringify(excludeObject)}`);\n\n\n return {\n _id: 0,\n ...excludeObject\n };\n }\n\n // Note: edited in v4.2.4 to return queueItem *after* possible timout has aborted it\n // Note: previous versions returned queueItem *before* its state/queueItemState is timeOuted\n async function queryById({correlationId, checkModTime = false}) {\n if (checkModTime) {\n debug(`queryById checkModTime: ${checkModTime}`);\n await checkTimeOut({correlationId});\n return queryById({correlationId});\n }\n const result = await operator.findOne({correlationId}, {projection: {_id: 0}});\n return result;\n }\n\n // Check that if the item has waited too long\n // If the last modification time for the queueItem is older than 1 minute\n // set state to ABORT and return false, otherwise return true\n // If the state is already ABORT or ERROR or DONE return false\n\n async function checkTimeOut({correlationId}) {\n const {modificationTime, queueItemState: oldState, importJobState} = await operator.findOne({correlationId});\n //debug(`${modificationTime} - oldState: ${oldState}`);\n // should we check for DONE too?\n if ([QUEUE_ITEM_STATE.ABORT, QUEUE_ITEM_STATE.ERROR, QUEUE_ITEM_STATE.DONE].includes(oldState)) {\n logger.silly(`${correlationId} has already state: ${oldState}`);\n return false;\n }\n\n const timeoutTime = moment(modificationTime).add(1, 'm');\n logger.silly(`${correlationId} timeOut @ ${timeoutTime}`);\n\n if (timeoutTime.isBefore()) {\n const finalImportJobStates = [IMPORT_JOB_STATE.ABORT, IMPORT_JOB_STATE.DONE, IMPORT_JOB_STATE.EMPTY, IMPORT_JOB_STATE.ERROR];\n if (!finalImportJobStates.includes(importJobState.CREATE)) {\n await setImportJobState({correlationId, operation: 'CREATE', importJobState: IMPORT_JOB_STATE.ABORT});\n }\n\n if (!finalImportJobStates.includes(importJobState.UPDATE)) {\n await setImportJobState({correlationId, operation: 'UPDATE', importJobState: IMPORT_JOB_STATE.ABORT});\n }\n\n if (!finalImportJobStates.includes(importJobState.FIX)) {\n await setImportJobState({correlationId, operation: 'FIX', importJobState: IMPORT_JOB_STATE.ABORT});\n }\n\n await setState({correlationId, state: QUEUE_ITEM_STATE.ABORT, errorStatus: httpStatus.REQUEST_TIMEOUT, errorMessage: `Timeout in ${oldState}`});\n\n return false;\n }\n\n return true;\n }\n\n async function remove(params) {\n logger.silly(`${JSON.stringify(params)}`);\n logger.info(`Removing from Mongo (${collection}) id: ${params.correlationId}`);\n debug(`${JSON.stringify(params)}`);\n debug(`Removing from Mongo (${collection}) id: ${params.correlationId}`);\n const clean = sanitize(params.correlationId);\n logger.silly(`mongo/remove: clean: ${JSON.stringify(clean)}`);\n debug(`mongo/remove: clean: ${JSON.stringify(clean)}`);\n\n\n try {\n //const metadataResult = await getFileMetadata({filename: clean});\n //logger.debug(`mongo/remove: metadataResult: ${JSON.stringify(metadataResult)}`);\n const noContent = await removeContent({correlationId: params.correlationId});\n debug(`noContent (removeContent result): ${JSON.stringify(noContent)}`);\n if (noContent) {\n const deleteResult = await operator.deleteOne({correlationId: clean});\n debug(`deleteResult: ${JSON.stringify(deleteResult)}`);\n return true;\n }\n } catch (err) {\n // TEST-COVERAGE: this error is not (currently) tested\n if (err instanceof MongoDriverError) {\n debug(err);\n if (err.message.indexOf('File not found for id') !== -1) {\n logger.silly(`mongo/remove: File not found, removing queueItem ${JSON.stringify(clean)} from ${collection}`);\n debug(`mongo/remove: File not found, removing queueItem ${JSON.stringify(clean)} from ${collection}`);\n await operator.deleteOne({correlationId: clean});\n return true;\n }\n logger.error(err.message);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, err.message);\n }\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, err.message);\n }\n }\n\n async function readContent(correlationId) {\n logger.info(`Reading content from mongo for id: ${correlationId} in ${collection}`);\n debug(`Reading content from mongo for id: ${correlationId} in ${collection}`);\n\n const clean = sanitize(correlationId);\n debug(clean);\n\n const result = await operator.findOne({correlationId: clean}); // njsscan-ignore: node_nosqli_injection\n debug(result);\n if (result) {\n const {operationSettings} = result;\n if (operationSettings.prio === false && operationSettings.noStream === false) {\n return {\n contentType: result.contentType,\n readStream: gridFSBucket.openDownloadStreamByName(clean)\n };\n }\n logger.debug(`OperationSettings for ${correlationId}: ${JSON.stringify(operationSettings)}`);\n debug(`OperationSettings for ${correlationId}: ${JSON.stringify(operationSettings)}`);\n debug(`Content is only available for streamBulk jobs. ${correlationId} is not a streamBulk job.`);\n throw new ApiError(httpStatus.BAD_REQUEST, {message: `Content is only available for streamBulk jobs. ${correlationId} is not a streamBulk job.`});\n }\n\n throw new ApiError(httpStatus.NOT_FOUND, {message: `Job ${correlationId} not found.`});\n }\n\n async function removeContent(params) {\n logger.info(`Removing content from mongo for id: ${params.correlationId} in ${collection}`);\n debug(`Removing content from mongo for id: ${params.correlationId} in ${collection}`);\n const clean = sanitize(params.correlationId);\n\n const result = await gridFSBucket.find({filename: clean}).toArray();\n debug(`mongo/removeContent: find bucket result ${JSON.stringify(result)}`);\n\n\n if (result.length > 0) {\n // Note: we assume and handle just one file for filename!\n const [firstBucketResult] = result;\n const fileId = firstBucketResult._id;\n\n await gridFSBucket.delete(fileId);\n return true;\n }\n\n logger.debug(`No files for ${params.correlationId} to delete`);\n return true;\n }\n\n function getOne({queueItemState, importJobState = undefined}) {\n //params example: \"queueItemState\": \"IMPORTER.IN_QUEUE\", \"importJobState\":{\"importJobState.UPDATE\": \"IN_QUEUE\"}\n logger.silly(`queueItemState: ${queueItemState}, importJobState: ${JSON.stringify(importJobState)}`);\n //debug(`queueItemState: ${queueItemState}, importJobState: ${JSON.stringify(importJobState)}`);\n const cleanQueueItemState = queueItemState ? {queueItemState: sanitize(queueItemState)} : undefined;\n const options = {projection: {_id: 0}};\n\n try {\n\n // Just queueItemState\n if (queueItemState && importJobState === undefined) {\n logger.silly(`Checking DB ${collection} for just ${JSON.stringify(cleanQueueItemState.queueItemState)}`);\n //debug(`Checking DB ${collection} for just ${JSON.stringify(cleanQueueItemState.queueItemState)}`);\n return operator.findOne({...cleanQueueItemState}, options);\n }\n\n // importJobState\n if (importJobState && queueItemState === undefined) {\n logger.silly(`Checking DB ${collection} for ${JSON.stringify(importJobState)}`);\n //debug(`Checking DB ${collection} for ${JSON.stringify(importJobState)}`);\n return operator.findOne({...importJobState}, options);\n }\n\n // importJobState and queueItemState\n if (importJobState && queueItemState) {\n logger.silly(`Checking DB ${collection} for ${queueItemState} and ${JSON.stringify(importJobState)}`);\n //debug(`Checking DB ${collection} for ${queueItemState} and ${JSON.stringify(importJobState)}`);\n return operator.findOne({...cleanQueueItemState, ...importJobState}, options);\n }\n\n logger.debug(`getOne not working!`);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, 'Missing parameters, cannot get queueItem');\n\n } catch (error) {\n const errorMessage = error.payload || error.message || '';\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);\n }\n }\n\n function getStream(correlationId) {\n logger.info(`Forming stream from mongo for ${correlationId} in ${collection}`);\n const clean = sanitize(correlationId);\n try {\n // Return content stream\n return gridFSBucket.openDownloadStreamByName(clean);\n } catch (error) {\n // TEST-COVERAGE: this error is not (currently) tested\n const errorMessage = error.payload || error.message || '';\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);\n }\n }\n\n async function pushIds({correlationId, handledIds, rejectedIds}) {\n logger.verbose(`Push ids (${handledIds.length}) and rejectedIds (${rejectedIds.length}) ${correlationId} to ${collection}`);\n logger.debug(`ids (${handledIds.length}): ${JSON.stringify(handledIds)}, rejectedIds ${rejectedIds.length}: ${JSON.stringify(rejectedIds)}`);\n const clean = sanitize(correlationId);\n await operator.updateOne({\n correlationId: clean\n }, {\n $set: {\n modificationTime: moment().toDate()\n },\n $push: {\n handledIds: {$each: handledIds},\n rejectedIds: {$each: rejectedIds}\n }\n });\n }\n\n async function pushMessages({correlationId, messages, messageField = 'messages'}) {\n logger.verbose(`Push messages (${messages.length}) to ${messageField} ${correlationId} to ${collection}`);\n logger.silly(`Messages (${messages.length}): ${JSON.stringify(messages)}}`);\n const clean = sanitize(correlationId);\n const cleanMessageField = sanitize(messageField);\n debug(`${messageField} -> ${cleanMessageField}`);\n await operator.updateOne({\n correlationId: clean\n }, {\n $set: {\n modificationTime: moment().toDate()\n },\n $push: {\n [cleanMessageField]: {$each: messages}\n }\n });\n }\n\n function setState({correlationId, state, errorMessage = undefined, errorStatus = undefined}) {\n const errorString = errorMessage || errorStatus ? `, Error message: '${JSON.stringify(errorMessage) || ''}', Error status: '${errorStatus || ''}'` : '';\n logger.info(`Setting queue-item state ${state} for ${correlationId}${errorString} to ${collection}`);\n\n const stateInQueueItemStates = Object.values(QUEUE_ITEM_STATE).indexOf(state) > -1;\n const stateInQueueItemStatesValidator = Object.values(QUEUE_ITEM_STATE.VALIDATOR).indexOf(state) > -1;\n const stateInQueueItemStatesImporter = Object.values(QUEUE_ITEM_STATE.IMPORTER).indexOf(state) > -1;\n if (!stateInQueueItemStates && !stateInQueueItemStatesValidator && !stateInQueueItemStatesImporter) {\n debug(`Trying to set invalid state ${state}`);\n throw new ApiError(httpStatus.BAD_REQUEST, 'Trying to set invalid state');\n }\n\n const clean = sanitize(correlationId);\n const updateValues = {\n queueItemState: state,\n modificationTime: moment().toDate(),\n errorMessage,\n errorStatus\n };\n\n // Do not update value that are undefined\n Object.keys(updateValues).forEach(key => updateValues[key] === undefined && delete updateValues[key]);\n\n return operator\n .findOneAndUpdate(\n {correlationId: clean},\n {$set: updateValues},\n {projection: {_id: 0}, returnDocument: 'after'}\n );\n }\n\n function setImportJobState({correlationId, operation, importJobState}) {\n\n // should this also get importJobState as previously created object? {}\n logger.info(`Setting queue-item importJobState: {${operation}: ${importJobState}} for ${correlationId}`);\n debug(`Setting queue-item importJobState: {${operation}: ${importJobState}} for ${correlationId}`);\n const cleanCorrelationId = sanitize(correlationId);\n const cleanImportJobState = sanitize(importJobState);\n\n if (!(operation in OPERATIONS)) {\n debug(`Error: ${operation} is not in ${JSON.stringify(OPERATIONS)}`);\n throw new ApiError(httpStatus.BAD_REQUEST, 'Invalid operation for import job state');\n }\n\n if (!(cleanImportJobState in IMPORT_JOB_STATE)) {\n debug(`Error: ${cleanImportJobState} is not in ${JSON.stringify(IMPORT_JOB_STATE)}`);\n throw new ApiError(httpStatus.BAD_REQUEST, 'Invalid import job state');\n }\n\n const newJobState = getNewJobState(operation, cleanImportJobState);\n\n\n function getNewJobState(operation, cleanImportJobState) {\n if (operation === OPERATIONS.CREATE) {\n return {'importJobState.CREATE': cleanImportJobState};\n }\n if (operation === OPERATIONS.UPDATE) {\n return {'importJobState.UPDATE': cleanImportJobState};\n }\n if (operation === OPERATIONS.FIX) {\n return {'importJobState.FIX': cleanImportJobState};\n }\n // istanbul ignore next\n // Ignoring for coverage - we error this already\n throw new ApiError('400', 'Invalid operation for import job state');\n }\n\n return operator.findOneAndUpdate({\n correlationId: cleanCorrelationId\n }, {\n $set: {\n ...newJobState,\n modificationTime: moment().toDate()\n }\n }, {projection: {_id: 0}, returnDocument: 'after'});\n }\n\n async function setOperation({correlationId, operation}) {\n const newOperation = operation;\n const {operation: oldOperation} = await operator.findOne({correlationId});\n logger.info(`Setting queue-item operation from ${oldOperation} to ${newOperation} for ${correlationId} to ${collection}`);\n const cleanCorrelationId = sanitize(correlationId);\n const cleanNewOperation = sanitize(newOperation);\n\n const result = await operator.findOneAndUpdate({\n correlationId: cleanCorrelationId\n }, {\n $set: {\n operation: cleanNewOperation,\n modificationTime: moment().toDate()\n }\n }, {projection: {_id: 0}, returnDocument: 'after'});\n debugDev(`${JSON.stringify(result)}`);\n return result.ok || result;\n // logger.debug(JSON.stringify(result));\n }\n\n async function setOperations({correlationId, addOperation, removeOperation = undefined}) {\n const cleanCorrelationId = sanitize(correlationId);\n\n const queueItem = await operator.findOne({correlationId: cleanCorrelationId});\n logger.silly(`We found a queueItem: ${JSON.stringify(queueItem)}`);\n\n const oldOperations = queueItem.operations;\n\n logger.info(`Setting queue-item operations from ${JSON.stringify(oldOperations)} by adding ${addOperation} and removing ${removeOperation} for ${correlationId} to ${collection}`);\n\n const operationsAfterRemove = oldOperations.filter(operation => operation !== removeOperation);\n const operationsAfterRemoveAndAdd = operationsAfterRemove.includes(addOperation) ? operationsAfterRemove : [...operationsAfterRemove, addOperation];\n\n logger.silly(`operationsAfterRemove: ${operationsAfterRemove}`);\n logger.silly(`operationAfterRemoveAndAdd: ${operationsAfterRemoveAndAdd}`);\n\n const result = await operator.findOneAndUpdate({\n correlationId: cleanCorrelationId\n }, {\n $set: {\n operations: operationsAfterRemoveAndAdd,\n modificationTime: moment().toDate()\n }\n }, {projection: {_id: 0}, returnDocument: 'after'});\n debugDev(`${JSON.stringify(result)}`);\n return result.ok || result;\n // logger.debug(JSON.stringify(result));\n }\n\n async function addBlobSize({correlationId}) {\n const cleanCorrelationId = sanitize(correlationId);\n\n const result = await operator.findOneAndUpdate({\n correlationId: cleanCorrelationId,\n queueItemState: QUEUE_ITEM_STATE.VALIDATOR.WAITING_FOR_RECORDS\n }, {\n $inc: {\n blobSize: 1\n },\n $set: {\n modificationTime: moment().toDate()\n }\n }, {projection: {_id: 0}, returnDocument: 'after'});\n\n logger.verbose(`AddBlobSizeResult in mongo: ${JSON.stringify(result)}`);\n debugDev(`${JSON.stringify(result)}`);\n return result;\n }\n\n async function setBlobSize({correlationId, blobSize}) {\n const cleanCorrelationId = sanitize(correlationId);\n const cleanBlobSize = sanitize(blobSize);\n\n const result = await operator.findOneAndUpdate({\n correlationId: cleanCorrelationId\n }, {\n $set: {\n blobSize: cleanBlobSize,\n modificationTime: moment().toDate()\n }\n }, {projection: {_id: 0}, returnDocument: 'after'});\n\n logger.verbose(`SetBlobSizeResult in mongo: ${JSON.stringify(result)}`);\n debugDev(`${JSON.stringify(result)}`);\n return result;\n }\n\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAQ,aAAa,cAAc,wBAAuB;AAC1D,OAAO,YAAY;AACnB,OAAO,gBAAgB;AACvB,OAAO,cAAc;AACrB,OAAO,uBAAuB;AAC9B,SAAQ,oBAAmB;AAC3B,SAAQ,SAAS,UAAU,oBAAmB;AAC9C,SAAQ,kBAAkB,kBAAkB,kBAAiB;AAC7D,SAAQ,gBAAe;AAiCvB,8BAA+B,WAAW,YAAY,KAAK,YAAY;AACrE,QAAM,SAAS,aAAa;AAC5B,QAAM,QAAQ,kBAAkB,0CAA0C;AAC1E,QAAM,WAAW,MAAM,OAAO,MAAM;AAGpC,QAAM,SAAS,MAAM,YAAY,QAAQ,SAAS;AAClD,QAAM,eAAe,OAAO,GAAG,EAAE;AACjC,QAAM,eAAe,IAAI,aAAa,cAAc,EAAC,YAAY,WAAU,CAAC;AAC5E,QAAM,WAAW,aAAa,WAAW,UAAU;AACnD,WAAS,UAAU,SAAS,SAAS,EAAE,iBAAiB,UAAU,EAAE;AAEpE,SAAO,EAAC,YAAY,YAAY,kBAAkB,2BAA2B,OAAO,kBAAkB,WAAW,cAAc,QAAQ,aAAa,eAAe,QAAQ,WAAW,UAAU,mBAAmB,SAAS,cAAc,cAAc,eAAe,aAAa,YAAW;AAE/R,iBAAe,WAAW,EAAC,eAAe,WAAW,cAAc,WAAW,kBAAiB,GAAG;AAChG,aAAS,YAAY;AACrB,UAAM,OAAO,OAAO,EAAE,OAAO;AAC7B,UAAM,eAAe;AAAA,MACnB;AAAA,MACA;AAAA,MACA;AAAA,MACA,YAAY,CAAC,SAAS;AAAA,MACtB;AAAA,MACA,mBAAmB;AAAA,QACjB,MAAM;AAAA,QACN,GAAG;AAAA,MACL;AAAA,MACA,gBAAgB,iBAAiB,UAAU;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