Skip to content

Commit

Permalink
feat: json metadata checker.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Czeladka committed Aug 14, 2024
1 parent 46d0029 commit eb1233d
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public static List<Either<IdentifiableProblem, TransactionItemEntity>> transacti
}).toList();
}

public static Either<IdentifiableProblem, TransactionItemEntity> transactionItemCannotRejectAlreadyApprovedResponse(String transactionId,
String txItemId) {
public static Either<IdentifiableProblem, TransactionItemEntity> transactionItemCannotRejectAlreadyApprovedForDispatchResponse(String transactionId,
String txItemId) {
val problem = Problem.builder()
.withTitle("TX_ALREADY_APPROVED_CANNOT_REJECT_TX_ITEM")
.withDetail(STR."Cannot reject transaction item \{txItemId} because transaction \{transactionId} has already been approved for dispatch")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public List<Either<IdentifiableProblem, TransactionItemEntity>> rejectTransactio

val txItem = txItemM.orElseThrow();
if (tx.getLedgerDispatchApproved()) {
transactionItemEntitiesE.add(transactionItemCannotRejectAlreadyApprovedResponse(transactionId, txItemId));
transactionItemEntitiesE.add(transactionItemCannotRejectAlreadyApprovedForDispatchResponse(transactionId, txItemId));
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.cardanofoundation.lob.app.blockchain_publisher.domain.entity.*;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.time.Clock;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
Expand Down Expand Up @@ -51,7 +50,7 @@ private MetadataMap createMetadataSection(long creationSlot) {

val now = Instant.now(clock);

metadataMap.put("creation_slot", BigInteger.valueOf(creationSlot));
metadataMap.put("creation_slot", String.valueOf(creationSlot));
metadataMap.put("timestamp", DateTimeFormatter.ISO_INSTANT.format(now));
metadataMap.put("version", VERSION);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,39 @@
"type": "object",
"properties": {
"creation_slot": {
"type": "integer"
"type": "string",
"pattern": "^[0-9]+$"
},
"version": {
"type": "string"
}
},
"required": ["creation_slot"]
"required": ["creation_slot", "version"]
},
"organisation": {
"org": {
"type": "object",
"properties": {
"country_code": {
"type": "string",
"pattern": "^[A-Z]{2}$"
},
"name": {
"type": "string"
},
"tax_id_number": {
"type": "string"
},
"id": {
"type": "string"
},
"currency_id": {
"type": "string",
"pattern": "^ISO_4217:[A-Z]{3}$|^ISO_24165:[A-Z0-9]+$"
}
},
"required": ["id"]
"required": ["country_code", "name", "tax_id_number", "id", "currency_id"]
},
"transactions": {
"txs": {
"type": "array",
"items": {
"type": "object",
Expand All @@ -29,97 +47,128 @@
"type": "string",
"format": "date"
},
"base_currency": {
"type": "object",
"properties": {
"internal_number": {
"type": "string"
},
"id": {
"type": "string"
}
},
"required": ["internal_code", "id"]
"number": {
"type": "string"
},
"batch_id": {
"type": "string"
},
"id": {
"type": "string"
},
"documents": {
"type": {
"type": "string",
"enum": [
"CardCharge",
"VendorBill",
"CardRefund",
"Journal",
"FxRevaluation",
"Transfer",
"CustomerPayment",
"ExpenseReport",
"VendorPayment",
"BillCredit"
]
},
"items": {
"type": "array",
"items": {
"type": "object",
"properties": {
"number": {
"type": "string"
"amount": {
"type": "string",
"pattern": "^[0-9]+(\\.[0-9]{1,2})?$"
},
"vat": {
"event_code": {
"type": "object",
"properties": {
"rate": {
"code": {
"type": "string"
},
"internal_code": {
"name": {
"type": "string"
}
}
},
"required": ["code", "name"]
},
"counterparty": {
"project": {
"type": "object",
"properties": {
"internal_code": {
"cust_code": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
}
}
},
"cost_center": {
"type": "string"
},
"project_code": {
"type": "string"
},
"target_currency": {
"type": "object",
"properties": {
"internal_code": {
"type": "string"
},
"id": {
"type": "string"
}
},
"required": ["internal_code", "id"]
},
"internal_number": {
"type": "string"
},
"id": {
"type": "string"
},
"type": {
"type": "string"
},
"fx_rate": {
"type": "string"
},
"items": {
"type": "array",
"items": {
"type": "object",
"properties": {
"amount": {
"type": "string"
},
"required": ["cust_code", "name"]
},
"cost_center": {
"type": "object",
"properties": {
"cust_code": {
"type": "string"
},
"name": {
"type": "string"
}
},
"required": ["cust_code", "name"]
},
"document": {
"type": "object",
"properties": {
"number": {
"type": "string"
},
"currency": {
"type": "object",
"properties": {
"cust_code": {
"type": "string"
},
"id": {
"type": "string",
"pattern": "^ISO_4217:[A-Z]{3}$|^ISO_24165:[A-Z0-9]+$"
}
},
"required": ["cust_code", "id"]
},
"counterparty": {
"type": "object",
"properties": {
"cust_code": {
"type": "string"
},
"type": {
"type": "string"
}
},
"required": ["cust_code", "type"]
}
},
"required": ["number", "currency"]
},
"id": {
"type": "string"
},
"fx_rate": {
"type": "string",
"pattern": "^[0-9]+(\\.[0-9]+)?$"
}
},
"required": ["amount", "id"]
"required": ["amount", "event_code", "document", "id", "fx_rate"]
}
},
"accounting_period": {
"type": "string",
"pattern": "^[0-9]{4}-[0-9]{2}$"
}
},
"required": ["date", "base_currency", "target_currency", "internal_number", "id", "type", "fx_rate", "items"]
"required": ["date", "number", "batch_id", "id", "type", "items", "accounting_period"]
}
}
},
"required": ["metadata", "organisation", "transactions"]
"required": ["metadata", "org", "txs"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.*;
import java.util.Set;

Expand Down Expand Up @@ -96,7 +95,7 @@ void testSerialiseToMetadataMap() {
assertThat(result.get("metadata")).isInstanceOf(MetadataMap.class);
MetadataMap metadata = (MetadataMap) result.get("metadata");

assertThat(metadata.get("creation_slot")).isEqualTo(BigInteger.valueOf(creationSlot));
assertThat(metadata.get("creation_slot")).isEqualTo(String.valueOf(creationSlot));
assertThat(metadata.get("timestamp")).isEqualTo("2023-06-01T10:15:30Z");
assertThat(metadata.get("version")).isEqualTo(MetadataSerialiser.VERSION);

Expand Down

0 comments on commit eb1233d

Please sign in to comment.