bugfix: doi-registration: Refactor XSLT and Vue components for improved data validation and conditional rendering
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 11s

- Updated doi_datacite.xslt to include conditional checks for empty values in creators, titles, subjects, contributors, dates, rights, sizes, formats, descriptions, and geoLocations to ensure only non-empty elements are rendered.
- Enhanced the handling of TitleAbstract and TitleAbstractAdditional templates to only output descriptions if the Value attribute is not empty.
- Modified the Doi.vue component to clean up the import statements and commented out unused warning display code for clarity.
This commit is contained in:
Kaimbacher 2025-12-04 17:01:13 +01:00
commit b16a1ba3f0
4 changed files with 201 additions and 158 deletions

View file

@ -195,7 +195,7 @@ export default class DatasetsController {
if (!user) {
return response.flash('You must be logged in to edit a dataset.', 'error').redirect().toRoute('app.login.show');
}
// $dataset = Dataset::with('user:id,login')->findOrFail($id);
const dataset = await Dataset.query().where('id', id).where('editor_id', user.id).firstOrFail();
@ -236,7 +236,7 @@ export default class DatasetsController {
throw error;
}
const id = request.param('id');
const user = auth.user;
const user = auth.user;
if (!user) {
return response.flash('You must be logged in to edit a dataset.', 'error').redirect().toRoute('app.login.show');
}
@ -306,7 +306,7 @@ export default class DatasetsController {
public async rejectUpdate({ request, response, auth }: HttpContext) {
const authUser = auth.user!;
if (!authUser) {
return response.flash('You must be logged in to edit a dataset.', 'error').redirect().toRoute('app.login.show');
}
@ -619,7 +619,7 @@ export default class DatasetsController {
});
}
public async doiStore({ request, response, auth }: HttpContext) {
public async doiStore({ request, response, session, auth }: HttpContext) {
const dataId = request.param('publish_id');
const user = auth.user;
if (!user) {
@ -627,10 +627,7 @@ export default class DatasetsController {
}
// Load dataset with minimal required relationships
const dataset = await Dataset.query()
.where('editor_id', user.id) // Ensure the user is the editor of the dataset
.where('publish_id', dataId)
.firstOrFail();
const dataset = await Dataset.query().where('editor_id', user.id).where('publish_id', dataId).firstOrFail();
const prefix = process.env.DATACITE_PREFIX || '';
const base_domain = process.env.BASE_DOMAIN || '';
@ -639,30 +636,44 @@ export default class DatasetsController {
const xmlMeta = (await Index.getDoiRegisterString(dataset)) as string;
// Prepare DOI registration data
const doiValue = `${prefix}/tethys.${dataset.publish_id}`; //'10.21388/tethys.213'
const landingPageUrl = `https://doi.${getDomain(base_domain)}/${prefix}/tethys.${dataset.publish_id}`; //https://doi.dev.tethys.at/10.21388/tethys.213
const doiValue = `${prefix}/tethys.${dataset.publish_id}`;
const landingPageUrl = `https://doi.${getDomain(base_domain)}/${prefix}/tethys.${dataset.publish_id}`;
// Register DOI with DataCite
const doiClient = new DoiClient();
const dataciteResponse = await doiClient.registerDoi(doiValue, xmlMeta, landingPageUrl);
if (dataciteResponse?.status !== 201) {
const message = `Unexpected DataCite MDS response code ${dataciteResponse?.status}`;
throw new DoiClientException(dataciteResponse?.status, message);
}
// DOI registration successful - persist and index
try {
// Save identifier
// Register DOI with DataCite
const doiClient = new DoiClient();
const dataciteResponse = await doiClient.registerDoi(doiValue, xmlMeta, landingPageUrl);
if (dataciteResponse?.status !== 201) {
const message = `Unexpected DataCite MDS response code ${dataciteResponse?.status}`;
throw new DoiClientException(dataciteResponse?.status, message);
}
// DOI registration successful - persist and index
await this.persistDoiAndIndex(dataset, doiValue);
return response.toRoute('editor.dataset.list').flash('message', 'You have successfully created a DOI for the dataset!');
return response
.flash('message', 'You have successfully created a DOI for the dataset!')
.redirect()
.toRoute('editor.dataset.list');
} catch (error) {
logger.error(`${__filename}: Failed to persist DOI and index dataset ${dataset.id}: ${error.message}`);
throw new HttpException(error.message);
}
// logger.error(`${__filename}: DOI registration failed for dataset ${dataset.id}: ${error.message}`);
// return response.toRoute('editor.dataset.list').flash('message', xmlMeta);
if (error instanceof DoiClientException) {
// Flash error for Inertia to pick up
session.flash('errors', {
doi: `DOI registration failed: ${error.message}`,
});
// Optionally also flash a warning for your warning display
session.flash('warning', error.message);
} else {
session.flash('errors', {
general: `An unexpected error occurred: ${error.message}`,
});
}
return response.redirect().back();
}
}
/**