From 44797c574b85a69224826e2e45c4dd0ebef5b58a Mon Sep 17 00:00:00 2001 From: Julius Lauterbach Date: Mon, 16 Dec 2024 12:00:06 +0100 Subject: [PATCH 1/2] SDC-665, added the current build version to the generated product xml --- pom.xml | 8 +++++++ .../product/xml/PlainSwapEditorHandler.java | 8 +++---- .../PlainSwapEditorController.java | 22 +++++++++++++------ 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index fcedfe63..b506cdb4 100644 --- a/pom.xml +++ b/pom.xml @@ -661,6 +661,14 @@ docker.io/finmath/${project.artifactId}:${project.version} --add-opens java.base/java.time=ALL-UNNAMED + + + build-info + + build-info + + + org.apache.maven.plugins diff --git a/src/main/java/net/finmath/smartcontract/product/xml/PlainSwapEditorHandler.java b/src/main/java/net/finmath/smartcontract/product/xml/PlainSwapEditorHandler.java index 208c306a..1b625ee4 100644 --- a/src/main/java/net/finmath/smartcontract/product/xml/PlainSwapEditorHandler.java +++ b/src/main/java/net/finmath/smartcontract/product/xml/PlainSwapEditorHandler.java @@ -75,7 +75,7 @@ public final class PlainSwapEditorHandler { * @throws JAXBException when marshalling/unmarshalling of a SDCmL object/file fails. * @throws DatatypeConfigurationException when conversion of dates to the FPmL specifications fails. */ - public PlainSwapEditorHandler(final PlainSwapOperationRequest plainSwapOperationRequest, String templatePath, String schemaPath) throws IOException, SAXException, JAXBException, DatatypeConfigurationException { + public PlainSwapEditorHandler(final PlainSwapOperationRequest plainSwapOperationRequest, String templatePath, String schemaPath, String projectVersion) throws IOException, SAXException, JAXBException, DatatypeConfigurationException { try { final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); sdcmlSchema = schemaFactory.newSchema((new ClassPathResource(schemaPath)).getURL()); @@ -107,7 +107,7 @@ public PlainSwapEditorHandler(final PlainSwapOperationRequest plainSwapOperation } // set the SDC specific stuff in the helper methods - setSdcValuationHeader(smartDerivativeContract); + setSdcValuationHeader(smartDerivativeContract, projectVersion); setSdcPartiesHeader(plainSwapOperationRequest, smartDerivativeContract); if(plainSwapOperationRequest.getValuationSymbols() != null && !plainSwapOperationRequest.getValuationSymbols().isEmpty()) { setSdcSettlementHeaderProvidedSymbols(plainSwapOperationRequest, smartDerivativeContract); @@ -351,12 +351,12 @@ private static void setSdcPartiesHeader(final PlainSwapOperationRequest tradeDes smartDerivativeContract.setParties(parties); } - private static void setSdcValuationHeader(final Smartderivativecontract smartDerivativeContract) { + private static void setSdcValuationHeader(final Smartderivativecontract smartDerivativeContract, String projectVersion) { Smartderivativecontract.Valuation valuationHeader = new Smartderivativecontract.Valuation(); Smartderivativecontract.Valuation.Artefact artifactHeader = new Smartderivativecontract.Valuation.Artefact(); artifactHeader.setGroupId("net.finmath"); artifactHeader.setArtifactId("finmath-smart-derivative-contract"); - artifactHeader.setVersion("0.1.8"); + artifactHeader.setVersion(projectVersion); valuationHeader.setArtefact(artifactHeader); smartDerivativeContract.setValuation(valuationHeader); } diff --git a/src/main/java/net/finmath/smartcontract/valuation/service/controllers/PlainSwapEditorController.java b/src/main/java/net/finmath/smartcontract/valuation/service/controllers/PlainSwapEditorController.java index e2dce598..da5a0f14 100644 --- a/src/main/java/net/finmath/smartcontract/valuation/service/controllers/PlainSwapEditorController.java +++ b/src/main/java/net/finmath/smartcontract/valuation/service/controllers/PlainSwapEditorController.java @@ -23,6 +23,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.info.BuildProperties; import org.springframework.core.io.Resource; import org.springframework.http.HttpStatus; import org.springframework.http.ProblemDetail; @@ -79,13 +80,15 @@ public class PlainSwapEditorController implements PlainSwapEditorApi { private final ResourceGovernor resourceGovernor; private final ObjectMapper objectMapper; private final ValuationConfig valuationConfig; + private final BuildProperties buildProperties; - public PlainSwapEditorController(DatabaseConnector databaseConnector, ResourceGovernor resourceGovernor, ObjectMapper objectMapper, ValuationConfig valuationConfig, ValuationConfig valuationConfig1) { + public PlainSwapEditorController(DatabaseConnector databaseConnector, ResourceGovernor resourceGovernor, ObjectMapper objectMapper, ValuationConfig valuationConfig, ValuationConfig valuationConfig1, BuildProperties buildProperties) { this.databaseConnector = databaseConnector; this.resourceGovernor = resourceGovernor; this.objectMapper = objectMapper; this.schemaPath = valuationConfig.getFpmlSchemaPath(); this.valuationConfig = valuationConfig1; + this.buildProperties = buildProperties; } /** @@ -101,7 +104,8 @@ public ResponseEntity generatePlainSwapSdcml(PlainSwapOperationRequest p String currentGenerator = identifyCurrentGenerator(plainSwapOperationRequest.getMarketDataProvider()); return ResponseEntity.ok(new PlainSwapEditorHandler(plainSwapOperationRequest, currentGenerator, - schemaPath).getContractAsXmlString()); + schemaPath, + buildProperties.getVersion()).getContractAsXmlString()); } catch (JAXBException | IOException | DatatypeConfigurationException | SAXException e) { /* 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 evaluateFromPlainSwapEditor(PlainSwapOperatio String currentGenerator = identifyCurrentGenerator(plainSwapOperationRequest.getMarketDataProvider()); sdcmlBody = new PlainSwapEditorHandler(plainSwapOperationRequest, currentGenerator, - schemaPath).getContractAsXmlString(); + schemaPath, + buildProperties.getVersion()).getContractAsXmlString(); } catch (JAXBException | IOException | DatatypeConfigurationException | SAXException e) { ProblemDetail pd = ProblemDetail.forStatusAndDetail(HttpStatus.INTERNAL_SERVER_ERROR, ErrorDetails.JAXB_ERROR_DETAIL); @@ -201,7 +206,8 @@ public ResponseEntity> getFixedSchedule(PlainSwapOperationR String currentGenerator = identifyCurrentGenerator(plainSwapOperationRequest.getMarketDataProvider()); return ResponseEntity.ok(new PlainSwapEditorHandler(plainSwapOperationRequest, currentGenerator, - schemaPath).getSchedule( + schemaPath, + buildProperties.getVersion()).getSchedule( PlainSwapEditorHandler.LegSelector.FIXED_LEG, marketData)); } catch (JAXBException | IOException | DatatypeConfigurationException | SAXException e) { ProblemDetail pd = ProblemDetail.forStatusAndDetail(HttpStatus.INTERNAL_SERVER_ERROR, @@ -246,7 +252,8 @@ public ResponseEntity> getFloatingSchedule(PlainSwapOperati String currentGenerator = identifyCurrentGenerator(plainSwapOperationRequest.getMarketDataProvider()); return ResponseEntity.ok(new PlainSwapEditorHandler(plainSwapOperationRequest, currentGenerator, - schemaPath).getSchedule( + schemaPath, + buildProperties.getVersion()).getSchedule( PlainSwapEditorHandler.LegSelector.FLOATING_LEG, marketData)); } catch (JAXBException | IOException | DatatypeConfigurationException | SAXException e) { ProblemDetail pd = ProblemDetail.forStatusAndDetail(HttpStatus.INTERNAL_SERVER_ERROR, @@ -312,7 +319,8 @@ public ResponseEntity refreshMarketData(PlainSwapOperationRequest p String currentGenerator = identifyCurrentGenerator(plainSwapOperationRequest.getMarketDataProvider()); sdc = SDCXMLParser.parse(new PlainSwapEditorHandler(plainSwapOperationRequest, currentGenerator, - schemaPath).getContractAsXmlString()); + schemaPath, + buildProperties.getVersion()).getContractAsXmlString()); } catch (IOException e) { ProblemDetail pd = ProblemDetail.forStatusAndDetail(HttpStatus.INTERNAL_SERVER_ERROR, ErrorDetails.STORAGE_ERROR_DETAIL); @@ -455,7 +463,7 @@ public ResponseEntity getParRate(PlainSwapOperationRequest plainSwapOper String currentGenerator = identifyCurrentGenerator(plainSwapOperationRequest.getMarketDataProvider()); return (new MarginCalculator()).getValue(marketDataString, new PlainSwapEditorHandler( plainSwapOperationRequest.notionalAmount(1E15), - currentGenerator, schemaPath).getContractAsXmlString()) + currentGenerator, schemaPath, buildProperties.getVersion()).getContractAsXmlString()) .getValue().doubleValue(); } catch (Exception e) { ProblemDetail pd = ProblemDetail.forStatusAndDetail(HttpStatus.INTERNAL_SERVER_ERROR, From ebc24dd4b8c2d42c8d7479b02de10191b3b9def1 Mon Sep 17 00:00:00 2001 From: Julius Lauterbach Date: Mon, 16 Dec 2024 12:19:24 +0100 Subject: [PATCH 2/2] SDC-665, fix for JAXBTest --- .../java/net/finmath/smartcontract/product/xml/JAXBTests.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/net/finmath/smartcontract/product/xml/JAXBTests.java b/src/test/java/net/finmath/smartcontract/product/xml/JAXBTests.java index a0260808..41c30291 100644 --- a/src/test/java/net/finmath/smartcontract/product/xml/JAXBTests.java +++ b/src/test/java/net/finmath/smartcontract/product/xml/JAXBTests.java @@ -157,10 +157,11 @@ void handlerTest() throws java.lang.Exception { final String generatorFile = "net.finmath.smartcontract.product.xml/smartderivativecontract.xml"; final String marketDataProvider = "refinitiv"; final String schemaPath = "net.finmath.smartcontract.product.xml/smartderivativecontract.xsd"; + final String projectVersion = "x.y.z"; PlainSwapOperationRequest request = generateRequest(marketDataProvider); - PlainSwapEditorHandler handler = new PlainSwapEditorHandler(request, generatorFile, schemaPath); + PlainSwapEditorHandler handler = new PlainSwapEditorHandler(request, generatorFile, schemaPath, projectVersion); //final String marketData = new String(ValuationClient.class.getClassLoader().getResourceAsStream("net/finmath/smartcontract/valuation/client/legacy/md_testset_refinitiv.xml").readAllBytes(), StandardCharsets.UTF_8); final String marketData = new String(ValuationClient.class.getClassLoader().getResourceAsStream("net/finmath/smartcontract/valuation/client/md_testset_rics.xml").readAllBytes(), StandardCharsets.UTF_8);