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

New DocumentMapper for XML and data retrieval using XPath #112

Merged
merged 8 commits into from Apr 29, 2023

Conversation

oswaldobapvicjr
Copy link
Owner

@oswaldobapvicjr oswaldobapvicjr commented Mar 17, 2023

New feature

Proposed solution

Introduce a new Mapper -- DocumentMapper -- inside the confectory-core module which allows the mapping of XML sources using standard JDK classes as org.w3c.dom.Document instances and data retrieval using XPath.

Module Provider(s) Properties XML JSON YAML
confectory-core JDK 8+ standard -- YES -- --

Examples of usage

Loading a XML file as a Document

Sample file (agents.xml)
<conf>
   <enabled>true</enabled>
   <agents>
      <agent>
         <class>Agent1</class>
         <interval>*/2 * * * *</interval>
      </agent>
      <agent>
         <class>Agent2</class>
         <interval>10s</interval>
      </agent>
   </agents>
</conf>
Code sample (desired):
Configuration<Document> config = Configuration.<Document>builder()
                                .source(new ClasspathFileSource<>("agents.xml"))
                                .mapper(new DocumentMapper())
                                .build();

config.getBean(); // returns an instance of org.w3c.dom.Document
config.getBoolean("//enabled"); // true
config.getString("//agents/agent[1]/class"); // "Agent1"
config.getString("//agents/agent[class='Agent2']/interval"); // "10s"

Task list

The following requirements shall be addressed in this issue:

  • New Mapper implementation (suggested name: DocumentMapper) for loading XML sources as org.w3c.dom.Document
  • New ConfigurationHelper implementation (suggested name: DocumentConfigurationHelper) to support configuration data retrieval using XPath
  • JUnits
  • Documentation updates

Quality criteria

The following criteria will be observed during the Code Review:

Code coverage

  • Unit tests shall secure the produced code.
  • Test unit test coverage shall remain the same or increase (never decrease)

Documentation

  • All methods shall be documented with Javadoc, providing examples of usage.
  • Javadoc pages shall be compilable with no errors or warnings
  • README.md shall be updated if applicable

@oswaldobapvicjr oswaldobapvicjr self-assigned this Mar 17, 2023
@oswaldobapvicjr oswaldobapvicjr added the enhancement New feature or request label Mar 17, 2023
@oswaldobapvicjr oswaldobapvicjr marked this pull request as draft March 17, 2023 03:32
@codecov
Copy link

codecov bot commented Mar 17, 2023

Codecov Report

Merging #112 (f1f99fa) into master (4f73989) will increase coverage by 0.03%.
The diff coverage is 100.00%.

@@             Coverage Diff              @@
##             master     #112      +/-   ##
============================================
+ Coverage     99.16%   99.20%   +0.03%     
- Complexity      385      408      +23     
============================================
  Files            63       65       +2     
  Lines           721      757      +36     
  Branches         51       53       +2     
============================================
+ Hits            715      751      +36     
  Misses            5        5              
  Partials          1        1              
Impacted Files Coverage Δ
...nternal/helper/GenericJsonConfigurationHelper.java 100.00% <ø> (ø)
...y/internal/helper/DocumentConfigurationHelper.java 100.00% <100.00%> (ø)
...ava/net/obvj/confectory/mapper/DocumentMapper.java 100.00% <100.00%> (ø)

@oswaldobapvicjr oswaldobapvicjr marked this pull request as ready for review March 27, 2023 03:16
@oswaldobapvicjr oswaldobapvicjr changed the title New helper for XML configuration using XPath New DocumentMapper for XML and data retrieval using XPath Mar 27, 2023
@oswaldobapvicjr oswaldobapvicjr merged commit 79b6f3b into master Apr 29, 2023
6 checks passed
@oswaldobapvicjr oswaldobapvicjr deleted the issue/0112 branch April 29, 2023 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant