Skip to content

Commit

Permalink
Feat: Add log entry when minting DOI (Merge pull request gigascience#…
Browse files Browse the repository at this point in the history
…2090)

when minting a DOI, add curation log entry

Refs:  gigascience#1667
  • Loading branch information
rija authored Nov 27, 2024
2 parents 80ea4a6 + 2ce6beb commit c929aa9
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased

- Feat #1667: Add log entry when minting DOI
- Fix #2094: Make Semgrep-based SAST analyzer available in tagged release
- Feat #701: Code refactoring to separate upload status transitions and notifications to prepare for upload status overhaul
- Security #1867: Update the gitlab static application security testing (SAST) job using the Semgrep-based analyzer
Expand Down
19 changes: 16 additions & 3 deletions protected/controllers/AdminDatasetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,18 +427,28 @@ public function actionMint()
Yii::app()->end();
}

$action = 'DOI Minting';
$log = sprintf('Dataset %s', $doi);
$doiResponse = $client->request('GET', $mds_doi_url . '/' . $mds_prefix . '/' . $doi, [
'http_errors' => false,
'auth' => [$mds_username, $mds_password]
]);
$result['doi_response'] = $doiResponse->getBody()->getContents();
$result['check_doi_status'] = $doiResponse->getStatusCode();
$isPresent = in_array($result['check_doi_status'], [200, 204]);
$log .= sprintf(' - Check DOI: %s', $isPresent ? "OK" : "DOI doesn't exist");

if ($result['check_doi_status'] === 200 || $result['check_doi_status'] === 204 || $result['check_doi_status'] === 404) {
$xml_data = $dataset->toXML();
if ($isPresent || $result['check_doi_status'] === 404) {
if (!$xml_data = $dataset->toXML()) {
$result['error'] = 'An error occurred while transforming the dataset as xml';
$log .= ' ERROR: An error occurred while transforming the dataset as xml';

echo json_encode($result);
Yii::app()->end();
}
$options = [
'headers' => [
'Content-Type' => 'text/xml; charset=UTF8',
'Content-Type' => 'text/xml;charset=UTF8',
],
'auth' => [$mds_username, $mds_password],
'body' => $xml_data,
Expand All @@ -450,6 +460,7 @@ public function actionMint()
$keyStatus = sprintf('%s_md_status', $result['check_doi_status'] === 200 ? 'update' : 'create');
$result[$keyResponse] = $updateMdResponse->getBody()->getContents();
$result[$keyStatus] = $updateMdResponse->getStatusCode();
$log .= sprintf(' - %s md response: %s', $result['check_doi_status'] === 200 ? 'update' : 'create', 201 === $result[$keyStatus] ? "OK" : $result[$keyResponse]);

if (201 === $updateMdResponse->getStatusCode() && 404 === $result['check_doi_status']) {
$result['doi_data'] = 'doi=' . $mds_prefix . '/' . $doi . "\n" . 'url=http://gigadb.org/dataset/' . $doi;
Expand All @@ -466,9 +477,11 @@ public function actionMint()

$result['create_doi_response'] = $response->getBody()->getContents();
$result['create_doi_status'] = $response->getStatusCode();
$log .= sprintf(' - Create DOI: %s', $result['create_doi_status'] === 201 ? 'OK' : $result['create_doi_response']);
}
}

CurationLog::createGeneralCurationLogEntry($dataset->id, $action, $log);
echo json_encode($result);
Yii::app()->end();
}
Expand Down
9 changes: 9 additions & 0 deletions protected/models/CurationLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ public static function createCurationLogEntry(int $id, string $fileName): bool
return $curationlog->save();
}

public static function createGeneralCurationLogEntry(int $id, string $action, string $content, $author = 'system'): bool
{
$curationLog = self::makeNewInstanceForCurationLogBy($id, $author);
$curationLog->action = $action;
$curationLog->comments = $content;

return $curationLog->save();
}

/**
*
* alias to allow code from develop up to commit 4ab4399 to work
Expand Down
5 changes: 2 additions & 3 deletions protected/models/Dataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,8 @@ public function getUrlToRedirectAttribute() {
}

/**
* toXML(): fucntion tha treturn Datacite XML for this dataset
* @return Datacite XML 4.0 for this dataset
* toXML(): function tha return Datacite XML for this dataset
* @return bool|string XML 4.0 for this dataset
*/
public function toXML() {
$xmlstr = "<?xml version='1.0' ?>\n".
Expand Down Expand Up @@ -594,7 +594,6 @@ public function toXML() {
$description->addAttribute('xml:lang','en-US','http://www.w3.org/XML/1998/namespace');
$description->addAttribute('descriptionType','Abstract');


return $xml->asXML();
}

Expand Down
28 changes: 16 additions & 12 deletions protected/views/adminDataset/_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,18 +358,22 @@
'data' => ['doi' => 'js:$("#Dataset_identifier").val()'],
'dataType' => 'json',
'success' => new CJavaScriptExpression('function(output) {
if (output.check_doi_status == 200 && output.update_md_status == 201) {
if (output.check_doi_status === 200 && output.update_md_status === 201) {
$("#minting").addClass("alert alert-info").html("This DOI exists in datacite already, no need to mint, but the metadata is updated!");
} else if (output.check_doi_status == 200 && output.update_md_status == 422) {
} else if (output.check_doi_status === 204 && output.create_md_status === 201) {
$("#minting").addClass("alert alert-info").html("This DOI exists but is not registered, no need to mint, but the metadata has been created!");
} else if (output.check_doi_status === 200 && output.update_md_status !== 201) {
$("#minting").addClass("alert alert-info").html("This DOI exists in datacite, but failed to update metadata because of: " + output.update_md_response);
} else if (output.create_md_status == 201 && output.create_doi_status == 201) {
$("#minting").addClass("alert alert-success").html("New DOI successfully minted");
} else if (output.check_doi_status == 404 && output.create_md_status == 422) {
} else if (output.check_doi_status === 204 && output.create_md_status !== 201) {
$("#minting").addClass("alert alert-info").html("This DOI exists in datacite, but failed to create metadata because of: " + output.create_md_response);
} else if (output.check_doi_status === 404 && output.create_md_status !== 201) {
$("#minting").addClass("alert alert-danger").html("This DOI cannot be created because of the metadata status: " + output.create_md_status + ". Details can be found at <a href=\'https://support.datacite.org/reference/mds#api-response-codes\' target=\'_blank\'>here</a>");
} else if (output.check_doi_status == 200 && output.update_md_status != 200) {
$("#minting").addClass("alert alert-danger").html("Error with metadata status: " + output.update_md_status + " and DOI status: " + output.check_doi_status + " Details can be found at <a href=\'https://support.datacite.org/reference/mds#api-response-codes\' target=\'_blank\'>here</a>");
} else if (output.create_md_status === 201 && output.create_doi_status !== 201) {
$("#minting").addClass("alert alert-success").html("New DOI couldn\'t be minted");
} else if (output.create_md_status === 201 && output.create_doi_status === 201) {
$("#minting").addClass("alert alert-success").html("New DOI successfully minted");
} else {
$("#minting").addClass("alert alert-danger").html("DOI status: " + output.check_doi_status + ". An error occurred");
$("#minting").addClass("alert alert-danger").html("An error occurred");
}
if (output.error) {
Expand All @@ -380,10 +384,10 @@
),
],
array(
'class' => 'btn background-btn m-0',
'id' => 'mint_doi_button',
'disabled' => in_array($model->upload_status, $status_array),
'title' => 'This botton will take all the dataset information stored in GigaDB and convert it to the DataCite schema in XML and via an API call, register that information with DataCite',
'class' => 'btn background-btn m-0',
'id' => 'mint_doi_button',
'disabled' => in_array($model->upload_status, $status_array),
'title' => 'This button will take all the dataset information stored in GigaDB and convert it to the DataCite schema in XML and via an API call, register that information with DataCite',
'data-toggle' => 'tooltip'
)
);
Expand Down
17 changes: 17 additions & 0 deletions tests/acceptance/AdminDatasetCurationLog.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@ok-needs-secrets
Feature: curation log entry under the dataset form
As a curator
I want to see see a curation log entry after minting DOI
So that the curation log entry is visible

Background:
Given I have signed in as admin

@ok
Scenario: Minting Doi and adding curation log entry
When I am on "/adminDataset/update/id/8"
And I press the button "Mint DOI"
And I wait "3" seconds
And I should see "This DOI exists in datacite already, no need to mint, but the metadata is updated!"
Then I am on "/adminDataset/update/id/8"
And I should see "Dataset 100006 - Check DOI: OK - update md response: OK"

0 comments on commit c929aa9

Please sign in to comment.