Search in sources :

Example 1 with ControlledVocabAlternate

use of edu.harvard.iq.dataverse.ControlledVocabAlternate in project dataverse by IQSS.

the class DatasetFieldServiceApi method parseControlledVocabulary.

private String parseControlledVocabulary(String[] values) {
    DatasetFieldType dsv = datasetFieldService.findByName(values[1]);
    // See if it already exists
    /*
         Matching relies on assumption that only one cv value will exist for a given identifier or display value
        If the lookup queries return multiple matches then retval is null 
        */
    // First see if cvv exists based on display name
    ControlledVocabularyValue cvv = datasetFieldService.findControlledVocabularyValueByDatasetFieldTypeAndStrValue(dsv, values[2], true);
    // then see if there's a match on identifier
    ControlledVocabularyValue cvvi = null;
    if (values[3] != null && !values[3].trim().isEmpty()) {
        cvvi = datasetFieldService.findControlledVocabularyValueByDatasetFieldTypeAndIdentifier(dsv, values[3]);
    }
    // if there's a match on identifier use it
    if (cvvi != null) {
        cvv = cvvi;
    }
    // if there's no match create a new one
    if (cvv == null) {
        cvv = new ControlledVocabularyValue();
        cvv.setDatasetFieldType(dsv);
        // Alt is only for dataload so only add to new
        for (int i = 5; i < values.length; i++) {
            ControlledVocabAlternate alt = new ControlledVocabAlternate();
            alt.setDatasetFieldType(dsv);
            alt.setControlledVocabularyValue(cvv);
            alt.setStrValue(values[i]);
            cvv.getControlledVocabAlternates().add(alt);
        }
    }
    cvv.setStrValue(values[2]);
    cvv.setIdentifier(values[3]);
    cvv.setDisplayOrder(Integer.parseInt(values[4]));
    datasetFieldService.save(cvv);
    return cvv.getStrValue();
}
Also used : ControlledVocabAlternate(edu.harvard.iq.dataverse.ControlledVocabAlternate) DatasetFieldType(edu.harvard.iq.dataverse.DatasetFieldType) ControlledVocabularyValue(edu.harvard.iq.dataverse.ControlledVocabularyValue)

Aggregations

ControlledVocabAlternate (edu.harvard.iq.dataverse.ControlledVocabAlternate)1 ControlledVocabularyValue (edu.harvard.iq.dataverse.ControlledVocabularyValue)1 DatasetFieldType (edu.harvard.iq.dataverse.DatasetFieldType)1