Skip to content

fix: cross-runtime consistency fixes#53

Open
sliedig wants to merge 4 commits intodevelopfrom
cross-runtime-fixes
Open

fix: cross-runtime consistency fixes#53
sliedig wants to merge 4 commits intodevelopfrom
cross-runtime-fixes

Conversation

@sliedig
Copy link
Contributor

@sliedig sliedig commented Mar 16, 2026

Issue number: #52

Summary

Changes

Fixes to align the Java runtime with Python, TypeScript, and .NET for functional equivalence and cross-runtime consistency.

Contracts Service (unicorn_contracts)

  • Renamed class and file ContractEventHandlerContractEventHandlerFunction
  • Changed Contract.java timestamp fields contractCreated and contractLastModifiedOn from Long to String
  • createContract: replaced Instant.now().toEpochMilli() + .n(...) with Instant.now().toString() + .s(...) for both timestamp attributes
  • updateContract: changed :modifiedDate expression value from .n(epoch millis) to .s(Instant.now().toString())
  • ResponseParser.java: removed .map(Long::valueOf) from contract_created and contract_last_modified_on parsing chains
  • Added ContractCreated metric (Count, 1) to createContract success path
  • Added ContractUpdated metric (Count, 1) to updateContract success path
  • Updated CreateContractTests.java to reference the renamed ContractEventHandlerFunction

Web Service / Publication Manager (unicorn_web)

  • RequestApprovalFunction: replaced hardcoded "Unicorn.Web" EventBridge source with System.getenv("SERVICE_NAMESPACE")
  • RequestApprovalFunction: expanded RequestApproval inner class with all required fields (status, listprice, images, description, currency) and populated them from the Property object in sendEvent
  • RequestApprovalFunction: added ApprovalsRequested metric (Count, 1) to sendEvent success path
  • PublicationEvaluationEventHandler: added guard to only process APPROVED or DECLINED evaluation results; logs a warning and returns for any other value
  • PublicationEvaluationEventHandler: added PropertiesApproved metric (Count, 1) to the update success path

User experience

Before: Timestamps were stored as DynamoDB Number (epoch millis), mismatched with other runtimes that use ISO 8601 strings. The RequestApprovalFunction emitted a partial event payload and used a hardcoded event source. No custom metrics were emitted for contract lifecycle events or publication approvals.

After: Timestamps are stored as ISO 8601 strings consistent with Python, TypeScript, and .NET. The RequestApprovalFunction emits a complete event payload with all required fields and uses SERVICE_NAMESPACE from the environment. Custom metrics (ContractCreated, ContractUpdated, ApprovalsRequested, PropertiesApproved) are emitted on each successful operation, matching all other runtimes.

Checklist

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

sliedig added 4 commits March 16, 2026 09:50
- Update Contract model to use String type for contractCreated and contractLastModifiedOn fields
- Remove Long::valueOf conversions in ResponseParser when parsing timestamp values from DynamoDB
- Align timestamp handling with string-based storage in DynamoDB AttributeValue
- Simplifies type conversion and maintains consistency with data source format
…lerFunction and add metrics

- Rename class from ContractEventHandler to ContractEventHandlerFunction for consistency
- Update all constructor references to use new class name
- Update logger initialization to reference new class name
- Add metrics tracking for ContractCreated and ContractUpdated events
- Reorganize imports to follow alphabetical ordering
- Change timestamp fields from Long (epoch millis) to String (ISO-8601 format)
- Update DynamoDB attribute builders to use string type for timestamp fields
- Clean up whitespace inconsistencies throughout the file
…entHandlerFunction

- Update handler field type from ContractEventHandler to ContractEventHandlerFunction
- Update handler instantiation in setUp() to use ContractEventHandlerFunction constructor
- Align test class with recent refactoring that renamed ContractEventHandler to ContractEventHandlerFunction
- Import Powertools metrics classes (Metrics, MetricsFactory, MetricUnit)
- Add validation for evaluation results (APPROVED/DECLINED) in PublicationEvaluationEventHandler
- Track PropertiesApproved metric when property status is updated
- Add SERVICE_NAMESPACE environment variable to RequestApprovalFunction
- Expand RequestApproval event payload with status, listprice, images, description, and currency fields
- Add corresponding getters and setters for new RequestApproval properties
- Use SERVICE_NAMESPACE for EventBridge event source instead of hardcoded "Unicorn.Web"
- Track ApprovalsRequested metric when events are sent to EventBridge
- Improve code formatting and consistency
@sliedig sliedig requested a review from a team as a code owner March 16, 2026 02:03
@github-actions github-actions bot added the bug Something isn't working label Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant