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.
feat: P4ADEV-1653 wf ingestion flow file worker dao for saving data (#4)
Co-authored-by: antonioT90 <34568575+antonioT90@users.noreply.github.com>
- Loading branch information
1 parent
7a02bf5
commit e510fd1
Showing
9 changed files
with
318 additions
and
2 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
33 changes: 33 additions & 0 deletions
33
src/main/java/it/gov/pagopa/pu/worker/ingestionflowfile/IngestionFlowFileDaoImpl.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,33 @@ | ||
package it.gov.pagopa.pu.worker.ingestionflowfile; | ||
|
||
import it.gov.pagopa.payhub.activities.dao.IngestionFlowFileDao; | ||
import it.gov.pagopa.payhub.activities.dto.IngestionFlowFileDTO; | ||
import it.gov.pagopa.pu.worker.ingestionflowfile.mapper.IngestionFlowFileMapper; | ||
import it.gov.pagopa.pu.worker.ingestionflowfile.model.IngestionFlowFile; | ||
import it.gov.pagopa.pu.worker.ingestionflowfile.repository.IngestionFlowFileRepository; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Optional; | ||
|
||
@Service | ||
public class IngestionFlowFileDaoImpl implements IngestionFlowFileDao { | ||
private final IngestionFlowFileRepository repository; | ||
private final IngestionFlowFileMapper ingestionFlowFileMapper; | ||
|
||
public IngestionFlowFileDaoImpl(IngestionFlowFileRepository repository, | ||
IngestionFlowFileMapper ingestionFlowFileMapper) { | ||
this.repository = repository; | ||
this.ingestionFlowFileMapper = ingestionFlowFileMapper; | ||
} | ||
|
||
@Override | ||
public Optional<IngestionFlowFileDTO> findById(Long ingestionFlowFileId) { | ||
Optional<IngestionFlowFile> ingestionFlowFile = repository.findById(ingestionFlowFileId); | ||
return ingestionFlowFile.map(ingestionFlowFileMapper::mapIngestionFlowFile2DTO); | ||
} | ||
|
||
@Override | ||
public boolean updateStatus(Long ingestionFlowFileId, String status) { | ||
return false; //TODO: implementation will be added with the task n. P4ADEV-1638 | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/main/java/it/gov/pagopa/pu/worker/ingestionflowfile/mapper/IngestionFlowFileMapper.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,68 @@ | ||
package it.gov.pagopa.pu.worker.ingestionflowfile.mapper; | ||
|
||
import it.gov.pagopa.payhub.activities.dto.IngestionFlowFileDTO; | ||
import it.gov.pagopa.payhub.activities.dto.OrganizationDTO; | ||
import it.gov.pagopa.payhub.activities.enums.IngestionFlowFileType; | ||
import it.gov.pagopa.pu.worker.ingestionflowfile.model.IngestionFlowFile; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Date; | ||
|
||
@Component | ||
public class IngestionFlowFileMapper { | ||
|
||
public IngestionFlowFile mapIngestionFlowFileDTO2Model(IngestionFlowFileDTO dto) { | ||
return IngestionFlowFile.builder() | ||
.ingestionFlowFileId(dto.getIngestionFlowFileId()) | ||
.flowFileType(dto.getFlowFileType().name()) | ||
.version(dto.getVersion()) | ||
.org(dto.getOrg().getOrgId()) | ||
.status(dto.getStatus()) | ||
.iuf(dto.getIuf()) | ||
.numTotalRows(dto.getNumTotalRows().intValue()) | ||
.numCorrectlyImportedRows(dto.getNumCorrectlyImportedRows().intValue()) | ||
.creationDate(dto.getCreationDate().toInstant()) | ||
.lastUpdateDate(dto.getLastUpdateDate().toInstant()) | ||
.flagActive(dto.isFlagActive()) | ||
.operatorName(dto.getOperatorName()) | ||
.flagSpontaneous(dto.getFlagSpontaneous()) | ||
.filePathName(dto.getFilePath()) | ||
.fileName(dto.getFileName()) | ||
.pdfGenerated(dto.getPdfGenerated().intValue()) | ||
.codRequestToken(dto.getCodRequestToken()) | ||
.codError(dto.getCodError()) | ||
.pspIdentifier(dto.getPspIdentifier()) | ||
.flowDateTime(dto.getFlowDateTime()) | ||
.fileSourceCode(dto.getFileSourceCode()) | ||
.discardFileName(dto.getDiscardFileName()) | ||
.build(); | ||
} | ||
|
||
public IngestionFlowFileDTO mapIngestionFlowFile2DTO(IngestionFlowFile model) { | ||
return IngestionFlowFileDTO.builder() | ||
.ingestionFlowFileId(model.getIngestionFlowFileId()) | ||
.flowFileType(IngestionFlowFileType.valueOf(model.getFlowFileType())) | ||
.version(model.getVersion()) | ||
.org(OrganizationDTO.builder().orgId(model.getOrg()).build()) | ||
.status(model.getStatus()) | ||
.iuf(model.getIuf()) | ||
.numTotalRows(Long.valueOf(model.getNumTotalRows())) | ||
.numCorrectlyImportedRows(Long.valueOf(model.getNumCorrectlyImportedRows())) | ||
.creationDate(Date.from(model.getCreationDate())) | ||
.lastUpdateDate(Date.from(model.getLastUpdateDate())) | ||
.flagActive(model.isFlagActive()) | ||
.operatorName(model.getOperatorName()) | ||
.flagSpontaneous(model.isFlagSpontaneous()) | ||
.filePath(model.getFilePathName()) | ||
.fileName(model.getFileName()) | ||
.pdfGenerated(Long.valueOf(model.getPdfGenerated())) | ||
.codRequestToken(model.getCodRequestToken()) | ||
.codError(model.getCodError()) | ||
.pspIdentifier(model.getPspIdentifier()) | ||
.flowDateTime(model.getFlowDateTime()) | ||
.fileSourceCode(model.getFileSourceCode()) | ||
.discardFileName(model.getDiscardFileName()) | ||
.build(); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/it/gov/pagopa/pu/worker/ingestionflowfile/model/IngestionFlowFile.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,47 @@ | ||
package it.gov.pagopa.pu.worker.ingestionflowfile.model; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.io.Serializable; | ||
import java.time.Instant; | ||
import java.time.LocalDateTime; | ||
|
||
@Data | ||
@Entity | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Table(name = "ingestion_flow_file") | ||
public class IngestionFlowFile implements Serializable { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ingestion_flow_file_generator") | ||
@SequenceGenerator(name = "ingestion_flow_file_generator", sequenceName = "ingestion_flow_file_seq", allocationSize = 1) | ||
private Long ingestionFlowFileId; | ||
private String flowFileType; | ||
private int version; | ||
private Long org; | ||
private String status; | ||
private String iuf; | ||
private int numTotalRows; | ||
private int numCorrectlyImportedRows; | ||
private Instant creationDate; | ||
private Instant lastUpdateDate; | ||
private boolean flagActive; | ||
private String operatorName; | ||
private boolean flagSpontaneous; | ||
private String filePathName; | ||
private String fileName; | ||
private int pdfGenerated; | ||
private String codRequestToken; | ||
private String codError; | ||
private String pspIdentifier; | ||
private LocalDateTime flowDateTime; | ||
private String state; | ||
private String fileSourceCode; | ||
private String discardFileName; | ||
} |
9 changes: 9 additions & 0 deletions
9
...ava/it/gov/pagopa/pu/worker/ingestionflowfile/repository/IngestionFlowFileRepository.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,9 @@ | ||
package it.gov.pagopa.pu.worker.ingestionflowfile.repository; | ||
|
||
import it.gov.pagopa.pu.worker.ingestionflowfile.model.IngestionFlowFile; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface IngestionFlowFileRepository extends JpaRepository<IngestionFlowFile, Long> { | ||
} |
53 changes: 53 additions & 0 deletions
53
src/test/java/it/gov/pagopa/pu/worker/ingestionflowfile/IngestionFlowFileDaoImplTest.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.pu.worker.ingestionflowfile; | ||
|
||
import it.gov.pagopa.payhub.activities.dto.IngestionFlowFileDTO; | ||
import it.gov.pagopa.pu.worker.ingestionflowfile.mapper.IngestionFlowFileMapper; | ||
import it.gov.pagopa.pu.worker.ingestionflowfile.model.IngestionFlowFile; | ||
import it.gov.pagopa.pu.worker.ingestionflowfile.repository.IngestionFlowFileRepository; | ||
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.Optional; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class IngestionFlowFileDaoImplTest { | ||
|
||
@Mock | ||
private IngestionFlowFileRepository repositoryMock; | ||
@Mock | ||
private IngestionFlowFileMapper mapperMock; | ||
|
||
private IngestionFlowFileDaoImpl service; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
service = new IngestionFlowFileDaoImpl(repositoryMock, mapperMock); | ||
} | ||
|
||
@Test | ||
void testFindById() { | ||
// Arrange | ||
Long id = 123L; | ||
IngestionFlowFile ingestionFlowFile = IngestionFlowFile.builder() | ||
.ingestionFlowFileId(id) | ||
.build(); | ||
|
||
IngestionFlowFileDTO expectedDTO = IngestionFlowFileDTO.builder() | ||
.ingestionFlowFileId(id).build(); | ||
|
||
when(mapperMock.mapIngestionFlowFile2DTO(ingestionFlowFile)).thenReturn(expectedDTO); | ||
when(repositoryMock.findById(id)).thenReturn(Optional.of(ingestionFlowFile)); | ||
|
||
// Act | ||
Optional<IngestionFlowFileDTO> result = service.findById(id); | ||
|
||
// Assert | ||
assertEquals(Optional.of(expectedDTO), result); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...st/java/it/gov/pagopa/pu/worker/ingestionflowfile/mapper/IngestionFlowFileMapperTest.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,35 @@ | ||
package it.gov.pagopa.pu.worker.ingestionflowfile.mapper; | ||
|
||
import it.gov.pagopa.payhub.activities.dto.IngestionFlowFileDTO; | ||
import it.gov.pagopa.pu.worker.ingestionflowfile.model.IngestionFlowFile; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static it.gov.pagopa.pu.worker.util.TestUtils.checkNotNullFields; | ||
import static it.gov.pagopa.pu.worker.util.faker.IngestionFlowFileFakerBuilder.buildFakeIngestionFlowFile; | ||
import static it.gov.pagopa.pu.worker.util.faker.IngestionFlowFileFakerBuilder.buildFakeIngestionFlowFileDTO; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
class IngestionFlowFileMapperTest { | ||
private IngestionFlowFileMapper mapper; | ||
|
||
@BeforeEach | ||
void setUp() { mapper = new IngestionFlowFileMapper(); } | ||
|
||
@Test | ||
void mapIngestionFlowFile2DTO() { | ||
IngestionFlowFile model = buildFakeIngestionFlowFile(); | ||
IngestionFlowFileDTO result = mapper.mapIngestionFlowFile2DTO(model); | ||
|
||
assertNotNull(result); | ||
checkNotNullFields(result); | ||
} | ||
|
||
@Test | ||
void mapIngestionFlowFileDTO2Model() { | ||
IngestionFlowFileDTO dto = buildFakeIngestionFlowFileDTO(); | ||
IngestionFlowFile result = mapper.mapIngestionFlowFileDTO2Model(dto); | ||
assertNotNull(result); | ||
checkNotNullFields(result, "state"); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/test/java/it/gov/pagopa/pu/worker/util/faker/IngestionFlowFileFakerBuilder.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,71 @@ | ||
package it.gov.pagopa.pu.worker.util.faker; | ||
|
||
import it.gov.pagopa.payhub.activities.dto.IngestionFlowFileDTO; | ||
import it.gov.pagopa.payhub.activities.dto.OrganizationDTO; | ||
import it.gov.pagopa.payhub.activities.enums.IngestionFlowFileType; | ||
import it.gov.pagopa.pu.worker.ingestionflowfile.model.IngestionFlowFile; | ||
|
||
|
||
import java.time.Instant; | ||
import java.time.LocalDateTime; | ||
import java.util.Date; | ||
|
||
public class IngestionFlowFileFakerBuilder { | ||
|
||
// Static builder for IngestionFlowFile entity | ||
public static IngestionFlowFile buildFakeIngestionFlowFile() { | ||
return IngestionFlowFile.builder() | ||
.ingestionFlowFileId(1L) | ||
.flowFileType(IngestionFlowFileType.PAYMENTS_REPORTING.name()) | ||
.version(1) | ||
.org(1001L) | ||
.status("ACTIVE") | ||
.iuf("IUF12345") | ||
.numTotalRows(100) | ||
.numCorrectlyImportedRows(95) | ||
.creationDate(Instant.now()) | ||
.lastUpdateDate(Instant.now()) | ||
.flagActive(true) | ||
.operatorName("Operator Name") | ||
.flagSpontaneous(false) | ||
.filePathName("/path/to/file") | ||
.fileName("example_file.csv") | ||
.pdfGenerated(5) | ||
.codRequestToken("REQ123TOKEN") | ||
.codError("NO_ERROR") | ||
.pspIdentifier("PSP001") | ||
.flowDateTime(LocalDateTime.now()) | ||
.state("VALID") | ||
.fileSourceCode("SRC001") | ||
.discardFileName("discarded_file.csv") | ||
.build(); | ||
} | ||
|
||
// Static builder for IngestionFlowFileDTO | ||
public static IngestionFlowFileDTO buildFakeIngestionFlowFileDTO() { | ||
return IngestionFlowFileDTO.builder() | ||
.ingestionFlowFileId(1L) | ||
.flowFileType(IngestionFlowFileType.PAYMENTS_REPORTING) | ||
.version(1) | ||
.org(OrganizationDTO.builder().orgId(123L).build()) | ||
.status("ACTIVE") | ||
.iuf("IUF12345") | ||
.numTotalRows(100L) | ||
.numCorrectlyImportedRows(95L) | ||
.creationDate(new Date()) | ||
.lastUpdateDate(new Date()) | ||
.flagActive(true) | ||
.operatorName("Operator Name") | ||
.flagSpontaneous(false) | ||
.filePath("/path/to/file") | ||
.fileName("example_file.csv") | ||
.pdfGenerated(5L) | ||
.codRequestToken("REQ123TOKEN") | ||
.codError("NO_ERROR") | ||
.pspIdentifier("PSP001") | ||
.flowDateTime(LocalDateTime.now()) | ||
.fileSourceCode("SRC001") | ||
.discardFileName("discarded_file.csv") | ||
.build(); | ||
} | ||
} |