Skip to content

Commit

Permalink
allow multiple required subfields (add parent once) IQSS#8236
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Nov 18, 2021
1 parent 4ba22f4 commit 247eb5a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/main/java/edu/harvard/iq/dataverse/DataversePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ public String save() {
// so we skip looking at parents (which get set automatically with their children)
if (!dsft.isHasChildren() && dsft.isRequiredDV()) {
boolean addRequiredInputLevels = false;
boolean parentAlreadyAdded = false;

if (!dsft.isHasParent() && dsft.isInclude()) {
addRequiredInputLevels = !dsft.isRequired();
Expand All @@ -622,9 +623,20 @@ public String save() {
if (addRequiredInputLevels) {
listDFTIL.add(new DataverseFieldTypeInputLevel(dsft, dataverse,true, true));

//also add the parent as required
//also add the parent as required (if it hasn't been added already)
if (dsft.isHasParent()) {
listDFTIL.add(new DataverseFieldTypeInputLevel(dsft.getParentDatasetFieldType(), dataverse,true, true));
DataverseFieldTypeInputLevel parentToAdd = new DataverseFieldTypeInputLevel(dsft.getParentDatasetFieldType(), dataverse, true, true);
for (DataverseFieldTypeInputLevel dataverseFieldTypeInputLevel : listDFTIL) {
if (dataverseFieldTypeInputLevel.getDatasetFieldType().getId() == parentToAdd.getDatasetFieldType().getId()) {
parentAlreadyAdded = true;
break;
}
}
if (!parentAlreadyAdded) {
// Only add the parent once. There's a UNIQUE (dataverse_id, datasetfieldtype_id)
// constraint on the dataversefieldtypeinputlevel table we need to avoid.
listDFTIL.add(parentToAdd);
}
}
}
}
Expand Down

0 comments on commit 247eb5a

Please sign in to comment.