generated from pagopa/template-payments-java-repository
-
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.
Merge remote-tracking branch 'origin/P4ADEV-1346-create-activity-veri…
…fy-authorization' into P4ADEV-1347-validation-activity # Conflicts: # build.gradle.kts # src/main/java/it/gov/pagopa/payhub/activities/dto/NationDTO.java # src/main/java/it/gov/pagopa/payhub/activities/exception/ActivitiesException.java
- Loading branch information
Showing
14 changed files
with
217 additions
and
28 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
001 | ||
003 |
5 changes: 0 additions & 5 deletions
5
src/main/java/it/gov/pagopa/payhub/activities/activity/PositionDebt.java
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
src/main/java/it/gov/pagopa/payhub/activities/activity/VerifyAuthorizationInstallments.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,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<OrganizationInstallmentTypeDTO> 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")); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/it/gov/pagopa/payhub/activities/config/JsonConfig.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,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; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/it/gov/pagopa/payhub/activities/constants/Constants.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,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"; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/it/gov/pagopa/payhub/activities/dao/OrganizationInstallmentTypeDao.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,10 @@ | ||
package it.gov.pagopa.payhub.activities.dao; | ||
|
||
import it.gov.pagopa.payhub.activities.dto.OrganizationInstallmentTypeDTO; | ||
|
||
import java.util.List; | ||
|
||
public interface OrganizationInstallmentTypeDao { | ||
|
||
List<OrganizationInstallmentTypeDTO> getByMygovEnteIdAndOperatoreUsername(Long mygovEnteId, String operatoreUsername); | ||
} |
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
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
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
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
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
11 changes: 11 additions & 0 deletions
11
src/main/java/it/gov/pagopa/payhub/activities/exception/custom/ValidatorException.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,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); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...st/java/it/gov/pagopa/payhub/activities/activity/VerifyAuthorizationInstallmentsTest.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,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)); | ||
} | ||
} | ||
|