forked from finos/rune-dsl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial * WIP * Created new docs * Updated description * Converted to Demo model * Update rosetta-java-documentation.md * Fixed typo --------- Co-authored-by: Hugo Hills <39260692+hugohills-regnosys@users.noreply.github.com>
- Loading branch information
1 parent
eafdcf2
commit ea556a9
Showing
4 changed files
with
412 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
--- | ||
title: "Rosetta Java Documentation" | ||
date: 2023-09-01T12:57:00+02:00 | ||
description: "This document describes the interface and usage of classes that are generated from a Rosetta model using the Java code generator." | ||
draft: false | ||
weight: 2 | ||
--- | ||
|
||
# Rosetta Java Documentation | ||
|
||
## Types and enums | ||
|
||
Coming soon. | ||
|
||
## Functions | ||
|
||
Coming soon. | ||
|
||
## Validation | ||
|
||
Coming soon. | ||
|
||
## Reports and rules | ||
|
||
Both reports and rules are represented in the same way as a [function](#functions). They implement the `ReportFunction<IN, OUT>` interface, which extends from `RosettaFunction`, and additionally exposes an `evaluate` method that takes in a single parameter of type `IN` (the input of a report, e.g., a `ReportableEvent`) and has a result of type `OUT` (the report output, e.g., a `CFTCPart43TransactionReport`). | ||
|
||
### Example: European Emission Report | ||
|
||
As a simple example, consider the following report definition: | ||
``` Haskell | ||
report EuropeanParliament EmissionPerformanceStandardsEU in real-time | ||
from VehicleOwnership | ||
when IsEuroStandardsCoverage | ||
with type EuropeanParliamentReport | ||
|
||
// Definition for regulatory references: | ||
body Authority EuropeanParliament | ||
corpus Regulation "Regulation (EU) 2019/631" EmissionPerformanceStandardsEU | ||
``` | ||
This report takes an input of type `VehicleOwnership`, and returns an instance of type `EuropeanParliamentReport`, defined as follows: | ||
``` Haskell | ||
type VehicleOwnership: | ||
drivingLicence DrivingLicence (1..1) | ||
vehicle Vehicle (1..1) | ||
|
||
type EuropeanParliamentReport: | ||
vehicleRegistrationID string (1..1) | ||
[ruleReference VehicleRegistrationID] | ||
vehicleClassificationType VehicleClassificationEnum (1..1) | ||
[ruleReference VehicleClassificationType] | ||
|
||
type Vehicle: | ||
registrationID string (1..1) | ||
vehicleClassification VehicleClassificationEnum (1..1) | ||
|
||
enum VehicleClassificationEnum: | ||
M1_Passengers | ||
M2_Passengers | ||
M3_Passengers | ||
N1I_Commercial | ||
... | ||
|
||
type Person: | ||
name string (1..1) | ||
|
||
type DrivingLicence: | ||
owner Person (1..1) | ||
countryofIssuance string (1..1) | ||
dateofIssuance date (1..1) | ||
dateOfRenewal date (0..1) | ||
vehicleEntitlement VehicleClassificationEnum (0..*) | ||
``` | ||
|
||
The report is supported by the following rules. | ||
|
||
``` Haskell | ||
eligibility rule IsEuroStandardsCoverage from VehicleOwnership: | ||
filter | ||
vehicle -> vehicleClassification = VehicleClassificationEnum -> M1_Passengers | ||
or vehicle -> vehicleClassification = VehicleClassificationEnum -> M2_Passengers | ||
or vehicle -> vehicleClassification = VehicleClassificationEnum -> M3_Passengers | ||
or vehicle -> vehicleClassification = VehicleClassificationEnum -> N1I_Commercial | ||
or ... | ||
|
||
reporting rule VehicleRegistrationID from VehicleOwnership: | ||
extract vehicle -> registrationID | ||
as "Vehicle Registration ID" | ||
|
||
reporting rule VehicleClassificationType from VehicleOwnership: <"Classification type of the vehicle"> | ||
extract vehicle -> vehicleClassification | ||
as "Vehicle Classification Type" | ||
``` | ||
|
||
#### Generated Java Code | ||
|
||
In Java, the report is represented by the following class: | ||
``` Java | ||
@ImplementedBy(EuropeanParliamentEmissionPerformanceStandardsEUReportFunction.EuropeanParliamentEmissionPerformanceStandardsEUReportFunctionDefault.class) | ||
public abstract class EuropeanParliamentEmissionPerformanceStandardsEUReportFunction implements ReportFunction<VehicleOwnership, EuropeanParliamentReport> { | ||
@Override | ||
public EuropeanParliamentReport evaluate(VehicleOwnership input) { | ||
EuropeanParliamentReport.EuropeanParliamentReportBuilder outputBuilder = doEvaluate(input); | ||
|
||
... // build the output and perform validation | ||
|
||
return output; | ||
} | ||
|
||
protected abstract EuropeanParliamentReport.EuropeanParliamentReportBuilder doEvaluate(VehicleOwnership input); | ||
|
||
public static class EuropeanParliamentEmissionPerformanceStandardsEUReportFunctionDefault extends EuropeanParliamentEmissionPerformanceStandardsEUReportFunction { | ||
@Override | ||
protected EuropeanParliamentReport.EuropeanParliamentReportBuilder doEvaluate(VehicleOwnership input) { ... } | ||
} | ||
} | ||
``` | ||
Note that we rely on the Guice dependency injection framework to separate specification (`EuropeanParliamentEmissionPerformanceStandardsEUReportFunction`) from implementation (`EuropeanParliamentEmissionPerformanceStandardsEUReportFunctionDefault`). The default implementation will delegate to the `VehicleRegistrationID` and `VehicleClassificationType` reporting rules, as specified in the Rosetta model. | ||
|
||
{{< notice info "Note" >}} | ||
The implementation of a report or a specific reporting rule can be customized by binding their Java class to a custom implementation in your Guice module. | ||
{{< /notice >}} | ||
|
||
#### Running a report | ||
|
||
To run the report, we first need to inject a report function instance using any conventional method delivered by Guice. An example: | ||
``` Java | ||
@Inject | ||
private EuropeanParliamentEmissionPerformanceStandardsEUReportFunction reportFunction; | ||
|
||
@Test | ||
private void testReportFunction() { | ||
VehicleOwnership input = ... // create or read a vehicle ownership instance | ||
EuropeanParliamentReport reportOutput = reportFunction.evaluate(input); | ||
|
||
assertEquals(input.getVehicle().getRegistrationID(), reportOutput.getVehicleRegistrationID()); | ||
} | ||
``` | ||
|
||
### Running a report that relies on rules annotated with `[legacy-syntax]` | ||
|
||
Some reporting rules you might encounter in a Rosetta model are marked with the `[legacy-syntax]` annotation. They are written in a deprecated syntax, and they need an additional Guice binding in order to work - otherwise you will see an exception during injection. Consequently, a report definition that relies in some way on a reporting rule annotated with `[legacy-syntax]` needs this binding as well. | ||
|
||
To run such a report, add the following binding to your Guice module. | ||
``` Java | ||
bind(RosettaActionFactory.class).to(RosettaActionFactoryImpl.class); | ||
``` | ||
You might need to add a dependency to the proprietary `rosetta-reports` artifact in order to import the `RosettaActionFactoryImpl` class. | ||
``` xml | ||
<dependency> | ||
<groupId>com.regnosys</groupId> | ||
<artifactId>rosetta-reports</artifactId> | ||
<version>7.6.3</version> | ||
</dependency> | ||
``` | ||
|
||
{{< notice info "Note" >}} | ||
Support for `[legacy-syntax]` will be dropped in the near future, and the `rosetta-reports` repository will be archived. | ||
{{< /notice >}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.