Search in sources :

Example 11 with DatasetFieldValue

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

the class JsonParser method parsePrimitiveValue.

public List<DatasetFieldValue> parsePrimitiveValue(JsonObject json) throws JsonParseException {
    List<DatasetFieldValue> vals = new LinkedList<>();
    if (json.getBoolean("multiple")) {
        for (JsonString val : json.getJsonArray("value").getValuesAs(JsonString.class)) {
            DatasetFieldValue datasetFieldValue = new DatasetFieldValue();
            datasetFieldValue.setDisplayOrder(vals.size() - 1);
            datasetFieldValue.setValue(val.getString().trim());
            vals.add(datasetFieldValue);
        }
    } else {
        DatasetFieldValue datasetFieldValue = new DatasetFieldValue();
        datasetFieldValue.setValue(json.getString("value", "").trim());
        vals.add(datasetFieldValue);
    }
    return vals;
}
Also used : DatasetFieldValue(edu.harvard.iq.dataverse.DatasetFieldValue) JsonString(javax.json.JsonString) LinkedList(java.util.LinkedList)

Example 12 with DatasetFieldValue

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

the class DatasetFieldWalker method walk.

public void walk(DatasetField fld, SettingsServiceBean settingsService) {
    l.startField(fld);
    DatasetFieldType datasetFieldType = fld.getDatasetFieldType();
    if (datasetFieldType.isControlledVocabulary()) {
        for (ControlledVocabularyValue cvv : sort(fld.getControlledVocabularyValues(), ControlledVocabularyValue.DisplayOrder)) {
            l.controledVocabularyValue(cvv);
        }
    } else if (datasetFieldType.isPrimitive()) {
        for (DatasetFieldValue pv : sort(fld.getDatasetFieldValues(), DatasetFieldValue.DisplayOrder)) {
            if (settingsService != null && settingsService.isTrueForKey(SettingsServiceBean.Key.ExcludeEmailFromExport, false) && DatasetFieldType.FieldType.EMAIL.equals(pv.getDatasetField().getDatasetFieldType().getFieldType())) {
                continue;
            }
            l.primitiveValue(pv);
        }
    } else if (datasetFieldType.isCompound()) {
        for (DatasetFieldCompoundValue dsfcv : sort(fld.getDatasetFieldCompoundValues(), DatasetFieldCompoundValue.DisplayOrder)) {
            l.startCompoundValue(dsfcv);
            for (DatasetField dsf : sort(dsfcv.getChildDatasetFields(), DatasetField.DisplayOrder)) {
                walk(dsf, settingsService);
            }
            l.endCompoundValue(dsfcv);
        }
    }
    l.endField(fld);
}
Also used : DatasetField(edu.harvard.iq.dataverse.DatasetField) DatasetFieldValue(edu.harvard.iq.dataverse.DatasetFieldValue) DatasetFieldType(edu.harvard.iq.dataverse.DatasetFieldType) DatasetFieldCompoundValue(edu.harvard.iq.dataverse.DatasetFieldCompoundValue) ControlledVocabularyValue(edu.harvard.iq.dataverse.ControlledVocabularyValue)

Aggregations

DatasetFieldValue (edu.harvard.iq.dataverse.DatasetFieldValue)12 DatasetField (edu.harvard.iq.dataverse.DatasetField)11 DatasetFieldCompoundValue (edu.harvard.iq.dataverse.DatasetFieldCompoundValue)5 ControlledVocabularyValue (edu.harvard.iq.dataverse.ControlledVocabularyValue)4 DatasetFieldType (edu.harvard.iq.dataverse.DatasetFieldType)4 JsonObject (javax.json.JsonObject)4 LinkedList (java.util.LinkedList)3 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 Dataset (edu.harvard.iq.dataverse.Dataset)2 DatasetDTO (edu.harvard.iq.dataverse.api.dto.DatasetDTO)2 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)2 CreateDatasetCommand (edu.harvard.iq.dataverse.engine.command.impl.CreateDatasetCommand)2 DestroyDatasetCommand (edu.harvard.iq.dataverse.engine.command.impl.DestroyDatasetCommand)2 JsonParseException (edu.harvard.iq.dataverse.util.json.JsonParseException)2 JsonParser (edu.harvard.iq.dataverse.util.json.JsonParser)2 StringReader (java.io.StringReader)2 List (java.util.List)2 JsonReader (javax.json.JsonReader)2 ConstraintViolation (javax.validation.ConstraintViolation)2