Skip to content

Commit 54af71e

Browse files
authored
Merge pull request #11539 from GlobalDataverseCommunityConsortium/11391-displayOnCreate-with-template
Addition to IQSS/11391 display on create with template
2 parents 7a3964b + 2b56397 commit 54af71e

File tree

3 files changed

+32
-58
lines changed

3 files changed

+32
-58
lines changed

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

Lines changed: 20 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,6 @@ public void setValidationMessage(String validationMessage) {
433433
private Boolean required;
434434
@Transient
435435
private Boolean hasRequiredChildren;
436-
437-
@Transient
438-
private Boolean hasRequiredChildrenDV;
439436

440437
public boolean isRequired() {
441438
if (required == null) {
@@ -478,70 +475,46 @@ public boolean isRequired() {
478475
return required;
479476
}
480477

481-
public boolean isHasRequiredChildrenDV() {
482-
483-
if (hasRequiredChildrenDV == null) {
484-
hasRequiredChildrenDV = false;
478+
public boolean isHasRequiredChildren() {
479+
if (hasRequiredChildren == null) {
480+
hasRequiredChildren = this.datasetFieldType.isHasRequiredChildren() || checkRequiredChildren(false);
485481
}
482+
return hasRequiredChildren;
483+
}
486484

485+
public boolean isHasRequiredChildrenDV() {
486+
return isHasRequiredChildren() && checkRequiredChildren(true);
487+
}
488+
489+
private boolean checkRequiredChildren(boolean checkDVOnly) {
487490
Dataverse dv = getDataverse();
488491
while (!dv.isMetadataBlockRoot()) {
489492
if (dv.getOwner() == null) {
490-
break; // we are at the root; which by defintion is metadata blcok root, regarldess of the value
493+
break; // we are at the root; which by defintion is metadata block root, regardless of the value
491494
}
492495
dv = dv.getOwner();
493496
}
494497

495498
List<DataverseFieldTypeInputLevel> dftilListFirst = dv.getDataverseFieldTypeInputLevels();
496499

497-
if (getDatasetFieldType().isHasChildren() && (!dftilListFirst.isEmpty())) {
498-
for (DatasetFieldType child : getDatasetFieldType().getChildDatasetFieldTypes()) {
499-
for (DataverseFieldTypeInputLevel dftilTest : dftilListFirst) {
500-
if (child.equals(dftilTest.getDatasetFieldType())) {
501-
//We only want to get it here if it is required by
502-
//the DV and not by default at the installation/DB level
503-
if (dftilTest.isRequired() && !child.isRequired()) {
504-
hasRequiredChildrenDV = true;
505-
break;
506-
}
507-
}
508-
}
509-
}
510-
}
511-
return hasRequiredChildrenDV;
512-
}
513-
514-
public boolean isHasRequiredChildren() {
515-
if (hasRequiredChildren == null) {
516-
hasRequiredChildren = false;
517-
}
518-
519-
if (this.datasetFieldType.isHasRequiredChildren()) {
520-
hasRequiredChildren = true;
521-
}
522-
523-
Dataverse dv = getDataverse();
524-
while (!dv.isMetadataBlockRoot()) {
525-
if (dv.getOwner() == null) {
526-
break; // we are at the root; which by defintion is metadata blcok root, regarldess of the value
527-
}
528-
dv = dv.getOwner();
529-
}
530-
531-
List<DataverseFieldTypeInputLevel> dftilListFirst = dv.getDataverseFieldTypeInputLevels();
532-
533500
if (getDatasetFieldType().isHasChildren() && (!dftilListFirst.isEmpty())) {
534501
for (DatasetFieldType child : getDatasetFieldType().getChildDatasetFieldTypes()) {
535502
for (DataverseFieldTypeInputLevel dftilTest : dftilListFirst) {
536503
if (child.equals(dftilTest.getDatasetFieldType())) {
537504
if (dftilTest.isRequired()) {
538-
hasRequiredChildren = true;
505+
if (checkDVOnly) {
506+
if (!child.isRequired()) {
507+
return true;
508+
}
509+
} else {
510+
return true;
511+
}
539512
}
540513
}
541514
}
542515
}
543-
}
544-
return hasRequiredChildren;
516+
}
517+
return false;
545518
}
546519

547520
public Dataverse getDataverse() {

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,11 @@ public void setMetadataValueBlocks(DatasetVersion datasetVersion) {
458458
mdb.setEmpty(false);
459459
datasetFieldsForView.add(dsf);
460460
}
461-
//Setting Local Display on Create on mdb when there are any set at dataverse level
462-
if (dsf.getDatasetFieldType().getLocalDisplayOnCreate() != null && dsf.getDatasetFieldType().getLocalDisplayOnCreate()){
463-
mdb.setLocalDisplayOnCreate(true);
464-
}
461+
// Setting Local Display on Create on mdb when there are any set at dataverse
462+
// level
463+
if (dsf.getDatasetFieldType().shouldDisplayOnCreate()) {
464+
mdb.setLocalDisplayOnCreate(true);
465+
}
465466
}
466467
}
467468

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,17 @@ public void setDatasetFieldTypes(List<DatasetFieldType> datasetFieldTypes) {
101101
}
102102

103103
public boolean isDisplayOnCreate() {
104-
// relying on "should" doesn't seem to work in context of a template
105-
// adding a transient that is updated in the DatasetVersionUI to fix
104+
//Localize case - e.g. being called in the context of a specific collection
105+
if (getLocalDisplayOnCreate() != null){
106+
return getLocalDisplayOnCreate();
107+
}
108+
// Non-localized case - the datasetFieldTypes are straight from the database and
109+
// never have dsfType.localDsiplayOnCreate set.
106110
for (DatasetFieldType dsfType : datasetFieldTypes) {
107-
boolean shouldDisplayOnCreate = dsfType.shouldDisplayOnCreate();
108-
if (shouldDisplayOnCreate) {
111+
if (dsfType.isDisplayOnCreate()) {
109112
return true;
110113
}
111114
}
112-
if (getLocalDisplayOnCreate() != null){
113-
return getLocalDisplayOnCreate();
114-
}
115115
return false;
116116
}
117117

0 commit comments

Comments
 (0)