use of edu.harvard.iq.dataverse.DatasetField in project dataverse by IQSS.
the class SwordServiceBean method addDatasetContact.
/**
* Mutate the dataset version, adding a datasetContact (email address) from
* the dataverse that will own the dataset.
*/
public void addDatasetContact(DatasetVersion newDatasetVersion, User user) {
DatasetFieldType emailDatasetFieldType = datasetFieldService.findByNameOpt(DatasetFieldConstant.datasetContact);
DatasetField emailDatasetField = DatasetField.createNewEmptyDatasetField(emailDatasetFieldType, newDatasetVersion);
for (DatasetField childField : emailDatasetField.getDatasetFieldCompoundValues().get(0).getChildDatasetFields()) {
if (DatasetFieldConstant.datasetContactEmail.equals(childField.getDatasetFieldType().getName())) {
// set the value to the in user's email
childField.getSingleValue().setValue(user.getDisplayInfo().getEmailAddress());
}
// We don't see any error from EZID but when using DataCite, we were seeing this error: Response code: 400, [xml] xml error: cvc-minLength-valid: Value '' with length = '0' is not facet-valid with respect to minLength '1' for type '#AnonType_contributorNamecontributorcontributorsresource'.
if (DatasetFieldConstant.datasetContactName.equals(childField.getDatasetFieldType().getName())) {
childField.getSingleValue().setValue(user.getDisplayInfo().getTitle());
}
}
newDatasetVersion.getDatasetFields().add(emailDatasetField);
}
use of edu.harvard.iq.dataverse.DatasetField in project dataverse by IQSS.
the class SwordServiceBean method addDatasetSubjectIfMissing.
/**
* If no subject exists, mutate the dataset version, adding "N/A" for the
* subject. Otherwise, leave the dataset alone.
*/
public void addDatasetSubjectIfMissing(DatasetVersion datasetVersion) {
DatasetFieldType subjectDatasetFieldType = datasetFieldService.findByNameOpt(DatasetFieldConstant.subject);
boolean subjectFieldExists = false;
List<DatasetField> datasetFields = datasetVersion.getDatasetFields();
for (DatasetField datasetField : datasetFields) {
logger.fine("datasetField: " + datasetField.getDisplayValue() + " ... " + datasetField.getDatasetFieldType().getName());
if (datasetField.getDatasetFieldType().getName().equals(subjectDatasetFieldType.getName())) {
subjectFieldExists = true;
logger.fine("subject field exists already");
break;
}
}
if (subjectFieldExists) {
// return early. nothing to do. dataset already has a subject
logger.fine("returning early because subject exists already");
return;
}
// if we made it here, we must not have a subject, so let's add one
DatasetField subjectDatasetField = DatasetField.createNewEmptyDatasetField(subjectDatasetFieldType, datasetVersion);
/**
* @todo Once dataverse has subject
* (https://github.com/IQSS/dataverse/issues/769), we should get subject
* from there for now, we'll use the global NA value. However, there is
* currently oddness in that if you go to edit the title of a dataset
* via the GUI you can not save the dataset without selecting a Subject:
* https://github.com/IQSS/dataverse/issues/1296#issuecomment-70146314
*/
ControlledVocabularyValue cvv = datasetFieldService.findNAControlledVocabularyValue();
subjectDatasetField.setSingleControlledVocabularyValue(cvv);
datasetVersion.getDatasetFields().add(subjectDatasetField);
}
use of edu.harvard.iq.dataverse.DatasetField in project dataverse by IQSS.
the class JsonPrinterTest method testDatasetContactWithPrivacy.
@Test
public void testDatasetContactWithPrivacy() {
MetadataBlock block = new MetadataBlock();
block.setName("citation");
List<DatasetField> fields = new ArrayList<>();
DatasetField datasetContactField = new DatasetField();
DatasetFieldType datasetContactDatasetFieldType = datasetFieldTypeSvc.findByName("datasetContact");
datasetContactDatasetFieldType.setMetadataBlock(block);
datasetContactField.setDatasetFieldType(datasetContactDatasetFieldType);
List<DatasetFieldCompoundValue> vals = new LinkedList<>();
DatasetFieldCompoundValue val = new DatasetFieldCompoundValue();
val.setParentDatasetField(datasetContactField);
val.setChildDatasetFields(Arrays.asList(constructPrimitive("datasetContactEmail", "foo@bar.com"), constructPrimitive("datasetContactName", "Foo Bar"), constructPrimitive("datasetContactAffiliation", "Bar University")));
vals.add(val);
datasetContactField.setDatasetFieldCompoundValues(vals);
fields.add(datasetContactField);
JsonPrinter jsonPrinter = new JsonPrinter(new MockSettingsSvc());
JsonObject jsonObject = JsonPrinter.json(block, fields).build();
assertNotNull(jsonObject);
System.out.println("json: " + JsonUtil.prettyPrint(jsonObject.toString()));
assertEquals("Foo Bar", jsonObject.getJsonArray("fields").getJsonObject(0).getJsonArray("value").getJsonObject(0).getJsonObject("datasetContactName").getString("value"));
assertEquals("Bar University", jsonObject.getJsonArray("fields").getJsonObject(0).getJsonArray("value").getJsonObject(0).getJsonObject("datasetContactAffiliation").getString("value"));
assertEquals(null, jsonObject.getJsonArray("fields").getJsonObject(0).getJsonArray("value").getJsonObject(0).getJsonObject("datasetContactEmail"));
JsonObject byBlocks = jsonPrinter.jsonByBlocks(fields).build();
System.out.println("byBlocks: " + JsonUtil.prettyPrint(byBlocks.toString()));
assertEquals("Foo Bar", byBlocks.getJsonObject("citation").getJsonArray("fields").getJsonObject(0).getJsonArray("value").getJsonObject(0).getJsonObject("datasetContactName").getString("value"));
assertEquals("Bar University", byBlocks.getJsonObject("citation").getJsonArray("fields").getJsonObject(0).getJsonArray("value").getJsonObject(0).getJsonObject("datasetContactAffiliation").getString("value"));
assertEquals(null, byBlocks.getJsonObject("citation").getJsonArray("fields").getJsonObject(0).getJsonArray("value").getJsonObject(0).getJsonObject("datasetContactEmail"));
}
use of edu.harvard.iq.dataverse.DatasetField in project dataverse by IQSS.
the class JsonPrinterTest method constructPrimitive.
DatasetField constructPrimitive(String datasetFieldTypeName, String value) {
DatasetField retVal = new DatasetField();
retVal.setDatasetFieldType(datasetFieldTypeSvc.findByName(datasetFieldTypeName));
retVal.setDatasetFieldValues(Collections.singletonList(new DatasetFieldValue(retVal, value)));
return retVal;
}
use of edu.harvard.iq.dataverse.DatasetField in project dataverse by IQSS.
the class IndexServiceBean method getTopicClassificationTermOrTermAndVocabulary.
/**
* If the "Topic Classification" has a "Vocabulary", return both the "Term"
* and the "Vocabulary" with the latter in parentheses. For example, the
* Murray Research Archive uses "1 (Generations)" and "yes (Follow-up
* permitted)".
*/
private String getTopicClassificationTermOrTermAndVocabulary(DatasetField topicClassDatasetField) {
String finalValue = null;
String topicClassVocab = null;
String topicClassValue = null;
for (DatasetField sibling : topicClassDatasetField.getParentDatasetFieldCompoundValue().getChildDatasetFields()) {
DatasetFieldType datasetFieldType = sibling.getDatasetFieldType();
String name = datasetFieldType.getName();
if (name.equals(DatasetFieldConstant.topicClassVocab)) {
topicClassVocab = sibling.getDisplayValue();
} else if (name.equals(DatasetFieldConstant.topicClassValue)) {
topicClassValue = sibling.getDisplayValue();
}
if (topicClassValue != null) {
if (topicClassVocab != null) {
finalValue = topicClassValue + " (" + topicClassVocab + ")";
} else {
finalValue = topicClassValue;
}
}
}
return finalValue;
}
Aggregations