Skip to content

Commit

Permalink
Merge pull request #9440 from lubitchv/9428-alternative-title
Browse files Browse the repository at this point in the history
make Alternative Title repeatable
  • Loading branch information
kcondon committed Sep 22, 2023
2 parents 4117f49 + 85e6661 commit fa577fb
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 24 deletions.
2 changes: 1 addition & 1 deletion conf/solr/9.3.0/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@
<!-- SCHEMA-FIELDS::BEGIN -->
<field name="accessToSources" type="text_en" multiValued="false" stored="true" indexed="true"/>
<field name="actionsToMinimizeLoss" type="text_en" multiValued="false" stored="true" indexed="true"/>
<field name="alternativeTitle" type="text_en" multiValued="false" stored="true" indexed="true"/>
<field name="alternativeTitle" type="text_en" multiValued="true" stored="true" indexed="true"/>
<field name="alternativeURL" type="text_en" multiValued="false" stored="true" indexed="true"/>
<field name="astroFacility" type="text_en" multiValued="true" stored="true" indexed="true"/>
<field name="astroInstrument" type="text_en" multiValued="true" stored="true" indexed="true"/>
Expand Down
9 changes: 9 additions & 0 deletions doc/release-notes/9428-alternative-title.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Alternative Title is made repeatable.
- One will need to update database with updated citation block.
`curl http://localhost:8080/api/admin/datasetfield/load -H "Content-type: text/tab-separated-values" -X POST --upload-file scripts/api/data/metadatablocks/citation.tsv`
- One will also need to update solr schema:
Change in "alternativeTitle" field multiValued="true" in `/usr/local/solr/solr-8.11.1/server/solr/collection1/conf/schema.xml`
Reload solr schema: `curl "http://localhost:8983/solr/admin/cores?action=RELOAD&core=collection1"`

Since Alternative Title is repeatable now, old json apis would not be compatable with a new version since value of alternative title has changed from simple string to an array.
For example, instead "value": "Alternative Title", the value canbe "value": ["Alternative Title1", "Alternative Title2"]
4 changes: 2 additions & 2 deletions scripts/api/data/dataset-create-new-all-default-fields.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
},
{
"typeName": "alternativeTitle",
"multiple": false,
"multiple": true,
"typeClass": "primitive",
"value": "Alternative Title"
"value": ["Alternative Title"]
},
{
"typeName": "alternativeURL",
Expand Down
2 changes: 1 addition & 1 deletion scripts/api/data/metadatablocks/citation.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#datasetField name title description watermark fieldType displayOrder displayFormat advancedSearchField allowControlledVocabulary allowmultiples facetable displayoncreate required parent metadatablock_id termURI
title Title The main title of the Dataset text 0 TRUE FALSE FALSE FALSE TRUE TRUE citation http://purl.org/dc/terms/title
subtitle Subtitle A secondary title that amplifies or states certain limitations on the main title text 1 FALSE FALSE FALSE FALSE FALSE FALSE citation
alternativeTitle Alternative Title Either 1) a title commonly used to refer to the Dataset or 2) an abbreviation of the main title text 2 FALSE FALSE FALSE FALSE FALSE FALSE citation http://purl.org/dc/terms/alternative
alternativeTitle Alternative Title Either 1) a title commonly used to refer to the Dataset or 2) an abbreviation of the main title text 2 FALSE FALSE TRUE FALSE FALSE FALSE citation http://purl.org/dc/terms/alternative
alternativeURL Alternative URL Another URL where one can view or access the data in the Dataset, e.g. a project or personal webpage https:// url 3 <a href="#VALUE" target="_blank">#VALUE</a> FALSE FALSE FALSE FALSE FALSE FALSE citation https://schema.org/distribution
otherId Other Identifier Another unique identifier for the Dataset (e.g. producer's or another repository's identifier) none 4 : FALSE FALSE TRUE FALSE FALSE FALSE citation
otherIdAgency Agency The name of the agency that generated the other identifier text 5 #VALUE FALSE FALSE FALSE FALSE FALSE FALSE otherId citation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,7 @@ private void processProdStmt(XMLStreamReader xmlr, MetadataBlockDTO citation) th
List<HashSet<FieldDTO>> producers = new ArrayList<>();
List<HashSet<FieldDTO>> grants = new ArrayList<>();
List<HashSet<FieldDTO>> software = new ArrayList<>();
List<String> prodPlac = new ArrayList<>();

for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) {
if (event == XMLStreamConstants.START_ELEMENT) {
Expand All @@ -1353,9 +1354,7 @@ private void processProdStmt(XMLStreamReader xmlr, MetadataBlockDTO citation) th
} else if (xmlr.getLocalName().equals("prodDate")) {
citation.getFields().add(FieldDTO.createPrimitiveFieldDTO("productionDate", parseDate(xmlr, "prodDate")));
} else if (xmlr.getLocalName().equals("prodPlac")) {
List<String> prodPlac = new ArrayList<>();
prodPlac.add(parseText(xmlr, "prodPlac"));
citation.getFields().add(FieldDTO.createMultiplePrimitiveFieldDTO(DatasetFieldConstant.productionPlace, prodPlac));
prodPlac.add(parseText(xmlr));
} else if (xmlr.getLocalName().equals("software")) {
HashSet<FieldDTO> set = new HashSet<>();
addToSet(set,"softwareVersion", xmlr.getAttributeValue(null, "version"));
Expand Down Expand Up @@ -1388,6 +1387,9 @@ private void processProdStmt(XMLStreamReader xmlr, MetadataBlockDTO citation) th
if (producers.size()>0) {
citation.getFields().add(FieldDTO.createMultipleCompoundFieldDTO("producer", producers));
}
if (prodPlac.size() > 0) {
citation.getFields().add(FieldDTO.createMultiplePrimitiveFieldDTO(DatasetFieldConstant.productionPlace, prodPlac));
}
return;
}
}
Expand All @@ -1397,6 +1399,7 @@ private void processProdStmt(XMLStreamReader xmlr, MetadataBlockDTO citation) th
private void processTitlStmt(XMLStreamReader xmlr, DatasetDTO datasetDTO) throws XMLStreamException, ImportException {
MetadataBlockDTO citation = datasetDTO.getDatasetVersion().getMetadataBlocks().get("citation");
List<HashSet<FieldDTO>> otherIds = new ArrayList<>();
List<String> altTitles = new ArrayList<>();

for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) {
if (event == XMLStreamConstants.START_ELEMENT) {
Expand All @@ -1407,8 +1410,7 @@ private void processTitlStmt(XMLStreamReader xmlr, DatasetDTO datasetDTO) throws
FieldDTO field = FieldDTO.createPrimitiveFieldDTO("subtitle", parseText(xmlr));
citation.getFields().add(field);
} else if (xmlr.getLocalName().equals("altTitl")) {
FieldDTO field = FieldDTO.createPrimitiveFieldDTO("alternativeTitle", parseText(xmlr));
citation.getFields().add(field);
altTitles.add(parseText(xmlr));
} else if (xmlr.getLocalName().equals("IDNo")) {
if ( AGENCY_HANDLE.equals( xmlr.getAttributeValue(null, "agency") ) || AGENCY_DOI.equals( xmlr.getAttributeValue(null, "agency") ) ) {
importGenericService.reassignIdentifierAsGlobalId(parseText(xmlr), datasetDTO);
Expand Down Expand Up @@ -1436,6 +1438,10 @@ private void processTitlStmt(XMLStreamReader xmlr, DatasetDTO datasetDTO) throws
if (otherIds.size()>0) {
citation.addField(FieldDTO.createMultipleCompoundFieldDTO("otherId", otherIds));
}
if (!altTitles.isEmpty()) {
FieldDTO field = FieldDTO.createMultiplePrimitiveFieldDTO(DatasetFieldConstant.alternativeTitle, altTitles);
citation.getFields().add(field);
}
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@ private static void createStdyDscr(XMLStreamWriter xmlw, DatasetDTO datasetDto)

writeFullElement(xmlw, "titl", dto2Primitive(version, DatasetFieldConstant.title), datasetDto.getMetadataLanguage());
writeFullElement(xmlw, "subTitl", dto2Primitive(version, DatasetFieldConstant.subTitle));
writeFullElement(xmlw, "altTitl", dto2Primitive(version, DatasetFieldConstant.alternativeTitle));
FieldDTO altField = dto2FieldDTO( version, DatasetFieldConstant.alternativeTitle, "citation" );
if (altField != null) {
writeMultipleElement(xmlw, "altTitl", altField, datasetDto.getMetadataLanguage());
}

xmlw.writeStartElement("IDNo");
writeAttribute(xmlw, "agency", persistentAgency);
Expand Down Expand Up @@ -988,7 +991,11 @@ private static void writeProducersElement(XMLStreamWriter xmlw, DatasetVersionDT
// productionPlace was made multiple as of 5.14:
// (a quick backward compatibility check was added to dto2PrimitiveList(),
// see the method for details)
writeFullElementList(xmlw, "prodPlac", dto2PrimitiveList(version, DatasetFieldConstant.productionPlace));

FieldDTO prodPlac = dto2FieldDTO( version, DatasetFieldConstant.productionPlace, "citation" );
if (prodPlac != null) {
writeMultipleElement(xmlw, "prodPlac", prodPlac, null);
}
writeSoftwareElement(xmlw, version);

writeGrantElement(xmlw, version);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package edu.harvard.iq.dataverse.export.openaire;

import java.io.OutputStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.logging.Logger;

import jakarta.json.JsonObject;
Expand Down Expand Up @@ -325,12 +321,34 @@ public static void writeTitlesElement(XMLStreamWriter xmlw, DatasetVersionDTO da
String subtitle = dto2Primitive(datasetVersionDTO, DatasetFieldConstant.subTitle);
title_check = writeTitleElement(xmlw, "Subtitle", subtitle, title_check, language);

String alternativeTitle = dto2Primitive(datasetVersionDTO, DatasetFieldConstant.alternativeTitle);
title_check = writeTitleElement(xmlw, "AlternativeTitle", alternativeTitle, title_check, language);

title_check = writeMultipleTitleElement(xmlw, "AlternativeTitle", datasetVersionDTO, "citation", title_check, language);
writeEndTag(xmlw, title_check);
}

private static boolean writeMultipleTitleElement(XMLStreamWriter xmlw, String titleType, DatasetVersionDTO datasetVersionDTO, String metadataBlockName, boolean title_check, String language) throws XMLStreamException {
MetadataBlockDTO block = datasetVersionDTO.getMetadataBlocks().get(metadataBlockName);
if (block != null) {
logger.fine("Block is not empty");
List<FieldDTO> fieldsBlock = block.getFields();
if (fieldsBlock != null) {
for (FieldDTO fieldDTO : fieldsBlock) {
logger.fine(titleType + " " + fieldDTO.getTypeName());
if (titleType.toLowerCase().equals(fieldDTO.getTypeName().toLowerCase())) {
logger.fine("Found Alt title");
List<String> fields = fieldDTO.getMultiplePrimitive();
for (String value : fields) {
if (!writeTitleElement(xmlw, titleType, value, title_check, language))
title_check = false;
}
break;
}
}
}
}

return title_check;
}

/**
* 3, Title (with optional type sub-properties) (M)
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
},
{
"typeName": "alternativeTitle",
"multiple": false,
"multiple": true,
"typeClass": "primitive",
"value": "Alternative Title"
"value": ["Alternative Title"]
},
{
"typeName": "alternativeURL",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
},
{
"typeName": "alternativeTitle",
"multiple": false,
"multiple": true,
"typeClass": "primitive",
"value": "Alternative Title"
"value": ["Alternative Title1", "Alternative Title2"]
},
{
"typeName": "otherId",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
"typeClass": "primitive",
"value": "Darwin's Finches"
},
{
"typeName": "alternativeTitle",
"multiple": true,
"typeClass": "primitive",
"value": ["Darwin's Finches Alternative Title1", "Darwin's Finches Alternative Title2"]
},
{
"typeName": "author",
"multiple": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<citation>
<titlStmt>
<titl xml:lang="en">Darwin's Finches</titl>
<altTitl>Darwin's Finches Alternative Title1</altTitl>
<altTitl>Darwin's Finches Alternative Title2</altTitl>
<IDNo agency="DOI">doi:10.5072/FK2/PCA2E3</IDNo>
</titlStmt>
<rspStmt>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
<titlStmt>
<titl>Replication Data for: Title</titl>
<subTitl>Subtitle</subTitl>
<altTitl>Alternative Title</altTitl>
<altTitl>Alternative Title1</altTitl>
<altTitl>Alternative Title2</altTitl>
<IDNo agency="DOI">doi:10.5072/FK2/WKUKGV</IDNo>
<IDNo agency="OtherIDAgency1">OtherIDIdentifier1</IDNo>
<IDNo agency="OtherIDAgency2">OtherIDIdentifier2</IDNo>
Expand Down

0 comments on commit fa577fb

Please sign in to comment.