Skip to content
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

displayInfo and displayAttribute tags for datasets.xml #240

Merged
merged 8 commits into from
Jan 24, 2025

Conversation

ayushsingh01042003
Copy link
Contributor

Issue #134

  • Tags <displayInfo> and <displayAttribute> are now available as global level tags in datasets.xml
  • They should contain the same number of elements seperated by a ,
  • displayAttribute is the attribute name from the top level addAttributes tag of a dataset whose value is displayed in the tooltip
  • displayInfo should contain what the word should be beside the tooltip
  • If tags are not added in datasets.xml the default values are "summary" and "license" which work the same

@ayushsingh01042003
Copy link
Contributor Author

TODO:

  • I had some difficulty in understanding the edd.ensureValid() hence it is just an if statement for now that checks if lengths of the array is the same. It means no error is given if tags have different lengths and summary and license are handled as usual.

  • Code structuring may be a little random for this PR but it seems to be working correctly:

Screenshot from 2025-01-14 13-53-44

Copy link
Contributor

@ChrisJohnNOAA ChrisJohnNOAA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good start. I have a couple of comments overall:

It'd be good to add tests. In particular a test that the parameters are parsed correctly and a test that they are used correctly. TopLevelHandlerTests.java would likely be a good spot for the parsing test (do note the comment about making sure EDStatic is not modified for other tests, so for now that means setting these values back to default when the test is complete). As for testing the usage, most likely that will be best done in JettyTests.java. You'll probably need to modify EDDTestDataset.generateDatasetsXml to include the new top level parameters and then in a new test in the JettyTests.java file, use SSR.getUrlResponseStringUnchanged to load a page for a dataset (that has the proper attributes) and make sure the new attributes are properly rendered.

This is currently only for the SAX parser and currently requires setting useSaxParser to true as well. That's fine but that should definitely be documented somewhere along with how to use it. Would you be able to include a short markdown file explaining the feature and that it's SAX parser only?

A couple of comments in the code as well.

String attribute = EDStatic.displayAttributeAr[i];

// Skip "summary" and "license" as they are already handled
if ("summary".equals(attribute) || "license".equals(attribute)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary and license should be included in this general version. That does mean removing their code above.

It'd be ideal to have their display attribute localized (using the EDStatic.EDDSummmaryAr[language] for summary and similar for license).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant that summary and license should be included in this loop.

@@ -3820,6 +3821,39 @@ public void writeHtmlDatasetInfo(
+ "</table>\n");
}

private String getDisplayInfo(int language, String loggedInAs) {
if (EDStatic.displayAttributeAr.length != EDStatic.displayInfoAr.length) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good spot to do the validation would be in LoadDatasets.java just after the parsing is complete:
https://github.com/ERDDAP/erddap/blob/main/WEB-INF/classes/gov/noaa/pfel/erddap/LoadDatasets.java#L229

If the validation fails, it should log the issue and then set the EDStatic.displayAttributeAr and EDStatic.displayInfoAr to the defaults.

It's probably worth keeping a check here to make sure they match just before using them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a log here as well.

@ayushsingh01042003
Copy link
Contributor Author

I made some progress but for the jetty tests when I run the command mvn -Dtest=JettyTests test the output is always
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
Is there some other way to run the Jetty Tests?

@ChrisJohnNOAA
Copy link
Contributor

I made some progress but for the jetty tests when I run the command mvn -Dtest=JettyTests test the output is always Tests run: 0, Failures: 0, Errors: 0, Skipped: 0 Is there some other way to run the Jetty Tests?

The JettyTests are part of the integration tests, You can run them with mvn verify, though that will run all of the integration tests. You should be able to run:

mvn -D it.test=JettyTests verify

or

mvn -Dtest=JettyTests verify

to run just the JettyTests I've seen both in documentation, haven't verified which one works myself.
You can most likely run an individual JettyTest (in any command that's working with JettyTests#specificTestName.

@ayushsingh01042003
Copy link
Contributor Author

ayushsingh01042003 commented Jan 19, 2025

  • So I tried using the above commands with '#testName' to run an individual integration test but the problem is it runs all the unit tests as well but when I run it with -DskipTests flag it skips both unit and integration tests and runs nothing.
    Could you confirm the command for running a singular integration test?

  • Also about it being sax parser only I was thinking to add it for SimpleXmlParser as well, it should be similar code used for sax parser and when you mentioned a markdown file that explains the tag it refered to a .md syntax file right?

  • And let me know if the current code I pushed seems correct or you think needs some changes(will add the comments towards the end when done with implementing all the features)

@@ -229,6 +229,13 @@ public void run() {
int nTry = nTryAndDatasets[0];
int nDatasets = nTryAndDatasets[1];

// validation for displayInfo and displayAttribute Tags
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put the validation in a function (validateDatasetsXmlResults or something). I know it's only one check right now, but making it a function would help make a place for future validation to be placed.

Copy link
Contributor

@ChrisJohnNOAA ChrisJohnNOAA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't run an individual integration test, so if those commands from the documentation are not working I'd need to look into it.

Adding to SimpleXmlParser logic would be good, though not needed, I'm happy with this being a feature to try to encourage people to update to the SAX parrser.

Yes, a file with.md syntax. I'm in the process of migrating all of the documentation to markdown format so that we can use Docusaurus for our documentation site.

Code code is on the right track, I've added some comments.

String attribute = EDStatic.displayAttributeAr[i];

// Skip "summary" and "license" as they are already handled
if ("summary".equals(attribute) || "license".equals(attribute)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant that summary and license should be included in this loop.

@ayushsingh01042003
Copy link
Contributor Author

ayushsingh01042003 commented Jan 19, 2025

I am not sure how I can add summary and license to the loop. Lets say an if condition for summary and another for license but since these two fields always need to be added, if the user enters
< displayAttribute >att1,license,att3< /displayAttribute >
We will end up not appending summary at all in the UI since if(attribute == "summary") block never runs

Was there some other way you were referring to implement this?

@ChrisJohnNOAA
Copy link
Contributor

I am not sure how I can add summary and license to the loop. Lets say an if condition for summary and another for license but since these two fields always need to be added, if the user enters < displayAttribute >att1,license,att3< /displayAttribute > We will end up not appending summary at all in the UI since if(attribute == "summary") block never runs

Was there some other way you were referring to implement this?

Yes, that is what I meant. The reasoning is to simplify the code (summary and license behave almost identically to these other attributes), make the behavior more predictable (having all of the items that appear the same way in the UI behave the same way in configuration), and allow for more admin control (admins can choose to change the order - maybe they want it to be citation,license,summary - or skip having a summary if they would like to).

@ayushsingh01042003
Copy link
Contributor Author

ayushsingh01042003 commented Jan 23, 2025

displayInfo and displayAttribute Tags

Description

This feature allows you to display global attributes of your choice on the datasets page in the Information row.

Usage Instructions

These tags can only be used with the Sax parser. To enable and use them, follow these steps:

  1. Enable the SAX Parser:
    Add the following line to your setup.xml file:

    <useSaxParser>true</useSaxParser>
  2. Add Tags in datasets.xml:
    In the datasets.xml file, include two top-level tags:

    <displayInfo></displayInfo>
    <displayAttribute></displayAttribute>
  3. Default Behavior:

    • If these tags are not added or left empty in the datasets.xml file, the default values are applied as follows:
      • displayInfo: Summary,License
      • displayAttribute: summary,license
  4. Ensure Consistency:
    The number of comma-separated values in both displayInfo and displayAttribute tags must be the same.

How It Works

  • The displayAttribute tag specifies global attributes (defined within the <addAttributes> tag) to be displayed for each dataset.
  • The corresponding values in the displayInfo tag are displayed as labels in the Information row of the UI.
  • When the user hovers over the displayed labels, a tooltip will appear, showing the value of the global attribute.

Example

<displayInfo>Display1,Display2</displayInfo>
<displayAttribute>att1,att2</displayAttribute>

Dataset Global Attributes Example:

<att name="att1">This is att1</att>
<att name="att2">This is att2</att>

UI Behavior:

  • The words Display1 and Display2 will be displayed in the Information row on the UI.
  • When hovered, tooltips will display the corresponding attribute values:
    • Display1: Tooltip shows This is att1
    • Display2: Tooltip shows This is att2

Notes

  • Ensure the attribute names specified in the displayAttribute tag match the global attributes defined in the dataset.
  • Incorrect or missing attributes will log error messages.

By following these steps, you can customize the Information row on the datasets page to display relevant global attributes with corresponding tooltips.

display.md

@ayushsingh01042003
Copy link
Contributor Author

  • Hope the above comment works for the markdown file
  • Let me know about any comments and changes to the markdown file or the code contributions

@ChrisJohnNOAA
Copy link
Contributor

  • Hope the above comment works for the markdown file
  • Let me know about any comments and changes to the markdown file or the code contributions

The documentation is great, Thanks for writing that!

I've sent a pull request that simplifies the code a little bit and fixes one of the JettyTests. Let me know if you have questions on those changes.

SImplify code in getDisplayInfo and add the new attributes to the Jet…
@ChrisJohnNOAA ChrisJohnNOAA merged commit c4dd45c into ERDDAP:main Jan 24, 2025
1 check passed
@ayushsingh01042003 ayushsingh01042003 deleted the displayInfo branch January 25, 2025 04:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants