Skip to content

Commit

Permalink
feat: serialize API3 reports and send to the blockchain
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Czeladka committed Jan 17, 2025
1 parent a34074b commit 5643664
Show file tree
Hide file tree
Showing 22 changed files with 907 additions and 289 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public Either<Problem, Void> storeIncomeStatementAsExample(String organisationId
val org = orgM.orElseThrow();

val reportExample = new ReportEntity();
reportExample.setIdControl(Report.idControl(organisationId, INCOME_STATEMENT, MONTH, (short) 2023, Optional.of((short) 3)));
reportExample.setReportId(Report.id(organisationId, INCOME_STATEMENT, MONTH, (short) 2023, reportExample.getVer(), Optional.of((short) 3)));

reportExample.setOrganisation(Organisation.builder()
Expand Down Expand Up @@ -164,6 +165,7 @@ public Either<Problem, Void> storeBalanceSheetAsExample(String organisationId) {
val org = orgM.orElseThrow();

val reportExample = new ReportEntity();
reportExample.setIdControl(Report.idControl(organisationId, BALANCE_SHEET, MONTH, (short) 2023, Optional.of((short) 3)));
reportExample.setReportId(Report.id(organisationId, INCOME_STATEMENT, YEAR, (short) 2024, reportExample.getVer(), Optional.empty()));

reportExample.setOrganisation(Organisation.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.cardanofoundation.lob.app.blockchain_common.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.val;
import org.cardanofoundation.lob.app.blockchain_common.service_assistance.JsonSchemaMetadataChecker;
import org.cardanofoundation.lob.app.blockchain_common.service_assistance.MetadataChecker;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;

@Configuration
public class BlockchainCommonConfig {

@Value("${lob.l1.transaction.metadata.validation.enable:true}")
private boolean enableChecker;

@Bean
@Qualifier("api1JsonSchemaMetadataChecker")
public MetadataChecker api1JsonSchemaMetadataChecker(ObjectMapper objectMapper,
@Value("classpath:api1_lob_blockchain_transaction_metadata_schema.json") Resource metadataSchemaResource
) {
val checker = new JsonSchemaMetadataChecker(objectMapper);
checker.setMetadataSchemaResource(metadataSchemaResource);
checker.setEnableChecker(enableChecker);

return checker;
}

@Bean
@Qualifier("api3JsonSchemaMetadataChecker")
public MetadataChecker api3JsonSchemaMetadataChecker(ObjectMapper objectMapper,
@Value("classpath:api3_lob_blockchain_transaction_metadata_schema.json") Resource metadataSchemaResource
) {
val checker = new JsonSchemaMetadataChecker(objectMapper);
checker.setMetadataSchemaResource(metadataSchemaResource);
checker.setEnableChecker(enableChecker);

return checker;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,21 @@
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service;

import java.io.IOException;

import static com.networknt.schema.SpecVersion.VersionFlag.V7;

@Slf4j
@Service
@RequiredArgsConstructor
public class JsonSchemaMetadataChecker implements MetadataChecker {

private final ObjectMapper objectMapper;

@Value("classpath:api1_lob_blockchain_transaction_metadata_schema.json")
@Setter
protected Resource metadataSchemaResource;

@Value("${lob.l1.transaction.metadata.validation.enable:true}")
@Setter
protected boolean enableChecker;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
"accountingPeriodPattern": {
"type": "string",
"pattern": "^[0-9]{4}-[0-9]{2}$"
},
"timestampPattern": {
"type": "string",
"pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?Z$"
}
},
"properties": {
Expand All @@ -30,9 +34,12 @@
},
"version": {
"type": "string"
},
"timestamp": {
"$ref": "#/definitions/timestampPattern"
}
},
"required": ["creation_slot", "version"]
"required": ["creation_slot", "version", "timestamp"]
},
"org": {
"type": "object",
Expand Down Expand Up @@ -187,7 +194,7 @@
"$ref": "#/definitions/bigDecimalPattern"
}
},
"required": ["amount", "event", "document", "id", "fx_rate"]
"required": ["amount", "event", "id", "fx_rate", "document"]
}
},
"accounting_period": {
Expand All @@ -199,4 +206,4 @@
}
},
"required": ["metadata", "org", "type", "data"]
}
}
Loading

0 comments on commit 5643664

Please sign in to comment.