diff --git a/build.gradle.kts b/build.gradle.kts index 1b85a03f..255f3d7f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,5 @@ +import org.springframework.boot.gradle.tasks.bundling.BootJar + plugins { java id("org.springframework.boot") version "3.3.5" @@ -40,6 +42,7 @@ val hibernateValidatorVersion = "8.0.1.Final" val commonsCompressVersion = "1.27.1" val commonsLang3Version = "3.17.0" val commonsTextVersion = "1.12.0" +val jacksonModuleVersion = "2.18.1" dependencies { @@ -48,7 +51,7 @@ dependencies { implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") implementation("org.hibernate.validator:hibernate-validator:$hibernateValidatorVersion") - // apache commons + //apache commons implementation("org.apache.commons:commons-compress:$commonsCompressVersion") implementation("org.apache.commons:commons-lang3:$commonsLang3Version") implementation("org.apache.commons:commons-text:$commonsTextVersion") @@ -56,6 +59,8 @@ dependencies { // Security fixes implementation("org.yaml:snakeyaml:$snakeYamlVersion") + implementation("com.fasterxml.jackson.module:jackson-module-parameter-names:$jacksonModuleVersion") + // Testing testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation("org.junit.jupiter:junit-jupiter-api") @@ -116,3 +121,12 @@ publishing { } } } + +tasks.withType { + enabled = true +} + +tasks.withType { + enabled = true +} + diff --git a/force-release b/force-release index 5325a8df..d7887218 100644 --- a/force-release +++ b/force-release @@ -1 +1 @@ -001 +003 diff --git a/src/main/java/it/gov/pagopa/payhub/activities/activity/PositionDebt.java b/src/main/java/it/gov/pagopa/payhub/activities/activity/PositionDebt.java deleted file mode 100644 index 71ad9b88..00000000 --- a/src/main/java/it/gov/pagopa/payhub/activities/activity/PositionDebt.java +++ /dev/null @@ -1,5 +0,0 @@ -package it.gov.pagopa.payhub.activities.activity; - -public class PositionDebt { - //TODO to be implemented with task https://pagopa.atlassian.net/browse/P4ADEV-1346 -} diff --git a/src/main/java/it/gov/pagopa/payhub/activities/activity/VerifyAuthorizationInstallments.java b/src/main/java/it/gov/pagopa/payhub/activities/activity/VerifyAuthorizationInstallments.java new file mode 100644 index 00000000..8dd23711 --- /dev/null +++ b/src/main/java/it/gov/pagopa/payhub/activities/activity/VerifyAuthorizationInstallments.java @@ -0,0 +1,30 @@ +package it.gov.pagopa.payhub.activities.activity; + +import it.gov.pagopa.payhub.activities.dao.OrganizationInstallmentTypeDao; +import it.gov.pagopa.payhub.activities.dto.InstallmentsOperatorDTO; +import it.gov.pagopa.payhub.activities.dto.OrganizationInstallmentTypeDTO; +import it.gov.pagopa.payhub.activities.exception.custom.ValidatorException; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class VerifyAuthorizationInstallments { + + private final OrganizationInstallmentTypeDao organizationInstallmentTypeDao; + + public VerifyAuthorizationInstallments(OrganizationInstallmentTypeDao organizationInstallmentTypeDao) { + this.organizationInstallmentTypeDao = organizationInstallmentTypeDao; + } + + public OrganizationInstallmentTypeDTO verifyAuth(InstallmentsOperatorDTO installmentsOperatorDTO, String username, Long mygovEnteId){ + + List organizationInstallmentTypeList = + organizationInstallmentTypeDao.getByMygovEnteIdAndOperatoreUsername(mygovEnteId, username); + + return organizationInstallmentTypeList.stream() + .filter(etd -> etd.getTypeCode().equals(installmentsOperatorDTO.getOrganizationTypeInstallment().getTypeCode())) + .findFirst() + .orElseThrow(() -> new ValidatorException("OrganizationInstallmentType is not active for this operator")); + } +} diff --git a/src/main/java/it/gov/pagopa/payhub/activities/config/JsonConfig.java b/src/main/java/it/gov/pagopa/payhub/activities/config/JsonConfig.java new file mode 100644 index 00000000..68924ade --- /dev/null +++ b/src/main/java/it/gov/pagopa/payhub/activities/config/JsonConfig.java @@ -0,0 +1,61 @@ +package it.gov.pagopa.payhub.activities.config; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.PropertyAccessor; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.databind.ser.std.DateSerializer; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer; +import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; +import com.fasterxml.jackson.module.paramnames.ParameterNamesModule; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Date; +import java.util.TimeZone; + +@Configuration +public class JsonConfig { + public static final String DATE_FORMAT = "yyyy/MM/dd"; + public static final String DATE_TIME_FORMAT = "yyyy/MM/dd-HH:mm:ss"; + + @Bean + public ObjectMapper objectMapper() { + ObjectMapper mapper = new ObjectMapper(); + mapper.registerModule(new JavaTimeModule()); + mapper.registerModule(new ParameterNamesModule(JsonCreator.Mode.DEFAULT)); + mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); + mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE); + mapper.setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.PUBLIC_ONLY); + mapper.setVisibility(PropertyAccessor.IS_GETTER, JsonAutoDetect.Visibility.PUBLIC_ONLY); + mapper.setVisibility(PropertyAccessor.SETTER, JsonAutoDetect.Visibility.PUBLIC_ONLY); + mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); + mapper.setVisibility(PropertyAccessor.CREATOR, JsonAutoDetect.Visibility.ANY); + mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + mapper.setTimeZone(TimeZone.getDefault()); + + SimpleModule module = new SimpleModule(); + module.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern(DATE_FORMAT))); + module.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT))); + module.addSerializer(Date.class, new DateSerializer(null, new SimpleDateFormat(DATE_TIME_FORMAT))); + + module.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern(DATE_FORMAT))); + module.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT))); + + mapper.registerModule(module); + return mapper; + } +} \ No newline at end of file diff --git a/src/main/java/it/gov/pagopa/payhub/activities/constants/Constants.java b/src/main/java/it/gov/pagopa/payhub/activities/constants/Constants.java new file mode 100644 index 00000000..23b1dcc0 --- /dev/null +++ b/src/main/java/it/gov/pagopa/payhub/activities/constants/Constants.java @@ -0,0 +1,8 @@ +package it.gov.pagopa.payhub.activities.constants; + +public class Constants { + private Constants() { + } + + public static final String TIPO_DOVUTO_MARCA_BOLLO_DIGITALE = "MARCA_BOLLO_DIGITALE"; +} diff --git a/src/main/java/it/gov/pagopa/payhub/activities/dao/OrganizationInstallmentTypeDao.java b/src/main/java/it/gov/pagopa/payhub/activities/dao/OrganizationInstallmentTypeDao.java new file mode 100644 index 00000000..37021557 --- /dev/null +++ b/src/main/java/it/gov/pagopa/payhub/activities/dao/OrganizationInstallmentTypeDao.java @@ -0,0 +1,10 @@ +package it.gov.pagopa.payhub.activities.dao; + +import it.gov.pagopa.payhub.activities.dto.OrganizationInstallmentTypeDTO; + +import java.util.List; + +public interface OrganizationInstallmentTypeDao { + + List getByMygovEnteIdAndOperatoreUsername(Long mygovEnteId, String operatoreUsername); +} diff --git a/src/main/java/it/gov/pagopa/payhub/activities/dto/InstallmentOperatorDTO.java b/src/main/java/it/gov/pagopa/payhub/activities/dto/InstallmentOperatorDTO.java index 52d37e99..f0cc0a2d 100644 --- a/src/main/java/it/gov/pagopa/payhub/activities/dto/InstallmentOperatorDTO.java +++ b/src/main/java/it/gov/pagopa/payhub/activities/dto/InstallmentOperatorDTO.java @@ -10,7 +10,7 @@ import java.time.LocalDateTime; @Data -@Builder +@Builder(toBuilder = true) @NoArgsConstructor @AllArgsConstructor public class InstallmentOperatorDTO implements Serializable { @@ -45,7 +45,7 @@ public class InstallmentOperatorDTO implements Serializable { private boolean flagGenerateIuv; private String iuf; - //datails elaborated installment + //details elaborated installment private LocalDateTime transactionStartDate; private String transactionId; private String holder; @@ -61,7 +61,7 @@ public class InstallmentOperatorDTO implements Serializable { private InstallmentPrimaryOrganizationDTO installmentPrimaryOrgDetail; private ElaboratedInstallmentPrimaryOrganizationDTO elaboratedInstallmentPrimaryOrgDetail; - //multibeneficiary detail + //multi beneficiary detail private MultiBeneficiaryInstallmentDTO multiBeneficiaryInstallmentDetail; private ElaboratedMultiBeneficiaryInstallmentDTO elaboratedMultiBeneficiaryInstallmentDetail; diff --git a/src/main/java/it/gov/pagopa/payhub/activities/dto/InstallmentPrimaryOrganizationDTO.java b/src/main/java/it/gov/pagopa/payhub/activities/dto/InstallmentPrimaryOrganizationDTO.java index c1d34712..1e9d1e28 100644 --- a/src/main/java/it/gov/pagopa/payhub/activities/dto/InstallmentPrimaryOrganizationDTO.java +++ b/src/main/java/it/gov/pagopa/payhub/activities/dto/InstallmentPrimaryOrganizationDTO.java @@ -6,11 +6,13 @@ import lombok.Data; import lombok.NoArgsConstructor; +import java.io.Serializable; + @Data -@Builder +@Builder(toBuilder = true) @NoArgsConstructor @AllArgsConstructor -public class InstallmentPrimaryOrganizationDTO { +public class InstallmentPrimaryOrganizationDTO implements Serializable { private String beneficiaryName; private String uniqueIdentificationCode; diff --git a/src/main/java/it/gov/pagopa/payhub/activities/dto/NationDTO.java b/src/main/java/it/gov/pagopa/payhub/activities/dto/NationDTO.java index c03aa4ba..5ac1fae7 100644 --- a/src/main/java/it/gov/pagopa/payhub/activities/dto/NationDTO.java +++ b/src/main/java/it/gov/pagopa/payhub/activities/dto/NationDTO.java @@ -13,11 +13,12 @@ @NoArgsConstructor @AllArgsConstructor public class NationDTO implements Serializable { + private Long nationId; private String nationName; private String codeIsoAlpha2; - public boolean hasProvince(){ + public boolean hasProvince(){ return StringUtils.equalsIgnoreCase(codeIsoAlpha2, "it"); - } + } } \ No newline at end of file diff --git a/src/main/java/it/gov/pagopa/payhub/activities/dto/OrganizationInstallmentTypeDTO.java b/src/main/java/it/gov/pagopa/payhub/activities/dto/OrganizationInstallmentTypeDTO.java index b30e46ec..1224f950 100644 --- a/src/main/java/it/gov/pagopa/payhub/activities/dto/OrganizationInstallmentTypeDTO.java +++ b/src/main/java/it/gov/pagopa/payhub/activities/dto/OrganizationInstallmentTypeDTO.java @@ -14,7 +14,6 @@ @AllArgsConstructor public class OrganizationInstallmentTypeDTO implements Serializable { - private Long installmentTypeId; private OrganizationDTO orgId; private String typeCode; diff --git a/src/main/java/it/gov/pagopa/payhub/activities/exception/ActivitiesException.java b/src/main/java/it/gov/pagopa/payhub/activities/exception/ActivitiesException.java index 99d94a6d..da1da819 100644 --- a/src/main/java/it/gov/pagopa/payhub/activities/exception/ActivitiesException.java +++ b/src/main/java/it/gov/pagopa/payhub/activities/exception/ActivitiesException.java @@ -5,16 +5,4 @@ public class ActivitiesException extends RuntimeException { public ActivitiesException(String message) { super(message); } - - public ActivitiesException(String message, Throwable cause) { - super(message, cause); - } - - public ActivitiesException(Throwable cause) { - super(cause); - } - - public ActivitiesException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { - super(message, cause, enableSuppression, writableStackTrace); - } -} \ No newline at end of file +} diff --git a/src/main/java/it/gov/pagopa/payhub/activities/exception/custom/ValidatorException.java b/src/main/java/it/gov/pagopa/payhub/activities/exception/custom/ValidatorException.java new file mode 100644 index 00000000..fe903920 --- /dev/null +++ b/src/main/java/it/gov/pagopa/payhub/activities/exception/custom/ValidatorException.java @@ -0,0 +1,11 @@ +package it.gov.pagopa.payhub.activities.exception.custom; + +import it.gov.pagopa.payhub.activities.exception.ActivitiesException; + + +public class ValidatorException extends ActivitiesException { + + public ValidatorException(String message) { + super(message); + } +} diff --git a/src/test/java/it/gov/pagopa/payhub/activities/activity/VerifyAuthorizationInstallmentsTest.java b/src/test/java/it/gov/pagopa/payhub/activities/activity/VerifyAuthorizationInstallmentsTest.java new file mode 100644 index 00000000..71e8f46e --- /dev/null +++ b/src/test/java/it/gov/pagopa/payhub/activities/activity/VerifyAuthorizationInstallmentsTest.java @@ -0,0 +1,70 @@ +package it.gov.pagopa.payhub.activities.activity; + +import it.gov.pagopa.payhub.activities.dao.OrganizationInstallmentTypeDao; +import it.gov.pagopa.payhub.activities.dto.InstallmentsOperatorDTO; +import it.gov.pagopa.payhub.activities.dto.OrganizationInstallmentTypeDTO; +import it.gov.pagopa.payhub.activities.dto.OrganizationTypeInstallmentDTO; +import it.gov.pagopa.payhub.activities.exception.custom.ValidatorException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class VerifyAuthorizationInstallmentsTest { + + @Mock + private OrganizationInstallmentTypeDao organizationInstallmentTypeDao; + + private VerifyAuthorizationInstallments verifyAuthorizationInstallments; + + @BeforeEach + void init() { + verifyAuthorizationInstallments = new VerifyAuthorizationInstallments(organizationInstallmentTypeDao); + } + + @Test + void givenVerifyAuthThenSuccess() { + String username = "username"; + Long mygovEnteId = 1L; + InstallmentsOperatorDTO installmentsOperatorDTO = new InstallmentsOperatorDTO(); + OrganizationTypeInstallmentDTO organizationTypeInstallmentDTO = new OrganizationTypeInstallmentDTO(); + + installmentsOperatorDTO.setOrganizationTypeInstallment(organizationTypeInstallmentDTO); + organizationTypeInstallmentDTO.setTypeCode("TYPE_CODE"); + + OrganizationInstallmentTypeDTO organizationInstallmentTypeDTO = new OrganizationInstallmentTypeDTO(); + organizationInstallmentTypeDTO.setTypeCode("TYPE_CODE"); + + when(organizationInstallmentTypeDao.getByMygovEnteIdAndOperatoreUsername(mygovEnteId, username)) + .thenReturn(List.of(organizationInstallmentTypeDTO)); + + OrganizationInstallmentTypeDTO result = verifyAuthorizationInstallments.verifyAuth(installmentsOperatorDTO, username, mygovEnteId); + + assertEquals(organizationInstallmentTypeDTO, result); + } + + @Test + void givenVerifyAuthWhenNotEqualTypeCodeThenThrowValidatorException() { + String username = "username"; + Long mygovEnteId = 1L; + InstallmentsOperatorDTO installmentsOperatorDTO = new InstallmentsOperatorDTO(); + + OrganizationInstallmentTypeDTO organizationInstallmentTypeDTO = new OrganizationInstallmentTypeDTO(); + organizationInstallmentTypeDTO.setTypeCode("TYPE_CODE"); + + when(organizationInstallmentTypeDao.getByMygovEnteIdAndOperatoreUsername(mygovEnteId, username)) + .thenReturn(List.of()); + + assertThrows(ValidatorException.class, () -> + verifyAuthorizationInstallments.verifyAuth(installmentsOperatorDTO, username, mygovEnteId)); + } +} +