- getMetadataForDoi and updateMetadataForDoi in DoiClient.php
- doi_datacite.xslt: show Subtitle - further tests in DoiClientTest.php - DoiController.php: safe DOI metadta in table dataset_identifiers
This commit is contained in:
parent
9b6a6469d7
commit
8f0b12fbf0
|
@ -78,7 +78,7 @@ class DoiController extends Controller
|
||||||
$dataId = $request->input('publish_id');
|
$dataId = $request->input('publish_id');
|
||||||
|
|
||||||
// Setup stylesheet
|
// Setup stylesheet
|
||||||
$this->loadStyleSheet(public_path() .'\prefixes\doi_datacite.xslt');
|
$this->loadStyleSheet(public_path() .'/prefixes/doi_datacite.xslt');
|
||||||
|
|
||||||
// set timestamp
|
// set timestamp
|
||||||
$date = new \DateTime();
|
$date = new \DateTime();
|
||||||
|
@ -114,14 +114,14 @@ class DoiController extends Controller
|
||||||
$appUrl = config('app.url');
|
$appUrl = config('app.url');
|
||||||
$landingPageUrl = $appUrl . "/dataset/" . $dataset->publish_id;
|
$landingPageUrl = $appUrl . "/dataset/" . $dataset->publish_id;
|
||||||
$response = $this->doiClient->registerDoi($doiValue, $xmlMeta, $landingPageUrl);
|
$response = $this->doiClient->registerDoi($doiValue, $xmlMeta, $landingPageUrl);
|
||||||
|
// if operation successful
|
||||||
if ($response->getStatusCode() == 201) {
|
if ($response->getStatusCode() == 201) {
|
||||||
$doi = new DatasetIdentifier();
|
$doi = new DatasetIdentifier();
|
||||||
$doi['value'] = $doiValue;
|
$doi['value'] = $doiValue;
|
||||||
$doi['dataset_id'] = $dataset->id;
|
$doi['dataset_id'] = $dataset->id;
|
||||||
$doi['type'] = "doi";
|
$doi['type'] = "doi";
|
||||||
$doi['status'] = "registered";
|
$doi['status'] = "registered";
|
||||||
$doi['registration_ts'] = now();
|
$doi->save();
|
||||||
// $doi->save();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class DatasetIdentifier extends Model
|
class DatasetIdentifier extends Model
|
||||||
{
|
{
|
||||||
protected $table = 'dataset_identifierss';
|
protected $table = 'dataset_identifiers';
|
||||||
protected $guarded = array();
|
protected $guarded = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -33,7 +33,7 @@ class DoiClient implements DoiInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a DOI or ARK with the given identifier
|
* Creates a DOI with the given identifier
|
||||||
*
|
*
|
||||||
* @param string $identifier The desired DOI identifier e.g. '10.5072/tethys.999',
|
* @param string $identifier The desired DOI identifier e.g. '10.5072/tethys.999',
|
||||||
* @param $xmlMeta
|
* @param $xmlMeta
|
||||||
|
@ -68,7 +68,6 @@ class DoiClient implements DoiInterface
|
||||||
}
|
}
|
||||||
// Response Codes
|
// Response Codes
|
||||||
// 201 Created: operation successful
|
// 201 Created: operation successful
|
||||||
// 400 Bad Request: invalid XML, wrong prefix
|
|
||||||
// 401 Unauthorised: no login
|
// 401 Unauthorised: no login
|
||||||
// 403 Forbidden: login problem, quota exceeded
|
// 403 Forbidden: login problem, quota exceeded
|
||||||
// 415 Wrong Content Type : Not including content type in the header.
|
// 415 Wrong Content Type : Not including content type in the header.
|
||||||
|
@ -167,18 +166,74 @@ class DoiClient implements DoiInterface
|
||||||
return ($statusCode == 200 && $landingPageURL == $body);
|
return ($statusCode == 200 && $landingPageURL == $body);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMetadataForDoi($identifier)
|
public function getMetadataForDoi($doiValue)
|
||||||
{
|
{
|
||||||
//
|
$response = null;
|
||||||
|
$url = $this->serviceUrl . '/metadata/' . $doiValue;
|
||||||
|
try {
|
||||||
|
$client = new Client([
|
||||||
|
'auth' => [$this->username, $this->password],
|
||||||
|
'base_uri' => $url,
|
||||||
|
'verify' => false,
|
||||||
|
]);
|
||||||
|
$response = $client->request('GET');
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$message = 'request to ' . $url . ' failed with ' . $e->getMessage();
|
||||||
|
throw new DoiClientException($message);
|
||||||
|
}
|
||||||
|
// Response Codes
|
||||||
|
// 200 OK: operation successful;
|
||||||
|
// 204 No Content: the DOI is known to DataCite Metadata Store (MDS), but no metadata have been registered;
|
||||||
|
// 401 Unauthorised: no login
|
||||||
|
// 403 Forbidden: permission problem or dataset belongs to another party;
|
||||||
|
// 404 Not Found: DOI does not exist in our database.
|
||||||
|
// 422 Unprocessable Entity Metadata failed validation against the DataCite Schema.
|
||||||
|
if ($response->getStatusCode() != 200) {
|
||||||
|
$message = 'unexpected DataCite MDS response code ' . $response->getStatusCode();
|
||||||
|
// $this->log($message, 'err');
|
||||||
|
throw new DoiClientException($message);
|
||||||
|
}
|
||||||
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateMetadataForDoi($identifier, $new_meta)
|
public function updateMetadataForDoi($doiValue, $newMeta)
|
||||||
{
|
{
|
||||||
//
|
$response = null;
|
||||||
|
$url = $this->serviceUrl . '/metadata/' . $doiValue;
|
||||||
|
try {
|
||||||
|
$client = new Client([
|
||||||
|
'auth' => [$this->username, $this->password],
|
||||||
|
// 'base_uri' => $url,
|
||||||
|
'verify' => false,
|
||||||
|
'headers' => [
|
||||||
|
'Content-Type' => 'application/xml;charset=UTF-8',
|
||||||
|
],
|
||||||
|
// 'body' => $xmlMeta,
|
||||||
|
]);
|
||||||
|
// Provide the body as a string.
|
||||||
|
$response = $client->request('PUT', $url, [
|
||||||
|
'body' => $newMeta,
|
||||||
|
]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$message = 'request to ' . $url . ' failed with ' . $e->getMessage();
|
||||||
|
// $this->log($message, 'err');
|
||||||
|
throw new DoiClientException($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
|
||||||
|
if ($response->getStatusCode() != 201) {
|
||||||
|
$message = 'unexpected DataCite MDS response code ' . $response->getStatusCode();
|
||||||
|
// $this->log($message, 'err');
|
||||||
|
throw new DoiClientException($message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Markiert den Datensatz zur übergebenen DOI als inaktiv.
|
* Markiert den Datensatz zur übergebenen DOI als inaktiv - Status registered (not findable)
|
||||||
*
|
*
|
||||||
* @param $doiValue
|
* @param $doiValue
|
||||||
*
|
*
|
||||||
|
|
|
@ -19,7 +19,7 @@ class CreateDatasetIdentifiersTable extends Migration
|
||||||
|
|
||||||
// foreign key to: documents.id
|
// foreign key to: documents.id
|
||||||
$table->integer('dataset_id')->unsigned();
|
$table->integer('dataset_id')->unsigned();
|
||||||
;
|
|
||||||
$table->foreign('dataset_id')->references('id')->on('documents')
|
$table->foreign('dataset_id')->references('id')->on('documents')
|
||||||
->onUpdate('cascade')->onDelete('cascade');
|
->onUpdate('cascade')->onDelete('cascade');
|
||||||
|
|
||||||
|
@ -34,8 +34,6 @@ class CreateDatasetIdentifiersTable extends Migration
|
||||||
'status',
|
'status',
|
||||||
['draft', 'registered', 'findable']
|
['draft', 'registered', 'findable']
|
||||||
)->nullable();
|
)->nullable();
|
||||||
// timestamp of DOI registration
|
|
||||||
$table->timestamp('registration_ts');
|
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -227,11 +227,21 @@
|
||||||
<xsl:value-of select="@Language" />
|
<xsl:value-of select="@Language" />
|
||||||
</xsl:attribute>
|
</xsl:attribute>
|
||||||
</xsl:if>
|
</xsl:if>
|
||||||
<xsl:if test="@Type != '' and @Type != 'Main'">
|
|
||||||
|
<xsl:choose>
|
||||||
|
<xsl:when test="@Type != '' and @Type != 'Sub' and @Type != 'Main'">
|
||||||
<xsl:attribute name="titleType">
|
<xsl:attribute name="titleType">
|
||||||
<xsl:value-of select="@Type" />
|
<xsl:value-of select="@Type" />
|
||||||
|
<xsl:text>Title</xsl:text>
|
||||||
</xsl:attribute>
|
</xsl:attribute>
|
||||||
</xsl:if>
|
</xsl:when>
|
||||||
|
<xsl:when test="@Type = 'Sub'">
|
||||||
|
<xsl:attribute name="titleType">
|
||||||
|
<xsl:value-of select="@Type" />
|
||||||
|
<xsl:text>title</xsl:text>
|
||||||
|
</xsl:attribute>
|
||||||
|
</xsl:when>
|
||||||
|
</xsl:choose>
|
||||||
<xsl:value-of select="@Value"/>
|
<xsl:value-of select="@Value"/>
|
||||||
</title>
|
</title>
|
||||||
</xsl:template>
|
</xsl:template>
|
||||||
|
|
|
@ -7,6 +7,7 @@ use Illuminate\Foundation\Testing\WithFaker;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use App\Tethys\Utils\DoiClient;
|
use App\Tethys\Utils\DoiClient;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class DoiClientTest extends TestCase
|
class DoiClientTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -21,48 +22,68 @@ class DoiClientTest extends TestCase
|
||||||
// $response->assertStatus(200);
|
// $response->assertStatus(200);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// public function testCheckDoi()
|
public function testCheckDoi()
|
||||||
// {
|
{
|
||||||
// $client = new DoiClient();
|
$client = new DoiClient();
|
||||||
// // $this->setExpectedException('Opus\Doi\ClientException');
|
// $this->setExpectedException('Opus\Doi\ClientException');
|
||||||
// $result = $client->checkDoi(
|
$publish_id = 1;
|
||||||
// '10.5072/tethys-999',
|
$prefix = config('tethys.datacite_prefix');
|
||||||
// 'http://localhost/opus4/frontdoor/index/index/999'
|
$doiValue = $prefix . '/tethys.' . $publish_id;
|
||||||
// );
|
$appUrl = config('app.url');
|
||||||
// $this->assertTrue($result);
|
$landingPageUrl = $appUrl . "/dataset/" . $publish_id;
|
||||||
|
$result = $client->checkDoi(
|
||||||
|
$doiValue,
|
||||||
|
$landingPageUrl
|
||||||
|
);
|
||||||
|
$this->assertTrue($result);
|
||||||
|
|
||||||
// $result = $client->checkDoi(
|
$result = $client->checkDoi(
|
||||||
// '10.5072/tethys-999',
|
'10.5072/tethys-999',
|
||||||
// 'http://localhost/opus4/frontdoor/index/index/111'
|
'http://localhost/opus4/frontdoor/index/index/111'
|
||||||
|
);
|
||||||
|
$this->assertFalse($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// public function testRegisterDoiWithDataCiteTestAccount()
|
||||||
|
// {
|
||||||
|
// // $this->markTestSkipped(
|
||||||
|
// // 'Test kann nur manuell gestartet werden (Zugangsdaten zum MDS-Testservice von DataCite erforderlich)'
|
||||||
|
// // );
|
||||||
|
|
||||||
|
// $myRequest = new Request();
|
||||||
|
// $myRequest->setMethod('POST');
|
||||||
|
|
||||||
|
// $myRequest->request->add(
|
||||||
|
// [
|
||||||
|
// 'publish_id' => 1,
|
||||||
|
// // 'path' => 'https://www.demo.laudatio-repository.org/foo'
|
||||||
|
// ]
|
||||||
// );
|
// );
|
||||||
// $this->assertFalse($result);
|
|
||||||
|
// $doiController = new \App\Http\Controllers\DoiController(new DoiClient());
|
||||||
|
// $doiController->store($myRequest);
|
||||||
|
|
||||||
|
|
||||||
|
// // $client = new DoiClient();
|
||||||
|
// // $client->registerDoi(
|
||||||
|
// // '10.5072/tethys-999',
|
||||||
|
// // xmlMeta,
|
||||||
|
// // 'http://localhost/opus4/frontdoor/index/index/999'
|
||||||
|
// // );
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public function testRegisterDoiWithDataCiteTestAccount()
|
public function testGetMetadataForDoi()
|
||||||
{
|
{
|
||||||
// $this->markTestSkipped(
|
$client = new DoiClient();
|
||||||
// 'Test kann nur manuell gestartet werden (Zugangsdaten zum MDS-Testservice von DataCite erforderlich)'
|
// $this->setExpectedException('Opus\Doi\ClientException');
|
||||||
// );
|
$publish_id = 1;
|
||||||
|
$prefix = config('tethys.datacite_prefix');
|
||||||
$myRequest = new Request();
|
$doiValue = $prefix . '/tethys.' . $publish_id;
|
||||||
$myRequest->setMethod('POST');
|
$response = $client->getMetadataForDoi(
|
||||||
|
$doiValue
|
||||||
$myRequest->request->add(
|
|
||||||
[
|
|
||||||
'publish_id' => 1,
|
|
||||||
'path' => 'https://www.demo.laudatio-repository.org/foo'
|
|
||||||
]
|
|
||||||
);
|
);
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
$doiController = new \App\Http\Controllers\DoiController(new DoiClient());
|
$testXml = new \SimpleXMLElement($response->getBody()->getContents());
|
||||||
$doiController->store($myRequest);
|
Log::alert($testXml->saveXML());
|
||||||
|
|
||||||
|
|
||||||
// $client = new DoiClient();
|
|
||||||
// $client->registerDoi(
|
|
||||||
// '10.5072/tethys-999',
|
|
||||||
// xmlMeta,
|
|
||||||
// 'http://localhost/opus4/frontdoor/index/index/999'
|
|
||||||
// );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user