From 9f3f0afe328d73f65c8bf18f9c50c6257d6570be Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Wed, 1 Dec 2021 18:35:39 +0100 Subject: [PATCH] Updated TimeCards support --- .../EpasMedDataSourceConfiguration.java | 2 +- .../epas/client/EPASTimeCardsClient.java | 64 ++++++++++++++++ .../isti/epasmed/epas/model/EPASAbsences.java | 24 ++++++ .../epasmed/epas/model/EPASPersonDays.java | 27 +++++++ .../epasmed/epas/model/EPASTimeCards.java | 23 ++++++ .../epas/service/EPASTimeCardsService.java | 25 +++++++ .../web/rest/epas/EPASTimeCardsResource.java | 75 +++++++++++++++++++ .../rest/epas/EPASTimeCardsResourceIT.java | 62 +++++++++++++++ 8 files changed, 301 insertions(+), 1 deletion(-) create mode 100644 src/main/java/it/cnr/isti/epasmed/epas/client/EPASTimeCardsClient.java create mode 100644 src/main/java/it/cnr/isti/epasmed/epas/model/EPASAbsences.java create mode 100644 src/main/java/it/cnr/isti/epasmed/epas/model/EPASPersonDays.java create mode 100644 src/main/java/it/cnr/isti/epasmed/epas/model/EPASTimeCards.java create mode 100644 src/main/java/it/cnr/isti/epasmed/epas/service/EPASTimeCardsService.java create mode 100644 src/main/java/it/cnr/isti/epasmed/web/rest/epas/EPASTimeCardsResource.java create mode 100644 src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASTimeCardsResourceIT.java diff --git a/src/main/java/it/cnr/isti/epasmed/config/EpasMedDataSourceConfiguration.java b/src/main/java/it/cnr/isti/epasmed/config/EpasMedDataSourceConfiguration.java index c0b677f..7475d2d 100644 --- a/src/main/java/it/cnr/isti/epasmed/config/EpasMedDataSourceConfiguration.java +++ b/src/main/java/it/cnr/isti/epasmed/config/EpasMedDataSourceConfiguration.java @@ -146,7 +146,7 @@ public class EpasMedDataSourceConfiguration { properties.put("hibernate.hbm2ddl.auto","none"); - // properties.put("hibernate.dialect", env.getProperty("hibernate.dialect")); + properties.put("hibernate.dialect", env.getProperty("hibernate.dialect")); em.setJpaPropertyMap(properties); return em; } diff --git a/src/main/java/it/cnr/isti/epasmed/epas/client/EPASTimeCardsClient.java b/src/main/java/it/cnr/isti/epasmed/epas/client/EPASTimeCardsClient.java new file mode 100644 index 0000000..d807716 --- /dev/null +++ b/src/main/java/it/cnr/isti/epasmed/epas/client/EPASTimeCardsClient.java @@ -0,0 +1,64 @@ +package it.cnr.isti.epasmed.epas.client; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +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.model.EPASPersons; +import it.cnr.isti.epasmed.epas.model.EPASTimeCards; + +@Component +public class EPASTimeCardsClient { + + private final Logger log = LoggerFactory.getLogger(getClass()); + + @Autowired + @Qualifier("RestTemplateForSecondUser") + RestTemplate rt; + + @Autowired + ApplicationProperties appProps; + + public EPASTimeCards getTimeCardByPersonId(String id, String year, String month) { + Map uriVariables = new HashMap<>(); + uriVariables.put("id", id); + uriVariables.put("year", year); + uriVariables.put("month", month); + + EPASTimeCards epasTimeCard = rt.getForObject( + appProps.getDatasourceEpasRest().getRestUrl() + "/v3/persondays/getMonthSituationByPerson?id={id}&year={year}&month={month}", + EPASTimeCards.class,uriVariables); + log.info("Retrieved EPASTimeCard: {}", epasTimeCard); + return epasTimeCard; + } + + + public List getTimeCardByOfficeCodeId(String id, String year, String month) { + Map uriVariables = new HashMap<>(); + uriVariables.put("sedeId", id); + uriVariables.put("year", year); + uriVariables.put("month", month); + + ResponseEntity> responseEntity = rt.exchange( + appProps.getDatasourceEpasRest().getRestUrl() + "/v3/persondays/getmonthsituationbyoffice?sedeId={sedeId}&year={year}&month={month}", HttpMethod.GET, null, + new ParameterizedTypeReference>() { + }, uriVariables); + List listEPASTimeCards = responseEntity.getBody(); + log.info("Retrieved EPASTimeCards: {}", listEPASTimeCards); + return listEPASTimeCards; + } + + + +} diff --git a/src/main/java/it/cnr/isti/epasmed/epas/model/EPASAbsences.java b/src/main/java/it/cnr/isti/epasmed/epas/model/EPASAbsences.java new file mode 100644 index 0000000..33988f8 --- /dev/null +++ b/src/main/java/it/cnr/isti/epasmed/epas/model/EPASAbsences.java @@ -0,0 +1,24 @@ +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 EPASAbsences implements Serializable { + + private static final long serialVersionUID = 1L; + + String code; + String date; + String id; + String justifiedTime; + String justifiedType; + String note; + +} \ No newline at end of file diff --git a/src/main/java/it/cnr/isti/epasmed/epas/model/EPASPersonDays.java b/src/main/java/it/cnr/isti/epasmed/epas/model/EPASPersonDays.java new file mode 100644 index 0000000..c09c4fc --- /dev/null +++ b/src/main/java/it/cnr/isti/epasmed/epas/model/EPASPersonDays.java @@ -0,0 +1,27 @@ +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 EPASPersonDays implements Serializable { + + private static final long serialVersionUID = 1L; + + EPASAbsences[] absences; + String date; + Integer difference; + String id; + Boolean isHoliday; + Boolean isTicketAvailable; + Integer progressive; + String[] stampings; + Integer timeAtWork; + +} \ No newline at end of file diff --git a/src/main/java/it/cnr/isti/epasmed/epas/model/EPASTimeCards.java b/src/main/java/it/cnr/isti/epasmed/epas/model/EPASTimeCards.java new file mode 100644 index 0000000..dab001b --- /dev/null +++ b/src/main/java/it/cnr/isti/epasmed/epas/model/EPASTimeCards.java @@ -0,0 +1,23 @@ +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 EPASTimeCards implements Serializable { + + private static final long serialVersionUID = 1L; + + String baseWorkingDays; + String month; + String year; + EPASPersons person; + EPASPersonDays[] personDays; + +} \ No newline at end of file diff --git a/src/main/java/it/cnr/isti/epasmed/epas/service/EPASTimeCardsService.java b/src/main/java/it/cnr/isti/epasmed/epas/service/EPASTimeCardsService.java new file mode 100644 index 0000000..91ccb2e --- /dev/null +++ b/src/main/java/it/cnr/isti/epasmed/epas/service/EPASTimeCardsService.java @@ -0,0 +1,25 @@ +package it.cnr.isti.epasmed.epas.service; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import it.cnr.isti.epasmed.epas.client.EPASTimeCardsClient; +import it.cnr.isti.epasmed.epas.model.EPASTimeCards; + +@Service +public class EPASTimeCardsService { + + @Autowired + EPASTimeCardsClient epasTimeCardsClient; + + public EPASTimeCards getTimeCardByPersonId(String id, String year, String month) { + return epasTimeCardsClient.getTimeCardByPersonId(id, year, month); + } + + public List getTimeCardByOfficeCodeId(String id, String year, String month) { + return epasTimeCardsClient.getTimeCardByOfficeCodeId(id, year, month); + } + +} 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 new file mode 100644 index 0000000..0ac66aa --- /dev/null +++ b/src/main/java/it/cnr/isti/epasmed/web/rest/epas/EPASTimeCardsResource.java @@ -0,0 +1,75 @@ +package it.cnr.isti.epasmed.web.rest.epas; + +import java.util.List; +import java.util.Optional; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +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.ResponseUtil; +import it.cnr.isti.epasmed.epas.model.EPASPersons; +import it.cnr.isti.epasmed.epas.model.EPASTimeCards; +import it.cnr.isti.epasmed.epas.service.EPASTimeCardsService; + +@RestController +@RequestMapping("/api/epas") +public class EPASTimeCardsResource { + + private final Logger log = LoggerFactory.getLogger(getClass()); + + @Value("${jhipster.clientApp.name}") + private String applicationName; + + private final EPASTimeCardsService epasTimeCardsService; + + public EPASTimeCardsResource(EPASTimeCardsService epasTimeCardsService) { + this.epasTimeCardsService = epasTimeCardsService; + + } + + /** + * {@code GET /timecards/show} : get time card by personId, year and month. + * + * @param personId the id of the persons. + * @param year the year + * @param month the month + * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body + * the EPAS Time Card, or with status {@code 404 (Not Found)}. + */ + @GetMapping("/timecards/show") + public ResponseEntity getEPASTimeCardByPersonId(@RequestParam("personId") String id, + @RequestParam("year") String year, @RequestParam("month") String month) { + log.info("REST request to get ePAS TimeCard by Person Id: personId={}, year={}, month={}", id,year,month); + EPASTimeCards epasTimeCard = epasTimeCardsService.getTimeCardByPersonId(id, year, month); + log.info("Retrieved TimeCard: {}", epasTimeCard); + return ResponseUtil.wrapOrNotFound(Optional.of(epasTimeCard)); + + } + + + /** + * {@code GET /timecards} : get the time cards list. + * + * @param officeCodeId the id of the office. + * @param year the year + * @param month the month + * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body + * the EPAS Time Card, or with status {@code 404 (Not Found)}. + */ + @GetMapping("/timecards") + public ResponseEntity> getEPASTimeCardByOfficeCodeId(@RequestParam("officeCodeId") String id, + @RequestParam("year") String year, @RequestParam("month") String month) { + log.info("REST request to get ePAS TimeCard list: officeCodeId={}, year={}, month={}", id,year,month); + List epasTimeCardsList = epasTimeCardsService.getTimeCardByOfficeCodeId(id, year, month); + return ResponseUtil.wrapOrNotFound(Optional.of(epasTimeCardsList)); + + } + +} diff --git a/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASTimeCardsResourceIT.java b/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASTimeCardsResourceIT.java new file mode 100644 index 0000000..2c6bd2c --- /dev/null +++ b/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASTimeCardsResourceIT.java @@ -0,0 +1,62 @@ +package it.cnr.isti.epasmed.web.rest.epas; + +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 EPASPersonsResource} REST controller. + */ +@AutoConfigureMockMvc +@WithMockUser(authorities = AuthoritiesConstants.ADMIN) +@SpringBootTest(classes = EpasmedApp.class) +@EnabledIf("false") +public class EPASTimeCardsResourceIT { + + 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"; + + + @Autowired + private MockMvc restEPASTimeCardsMockMvc; + + @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 getTimeCardByPersonId() throws Exception { + restEPASTimeCardsMockMvc.perform(get("/api/epas/timecards/show?personId=113&year=2021&month=11")).andExpect(status().isOk()); + } + + @Test + public void getTimeCardByOfficeCodeId() throws Exception { + restEPASTimeCardsMockMvc.perform(get("/api/epas/timecards?officeCodeId="+OFFICE_DEFAULT_CODEID+"&year=2021&month=11")).andExpect(status().isOk()); + } + +}