-
Notifications
You must be signed in to change notification settings - Fork 492
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
Correction of JsonPrinter output for metadatablock api calls #10764
base: develop
Are you sure you want to change the base?
Changes from 6 commits
f5d1299
a218417
8c99a74
d197373
db1c59c
9c480a3
65eee38
7884bdb
7605345
886c8ad
01b6762
3fd62f6
cd3f0ef
b2e271a
957adab
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
This pull request fixes an issue in the JsonPrinter class so that there are no duplicated entries in the JSON metadata or ommitted metadata properties. After the fix is applied the /api/metadatablocks/ endpoint should return correct JSON. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,7 +55,7 @@ | |
import jakarta.ejb.Singleton; | ||
import jakarta.json.JsonArray; | ||
import jakarta.json.JsonObject; | ||
import java.math.BigDecimal; | ||
import java.util.function.Predicate; | ||
|
||
/** | ||
* Convert objects to Json. | ||
|
@@ -639,9 +639,13 @@ public static JsonObjectBuilder json(MetadataBlock metadataBlock, boolean printO | |
jsonObjectBuilder.add("displayOnCreate", metadataBlock.isDisplayOnCreate()); | ||
|
||
JsonObjectBuilder fieldsBuilder = Json.createObjectBuilder(); | ||
Set<DatasetFieldType> datasetFieldTypes = new TreeSet<>(metadataBlock.getDatasetFieldTypes()); | ||
|
||
for (DatasetFieldType datasetFieldType : datasetFieldTypes) { | ||
|
||
Predicate<DatasetFieldType> isNoChild = element -> element.isChild() == false; | ||
List<DatasetFieldType> childLessList = metadataBlock.getDatasetFieldTypes().stream().filter(isNoChild).toList(); | ||
Set<DatasetFieldType> datasetFieldTypesNoChildSorted = new TreeSet<>(childLessList); | ||
|
||
for (DatasetFieldType datasetFieldType : datasetFieldTypesNoChildSorted) { | ||
|
||
Long datasetFieldTypeId = datasetFieldType.getId(); | ||
boolean requiredAsInputLevelInOwnerDataverse = ownerDataverse != null && ownerDataverse.isDatasetFieldTypeRequiredAsInputLevel(datasetFieldTypeId); | ||
boolean includedAsInputLevelInOwnerDataverse = ownerDataverse != null && ownerDataverse.isDatasetFieldTypeIncludedAsInputLevel(datasetFieldTypeId); | ||
|
@@ -658,7 +662,7 @@ public static JsonObjectBuilder json(MetadataBlock metadataBlock, boolean printO | |
fieldsBuilder.add(datasetFieldType.getName(), json(datasetFieldType, ownerDataverse)); | ||
} | ||
} | ||
|
||
jsonObjectBuilder.add("fields", fieldsBuilder); | ||
return jsonObjectBuilder; | ||
} | ||
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'm just going to put this comment here at the bottom but @ffritze can you please get the following test passing? edu.harvard.iq.dataverse.api.DataversesIT.testListMetadataBlocks is failing with this:
I also mentioned this here: https://dataverse.zulipchat.com/#narrow/stream/378866-troubleshooting/topic/metadatablocks.20api/near/460096243 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. When I start mvn clean package from my pull request branch which has dataverse 6.3 as basis there are no failing tests: That's why I am not quite sure if the failing test has something to do with my pull request. Should I switch to develop and try to fix the test anyway? 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. Those tests executed at build time are unit tests. @pdurbin is referring to the integration tests, and in particular the test To run integration tests, you need to have the environment running locally. You can do this by using the containerized dev environment. Steps:
I recommend that you update this branch with develop, as the metadata blocks endpoint was recently modified, and I'm not sure if you have the latest changes. The test may fail because of the changes you have made. There are assertions in the test that check the number of fields returned, and your changes likely reduced this number by removing duplicate child fields that were previously listed (repeated) as parents. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm suggesting that we remove the reference to JsonPrinter because API users don't need to worry about the underlying implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ffritze
The requested change was not made. Also this now has to be added under V6.5 in the changeling.rst