Skip to content

Commit

Permalink
Merge pull request #46 from pagopa/PAGOPA-960-sviluppo-migrazione-dat…
Browse files Browse the repository at this point in the history
…i-storage-to-cosmos-e-applicazione-in-uat-e-prod

Pagopa 960 sviluppo migrazione dati storage to cosmos e applicazione in uat e prod
  • Loading branch information
pasqualespica authored Jun 22, 2023
2 parents 17ce5a5 + 700cf4f commit 8545121
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .devops/deploy-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ variables:
dockerRegistryServiceConnection: $(UAT_CONTAINER_REGISTRY_SERVICE_CONN)
dockerRegistryFqdn: $(UAT_CONTAINER_NAMESPACE)
kubernetesServiceConnection: '$(UAT_KUBERNETES_SERVICE_CONN)'
poolImage: 'pagopa-uat-loadtest-linux'
poolImage: 'pagopa-uat-linux'
appInsightsServiceConn: "$(TF_APPINSIGHTS_SERVICE_CONN_UAT)"
appInsightsResourceId: "$(TF_APPINSIGHTS_RESOURCE_ID_UAT)"
apiConfigSubscriptionKey: '$(UAT_API_CONFIG_SUBSCRIPTION_KEY)'
Expand Down
4 changes: 2 additions & 2 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apiVersion: v1
name: pagopa-gpd-payments
description: Microservice that exposes API for payment receipts retrieving and other operations
type: application
version: 0.3.4
appVersion: 0.3.4
version: 0.5.0
appVersion: 0.3.4-2-PAGOPA-960-sviluppo-migrazione-dati-storage-to-cosmos-e-applicazione-in-uat-e-prod
dependencies:
- name: microservice-chart
version: 1.21.0
Expand Down
4 changes: 2 additions & 2 deletions helm/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-gpd-payments
tag: "0.3.4"
tag: "0.3.4-2-PAGOPA-960-sviluppo-migrazione-dati-storage-to-cosmos-e-applicazione-in-uat-e-prod"
pullPolicy: Always
livenessProbe:
httpGet:
Expand Down Expand Up @@ -109,7 +109,7 @@ microservice-chart:
create: true
image:
repository: ghcr.io/pagopa/pagopa-gpd-payments
tag: "0.3.4"
tag: "0.3.4-2-PAGOPA-960-sviluppo-migrazione-dati-storage-to-cosmos-e-applicazione-in-uat-e-prod"
pullPolicy: Always
envConfig: {}
envSecret: {}
6 changes: 3 additions & 3 deletions helm/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-gpd-payments
tag: "0.3.4"
tag: "0.3.4-2-PAGOPA-960-sviluppo-migrazione-dati-storage-to-cosmos-e-applicazione-in-uat-e-prod"
pullPolicy: Always
livenessProbe:
httpGet:
Expand Down Expand Up @@ -69,7 +69,7 @@ microservice-chart:
LOGGING_LEVEL: "INFO"
CACHE_SIZE: "1000"
CACHE_EXPIRATION_TIME: "1d"
AZURE_TABLES_TABLENAME: "pagopapagopa-p-weu-gpsweugpdpaymentsreceiptstable"
AZURE_TABLES_TABLENAME: "gpdpaymentsreceiptstable"
API_CONFIG_HOST: "https://api.platform.pagopa.it/apiconfig/auth/api/v1"
GPS_HOST: "https://api.platform.pagopa.it/gps/spontaneous-payments-service/v1"
GPD_HOST: "https://api.platform.pagopa.it/gpd/api/v1"
Expand Down Expand Up @@ -109,7 +109,7 @@ microservice-chart:
create: true
image:
repository: ghcr.io/pagopa/pagopa-gpd-payments
tag: "0.3.4"
tag: "0.3.4-2-PAGOPA-960-sviluppo-migrazione-dati-storage-to-cosmos-e-applicazione-in-uat-e-prod"
pullPolicy: Always
envConfig: {}
envSecret: {}
6 changes: 3 additions & 3 deletions helm/values-uat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-gpd-payments
tag: "0.3.4"
tag: "0.3.4-2-PAGOPA-960-sviluppo-migrazione-dati-storage-to-cosmos-e-applicazione-in-uat-e-prod"
pullPolicy: Always
livenessProbe:
httpGet:
Expand Down Expand Up @@ -69,7 +69,7 @@ microservice-chart:
LOGGING_LEVEL: "INFO"
CACHE_SIZE: "1000"
CACHE_EXPIRATION_TIME: "1s"
AZURE_TABLES_TABLENAME: "pagopapagopa-u-weu-gpsweugpdpaymentsreceiptstable"
AZURE_TABLES_TABLENAME: "gpdpaymentsreceiptstable"
API_CONFIG_HOST: "https://api.uat.platform.pagopa.it/apiconfig/auth/api/v1"
GPS_HOST: "https://api.uat.platform.pagopa.it/gps/spontaneous-payments-service/v1"
GPD_HOST: "https://api.uat.platform.pagopa.it/gpd/api/v1"
Expand Down Expand Up @@ -109,7 +109,7 @@ microservice-chart:
create: true
image:
repository: ghcr.io/pagopa/pagopa-gpd-payments
tag: "0.3.4"
tag: "0.3.4-2-PAGOPA-960-sviluppo-migrazione-dati-storage-to-cosmos-e-applicazione-in-uat-e-prod"
pullPolicy: Always
envConfig: {}
envSecret: {}
2 changes: 1 addition & 1 deletion openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"title": "PagoPA API Payments",
"description": "Payments",
"termsOfService": "https://www.pagopa.gov.it/",
"version": "0.3.4"
"version": "0.3.4-2-PAGOPA-960-sviluppo-migrazione-dati-storage-to-cosmos-e-applicazione-in-uat-e-prod"
},
"servers": [
{
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<groupId>it.gov.pagopa</groupId>
<artifactId>payments</artifactId>
<version>0.3.4</version>
<version>0.3.4-2-PAGOPA-960-sviluppo-migrazione-dati-storage-to-cosmos-e-applicazione-in-uat-e-prod</version>
<name>Payments</name>
<description>Payments</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.validation.constraints.Positive;
import javax.validation.constraints.PositiveOrZero;

@Tag(name = "Payments receipts API")
@RequestMapping
@Validated
Expand Down Expand Up @@ -117,8 +120,11 @@ ResponseEntity<ReceiptsInfo> getOrganizationReceipts(
required = true)
@PathVariable("organizationfiscalcode")
String organizationFiscalCode,
@Parameter(description = "Page number") @RequestParam(required = true) @PositiveOrZero int pageNum,
@Parameter(description = "Number of elements per page") @RequestParam(required = true) @Positive int pageSize,
@Parameter(description = "Filter by debtor") @RequestParam(required = false) String debtor,
@Parameter(description = "Filter by service") @RequestParam(required = false) String service,
@Parameter(description = "Filter by date, from this date") @RequestParam(required = false) String from,
@Parameter(description = "Filter by date, to this date") @RequestParam(required = false) String to);

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@
import it.gov.pagopa.payments.model.ReceiptModelResponse;
import it.gov.pagopa.payments.model.ReceiptsInfo;
import it.gov.pagopa.payments.service.PaymentsService;
import it.gov.pagopa.payments.utils.CommonUtil;

import java.util.stream.Collectors;
import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Positive;

import lombok.extern.slf4j.Slf4j;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -48,11 +45,13 @@ public ResponseEntity<String> getReceiptByIUV(String organizationFiscalCode, Str

@Override
public ResponseEntity<ReceiptsInfo> getOrganizationReceipts(
String organizationFiscalCode,
String debtor,
String service,
String from,
String to) {
String organizationFiscalCode,
int pageNum,
int pageSize,
String debtor,
String service,
String from,
String to) {
log.info(
String.format(
LOG_BASE_HEADER_INFO,
Expand All @@ -64,7 +63,7 @@ public ResponseEntity<ReceiptsInfo> getOrganizationReceipts(
+ "; service= "
+ service));
PaymentsResult<ReceiptEntity> receipts =
paymentsService.getOrganizationReceipts(organizationFiscalCode, debtor, service, from, to);
paymentsService.getOrganizationReceipts(organizationFiscalCode, debtor, service, from, to, pageNum, pageSize);
return new ResponseEntity<>(
ReceiptsInfo.builder()
.receiptsList(
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/it/gov/pagopa/payments/exception/AppError.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public enum AppError {
"Receipt conflict",
"The receipt inserted already exists"),

NOT_ENOUGH_ELEMENTS(
HttpStatus.INTERNAL_SERVER_ERROR,
"Not enough elements",
"The page number is too big for the filtered elements"),

UNKNOWN(null, null, null);

public final HttpStatus httpStatus;
Expand Down
43 changes: 33 additions & 10 deletions src/main/java/it/gov/pagopa/payments/service/PaymentsService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package it.gov.pagopa.payments.service;

import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.PagedResponse;
import com.azure.data.tables.TableClient;
import com.azure.data.tables.models.ListEntitiesOptions;
import com.azure.data.tables.models.TableEntity;
Expand All @@ -19,9 +21,9 @@
import org.springframework.stereotype.Service;

import javax.validation.constraints.NotBlank;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

@Service
@Slf4j
Expand All @@ -43,11 +45,13 @@ public PaymentsResult<ReceiptEntity> getOrganizationReceipts(
String debtor,
String service,
String from,
String to) {
String to,
int pageNum,
int pageSize) {
try {

List<ReceiptEntity> filteredEntities = retrieveEntitiesByFilter(tableClient,
organizationFiscalCode, debtor, service, from, to);
organizationFiscalCode, debtor, service, from, to, pageNum, pageSize);
return this.setReceiptsOutput(getGPDCheckedReceiptsList(filteredEntities, tableClient));

}
Expand Down Expand Up @@ -121,7 +125,8 @@ public List<ReceiptEntity> getGPDCheckedReceiptsList(List<ReceiptEntity> result,
}

public List<ReceiptEntity> retrieveEntitiesByFilter(TableClient tableClient, String organizationFiscalCode,
String debtor, String service, String from, String to) {
String debtor, String service, String from,
String to, int pageNum, int pageSize) {

List<String> filters = new ArrayList<>();

Expand All @@ -138,11 +143,29 @@ public List<ReceiptEntity> retrieveEntitiesByFilter(TableClient tableClient, Str
if(null != from && null != to){
filters.add(String.format("paymentDate ge '%s' and paymentDate le '%s'", from, to));
}
return tableClient.listEntities(new ListEntitiesOptions()
.setFilter(String.join(" and ", filters)), null, null)
.stream()
.map(ConvertTableEntityToReceiptEntity::mapTableEntityToReceiptEntity)
.collect(Collectors.toList());

Iterator<PagedResponse<TableEntity>> filteredIterator = tableClient
.listEntities(
new ListEntitiesOptions()
.setTop(pageSize)
.setFilter(String.join(" and ", filters)
), null, null)
.iterableByPage()
.iterator();

for(int i = 0; i < pageNum - 1; i++){
if(!filteredIterator.hasNext()){
throw new AppException(AppError.NOT_ENOUGH_ELEMENTS);
} else {
filteredIterator.next();
}
}

if(!filteredIterator.hasNext()) {
throw new AppException(AppError.NOT_ENOUGH_ELEMENTS);
}

return filteredIterator.next().getValue().stream().map(ConvertTableEntityToReceiptEntity::mapTableEntityToReceiptEntity).collect(Collectors.toList());
}

private static void getStartsWithFilter(List<String> filters, String startsWith) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ void getOrganizationReceipts_200() throws Exception {
PaymentsResult<ReceiptEntity> receipts = new PaymentsResult<ReceiptEntity>();
receipts.setResults(new ArrayList<ReceiptEntity>());
when(paymentsService.getOrganizationReceipts(
anyString(), anyString(), anyString(), anyString(), anyString()))
anyString(), anyString(), anyString(), anyString(), anyString(), anyInt(), anyInt()))
.thenReturn(receipts);

ResponseEntity<ReceiptsInfo> res =
paymentsController.getOrganizationReceipts(
anyString(), anyString(), anyString(), anyString(), anyString());
anyString(), anyInt(), anyInt(), anyString(), anyString(), anyString(), anyString());
assertEquals(HttpStatus.OK, res.getStatusCode());
}

Expand All @@ -102,10 +102,10 @@ void getOrganizationReceipts_404() throws Exception {
// precondition
doThrow(new AppException(AppError.RECEIPTS_NOT_FOUND, "111", 0))
.when(paymentsService)
.getOrganizationReceipts(anyString(), anyString(), anyString(), anyString(), anyString());
.getOrganizationReceipts(anyString(), anyString(), anyString(), anyString(), anyString(), anyInt(), anyInt());
try {
paymentsController.getOrganizationReceipts(
anyString(), anyString(), anyString(), anyString(), anyString());
anyString(), anyInt(), anyInt(), anyString(), anyString(), anyString(), anyString());
} catch (AppException e) {
assertEquals(HttpStatus.NOT_FOUND, e.getHttpStatus());
}
Expand Down
Loading

0 comments on commit 8545121

Please sign in to comment.