- npm updates, delete cd 0.3.3
- aslo add collection for GetRecord request - add src/utils/utility-functions.ts - don't create empty xml caches
This commit is contained in:
parent
ea568123f1
commit
10b1fb0c86
10 changed files with 133 additions and 77 deletions
|
@ -40,14 +40,14 @@ export class App extends Server {
|
|||
next();
|
||||
});
|
||||
|
||||
// this.app.use(bodyParser.json());
|
||||
// this.app.use(bodyParser.json());
|
||||
// for parsing application/json
|
||||
this.app.use(bodyParser.json({ limit: "100mb" }));
|
||||
// for parsing application/xwww-
|
||||
this.app.use(bodyParser.urlencoded({ limit: "50mb", extended: true }));
|
||||
// this.app.use(forms.array());
|
||||
// this.app.use(forms.array());
|
||||
// for parsing multipart/form-data = uploads
|
||||
// this.app.use(upload.array());
|
||||
// this.app.use(upload.array());
|
||||
}
|
||||
|
||||
private boostrap(): void {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -11,7 +11,6 @@ import dayjs, { Dayjs } from "dayjs";
|
|||
import { Dataset, Project, License, Collection, CollectionRole } from "../models/init-models";
|
||||
import Logger from "jet-logger";
|
||||
import { BadOaiModelException, OaiModelException } from "../exceptions/OaiModelException";
|
||||
import PageNotFoundException from "../exceptions/PageNotFoundException";
|
||||
import { OaiErrorCodes, OaiModelError } from "../exceptions/OaiErrorCodes";
|
||||
import XmlModel from "../library/XmlModel";
|
||||
import Configuration from "../library/oai/OaiConfiguration";
|
||||
|
@ -19,6 +18,7 @@ import ResumptionToken from "../library/oai/ResumptionToken";
|
|||
import TokenWorker from "../library/oai/TokenWorker";
|
||||
import utc from "dayjs/plugin/utc";
|
||||
import timezone from "dayjs/plugin/timezone";
|
||||
import { getDomain } from "../utils/utility-functions";
|
||||
|
||||
interface XslTParameter {
|
||||
[key: string]: any;
|
||||
|
@ -102,7 +102,7 @@ export class OaiController {
|
|||
await this.handleRequest(oaiRequest, request);
|
||||
} catch (error) {
|
||||
if (error instanceof OaiModelException) {
|
||||
let code = error.oaiCode;
|
||||
const code = error.oaiCode;
|
||||
let oaiErrorCode: string | undefined = "Unknown oai error code " + code;
|
||||
if (OaiModelError.has(error.oaiCode) && OaiModelError.get(code) != undefined) {
|
||||
oaiErrorCode = OaiModelError.get(error.oaiCode);
|
||||
|
@ -291,7 +291,7 @@ export class OaiController {
|
|||
|
||||
const dataset = await Dataset.findOne({
|
||||
where: { publish_id: dataId },
|
||||
include: ["xmlCache"],
|
||||
include: ["xmlCache", "collections"],
|
||||
// order: ['server_date_published'],
|
||||
});
|
||||
if (!dataset || !dataset.publish_id) {
|
||||
|
@ -683,29 +683,11 @@ export class OaiController {
|
|||
|
||||
private addLandingPageAttribute(domNode: XMLBuilder, dataid: string) {
|
||||
const baseDomain = process.env.BASE_DOMAIN || "localhost";
|
||||
const url = "https://" + this.getDomain(baseDomain) + "/dataset/" + dataid;
|
||||
const url = "https://" + getDomain(baseDomain) + "/dataset/" + dataid;
|
||||
// add attribute du dataset xml element
|
||||
domNode.att("landingpage", url);
|
||||
}
|
||||
|
||||
private getDomain(host: string): string {
|
||||
// $myhost = strtolower(trim($host));
|
||||
let myHost: string = host.trim().toLocaleLowerCase();
|
||||
// $count = substr_count($myhost, '.');
|
||||
const count: number = myHost.split(",").length - 1;
|
||||
|
||||
if (count == 2) {
|
||||
const words = myHost.split(".");
|
||||
if (words[1].length > 3) {
|
||||
myHost = myHost.split(".", 2)[1];
|
||||
}
|
||||
} else if (count > 2) {
|
||||
myHost = this.getDomain(myHost.split(".", 2)[1]);
|
||||
}
|
||||
myHost = myHost.replace(new RegExp(/^.*:\/\//i, "g"), "");
|
||||
return myHost;
|
||||
}
|
||||
|
||||
private getDocumentIdByIdentifier(oaiIdentifier: string): string {
|
||||
const identifierParts: string[] = oaiIdentifier.split(":"); // explode(":", $oaiIdentifier);
|
||||
const dataId: string = identifierParts[2];
|
||||
|
@ -735,20 +717,22 @@ export class OaiController {
|
|||
private async createXmlRecord(dataset: Dataset, datasetNode: XMLBuilder) {
|
||||
const domNode = await this.getDatasetXmlDomNode(dataset);
|
||||
|
||||
// add frontdoor url and data-type
|
||||
// if (dataset.publish_id) {
|
||||
dataset.publish_id && this.addLandingPageAttribute(domNode, dataset.publish_id.toString());
|
||||
// }
|
||||
this.addSpecInformation(domNode, "data-type:" + dataset.type);
|
||||
if (domNode) {
|
||||
// add frontdoor url and data-type
|
||||
// if (dataset.publish_id) {
|
||||
dataset.publish_id && this.addLandingPageAttribute(domNode, dataset.publish_id.toString());
|
||||
// }
|
||||
this.addSpecInformation(domNode, "data-type:" + dataset.type);
|
||||
|
||||
if (dataset.collections) {
|
||||
for (const coll of dataset.collections) {
|
||||
const collRole = await coll.getCollectionRole();
|
||||
this.addSpecInformation(domNode, collRole.oai_name + ":" + coll.number);
|
||||
if (dataset.collections) {
|
||||
for (const coll of dataset.collections) {
|
||||
const collRole = await coll.getCollectionRole();
|
||||
this.addSpecInformation(domNode, collRole.oai_name + ":" + coll.number);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
datasetNode.import(domNode);
|
||||
datasetNode.import(domNode);
|
||||
}
|
||||
}
|
||||
|
||||
private async getDatasetXmlDomNode(dataset: Dataset) {
|
||||
|
|
|
@ -115,32 +115,33 @@ export default class XmlModel {
|
|||
} else {
|
||||
//create domDocument during runtime
|
||||
// domDocument = $this->strategy->getDomDocument();
|
||||
domDocument = create({ version: "1.0", encoding: "UTF-8", standalone: true }, "<root></root>");
|
||||
// domDocument = create({ version: "1.0", encoding: "UTF-8", standalone: true }, "<root></root>");
|
||||
return null;
|
||||
}
|
||||
|
||||
//if caching isn't wanted return only dom Document
|
||||
if (this._caching != true) {
|
||||
return domDocument;
|
||||
//otherwise caching is desired:
|
||||
// save xml cache to db and return domDocument
|
||||
} else {
|
||||
// save new DocumentXmlCache
|
||||
if (!this.cache) {
|
||||
this.cache = new DocumentXmlCache();
|
||||
this.cache.document_id = dataset.id;
|
||||
}
|
||||
// if (!this.cache.document_id) {
|
||||
// this.cache.document_id = dataset.id;
|
||||
// }
|
||||
this.cache.xml_version = 1; // (int)$this->strategy->getVersion();
|
||||
this.cache.server_date_modified = dayjs(dataset.server_date_modified).format("YYYY-MM-DD HH:mm:ss");
|
||||
this.cache.xml_data = domDocument.end();
|
||||
// //if caching isn't wanted return only dom Document
|
||||
// if (this._caching != true) {
|
||||
// return domDocument;
|
||||
// //otherwise caching is desired:
|
||||
// // save xml cache to db and return domDocument
|
||||
// } else {
|
||||
// // save new DocumentXmlCache
|
||||
// if (!this.cache) {
|
||||
// this.cache = new DocumentXmlCache();
|
||||
// this.cache.document_id = dataset.id;
|
||||
// }
|
||||
// // if (!this.cache.document_id) {
|
||||
// // this.cache.document_id = dataset.id;
|
||||
// // }
|
||||
// this.cache.xml_version = 1; // (int)$this->strategy->getVersion();
|
||||
// this.cache.server_date_modified = dayjs(dataset.server_date_modified).format("YYYY-MM-DD HH:mm:ss");
|
||||
// this.cache.xml_data = domDocument.end();
|
||||
|
||||
//save xml cache
|
||||
this.cache.save();
|
||||
// return newly created xml cache
|
||||
return domDocument;
|
||||
}
|
||||
// //save xml cache
|
||||
// this.cache.save();
|
||||
// // return newly created xml cache
|
||||
// return domDocument;
|
||||
// }
|
||||
}
|
||||
|
||||
private async getDomDocumentFromXmlCache(): Promise<XMLBuilder | null> {
|
||||
|
|
|
@ -79,7 +79,7 @@ class Dataset extends Model<InferAttributes<Dataset>, InferCreationAttributes<Da
|
|||
|
||||
declare collections?: NonAttribute<Collection[]>;
|
||||
// declare static associations: {
|
||||
|
||||
|
||||
// };
|
||||
|
||||
// getters that are not attributes should be tagged using NonAttribute
|
||||
|
|
|
@ -229,8 +229,8 @@ export function initModels() {
|
|||
});
|
||||
|
||||
// dataset and collections
|
||||
//licences
|
||||
const DatasetCollection = sequelizeConnection.define(
|
||||
//licences
|
||||
const DatasetCollection = sequelizeConnection.define(
|
||||
"link_documents_collections",
|
||||
{},
|
||||
{
|
||||
|
|
21
src/utils/utility-functions.ts
Normal file
21
src/utils/utility-functions.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
export function sum(a: number, b: number): number {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
export function getDomain(host: string): string {
|
||||
// $myhost = strtolower(trim($host));
|
||||
let myHost: string = host.trim().toLocaleLowerCase();
|
||||
// $count = substr_count($myhost, '.');
|
||||
const count: number = myHost.split(",").length - 1;
|
||||
|
||||
if (count == 2) {
|
||||
const words = myHost.split(".");
|
||||
if (words[1].length > 3) {
|
||||
myHost = myHost.split(".", 2)[1];
|
||||
}
|
||||
} else if (count > 2) {
|
||||
myHost = getDomain(myHost.split(".", 2)[1]);
|
||||
}
|
||||
myHost = myHost.replace(new RegExp(/^.*:\/\//i, "g"), "");
|
||||
return myHost;
|
||||
}
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue