Skip to content

Commit

Permalink
Merge pull request #299 from pagopa/develop
Browse files Browse the repository at this point in the history
fix: promotion to master
  • Loading branch information
and-mora authored Nov 30, 2022
2 parents 6da0132 + f603da9 commit 70828f0
Show file tree
Hide file tree
Showing 21 changed files with 94 additions and 32 deletions.
4 changes: 2 additions & 2 deletions api/batch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<parent>
<artifactId>rtd-ms-transaction-filter-api</artifactId>
<groupId>it.gov.pagopa.rtd.ms.transaction_filter.api</groupId>
<version>1.3.2</version>
<version>1.3.3</version>
</parent>

<artifactId>rtd-ms-transaction-filter-api-batch</artifactId>
<version>1.3.2</version>
<version>1.3.3</version>

<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package it.gov.pagopa.rtd.transaction_filter.batch.model;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import lombok.*;

import javax.validation.constraints.NotBlank;
Expand Down Expand Up @@ -84,8 +86,11 @@

/**
* Transaction amount
* max value: 999.999.999,99€
*/
@NotNull
@Min(value = 0)
@Max(value = 99999999999L)
Long amount;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public InboundTransaction process(InboundTransaction inboundTransaction) {
}
key.setAccountingDate(storeService.flyweightAccountingDate(
inboundTransaction.getTrxDate().substring(0, 10)));
boolean dirtyDataFound = storeService.storeAggregate(key, Math.toIntExact(inboundTransaction.getAmount()), inboundTransaction.getVat(),
boolean dirtyDataFound = storeService.storeAggregate(key, inboundTransaction.getAmount(), inboundTransaction.getVat(),
inboundTransaction.getPosType());

if (dirtyDataFound) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import it.gov.pagopa.rtd.transaction_filter.service.TransactionWriterService;
import java.security.SecureRandom;
import java.util.UUID;
import lombok.Data;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -226,7 +227,7 @@ private File getDestionationFileByStatus(String sourceFilePath, boolean isComple
if (isCompleted) {
String archivalPath = resolver.getResources(successPath)[0].getFile().getAbsolutePath();
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");
destinationPath = archivalPath + File.separator + SecureRandom.getInstanceStrong().nextLong() +
destinationPath = archivalPath + File.separator + UUID.randomUUID().toString().replace("-", "").substring(0, 20) +
"_" + OffsetDateTime.now().format(fmt) + "_" + filename;
} else {
String archivalPath = resolver.getResources(uploadPendingPath)[0].getFile().getAbsolutePath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ void processTransactionWithValidCorrelationId(String correlationId) {
}

@ParameterizedTest
@ValueSource(longs = {1000, 200000})
@ValueSource(longs = {0, 1000, 200000, Integer.MAX_VALUE + 1L, 3000000000L, 99999999999L})
void processTransactionWithValidAmount(Long amount) {
BDDMockito.doReturn(true).when(storeServiceMock).hasHpan(FAKE_ENROLLED_PAN);
BDDMockito.doReturn(FAKE_SALT).when(storeServiceMock).getSalt();
Expand All @@ -241,6 +241,17 @@ void processTransactionWithValidAmount(Long amount) {
Assertions.assertEquals(amount, outbound.getAmount());
}

@ParameterizedTest
@ValueSource(longs = {-100L, 100000000000L})
void processTransactionWithInvalidAmount(Long amount) {
BDDMockito.doReturn(true).when(storeServiceMock).hasHpan(FAKE_ENROLLED_PAN);
BDDMockito.doReturn(FAKE_SALT).when(storeServiceMock).getSalt();
InboundTransaction transaction = fakeInboundTransaction();
transaction.setAmount(amount);
InboundTransactionItemProcessor processor = new InboundTransactionItemProcessor(storeServiceMock, false);
Assertions.assertThrows(ConstraintViolationException.class, () -> processor.process(transaction));
}

@ParameterizedTest
@ValueSource(strings = {"1234", "412", "15", ""})
void processTransactionWithInvalidAmountCurrencyThrowsException(String amountCurrency) {
Expand Down
4 changes: 2 additions & 2 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<parent>
<artifactId>rtd-ms-transaction-filter</artifactId>
<groupId>it.gov.pagopa.rtd.ms</groupId>
<version>1.3.2</version>
<version>1.3.3</version>
</parent>

<groupId>it.gov.pagopa.rtd.ms.transaction_filter.api</groupId>
<artifactId>rtd-ms-transaction-filter-api</artifactId>
<version>1.3.2</version>
<version>1.3.3</version>

<packaging>pom</packaging>

Expand Down
4 changes: 2 additions & 2 deletions app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<parent>
<artifactId>rtd-ms-transaction-filter</artifactId>
<groupId>it.gov.pagopa.rtd.ms</groupId>
<version>1.3.2</version>
<version>1.3.3</version>
</parent>

<groupId>it.gov.pagopa.rtd.ms.transaction_filter</groupId>
<artifactId>transaction-filter-app</artifactId>
<version>1.3.2</version>
<version>1.3.3</version>

<dependencies>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ batchConfiguration:
rest-client:
user-agent:
prefix: BatchService
version: 1.3.2
version: 1.3.3
hpan:
serviceCode: hpan-service
base-url: ${HPAN_SERVICE_URL:https://bpd-dev.azure-api.net:${HPAN_SERVICE_PORT:443}}
Expand Down
11 changes: 10 additions & 1 deletion app/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@
</appender>

<!-- file appender-->
<appender name="fileMask" class="ch.qos.logback.core.FileAppender">
<appender name="fileMask" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_FILE}</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>${LOG_FILE}.%d.gz</fileNamePattern>

<!-- keep 15 days' worth of history capped at 100MB total size -->
<maxHistory>15</maxHistory>
<totalSizeCap>100MB</totalSizeCap>
</rollingPolicy>

<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="it.gov.pagopa.rtd.transaction_filter.logger.MaskingPatternLayout">
<maskPattern>Ocp-Apim-Subscription-Key\s*:\s*(.*)</maskPattern> <!-- apikey pattern -->
Expand Down
4 changes: 2 additions & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<parent>
<artifactId>rtd-ms-transaction-filter</artifactId>
<groupId>it.gov.pagopa.rtd.ms</groupId>
<version>1.3.2</version>
<version>1.3.3</version>
</parent>

<groupId>it.gov.pagopa.rtd.ms.transaction_filter</groupId>
<artifactId>rtd-ms-transaction-filter-core</artifactId>
<version>1.3.2</version>
<version>1.3.3</version>

<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public interface StoreService {
* @param posType the transaction POS type
* @return boolean true if dirty data has been found during aggregation
*/
boolean storeAggregate(AggregationKey key, int amount, String vat, String posType);
boolean storeAggregate(AggregationKey key, long amount, String vat, String posType);

/**
* Get the aggregate computed over a single aggregation key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public boolean hasHpan(String hpan) {
}

@Override
public synchronized boolean storeAggregate(AggregationKey key, int amount, String vat, String posType) {
public synchronized boolean storeAggregate(AggregationKey key, long amount, String vat, String posType) {
aggregates.putIfAbsent(key, new AggregationData());
AggregationData data = aggregates.get(key);
data.incNumTrx();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ public class AggregationData {
private int numTrx;
// Integer should be fine until we aggregate on daily basis.
// Remember to re-evaluate the data type in case the aggregation period would be increased.
private int totalAmount;
private long totalAmount;
private String vat = INIT_VAT;
private byte posType = INIT_POS_TYPE;

public void incNumTrx() {
this.numTrx += 1;
}

public void incTotalAmount(int amount) {
this.totalAmount += amount;
public void incTotalAmount(long amount) {
this.totalAmount = Math.addExact(this.totalAmount, amount);
}

public boolean updateVatOrMarkAsDirty(String vat) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package it.gov.pagopa.rtd.transaction_filter.service;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import ch.qos.logback.classic.Level;
Expand Down Expand Up @@ -120,7 +121,7 @@ public void getAggregateAfterStoreReturnsData() {
storeService.storeAggregate(key, 1000, null, "01");
AggregationData expectedData = new AggregationData();
expectedData.setNumTrx(1);
expectedData.setTotalAmount(1000);
expectedData.setTotalAmount(1000L);
expectedData.setPosType((byte)1);
expectedData.setVat(null);
Assert.assertEquals(expectedData, storeService.getAggregate(key));
Expand All @@ -140,7 +141,7 @@ public void getAggregateAfterMultipleStoreReturnsData() {
storeService.storeAggregate(key, 2500, null, "01");
AggregationData expectedData = new AggregationData();
expectedData.setNumTrx(2);
expectedData.setTotalAmount(3500);
expectedData.setTotalAmount(3500L);
expectedData.setPosType((byte)1);
expectedData.setVat(null);
Assert.assertEquals(expectedData, storeService.getAggregate(key));
Expand Down Expand Up @@ -260,4 +261,39 @@ public void clearAllEmptiesDataStructures() {
Assert.assertNull(storeService.getTargetInputFile());
}

@Test
public void testTotalAmountIntegerLimit() {
AggregationKey key = new AggregationKey();
key.setTerminalId("1");
key.setMerchantId("1");
key.setAcquirerId(storeService.flyweightAcquirerId("1"));
key.setSenderCode(storeService.flyweightSenderCode("code"));
key.setFiscalCode("FC");
key.setAccountingDate(storeService.flyweightAccountingDate("2022-04-07"));
key.setOperationType((byte)0);

storeService.storeAggregate(key, Integer.MAX_VALUE - 1, "vat", "00");
storeService.storeAggregate(key, Integer.MAX_VALUE - 1, "vat", "00");

assertThat(storeService.getAggregate(key).getTotalAmount())
.isNotNegative()
.isEqualTo((Integer.MAX_VALUE - 1) * 2L);
}

@Test
public void whenSumOverflowLongThenThrowArithmeticException() {
AggregationKey key = new AggregationKey();
key.setTerminalId("1");
key.setMerchantId("1");
key.setAcquirerId(storeService.flyweightAcquirerId("1"));
key.setSenderCode(storeService.flyweightSenderCode("code"));
key.setFiscalCode("FC");
key.setAccountingDate(storeService.flyweightAccountingDate("2022-04-07"));
key.setOperationType((byte)0);

storeService.storeAggregate(key, Long.MAX_VALUE - 1, "vat", "00");

assertThatThrownBy(() -> storeService.storeAggregate(key, Integer.MAX_VALUE - 1, "vat", "00"))
.isInstanceOf(ArithmeticException.class);
}
}
4 changes: 2 additions & 2 deletions integration/jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<parent>
<artifactId>rtd-ms-transaction-filter-integration</artifactId>
<groupId>it.gov.pagopa.rtd.ms.transaction_filter</groupId>
<version>1.3.2</version>
<version>1.3.3</version>
</parent>

<groupId>it.gov.pagopa.rtd.ms.transaction_filter.integration</groupId>
<artifactId>rtd-ms-transaction-filter-integration-jpa</artifactId>
<version>1.3.2</version>
<version>1.3.3</version>

<dependencies>
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<parent>
<artifactId>rtd-ms-transaction-filter</artifactId>
<groupId>it.gov.pagopa.rtd.ms</groupId>
<version>1.3.2</version>
<version>1.3.3</version>
</parent>

<groupId>it.gov.pagopa.rtd.ms.transaction_filter</groupId>
<artifactId>rtd-ms-transaction-filter-integration</artifactId>
<version>1.3.2</version>
<version>1.3.3</version>

<packaging>pom</packaging>

Expand Down
4 changes: 2 additions & 2 deletions integration/rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<parent>
<groupId>it.gov.pagopa.rtd.ms.transaction_filter</groupId>
<artifactId>rtd-ms-transaction-filter-integration</artifactId>
<version>1.3.2</version>
<version>1.3.3</version>
</parent>

<groupId>it.gov.pagopa.rtd.ms.transaction_filter.integration</groupId>
<artifactId>rtd-ms-transaction-filter-integration-rest</artifactId>
<version>1.3.2</version>
<version>1.3.3</version>

<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void whenLogContainsSaltThenAnonymizeIt(CapturedOutput output) {
String stringWithSalt =
"[HpanRestConnector#getSalt] ---> GET https://api.dev.cstar.pagopa.it/rtd/payment-instrument-manager/v2/salt HTTP/1.1\n"
+ "[HpanRestConnector#getSalt] Ocp-Apim-Subscription-Key: ciao\n"
+ "[HpanRestConnector#getSalt] User-Agent: BatchService/1.3.2\n"
+ "[HpanRestConnector#getSalt] User-Agent: BatchService/1.3.3\n"
+ "[HpanRestConnector#getSalt] ---> END HTTP (0-byte body)\n"
+ "[HpanRestConnector#getSalt] <--- HTTP/1.1 200 OK (57ms)\n"
+ "[HpanRestConnector#getSalt] connection: keep-alive\n"
Expand Down
2 changes: 1 addition & 1 deletion ops_resources/example_config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ batchConfiguration:
rest-client:
user-agent:
prefix: BatchService
version: 1.3.2
version: 1.3.3
hpan:
serviceCode: hpan-service
base-url: ${HPAN_SERVICE_URL:https://bpd-dev.azure-api.net:${HPAN_SERVICE_PORT:443}}
Expand Down
2 changes: 1 addition & 1 deletion ops_resources/example_config/application_hbsql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ batchConfiguration:
rest-client:
user-agent:
prefix: BatchService
version: 1.3.2
version: 1.3.3
hpan:
serviceCode: hpan-service
base-url: ${HPAN_SERVICE_URL:https://bpd-dev.azure-api.net:${HPAN_SERVICE_PORT:443}}
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

<groupId>it.gov.pagopa.rtd.ms</groupId>
<artifactId>rtd-ms-transaction-filter</artifactId>
<version>1.3.2</version>
<version>1.3.3</version>

<packaging>pom</packaging>

<properties>
<java.version>1.8</java.version>
<spring-boot.version>2.7.4</spring-boot.version>
<postgresql.version>42.5.0</postgresql.version>
<postgresql.version>42.5.1</postgresql.version>
<springframework-cloud.version>3.1.4</springframework-cloud.version>
<snakeyaml.version>1.33</snakeyaml.version>
<common-io.version>2.11.0</common-io.version>
Expand All @@ -33,7 +33,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sonar.exclusions>**/enums/**,**/model/**,**/Constants*.java,**/*Config.java,**/*Application.java
</sonar.exclusions>
<transaction-filter.version>1.3.2</transaction-filter.version>
<transaction-filter.version>1.3.3</transaction-filter.version>
</properties>

<dependencyManagement>
Expand Down

0 comments on commit 70828f0

Please sign in to comment.