- removed extra test datacite accounts from .env
All checks were successful
CI Pipeline / japa-tests (push) Successful in 57s
All checks were successful
CI Pipeline / japa-tests (push) Successful in 57s
- updated DoiClient.ts - removed test error via /welcome page - npm updates
This commit is contained in:
parent
c9ba7d6adc
commit
8cef7390d7
11 changed files with 186 additions and 229 deletions
|
@ -311,14 +311,10 @@ export default class DatasetsController {
|
|||
|
||||
let prefix = '';
|
||||
let base_domain = '';
|
||||
const datacite_environment = process.env.DATACITE_ENVIRONMENT || 'debug';
|
||||
if (datacite_environment === 'debug') {
|
||||
prefix = process.env.DATACITE_TEST_PREFIX || '';
|
||||
base_domain = process.env.TEST_BASE_DOMAIN || '';
|
||||
} else if (datacite_environment === 'production') {
|
||||
prefix = process.env.DATACITE_PREFIX || '';
|
||||
base_domain = process.env.BASE_DOMAIN || '';
|
||||
}
|
||||
// const datacite_environment = process.env.DATACITE_ENVIRONMENT || 'debug';
|
||||
prefix = process.env.DATACITE_PREFIX || '';
|
||||
base_domain = process.env.BASE_DOMAIN || '';
|
||||
|
||||
|
||||
// register DOI:
|
||||
const doiValue = prefix + '/tethys.' + dataset.publish_id; //'10.21388/tethys.213'
|
||||
|
|
|
@ -5,30 +5,21 @@ 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 axios, { AxiosResponse } from 'axios';
|
||||
|
||||
export class DoiClient implements DoiClientContract {
|
||||
username: string;
|
||||
password: string;
|
||||
serviceUrl: string;
|
||||
// prefix: string;
|
||||
// base_domain: string;
|
||||
public username: string;
|
||||
public password: string;
|
||||
public serviceUrl: string;
|
||||
|
||||
constructor() {
|
||||
const datacite_environment = process.env.DATACITE_ENVIRONMENT || 'debug';
|
||||
if (datacite_environment === 'debug') {
|
||||
this.username = process.env.DATACITE_TEST_USERNAME || '';
|
||||
this.password = process.env.DATACITE_TEST_PASSWORD || '';
|
||||
this.serviceUrl = process.env.DATACITE_TEST_SERVICE_URL || '';
|
||||
// this.prefix = process.env.DATACITE_TEST_PREFIX || '';
|
||||
// this.base_domain = process.env.TEST_BASE_DOMAIN || '';
|
||||
} else if (datacite_environment === 'production') {
|
||||
this.username = process.env.DATACITE_USERNAME || '';
|
||||
this.password = process.env.DATACITE_PASSWORD || '';
|
||||
this.serviceUrl = process.env.DATACITE_SERVICE_URL || '';
|
||||
// this.prefix = process.env.DATACITE_PREFIX || '';
|
||||
// this.base_domain = process.env.BASE_DOMAIN || '';
|
||||
}
|
||||
// const datacite_environment = process.env.DATACITE_ENVIRONMENT || 'debug';
|
||||
this.username = process.env.DATACITE_USERNAME || '';
|
||||
this.password = process.env.DATACITE_PASSWORD || '';
|
||||
this.serviceUrl = process.env.DATACITE_SERVICE_URL || '';
|
||||
// this.prefix = process.env.DATACITE_PREFIX || '';
|
||||
// this.base_domain = process.env.BASE_DOMAIN || '';
|
||||
|
||||
if (this.username === '' || this.password === '' || this.serviceUrl === '') {
|
||||
const message = 'issing configuration settings to properly initialize DOI client';
|
||||
Logger.error(message);
|
||||
|
@ -43,13 +34,13 @@ export class DoiClient implements DoiClientContract {
|
|||
* @param xmlMeta
|
||||
* @param landingPageUrl e.g. https://www.tethys.at/dataset/1
|
||||
*
|
||||
* @return Promise<number> The http response in the form of a axios response
|
||||
* @return Promise<AxiosResponse<any>> The http response in the form of a axios response
|
||||
*/
|
||||
public async registerDoi(doiValue: string, xmlMeta: string, landingPageUrl: string): Promise<AxiosResponse<any>> {
|
||||
//step 1: register metadata via xml upload
|
||||
// state draft
|
||||
let response;
|
||||
let url = `${this.serviceUrl}/metadata/${doiValue}`; //https://mds.test.datacite.org/metadata/10.21388/tethys.213
|
||||
// let response;
|
||||
// let url = `${this.serviceUrl}/metadata/${doiValue}`; //https://mds.test.datacite.org/metadata/10.21388/tethys.213
|
||||
const auth = {
|
||||
username: this.username,
|
||||
password: this.password,
|
||||
|
@ -58,62 +49,44 @@ export class DoiClient implements DoiClientContract {
|
|||
'Content-Type': 'application/xml;charset=UTF-8',
|
||||
};
|
||||
try {
|
||||
response = await axios.put(url, xmlMeta, {
|
||||
auth,
|
||||
headers,
|
||||
});
|
||||
} catch (error) {
|
||||
const message = `request to ${url} failed with ${error.message}`;
|
||||
// Handle the error, log it, or rethrow as needed
|
||||
Logger.error(message);
|
||||
throw new DoiClientException(StatusCodes.SERVICE_UNAVAILABLE, message);
|
||||
}
|
||||
// let test = response.data; // 'OK (10.21388/TETHYS.213)'
|
||||
const metadataResponse = await axios.put(`${this.serviceUrl}/metadata/${doiValue}`, xmlMeta, { auth, headers });
|
||||
|
||||
// Response Codes
|
||||
// 201 Created: operation successful
|
||||
// 401 Unauthorised: no login
|
||||
// 403 Forbidden: login problem, quota exceeded
|
||||
// 415 Wrong Content Type : Not including content type in the header.
|
||||
// 422 Unprocessable Entity : invalid XML
|
||||
if (response.status !== 201) {
|
||||
const message = 'unexpected DataCite MDS response code ' + response.status;
|
||||
// $this->log($message, 'err');
|
||||
throw new DoiClientException(response.status, message);
|
||||
}
|
||||
// Response Codes
|
||||
// 201 Created: operation successful
|
||||
// 401 Unauthorised: no login
|
||||
// 403 Forbidden: login problem, quota exceeded
|
||||
// 415 Wrong Content Type : Not including content type in the header.
|
||||
// 422 Unprocessable Entity : invalid XML
|
||||
// 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);
|
||||
throw new DoiClientException(metadataResponse.status, message);
|
||||
}
|
||||
|
||||
// step 2: Register the DOI name
|
||||
// // DOI und URL der Frontdoor des zugehörigen Dokuments übergeben: state findable
|
||||
// const url2 = this.serviceUrl + "/doi/" + doiValue;
|
||||
url = `${this.serviceUrl}/doi/${doiValue}`; //'https://mds.test.datacite.org/doi/10.21388/tethys.213'
|
||||
headers = {
|
||||
'Content-Type': 'text/plain;charset=UTF-8',
|
||||
};
|
||||
const data = `doi=${doiValue}\nurl=${landingPageUrl}`;
|
||||
try {
|
||||
response = await axios.put(url, data, {
|
||||
const doiResponse = await axios.put(`${this.serviceUrl}/doi/${doiValue}`, `doi=${doiValue}\nurl=${landingPageUrl}`, {
|
||||
auth,
|
||||
headers,
|
||||
});
|
||||
|
||||
// Access the response data using response.data
|
||||
// Do something with the response.data
|
||||
// Response Codes
|
||||
// 201 Created: operation successful
|
||||
// 400 Bad Request: request body must be exactly two lines: DOI and URL; wrong domain, wrong prefix;
|
||||
// 401 Unauthorised: no login
|
||||
// 403 Forbidden: login problem, quota exceeded
|
||||
// 412 Precondition failed: metadata must be uploaded first.
|
||||
if (doiResponse.status !== 201) {
|
||||
const message = `Unexpected DataCite MDS response code ${doiResponse.status}`;
|
||||
Logger.error(message);
|
||||
throw new DoiClientException(doiResponse.status, message);
|
||||
}
|
||||
|
||||
return doiResponse;
|
||||
} catch (error) {
|
||||
const message = `request to ${url} failed with ${error.message}`;
|
||||
// const message = `request for registering DOI failed with ${error.message}`;
|
||||
// Handle the error, log it, or rethrow as needed
|
||||
throw new DoiClientException(response.status, message);
|
||||
Logger.error(error.message);
|
||||
throw new DoiClientException(error.response.status, error.response.data);
|
||||
}
|
||||
// Response Codes
|
||||
// 201 Created: operation successful
|
||||
// 400 Bad Request: request body must be exactly two lines: DOI and URL; wrong domain, wrong prefix;
|
||||
// 401 Unauthorised: no login
|
||||
// 403 Forbidden: login problem, quota exceeded
|
||||
// 412 Precondition failed: metadata must be uploaded first.
|
||||
if (response.status != 201) {
|
||||
const message = 'unexpected DataCite MDS response code ' + response.status;
|
||||
Logger.error(message);
|
||||
throw new DoiClientException(response.status, message);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,15 +33,16 @@ export default {
|
|||
|
||||
// set prefix
|
||||
let prefix = '';
|
||||
let base_domain = '';
|
||||
const datacite_environment = process.env.DATACITE_ENVIRONMENT || 'debug';
|
||||
if (datacite_environment === 'debug') {
|
||||
prefix = process.env.DATACITE_TEST_PREFIX || '';
|
||||
base_domain = process.env.TEST_BASE_DOMAIN || '';
|
||||
} else if (datacite_environment === 'production') {
|
||||
prefix = process.env.DATACITE_PREFIX || '';
|
||||
base_domain = process.env.BASE_DOMAIN || '';
|
||||
}
|
||||
// let base_domain = '';
|
||||
// const datacite_environment = process.env.DATACITE_ENVIRONMENT || 'debug';
|
||||
// if (datacite_environment === 'debug') {
|
||||
// prefix = process.env.DATACITE_TEST_PREFIX || '';
|
||||
// base_domain = process.env.TEST_BASE_DOMAIN || '';
|
||||
// } else if (datacite_environment === 'production') {
|
||||
// prefix = process.env.DATACITE_PREFIX || '';
|
||||
// base_domain = process.env.BASE_DOMAIN || '';
|
||||
// }
|
||||
prefix = process.env.DATACITE_PREFIX || '';
|
||||
xsltParameter['prefix'] = prefix;
|
||||
|
||||
const repIdentifier = 'tethys';
|
||||
|
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue