Summary
A set of fixes to align the Java runtime with the other runtimes (Python, TypeScript, .NET) for functional equivalence and cross-runtime consistency.
Contracts Service
Class rename
- Renamed class
ContractEventHandler → ContractEventHandlerFunction in unicorn_contracts/ContractsService/src/main/java/contracts/ContractEventHandler.java
- Renamed the file to
ContractEventHandlerFunction.java
- Updated
CreateContractTests.java to reference ContractEventHandlerFunction
Timestamp type change (Contract.java)
- Changed
contractCreated field from Long to String
- Changed
contractLastModifiedOn field from Long to String
Timestamp storage in createContract
- Replaced
Instant.now().toEpochMilli() with Instant.now().toString()
- Changed DynamoDB attribute storage from
.n(String.valueOf(timestamp)) to .s(Instant.now().toString())
- Applied to both
contract_created and contract_last_modified_on attributes
Timestamp storage in updateContract
- Changed expression attribute value
:modifiedDate from .n(String.valueOf(Instant.now().toEpochMilli())) to .s(Instant.now().toString())
ResponseParser.java
- Removed
.map(Long::valueOf) from contract_created and contract_last_modified_on parsing chains (fields are now String, not Long)
Observability metrics
- Added
ContractCreated metric (MetricUnit.COUNT, value 1) to createContract success path
- Added
ContractUpdated metric (MetricUnit.COUNT, value 1) to updateContract success path
- Uses
MetricsFactory.getMetricsInstance().addMetric(...) (correct instance-based API for Powertools Java v2.x)
Web Service (Publication Manager)
Event source from environment variable (RequestApprovalFunction.java)
- Added
SERVICE_NAMESPACE field read from System.getenv("SERVICE_NAMESPACE")
- Replaced hardcoded
"Unicorn.Web" source in sendEvent with the SERVICE_NAMESPACE field
Complete event payload (RequestApprovalFunction.java)
- Expanded the
RequestApproval inner class to include all required fields: status, listprice (Float), images (List<String>), description, currency
- Updated
sendEvent to populate all fields from the Property object into the event detail
Observability metrics (RequestApprovalFunction.java)
- Added
ApprovalsRequested metric (MetricUnit.COUNT, value 1) to sendEvent success path
Evaluation result validation (PublicationEvaluationEventHandler.java)
- Added guard to only process events where
evaluationResult is APPROVED or DECLINED
- Logs a warning and returns without writing to DynamoDB for any other value
Observability metrics (PublicationEvaluationEventHandler.java)
- Added
PropertiesApproved metric (MetricUnit.COUNT, value 1) to updatePropertyStatus success path
Summary
A set of fixes to align the Java runtime with the other runtimes (Python, TypeScript, .NET) for functional equivalence and cross-runtime consistency.
Contracts Service
Class rename
ContractEventHandler→ContractEventHandlerFunctioninunicorn_contracts/ContractsService/src/main/java/contracts/ContractEventHandler.javaContractEventHandlerFunction.javaCreateContractTests.javato referenceContractEventHandlerFunctionTimestamp type change (
Contract.java)contractCreatedfield fromLongtoStringcontractLastModifiedOnfield fromLongtoStringTimestamp storage in
createContractInstant.now().toEpochMilli()withInstant.now().toString().n(String.valueOf(timestamp))to.s(Instant.now().toString())contract_createdandcontract_last_modified_onattributesTimestamp storage in
updateContract:modifiedDatefrom.n(String.valueOf(Instant.now().toEpochMilli()))to.s(Instant.now().toString())ResponseParser.java.map(Long::valueOf)fromcontract_createdandcontract_last_modified_onparsing chains (fields are nowString, notLong)Observability metrics
ContractCreatedmetric (MetricUnit.COUNT, value1) tocreateContractsuccess pathContractUpdatedmetric (MetricUnit.COUNT, value1) toupdateContractsuccess pathMetricsFactory.getMetricsInstance().addMetric(...)(correct instance-based API for Powertools Java v2.x)Web Service (Publication Manager)
Event source from environment variable (
RequestApprovalFunction.java)SERVICE_NAMESPACEfield read fromSystem.getenv("SERVICE_NAMESPACE")"Unicorn.Web"source insendEventwith theSERVICE_NAMESPACEfieldComplete event payload (
RequestApprovalFunction.java)RequestApprovalinner class to include all required fields:status,listprice(Float),images(List<String>),description,currencysendEventto populate all fields from thePropertyobject into the event detailObservability metrics (
RequestApprovalFunction.java)ApprovalsRequestedmetric (MetricUnit.COUNT, value1) tosendEventsuccess pathEvaluation result validation (
PublicationEvaluationEventHandler.java)evaluationResultisAPPROVEDorDECLINEDObservability metrics (
PublicationEvaluationEventHandler.java)PropertiesApprovedmetric (MetricUnit.COUNT, value1) toupdatePropertyStatussuccess path