- 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
|
@ -8,8 +8,6 @@
|
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
|
||||
|
||||
<!--<xsl:param name="urnResolverUrl" />-->
|
||||
|
||||
<!-- add include here for each new metadata format -->
|
||||
<xsl:include href="assets/oai_datacite.xslt" />
|
||||
<xsl:include href="assets/oai_2_iso19139.xslt" />
|
||||
|
@ -47,11 +45,56 @@
|
|||
|
||||
<xsl:variable name="langCodes" select="document('assets/langCodeMap.xml')/langCodeMap/langCode"/>
|
||||
|
||||
<!-- Characters we'll support.
|
||||
We could add control chars 0-31 and 127-159, but we won't. -->
|
||||
<xsl:variable name="ascii"> !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~</xsl:variable>
|
||||
<xsl:variable name="latin1"> ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ</xsl:variable>
|
||||
<!-- Characters that usually don't need to be escaped -->
|
||||
<xsl:variable name="safe">!'()*-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~</xsl:variable>
|
||||
<xsl:variable name="hex" >0123456789ABCDEF</xsl:variable>
|
||||
|
||||
<xsl:template name="url-encode">
|
||||
<xsl:param name="str"/>
|
||||
<xsl:if test="$str">
|
||||
<xsl:variable name="first-char" select="substring($str,1,1)"/>
|
||||
<xsl:choose>
|
||||
<xsl:when test="contains($safe,$first-char)">
|
||||
<xsl:value-of select="$first-char"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:variable name="codepoint">
|
||||
<xsl:choose>
|
||||
<xsl:when test="contains($ascii,$first-char)">
|
||||
<xsl:value-of select="string-length(substring-before($ascii,$first-char)) + 32"/>
|
||||
</xsl:when>
|
||||
<xsl:when test="contains($latin1,$first-char)">
|
||||
<xsl:value-of select="string-length(substring-before($latin1,$first-char)) + 160"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:message terminate="no">Warning: string contains a character that is out of range! Substituting "?".</xsl:message>
|
||||
<xsl:text>63</xsl:text>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
<xsl:variable name="hex-digit1" select="substring($hex,floor($codepoint div 16) + 1,1)"/>
|
||||
<xsl:variable name="hex-digit2" select="substring($hex,$codepoint mod 16 + 1,1)"/>
|
||||
<xsl:value-of select="concat('%',$hex-digit1,$hex-digit2)"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
<xsl:if test="string-length($str) > 1">
|
||||
<xsl:call-template name="url-encode">
|
||||
<xsl:with-param name="str" select="substring($str,2)"/>
|
||||
</xsl:call-template>
|
||||
</xsl:if>
|
||||
</xsl:if>
|
||||
</xsl:template>
|
||||
|
||||
|
||||
<!--create the head of oai response -->
|
||||
<xsl:template match="/root">
|
||||
<!-- stylesheet for browser -->
|
||||
<xsl:processing-instruction name="xml-stylesheet">
|
||||
<xsl:text>type="text/xsl" href="../assets/oai2_style.xslt" title="Defaultstyle"</xsl:text>
|
||||
<xsl:text>type="text/xsl" href="assets/oai2_style.xslt"</xsl:text>
|
||||
</xsl:processing-instruction>
|
||||
|
||||
<OAI-PMH xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
|
||||
|
@ -416,7 +459,10 @@
|
|||
<xsl:apply-templates select="Identifier" mode="oai_dc" />
|
||||
</xsl:if> -->
|
||||
<dc:identifier>
|
||||
<xsl:value-of select="@landingpage" />
|
||||
<xsl:value-of select="string(@landingpage)" />
|
||||
<!-- <xsl:call-template name="url-encode">
|
||||
<xsl:with-param name="str" select="@landingpage"/>
|
||||
</xsl:call-template> -->
|
||||
</dc:identifier>
|
||||
<!-- dc:language -->
|
||||
<xsl:apply-templates select="@Language" mode="oai_dc" />
|
||||
|
@ -553,7 +599,6 @@
|
|||
<xsl:value-of select="@Value" />
|
||||
</dc:subject>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="Collection" mode="oai_dc">
|
||||
<dc:subject>
|
||||
<!-- <xsl:if test="@Language != ''">
|
||||
|
@ -567,7 +612,10 @@
|
|||
|
||||
<xsl:template match="Reference" mode="oai_dc">
|
||||
<dc:relation>
|
||||
<xsl:value-of select="@Value" />
|
||||
<xsl:value-of select="string(@Value)" />
|
||||
<!-- <xsl:call-template name="url-encode">
|
||||
<xsl:with-param name="str" select="@Value"/>
|
||||
</xsl:call-template> -->
|
||||
</dc:relation>
|
||||
</xsl:template>
|
||||
|
||||
|
@ -673,7 +721,10 @@
|
|||
<xsl:template match="Identifier" mode="oai_dc">
|
||||
<dc:relation>
|
||||
<!-- <xsl:value-of select="concat($doiLink, @Value)" /> -->
|
||||
<xsl:value-of select="concat($doiPrefix, @Value)" />
|
||||
<xsl:value-of select="concat($doiPrefix, string(@Value))" />
|
||||
<!-- <xsl:call-template name="url-encode">
|
||||
<xsl:with-param name="str" select="concat($doiPrefix, @Value)"/>
|
||||
</xsl:call-template> -->
|
||||
</dc:relation>
|
||||
</xsl:template>
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
"dependencies": {
|
||||
"@overnightjs/core": "^1.7.6",
|
||||
"body-parser": "^1.20.0",
|
||||
"cd": "^0.3.3",
|
||||
"core-js": "^3.25.5",
|
||||
"cors": "^2.8.5",
|
||||
"dayjs": "^1.11.5",
|
||||
|
|
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,6 +717,7 @@ export class OaiController {
|
|||
private async createXmlRecord(dataset: Dataset, datasetNode: XMLBuilder) {
|
||||
const domNode = await this.getDatasetXmlDomNode(dataset);
|
||||
|
||||
if (domNode) {
|
||||
// add frontdoor url and data-type
|
||||
// if (dataset.publish_id) {
|
||||
dataset.publish_id && this.addLandingPageAttribute(domNode, dataset.publish_id.toString());
|
||||
|
@ -750,6 +733,7 @@ export class OaiController {
|
|||
|
||||
datasetNode.import(domNode);
|
||||
}
|
||||
}
|
||||
|
||||
private async getDatasetXmlDomNode(dataset: Dataset) {
|
||||
// dataset.fetchValues();
|
||||
|
|
|
@ -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) {
|
||||
// //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;
|
||||
// }
|
||||
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 (!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> {
|
||||
|
|
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…
Reference in New Issue
Block a user