Updated TimeCards support
This commit is contained in:
parent
fe3949d77d
commit
9f3f0afe32
|
@ -146,7 +146,7 @@ public class EpasMedDataSourceConfiguration {
|
||||||
|
|
||||||
|
|
||||||
properties.put("hibernate.hbm2ddl.auto","none");
|
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);
|
em.setJpaPropertyMap(properties);
|
||||||
return em;
|
return em;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<String, String> 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<EPASTimeCards> getTimeCardByOfficeCodeId(String id, String year, String month) {
|
||||||
|
Map<String, String> uriVariables = new HashMap<>();
|
||||||
|
uriVariables.put("sedeId", id);
|
||||||
|
uriVariables.put("year", year);
|
||||||
|
uriVariables.put("month", month);
|
||||||
|
|
||||||
|
ResponseEntity<List<EPASTimeCards>> responseEntity = rt.exchange(
|
||||||
|
appProps.getDatasourceEpasRest().getRestUrl() + "/v3/persondays/getmonthsituationbyoffice?sedeId={sedeId}&year={year}&month={month}", HttpMethod.GET, null,
|
||||||
|
new ParameterizedTypeReference<List<EPASTimeCards>>() {
|
||||||
|
}, uriVariables);
|
||||||
|
List<EPASTimeCards> listEPASTimeCards = responseEntity.getBody();
|
||||||
|
log.info("Retrieved EPASTimeCards: {}", listEPASTimeCards);
|
||||||
|
return listEPASTimeCards;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
|
||||||
|
}
|
|
@ -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<EPASTimeCards> getTimeCardByOfficeCodeId(String id, String year, String month) {
|
||||||
|
return epasTimeCardsClient.getTimeCardByOfficeCodeId(id, year, month);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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<EPASTimeCards> 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<List<EPASTimeCards>> 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<EPASTimeCards> epasTimeCardsList = epasTimeCardsService.getTimeCardByOfficeCodeId(id, year, month);
|
||||||
|
return ResponseUtil.wrapOrNotFound(Optional.of(epasTimeCardsList));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue