forked from 4Science/DSpace
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
datacite import plugin for Project entities
import service for projects extending the existing datacite import plugin implementation and basic import mapping matching the current fields in the submission forms and the existing transformators/extractors for the metadata DSpace#9636
- Loading branch information
1 parent
f6ce766
commit 0e82053
Showing
12 changed files
with
309 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...-api/src/main/java/org/dspace/importer/external/datacite/DataCiteProjectFieldMapping.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* The contents of this file are subject to the license and copyright | ||
* detailed in the LICENSE and NOTICE files at the root of the source | ||
* tree and available online at | ||
* | ||
* http://www.dspace.org/license/ | ||
*/ | ||
package org.dspace.importer.external.datacite; | ||
|
||
import java.util.Map; | ||
|
||
import jakarta.annotation.Resource; | ||
import org.dspace.importer.external.metadatamapping.AbstractMetadataFieldMapping; | ||
|
||
/** | ||
* An implementation of {@link AbstractMetadataFieldMapping} | ||
* Responsible for defining the mapping of the datacite metadatum fields on the DSpace metadatum fields | ||
* | ||
* @author Pasquale Cavallo (pasquale.cavallo at 4science dot it) | ||
* @author Florian Gantner ([email protected]) | ||
*/ | ||
public class DataCiteProjectFieldMapping extends AbstractMetadataFieldMapping { | ||
|
||
/** | ||
* Defines which metadatum is mapped on which metadatum. Note that while the key must be unique it | ||
* only matters here for postprocessing of the value. The mapped MetadatumContributor has full control over | ||
* what metadatafield is generated. | ||
* | ||
* @param metadataFieldMap The map containing the link between retrieve metadata and metadata that will be set to | ||
* the item. | ||
*/ | ||
@Override | ||
@Resource(name = "dataciteProjectMetadataFieldMap") | ||
public void setMetadataFieldMap(Map metadataFieldMap) { | ||
super.setMetadataFieldMap(metadataFieldMap); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...org/dspace/importer/external/datacite/DataCiteProjectImportMetadataSourceServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* The contents of this file are subject to the license and copyright | ||
* detailed in the LICENSE and NOTICE files at the root of the source | ||
* tree and available online at | ||
* | ||
* http://www.dspace.org/license/ | ||
*/ | ||
package org.dspace.importer.external.datacite; | ||
|
||
/** | ||
* Implements a data source for querying Datacite for specific for Project resourceTypes. | ||
* This inherits the methods of DataCiteImportMetadataSourceServiceImpl | ||
* | ||
* @author Florian Gantner ([email protected]) | ||
* | ||
*/ | ||
public class DataCiteProjectImportMetadataSourceServiceImpl | ||
extends DataCiteImportMetadataSourceServiceImpl { | ||
|
||
@Override | ||
public String getImportSource() { | ||
return "dataciteProject"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
...ebapp/src/test/java/org/dspace/app/rest/DataCiteProjectImportMetadataSourceServiceIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/** | ||
* The contents of this file are subject to the license and copyright | ||
* detailed in the LICENSE and NOTICE files at the root of the source | ||
* tree and available online at | ||
* | ||
* http://www.dspace.org/license/ | ||
*/ | ||
package org.dspace.app.rest; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.io.InputStream; | ||
import java.nio.charset.Charset; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.apache.http.client.methods.CloseableHttpResponse; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.dspace.importer.external.datacite.DataCiteProjectImportMetadataSourceServiceImpl; | ||
import org.dspace.importer.external.datamodel.ImportRecord; | ||
import org.dspace.importer.external.liveimportclient.service.LiveImportClientImpl; | ||
import org.dspace.importer.external.metadatamapping.MetadatumDTO; | ||
import org.dspace.kernel.ServiceManager; | ||
import org.dspace.services.factory.DSpaceServicesFactory; | ||
import org.junit.Test; | ||
import org.mockito.ArgumentMatchers; | ||
import org.mockito.Mockito; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
|
||
/** | ||
* Integration tests for {@link DataCiteProjectImportMetadataSourceServiceImpl} | ||
* General tests for the datacite api are covered in the {@link DataCiteImportMetadataSourceServiceIT} | ||
* | ||
* @author Florian Gantner ([email protected]) | ||
*/ | ||
public class DataCiteProjectImportMetadataSourceServiceIT extends AbstractLiveImportIntegrationTest { | ||
|
||
@Autowired | ||
private LiveImportClientImpl liveImportClientImpl; | ||
|
||
// @Autowired | ||
private DataCiteProjectImportMetadataSourceServiceImpl dataCiteProjectServiceImpl; | ||
|
||
@Test | ||
public void dataCiteProjectImportMetadataGetRecordsTest() throws Exception { | ||
context.turnOffAuthorisationSystem(); | ||
ServiceManager serviceManager = DSpaceServicesFactory.getInstance().getServiceManager(); | ||
dataCiteProjectServiceImpl = serviceManager.getServiceByName("DataCiteProjectImportService", | ||
DataCiteProjectImportMetadataSourceServiceImpl.class); | ||
CloseableHttpClient originalHttpClient = liveImportClientImpl.getHttpClient(); | ||
CloseableHttpClient httpClient = Mockito.mock(CloseableHttpClient.class); | ||
try (InputStream dataCiteResp = getClass().getResourceAsStream("dataCiteProject-test.json")) { | ||
String dataCiteRespXmlResp = IOUtils.toString(dataCiteResp, Charset.defaultCharset()); | ||
|
||
liveImportClientImpl.setHttpClient(httpClient); | ||
CloseableHttpResponse response = mockResponse(dataCiteRespXmlResp, 200, "OK"); | ||
when(httpClient.execute(ArgumentMatchers.any())).thenReturn(response); | ||
|
||
context.restoreAuthSystemState(); | ||
ArrayList<ImportRecord> collection2match = getRecords(); | ||
Collection<ImportRecord> recordsImported = dataCiteProjectServiceImpl.getRecords("10.60872/ror", | ||
0, -1); | ||
assertEquals(1, recordsImported.size()); | ||
matchRecords(new ArrayList<>(recordsImported), collection2match); | ||
} finally { | ||
liveImportClientImpl.setHttpClient(originalHttpClient); | ||
} | ||
} | ||
|
||
private ArrayList<ImportRecord> getRecords() { | ||
ArrayList<ImportRecord> records = new ArrayList<>(); | ||
//define first record | ||
List<MetadatumDTO> metadatums = new ArrayList<>(); | ||
MetadatumDTO title = createMetadatumDTO("dc", "title", null, | ||
"Affiliations and Identifiers for Research Organizations (ROR)"); | ||
MetadatumDTO title1 = createMetadatumDTO("dc", "title", null, | ||
"Identifying Organizations"); | ||
MetadatumDTO projectidentifier = createMetadatumDTO("dc", "identifier", null, "10.60872/ror"); | ||
MetadatumDTO contributor1 = createMetadatumDTO("project", "investigator", null, | ||
"Ted Habermann"); | ||
MetadatumDTO description1 = createMetadatumDTO("dc", "description", null, | ||
"The Research Organization Registry (ROR) is a community-led project launched in January 2019 to " + | ||
"develop an open, sustainable, usable, and unique identifier for every research organization in the " + | ||
"world. Metadata Game Changers worked with Dryad in the first large-scale adoption of RORs by a " + | ||
"repository. We connected to papers related to Dryad datasets, found affiliations from Crossref and " + | ||
"other sources, searched the early ROR for identifiers, and added them to the Dryad metadata. Since " + | ||
"that time, we have been involved in re-curating repositories to add RORs and other kinds of " + | ||
"identifiers."); | ||
MetadatumDTO subject1 = createMetadatumDTO("dc", "subject", null, "ROR"); | ||
MetadatumDTO subject2 = createMetadatumDTO("dc", "subject", null, | ||
"Research Organizations"); | ||
MetadatumDTO subject3 = createMetadatumDTO("dc", "subject", null, "Identifiers"); | ||
MetadatumDTO subject4 = createMetadatumDTO("dc", "subject", null, "Affiliations"); | ||
MetadatumDTO subject5 = createMetadatumDTO("dc", "subject", null, "Metadata"); | ||
metadatums.add(title); | ||
metadatums.add(title1); | ||
metadatums.add(projectidentifier); | ||
metadatums.add(contributor1); | ||
metadatums.add(description1); | ||
metadatums.add(subject1); | ||
metadatums.add(subject2); | ||
metadatums.add(subject3); | ||
metadatums.add(subject4); | ||
metadatums.add(subject5); | ||
|
||
ImportRecord firstRecord = new ImportRecord(metadatums); | ||
|
||
records.add(firstRecord); | ||
return records; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
dspace-server-webapp/src/test/resources/org/dspace/app/rest/dataCiteProject-test.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters