forked from geolba/tethys.backend
- update to AdonisJS 6
This commit is contained in:
parent
f828ca4491
commit
cb51a4136f
167 changed files with 21485 additions and 21212 deletions
|
@ -1,44 +1,34 @@
|
|||
import { BaseCommand, flags } from '@adonisjs/core/build/standalone';
|
||||
// import Logger from '@ioc:Adonis/Core/Logger';
|
||||
import { XMLBuilder } from 'xmlbuilder2/lib/interfaces';
|
||||
import { XMLBuilder } from 'xmlbuilder2/lib/interfaces.js';
|
||||
import { create } from 'xmlbuilder2';
|
||||
import Dataset from 'App/Models/Dataset';
|
||||
import XmlModel from 'App/Library/XmlModel';
|
||||
import Dataset from '#app/Models/Dataset';
|
||||
import XmlModel from '#app/Library/XmlModel';
|
||||
import { readFileSync } from 'fs';
|
||||
import { transform } from 'saxon-js';
|
||||
import SaxonJS from 'saxon-js';
|
||||
import { Client } from '@opensearch-project/opensearch';
|
||||
import { getDomain } from 'App/Utils/utility-functions';
|
||||
import { getDomain } from '#app/Utils/utility-functions';
|
||||
import { BaseCommand, flags } from '@adonisjs/core/ace';
|
||||
import { CommandOptions } from '@adonisjs/core/types/ace';
|
||||
|
||||
const opensearchNode = process.env.OPENSEARCH_HOST || 'localhost';
|
||||
const client = new Client({ node: `http://${opensearchNode}` }); // replace with your OpenSearch endpoint
|
||||
|
||||
export default class IndexDatasets extends BaseCommand {
|
||||
public static commandName = 'index:datasets';
|
||||
public static description = 'Index datasets based on publish_id';
|
||||
static commandName = 'index:datasets';
|
||||
static description = 'Index datasets based on publish_id';
|
||||
|
||||
@flags.number({ alias: 'p' })
|
||||
public publish_id: number;
|
||||
|
||||
public static settings = {
|
||||
/**
|
||||
* Set the following value to true, if you want to load the application
|
||||
* before running the command. Don't forget to call `node ace generate:manifest`
|
||||
* afterwards.
|
||||
*/
|
||||
static options: CommandOptions = {
|
||||
loadApp: true,
|
||||
|
||||
/**
|
||||
* Set the following value to true, if you want this command to keep running until
|
||||
* you manually decide to exit the process. Don't forget to call
|
||||
* `node ace generate:manifest` afterwards.
|
||||
*/
|
||||
stayAlive: false,
|
||||
staysAlive: false,
|
||||
};
|
||||
|
||||
public async run() {
|
||||
async run() {
|
||||
this.logger.info('Hello world!');
|
||||
// const { default: Dataset } = await import('App/Models/Dataset');
|
||||
const datasets = await this.getDatasets();
|
||||
const { default: Dataset } = await import('#app/Models/Dataset');
|
||||
const datasets = await Dataset.query().where('server_state', 'published').exec(); //this.getDatasets();
|
||||
const proc = readFileSync('public/assets2/solr.sef.json');
|
||||
const index_name = 'tethys-records';
|
||||
|
||||
|
@ -50,13 +40,15 @@ export default class IndexDatasets extends BaseCommand {
|
|||
}
|
||||
}
|
||||
|
||||
private async getDatasets(): Promise<Dataset[]> {
|
||||
const query = Dataset.query().preload('xmlCache').where('server_state', 'published');
|
||||
if (this.publish_id) {
|
||||
query.where('publish_id', this.publish_id);
|
||||
}
|
||||
return await query;
|
||||
}
|
||||
// private async getDatasets(): Promise<any[]> {
|
||||
// // const { default: Dataset } = await import('#app/Models/Dataset');
|
||||
// // const Dataset = (await import('#app/Models/Dataset')).default
|
||||
// const query = Dataset.query().where('server_state', 'published');
|
||||
// if (this.publish_id) {
|
||||
// query.where('publish_id', this.publish_id);
|
||||
// }
|
||||
// return await query;
|
||||
// }
|
||||
|
||||
private async indexDocument(dataset: Dataset, index_name: string, proc: Buffer): Promise<void> {
|
||||
try {
|
||||
|
@ -75,14 +67,14 @@ export default class IndexDatasets extends BaseCommand {
|
|||
}
|
||||
}
|
||||
|
||||
private async getJsonString(dataset, proc) {
|
||||
private async getJsonString(dataset: Dataset, proc: Buffer) {
|
||||
let xml = create({ version: '1.0', encoding: 'UTF-8', standalone: true }, '<root></root>');
|
||||
const datasetNode = xml.root().ele('Dataset');
|
||||
await this.createXmlRecord(dataset, datasetNode);
|
||||
const xmlString = xml.end({ prettyPrint: false });
|
||||
|
||||
try {
|
||||
const result = await transform({
|
||||
const result = await SaxonJS.transform({
|
||||
stylesheetText: proc,
|
||||
destination: 'serialized',
|
||||
sourceText: xmlString,
|
||||
|
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue