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

Refactor ModsExporter to use StaX from JAXB #9740

Merged
merged 15 commits into from
May 8, 2023

Conversation

yenniejunvu
Copy link
Contributor

Some starting changes to ModsExporter, refactoring from using JAXB to StAX. Not done yet, just wanted to commit some initial changes.

Fix for #9682

Compulsory checks

Preview Give feedback

@yenniejunvu yenniejunvu changed the title created XMLStreamWriter Refactor ModsExporter to use StaX from JAXB Apr 5, 2023
@yenniejunvu
Copy link
Contributor Author

Alternatively, I could get rid of modsCollection altogether and write directly to the export file in each respective 'add' method. I would call createStaxWriter first, before the loop.

@yenniejunvu
Copy link
Contributor Author

Some solid progress for refactoring, but need to figure out a different way to handle OriginInformation and RelatedInformation

@yenniejunvu
Copy link
Contributor Author

Working on fixing checkstyle and cleaning up the code

@yenniejunvu yenniejunvu marked this pull request as ready for review April 12, 2023 20:09
addIdentifier(writer, new UnknownField("citekey"), citeKey);
} catch (
XMLStreamException e) {
throw new RuntimeException(e); // cant throw SaveException?
Copy link
Member

Choose a reason for hiding this comment

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

This looks a bit odd to me. What is the purpose?
Why not use the isPresent? Or set it to an empty string? e.g. ifPresent.OrElse(...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you asking about the purpose of using try-catch here? Or the use of ifPresent(citekey ... ?

I used ifPresent because that is what the code had originally.

Copy link
Member

Choose a reason for hiding this comment

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

Both. First question: Why do you need the cry catch? I would assume if there is no citeKey we set it to empty string or something like this and the other line does a similar check down below. So it's kind of duplicated code

@Siedlerchr
Copy link
Member

Changelog entries should be understandable for the normal average user, they can't do anything with the technical detils

@koppor
Copy link
Member

koppor commented Apr 22, 2023

Changelog entries should be understandable for the normal average user, they can't do anything with the technical detils

We don't need a changelog entry here as there is no functionality changed, is it?

@koppor
Copy link
Member

koppor commented Apr 22, 2023

Working on fixing checkstyle and cleaning up the code

Regarding checkstyle: You can click on https://github.com/JabRef/jabref/pull/9740/files to directly see the checkstyle comments. Moreover, IntelliJ has a build-in checkstyle plugin. The setup is explained at https://devdocs.jabref.org/getting-into-the-code/guidelines-for-setting-up-a-local-workspace. Search for "checkstyle".

If everything works, checkstyle checking can be started with one click:

@koppor koppor added the status: changes required Pull requests that are not yet complete label Apr 24, 2023
Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

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

Some small comments.

Are there tests for the modsexporter? I saw some TODOs in the code - is the expected output covered by test cases?

import org.jabref.logic.importer.fileformat.mods.TitleInfoDefinition;
import org.jabref.logic.importer.fileformat.mods.TypeOfResourceDefinition;
import org.jabref.logic.importer.fileformat.mods.UrlDefinition;
// relevant StAX imports
Copy link
Member

Choose a reason for hiding this comment

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

No need to comment on this, just remove that.

CHANGELOG.md Outdated Show resolved Hide resolved
@@ -76,267 +49,343 @@ public void export(final BibDatabaseContext databaseContext, final Path file, Li
}

try {
ModsCollectionDefinition modsCollection = new ModsCollectionDefinition();
// create writer
IndentingXMLStreamWriter writer = createWriter(file);
Copy link
Member

Choose a reason for hiding this comment

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

I think, the writer should be in the "try" statement - to have it auto closable:

try (IndentingXMLStreamWriter writer = createWriter(file))

Copy link
Member

Choose a reason for hiding this comment

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

Does not work! StreamWriter does not support auto closable.

Comment on lines 148 to 149
writer.flush();
writer.close();
Copy link
Member

Choose a reason for hiding this comment

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

Obsolete at try-with-resources.

Copy link
Member

Choose a reason for hiding this comment

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

As mentionend earlier, java's XMLWriter do not implement auto closable

Copy link
Member

Choose a reason for hiding this comment

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

Now there is a JavaComment on that. Thank you!

src/main/java/org/jabref/logic/exporter/ModsExporter.java Outdated Show resolved Hide resolved
src/main/java/org/jabref/logic/exporter/ModsExporter.java Outdated Show resolved Hide resolved
src/main/java/org/jabref/logic/exporter/ModsExporter.java Outdated Show resolved Hide resolved
src/main/java/org/jabref/logic/exporter/ModsExporter.java Outdated Show resolved Hide resolved
@Siedlerchr
Copy link
Member

What is the status here? It would be great if you continue working on this.

Siedlerchr added 4 commits May 7, 2023 19:31
* upstream/main: (110 commits)
  remove extra hack rather add a todo
  Enable CompareEnumsWithEqualityOperator
  cleanup
  checkstyle
  checkstyle
  Prefer u over y, remove some patterns that have not a  test yet make parameterized test
  Enable ChainStringBuilderAppendCalls
  Add four rules not having any effect
  Apply BooleanChecksNotInverted
  Remove unused RadioButtonCell
  move exception handling upwards
  Minimal config for openRewrite
  Fix missing #
  Update CHANGELOG.md
  exchange locations between library mode and library encoding added to Changelog
  exchange locations between library mode and library encoding in general tab
  Fix modernizer (JabRef#9824)
  CHANGELOG.md
  Removed unused code
  Refined ui
  ...

# Conflicts:
#	src/main/java/org/jabref/logic/exporter/ModsExporter.java
@Siedlerchr Siedlerchr added status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers and removed status: changes required Pull requests that are not yet complete labels May 8, 2023
@koppor koppor merged commit 68b72e0 into JabRef:main May 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants