Skip to content

Commit

Permalink
PN-10049: Added lastUpdateTimestamp attribute to RequestMetadata and … (
Browse files Browse the repository at this point in the history
#453)

* PN-10049: Added lastUpdateTimestamp attribute to RequestMetadata and RequestMetadataDto.
Updated insert and patch methods to support new field.

* PN-10049 : fixed format of lastUpdateTimestapd, added insertTimestamp

* PN-10049: Added lastUpdateTimestamp setting in RequestMetadataServiceImpl.setMessageIdInRequestMetadata() method.

* Delete src/test/java/it/pagopa/pn/ec/pec/configurationProperties directory

deleted duplicated package

---------

Co-authored-by: ElenaPagnacco <[email protected]>
Co-authored-by: Mario Ottone <[email protected]>
Co-authored-by: DamianoLozzi <[email protected]>
Co-authored-by: damiano.lozzi <[email protected]>
  • Loading branch information
5 people authored Apr 12, 2024
1 parent dfc5d0d commit 5aca174
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ components:
$ref: '#/components/schemas/EventsDto'
retry:
$ref: '#/components/schemas/RetryDto'
lastUpdateTimestamp:
type: string

PatchDto:
type: object
Expand All @@ -339,6 +341,8 @@ components:
$ref: './schemas/internal-schemas-digital-v1.yaml#/components/schemas/DigitalProgressStatusDto'
paperProgrStatus:
$ref: './schemas/internal-schemas-paper-v1.yaml#/components/schemas/PaperProgressStatusDto'
insertTimestamp:
type: string

RetryDto:
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import lombok.experimental.FieldDefaults;
import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbBean;

import java.time.OffsetDateTime;

@FieldDefaults(level = AccessLevel.PRIVATE)
@NoArgsConstructor
@AllArgsConstructor
Expand All @@ -15,4 +17,6 @@ public class Events {

DigitalProgressStatus digProgrStatus;
PaperProgressStatus paperProgrStatus;
String insertTimestamp;

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ public class RequestMetadata extends DocumentVersion {
PaperRequestMetadata paperRequestMetadata;
List<Events> eventsList;
Retry retry;
String lastUpdateTimestamp;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package it.pagopa.pn.ec.repositorymanager.service.impl;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.ObjectMapper;
import it.pagopa.pn.commons.utils.dynamodb.async.DynamoDbAsyncTableDecorator;
import it.pagopa.pn.ec.commons.exception.RepositoryManagerException;
import it.pagopa.pn.ec.repositorymanager.configurationproperties.RepositoryManagerDynamoTableName;
Expand All @@ -16,8 +18,13 @@
import software.amazon.awssdk.enhanced.dynamodb.Key;
import software.amazon.awssdk.enhanced.dynamodb.TableSchema;

import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import static it.pagopa.pn.ec.commons.utils.DynamoDbUtils.DYNAMO_OPTIMISTIC_LOCKING_RETRY;
Expand All @@ -31,6 +38,8 @@
@CustomLog
public class RequestMetadataServiceImpl implements RequestMetadataService {

private final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX");

private final DynamoDbAsyncTableDecorator<RequestMetadata> requestMetadataDynamoDbTable;

public RequestMetadataServiceImpl(DynamoDbEnhancedAsyncClient dynamoDbEnhancedClient,
Expand Down Expand Up @@ -95,14 +104,17 @@ public Mono<RequestMetadata> insertRequestMetadata(RequestMetadata requestMetada
return Mono.error(new RepositoryManagerException.RequestMalformedException(
"Valorizzare solamente un tipologia di richiesta metadata"));
}

OffsetDateTime lastUpdateTimestamp = OffsetDateTime.now().withOffsetSameInstant(ZoneOffset.UTC).truncatedTo(ChronoUnit.MILLIS);
requestMetadata.setLastUpdateTimestamp(lastUpdateTimestamp.format(dtf));
return insertRequestMetadataInDynamoDb(requestMetadata);
})
.doOnError(RepositoryManagerException.RequestMalformedException.class, throwable -> log.debug(throwable.getMessage()))
.thenReturn(requestMetadata)
.doOnSuccess(result -> log.info(SUCCESSFUL_OPERATION_ON_LABEL, concatRequestId, INSERT_REQUEST_METADATA_OP, result));
}

private Mono<RequestMetadata> managePatch(String requestId, Patch patch, RequestMetadata retrieveRequestMetadata) {
private Mono<RequestMetadata> managePatch(String requestId, Patch patch, RequestMetadata retrieveRequestMetadata) {
var retry = patch.getRetry();

if (retry != null) {
Expand All @@ -121,6 +133,10 @@ private Mono<RequestMetadata> managePatch(String requestId, Patch patch, Request
var eventsList = retrieveRequestMetadata.getEventsList();
eventsCheck(event, eventsList, requestId);
var newEventsList = new ArrayList<>(eventsList != null ? eventsList : Collections.emptyList());

OffsetDateTime insertTimestamp = OffsetDateTime.now().withOffsetSameInstant(ZoneOffset.UTC).truncatedTo(ChronoUnit.MILLIS);
event.setInsertTimestamp(insertTimestamp.format(dtf));

newEventsList.add(event);
retrieveRequestMetadata.setEventsList(newEventsList);
if (event.getDigProgrStatus() != null) {
Expand Down Expand Up @@ -165,6 +181,11 @@ public Mono<RequestMetadata> patchRequestMetadata(String concatRequestId, Patch
.flatMap(retrieveRequestMetadata -> managePatch(concatRequestId,
patch,
retrieveRequestMetadata))
.map(requestMetadata -> {
OffsetDateTime lastUpdateTimestamp = OffsetDateTime.now().withOffsetSameInstant(ZoneOffset.UTC).truncatedTo(ChronoUnit.MILLIS);
requestMetadata.setLastUpdateTimestamp(lastUpdateTimestamp.format(dtf));
return requestMetadata;
})
.flatMap(this::updateRequestMetadataInDynamoDb)
.retryWhen(DYNAMO_OPTIMISTIC_LOCKING_RETRY)
.doOnSuccess(result -> log.info(SUCCESSFUL_OPERATION_ON_LABEL, concatRequestId, PATCH_REQUEST_METADATA_OP, result));
Expand All @@ -187,6 +208,8 @@ public Mono<RequestMetadata> getRequestMetadataByMessageId(String concatRequestI
public Mono<RequestMetadata> setMessageIdInRequestMetadata(String concatRequestId) {
return getRequestMetadata(concatRequestId).flatMap(retrievedRequestMetadata -> {
retrievedRequestMetadata.setMessageId(encodeMessageId(concatRequestId));
OffsetDateTime lastUpdateTimestamp = OffsetDateTime.now().withOffsetSameInstant(ZoneOffset.UTC).truncatedTo(ChronoUnit.MILLIS);
retrievedRequestMetadata.setLastUpdateTimestamp(lastUpdateTimestamp.format(dtf));
return Mono.fromCompletionStage(requestMetadataDynamoDbTable.updateItem(retrievedRequestMetadata));
}).retryWhen(DYNAMO_OPTIMISTIC_LOCKING_RETRY);
}
Expand Down

0 comments on commit 5aca174

Please sign in to comment.