Skip to content

Commit

Permalink
add funder #4371
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Oct 11, 2018
1 parent 4ca8f38 commit 043080d
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 7 deletions.
51 changes: 44 additions & 7 deletions src/main/java/edu/harvard/iq/dataverse/DatasetVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,37 @@ public List<DatasetAuthor> getDatasetAuthors() {
}
return retList;
}


public List<String> getFunders() {
List<String> retList = new ArrayList<>();
for (DatasetField dsf : this.getDatasetFields()) {
boolean addFunder = false;
if (dsf.getDatasetFieldType().getName().equals(DatasetFieldConstant.contributor)) {
for (DatasetFieldCompoundValue contributorValue : dsf.getDatasetFieldCompoundValues()) {
String contributorName = null;
String contributorType = null;
for (DatasetField subField : contributorValue.getChildDatasetFields()) {
if (subField.getDatasetFieldType().getName().equals(DatasetFieldConstant.contributorName)) {
contributorName = subField.getDisplayValue();
}
if (subField.getDatasetFieldType().getName().equals(DatasetFieldConstant.contributorType)) {
contributorType = subField.getDisplayValue();
// TODO: Consider how this will work in French, Chinese, etc.
String funderString = "Funder";

This comment has been minimized.

Copy link
@pdurbin

pdurbin Oct 11, 2018

Author Member

@JayanthyChengan @scolapasta any thoughts on how "Funder" is hard coded in English here? I guess I'm waiting for #4684 and controlledvocabulary.contributorType.funder=Funder from src/main/java/citation.properties in pull request #5111.

if (funderString.equals(contributorType)) {
addFunder = true;
}
}
}
if (addFunder) {
retList.add(contributorName);
}
}
}
}
return retList;
}

public List<String> getTimePeriodsCovered() {
List <String> retList = new ArrayList<>();
for (DatasetField dsf : this.getDatasetFields()) {
Expand Down Expand Up @@ -1486,12 +1516,6 @@ public String getJsonLd() {
*
*/

/**
* funder (if available)
* TODO
* (punted, for now - see #2243)
*/

job.add("schemaVersion", "https://schema.org/version/3.3");

TermsOfUseAndAccess terms = this.getTermsOfUseAndAccess();
Expand Down Expand Up @@ -1522,6 +1546,19 @@ public String getJsonLd() {
.add("@type", "Organization")
.add("name", installationBrandName)
);

List<String> funderNames = getFunders();
if (!funderNames.isEmpty()) {
JsonArrayBuilder funderArray = Json.createArrayBuilder();
for (String funderName : funderNames) {
JsonObjectBuilder funder = Json.createObjectBuilder();
funder.add("@type", "Organization");
funder.add("name", funderName);
funderArray.add(funder);
}
job.add("funder", funderArray);
}

jsonLd = job.build().toString();
return jsonLd;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,28 @@ public void setUp() {
t.setParentDatasetFieldType(compoundSingleType);
}
compoundSingleType.setChildDatasetFieldTypes(childTypes);

DatasetFieldType contributorType = datasetFieldTypeSvc.add(new DatasetFieldType("contributor", DatasetFieldType.FieldType.TEXT, true));
Set<DatasetFieldType> contributorChildTypes = new HashSet<>();
contributorChildTypes.add(datasetFieldTypeSvc.add(new DatasetFieldType("contributorName", DatasetFieldType.FieldType.TEXT, false)));
DatasetFieldType contributorTypes = datasetFieldTypeSvc.add(new DatasetFieldType("contributorType", DatasetFieldType.FieldType.TEXT, false));
contributorTypes.setAllowControlledVocabulary(true);
contributorTypes.setControlledVocabularyValues(Arrays.asList(
// Why aren't these enforced?
new ControlledVocabularyValue(1l, "Data Collector", contributorTypes),
new ControlledVocabularyValue(2l, "Data Curator", contributorTypes),
new ControlledVocabularyValue(3l, "Data Manager", contributorTypes),
new ControlledVocabularyValue(3l, "Editor", contributorTypes),
new ControlledVocabularyValue(3l, "Funder", contributorTypes),
new ControlledVocabularyValue(3l, "Hosting Institution", contributorTypes)
// Etc. There are more.
));
contributorChildTypes.add(datasetFieldTypeSvc.add(contributorTypes));
for (DatasetFieldType t : contributorChildTypes) {
t.setParentDatasetFieldType(contributorType);
}
contributorType.setChildDatasetFieldTypes(contributorChildTypes);

}

@After
Expand Down Expand Up @@ -194,6 +216,9 @@ public void testExportDataset() throws Exception {
assertEquals("https://librascholar.org", json2.getJsonObject("includedInDataCatalog").getString("url"));
assertEquals("Organization", json2.getJsonObject("provider").getString("@type"));
assertEquals("LibraScholar", json2.getJsonObject("provider").getString("name"));
assertEquals("Organization", json2.getJsonArray("funder").getJsonObject(0).getString("@type"));
assertEquals("National Science Foundation", json2.getJsonArray("funder").getJsonObject(0).getString("name"));
assertEquals(1, json2.getJsonArray("funder").size());
}

/**
Expand Down
35 changes: 35 additions & 0 deletions src/test/resources/json/dataset-finch2.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,41 @@
}
}
]
},
{
"typeName": "contributor",
"multiple": true,
"typeClass": "compound",
"value": [
{
"contributorType": {
"typeName": "contributorType",
"multiple": false,
"typeClass": "controlledVocabulary",
"value": "Data Collector"
},
"contributorName": {
"typeName": "contributorName",
"multiple": false,
"typeClass": "primitive",
"value": "Holmes, Sherlock"
}
},
{
"contributorType": {
"typeName": "contributorType",
"multiple": false,
"typeClass": "controlledVocabulary",
"value": "Funder"
},
"contributorName": {
"typeName": "contributorName",
"multiple": false,
"typeClass": "primitive",
"value": "National Science Foundation"
}
}
]
}
],
"displayName": "Citation Metadata"
Expand Down

0 comments on commit 043080d

Please sign in to comment.