This commit is contained in:
parent
f828ca4491
commit
cb51a4136f
167 changed files with 21485 additions and 21212 deletions
|
@ -1,11 +1,12 @@
|
|||
// import { Client } from 'guzzle';
|
||||
// import { Log } from '@adonisjs/core/build/standalone';
|
||||
// import { DoiInterface } from './interfaces/DoiInterface';
|
||||
import DoiClientContract from 'App/Library/Doi/DoiClientContract';
|
||||
import DoiClientException from 'App/Exceptions/DoiClientException';
|
||||
import DoiClientContract from '#app/Library/Doi/DoiClientContract';
|
||||
import DoiClientException from '#app/Exceptions/DoiClientException';
|
||||
import { StatusCodes } from 'http-status-codes';
|
||||
import Logger from '@ioc:Adonis/Core/Logger';
|
||||
import axios, { AxiosResponse } from 'axios';
|
||||
import logger from '@adonisjs/core/services/logger';
|
||||
import { AxiosResponse } from 'axios';
|
||||
import axios from 'axios';
|
||||
|
||||
export class DoiClient implements DoiClientContract {
|
||||
public username: string;
|
||||
|
@ -22,7 +23,7 @@ export class DoiClient implements DoiClientContract {
|
|||
|
||||
if (this.username === '' || this.password === '' || this.serviceUrl === '') {
|
||||
const message = 'issing configuration settings to properly initialize DOI client';
|
||||
Logger.error(message);
|
||||
logger.error(message);
|
||||
throw new DoiClientException(StatusCodes.BAD_REQUEST, message);
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +50,7 @@ export class DoiClient implements DoiClientContract {
|
|||
'Content-Type': 'application/xml;charset=UTF-8',
|
||||
};
|
||||
try {
|
||||
const metadataResponse = await axios.put(`${this.serviceUrl}/metadata/${doiValue}`, xmlMeta, { auth, headers });
|
||||
const metadataResponse = await axios.default.put(`${this.serviceUrl}/metadata/${doiValue}`, xmlMeta, { auth, headers });
|
||||
|
||||
// Response Codes
|
||||
// 201 Created: operation successful
|
||||
|
@ -60,11 +61,11 @@ export class DoiClient implements DoiClientContract {
|
|||
// let test = metadataResponse.data; // 'OK (10.21388/TETHYS.213)'
|
||||
if (metadataResponse.status !== 201) {
|
||||
const message = `Unexpected DataCite MDS response code ${metadataResponse.status}`;
|
||||
Logger.error(message);
|
||||
logger.error(message);
|
||||
throw new DoiClientException(metadataResponse.status, message);
|
||||
}
|
||||
|
||||
const doiResponse = await axios.put(`${this.serviceUrl}/doi/${doiValue}`, `doi=${doiValue}\nurl=${landingPageUrl}`, {
|
||||
const doiResponse = await axios.default.put(`${this.serviceUrl}/doi/${doiValue}`, `doi=${doiValue}\nurl=${landingPageUrl}`, {
|
||||
auth,
|
||||
headers,
|
||||
});
|
||||
|
@ -77,7 +78,7 @@ export class DoiClient implements DoiClientContract {
|
|||
// 412 Precondition failed: metadata must be uploaded first.
|
||||
if (doiResponse.status !== 201) {
|
||||
const message = `Unexpected DataCite MDS response code ${doiResponse.status}`;
|
||||
Logger.error(message);
|
||||
logger.error(message);
|
||||
throw new DoiClientException(doiResponse.status, message);
|
||||
}
|
||||
|
||||
|
@ -85,7 +86,7 @@ export class DoiClient implements DoiClientContract {
|
|||
} catch (error) {
|
||||
// const message = `request for registering DOI failed with ${error.message}`;
|
||||
// Handle the error, log it, or rethrow as needed
|
||||
Logger.error(error.message);
|
||||
logger.error(error.message);
|
||||
throw new DoiClientException(error.response.status, error.response.data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// import ResumptionToken from './ResumptionToken';
|
||||
import { AxiosResponse } from 'axios';
|
||||
|
||||
export default interface DoiClientContract {
|
||||
username: string;
|
||||
|
@ -6,7 +7,7 @@ export default interface DoiClientContract {
|
|||
serviceUrl: string;
|
||||
// prefix: string;
|
||||
// base_domain: string;
|
||||
registerDoi(doiValue: string, xmlMeta: string, landingPageUrl: string);
|
||||
registerDoi(doiValue: string, xmlMeta: string, landingPageUrl: string): Promise<AxiosResponse<any>>;
|
||||
// get(key: string): Promise<ResumptionToken | null>;
|
||||
// set(token: ResumptionToken): Promise<string>;
|
||||
}
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue