Skip to content

Commit 08bfa30

Browse files
committed
Enhance CVOC value validation to ensure actual controlled vocabulary values are selected, preventing invalid N/A placeholders.
1 parent 09c55ce commit 08bfa30

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

src/main/java/edu/harvard/iq/dataverse/DatasetFieldValidator.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,25 @@ public boolean isValid(DatasetField value, ConstraintValidatorContext context) {
5959
}
6060

6161
// if value is not primitive or not empty
62-
if (!dsfType.isPrimitive() || !StringUtils.isBlank(value.getValue())) {
62+
// For controlled vocabulary fields, check that actual CV values are selected,
63+
// not just that datasetFieldValues contains something (which might be an invalid N/A placeholder)
64+
// See https://github.com/IQSS/dataverse/issues/11900
65+
if (!dsfType.isPrimitive()) {
6366
return true;
6467
}
68+
69+
if (dsfType.isControlledVocabulary()) {
70+
// For CV fields, check if there are actual controlled vocabulary values selected
71+
if (value.getControlledVocabularyValues() != null && !value.getControlledVocabularyValues().isEmpty()) {
72+
return true;
73+
}
74+
// If no CV values, fall through to required field check below
75+
} else {
76+
// For non-CV primitive fields, check if value is not blank
77+
if (!StringUtils.isBlank(value.getValue())) {
78+
return true;
79+
}
80+
}
6581

6682
if (value.isRequired()) {
6783
String errorMessage = null;

0 commit comments

Comments
 (0)