- added doi registration

- npm updates for webpack-encore and postcss-loader
- DatasetExtension.ts: use relation contributors for PersonContributor
- added DoiClient.ts and DoiClientContract.ts
- rozes.ts: addes routes for creating and storing doi identifier
- addes xslt doi_datacite.xslt needed for registering DOI identifier
This commit is contained in:
Kaimbacher 2024-01-26 09:39:03 +01:00
parent ebc62d9117
commit c9ba7d6adc
22 changed files with 1836 additions and 677 deletions

View file

@ -1,5 +1,5 @@
import { BaseCommand, flags } from '@adonisjs/core/build/standalone';
import Logger from '@ioc:Adonis/Core/Logger';
// import Logger from '@ioc:Adonis/Core/Logger';
import { XMLBuilder } from 'xmlbuilder2/lib/interfaces';
import { create } from 'xmlbuilder2';
import Dataset from 'App/Models/Dataset';
@ -7,6 +7,7 @@ import XmlModel from 'App/Library/XmlModel';
import { readFileSync } from 'fs';
import { transform } from 'saxon-js';
import { Client } from '@opensearch-project/opensearch';
import { getDomain } from 'App/Utils/utility-functions';
const opensearchNode = process.env.OPENSEARCH_HOST || 'localhost';
const client = new Client({ node: `http://${opensearchNode}` }); // replace with your OpenSearch endpoint
@ -43,9 +44,9 @@ export default class IndexDatasets extends BaseCommand {
for (var dataset of datasets) {
// Logger.info(`File publish_id ${dataset.publish_id}`);
const jsonString = await this.getJsonString(dataset, proc);
// const jsonString = await this.getJsonString(dataset, proc);
// console.log(jsonString);
await this.indexDocument(dataset, index_name, jsonString);
await this.indexDocument(dataset, index_name, proc);
}
}
@ -57,6 +58,23 @@ export default class IndexDatasets extends BaseCommand {
return await query;
}
private async indexDocument(dataset: Dataset, index_name: string, proc: Buffer): Promise<void> {
try {
const doc = await this.getJsonString(dataset, proc);
let document = JSON.parse(doc);
await client.index({
id: dataset.publish_id?.toString(),
index: index_name,
body: document,
refresh: true,
});
this.logger.info(`dataset with publish_id ${dataset.publish_id} successfully indexed`);
} catch (error) {
this.logger.error(`An error occurred while indexing datsaet with publish_id ${dataset.publish_id}.`);
}
}
private async getJsonString(dataset, proc) {
let xml = create({ version: '1.0', encoding: 'UTF-8', standalone: true }, '<root></root>');
const datasetNode = xml.root().ele('Dataset');
@ -71,29 +89,16 @@ export default class IndexDatasets extends BaseCommand {
});
return result.principalResult;
} catch (error) {
Logger.error(`An error occurred while creating the user, error: ${error.message},`);
this.logger.error(`An error occurred while creating the user, error: ${error.message},`);
return '';
}
}
private async indexDocument(dataset: Dataset, index_name: string, doc: string): Promise<void> {
try {
let document = JSON.parse(doc);
await client.index({
id: dataset.publish_id?.toString(),
index: index_name,
body: document,
refresh: true,
});
Logger.info(`dataset with publish_id ${dataset.publish_id} successfully indexed`);
} catch (error) {
Logger.error(`An error occurred while indexing datsaet with publish_id ${dataset.publish_id}.`);
}
}
private async createXmlRecord(dataset: Dataset, datasetNode: XMLBuilder): Promise<void> {
const domNode = await this.getDatasetXmlDomNode(dataset);
if (domNode) {
dataset.publish_id && this.addLandingPageAttribute(domNode, dataset.publish_id.toString());
this.addSpecInformation(domNode, 'data-type:' + dataset.type);
datasetNode.import(domNode);
}
}
@ -113,4 +118,15 @@ export default class IndexDatasets extends BaseCommand {
const domDocument: XMLBuilder | null = await xmlModel.getDomDocument();
return domDocument;
}
private addSpecInformation(domNode: XMLBuilder, information: string) {
domNode.ele('SetSpec').att('Value', information);
}
private addLandingPageAttribute(domNode: XMLBuilder, dataid: string) {
const baseDomain = process.env.OAI_BASE_DOMAIN || 'localhost';
const url = 'https://' + getDomain(baseDomain) + '/dataset/' + dataid;
// add attribute du dataset xml element
domNode.att('landingpage', url);
}
}