-
Notifications
You must be signed in to change notification settings - Fork 543
11391 display on create with template #11411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
138a62a
8353cda
88d72cf
67e5c5c
ce1f019
0c7db76
9b4516c
29c8cd9
a84d4d7
0b17352
6956a85
f3b68ca
b3c914c
2f13a7e
6353eb3
7ad65fb
fac6017
9bb2d69
af90095
6d5533f
86df1c3
c2ac931
80fded1
1df00af
533500f
e474e1c
4aad960
988a7bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -433,11 +433,13 @@ public void setValidationMessage(String validationMessage) { | |
| private Boolean required; | ||
| @Transient | ||
| private Boolean hasRequiredChildren; | ||
|
|
||
|
|
||
| @Transient | ||
| private Boolean hasRequiredChildrenDV; | ||
|
|
||
| public boolean isRequired() { | ||
| if (required == null) { | ||
| required = false; | ||
|
|
||
| required = false; | ||
| if (this.datasetFieldType.isRequired()) { | ||
| required = true; | ||
| } else { | ||
|
|
@@ -464,11 +466,51 @@ public boolean isRequired() { | |
| { | ||
| required = false; | ||
| } | ||
|
|
||
| //this is needed to enforce required children validation and display on create #11421 | ||
| //set the parent to required only if a child is set to required at the DV level | ||
| if (this.datasetFieldType.isCompound() && isHasRequiredChildrenDV()) { | ||
| required = true; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| return required; | ||
| } | ||
|
|
||
| public boolean isHasRequiredChildrenDV() { | ||
|
|
||
| if (hasRequiredChildrenDV == null) { | ||
| hasRequiredChildrenDV = false; | ||
| } | ||
|
|
||
| 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())) { | ||
| //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; | ||
|
qqmyers marked this conversation as resolved.
|
||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return hasRequiredChildrenDV; | ||
| } | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aside from lines 518/519, it looks like this method and the next one are the same? Is there a way to consolidate? E.g. is isHasRequiredChildren == isHasRequiredChildrenDV || this.datasetFieldType.isHasRequiredChildren() (not requiring two transients)?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem here is maintaining the conditionally required child dataset set field type. If the child is required at the installation level (in the db), but it's parent is not required in the db then it is conditionally required. There's no way to make a child dataset field type conditionally required at the dv level, because there's no way to set the parent as required. We are assuming that if a child field is made required at the dv level then the parent must also be required.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You understand the difference better than I do, but I was mostly talking about a mechanical refactor. I made a quick PR against this branch with a refactor to drop the separate variable and reduce duplicate code. It shouldn't change functionality at all. |
||
| public boolean isHasRequiredChildren() { | ||
| if (hasRequiredChildren == null) { | ||
| hasRequiredChildren = false; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -101,14 +101,30 @@ public void setDatasetFieldTypes(List<DatasetFieldType> datasetFieldTypes) { | |||||
| } | ||||||
|
|
||||||
| public boolean isDisplayOnCreate() { | ||||||
| // relying on "should" doesn't seem to work in context of a template | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should relies on a transient datsetfieldtype localdisplayoncreate that must not be getting getting set in the DatasetVersionUI init method. If it were, it think it should work. Is it just because of the order of these 2 lines: dataverse/src/main/java/edu/harvard/iq/dataverse/DatasetPage.java Lines 2135 to 2136 in 039b3b7
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did try switching the order here and commenting out the section in init-UI but it still doesn't display the metadata block that has only display on create set at the DV level.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it - I still wonder a bit about the order of those lines, but digging some more I realized why shouldDisplayOnCreate can't work in the MetadataBlock.isDisplayOnCreate call - the fieldTypes being checked there are straight from the db and not the ones from the workingVersion datasetfield.getDatasetFieldType list which has been localized to the local collection. Given that - it's clear why your solution is needed - the metadatablock localDisplayOnCreate has to be set by checking the localized field types from the working version, which is what the code in DatasetVersionUI does. |
||||||
| // adding a transient that is updated in the DatasetVersionUI to fix | ||||||
| for (DatasetFieldType dsfType : datasetFieldTypes) { | ||||||
| boolean shouldDisplayOnCreate = dsfType.shouldDisplayOnCreate(); | ||||||
| if (shouldDisplayOnCreate) { | ||||||
| return true; | ||||||
| } | ||||||
| } | ||||||
| if (getLocalDisplayOnCreate() != null){ | ||||||
| return getLocalDisplayOnCreate(); | ||||||
| } | ||||||
| return false; | ||||||
| } | ||||||
|
|
||||||
| @Transient | ||||||
| private Boolean localDisplayOnCreate; | ||||||
|
|
||||||
| public Boolean getLocalDisplayOnCreate() { | ||||||
| return localDisplayOnCreate; | ||||||
| } | ||||||
|
|
||||||
| public void setLocalDisplayOnCreate(Boolean localDisplayOnCreate) { | ||||||
| this.localDisplayOnCreate = localDisplayOnCreate; | ||||||
| } | ||||||
|
|
||||||
| public String getDisplayName() { | ||||||
| return displayName; | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.