diff --git a/.gitignore b/.gitignore
index ef3ed48..605977d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,4 +2,5 @@ target/**/*
.vscode
/.idea/
emulatorcert.crt
-.env
\ No newline at end of file
+*.env
+**/*paDemandPaymentNoticeRequest.xml
\ No newline at end of file
diff --git a/README.md b/README.md
index 1e90fa7..a6ec5b3 100644
--- a/README.md
+++ b/README.md
@@ -91,7 +91,7 @@ The easiest way to develop locally is start only db container and run spring-boo
...
```
-### Configure Cosmos emulator
+### Configure Cosmos emulator
Launch the script in `utilities` folder:
@@ -126,4 +126,4 @@ Todo
Made with ❤️ from PagoPa S.p.A.
### Mainteiners
-See `CODEOWNERS` file
+See `CODEOWNERS` file
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index d153a4e..b72a822 100644
--- a/pom.xml
+++ b/pom.xml
@@ -58,6 +58,10 @@
spring-cloud-starter-openfeign
${openfeign-version}
+
+ org.springframework
+ spring-context
+
org.aspectj
aspectjweaver
diff --git a/src/main/java/it/gov/pagopa/spontaneouspayment/SpontaneousPaymentApplication.java b/src/main/java/it/gov/pagopa/spontaneouspayment/SpontaneousPaymentApplication.java
index 38cb9b4..42b0daf 100644
--- a/src/main/java/it/gov/pagopa/spontaneouspayment/SpontaneousPaymentApplication.java
+++ b/src/main/java/it/gov/pagopa/spontaneouspayment/SpontaneousPaymentApplication.java
@@ -1,24 +1,28 @@
package it.gov.pagopa.spontaneouspayment;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.DependsOn;
+
import com.azure.spring.data.cosmos.core.mapping.EnableCosmosAuditing;
import com.azure.spring.data.cosmos.repository.config.EnableCosmosRepositories;
+
import it.gov.pagopa.spontaneouspayment.entity.CreditInstitution;
import it.gov.pagopa.spontaneouspayment.entity.Service;
import it.gov.pagopa.spontaneouspayment.entity.ServiceProperty;
import it.gov.pagopa.spontaneouspayment.entity.ServiceRef;
import it.gov.pagopa.spontaneouspayment.repository.CIRepository;
import it.gov.pagopa.spontaneouspayment.repository.ServiceRepository;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.CommandLineRunner;
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-
-import java.util.ArrayList;
-import java.util.List;
@SpringBootApplication
@EnableCosmosRepositories("it.gov.pagopa.spontaneouspayment.repository")
@EnableCosmosAuditing
+@DependsOn("expressionResolver")
public class SpontaneousPaymentApplication implements CommandLineRunner {
@Autowired
@@ -33,7 +37,7 @@ public static void main(String[] args) {
public void run(String... var1) {
CreditInstitution ci = new CreditInstitution();
- ci.setOrganizationFiscalCode("organizationTest");
+ ci.setFiscalCode("organizationTest");
ci.setCompanyName("Comune di Roma");
ci.setStatus("ATTIVO");
diff --git a/src/main/java/it/gov/pagopa/spontaneouspayment/config/AppConfiguration.java b/src/main/java/it/gov/pagopa/spontaneouspayment/config/AppConfiguration.java
index 9fb72f9..d1dcac5 100644
--- a/src/main/java/it/gov/pagopa/spontaneouspayment/config/AppConfiguration.java
+++ b/src/main/java/it/gov/pagopa/spontaneouspayment/config/AppConfiguration.java
@@ -1,5 +1,10 @@
package it.gov.pagopa.spontaneouspayment.config;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.lang.Nullable;
import com.azure.core.credential.AzureKeyCredential;
import com.azure.cosmos.CosmosClientBuilder;
import com.azure.cosmos.DirectConnectionConfig;
@@ -10,10 +15,6 @@
import com.azure.spring.data.cosmos.core.ResponseDiagnosticsProcessor;
import com.azure.spring.data.cosmos.repository.config.EnableCosmosRepositories;
import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.lang.Nullable;
@Configuration
@EnableCosmosRepositories
@@ -27,20 +28,15 @@ public class AppConfiguration extends AbstractCosmosConfiguration {
@Value("${azure.cosmos.key}")
private String key;
- @Value("${azure.cosmos.secondary-key}")
- private String secondaryKey;
-
@Value("${azure.cosmos.database}")
private String dbName;
@Value("${azure.cosmos.populate-query-metrics}")
private boolean queryMetricsEnabled;
- private AzureKeyCredential azureKeyCredential;
-
@Bean
public CosmosClientBuilder getCosmosClientBuilder() {
- this.azureKeyCredential = new AzureKeyCredential(key);
+ AzureKeyCredential azureKeyCredential = new AzureKeyCredential(key);
DirectConnectionConfig directConnectionConfig = new DirectConnectionConfig();
GatewayConnectionConfig gatewayConnectionConfig = new GatewayConnectionConfig();
return new CosmosClientBuilder()
@@ -57,10 +53,6 @@ public CosmosConfig cosmosConfig() {
.build();
}
- public void switchToSecondaryKey() {
- this.azureKeyCredential.update(secondaryKey);
- }
-
@Override
protected String getDatabaseName() {
return dbName;
diff --git a/src/main/java/it/gov/pagopa/spontaneouspayment/config/EntityValidator.java b/src/main/java/it/gov/pagopa/spontaneouspayment/config/EntityValidator.java
index f6f7065..ce8c618 100644
--- a/src/main/java/it/gov/pagopa/spontaneouspayment/config/EntityValidator.java
+++ b/src/main/java/it/gov/pagopa/spontaneouspayment/config/EntityValidator.java
@@ -28,7 +28,7 @@ public class EntityValidator {
* @param joinPoint not used
* @param result the response to validate
*/
- @AfterReturning(pointcut = "execution(* it.gov.pagopa.spontaneouspayment.repository.*.*(..))", returning = "result")
+ @AfterReturning(pointcut = "execution(* it.gov.pagopa.spontaneouspayment.repository.impl.*.*(..))", returning = "result")
public void validateResponse(JoinPoint joinPoint, Object result) {
if (result instanceof ResponseEntity) {
validateResponse((ResponseEntity>) result);
diff --git a/src/main/java/it/gov/pagopa/spontaneouspayment/controller/impl/PaymentsController.java b/src/main/java/it/gov/pagopa/spontaneouspayment/controller/impl/PaymentsController.java
index 950c02a..d5924ee 100644
--- a/src/main/java/it/gov/pagopa/spontaneouspayment/controller/impl/PaymentsController.java
+++ b/src/main/java/it/gov/pagopa/spontaneouspayment/controller/impl/PaymentsController.java
@@ -1,17 +1,16 @@
package it.gov.pagopa.spontaneouspayment.controller.impl;
-import it.gov.pagopa.spontaneouspayment.controller.IPaymentsController;
-import it.gov.pagopa.spontaneouspayment.model.SpontaneousPaymentModel;
-import it.gov.pagopa.spontaneouspayment.model.response.PaymentPositionModel;
-import it.gov.pagopa.spontaneouspayment.service.PaymentsService;
-import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
+import it.gov.pagopa.spontaneouspayment.controller.IPaymentsController;
+import it.gov.pagopa.spontaneouspayment.model.SpontaneousPaymentModel;
+import it.gov.pagopa.spontaneouspayment.model.response.PaymentPositionModel;
+import it.gov.pagopa.spontaneouspayment.service.PaymentsService;
+
@Controller
-@Slf4j
public class PaymentsController implements IPaymentsController {
@Autowired
diff --git a/src/main/java/it/gov/pagopa/spontaneouspayment/entity/CreditInstitution.java b/src/main/java/it/gov/pagopa/spontaneouspayment/entity/CreditInstitution.java
index f49cdac..1732015 100644
--- a/src/main/java/it/gov/pagopa/spontaneouspayment/entity/CreditInstitution.java
+++ b/src/main/java/it/gov/pagopa/spontaneouspayment/entity/CreditInstitution.java
@@ -1,6 +1,8 @@
package it.gov.pagopa.spontaneouspayment.entity;
import com.azure.spring.data.cosmos.core.mapping.Container;
+import com.azure.spring.data.cosmos.core.mapping.PartitionKey;
+
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
@@ -14,20 +16,17 @@
import java.time.LocalDateTime;
import java.util.List;
-@Container(containerName = "credit_institution", ru = "400")
+@Container(containerName = "${azure.cosmos.ec-container-name}", autoCreateContainer = false)
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class CreditInstitution {
- //@Id
- //@GeneratedValue
- //private String id;
@Id
- //@PartitionKey
- private String organizationFiscalCode;
+ @PartitionKey
+ private String fiscalCode;
@NotBlank(message = "company name is required")
private String companyName;
diff --git a/src/main/java/it/gov/pagopa/spontaneouspayment/entity/Service.java b/src/main/java/it/gov/pagopa/spontaneouspayment/entity/Service.java
index 2798ab3..1cf5160 100644
--- a/src/main/java/it/gov/pagopa/spontaneouspayment/entity/Service.java
+++ b/src/main/java/it/gov/pagopa/spontaneouspayment/entity/Service.java
@@ -1,6 +1,8 @@
package it.gov.pagopa.spontaneouspayment.entity;
import com.azure.spring.data.cosmos.core.mapping.Container;
+import com.azure.spring.data.cosmos.core.mapping.PartitionKey;
+
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
@@ -13,7 +15,7 @@
import java.time.LocalDateTime;
import java.util.List;
-@Container(containerName = "services", ru = "400")
+@Container(containerName = "${azure.cosmos.service-container-name}", autoCreateContainer = false)
@Getter
@Setter
@NoArgsConstructor
@@ -28,6 +30,7 @@ public class Service {
private String description;
@NotBlank(message = "transfer category is required")
+ @PartitionKey
private String transferCategory; // tassonomia
@NotBlank(message = "remittance information is required")
diff --git a/src/main/java/it/gov/pagopa/spontaneouspayment/repository/CIRepository.java b/src/main/java/it/gov/pagopa/spontaneouspayment/repository/CIRepository.java
index d1b57e5..b9cafa4 100644
--- a/src/main/java/it/gov/pagopa/spontaneouspayment/repository/CIRepository.java
+++ b/src/main/java/it/gov/pagopa/spontaneouspayment/repository/CIRepository.java
@@ -12,9 +12,9 @@
@Repository
public interface CIRepository extends CosmosRepository {
- @Query("select TOP 1 * from c where c.organizationFiscalCode = @organizationFiscalCode and EXISTS (SELECT VALUE t FROM t IN c.services WHERE t.id = @serviceId)")
+ @Query("select TOP 1 * from c where c.fiscalCode = @organizationFiscalCode and EXISTS (SELECT VALUE t FROM t IN c.services WHERE t.id = @serviceId)")
List getCreditInstitutionByOrgFiscCodeAndServiceId(@Param("organizationFiscalCode") String organizationFiscalCode, @Param("serviceId") String serviceId);
- Optional findByOrganizationFiscalCode(String organizationFiscalCode);
+ Optional findByFiscalCode(String organizationFiscalCode);
}
diff --git a/src/main/java/it/gov/pagopa/spontaneouspayment/service/PaymentsService.java b/src/main/java/it/gov/pagopa/spontaneouspayment/service/PaymentsService.java
index 7fab5dd..eadb39f 100644
--- a/src/main/java/it/gov/pagopa/spontaneouspayment/service/PaymentsService.java
+++ b/src/main/java/it/gov/pagopa/spontaneouspayment/service/PaymentsService.java
@@ -88,7 +88,7 @@ private it.gov.pagopa.spontaneouspayment.entity.Service getServiceDetails(@NotNu
}
private CreditInstitution getCreditorInstitution(String organizationFiscalCode) {
- return ciRepository.findByOrganizationFiscalCode(organizationFiscalCode)
+ return ciRepository.findByFiscalCode(organizationFiscalCode)
.orElseThrow(() -> new AppException(AppError.ORGANIZATION_SERVICE_NOT_FOUND, organizationFiscalCode));
}
diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties
index 429ee24..e38850a 100644
--- a/src/main/resources/application-local.properties
+++ b/src/main/resources/application-local.properties
@@ -4,10 +4,12 @@ properties.environment=local
# Cosmos account config
azure.cosmos.uri=https://localhost:8081
azure.cosmos.key=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==
-azure.cosmos.database=gps
-azure.cosmos.secondary-key=
+azure.cosmos.database=db
azure.cosmos.populate-query-metrics=false
+azure.cosmos.ec-container-name=creditor_institutions
+azure.cosmos.service-container-name=services
+
service.gpd.host=http://localhost:8085
# timeout
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 050a941..9ea3526 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -1,3 +1,7 @@
+#cors
+#spring_cors_origin=*
+server.port=9090
+
# info
application.name=@project.artifactId@
application.version=@project.version@
@@ -8,9 +12,11 @@ properties.environment=azure
azure.cosmos.uri=${COSMOS_URI}
azure.cosmos.key=${COSMOS_KEY}
azure.cosmos.database=${COSMOS_DATABASE}
-azure.cosmos.secondary-key=${COSMOS_SECONDARY_KEY}
azure.cosmos.populate-query-metrics=${COSMOS_QUERY_METRICS}
+azure.cosmos.ec-container-name=${EC_CONTAINER_NAME}
+azure.cosmos.service-container-name=${SERVICE_CONTAINER_NAME}
+
service.gpd.host=${GPD_HOST}
# timeout
@@ -26,4 +32,9 @@ logging.level.root=${LOGGING_LEVEL}
logging.level.it.gov.pagopa.spontaneouspayment=${LOGGING_LEVEL}
-
+#jpa:
+# spring.jpa.hibernate.ddl-auto=validate
+# spring.jpa.show-sql=false
+# spring.jpa.open-in-view=false
+spring.devtools.add-properties=true
+spring.profiles.active=@spring.profiles.active@
diff --git a/utilities/cosmos.sh b/utilities/cosmos.sh
new file mode 100755
index 0000000..d880568
--- /dev/null
+++ b/utilities/cosmos.sh
@@ -0,0 +1,81 @@
+#!/bin/bash
+
+# set -e
+
+# force delete image and container of MS AZ Cosmos DB Emulator
+docker container rm -f test-linux-emulator
+# force delete image and container of MS AZ Cosmos DB Emulator
+docker image rm -f mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest
+
+PORT=$1
+JVM_HOME=$2
+
+# Main ...
+if [ -z "$PORT" ]
+then
+ PORT=8081
+ echo "CosmosDB starting on DEFAULT port $PORT"
+else
+ echo "CosmosDB starting on specific port $PORT"
+fi
+
+if [ -z "$JVM_HOME" ]
+then
+ JVM_HOME=$JAVA_HOME
+ echo "Using DEFAULT JAVA_HOME $JVM_HOME"
+else
+ echo "Using custom JAVA_HOME $JVM_HOME"
+fi
+
+
+# Azure Cosmos DB Emulator
+URL="https://localhost:$PORT/_explorer/index.html"
+
+ipaddr=$(ifconfig | grep "inet " | grep -Fv 127.0.0.1 | awk '{print $2}' | head -n 1)
+echo "Using ${ipaddr} for CosmosDB configuration..."
+
+docker pull mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator
+
+docker run \
+ --detach \
+ --publish $PORT:8081 \
+ --publish 10251-10254:10251-10254 \
+ --memory 3g --cpus=2.0 \
+ --name=test-linux-emulator \
+ --env AZURE_COSMOS_EMULATOR_PARTITION_COUNT=10 \
+ --env AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE=true \
+ --env AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE=$ipaddr \
+ --interactive \
+ --tty \
+ mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator
+
+echo -n "CosmosDB starting..."
+cosmos_started="`docker logs test-linux-emulator | grep -wc Started`"
+echo -n $cosmos_started
+# check cosmos is UP
+while [ "$cosmos_started" != "12" ]
+do
+ sleep 3
+ echo -n "."
+ cosmos_started=`docker logs test-linux-emulator | grep -wc Started`
+ echo -n $cosmos_started
+done
+
+echo "!!! STARTED !!!"
+
+echo "Setting certificate..."
+
+curl -k "https://${ipaddr}:${PORT}/_explorer/emulator.pem" > emulatorcert.crt
+
+# add keychain accesss
+sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain emulatorcert.crt
+
+# add jvm trust-store
+keystore_alias="cosmoskeystore"
+echo "Remember, the keystore passowrd is: changeit"
+sudo keytool -delete -alias $keystore_alias -keystore "${JAVA_HOME}/lib/security/cacerts"
+sudo keytool -trustcacerts -keystore "${JAVA_HOME}/lib/security/cacerts" -storepass changeit -importcert -alias $keystore_alias -file emulatorcert.crt
+
+echo "Setting certificate...done."
+
+open $URL