Skip to content

Commit

Permalink
Add timestamp_created
Browse files Browse the repository at this point in the history
  • Loading branch information
jnpsk committed Oct 15, 2024
1 parent 8788d5c commit 9bfde39
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 16 deletions.
3 changes: 2 additions & 1 deletion docs/Database-Structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,9 @@ Stores callback URLs - per-application endpoints that are notified whenever an a
| initial_backoff | VARCHAR(64) | - | Initial backoff period before the next send attempt, stored as a ISO 8601 string. |
| retention_period | VARCHAR(64) | - | Minimal duration for which is a completed callback event persisted, stored as a ISO 8601 string. |
| timestamp_last_failure | DATETIME | - | The timestamp of the most recent failed callback event associated with this configuration. |
| failure_count | INTEGER | - | The number of consecutive failed callback events associated with this configuration. |
| failure_count | INTEGER | DEFAULT 0 NOT NULL | The number of consecutive failed callback events associated with this configuration. |
| enabled | BOOLEAN | - | Indicator specifying whether the Callback URL should be used. |
| timestamp_created | DATETIME | DEFAULT NOW() NOT NULL | Timestamp when the record was created. |
| timestamp_last_updated | DATETIME | - | Timestamp of the last update of the record via the Callback Management API. |
<!-- end -->

Expand Down
9 changes: 5 additions & 4 deletions docs/PowerAuth-Server-1.9.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ to `true` (enabled) by default. A Callback URL remains enabled until a delete re
Management API, at which point the `enabled` column is set to `false` (disabled). Disabled Callback URLs will be
excluded from all subsequent queries and operations.

### Add Column of Last Callback Configuration Update
### Callback URL Creation and Last Update Timestamp

A new column `timestamp_last_updated` has been added to the `pa_application_callback` table to store the timestamp of the
last record update via the Callback Management API. This addition supports the caching mechanism for REST clients used
to callback posting.
Following columns has been added to the `pa_application_callback` table to improve caching mechanism of REST clients
used for callback posting:
- `timestamp_created` to store the timestamp of the record creation, and
- `timestamp_last_updated` to store the timestamp of the last record update via the Callback Management API.

## REST API Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
<changeSet id="1" logicalFilePath="powerauth-java-server/1.9.x/20241010-rest-client-caching.xml" author="Jan Pesek">
<preConditions onFail="MARK_RAN">
<not>
<columnExists tableName="pa_application_callback" columnName="timestamp_created" />
<columnExists tableName="pa_application_callback" columnName="timestamp_last_updated" />
</not>
</preConditions>
<comment>Add timestamp_last_updated column to pa_application_callback table.</comment>
<comment>Add columns timestamp_last_updated and timestamp_created to pa_application_callback table</comment>
<addColumn tableName="pa_application_callback">
<column name="timestamp_last_updated" type="timestamp(6)" defaultValueComputed="${now}">
<column name="timestamp_created" type="timestamp(6)" defaultValueComputed="${now}">
<constraints nullable="false" />
</column>
<column name="timestamp_last_updated" type="timestamp(6)" />
</addColumn>
</changeSet>

Expand Down
Binary file modified docs/images/arch_db_structure.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions docs/sql/mssql/migration_1.8.0_1.9.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ ALTER TABLE pa_application_callback ADD enabled bit CONSTRAINT DF_pa_application
GO

-- Changeset powerauth-java-server/1.9.x/20241010-rest-client-caching.xml::1::Jan Pesek
-- Add timestamp_last_updated column to pa_application_callback table.
ALTER TABLE pa_application_callback ADD timestamp_last_updated datetime2(6) CONSTRAINT DF_pa_application_callback_timestamp_last_updated DEFAULT GETDATE() NOT NULL;
-- Add columns timestamp_last_updated and timestamp_created to pa_application_callback table
ALTER TABLE pa_application_callback ADD timestamp_created datetime2(6) CONSTRAINT DF_pa_application_callback_timestamp_created DEFAULT GETDATE() NOT NULL;
GO

ALTER TABLE pa_application_callback ADD timestamp_last_updated datetime2(6);
GO

-- Changeset powerauth-java-server/1.9.x/20241003-add-tag-1.9.0.xml::1::Lubos Racansky
6 changes: 4 additions & 2 deletions docs/sql/oracle/migration_1.8.0_1.9.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ ALTER TABLE pa_application_callback ADD failure_count INTEGER DEFAULT 0 NOT NULL
ALTER TABLE pa_application_callback ADD enabled BOOLEAN DEFAULT 1 NOT NULL;

-- Changeset powerauth-java-server/1.9.x/20241010-rest-client-caching.xml::1::Jan Pesek
-- Add timestamp_last_updated column to pa_application_callback table.
ALTER TABLE pa_application_callback ADD timestamp_last_updated TIMESTAMP(6) DEFAULT sysdate NOT NULL;
-- Add columns timestamp_last_updated and timestamp_created to pa_application_callback table
ALTER TABLE pa_application_callback ADD timestamp_created TIMESTAMP(6) DEFAULT sysdate NOT NULL;

ALTER TABLE pa_application_callback ADD timestamp_last_updated TIMESTAMP(6);

-- Changeset powerauth-java-server/1.9.x/20241003-add-tag-1.9.0.xml::1::Lubos Racansky
6 changes: 4 additions & 2 deletions docs/sql/postgresql/migration_1.8.0_1.9.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ ALTER TABLE pa_application_callback ADD failure_count INTEGER DEFAULT 0 NOT NULL
ALTER TABLE pa_application_callback ADD enabled BOOLEAN DEFAULT TRUE NOT NULL;

-- Changeset powerauth-java-server/1.9.x/20241010-rest-client-caching.xml::1::Jan Pesek
-- Add timestamp_last_updated column to pa_application_callback table.
ALTER TABLE pa_application_callback ADD timestamp_last_updated TIMESTAMP(6) WITHOUT TIME ZONE DEFAULT NOW() NOT NULL;
-- Add columns timestamp_last_updated and timestamp_created to pa_application_callback table
ALTER TABLE pa_application_callback ADD timestamp_created TIMESTAMP(6) WITHOUT TIME ZONE DEFAULT NOW() NOT NULL;

ALTER TABLE pa_application_callback ADD timestamp_last_updated TIMESTAMP(6) WITHOUT TIME ZONE;

-- Changeset powerauth-java-server/1.9.x/20241003-add-tag-1.9.0.xml::1::Lubos Racansky
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,17 @@ public class CallbackUrlEntity implements Serializable {
@Column(name = "enabled", nullable = false)
private boolean enabled = true;

/**
* Timestamp of the creation.
*/
@Column(name = "timestamp_created", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
private LocalDateTime timestampCreated = LocalDateTime.now();

/**
* Timestamp of the last update via Callback Management API.
*/
@Column(name = "timestamp_last_updated", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
private LocalDateTime timestampLastUpdated = LocalDateTime.now();
@Column(name = "timestamp_last_updated")
private LocalDateTime timestampLastUpdated;

@Override
public boolean equals(Object o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class CallbackUrlRestClientCacheLoader implements CacheLoader<String, Cac
}

final LocalDateTime lastEntityUpdate = optionalCallbackUrlEntity.get().getTimestampLastUpdated();
if (lastEntityUpdate.isAfter(cachedRestClient.timestampCreated())) {
if (lastEntityUpdate != null && lastEntityUpdate.isAfter(cachedRestClient.timestampCreated())) {
final RestClient restClient = initializeRestClient(optionalCallbackUrlEntity.get());
return new CachedRestClient(restClient, LocalDateTime.now());
}
Expand Down

0 comments on commit 9bfde39

Please sign in to comment.