From 82589c8dc0b68ff3e23833106b015e8a770a456c Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Tue, 7 Dec 2021 19:12:52 +0100 Subject: [PATCH] Added EPAS Children support --- ...Cient.java => EPASAffiliationsClient.java} | 2 +- .../epas/client/EPASChildrenClient.java | 103 ++++++ ...ctsCient.java => EPASContractsClient.java} | 2 +- ...GroupsCient.java => EPASGroupsClient.java} | 2 +- ...LeavesCient.java => EPASLeavesClient.java} | 2 +- ...rsonsCient.java => EPASPersonsClient.java} | 2 +- .../epasmed/epas/dto/EPASChildrenDTO.java | 22 ++ .../epas/mapper/EPASChildrenMapper.java | 40 +++ .../isti/epasmed/epas/model/EPASChildren.java | 25 ++ .../epas/service/EPASAffiliationsService.java | 4 +- .../epas/service/EPASChildrenService.java | 50 +++ .../epas/service/EPASContractsService.java | 4 +- .../epas/service/EPASGroupsService.java | 4 +- .../epas/service/EPASLeavesService.java | 4 +- .../epas/service/EPASPersonsService.java | 4 +- .../repository/SIMasterLogRepository.java | 7 +- .../service/SIMasterLogService.java | 2 +- .../epasmed/web/rest/AccountResource.java | 48 ++- .../web/rest/epas/EPASChildrenResource.java | 178 +++++++++++ .../web/rest/epas/EPASTimeCardsResource.java | 3 +- .../SIMasterLogResource.java | 6 +- .../web/rest/epas/EPASChildrenResourceIT.java | 301 ++++++++++++++++++ .../web/rest/epas/EPASPersonsResourceIT.java | 4 +- .../SIMasterLogResourceIT.java | 51 +++ .../web/rest/{ => sync}/SyncResourceIT.java | 3 +- .../isti/epasmed/web/rest/epas/figliISTI.csv | 113 +++++++ .../epas/{personale.csv => personaleISTI.csv} | 0 27 files changed, 941 insertions(+), 45 deletions(-) rename src/main/java/it/cnr/isti/epasmed/epas/client/{EPASAffiliationsCient.java => EPASAffiliationsClient.java} (99%) create mode 100644 src/main/java/it/cnr/isti/epasmed/epas/client/EPASChildrenClient.java rename src/main/java/it/cnr/isti/epasmed/epas/client/{EPASContractsCient.java => EPASContractsClient.java} (99%) rename src/main/java/it/cnr/isti/epasmed/epas/client/{EPASGroupsCient.java => EPASGroupsClient.java} (98%) rename src/main/java/it/cnr/isti/epasmed/epas/client/{EPASLeavesCient.java => EPASLeavesClient.java} (99%) rename src/main/java/it/cnr/isti/epasmed/epas/client/{EPASPersonsCient.java => EPASPersonsClient.java} (99%) create mode 100644 src/main/java/it/cnr/isti/epasmed/epas/dto/EPASChildrenDTO.java create mode 100644 src/main/java/it/cnr/isti/epasmed/epas/mapper/EPASChildrenMapper.java create mode 100644 src/main/java/it/cnr/isti/epasmed/epas/model/EPASChildren.java create mode 100644 src/main/java/it/cnr/isti/epasmed/epas/service/EPASChildrenService.java create mode 100644 src/main/java/it/cnr/isti/epasmed/web/rest/epas/EPASChildrenResource.java create mode 100644 src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASChildrenResourceIT.java create mode 100644 src/test/java/it/cnr/isti/epasmed/web/rest/sistemainformativo/SIMasterLogResourceIT.java rename src/test/java/it/cnr/isti/epasmed/web/rest/{ => sync}/SyncResourceIT.java (95%) create mode 100644 src/test/resources/it/cnr/isti/epasmed/web/rest/epas/figliISTI.csv rename src/test/resources/it/cnr/isti/epasmed/web/rest/epas/{personale.csv => personaleISTI.csv} (100%) diff --git a/src/main/java/it/cnr/isti/epasmed/epas/client/EPASAffiliationsCient.java b/src/main/java/it/cnr/isti/epasmed/epas/client/EPASAffiliationsClient.java similarity index 99% rename from src/main/java/it/cnr/isti/epasmed/epas/client/EPASAffiliationsCient.java rename to src/main/java/it/cnr/isti/epasmed/epas/client/EPASAffiliationsClient.java index 3b601b0..fef3b4a 100644 --- a/src/main/java/it/cnr/isti/epasmed/epas/client/EPASAffiliationsCient.java +++ b/src/main/java/it/cnr/isti/epasmed/epas/client/EPASAffiliationsClient.java @@ -21,7 +21,7 @@ import it.cnr.isti.epasmed.epas.dto.EPASAffiliationsDTO; import it.cnr.isti.epasmed.epas.model.EPASAffiliations; @Component -public class EPASAffiliationsCient { +public class EPASAffiliationsClient { private final Logger log = LoggerFactory.getLogger(getClass()); diff --git a/src/main/java/it/cnr/isti/epasmed/epas/client/EPASChildrenClient.java b/src/main/java/it/cnr/isti/epasmed/epas/client/EPASChildrenClient.java new file mode 100644 index 0000000..7e5733d --- /dev/null +++ b/src/main/java/it/cnr/isti/epasmed/epas/client/EPASChildrenClient.java @@ -0,0 +1,103 @@ +package it.cnr.isti.epasmed.epas.client; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.validation.Valid; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + +import it.cnr.isti.epasmed.config.ApplicationProperties; +import it.cnr.isti.epasmed.epas.dto.EPASChildrenDTO; +import it.cnr.isti.epasmed.epas.model.EPASChildren; + +@Component +public class EPASChildrenClient { + + private final Logger log = LoggerFactory.getLogger(getClass()); + + @Autowired + @Qualifier("RestTemplateForFirstUser") + RestTemplate rt; + + @Autowired + ApplicationProperties appProps; + + public EPASChildren getById(String id) { + EPASChildren epasChildren = rt.getForObject( + appProps.getDatasourceEpasRest().getRestUrl() + "/v2/child/show?id={id}", EPASChildren.class, id); + log.info("Retrieved Child: {}", epasChildren); + return epasChildren; + } + + public List getByPersonId(String id) { + ResponseEntity> responseEntity = rt.exchange( + appProps.getDatasourceEpasRest().getRestUrl() + "/v2/child/byPerson?id={id}", HttpMethod.GET, null, + new ParameterizedTypeReference>() { + }, id); + List listEPASChildren = responseEntity.getBody(); + log.info("Retrieved Children: {}", listEPASChildren); + return listEPASChildren; + + } + + public List getByPersonFiscalCode(String fc) { + ResponseEntity> responseEntity = rt.exchange( + appProps.getDatasourceEpasRest().getRestUrl() + "/v2/child/byPerson?fiscalCode={fc}", HttpMethod.GET, + null, new ParameterizedTypeReference>() { + }, fc); + List listEPASChildren = responseEntity.getBody(); + log.info("Retrieved Children: {}", listEPASChildren); + return listEPASChildren; + + } + + public List getByPersonEmail(String email) { + ResponseEntity> responseEntity = rt.exchange( + appProps.getDatasourceEpasRest().getRestUrl() + "/v2/child/byPerson?fiscalCode={email}", HttpMethod.GET, + null, new ParameterizedTypeReference>() { + }, email); + List listEPASChildren = responseEntity.getBody(); + log.info("Retrieved Children: {}", listEPASChildren); + return listEPASChildren; + + } + + public EPASChildren create(EPASChildrenDTO epasChildrenDTO) { + ResponseEntity response = rt.postForEntity( + appProps.getDatasourceEpasRest().getRestUrl() + "/v2/child/create", epasChildrenDTO, + EPASChildren.class); + + EPASChildren createdEPASChildren = response.getBody(); + + log.info("Created Child: {}", createdEPASChildren); + return createdEPASChildren; + } + + public void updateById(String id, @Valid EPASChildrenDTO epasChildrenDTO) { + Map uriVariables = new HashMap<>(); + uriVariables.put("id", id); + + rt.put(appProps.getDatasourceEpasRest().getRestUrl() + "/v2/child/update?id={id}", epasChildrenDTO, + uriVariables); + + log.info("Updated Child: {}", id); + return; + } + + public void deleteById(String id) { + rt.delete(appProps.getDatasourceEpasRest().getRestUrl() + "/v2/child/delete?id={id}", id); + log.info("Deleted Child with id: {}", id); + return; + } + +} diff --git a/src/main/java/it/cnr/isti/epasmed/epas/client/EPASContractsCient.java b/src/main/java/it/cnr/isti/epasmed/epas/client/EPASContractsClient.java similarity index 99% rename from src/main/java/it/cnr/isti/epasmed/epas/client/EPASContractsCient.java rename to src/main/java/it/cnr/isti/epasmed/epas/client/EPASContractsClient.java index 27d6ff0..f0e4946 100644 --- a/src/main/java/it/cnr/isti/epasmed/epas/client/EPASContractsCient.java +++ b/src/main/java/it/cnr/isti/epasmed/epas/client/EPASContractsClient.java @@ -21,7 +21,7 @@ import it.cnr.isti.epasmed.epas.dto.EPASContractsDTO; import it.cnr.isti.epasmed.epas.model.EPASContracts; @Component -public class EPASContractsCient { +public class EPASContractsClient { private final Logger log = LoggerFactory.getLogger(getClass()); diff --git a/src/main/java/it/cnr/isti/epasmed/epas/client/EPASGroupsCient.java b/src/main/java/it/cnr/isti/epasmed/epas/client/EPASGroupsClient.java similarity index 98% rename from src/main/java/it/cnr/isti/epasmed/epas/client/EPASGroupsCient.java rename to src/main/java/it/cnr/isti/epasmed/epas/client/EPASGroupsClient.java index d9ee272..dacd09f 100644 --- a/src/main/java/it/cnr/isti/epasmed/epas/client/EPASGroupsCient.java +++ b/src/main/java/it/cnr/isti/epasmed/epas/client/EPASGroupsClient.java @@ -21,7 +21,7 @@ import it.cnr.isti.epasmed.epas.dto.EPASGroupsDTO; import it.cnr.isti.epasmed.epas.model.EPASGroups; @Component -public class EPASGroupsCient { +public class EPASGroupsClient { private final Logger log = LoggerFactory.getLogger(getClass()); diff --git a/src/main/java/it/cnr/isti/epasmed/epas/client/EPASLeavesCient.java b/src/main/java/it/cnr/isti/epasmed/epas/client/EPASLeavesClient.java similarity index 99% rename from src/main/java/it/cnr/isti/epasmed/epas/client/EPASLeavesCient.java rename to src/main/java/it/cnr/isti/epasmed/epas/client/EPASLeavesClient.java index 5b6757a..f91b9ec 100644 --- a/src/main/java/it/cnr/isti/epasmed/epas/client/EPASLeavesCient.java +++ b/src/main/java/it/cnr/isti/epasmed/epas/client/EPASLeavesClient.java @@ -18,7 +18,7 @@ import it.cnr.isti.epasmed.config.ApplicationProperties; import it.cnr.isti.epasmed.epas.model.EPASLeaves; @Component -public class EPASLeavesCient { +public class EPASLeavesClient { private final Logger log = LoggerFactory.getLogger(getClass()); diff --git a/src/main/java/it/cnr/isti/epasmed/epas/client/EPASPersonsCient.java b/src/main/java/it/cnr/isti/epasmed/epas/client/EPASPersonsClient.java similarity index 99% rename from src/main/java/it/cnr/isti/epasmed/epas/client/EPASPersonsCient.java rename to src/main/java/it/cnr/isti/epasmed/epas/client/EPASPersonsClient.java index 92ae3e3..3f98f3b 100644 --- a/src/main/java/it/cnr/isti/epasmed/epas/client/EPASPersonsCient.java +++ b/src/main/java/it/cnr/isti/epasmed/epas/client/EPASPersonsClient.java @@ -21,7 +21,7 @@ import it.cnr.isti.epasmed.epas.dto.EPASPersonsDTO; import it.cnr.isti.epasmed.epas.model.EPASPersons; @Component -public class EPASPersonsCient { +public class EPASPersonsClient { private final Logger log = LoggerFactory.getLogger(getClass()); diff --git a/src/main/java/it/cnr/isti/epasmed/epas/dto/EPASChildrenDTO.java b/src/main/java/it/cnr/isti/epasmed/epas/dto/EPASChildrenDTO.java new file mode 100644 index 0000000..8a48496 --- /dev/null +++ b/src/main/java/it/cnr/isti/epasmed/epas/dto/EPASChildrenDTO.java @@ -0,0 +1,22 @@ +package it.cnr.isti.epasmed.epas.dto; + +import java.io.Serializable; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class EPASChildrenDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + private String name; + private String surname; + private String fiscalCode; + private String bornDate; + private String externalId; + private String personId; +} \ No newline at end of file diff --git a/src/main/java/it/cnr/isti/epasmed/epas/mapper/EPASChildrenMapper.java b/src/main/java/it/cnr/isti/epasmed/epas/mapper/EPASChildrenMapper.java new file mode 100644 index 0000000..05eeac7 --- /dev/null +++ b/src/main/java/it/cnr/isti/epasmed/epas/mapper/EPASChildrenMapper.java @@ -0,0 +1,40 @@ +package it.cnr.isti.epasmed.epas.mapper; + +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +import org.springframework.stereotype.Service; + +import it.cnr.isti.epasmed.epas.dto.EPASChildrenDTO; +import it.cnr.isti.epasmed.epas.model.EPASChildren; + +/** + * Mapper for the entity {@link EPASChildren} and its DTO called + * {@link EPASChildrenDTO}. + * + * Normal mappers are generated using MapStruct, this one is hand-coded as + * MapStruct support is still in beta, and requires a manual step with an IDE. + */ +@Service +public class EPASChildrenMapper { + + public List epasChildrenToEPASChildrenDTOs(List epasChildrenList) { + return epasChildrenList.stream().filter(Objects::nonNull).map(this::epasChildrenToEPASChildrenDTO) + .collect(Collectors.toList()); + } + + public EPASChildrenDTO epasChildrenToEPASChildrenDTO(EPASChildren epasChildren) { + if (epasChildren == null) { + return null; + } else { + EPASChildrenDTO epasChildrenDTO = new EPASChildrenDTO(); + epasChildrenDTO.setName(epasChildren.getName()); + epasChildrenDTO.setSurname(epasChildren.getSurname()); + epasChildrenDTO.setFiscalCode(epasChildren.getFiscalCode()); + epasChildrenDTO.setBornDate(epasChildren.getBornDate()); + epasChildrenDTO.setExternalId(epasChildren.getExternalId()); + return epasChildrenDTO; + } + } +} diff --git a/src/main/java/it/cnr/isti/epasmed/epas/model/EPASChildren.java b/src/main/java/it/cnr/isti/epasmed/epas/model/EPASChildren.java new file mode 100644 index 0000000..535087a --- /dev/null +++ b/src/main/java/it/cnr/isti/epasmed/epas/model/EPASChildren.java @@ -0,0 +1,25 @@ +package it.cnr.isti.epasmed.epas.model; + +import java.io.Serializable; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class EPASChildren implements Serializable { + + private static final long serialVersionUID = 1L; + + private String bornDate; + private String externalId; + private String fiscalCode; + private String id; + private String name; + private String surname; + private String updatedAt; + +} \ No newline at end of file diff --git a/src/main/java/it/cnr/isti/epasmed/epas/service/EPASAffiliationsService.java b/src/main/java/it/cnr/isti/epasmed/epas/service/EPASAffiliationsService.java index 98a4d45..bd489e3 100644 --- a/src/main/java/it/cnr/isti/epasmed/epas/service/EPASAffiliationsService.java +++ b/src/main/java/it/cnr/isti/epasmed/epas/service/EPASAffiliationsService.java @@ -7,7 +7,7 @@ import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import it.cnr.isti.epasmed.epas.client.EPASAffiliationsCient; +import it.cnr.isti.epasmed.epas.client.EPASAffiliationsClient; import it.cnr.isti.epasmed.epas.dto.EPASAffiliationsDTO; import it.cnr.isti.epasmed.epas.model.EPASAffiliations; @@ -15,7 +15,7 @@ import it.cnr.isti.epasmed.epas.model.EPASAffiliations; public class EPASAffiliationsService { @Autowired - EPASAffiliationsCient epasAffiliationsClient; + EPASAffiliationsClient epasAffiliationsClient; public EPASAffiliations getById(String id) { return epasAffiliationsClient.getById(id); diff --git a/src/main/java/it/cnr/isti/epasmed/epas/service/EPASChildrenService.java b/src/main/java/it/cnr/isti/epasmed/epas/service/EPASChildrenService.java new file mode 100644 index 0000000..02480d0 --- /dev/null +++ b/src/main/java/it/cnr/isti/epasmed/epas/service/EPASChildrenService.java @@ -0,0 +1,50 @@ +package it.cnr.isti.epasmed.epas.service; + +import java.util.List; + +import javax.validation.Valid; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import it.cnr.isti.epasmed.epas.client.EPASChildrenClient; +import it.cnr.isti.epasmed.epas.dto.EPASChildrenDTO; +import it.cnr.isti.epasmed.epas.model.EPASChildren; + +@Service +public class EPASChildrenService { + + @Autowired + EPASChildrenClient epasChildrenClient; + + public EPASChildren getById(String id) { + return epasChildrenClient.getById(id); + } + + public List getByPersonId(String id) { + return epasChildrenClient.getByPersonId(id); + } + + public List getByPersonFiscalCode(String fc) { + return epasChildrenClient.getByPersonFiscalCode(fc); + } + + public List getByPersonEmail(String email) { + return epasChildrenClient.getByPersonEmail(email); + } + + public EPASChildren create(EPASChildrenDTO epasChildrenDTO) { + return epasChildrenClient.create(epasChildrenDTO); + } + + public void updateById(String id, @Valid EPASChildrenDTO epasChildrenDTO) { + epasChildrenClient.updateById(id, epasChildrenDTO); + } + + public void deleteById(String id) { + epasChildrenClient.deleteById(id); + } + + + +} diff --git a/src/main/java/it/cnr/isti/epasmed/epas/service/EPASContractsService.java b/src/main/java/it/cnr/isti/epasmed/epas/service/EPASContractsService.java index 1820855..0cac8a4 100644 --- a/src/main/java/it/cnr/isti/epasmed/epas/service/EPASContractsService.java +++ b/src/main/java/it/cnr/isti/epasmed/epas/service/EPASContractsService.java @@ -7,7 +7,7 @@ import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import it.cnr.isti.epasmed.epas.client.EPASContractsCient; +import it.cnr.isti.epasmed.epas.client.EPASContractsClient; import it.cnr.isti.epasmed.epas.dto.EPASContractsDTO; import it.cnr.isti.epasmed.epas.model.EPASContracts; @@ -15,7 +15,7 @@ import it.cnr.isti.epasmed.epas.model.EPASContracts; public class EPASContractsService { @Autowired - EPASContractsCient epasContractsClient; + EPASContractsClient epasContractsClient; public EPASContracts getById(String id) { return epasContractsClient.getById(id); diff --git a/src/main/java/it/cnr/isti/epasmed/epas/service/EPASGroupsService.java b/src/main/java/it/cnr/isti/epasmed/epas/service/EPASGroupsService.java index eb7e087..220e41c 100644 --- a/src/main/java/it/cnr/isti/epasmed/epas/service/EPASGroupsService.java +++ b/src/main/java/it/cnr/isti/epasmed/epas/service/EPASGroupsService.java @@ -7,7 +7,7 @@ import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import it.cnr.isti.epasmed.epas.client.EPASGroupsCient; +import it.cnr.isti.epasmed.epas.client.EPASGroupsClient; import it.cnr.isti.epasmed.epas.dto.EPASGroupsDTO; import it.cnr.isti.epasmed.epas.model.EPASGroups; @@ -15,7 +15,7 @@ import it.cnr.isti.epasmed.epas.model.EPASGroups; public class EPASGroupsService { @Autowired - EPASGroupsCient epasGroupsClient; + EPASGroupsClient epasGroupsClient; public EPASGroups getById(String id) { return epasGroupsClient.getById(id); diff --git a/src/main/java/it/cnr/isti/epasmed/epas/service/EPASLeavesService.java b/src/main/java/it/cnr/isti/epasmed/epas/service/EPASLeavesService.java index 730c637..8e3366d 100644 --- a/src/main/java/it/cnr/isti/epasmed/epas/service/EPASLeavesService.java +++ b/src/main/java/it/cnr/isti/epasmed/epas/service/EPASLeavesService.java @@ -5,14 +5,14 @@ import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import it.cnr.isti.epasmed.epas.client.EPASLeavesCient; +import it.cnr.isti.epasmed.epas.client.EPASLeavesClient; import it.cnr.isti.epasmed.epas.model.EPASLeaves; @Service public class EPASLeavesService { @Autowired - EPASLeavesCient epasLeavesClient; + EPASLeavesClient epasLeavesClient; public List getLeavesByPersonId(String id, String year) { return epasLeavesClient.getByPersonId(id, year); diff --git a/src/main/java/it/cnr/isti/epasmed/epas/service/EPASPersonsService.java b/src/main/java/it/cnr/isti/epasmed/epas/service/EPASPersonsService.java index 6ccb738..afc9a1e 100644 --- a/src/main/java/it/cnr/isti/epasmed/epas/service/EPASPersonsService.java +++ b/src/main/java/it/cnr/isti/epasmed/epas/service/EPASPersonsService.java @@ -7,7 +7,7 @@ import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import it.cnr.isti.epasmed.epas.client.EPASPersonsCient; +import it.cnr.isti.epasmed.epas.client.EPASPersonsClient; import it.cnr.isti.epasmed.epas.dto.EPASPersonsDTO; import it.cnr.isti.epasmed.epas.model.EPASPersons; @@ -15,7 +15,7 @@ import it.cnr.isti.epasmed.epas.model.EPASPersons; public class EPASPersonsService { @Autowired - EPASPersonsCient epasPersonsClient; + EPASPersonsClient epasPersonsClient; public EPASPersons getById(String id) { return epasPersonsClient.getById(id); diff --git a/src/main/java/it/cnr/isti/epasmed/sistemainformativo/repository/SIMasterLogRepository.java b/src/main/java/it/cnr/isti/epasmed/sistemainformativo/repository/SIMasterLogRepository.java index f32b1a6..ec23cfe 100644 --- a/src/main/java/it/cnr/isti/epasmed/sistemainformativo/repository/SIMasterLogRepository.java +++ b/src/main/java/it/cnr/isti/epasmed/sistemainformativo/repository/SIMasterLogRepository.java @@ -24,14 +24,11 @@ public class SIMasterLogRepository { public SIMasterLogRepository(final @Qualifier("sistemaInformativoDataSource") DataSource dataSource) { super(); this.jdbcTemplate = new JdbcTemplate(dataSource); - // this.dataSource = dataSource; - // logger.debug("MasterLogRepository DataSource set: "+dataSource.toString()); } - public int count() { + public Long count() { log.debug("Call MasterLogRepository Count()"); - // return 1000; - return jdbcTemplate.queryForObject("select count(*) from master_log", Integer.class); + return jdbcTemplate.queryForObject("select count(*) from master_log", Long.class); } public void startFluxReads() { diff --git a/src/main/java/it/cnr/isti/epasmed/sistemainformativo/service/SIMasterLogService.java b/src/main/java/it/cnr/isti/epasmed/sistemainformativo/service/SIMasterLogService.java index 2f599fb..ebbc4cc 100644 --- a/src/main/java/it/cnr/isti/epasmed/sistemainformativo/service/SIMasterLogService.java +++ b/src/main/java/it/cnr/isti/epasmed/sistemainformativo/service/SIMasterLogService.java @@ -25,7 +25,7 @@ public class SIMasterLogService { } - public int count() { + public Long count() { log.debug("Request MasterLog count()"); return masterLogRepository.count(); } diff --git a/src/main/java/it/cnr/isti/epasmed/web/rest/AccountResource.java b/src/main/java/it/cnr/isti/epasmed/web/rest/AccountResource.java index 5641db1..dd2515e 100644 --- a/src/main/java/it/cnr/isti/epasmed/web/rest/AccountResource.java +++ b/src/main/java/it/cnr/isti/epasmed/web/rest/AccountResource.java @@ -1,8 +1,31 @@ package it.cnr.isti.epasmed.web.rest; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.List; +import java.util.Optional; + +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; + +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + import it.cnr.isti.epasmed.domain.PersistentToken; -import it.cnr.isti.epasmed.repository.PersistentTokenRepository; import it.cnr.isti.epasmed.domain.User; +import it.cnr.isti.epasmed.repository.PersistentTokenRepository; import it.cnr.isti.epasmed.repository.UserRepository; import it.cnr.isti.epasmed.security.AuthoritiesConstants; import it.cnr.isti.epasmed.security.SecurityUtils; @@ -10,24 +33,12 @@ import it.cnr.isti.epasmed.service.MailService; import it.cnr.isti.epasmed.service.UserService; import it.cnr.isti.epasmed.service.dto.PasswordChangeDTO; import it.cnr.isti.epasmed.service.dto.UserDTO; -import it.cnr.isti.epasmed.web.rest.errors.*; +import it.cnr.isti.epasmed.web.rest.errors.EmailAlreadyUsedException; +import it.cnr.isti.epasmed.web.rest.errors.InvalidPasswordException; +import it.cnr.isti.epasmed.web.rest.errors.LoginAlreadyUsedException; import it.cnr.isti.epasmed.web.rest.vm.KeyAndPasswordVM; import it.cnr.isti.epasmed.web.rest.vm.ManagedUserVM; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.http.HttpStatus; -import org.springframework.security.access.annotation.Secured; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.*; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.util.*; - /** * REST controller for managing the current user's account. */ @@ -36,7 +47,10 @@ import java.util.*; public class AccountResource { private static class AccountResourceException extends RuntimeException { - private AccountResourceException(String message) { + + private static final long serialVersionUID = 1L; + + private AccountResourceException(String message) { super(message); } } diff --git a/src/main/java/it/cnr/isti/epasmed/web/rest/epas/EPASChildrenResource.java b/src/main/java/it/cnr/isti/epasmed/web/rest/epas/EPASChildrenResource.java new file mode 100644 index 0000000..046e9bd --- /dev/null +++ b/src/main/java/it/cnr/isti/epasmed/web/rest/epas/EPASChildrenResource.java @@ -0,0 +1,178 @@ +package it.cnr.isti.epasmed.web.rest.epas; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.List; +import java.util.Optional; + +import javax.validation.Valid; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import io.github.jhipster.web.util.HeaderUtil; +import io.github.jhipster.web.util.ResponseUtil; +import it.cnr.isti.epasmed.epas.dto.EPASChildrenDTO; +import it.cnr.isti.epasmed.epas.model.EPASChildren; +import it.cnr.isti.epasmed.epas.service.EPASChildrenService; +import it.cnr.isti.epasmed.security.AuthoritiesConstants; +import it.cnr.isti.epasmed.web.rest.errors.BadRequestAlertException; + +@RestController +@RequestMapping("/api/epas") +public class EPASChildrenResource { + + private final Logger log = LoggerFactory.getLogger(getClass()); + + @Value("${jhipster.clientApp.name}") + private String applicationName; + + private final EPASChildrenService epasChildrenService; + + public EPASChildrenResource(EPASChildrenService epasChildrenServiceService) { + this.epasChildrenService = epasChildrenServiceService; + + } + + /** + * {@code GET /child/:id} : get children by id. + * + * @param id the id of the children to find. + * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body + * the EPAS Children, or with status {@code 404 (Not Found)}. + */ + @GetMapping("/child/{id}") + public ResponseEntity getEPASChildrenById(@PathVariable String id) { + log.info("REST request to get ePAS Children by Id: {}", id); + EPASChildren epasChildren = epasChildrenService.getById(id); + log.info("Retrieved Children: {}", epasChildren); + return ResponseUtil.wrapOrNotFound(Optional.of(epasChildren)); + + } + + /** + * {@code GET /child/byPerson} : get children by person + * + * @param id the id of the person. + * @param fiscalCode the fiscal code of the person. + * @param email the email of the person. + * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body + * the EPAS Children, or with status {@code 404 (Not Found)}. + */ + @GetMapping("/child/byPerson") + public ResponseEntity> getEPASChildrenByPerson(@RequestParam("id") Optional id, + @RequestParam("fiscalCode") Optional fiscalCode, + @RequestParam("email") Optional email) { + + + List listEpasChildren = null; + if (id.isPresent()) { + log.info("REST request to get ePAS Children by Person id: {}", id.get()); + listEpasChildren = epasChildrenService.getByPersonId(id.get()); + } else { + if (fiscalCode.isPresent()) { + log.info("REST request to get ePAS Children by Person fiscalcode: {}", fiscalCode.get()); + listEpasChildren = epasChildrenService.getByPersonFiscalCode(fiscalCode.get()); + } else { + if (email.isPresent()) { + log.info("REST request to get ePAS Children by Person email: {}", email.get()); + listEpasChildren = epasChildrenService.getByPersonEmail(email.get()); + } else { + return ResponseUtil.wrapOrNotFound(Optional.of(listEpasChildren), HeaderUtil.createFailureAlert(applicationName,false, + "","","Invalid parameter in call")); + + } + } + } + log.info("Retrieved Certification: {}", listEpasChildren); + return ResponseUtil.wrapOrNotFound(Optional.of(listEpasChildren)); + } + + + + /** + * {@code POST /child} : Creates a new child. + *

+ * + * @param epasChildrenDTO the user to create. + * @return the {@link ResponseEntity} with status {@code 201 (Created)} and with + * body the new ePAS Child, or with status {@code 400 (Bad Request)} + * @throws URISyntaxException if the Location URI syntax is incorrect. + * @throws BadRequestAlertException {@code 400 (Bad Request)} if the id is + * already in use. + */ + @PostMapping("/child") + @PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")") + public ResponseEntity createEPASChildren(@Valid @RequestBody EPASChildrenDTO epasChildrenDTO) + throws URISyntaxException { + log.debug("REST request to create EPAS Child: {}", epasChildrenDTO); + + EPASChildren createdEPASChildren = epasChildrenService.create(epasChildrenDTO); + StringBuilder sb = new StringBuilder(); + sb.append(createdEPASChildren.getSurname()); + sb.append(" "); + sb.append(createdEPASChildren.getName()); + + + return ResponseEntity.created(new URI("/api/epas/child/" + createdEPASChildren.getId())) + .headers(HeaderUtil.createAlert(applicationName, + "A ePAS Child is created with identifier " + createdEPASChildren.getId(), + sb.toString())) + .body(createdEPASChildren); + + } + + /** + * {@code PUT /child/:id} : Updates an existing ePAS Children by id. + * + * @param epasChildrenDTO the new ePAS Children info. + * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body + * the updated ePAS Children. + * + */ + @PutMapping("/child/{id}") + @PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")") + public ResponseEntity updateEPASChildrenById(@PathVariable String id, + @Valid @RequestBody EPASChildrenDTO epasChildrenDTO) { + log.debug("REST request to update ePAS Children : {} by {}", id, epasChildrenDTO); + epasChildrenService.updateById(id, epasChildrenDTO); + EPASChildren updatedEPASChildren = epasChildrenService.getById(id); + Optional oEPASChildren = Optional.of(updatedEPASChildren); + StringBuilder sb = new StringBuilder(); + sb.append(updatedEPASChildren.getSurname()); + sb.append(" "); + sb.append(updatedEPASChildren.getName()); + + return ResponseUtil.wrapOrNotFound(oEPASChildren, HeaderUtil.createAlert(applicationName, + "A ePAS Child is updated with identifier " + updatedEPASChildren.getId(), sb.toString())); + } + + /** + * {@code DELETE /child/:id} : delete ePAS Children by id. + * + * @param id the id of the ePAS Children to delete. + * @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}. + */ + @DeleteMapping("/child/{id}") + @PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")") + public ResponseEntity deleteEPASChildrenById(@PathVariable String id) { + log.debug("REST request to delete ePAS Children by id: {}", id); + epasChildrenService.deleteById(id); + return ResponseEntity.noContent() + .headers(HeaderUtil.createAlert(applicationName, "A Child is deleted with identifier " + id, id)) + .build(); + } + +} diff --git a/src/main/java/it/cnr/isti/epasmed/web/rest/epas/EPASTimeCardsResource.java b/src/main/java/it/cnr/isti/epasmed/web/rest/epas/EPASTimeCardsResource.java index 139b90f..725150a 100644 --- a/src/main/java/it/cnr/isti/epasmed/web/rest/epas/EPASTimeCardsResource.java +++ b/src/main/java/it/cnr/isti/epasmed/web/rest/epas/EPASTimeCardsResource.java @@ -14,7 +14,6 @@ import org.springframework.web.bind.annotation.RestController; import io.github.jhipster.web.util.HeaderUtil; import io.github.jhipster.web.util.ResponseUtil; -import it.cnr.isti.epasmed.epas.model.EPASCertifications; import it.cnr.isti.epasmed.epas.model.EPASTimeCards; import it.cnr.isti.epasmed.epas.service.EPASTimeCardsService; @@ -46,7 +45,7 @@ public class EPASTimeCardsResource { * the EPAS TimeCards, or with status {@code 404 (Not Found)}. */ @GetMapping("/timecards/byPerson") - public ResponseEntity getEPASCertificationByPerson(@RequestParam("id") Optional id, + public ResponseEntity getEPASTimeCardsByPerson(@RequestParam("id") Optional id, @RequestParam("fiscalCode") Optional fiscalCode, @RequestParam("email") Optional email, @RequestParam("year") String year,@RequestParam("month") String month) { diff --git a/src/main/java/it/cnr/isti/epasmed/web/rest/sistemainformativo/SIMasterLogResource.java b/src/main/java/it/cnr/isti/epasmed/web/rest/sistemainformativo/SIMasterLogResource.java index 9966c0d..035a6ac 100644 --- a/src/main/java/it/cnr/isti/epasmed/web/rest/sistemainformativo/SIMasterLogResource.java +++ b/src/main/java/it/cnr/isti/epasmed/web/rest/sistemainformativo/SIMasterLogResource.java @@ -22,8 +22,10 @@ public class SIMasterLogResource { } @GetMapping("/masterlog/count") - public int getCount() { - return masterLogService.count(); + public Long getCount() { + Long fluxValue=masterLogService.count(); + log.info("SI masterlog value: {}",fluxValue); + return fluxValue; } } diff --git a/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASChildrenResourceIT.java b/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASChildrenResourceIT.java new file mode 100644 index 0000000..55651d5 --- /dev/null +++ b/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASChildrenResourceIT.java @@ -0,0 +1,301 @@ +package it.cnr.isti.epasmed.web.rest.epas; + +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.core.env.Environment; +import org.springframework.http.MediaType; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.context.junit.jupiter.EnabledIf; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +import it.cnr.isti.epasmed.EpasmedApp; +import it.cnr.isti.epasmed.epas.dto.EPASChildrenDTO; +import it.cnr.isti.epasmed.epas.mapper.EPASChildrenMapper; +import it.cnr.isti.epasmed.epas.model.EPASChildren; +import it.cnr.isti.epasmed.epas.model.EPASOffice; +import it.cnr.isti.epasmed.epas.model.EPASPersons; +import it.cnr.isti.epasmed.security.AuthoritiesConstants; +import it.cnr.isti.epasmed.web.rest.TestUtil; + +/** + * Integration tests for the {@link EPASChildrenResource} REST controller. + */ +@AutoConfigureMockMvc +@WithMockUser(authorities = AuthoritiesConstants.ADMIN) +@SpringBootTest(classes = EpasmedApp.class) +@EnabledIf("false") +public class EPASChildrenResourceIT { + + private final Logger log = LoggerFactory.getLogger(getClass()); + + private static final String OFFICE_DEFAULT_ID = "1"; + private static final String OFFICE_DEFAULT_NAME = "ISTI - Pisa"; + private static final String OFFICE_DEFAULT_CODE = "074000"; + private static final String OFFICE_DEFAULT_CODEID = "225200"; + + private static final String PERSON_DEFAULT_ID = "113"; + // private static final String PERSON_DEFAULT_NAME = "Giuseppe"; + // private static final String PERSON_DEFAULT_SURNAME = "Amato"; + private static final String PERSON_DEFAULT_FISCAL_CODE = "MTAGPP68D15D976W"; + private static final String PERSON_DEFAULT_EMAIL = "giuseppe.amato@cnr.it"; + // private static final String PERSON_DEFAULT_QUALIFICATION = "2"; + + private static final String CHILDREN_DEFAULT_ID = "xxx"; + private static final String CHILDREN_DEFAULT_NAME = "childNomeTest1"; + private static final String CHILDREN_DEFAULT_SURNAME = "childCognomeTest1"; + private static final String CHILDREN_DEFAULT_FISCAL_CODE = "childCodicefiscaleTest1"; + + private static final String CHILDREN_UPDATE_NAME = "childNomeTest2"; + + @Autowired + private MockMvc restEPASChildrenMockMvc; + + @Autowired + private EPASChildrenMapper epasChildrenMapper; + + @Autowired + private Environment environment; + + private EPASChildren epasChildren; + private EPASChildrenDTO epasChildrenDTO; + + public static EPASOffice createOffice() { + EPASOffice epasOffice = new EPASOffice(); + epasOffice.setId(OFFICE_DEFAULT_ID); + epasOffice.setName(OFFICE_DEFAULT_NAME); + epasOffice.setCode(OFFICE_DEFAULT_CODE); + epasOffice.setCodeId(OFFICE_DEFAULT_CODEID); + return epasOffice; + } + + public static EPASChildren createTestChild() { + EPASChildren epasChildren = new EPASChildren(); + epasChildren.setId(CHILDREN_DEFAULT_ID); + epasChildren.setName(CHILDREN_DEFAULT_NAME); + epasChildren.setSurname(CHILDREN_DEFAULT_SURNAME); + epasChildren.setFiscalCode(CHILDREN_DEFAULT_FISCAL_CODE); + epasChildren.setBornDate("2021-10-01"); + return epasChildren; + } + + @BeforeEach + public void initTest() { + for (String profileName : environment.getActiveProfiles()) { + log.info("Currently active profile - " + profileName); + } + log.info("System env - " + System.getenv("spring.profiles.active")); + epasChildren = createTestChild(); + epasChildrenDTO = epasChildrenMapper.epasChildrenToEPASChildrenDTO(epasChildren); + + } + + @Test + public void getChildrenById() throws Exception { + restEPASChildrenMockMvc.perform(get("/api/epas/child/1")).andExpect(status().isOk()); + } + + @Test + public void getChildrenByPersonId() throws Exception { + restEPASChildrenMockMvc.perform(get("/api/epas/child/byPerson?id=" + PERSON_DEFAULT_ID)) + .andExpect(status().isOk()); + } + + @Test + public void getChilrenByPersonFiscalCode() throws Exception { + restEPASChildrenMockMvc.perform(get("/api/epas/child/byPerson?fiscalCode=" + PERSON_DEFAULT_FISCAL_CODE)) + .andExpect(status().isOk()); + } + + @Test + public void getChildrenByPersonEmail() throws Exception { + restEPASChildrenMockMvc.perform(get("/api/epas/child/byPerson?email=" + PERSON_DEFAULT_EMAIL)) + .andExpect(status().isOk()); + } + + @Test + public void createChildren() throws Exception { + restEPASChildrenMockMvc + .perform(post("/api/epas/child").contentType(MediaType.APPLICATION_JSON) + .content(TestUtil.convertObjectToJsonBytes(epasChildrenDTO)).with(csrf())) + .andExpect(status().isCreated()); + + } + + @Test + public void istiAddChildren() { + String userDirectory = System.getProperty("user.dir"); + log.info(userDirectory); + List istiChildren = null; + try (Stream stream = Files + .lines(Paths.get("src/test/resources/it/cnr/isti/epasmed/web/rest/epas/figliISTI.csv"))) { + istiChildren = stream.skip(1).map(istiMapToChildren).collect(Collectors.toList()); + } catch (Exception e) { + log.error(e.getLocalizedMessage(), e); + return; + } + log.info("ISTI Children loaded"); + + List epasPersons = null; + try { + MvcResult result = restEPASChildrenMockMvc.perform(get("/api/epas/persons?officeId=" + OFFICE_DEFAULT_ID)) + .andExpect(status().isOk()).andReturn(); + + ObjectMapper mapper = new ObjectMapper(); + epasPersons = mapper.readValue(result.getResponse().getContentAsString(), + new TypeReference>() { + }); + + } catch (Exception e) { + log.error(e.getLocalizedMessage(), e); + return; + } + + log.info("EPAS Persons loaded"); + + List createDTOList = new ArrayList<>(); + + for (EPASChildrenDTO childrenDTO : istiChildren) { + if (childrenDTO.getPersonId() != null && !childrenDTO.getPersonId().isEmpty()) { + for (EPASPersons istip : epasPersons) { + if (istip.getFiscalCode() != null && !istip.getFiscalCode().isEmpty() + && istip.getFiscalCode().compareTo(childrenDTO.getPersonId()) == 0) { + List allReadyPresentChildren = new ArrayList<>(); + try { + MvcResult result = restEPASChildrenMockMvc + .perform(get("/api/epas/child/byPerson?fiscalCode=" + istip.getFiscalCode())) + .andExpect(status().isOk()).andReturn(); + + ObjectMapper mapper = new ObjectMapper(); + allReadyPresentChildren = mapper.readValue(result.getResponse().getContentAsString(), + new TypeReference>() { + }); + + } catch (Exception e) { + log.error(e.getLocalizedMessage(), e); + return; + } + + boolean allReadyPresentC = false; + for (EPASChildren aec : allReadyPresentChildren) { + if (aec.getSurname().compareToIgnoreCase(childrenDTO.getSurname()) == 0 + && aec.getName().compareToIgnoreCase(childrenDTO.getName()) == 0) { + allReadyPresentC = true; + break; + } + } + if (!allReadyPresentC) { + childrenDTO.setPersonId(istip.getId()); + createDTOList.add(childrenDTO); + } + break; + } + } + } + } + + log.info("Children Create List builded"); + + for (EPASChildrenDTO up : createDTOList) { + try { + restEPASChildrenMockMvc + .perform(post("/api/epas/child").contentType(MediaType.APPLICATION_JSON) + .content(TestUtil.convertObjectToJsonBytes(up)).with(csrf())) + .andExpect(status().isOk()); + } catch (Exception e) { + log.error(e.getLocalizedMessage(), e); + } + } + } + + private Function istiMapToChildren = (line) -> { + + String[] p = line.split(",");// a CSV has comma separated lines + + EPASChildrenDTO child = new EPASChildrenDTO(); + + // <-- this is the first column in the csv file + if (p[0] != null && p[0].length() > 0) { + String surname = p[0].substring(1, p[0].length() - 1); + if (surname != null && !surname.isEmpty()) { + child.setSurname(surname); + } + } + + if (p[1] != null && p[1].length() > 0) { + String name = p[1].substring(1, p[1].length() - 1); + if (name != null && !name.isEmpty()) { + child.setName(name); + } + } + + if (p[2] != null && p[2].length() > 0) { + String bornDate = p[2].substring(1, p[2].length() - 1); + if (bornDate != null && !bornDate.isEmpty()) { + child.setBornDate(bornDate); + } + } + + if (p[3] != null && p[3].length() > 0) { + String externalId = p[3].substring(1, p[3].length() - 1); + if (externalId != null && !externalId.isEmpty()) { + child.setExternalId(externalId); + } + } + + if (p[4] != null && p[4].length() > 0) { + String parentCodiceFiscale = p[4].substring(1, p[4].length() - 1); + if (parentCodiceFiscale != null && !parentCodiceFiscale.isEmpty()) { + child.setPersonId(parentCodiceFiscale); + } + } + + child.setFiscalCode(""); + return child; + }; + + @Test + public void updateChildrenById() throws Exception { + epasChildrenDTO.setName(CHILDREN_UPDATE_NAME); + MvcResult mvcResult = restEPASChildrenMockMvc + .perform(put("/api/epas/child/" + CHILDREN_DEFAULT_ID).contentType(MediaType.APPLICATION_JSON) + .content(TestUtil.convertObjectToJsonBytes(epasChildrenDTO)).with(csrf())) + .andExpect(status().isOk()).andReturn(); + ObjectMapper mapper = new ObjectMapper(); + + EPASChildren epasChildren = mapper.readValue(mvcResult.getResponse().getContentAsByteArray(), + EPASChildren.class); + log.info("Updated EPAS Child by id: " + epasChildren); + } + + @Test + public void deleteChildrenById() throws Exception { + restEPASChildrenMockMvc.perform(delete("/api/epas/child/" + CHILDREN_DEFAULT_ID).with(csrf())) + .andExpect(status().is2xxSuccessful()).andReturn(); + log.info("Deleted EPAS Child by id: " + CHILDREN_DEFAULT_ID); + } + +} diff --git a/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASPersonsResourceIT.java b/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASPersonsResourceIT.java index 3aa7026..56568e2 100644 --- a/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASPersonsResourceIT.java +++ b/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASPersonsResourceIT.java @@ -56,7 +56,7 @@ public class EPASPersonsResourceIT { private static final String OFFICE_DEFAULT_CODE = "074000"; private static final String OFFICE_DEFAULT_CODEID = "225200"; - private static final String PERSON_DEFAULT_ID = "176"; + private static final String PERSON_DEFAULT_ID = "xxx"; private static final String PERSON_DEFAULT_NAME = "nometest1"; private static final String PERSON_DEFAULT_SURNAME = "cognometest1"; private static final String PERSON_DEFAULT_FISCAL_CODE = "codicefiscaletes"; @@ -145,7 +145,7 @@ public class EPASPersonsResourceIT { log.info(userDirectory); List istiPersons = null; try (Stream stream = Files - .lines(Paths.get("src/test/resources/it/cnr/isti/epasmed/web/rest/epas/personale.csv"))) { + .lines(Paths.get("src/test/resources/it/cnr/isti/epasmed/web/rest/epas/personaleISTI.csv"))) { istiPersons = stream.skip(1).map(istiMapToPerson).collect(Collectors.toList()); } catch (Exception e) { log.error(e.getLocalizedMessage(), e); diff --git a/src/test/java/it/cnr/isti/epasmed/web/rest/sistemainformativo/SIMasterLogResourceIT.java b/src/test/java/it/cnr/isti/epasmed/web/rest/sistemainformativo/SIMasterLogResourceIT.java new file mode 100644 index 0000000..46f9bb1 --- /dev/null +++ b/src/test/java/it/cnr/isti/epasmed/web/rest/sistemainformativo/SIMasterLogResourceIT.java @@ -0,0 +1,51 @@ +package it.cnr.isti.epasmed.web.rest.sistemainformativo; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.core.env.Environment; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.context.junit.jupiter.EnabledIf; +import org.springframework.test.web.servlet.MockMvc; + +import it.cnr.isti.epasmed.EpasmedApp; +import it.cnr.isti.epasmed.security.AuthoritiesConstants; + +/** + * Integration tests for the {@link SIMasterLogResource} REST controller. + */ +@AutoConfigureMockMvc +@WithMockUser(authorities = AuthoritiesConstants.ADMIN) +@SpringBootTest(classes = EpasmedApp.class) +@EnabledIf("true") +public class SIMasterLogResourceIT { + + private final Logger log = LoggerFactory.getLogger(getClass()); + + @Autowired + private MockMvc restSIMasterLogMockMvc; + + @Autowired + private Environment environment; + + @BeforeEach + public void initTest() { + for (String profileName : environment.getActiveProfiles()) { + log.info("Currently active profile - " + profileName); + } + log.info("System env - " + System.getenv("spring.profiles.active")); + } + + @Test + public void getMasterLogCount() throws Exception { + restSIMasterLogMockMvc.perform(get("/api/sistemainformativo/masterlog/count")).andExpect(status().isOk()); + } + +} diff --git a/src/test/java/it/cnr/isti/epasmed/web/rest/SyncResourceIT.java b/src/test/java/it/cnr/isti/epasmed/web/rest/sync/SyncResourceIT.java similarity index 95% rename from src/test/java/it/cnr/isti/epasmed/web/rest/SyncResourceIT.java rename to src/test/java/it/cnr/isti/epasmed/web/rest/sync/SyncResourceIT.java index dfc0ad3..75ff306 100644 --- a/src/test/java/it/cnr/isti/epasmed/web/rest/SyncResourceIT.java +++ b/src/test/java/it/cnr/isti/epasmed/web/rest/sync/SyncResourceIT.java @@ -1,4 +1,4 @@ -package it.cnr.isti.epasmed.web.rest; +package it.cnr.isti.epasmed.web.rest.sync; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; @@ -18,6 +18,7 @@ import org.springframework.test.web.servlet.MockMvc; import it.cnr.isti.epasmed.EpasmedApp; import it.cnr.isti.epasmed.security.AuthoritiesConstants; +import it.cnr.isti.epasmed.web.rest.SyncResource; /** * Integration tests for the {@link SyncResource} REST controller. diff --git a/src/test/resources/it/cnr/isti/epasmed/web/rest/epas/figliISTI.csv b/src/test/resources/it/cnr/isti/epasmed/web/rest/epas/figliISTI.csv new file mode 100644 index 0000000..174a8ea --- /dev/null +++ b/src/test/resources/it/cnr/isti/epasmed/web/rest/epas/figliISTI.csv @@ -0,0 +1,113 @@ +"t_figli_cognome","t_figli_nome","t_figli_data_nascita","t_figli_codice","t_personale_codice_fiscale" +"Ter Beek","Ciro","2007-01-08","1","TRBMCH72R07Z126L" +"Ter Beek","Olivia","2008-10-14","2","TRBMCH72R07Z126L" +"Rota","Alice","2005-09-08","3","PLTSRN73A70G702U" +"Pieri","Margherita","2011-10-05","6","PRIGRL74E31G491R" +"Manghi","Tommaso","2010-11-21","7","MNGPLA70T22D612X" +"Nanni","Martina","2008-11-30","8","NNNMRC73M11Z130N" +"Nanni","Andrea","2005-01-14","9","NNNMRC73M11Z130N" +"Gennaro","Flavio","2006-02-21","10","GNNCLD68A12D960O" +"Dazzi","Aurora","2012-05-26","11","DZZPRZ79S23B832W" +"Scopigno","Jacopo","2005-05-27","12","SCPRRT60L20H501Z" +"Barsocchi","Samuele","2010-09-16","13","BRSPLA78S27G702C" +"Falchi","Floriano","2010-01-12","14","FLCFRZ75H11G843N" +"Falchi","Floriano","2010-01-13","15","FEOGTT76M57G702C" +"Nardi","Valerio","2007-12-04","16","NRDLSN75B22E625N" +"Nardi","Dario","2010-04-23","17","NRDLSN75B22E625N" +"Pierotti","Alessio","2010-04-20","18","FRRMNL83M56G702N" +"Pingi","Leonardo","2005-12-01","19","PNGPLA69A10E506F" +"Pingi","Emma","2009-02-28","20","PNGPLA69A10E506F" +"Cignoni","Margherita","2008-08-21","21","CGNPLA68M27B509P" +"Concordia","Edoardo","2005-05-12","22","CNCCSR65S20E058O" +"Concordia","Andrea","2008-05-08","23","CNCCSR65S20E058O" +"Coco","Gaia","2007-11-12","24","CCOLSN70P02C351P" +"Coco","Brando","2010-04-30","25","CCOLSN70P02C351P" +"Lami","Ranieri","2006-03-03","26","LMAGPP68M29G702D" +"Chiaradonna","Alice","2008-04-18","27","CHRSVN66S21Z133B" +"Esuli","Caterina","2006-10-12","28","SLENDR77T26G702W" +"Esuli","Alessandra","2009-10-20","29","SLENDR77T26G702W" +"Sebastiani","Irene","2006-01-13","30","SBSFRZ60B15C372J" +"Giulivi","Aurora","2006-07-01","31","DMTFNC72S46H793U" +"Giulivi","Lorenzo","2009-01-26","32","DMTFNC72S46H793U" +"Giulivi","Matteo","2011-11-07","33","DMTFNC72S46H793U" +"Russo","Sofia","2005-06-03","34","BRRFNC71M61G702S" +"Russo","Leonardo","2010-12-17","35","BRRFNC71M61G702S" +"Piccioli","Sergio","2005-04-13","36","PCCTMS69D11G702V" +"Ricci","Leonardo","2010-03-05","37","TZZSRN71P61L702F" +"Salerno","Jacopo","2012-08-15","38","GRGDNL79T61G482Z" +"Bennici","Sofia Paola","2012-12-29","39","GRRMRA75B63F839N" +"Ricci","Matteo","2007-09-27","40","TZZSRN71P61L702F" +"Trasarti","Lorenzo","2013-04-11","41","TRSRRT79M08M082U" +"Bueti","Laura","2013-07-29","43","SNTCML69R48F205S" +"Campone","Cristofer","2013-07-02","44","CMPGRL78L31Z315T" +"Campone","Marcus","2013-07-02","45","CMPGRL78L31Z315T" +"Candela","Lorenzo","2013-05-06","48","CNDLRD76B13A399L" +"Gotta","Amelia Lorena","2009-10-01","49","GTTLRT77R01D969N" +"Gotta","Mario","2012-01-02","50","GTTLRT77R01D969N" +"Corsini","Beatrice","2013-12-03","51","CRSMSM74A10H980B" +"Manghi","Giacomo","2014-04-25","52","CLNSRA74S49A485U" +"Manghi","Tommaso","2010-11-21","54","CLNSRA74S49A485U" +"Manghi","Giacomo","2014-04-25","57","MNGPLA70T22D612X" +"Di Renzo","Maria Sofia","2011-12-22","60","BSCSLL74R54H163P" +"Bennici","Chiara Luce","2014-08-29","62","GRRMRA75B63F839N" +"Barsocchi","Sara","2014-08-15","63","BRSPLA78S27G702C" +"Falchi","Niccolò","2014-08-28","64","FEOGTT76M57G702C" +"Righi","Anna","2014-08-31","65","RGHMRC75M21E625Z" +"Torraco","Sara","2014-12-18","68","LMBSFN76C46I045D" +"Di Renzo Biscoglio","John Alexander","2014-11-26","69","BSCSLL74R54H163" +"Girolami","Adele","2014-12-23","70","GRLMHL81L07G628D" +"Ganovelli","Eva","2015-02-15","74","GNVFBA71B10L424Q" +"Ciancia","Viola","2015-03-10","78","CNCVCN77S01F052K" +"Fagni","Niccolò","2011-03-28","79","FGNTZN75L19G713R" +"Fagni","Leonardo","2015-04-29","80","FGNTZN75L19G713R" +"Gotta","Giuditta Diletta","2015-07-22","83","GTTLRT77R01D969N" +"Calabrò","Giulia","2015-11-19","84","CLBNNL81C05H224R" +"Salerno","Diego","2015-12-20","86","GRGDNL79T61G482Z" +"Falchi","Nicolò","2014-08-28","88","FLCFRZ75H11G843N" +"Volpini","Emanuele","2016-02-06","89","VLPFRC79R18G843Z" +"Giordano","Alessia","2004-11-30","90","MNDTZN68M67I422Z" +"Nardini","Maria Sole","2016-05-26","91","NRDFNC80E05G491G" +"Rinzivillo","Alice","2016-09-15","92","RNZSVT76R29H163J" +"Carlini","Elena","2016-04-05","93","CRLMNL81M13E463L" +"Romano","Sofia","2011-04-18","94","RMNVTR73C05H224X" +"Romano","Martina","2015-12-23","95","RMNVTR73C05H224X" +"Russo","Diego","2014-02-27","112","RSSDRA76D18E625D" +"Fornasari","luca","2017-06-01","113","FRLBBR76T43E625E" +"Frigerio","Riccardo","2013-12-18","114","PSCMNT81R46D862B" +"Palma","Giorgia","2017-08-03","118","PLMGPL84C10I549Y" +"Ottonello","Orsola","2017-08-23","119","LNTFNC77P67B771D" +"Candela","Niccolò","2017-09-16","120","CNDLRD76B13A399L" +"Rossetti","Irene","2017-11-13","123","RSSGLI84R06E202M" +"Tampucci","Chiara","2016-12-12","124","TMPMRC81H17G702E" +"Nobile","Maria","2009-09-10","127","BGLMRM73P70D583A" +"Nobile","Marco","2015-02-23","128","BGLMRM73P70D583A" +"Russo","Anna Irene","2017-12-21","132","RSSDRA76D18E625D" +"Dellepiane","Alessio","2017-11-24","133","DLLMTT79A03D969W" +"La Bruzzo","Alice","2017-12-29","136","LBRSDR82P20I199Q" +"Ciancia","Alice","2018-02-23","138","CNCVCN77S01F052K" +"Coro","Orlando","2018-05-04","139","CROGPL80H25F839W" +"Coro","Orlando","2018-05-04","141","BRTVNT80R55G702I" +"Galesi","Alessio","2010-06-26","144","GLSGLI83E10E379Y" +"Puntoni","Matteo","2018-08-28","146","PNTMRC77T05G702B" +"De Luca","Benedetta","2018-09-01","148","FLCCHR79A50A657F" +"Romondia","Zoe","2012-04-23","150","CDACLD78D61G687Y" +"Romondia","Teti","2015-06-15","151","CDACLD78D61G687Y" +"Salvadorini","Pietro","2010-09-17","154","LZZMME81E62E463W" +"Salvadorini","Lidia","2013-11-10","155","LZZMME81E62E463W" +"Fornasari","Sara","2018-12-31","156","FRLBBR76T43E625E" +"Girolami","Leonardo","2018-07-23","159","GRLMHL81L07G628D" +"Trasarti","Giulia","2019-04-04","161","TRSRRT79M08M082U" +"Trasarti","Camilla","2019-04-04","163","TRSRRT79M08M082U" +"Trani","Martina","2014-12-26","165","TRNSVT83D12E396M" +"Trani","Gennaro","2017-11-16","166","TRNSVT83D12E396M" +"Mannocci","Lidya","2019-09-13","168","MNNNDR84C27G702H" +"Palma","Giorgia","2017-08-03","169","STTLNE73R57I726Q" +"Ganovelli","Teseo","2020-03-15","171","GNVFBA71B10L424Q" +"Gabrielli","Nicolò","2020-12-28","172","GBRLNZ84R01G628X" +"Berardi","Gabriele","2021-01-20","173","MNTCST85P59Z129X" +"Frosini","Lorenzo","2021-09-29","175","FRRMNL83M56G702N" +"Calabrò","Davide","2021-10-01","176","CLBNNL81C05H224R" +"Vairo","Valerio","2021-09-12","177","VRACDF82P22H926O" +"Panichi","Eliseo","2021-10-30","178","PNCGCR75S04L103G" +"Carlini","Damiano","2021-11-02","179","CRLMNL81M13E463L" +"Puntoni","Michele","2020-09-01","181","PNTMRC77T05G702B" \ No newline at end of file diff --git a/src/test/resources/it/cnr/isti/epasmed/web/rest/epas/personale.csv b/src/test/resources/it/cnr/isti/epasmed/web/rest/epas/personaleISTI.csv similarity index 100% rename from src/test/resources/it/cnr/isti/epasmed/web/rest/epas/personale.csv rename to src/test/resources/it/cnr/isti/epasmed/web/rest/epas/personaleISTI.csv