Some checks failed
build.yaml / feat: Enhance background job settings UI and functionality (push) Failing after 0s
- Updated BackgroundJob.vue to improve the display of background job statuses, including missing cross-references and current job mode. - Added auto-refresh functionality for background job status. - Introduced success toast notifications for successful status refreshes. - Modified the XML serialization process in DatasetXmlSerializer for better caching and performance. - Implemented a new RuleProvider for managing custom validation rules. - Improved error handling in routes for loading background job settings. - Enhanced ClamScan configuration with socket support for virus scanning. - Refactored dayjs utility to streamline locale management.
104 lines
3.4 KiB
TypeScript
104 lines
3.4 KiB
TypeScript
import { column, BaseModel, SnakeCaseNamingStrategy, belongsTo } from '@adonisjs/lucid/orm';
|
|
import Dataset from './dataset.js';
|
|
import { builder, create } from 'xmlbuilder2';
|
|
import { XMLBuilder } from 'xmlbuilder2/lib/interfaces.js';
|
|
import db from '@adonisjs/lucid/services/db';
|
|
import { DateTime } from 'luxon';
|
|
import type { BelongsTo } from '@adonisjs/lucid/types/relations';
|
|
import logger from '@adonisjs/core/services/logger';
|
|
|
|
export default class DocumentXmlCache extends BaseModel {
|
|
public static namingStrategy = new SnakeCaseNamingStrategy();
|
|
public static table = 'document_xml_cache';
|
|
// public static fillable: string[] = ['value', 'label', 'type', 'relation'];
|
|
// public static primaryKey = false;
|
|
static primaryKey = ''; // Set primaryKey to null to indicate there is no primary key
|
|
|
|
@column({
|
|
isPrimary: true,
|
|
})
|
|
public document_id: number;
|
|
|
|
@column({})
|
|
public xml_version: number;
|
|
|
|
@column()
|
|
public server_date_modified?: string;
|
|
|
|
// @column.dateTime({
|
|
// autoCreate: true,
|
|
// autoUpdate: true,
|
|
// })
|
|
// public updated_at?: DateTime;
|
|
|
|
@column({})
|
|
public xml_data: string;
|
|
|
|
@belongsTo(() => Dataset, {
|
|
foreignKey: 'document_id',
|
|
})
|
|
public dataset: BelongsTo<typeof Dataset>;
|
|
|
|
/**
|
|
* Get dom document of 'xml_data' string
|
|
*
|
|
* @returns {XMLBuilder}
|
|
*/
|
|
public getDomDocument(): XMLBuilder {
|
|
// const dom = xmlbuilder.create({ version: "1.0", encoding: "UTF-8", standalone: true });
|
|
let dom: XMLBuilder = create({ version: '1.0', encoding: 'UTF-8', standalone: true }, this.xml_data);
|
|
// return dom.first();
|
|
|
|
const rdrDataset = dom.find(
|
|
(n) => {
|
|
const test = n.node.nodeName == 'Rdr_Dataset';
|
|
return test;
|
|
},
|
|
false,
|
|
true,
|
|
)?.node;
|
|
|
|
if (rdrDataset == undefined) {
|
|
return dom.first();
|
|
} else {
|
|
dom = builder({ version: '1.0', encoding: 'UTF-8', standalone: true }, rdrDataset);
|
|
return dom;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check if a valid (non-stale) cache entry exists
|
|
* Cache is valid only if it was created AFTER the dataset's last modification
|
|
*
|
|
* @param datasetId - The dataset ID to check
|
|
* @param datasetServerDateModified - The dataset's last modification timestamp
|
|
* @returns true if valid cache exists, false otherwise
|
|
*/
|
|
public static async hasValidEntry(datasetId: number, datasetServerDateModified: DateTime): Promise<boolean> {
|
|
const serverDateModifiedString: string = datasetServerDateModified.toFormat('yyyy-MM-dd HH:mm:ss'); // Convert DateTime to ISO string
|
|
|
|
const row = await db
|
|
.from(this.table)
|
|
.where('document_id', datasetId)
|
|
.where('server_date_modified', '>', serverDateModifiedString) // Check if server_date_modified is newer or equal
|
|
.first();
|
|
|
|
const isValid = !!row;
|
|
|
|
if (isValid) {
|
|
logger.debug(`Valid cache found for dataset ${datasetId}`);
|
|
} else {
|
|
logger.debug(`No valid cache for dataset ${datasetId} (dataset modified: ${serverDateModifiedString})`);
|
|
}
|
|
|
|
return isValid;
|
|
}
|
|
|
|
/**
|
|
* Invalidate (delete) cache entry
|
|
*/
|
|
public async invalidate(): Promise<void> {
|
|
await this.delete();
|
|
logger.debug(`Invalidated cache for document ${this.document_id}`);
|
|
}
|
|
}
|