Skip to content

Commit

Permalink
Merge pull request #113 from Julius278/feature/665-current-version-fix
Browse files Browse the repository at this point in the history
SDC-665, added the current build version to the generated product xml
  • Loading branch information
cfries authored Dec 16, 2024
2 parents 7a5e366 + ebc24dd commit a78f9f7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,14 @@
<imageName>docker.io/finmath/${project.artifactId}:${project.version}</imageName>
<jvmArguments>--add-opens java.base/java.time=ALL-UNNAMED</jvmArguments>
</configuration>
<executions>
<execution>
<id>build-info</id>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -101,7 +104,8 @@ public ResponseEntity<String> 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
Expand Down Expand Up @@ -135,7 +139,8 @@ public ResponseEntity<ValueResult> 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);
Expand Down Expand Up @@ -201,7 +206,8 @@ public ResponseEntity<List<CashflowPeriod>> 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,
Expand Down Expand Up @@ -246,7 +252,8 @@ public ResponseEntity<List<CashflowPeriod>> 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,
Expand Down Expand Up @@ -312,7 +319,8 @@ public ResponseEntity<ValueResult> 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);
Expand Down Expand Up @@ -455,7 +463,7 @@ public ResponseEntity<Double> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a78f9f7

Please sign in to comment.