Added EPAS Absence Types support
This commit is contained in:
parent
b93948790f
commit
04823dc286
|
@ -0,0 +1,47 @@
|
||||||
|
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.EPASAbsenceTypes;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class EPASAbsenceTypesClient {
|
||||||
|
|
||||||
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Qualifier("RestTemplateForSecondUser")
|
||||||
|
RestTemplate rt;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ApplicationProperties appProps;
|
||||||
|
|
||||||
|
public List<EPASAbsenceTypes> getAbsenceTypes() {
|
||||||
|
Map<String, String> uriVariables = new HashMap<>();
|
||||||
|
uriVariables.put("onlyActive", "true");
|
||||||
|
uriVariables.put("used", "true");
|
||||||
|
|
||||||
|
ResponseEntity<List<EPASAbsenceTypes>> responseEntity = rt.exchange(
|
||||||
|
appProps.getDatasourceEpasRest().getRestUrl()
|
||||||
|
+ "/v3/absenceTypes/list?onlyActive={onlyActive}&used={used}",
|
||||||
|
HttpMethod.GET, null, new ParameterizedTypeReference<List<EPASAbsenceTypes>>() {
|
||||||
|
}, uriVariables);
|
||||||
|
List<EPASAbsenceTypes> listEPASAbsenceTypes = responseEntity.getBody();
|
||||||
|
log.info("Retrieved EPASAbsenceTypes: {}", listEPASAbsenceTypes);
|
||||||
|
return listEPASAbsenceTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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 EPASAbsenceTypes implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private String certificateCode;
|
||||||
|
private String code;
|
||||||
|
private String consideredWeekEnd;
|
||||||
|
private String description;
|
||||||
|
private String id;
|
||||||
|
private String internalUse;
|
||||||
|
private String justifiedTime;
|
||||||
|
private String validFrom;
|
||||||
|
private String validTo;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
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.EPASAbsenceTypesClient;
|
||||||
|
import it.cnr.isti.epasmed.epas.model.EPASAbsenceTypes;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class EPASAbsenceTypesService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
EPASAbsenceTypesClient epasAbsenceTypesClient;
|
||||||
|
|
||||||
|
public List<EPASAbsenceTypes> getAbsenceTypes() {
|
||||||
|
return epasAbsenceTypesClient.getAbsenceTypes();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
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.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import io.github.jhipster.web.util.ResponseUtil;
|
||||||
|
import it.cnr.isti.epasmed.epas.model.EPASAbsenceTypes;
|
||||||
|
import it.cnr.isti.epasmed.epas.service.EPASAbsenceTypesService;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/epas")
|
||||||
|
public class EPASAbsenceTypesResource {
|
||||||
|
|
||||||
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
|
@Value("${jhipster.clientApp.name}")
|
||||||
|
private String applicationName;
|
||||||
|
|
||||||
|
private final EPASAbsenceTypesService epasAbsenceTypesService;
|
||||||
|
|
||||||
|
public EPASAbsenceTypesResource(EPASAbsenceTypesService epasAbsenceTypesService) {
|
||||||
|
this.epasAbsenceTypesService = epasAbsenceTypesService;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@code GET /absenceTypes} : get the absence types list.
|
||||||
|
*
|
||||||
|
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body
|
||||||
|
* the list of EPAS Absence Types, or with status
|
||||||
|
* {@code 404 (Not Found)}.
|
||||||
|
*/
|
||||||
|
@GetMapping("/absenceTypes")
|
||||||
|
public ResponseEntity<List<EPASAbsenceTypes>> getEPASAbsencesTypes() {
|
||||||
|
log.debug("REST request GET EPAS Absences Types");
|
||||||
|
List<EPASAbsenceTypes> epasAbsenceTypesList = null;
|
||||||
|
|
||||||
|
epasAbsenceTypesList = epasAbsenceTypesService.getAbsenceTypes();
|
||||||
|
|
||||||
|
return ResponseUtil.wrapOrNotFound(Optional.of(epasAbsenceTypesList));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,84 @@
|
||||||
|
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 java.util.List;
|
||||||
|
|
||||||
|
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 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.model.EPASAbsenceTypes;
|
||||||
|
import it.cnr.isti.epasmed.security.AuthoritiesConstants;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Integration tests for the {@link EPASAbsenceTypesResource} REST controller.
|
||||||
|
*/
|
||||||
|
@AutoConfigureMockMvc
|
||||||
|
@WithMockUser(authorities = AuthoritiesConstants.ADMIN)
|
||||||
|
@SpringBootTest(classes = EpasmedApp.class)
|
||||||
|
@EnabledIf("false")
|
||||||
|
public class EPASAbsenceTypesResourceIT {
|
||||||
|
|
||||||
|
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 restEPASAbsenceTypesMockMvc;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private Environment environment;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void initTest() {
|
||||||
|
for (String profileName : environment.getActiveProfiles()) {
|
||||||
|
log.info("Currently active profile - " + profileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAbsenceTypes() throws Exception {
|
||||||
|
|
||||||
|
List<EPASAbsenceTypes> epasAbsenceTypes = null;
|
||||||
|
try {
|
||||||
|
MvcResult result = restEPASAbsenceTypesMockMvc.perform(get("/api/epas/absenceTypes"))
|
||||||
|
.andExpect(status().isOk()).andReturn();
|
||||||
|
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
epasAbsenceTypes = mapper.readValue(result.getResponse().getContentAsString(),
|
||||||
|
new TypeReference<List<EPASAbsenceTypes>>() {
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getLocalizedMessage(), e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (epasAbsenceTypes != null) {
|
||||||
|
log.info("EPAS Absence Types size: {}", epasAbsenceTypes.size());
|
||||||
|
for (EPASAbsenceTypes type : epasAbsenceTypes) {
|
||||||
|
log.info("{}", type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue