Skip to content
Merged
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
67 changes: 20 additions & 47 deletions src/main/java/edu/harvard/iq/dataverse/DatasetField.java
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,6 @@ public void setValidationMessage(String validationMessage) {
private Boolean required;
@Transient
private Boolean hasRequiredChildren;

@Transient
private Boolean hasRequiredChildrenDV;

public boolean isRequired() {
if (required == null) {
Expand Down Expand Up @@ -478,70 +475,46 @@ public boolean isRequired() {
return required;
}

public boolean isHasRequiredChildrenDV() {

if (hasRequiredChildrenDV == null) {
hasRequiredChildrenDV = false;
public boolean isHasRequiredChildren() {
if (hasRequiredChildren == null) {
hasRequiredChildren = this.datasetFieldType.isHasRequiredChildren() || checkRequiredChildren(false);
}
return hasRequiredChildren;
}

public boolean isHasRequiredChildrenDV() {
return isHasRequiredChildren() && checkRequiredChildren(true);
}

private boolean checkRequiredChildren(boolean checkDVOnly) {
Dataverse dv = getDataverse();
while (!dv.isMetadataBlockRoot()) {
if (dv.getOwner() == null) {
break; // we are at the root; which by defintion is metadata blcok root, regarldess of the value
break; // we are at the root; which by defintion is metadata block root, regardless of the value
}
dv = dv.getOwner();
}

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

if (getDatasetFieldType().isHasChildren() && (!dftilListFirst.isEmpty())) {
for (DatasetFieldType child : getDatasetFieldType().getChildDatasetFieldTypes()) {
for (DataverseFieldTypeInputLevel dftilTest : dftilListFirst) {
if (child.equals(dftilTest.getDatasetFieldType())) {
//We only want to get it here if it is required by
//the DV and not by default at the installation/DB level
if (dftilTest.isRequired() && !child.isRequired()) {
hasRequiredChildrenDV = true;
break;
}
}
}
}
}
return hasRequiredChildrenDV;
}

public boolean isHasRequiredChildren() {
if (hasRequiredChildren == null) {
hasRequiredChildren = false;
}

if (this.datasetFieldType.isHasRequiredChildren()) {
hasRequiredChildren = true;
}

Dataverse dv = getDataverse();
while (!dv.isMetadataBlockRoot()) {
if (dv.getOwner() == null) {
break; // we are at the root; which by defintion is metadata blcok root, regarldess of the value
}
dv = dv.getOwner();
}

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

if (getDatasetFieldType().isHasChildren() && (!dftilListFirst.isEmpty())) {
for (DatasetFieldType child : getDatasetFieldType().getChildDatasetFieldTypes()) {
for (DataverseFieldTypeInputLevel dftilTest : dftilListFirst) {
if (child.equals(dftilTest.getDatasetFieldType())) {
if (dftilTest.isRequired()) {
hasRequiredChildren = true;
if (checkDVOnly) {
if (!child.isRequired()) {
return true;
}
} else {
return true;
}
}
}
}
}
}
return hasRequiredChildren;
}
return false;
}

public Dataverse getDataverse() {
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/edu/harvard/iq/dataverse/DatasetVersionUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,11 @@ public void setMetadataValueBlocks(DatasetVersion datasetVersion) {
mdb.setEmpty(false);
datasetFieldsForView.add(dsf);
}
//Setting Local Display on Create on mdb when there are any set at dataverse level
if (dsf.getDatasetFieldType().getLocalDisplayOnCreate() != null && dsf.getDatasetFieldType().getLocalDisplayOnCreate()){
mdb.setLocalDisplayOnCreate(true);
}
// Setting Local Display on Create on mdb when there are any set at dataverse
// level
if (dsf.getDatasetFieldType().shouldDisplayOnCreate()) {
mdb.setLocalDisplayOnCreate(true);
}
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/main/java/edu/harvard/iq/dataverse/MetadataBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,17 @@ public void setDatasetFieldTypes(List<DatasetFieldType> datasetFieldTypes) {
}

public boolean isDisplayOnCreate() {
// relying on "should" doesn't seem to work in context of a template
// adding a transient that is updated in the DatasetVersionUI to fix
//Localize case - e.g. being called in the context of a specific collection
if (getLocalDisplayOnCreate() != null){
return getLocalDisplayOnCreate();
}
// Non-localized case - the datasetFieldTypes are straight from the database and
// never have dsfType.localDsiplayOnCreate set.
for (DatasetFieldType dsfType : datasetFieldTypes) {
boolean shouldDisplayOnCreate = dsfType.shouldDisplayOnCreate();
if (shouldDisplayOnCreate) {
if (dsfType.isDisplayOnCreate()) {
return true;
}
}
if (getLocalDisplayOnCreate() != null){
return getLocalDisplayOnCreate();
}
return false;
}

Expand Down