Search in sources :

Example 16 with DatasetField

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);
}
Also used : DatasetField(edu.harvard.iq.dataverse.DatasetField) DatasetFieldType(edu.harvard.iq.dataverse.DatasetFieldType)

Example 17 with DatasetField

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);
}
Also used : DatasetField(edu.harvard.iq.dataverse.DatasetField) DatasetFieldType(edu.harvard.iq.dataverse.DatasetFieldType) ControlledVocabularyValue(edu.harvard.iq.dataverse.ControlledVocabularyValue)

Example 18 with DatasetField

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"));
}
Also used : MetadataBlock(edu.harvard.iq.dataverse.MetadataBlock) DatasetField(edu.harvard.iq.dataverse.DatasetField) ArrayList(java.util.ArrayList) JsonObject(javax.json.JsonObject) DatasetFieldType(edu.harvard.iq.dataverse.DatasetFieldType) DatasetFieldCompoundValue(edu.harvard.iq.dataverse.DatasetFieldCompoundValue) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 19 with DatasetField

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;
}
Also used : DatasetField(edu.harvard.iq.dataverse.DatasetField) DatasetFieldValue(edu.harvard.iq.dataverse.DatasetFieldValue)

Example 20 with DatasetField

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;
}
Also used : DatasetField(edu.harvard.iq.dataverse.DatasetField) DatasetFieldType(edu.harvard.iq.dataverse.DatasetFieldType)

Aggregations

DatasetField (edu.harvard.iq.dataverse.DatasetField)32 DatasetFieldType (edu.harvard.iq.dataverse.DatasetFieldType)16 JsonObject (javax.json.JsonObject)13 DatasetFieldCompoundValue (edu.harvard.iq.dataverse.DatasetFieldCompoundValue)11 DatasetFieldValue (edu.harvard.iq.dataverse.DatasetFieldValue)11 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)8 ControlledVocabularyValue (edu.harvard.iq.dataverse.ControlledVocabularyValue)7 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)7 LinkedList (java.util.LinkedList)7 Dataset (edu.harvard.iq.dataverse.Dataset)6 DataFile (edu.harvard.iq.dataverse.DataFile)4 FileMetadata (edu.harvard.iq.dataverse.FileMetadata)4 ConstraintViolation (javax.validation.ConstraintViolation)4 Gson (com.google.gson.Gson)3 Dataverse (edu.harvard.iq.dataverse.Dataverse)3 MetadataBlock (edu.harvard.iq.dataverse.MetadataBlock)3 StringReader (java.io.StringReader)3 Timestamp (java.sql.Timestamp)3 Date (java.util.Date)3