Skip to content

Commit

Permalink
Merged in task/dspace-cris-2023_02_x/DSC-1935 (pull request DSpace#2789)
Browse files Browse the repository at this point in the history
[DSC-1935] Update Datacite schema

Approved-by: Stefano Maffei
  • Loading branch information
NikitaKr1vonosov authored and steph-ieffam committed Oct 4, 2024
2 parents 96d33a9 + 43d9ce2 commit b93ffc3
Show file tree
Hide file tree
Showing 8 changed files with 244 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* 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.content.integration.crosswalks.virtualfields;

import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.dspace.content.Item;
import org.dspace.content.MetadataValue;
import org.dspace.content.service.ItemService;
import org.dspace.core.Context;
import org.springframework.beans.factory.annotation.Autowired;

/**
* Builds the values at specific place.
*
* @author Mohamed Eskander (mohamed.eskander at 4science.com)
*/
public class VirtualFieldAtPlace implements VirtualField {

private final ItemService itemService;

@Autowired
public VirtualFieldAtPlace(ItemService itemService) {
this.itemService = itemService;
}

public String[] getMetadata(Context context, Item item, String fieldName) {
String[] virtualFieldName = fieldName.split("\\.", 4);
if (virtualFieldName.length != 4) {
return new String[] {};
}

String metadataField = virtualFieldName[2].replaceAll("-", ".");
int place = Integer.parseInt(virtualFieldName[3]);
List<MetadataValue> values = itemService.getMetadataByMetadataString(item, metadataField);
if (CollectionUtils.isEmpty(values)) {
return null;
}

return new String[] { values.get(place).getValue() };
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<resource
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://datacite.org/schema/kernel-4" xsi:schemaLocation="http://datacite.org/schema/kernel-4 http://schema.datacite.org/meta/kernel-4/metadata.xsd">
<creators>
<creator>
<creatorName>(:unav)</creatorName>
</creator>
</creators>
<titles>
<title>Publication title</title>
</titles>
<publisher
publisherIdentifier="rorID2" publisherIdentifierScheme="ROR" schemeURI="https://ror.org/"
>Publisher</publisher>
<publicationYear>2023</publicationYear>
<dates>
<date dateType="Issued">2023</date>
<date dateType="Available">2023-10-20</date>
</dates>
<language>it</language>
<resourceType resourceTypeGeneral="Other">
Unknown
</resourceType>
<alternateIdentifiers>
<alternateIdentifier alternateIdentifierType="url">http://localhost:4000/handle/123456789/99999</alternateIdentifier>
</alternateIdentifiers>
<rightsList>
</rightsList>
<descriptions>
</descriptions>
</resource>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<resource
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://datacite.org/schema/kernel-4" xsi:schemaLocation="http://datacite.org/schema/kernel-4 http://schema.datacite.org/meta/kernel-4/metadata.xsd">
<creators>
<creator>
<creatorName>(:unav)</creatorName>
</creator>
</creators>
<titles>
<title>Publication title</title>
</titles>
<publisher
publisherIdentifier="rorID2" publisherIdentifierScheme="ROR" schemeURI="https://ror.org/"
>Publisher</publisher>
<publicationYear>2023</publicationYear>
<dates>
<date dateType="Issued">2023</date>
<date dateType="Available">2023-10-20</date>
</dates>
<resourceType resourceTypeGeneral="Other">
Unknown
</resourceType>
<alternateIdentifiers>
<alternateIdentifier alternateIdentifierType="url">http://localhost:4000/handle/123456789/99999</alternateIdentifier>
</alternateIdentifiers>
<rightsList>
</rightsList>
<descriptions>
</descriptions>
</resource>
Original file line number Diff line number Diff line change
Expand Up @@ -2606,6 +2606,76 @@ public void testReferCrosswalkPublicationDataciteXml() throws Exception {

}

@Test
public void testReferCrosswalkPublicationDataciteXmlWithoutTypeAndAuthor() throws Exception {

ReferCrosswalk referCrosswalk = new DSpace().getServiceManager()
.getServiceByName("referCrosswalkPublicationDataciteXml", ReferCrosswalk.class);
assertThat(referCrosswalk, notNullValue());

Item publisher = createItem(context, collection)
.withEntityType("OrgUnit")
.withTitle("Publisher Name")
.withOrgUnitRORIdentifier("rorID2")
.build();
Item item = createItem(context, collection)
.withEntityType("Publication")
.withTitle("Publication title")
.withPublisher("Publisher", publisher.getID().toString())
.withIssueDate("2023")
.withDateAvailable("2023-10-20")
.withHandle("123456789/99999")
.build();

ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

referCrosswalk.disseminate(context, item, byteArrayOutputStream);

System.out.println(new String(byteArrayOutputStream.toByteArray()));

try (FileInputStream fis = getFileInputStream("publication-without-authors-and-type-datacite.xml")) {
String expectedXml = IOUtils.toString(fis, Charset.defaultCharset());
compareEachLine(byteArrayOutputStream.toString(), expectedXml);
}

}

@Test
public void testReferCrosswalkPublicationDataciteXmlWithVirtualPlace() throws Exception {

ReferCrosswalk referCrosswalk = new DSpace().getServiceManager()
.getServiceByName("referCrosswalkPublicationDataciteXml", ReferCrosswalk.class);
assertThat(referCrosswalk, notNullValue());

Item publisher = createItem(context, collection)
.withEntityType("OrgUnit")
.withTitle("Publisher Name")
.withOrgUnitRORIdentifier("rorID2")
.build();
Item item = createItem(context, collection)
.withEntityType("Publication")
.withTitle("Publication title")
.withPublisher("Publisher", publisher.getID().toString())
.withIssueDate("2023")
.withLanguage(Locale.ITALIAN.getLanguage())
.withLanguage(Locale.ENGLISH.getLanguage())
.withDateAvailable("2023-10-20")
.withHandle("123456789/99999")
.build();

ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

referCrosswalk.disseminate(context, item, byteArrayOutputStream);

System.out.println(new String(byteArrayOutputStream.toByteArray()));

try (FileInputStream fis = getFileInputStream("publication-virtual-place-datacite.xml")) {
String expectedXml = IOUtils.toString(fis, Charset.defaultCharset());
compareEachLine(byteArrayOutputStream.toString(), expectedXml);
}

}

@Test
public void testExportToDataciteFormatItemWithThreeDOI() throws Exception {
String prefix;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,17 @@
<date dateType="Available">@dc.date.available@</date>
@if.not.metadata.datacite-available.end@
</dates>
<language>@dc.language.iso@</language>
<language>@virtual.place.dc-language-iso.0@</language>
@if.metadata.dc-type.start@
<resourceType resourceTypeGeneral="@virtual.mapConverter.type2datacite.dc-type@">
@virtual.mapConverter.type2datacitelabel.dc-type@
</resourceType>
@if.metadata.dc-type.end@
@if.not.metadata.dc-type.start@
<resourceType resourceTypeGeneral="Other">
Unknown
</resourceType>
@if.not.metadata.dc-type.end@
<alternateIdentifiers>
<alternateIdentifier alternateIdentifierType="url">@dc.identifier.uri@</alternateIdentifier>
<alternateIdentifier alternateIdentifierType="doi">@virtual.alternative-doi.dc-identifier-doi@</alternateIdentifier>
Expand Down
16 changes: 14 additions & 2 deletions dspace/config/crosswalks/template/product-datacite-xml.template
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@
@relation.dc-publisher.end@
>@dc.publisher@</publisher>
@if.metadata.dc-publisher.end@
<publicationYear>@virtual.date.dc-date-issued.YYYY@</publicationYear>
@if.metadata.dc-date-issued.start@
<publicationYear>@virtual.date.dc-date-issued.YYYY@</publicationYear>
@if.metadata.dc-date-issued.end@
@if.not.metadata.dc-date-issued.start@
<publicationYear>(:unav)</publicationYear>
@if.not.metadata.dc-date-issued.end@
@if.metadata.dc-subject.start@
<subjects>
<subject>@dc.subject@</subject>
Expand All @@ -46,10 +51,17 @@
<date dateType="Available">@dc.date.available@</date>
@if.not.metadata.datacite-available.end@
</dates>
<language>@dc.language.iso@</language>
<language>@virtual.place.dc-language-iso.0@</language>
@if.metadata.dc-type.start@
<resourceType resourceTypeGeneral="@virtual.mapConverter.type2datacite.dc-type@">
@virtual.mapConverter.type2datacitelabel.dc-type@
</resourceType>
@if.metadata.dc-type.end@
@if.not.metadata.dc-type.start@
<resourceType resourceTypeGeneral="Other">
Unknown
</resourceType>
@if.not.metadata.dc-type.end@
<alternateIdentifiers>
<alternateIdentifier alternateIdentifierType="url">@dc.identifier.uri@</alternateIdentifier>
<alternateIdentifier alternateIdentifierType="doi">@virtual.alternative-doi.dc-identifier-doi@</alternateIdentifier>
Expand Down
55 changes: 37 additions & 18 deletions dspace/config/crosswalks/template/publication-datacite-xml.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,29 @@
xmlns="http://datacite.org/schema/kernel-4" xsi:schemaLocation="http://datacite.org/schema/kernel-4 http://schema.datacite.org/meta/kernel-4/metadata.xsd">
<identifier identifierType="DOI">@virtual.primary-doi.dc-identifier-doi@</identifier>
<creators>
@group.dc-contributor-author.start@
<creator>
<creatorName>@dc.contributor.author@</creatorName>
@relation.dc-contributor-author.start@
<nameIdentifier nameIdentifierScheme="ORCID" schemeURI="http://orcid.org/">@person.identifier.orcid@</nameIdentifier>
@relation.dc-contributor-author.end@
@relation.oairecerif-author-affiliation.start@
<affiliation
affiliationIdentifier="@organization.identifier.ror@" affiliationIdentifierScheme="ROR" schemeURI="https://ror.org/"
>@dc.title@</affiliation>
@relation.oairecerif-author-affiliation.end@
@if.not.authority.oairecerif-author-affiliation.start@
<affiliation>@oairecerif.author.affiliation@</affiliation>
@if.not.authority.oairecerif-author-affiliation.end@
</creator>
@group.dc-contributor-author.end@
@if.metadata.dc-contributor-author.start@
@group.dc-contributor-author.start@
<creator>
<creatorName>@dc.contributor.author@</creatorName>
@relation.dc-contributor-author.start@
<nameIdentifier nameIdentifierScheme="ORCID" schemeURI="http://orcid.org/">@person.identifier.orcid@</nameIdentifier>
@relation.dc-contributor-author.end@
@relation.oairecerif-author-affiliation.start@
<affiliation
affiliationIdentifier="@organization.identifier.ror@" affiliationIdentifierScheme="ROR" schemeURI="https://ror.org/"
>@dc.title@</affiliation>
@relation.oairecerif-author-affiliation.end@
@if.not.authority.oairecerif-author-affiliation.start@
<affiliation>@oairecerif.author.affiliation@</affiliation>
@if.not.authority.oairecerif-author-affiliation.end@
</creator>
@group.dc-contributor-author.end@
@if.metadata.dc-contributor-author.end@
@if.not.metadata.dc-contributor-author.start@
<creator>
<creatorName>(:unav)</creatorName>
</creator>
@if.not.metadata.dc-contributor-author.end@
</creators>
<titles>
<title>@dc.title@</title>
Expand All @@ -31,7 +38,12 @@
@relation.dc-publisher.end@
>@dc.publisher@</publisher>
@if.metadata.dc-publisher.end@
<publicationYear>@virtual.date.dc-date-issued.YYYY@</publicationYear>
@if.metadata.dc-date-issued.start@
<publicationYear>@virtual.date.dc-date-issued.YYYY@</publicationYear>
@if.metadata.dc-date-issued.end@
@if.not.metadata.dc-date-issued.start@
<publicationYear>(:unav)</publicationYear>
@if.not.metadata.dc-date-issued.end@
@if.metadata.dc-subject.start@
<subjects>
<subject>@dc.subject@</subject>
Expand All @@ -46,10 +58,17 @@
<date dateType="Available">@dc.date.available@</date>
@if.not.metadata.datacite-available.end@
</dates>
<language>@dc.language.iso@</language>
<language>@virtual.place.dc-language-iso.0@</language>
@if.metadata.dc-type.start@
<resourceType resourceTypeGeneral="@virtual.mapConverter.type2datacite.dc-type@">
@virtual.mapConverter.type2datacitelabel.dc-type@
</resourceType>
@if.metadata.dc-type.end@
@if.not.metadata.dc-type.start@
<resourceType resourceTypeGeneral="Other">
Unknown
</resourceType>
@if.not.metadata.dc-type.end@
<alternateIdentifiers>
<alternateIdentifier alternateIdentifierType="url">@dc.identifier.uri@</alternateIdentifier>
<alternateIdentifier alternateIdentifierType="doi">@virtual.alternative-doi.dc-identifier-doi@</alternateIdentifier>
Expand Down
4 changes: 3 additions & 1 deletion dspace/config/spring/api/crosswalks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@
<entry key="vocabulary_i18n" value-ref="virtualFieldVocabularyI18n" />
<entry key="metric" value-ref="virtualFieldMetric" />
<entry key="citations" value-ref="virtualFieldCitations" />
<entry key="place" value-ref="virtualFieldAtPlace" />
</map>
</constructor-arg>
</bean>
Expand Down Expand Up @@ -606,7 +607,8 @@

<bean class="org.dspace.content.integration.crosswalks.virtualfields.postprocessors.FirstSelectedCitationsPostProcessor" />
<bean class="org.dspace.content.integration.crosswalks.virtualfields.postprocessors.GroupByTypeCitationsPostProcessor" />

<bean class="org.dspace.content.integration.crosswalks.virtualfields.VirtualFieldAtPlace" id="virtualFieldAtPlace"/>

<!-- MapConverter configuration -->

<bean id="org.dspace.util.MapConverters" class="org.dspace.util.MapConverters">
Expand Down

0 comments on commit b93ffc3

Please sign in to comment.