generated from pagopa/pagopa-functions-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PAGOPA-695] chore: move sources from debt-position
- Loading branch information
Showing
25 changed files
with
3,314 additions
and
93 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package it.gov.pagopa.reporting; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.microsoft.azure.functions.ExecutionContext; | ||
import com.microsoft.azure.functions.annotation.FunctionName; | ||
import com.microsoft.azure.functions.annotation.QueueTrigger; | ||
import com.sun.xml.ws.client.ClientTransportException; | ||
import it.gov.pagopa.reporting.models.OrganizationsMessage; | ||
import it.gov.pagopa.reporting.service.FlowsService; | ||
import it.gov.pagopa.reporting.service.NodoChiediElencoFlussi; | ||
import it.gov.pagopa.reporting.service.OrganizationsService; | ||
import it.gov.pagopa.reporting.servicewsdl.FaultBean; | ||
import it.gov.pagopa.reporting.servicewsdl.TipoElencoFlussiRendicontazione; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Arrays; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* Azure Functions with Azure Queue trigger. | ||
*/ | ||
public class RetrieveFlows { | ||
|
||
private final String storageConnectionString = System.getenv("FLOW_SA_CONNECTION_STRING"); | ||
private final String flowsTable = System.getenv("FLOWS_TABLE"); | ||
private final String flowsQueue = System.getenv("FLOWS_QUEUE"); | ||
private final String organizationsTable = System.getenv("ORGANIZATIONS_TABLE"); | ||
private final String organizationsQueue = System.getenv("ORGANIZATIONS_QUEUE"); | ||
private final String timeToLiveInSeconds = System.getenv("QUEUE_RETENTION_SEC"); | ||
private final String initialVisibilityDelayInSeconds = System.getenv("QUEUE_DELAY_SEC"); | ||
private final String maxRetryQueuing = System.getenv("MAX_RETRY_QUEUING"); | ||
|
||
/** | ||
* This function will be invoked when a new message is detected in the queue | ||
*/ | ||
@FunctionName("RetrieveFlows") | ||
public void run( | ||
@QueueTrigger(name = "RetrieveOrganizationsTrigger", queueName = "%ORGANIZATIONS_QUEUE%", connection = "FLOW_SA_CONNECTION_STRING") String message, | ||
final ExecutionContext context) { | ||
|
||
Logger logger = context.getLogger(); | ||
logger.log(Level.INFO, () -> String.format("[RetrieveOrganizationsTrigger START] processed the message: %s at %s", message, LocalDateTime.now())); | ||
|
||
NodoChiediElencoFlussi nodeClient = this.getNodeClientInstance(); | ||
FlowsService flowsService = this.getFlowsServiceInstance(logger); | ||
|
||
try { | ||
OrganizationsMessage organizationsMessage = new ObjectMapper().readValue(message, OrganizationsMessage.class); | ||
|
||
Arrays.stream(organizationsMessage.getIdPA()) | ||
.forEach((organization -> { | ||
try { | ||
// call NODO dei pagamenti | ||
nodeClient.nodoChiediElencoFlussiRendicontazione(organization); | ||
|
||
// retrieve result | ||
FaultBean faultBean = nodeClient.getNodoChiediElencoFlussiRendicontazioneFault(); | ||
|
||
TipoElencoFlussiRendicontazione elencoFlussi = nodeClient.getNodoChiediElencoFlussiRendicontazione(); | ||
|
||
if (faultBean != null) { | ||
logger.log(Level.WARNING, () -> "[RetrieveFlows] faultBean DESC " + faultBean.getDescription()); | ||
} else if (elencoFlussi != null) { | ||
logger.log(Level.INFO, () -> "[RetrieveFlows] elencoFlussi PA " + organization + " TotRestituiti " + elencoFlussi.getTotRestituiti()); | ||
flowsService.flowsProcessing(elencoFlussi.getIdRendicontazione(), organization); | ||
} | ||
} catch (ClientTransportException e) { | ||
logger.log(Level.SEVERE, () -> "[NODO Connection down] " + organization); | ||
int retry = organizationsMessage.getRetry(); | ||
if (retry < Integer.parseInt(maxRetryQueuing)) { | ||
OrganizationsService organizationsService = getOrganizationsServiceInstance(logger); | ||
organizationsService.retryToOrganizationsQueue(organization, retry + 1); | ||
} else { | ||
logger.log(Level.SEVERE, () -> "[NODO Connection down] Max retry exceeded."); | ||
} | ||
} | ||
|
||
})); | ||
} catch (JsonProcessingException e) { | ||
logger.log(Level.SEVERE, () -> "[RetrieveOrganizationsTrigger] Error " + e.getLocalizedMessage()); | ||
} | ||
|
||
} | ||
|
||
public NodoChiediElencoFlussi getNodeClientInstance() { | ||
return new NodoChiediElencoFlussi(); | ||
} | ||
|
||
public FlowsService getFlowsServiceInstance(Logger logger) { | ||
return new FlowsService(this.storageConnectionString, this.flowsTable, this.flowsQueue, logger); | ||
} | ||
|
||
public OrganizationsService getOrganizationsServiceInstance(Logger logger) { | ||
return new OrganizationsService(this.storageConnectionString, this.organizationsTable, this.organizationsQueue, Integer.parseInt(timeToLiveInSeconds), Integer.parseInt(initialVisibilityDelayInSeconds), logger); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/it/gov/pagopa/reporting/RetrieveOrganizations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package it.gov.pagopa.reporting; | ||
|
||
import com.microsoft.azure.functions.ExecutionContext; | ||
import com.microsoft.azure.functions.annotation.FunctionName; | ||
import com.microsoft.azure.functions.annotation.TimerTrigger; | ||
import it.gov.pagopa.reporting.service.OrganizationsService; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* Azure Functions with Timer trigger. | ||
*/ | ||
public class RetrieveOrganizations { | ||
|
||
private final String storageConnectionString = System.getenv("FLOW_SA_CONNECTION_STRING"); | ||
private final String organizationsTable = System.getenv("ORGANIZATIONS_TABLE"); | ||
private final String organizationsQueue = System.getenv("ORGANIZATIONS_QUEUE"); | ||
private final String timeToLiveInSeconds = System.getenv("QUEUE_RETENTION_SEC"); | ||
private final String initialVisibilityDelayInSeconds = System.getenv("QUEUE_DELAY_SEC"); | ||
|
||
/** | ||
* This function will be invoked periodically according to the specified | ||
* schedule. | ||
*/ | ||
// schedule = "*/5 * * * * *" | ||
|
||
@FunctionName("ReportingBatchFunction") | ||
public void run( | ||
@TimerTrigger(name = "ReportingBatchTrigger", schedule = "%NCRON_SCHEDULE_BATCH%") String timerInfo, | ||
final ExecutionContext context | ||
) { | ||
|
||
Logger logger = context.getLogger(); | ||
|
||
logger.log(Level.INFO, () -> "Reporting Batch Trigger function executed at: " + LocalDateTime.now()); | ||
|
||
// update organization list to flows table | ||
OrganizationsService organizationsService = this.getOrganizationsServiceInstance(logger); | ||
List<String> organizationListToProcess = organizationsService.getOrganizations(); | ||
|
||
// add to organizations queue | ||
organizationsService.addToOrganizationsQueue(organizationListToProcess); | ||
|
||
} | ||
|
||
public OrganizationsService getOrganizationsServiceInstance(Logger logger) { | ||
return new OrganizationsService(this.storageConnectionString, this.organizationsTable, this.organizationsQueue, Integer.parseInt(timeToLiveInSeconds), Integer.parseInt(initialVisibilityDelayInSeconds), logger); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/it/gov/pagopa/reporting/entity/FlowEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package it.gov.pagopa.reporting.entity; | ||
|
||
import com.microsoft.azure.storage.table.TableServiceEntity; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class FlowEntity extends TableServiceEntity { | ||
|
||
private String flowDate; | ||
|
||
public FlowEntity(String flowId, String flowDate, String idPA) { | ||
|
||
this.partitionKey = idPA; | ||
this.rowKey = flowId; | ||
this.flowDate = flowDate; | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/it/gov/pagopa/reporting/entity/OrganizationEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package it.gov.pagopa.reporting.entity; | ||
|
||
import com.microsoft.azure.storage.table.TableServiceEntity; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
public class OrganizationEntity extends TableServiceEntity { | ||
|
||
private String organizationOnboardingDate; | ||
public static final String ORGANIZATION_KEY = "organization"; | ||
|
||
public OrganizationEntity(String organizationId, String organizationOnboardingDate) { | ||
this.partitionKey = ORGANIZATION_KEY; | ||
this.rowKey = organizationId; | ||
this.organizationOnboardingDate = organizationOnboardingDate; | ||
} | ||
|
||
public OrganizationEntity(String organizationId) { | ||
this.partitionKey = ORGANIZATION_KEY; | ||
this.rowKey = organizationId; | ||
// https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.cosmos.table.tableentity.etag?view=azure-dotnet#microsoft-azure-cosmos-table-tableentity-etag | ||
this.etag = "*"; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/it/gov/pagopa/reporting/models/FlowsMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package it.gov.pagopa.reporting.models; | ||
|
||
import it.gov.pagopa.reporting.servicewsdl.TipoIdRendicontazione; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class FlowsMessage { | ||
|
||
private String idPA; | ||
private TipoIdRendicontazione[] flows; | ||
private Integer retry; | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/it/gov/pagopa/reporting/models/Organization.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package it.gov.pagopa.reporting.models; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class Organization { | ||
|
||
private String organizationFiscalCode; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/it/gov/pagopa/reporting/models/OrganizationsMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package it.gov.pagopa.reporting.models; | ||
|
||
import lombok.*; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
public class OrganizationsMessage { | ||
|
||
private String[] idPA; | ||
private Integer retry; | ||
} |
Oops, something went wrong.