Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,25 @@ public boolean isValid(DatasetField value, ConstraintValidatorContext context) {
}

// if value is not primitive or not empty
if (!dsfType.isPrimitive() || !StringUtils.isBlank(value.getValue())) {
// For controlled vocabulary fields, check that actual CV values are selected,
// not just that datasetFieldValues contains something (which might be an invalid N/A placeholder)
// See https://github.com/IQSS/dataverse/issues/11900
if (!dsfType.isPrimitive()) {
return true;
}

if (dsfType.isControlledVocabulary()) {
// For CV fields, check if there are actual controlled vocabulary values selected
if (value.getControlledVocabularyValues() != null && !value.getControlledVocabularyValues().isEmpty()) {
return true;
}
// If no CV values, fall through to required field check below
} else {
// For non-CV primitive fields, check if value is not blank
if (!StringUtils.isBlank(value.getValue())) {
return true;
}
}

if (value.isRequired()) {
String errorMessage = null;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -4005,8 +4005,8 @@ public String save() {
dataset.setOwner(ownerId != null ? dataverseService.find(ownerId) : null);
}
// Validate
Set<ConstraintViolation> constraintViolations = workingVersion.validate();
if (!constraintViolations.isEmpty()) {
workingVersion.validate(); // add validation messages to dataset fields
if (!workingVersion.isValid()) {
FacesContext.getCurrentInstance().validationFailed();
return "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,14 @@ protected void validateOrDie(DatasetVersion dsv, Boolean lenient) throws Command
Set<ConstraintViolation> constraintViolations = dsv.validate();
if (!constraintViolations.isEmpty()) {
if (lenient) {
// populate invalid fields with N/A
// populate invalid primitive fields with N/A
// Note: controlled vocabulary fields should NOT get N/A values in datasetfieldvalue,
// as this creates an inconsistent state where the CV field appears valid but is empty.
// See https://github.com/IQSS/dataverse/issues/11900
constraintViolations.stream()
.filter(cv -> cv.getRootBean() instanceof DatasetField)
.map(cv -> ((DatasetField) cv.getRootBean()))
.filter(f -> !f.getDatasetFieldType().isControlledVocabulary())
.forEach(f -> f.setSingleValue(DatasetField.NA_VALUE));

} else {
Expand Down