Skip to content

Commit a78f9f7

Browse files
authored
Merge pull request #113 from Julius278/feature/665-current-version-fix
SDC-665, added the current build version to the generated product xml
2 parents 7a5e366 + ebc24dd commit a78f9f7

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,14 @@
661661
<imageName>docker.io/finmath/${project.artifactId}:${project.version}</imageName>
662662
<jvmArguments>--add-opens java.base/java.time=ALL-UNNAMED</jvmArguments>
663663
</configuration>
664+
<executions>
665+
<execution>
666+
<id>build-info</id>
667+
<goals>
668+
<goal>build-info</goal>
669+
</goals>
670+
</execution>
671+
</executions>
664672
</plugin>
665673
<plugin>
666674
<groupId>org.apache.maven.plugins</groupId>

src/main/java/net/finmath/smartcontract/product/xml/PlainSwapEditorHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public final class PlainSwapEditorHandler {
7575
* @throws JAXBException when marshalling/unmarshalling of a SDCmL object/file fails.
7676
* @throws DatatypeConfigurationException when conversion of dates to the FPmL specifications fails.
7777
*/
78-
public PlainSwapEditorHandler(final PlainSwapOperationRequest plainSwapOperationRequest, String templatePath, String schemaPath) throws IOException, SAXException, JAXBException, DatatypeConfigurationException {
78+
public PlainSwapEditorHandler(final PlainSwapOperationRequest plainSwapOperationRequest, String templatePath, String schemaPath, String projectVersion) throws IOException, SAXException, JAXBException, DatatypeConfigurationException {
7979
try {
8080
final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
8181
sdcmlSchema = schemaFactory.newSchema((new ClassPathResource(schemaPath)).getURL());
@@ -107,7 +107,7 @@ public PlainSwapEditorHandler(final PlainSwapOperationRequest plainSwapOperation
107107
}
108108

109109
// set the SDC specific stuff in the helper methods
110-
setSdcValuationHeader(smartDerivativeContract);
110+
setSdcValuationHeader(smartDerivativeContract, projectVersion);
111111
setSdcPartiesHeader(plainSwapOperationRequest, smartDerivativeContract);
112112
if(plainSwapOperationRequest.getValuationSymbols() != null && !plainSwapOperationRequest.getValuationSymbols().isEmpty()) {
113113
setSdcSettlementHeaderProvidedSymbols(plainSwapOperationRequest, smartDerivativeContract);
@@ -351,12 +351,12 @@ private static void setSdcPartiesHeader(final PlainSwapOperationRequest tradeDes
351351
smartDerivativeContract.setParties(parties);
352352
}
353353

354-
private static void setSdcValuationHeader(final Smartderivativecontract smartDerivativeContract) {
354+
private static void setSdcValuationHeader(final Smartderivativecontract smartDerivativeContract, String projectVersion) {
355355
Smartderivativecontract.Valuation valuationHeader = new Smartderivativecontract.Valuation();
356356
Smartderivativecontract.Valuation.Artefact artifactHeader = new Smartderivativecontract.Valuation.Artefact();
357357
artifactHeader.setGroupId("net.finmath");
358358
artifactHeader.setArtifactId("finmath-smart-derivative-contract");
359-
artifactHeader.setVersion("0.1.8");
359+
artifactHeader.setVersion(projectVersion);
360360
valuationHeader.setArtefact(artifactHeader);
361361
smartDerivativeContract.setValuation(valuationHeader);
362362
}

src/main/java/net/finmath/smartcontract/valuation/service/controllers/PlainSwapEditorController.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.slf4j.Logger;
2424
import org.slf4j.LoggerFactory;
2525
import org.springframework.beans.factory.annotation.Value;
26+
import org.springframework.boot.info.BuildProperties;
2627
import org.springframework.core.io.Resource;
2728
import org.springframework.http.HttpStatus;
2829
import org.springframework.http.ProblemDetail;
@@ -79,13 +80,15 @@ public class PlainSwapEditorController implements PlainSwapEditorApi {
7980
private final ResourceGovernor resourceGovernor;
8081
private final ObjectMapper objectMapper;
8182
private final ValuationConfig valuationConfig;
83+
private final BuildProperties buildProperties;
8284

83-
public PlainSwapEditorController(DatabaseConnector databaseConnector, ResourceGovernor resourceGovernor, ObjectMapper objectMapper, ValuationConfig valuationConfig, ValuationConfig valuationConfig1) {
85+
public PlainSwapEditorController(DatabaseConnector databaseConnector, ResourceGovernor resourceGovernor, ObjectMapper objectMapper, ValuationConfig valuationConfig, ValuationConfig valuationConfig1, BuildProperties buildProperties) {
8486
this.databaseConnector = databaseConnector;
8587
this.resourceGovernor = resourceGovernor;
8688
this.objectMapper = objectMapper;
8789
this.schemaPath = valuationConfig.getFpmlSchemaPath();
8890
this.valuationConfig = valuationConfig1;
91+
this.buildProperties = buildProperties;
8992
}
9093

9194
/**
@@ -101,7 +104,8 @@ public ResponseEntity<String> generatePlainSwapSdcml(PlainSwapOperationRequest p
101104
String currentGenerator = identifyCurrentGenerator(plainSwapOperationRequest.getMarketDataProvider());
102105
return ResponseEntity.ok(new PlainSwapEditorHandler(plainSwapOperationRequest,
103106
currentGenerator,
104-
schemaPath).getContractAsXmlString());
107+
schemaPath,
108+
buildProperties.getVersion()).getContractAsXmlString());
105109
} catch (JAXBException | IOException | DatatypeConfigurationException | SAXException e) {
106110
/*
107111
You may see this recurring snippet of code in other controller methods as well. Its goal is to report the stack
@@ -135,7 +139,8 @@ public ResponseEntity<ValueResult> evaluateFromPlainSwapEditor(PlainSwapOperatio
135139
String currentGenerator = identifyCurrentGenerator(plainSwapOperationRequest.getMarketDataProvider());
136140
sdcmlBody = new PlainSwapEditorHandler(plainSwapOperationRequest,
137141
currentGenerator,
138-
schemaPath).getContractAsXmlString();
142+
schemaPath,
143+
buildProperties.getVersion()).getContractAsXmlString();
139144
} catch (JAXBException | IOException | DatatypeConfigurationException | SAXException e) {
140145
ProblemDetail pd = ProblemDetail.forStatusAndDetail(HttpStatus.INTERNAL_SERVER_ERROR,
141146
ErrorDetails.JAXB_ERROR_DETAIL);
@@ -201,7 +206,8 @@ public ResponseEntity<List<CashflowPeriod>> getFixedSchedule(PlainSwapOperationR
201206
String currentGenerator = identifyCurrentGenerator(plainSwapOperationRequest.getMarketDataProvider());
202207
return ResponseEntity.ok(new PlainSwapEditorHandler(plainSwapOperationRequest,
203208
currentGenerator,
204-
schemaPath).getSchedule(
209+
schemaPath,
210+
buildProperties.getVersion()).getSchedule(
205211
PlainSwapEditorHandler.LegSelector.FIXED_LEG, marketData));
206212
} catch (JAXBException | IOException | DatatypeConfigurationException | SAXException e) {
207213
ProblemDetail pd = ProblemDetail.forStatusAndDetail(HttpStatus.INTERNAL_SERVER_ERROR,
@@ -246,7 +252,8 @@ public ResponseEntity<List<CashflowPeriod>> getFloatingSchedule(PlainSwapOperati
246252
String currentGenerator = identifyCurrentGenerator(plainSwapOperationRequest.getMarketDataProvider());
247253
return ResponseEntity.ok(new PlainSwapEditorHandler(plainSwapOperationRequest,
248254
currentGenerator,
249-
schemaPath).getSchedule(
255+
schemaPath,
256+
buildProperties.getVersion()).getSchedule(
250257
PlainSwapEditorHandler.LegSelector.FLOATING_LEG, marketData));
251258
} catch (JAXBException | IOException | DatatypeConfigurationException | SAXException e) {
252259
ProblemDetail pd = ProblemDetail.forStatusAndDetail(HttpStatus.INTERNAL_SERVER_ERROR,
@@ -312,7 +319,8 @@ public ResponseEntity<ValueResult> refreshMarketData(PlainSwapOperationRequest p
312319
String currentGenerator = identifyCurrentGenerator(plainSwapOperationRequest.getMarketDataProvider());
313320
sdc = SDCXMLParser.parse(new PlainSwapEditorHandler(plainSwapOperationRequest,
314321
currentGenerator,
315-
schemaPath).getContractAsXmlString());
322+
schemaPath,
323+
buildProperties.getVersion()).getContractAsXmlString());
316324
} catch (IOException e) {
317325
ProblemDetail pd = ProblemDetail.forStatusAndDetail(HttpStatus.INTERNAL_SERVER_ERROR,
318326
ErrorDetails.STORAGE_ERROR_DETAIL);
@@ -455,7 +463,7 @@ public ResponseEntity<Double> getParRate(PlainSwapOperationRequest plainSwapOper
455463
String currentGenerator = identifyCurrentGenerator(plainSwapOperationRequest.getMarketDataProvider());
456464
return (new MarginCalculator()).getValue(marketDataString, new PlainSwapEditorHandler(
457465
plainSwapOperationRequest.notionalAmount(1E15),
458-
currentGenerator, schemaPath).getContractAsXmlString())
466+
currentGenerator, schemaPath, buildProperties.getVersion()).getContractAsXmlString())
459467
.getValue().doubleValue();
460468
} catch (Exception e) {
461469
ProblemDetail pd = ProblemDetail.forStatusAndDetail(HttpStatus.INTERNAL_SERVER_ERROR,

src/test/java/net/finmath/smartcontract/product/xml/JAXBTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,11 @@ void handlerTest() throws java.lang.Exception {
157157
final String generatorFile = "net.finmath.smartcontract.product.xml/smartderivativecontract.xml";
158158
final String marketDataProvider = "refinitiv";
159159
final String schemaPath = "net.finmath.smartcontract.product.xml/smartderivativecontract.xsd";
160+
final String projectVersion = "x.y.z";
160161

161162
PlainSwapOperationRequest request = generateRequest(marketDataProvider);
162163

163-
PlainSwapEditorHandler handler = new PlainSwapEditorHandler(request, generatorFile, schemaPath);
164+
PlainSwapEditorHandler handler = new PlainSwapEditorHandler(request, generatorFile, schemaPath, projectVersion);
164165

165166
//final String marketData = new String(ValuationClient.class.getClassLoader().getResourceAsStream("net/finmath/smartcontract/valuation/client/legacy/md_testset_refinitiv.xml").readAllBytes(), StandardCharsets.UTF_8);
166167
final String marketData = new String(ValuationClient.class.getClassLoader().getResourceAsStream("net/finmath/smartcontract/valuation/client/md_testset_rics.xml").readAllBytes(), StandardCharsets.UTF_8);

0 commit comments

Comments
 (0)