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/service provider #14

Merged
merged 33 commits into from
May 12, 2022
Merged

Conversation

poikilotherm
Copy link
Member

@poikilotherm poikilotherm commented May 9, 2022

Compiles, but has failing tests.

Relates to #1

Leftover TODOs for this module:

  • Fix failing tests...
  • Let service-provider parsers use an XmlReader that is closed by the handler (give reader, not stream) or create reader just when parsing and use try-with-resources Moved to Refactor service-provider parsers handling streams #17
  • Add tests for new JdkHttpOaiClient implementation (target?) Moved to Add tests for JdkHttpOaiClient #18
  • Move all tests from JUnit 4 to 5
  • Remove unused dependency for Mockito
  • Look at findings from SonarCloud for this module, fix urgents

Larger TODOs for this module and beyond:

  • Remove usages of java.util.Date and java.util.Time
  • Double-check every module for reading back data from a stream that might not contain data due to a writer buffer (this causes trouble that appeared as failing tests)

- Replace Lyncode XMLIO with our forked lib
- Replace any references to DSpace packages with io.gdcc
…th JDK HTTP client

- Removes the old Apache Http Client dependency (good!)
- Removes the old HttpOAIClient implementation based on Apache HTTP
- Uses a builder pattern to create and use the OAI client
- OAIClient now abstract class with a default implementation JdkHttpOaiClient
- OAIClient contains an interface for the builder, also implemented inside JdkHttpOaiClient.JdkHttpBuilder
- The builder interface tries to expose as much useful behaviour as possible
- Lots of Javadoc
- Tests for default implementation not yet implemented
In a lots of usages, the XmlReader is created for a single stream.
It makes sense to use the reader within a try-with-resources block,
but this requires to implement AutoClosable.

Please note: the stream will not be closed by the underlying StAX parser.
But as the stream is usually within the same try-with-resources block,
it will be closed, too.
- No more log4j 1.2 (good!)
- Move stax2-api to newer version via parent POM
- Update StAX2 Parser Woodstox to latest version from FasterXML
- Make the parser scope runtime and optional to allow swapping for different version
  (appserver provided etc) or even switch to other implementation (like Aalto)
… usage

- Instead of using Apache IOUtils to close the stream in a finally block,
  use proper try-with-resources.
- Replace all lyncode/dspace packages with io.gdcc ones
- Fix some vars that should be final
- Fix some catch-block syntactic sugar for exceptions handled the same
- Add some comments of leftover TODOs regarding deduplication etc
…eters

- Also deleted from parent POM as no longer in use anywhere
The example Item implementation method InMemoryItem.withDefaults()
set the list of sets to an unmodifiable list type. Fixing
with same usage of withSet() as in randomItem()
…ons to test

- These are only here for testing and to provide an example. No one should use these in real applications!
- As we reuse these classes from data-provider in service-provider tests, the most likely
  reason why these landed on the normal classpath in the first place was test classes aren't
  included in the data-provider JAR, which is included as testing dep in service-provider
- The solution for this very simple case here is to create a tests JAR from data-provider,
  which can be pulled as an additional testing dependency next to the normal JAR.
Draw in the simple logging implementation for tests.
The XMLIO library is very basic and is mostly used to offer
writing capabilities to xoai-common and reading capabilities to
all other XOAI modules.

There are classes using the writer directly due to the name conflict
of io.gdcc.xoai.xml.XmlWriter and former io.gdcc.xoai.xmlio.XmlWriter.
With the renaming, this cannot happen anymore. This was also
annotated by Sonarcloud, and yes, it led to wrong practice.

The interfaces io.gdcc.xoai.xmlio.XmlWritable and
io.gdcc.xoai.xmlio.XmlReadable are not used anywhere and are duplicated
with the ones with the same name in io.gdcc.xoai.xml from xoai-common
module. They have been removed accordingly.
Some common classes wrongfully used the now rename XmlIoWriter class
and more from the xoai-xmlio package.
This is now fixed and should avoid some errors.
- Use try-with-resources, but make sure everything is closed before reading back the stream data
- Throw IllegalArgumentException when the xml string could not be formatted - return an empty string is not helpful
- Use try-with-resources, but make sure everything is closed before reading back the stream data
Instead of creating just another writer, reuse the implementation already present
XmlReader.retrieveCurrentAsString was failing to add the end element
of the outermost XML tag. This was noticed from failing tests in
service-provider, where an XML transformer complained about the missing
closing tag.
Also removing the JUnit4 and Mockito dependency, including dependencyManagement from parent POM.
Make sure the XmlReader change does not trigger any unforeseen consequences.
The module does not rely on the StAX parsing directly, as it used the xmlio
and common modules to do the heavy lifting.
As Sonarcloud indicated, there are some code smells fixed here:
- Make class variables final as they aren't changed again and assigned via constructor.
- Refactor to use the diamond operator for generic class usages.
- Avoid an NPE hazard with the strange conversion of the exception when no sets can be found.
@poikilotherm poikilotherm force-pushed the refactor/service-provider branch from df27ff3 to d924ba0 Compare May 11, 2022 17:11
@poikilotherm poikilotherm force-pushed the refactor/service-provider branch from d924ba0 to 87e09d2 Compare May 11, 2022 17:19
@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 54 Code Smells

30.6% 30.6% Coverage
0.0% 0.0% Duplication

@poikilotherm
Copy link
Member Author

Folks, I'm shipping this now. The larger things like readbacks etc will be targeted in another iteration.

@poikilotherm poikilotherm marked this pull request as ready for review May 12, 2022 12:55
@poikilotherm poikilotherm merged commit c30e88a into branch-5.0 May 12, 2022
@poikilotherm poikilotherm deleted the refactor/service-provider branch May 12, 2022 12:55
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.

1 participant