Skip to content

Commit

Permalink
Merge branch 'changeLicenseSending-595' into 'main'
Browse files Browse the repository at this point in the history
Changes exporting of dataset license in Dataset Package

See merge request softwares-pkp/plugins_ojs/dataverse!144
  • Loading branch information
JhonathanLepidus committed Sep 28, 2023
2 parents 2de2b77 + 5be7041 commit 2d5fa08
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 43 deletions.
13 changes: 0 additions & 13 deletions classes/DataverseMetadata.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,6 @@ public function getDefaultLicense(): string
}
}

public function getLicenseUri(string $licenseName): string
{
if(is_null($this->dataverseLicenses)) {
$this->getDataverseLicenses();
}

foreach($this->dataverseLicenses as $license) {
if($license['name'] == $licenseName) {
return $license['uri'];
}
}
}

private function getDataverseConfiguration(): DataverseConfiguration
{
$request = Application::get()->getRequest();
Expand Down
16 changes: 2 additions & 14 deletions dataverseAPI/packagers/NativeAPIDatasetPackager.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ public function __construct(Dataset $dataset)
parent::__construct($dataset);
}

public function setDataverseMetadata(DataverseMetadata $dataverseMetadata)
{
$this->dataverseMetadata = $dataverseMetadata;
}

public function getPackageDirPath(): string
{
return $this->packageDirPath;
Expand All @@ -40,7 +35,7 @@ public function loadPackageData(): void
$datasetData = $this->dataset->getAllData();

if(isset($datasetData['license'])) {
$this->datasetLicense = $this->createLicenseNode($datasetData['license']);
$this->datasetLicense = $datasetData['license'];
}

foreach ($datasetData as $attr => $value) {
Expand Down Expand Up @@ -127,13 +122,6 @@ public function getMetadataField(string $metadata): array
return isset($fields[$metadata]) ? $fields[$metadata] : [];
}

private function createLicenseNode(string $licenseName): array
{
$licenseUri = $this->dataverseMetadata->getLicenseUri($licenseName);

return ['name' => $licenseName, 'uri' => $licenseUri];
}

private function createSimpleCompoundMetadata(array $metadataField, string $value): array
{
$typeName = $metadataField['typeName'] == 'publication'
Expand Down Expand Up @@ -183,7 +171,7 @@ public function createDatasetPackage(): void
$datasetContent['metadataBlocks']['citation']['fields'] = $this->getDatasetMetadata();

if(is_null($this->dataset->getPersistentId())) {
$datasetContent['datasetVersion'] = $datasetContent;
$datasetContent = ['datasetVersion' => $datasetContent];
}

$datasetPackage = fopen($this->getPackagePath(), 'w');
Expand Down
19 changes: 3 additions & 16 deletions tests/dataverseAPI/packagers/NativeAPIDatasetPackagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
class NativeAPIDatasetPackagerTest extends PKPTestCase
{
private $packager;
private $licenseName = 'CC BY 4.0';
private $licenseUri = 'http://creativecommons.org/licenses/by/4.0';
private $license = 'CC BY 4.0';

protected function setUp(): void
{
Expand All @@ -21,16 +20,6 @@ protected function tearDown(): void
parent::tearDown();
}

private function getDataverseMetadataMock()
{
$mockDataverseMetadata = $this->createMock(DataverseMetadata::class);
$mockDataverseMetadata->method('getLicenseUri')->willReturnMap([
[$this->licenseName, $this->licenseUri]
]);

return $mockDataverseMetadata;
}

public function testNativeAPIPackagerReturnsPackageDirPath(): void
{
$dataset = new Dataset();
Expand Down Expand Up @@ -175,18 +164,16 @@ public function testDatasetJsonContainsDatasetData(): void
$dataset = new Dataset();
$dataset->setPersistentId('doi:10.5072/FK2/TEST');
$dataset->setTitle('Test title');
$dataset->setLicense($this->licenseName);
$dataset->setLicense($this->license);

$this->packager = new NativeAPIDatasetPackager($dataset);
$this->packager->setDataverseMetadata($this->getDataverseMetadataMock());
$this->packager->loadPackageData();
$this->packager->createDatasetPackage();

$datasetJson = json_decode(file_get_contents($this->packager->getPackageDirPath() . '/dataset.json'), true);

$licenseInJson = $datasetJson['license'];
$expectedLicense = ['name' => $this->licenseName, 'uri' => $this->licenseUri];
$this->assertEquals($expectedLicense, $licenseInJson);
$this->assertEquals($this->license, $licenseInJson);

$titleInJson = $datasetJson['metadataBlocks']['citation']['fields'][0]['value'];
$this->assertEquals($dataset->getTitle(), $titleInJson);
Expand Down

0 comments on commit 2d5fa08

Please sign in to comment.