use of edu.harvard.iq.dataverse.DatasetField in project dataverse by IQSS.
the class JsonParser method parseCompoundValue.
public List<DatasetFieldCompoundValue> parseCompoundValue(DatasetFieldType compoundType, JsonObject json) throws JsonParseException {
List<ControlledVocabularyException> vocabExceptions = new ArrayList<>();
List<DatasetFieldCompoundValue> vals = new LinkedList<>();
if (json.getBoolean("multiple")) {
int order = 0;
for (JsonObject obj : json.getJsonArray("value").getValuesAs(JsonObject.class)) {
DatasetFieldCompoundValue cv = new DatasetFieldCompoundValue();
List<DatasetField> fields = new LinkedList<>();
for (String fieldName : obj.keySet()) {
JsonObject childFieldJson = obj.getJsonObject(fieldName);
DatasetField f = null;
try {
f = parseField(childFieldJson);
} catch (ControlledVocabularyException ex) {
vocabExceptions.add(ex);
}
if (f != null) {
if (!compoundType.getChildDatasetFieldTypes().contains(f.getDatasetFieldType())) {
throw new JsonParseException("field " + f.getDatasetFieldType().getName() + " is not a child of " + compoundType.getName());
}
f.setParentDatasetFieldCompoundValue(cv);
fields.add(f);
}
}
if (!fields.isEmpty()) {
cv.setChildDatasetFields(fields);
cv.setDisplayOrder(order);
vals.add(cv);
}
order++;
}
} else {
DatasetFieldCompoundValue cv = new DatasetFieldCompoundValue();
List<DatasetField> fields = new LinkedList<>();
JsonObject value = json.getJsonObject("value");
for (String key : value.keySet()) {
JsonObject childFieldJson = value.getJsonObject(key);
DatasetField f = null;
try {
f = parseField(childFieldJson);
} catch (ControlledVocabularyException ex) {
vocabExceptions.add(ex);
}
if (f != null) {
f.setParentDatasetFieldCompoundValue(cv);
fields.add(f);
}
}
if (!fields.isEmpty()) {
cv.setChildDatasetFields(fields);
vals.add(cv);
}
}
if (!vocabExceptions.isEmpty()) {
throw new CompoundVocabularyException("Invalid controlled vocabulary in compound field ", vocabExceptions, vals);
}
return vals;
}
use of edu.harvard.iq.dataverse.DatasetField 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);
}
Aggregations