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 index 229f48f..b06f1ef 100644 --- a/src/main/java/it/cnr/isti/epasmed/epas/client/EPASTimeCardsClient.java +++ b/src/main/java/it/cnr/isti/epasmed/epas/client/EPASTimeCardsClient.java @@ -43,6 +43,35 @@ public class EPASTimeCardsClient { return epasTimeCard; } + public EPASTimeCards getByPersonFiscalCode(String fc, String year, String month) { + log.info("Retrieving EPASTimeCard by person fiscalcode: {}", fc); + Map uriVariables = new HashMap<>(); + uriVariables.put("fc", fc); + uriVariables.put("year", year); + uriVariables.put("month", month); + + EPASTimeCards epasTimeCard = rt.getForObject( + appProps.getDatasourceEpasRest().getRestUrl() + "/v3/persondays/getMonthSituationByPerson?fiscalCode={fc}&year={year}&month={month}", + EPASTimeCards.class,uriVariables); + log.info("Retrieved EPASTimeCard: {}", epasTimeCard); + return epasTimeCard; + } + + + public EPASTimeCards getByPersonEmail(String email, String year, String month) { + log.info("Retrieving EPASTimeCard by person email: {}", email); + Map uriVariables = new HashMap<>(); + uriVariables.put("email", email); + uriVariables.put("year", year); + uriVariables.put("month", month); + + EPASTimeCards epasTimeCard = rt.getForObject( + appProps.getDatasourceEpasRest().getRestUrl() + "/v3/persondays/getMonthSituationByPerson?email={email}&year={year}&month={month}", + EPASTimeCards.class,uriVariables); + log.info("Retrieved EPASTimeCard: {}", epasTimeCard); + return epasTimeCard; + } + public List getByOfficeCodeId(String id, String year, String month) { Map uriVariables = new HashMap<>(); @@ -59,6 +88,9 @@ public class EPASTimeCardsClient { return listEPASTimeCards; } + + + } diff --git a/src/main/java/it/cnr/isti/epasmed/epas/client/EPASValidatesClient.java b/src/main/java/it/cnr/isti/epasmed/epas/client/EPASValidatesClient.java index d86c1b7..0d85fd4 100644 --- a/src/main/java/it/cnr/isti/epasmed/epas/client/EPASValidatesClient.java +++ b/src/main/java/it/cnr/isti/epasmed/epas/client/EPASValidatesClient.java @@ -26,7 +26,7 @@ public class EPASValidatesClient { ApplicationProperties appProps; public String isByPersonEmail(String email, String year, String month) { - log.info("Retrieving EPASValidates status for person email: {}", email); + log.info("Retrieving EPASValidates status by person email: {}", email); Map uriVariables = new HashMap<>(); uriVariables.put("email", email); uriVariables.put("year", year); 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 index 94f46b7..9e0563a 100644 --- a/src/main/java/it/cnr/isti/epasmed/epas/service/EPASTimeCardsService.java +++ b/src/main/java/it/cnr/isti/epasmed/epas/service/EPASTimeCardsService.java @@ -18,6 +18,14 @@ public class EPASTimeCardsService { return epasTimeCardsClient.getByPersonId(id, year, month); } + public EPASTimeCards getTimeCardByPersonFiscalCode(String fc, String year, String month) { + return epasTimeCardsClient.getByPersonFiscalCode(fc, year, month); + } + + public EPASTimeCards getTimeCardByPersonEmail(String email, String year, String month) { + return epasTimeCardsClient.getByPersonEmail(email, year, month); + } + public List getTimeCardByOfficeCodeId(String id, String year, String month) { return epasTimeCardsClient.getByOfficeCodeId(id, year, month); } diff --git a/src/main/java/it/cnr/isti/epasmed/sync/SyncService.java b/src/main/java/it/cnr/isti/epasmed/sync/SyncService.java index c4cc94c..763d7fc 100644 --- a/src/main/java/it/cnr/isti/epasmed/sync/SyncService.java +++ b/src/main/java/it/cnr/isti/epasmed/sync/SyncService.java @@ -1,6 +1,7 @@ package it.cnr.isti.epasmed.sync; import java.time.LocalDateTime; +import java.util.GregorianCalendar; import java.util.List; import org.slf4j.Logger; @@ -12,8 +13,11 @@ import it.cnr.isti.epasmed.domain.TabsSI; import it.cnr.isti.epasmed.epas.dto.EPASPersonsDTO; import it.cnr.isti.epasmed.epas.mapper.EPASPersonsMapper; import it.cnr.isti.epasmed.epas.model.EPASPersons; +import it.cnr.isti.epasmed.epas.model.EPASTimeCards; +import it.cnr.isti.epasmed.epas.model.EPASValidates; import it.cnr.isti.epasmed.epas.service.EPASPersonsService; import it.cnr.isti.epasmed.epas.service.EPASTimeCardsService; +import it.cnr.isti.epasmed.epas.service.EPASValidatesService; import it.cnr.isti.epasmed.service.TabsSIService; import it.cnr.isti.epasmed.sistemainformativo.model.SIAnagrafico; import it.cnr.isti.epasmed.sistemainformativo.model.SIEmail; @@ -26,6 +30,8 @@ import it.cnr.isti.epasmed.sistemainformativo.service.SITelefoniService; @Service public class SyncService { private static final String ISTI_OFFICE_ID = "1"; + private static final String ISTI_OFFICE_CODEID = "225200"; + private static final String SI_FLAG_DEL_TRUE = "1"; private static final String SI_RECAPITO_TELEFONICO_UFFICIO = "Ufficio"; @SuppressWarnings("unused") @@ -51,9 +57,10 @@ public class SyncService { @Autowired EPASPersonsMapper epasPersonsMapper; @Autowired + EPASTimeCardsService epasTimeCardsService; - - + @Autowired + EPASValidatesService epasValidatesService; private boolean banagrafico; private boolean bemail; @@ -421,7 +428,7 @@ public class SyncService { TabsSI cartelliniTab = null; - /* + for (TabsSI tab : tabsSI) { log.info("TabSI: {}", tab); if (tab.getOperazioni() != null && !tab.getOperazioni().isEmpty() @@ -431,31 +438,62 @@ public class SyncService { } switch (tab.getNome()) { - case "orario": - syncOrario(idFlux,tab); - break; - case "pers_orario": - syncPersOrario(idFlux,tab); - break; + //case "orario": + // syncOrario(idFlux,tab); + // break; + //case "pers_orario": + // syncPersOrario(idFlux,tab); + // break; case "cartellini": break; case "cartellini_rendicontazioni": syncCartelliniRendicontazioni(idFlux,tab); - break; - - case "lavoro_fuori_sede": - syncLavoroFuoriSede(idFlux,tab); - break; - case "aspettative": - syncAspettative(idFlux,tab); - break; + break; + //case "lavoro_fuori_sede": + // syncLavoroFuoriSede(idFlux,tab); + // break; + //case "aspettative": + // syncAspettative(idFlux,tab); + // break; default: break; } } - }*/ + } } - - + + private void syncCartelliniRendicontazioni(Long idFlux, TabsSI tab) { + if (tab.getIdFlusso() == null || tab.getIdFlusso().longValue() == 0) { + log.info("Invalid Id Flusso for tab: {}", tab); + return; + } + long maxIdFlusso = 0; + + GregorianCalendar lastMonthSent=new GregorianCalendar(2021,11,1); + GregorianCalendar nextMonthToSent=new GregorianCalendar(); + nextMonthToSent.setTime(lastMonthSent.getTime()); + nextMonthToSent.add(GregorianCalendar.MONTH, 1); + String y=String.valueOf(nextMonthToSent.get(GregorianCalendar.YEAR)); + String m=String.valueOf(nextMonthToSent.get(GregorianCalendar.YEAR)); + EPASValidates epasValidates=epasValidatesService.getValidatesByOfficeCodeId(ISTI_OFFICE_CODEID, y, + m); + + if(!epasValidates.getAllCertificationsValidated()) { + log.info("No new month closed on EPAS: [year={}, month={}]", y,m); + return; + } + + //TODO + log.info("Certifications Validated: [year={}, month={}]",y,m); + for(EPASPersons person:epasValidates.getValidatedPersons()) { + log.info("Writing TimeCard for Person: {}",person); + EPASTimeCards epasTimeCards=epasTimeCardsService.getTimeCardByPersonEmail(person.getEmail(), y, m); + + } + + + + } + } 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 a45111a..139b90f 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 @@ -12,7 +12,9 @@ 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.model.EPASCertifications; import it.cnr.isti.epasmed.epas.model.EPASTimeCards; import it.cnr.isti.epasmed.epas.service.EPASTimeCardsService; @@ -31,29 +33,53 @@ public class EPASTimeCardsResource { 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 + * {@code GET /timecards/byPerson} : get time card by person, year and month + * + * @param id the id of the person. + * @param fiscalCode the fiscal code of the person. + * @param email the email of the person. + * @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)}. + * the EPAS TimeCards, 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)); - + @GetMapping("/timecards/byPerson") + public ResponseEntity getEPASCertificationByPerson(@RequestParam("id") Optional id, + @RequestParam("fiscalCode") Optional fiscalCode, + @RequestParam("email") Optional email, + @RequestParam("year") String year,@RequestParam("month") String month) { + + + EPASTimeCards epasTimeCards = null; + if (id.isPresent()) { + log.info("REST request to get ePAS TimeCards by Person id: {}", id.get()); + epasTimeCards = epasTimeCardsService.getTimeCardByPersonId(id.get(), year, month); + } else { + if (fiscalCode.isPresent()) { + log.info("REST request to get ePAS TimeCards by Person fiscalcode: {}", fiscalCode.get()); + epasTimeCards = epasTimeCardsService.getTimeCardByPersonFiscalCode(fiscalCode.get(), year, month); + } else { + if (email.isPresent()) { + log.info("REST request to get ePAS TimeCards by Person email: {}", email.get()); + epasTimeCards = epasTimeCardsService.getTimeCardByPersonEmail(email.get(), year, month); + } else { + return ResponseUtil.wrapOrNotFound(Optional.of(epasTimeCards), HeaderUtil.createFailureAlert(applicationName,false, + "","","Invalid parameter in call")); + + } + } + } + log.info("Retrieved Certification: {}", epasTimeCards); + return ResponseUtil.wrapOrNotFound(Optional.of(epasTimeCards)); } + + /** - * {@code GET /timecards} : get the time cards list. + * {@code GET /timecards/byOffice} : get the time cards list. * * @param officeCodeId the id of the office. * @param year the year @@ -61,8 +87,8 @@ public class EPASTimeCardsResource { * @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, + @GetMapping("/timecards/byOffice") + public ResponseEntity> getEPASTimeCardByOffice(@RequestParam("codeId") 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); diff --git a/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASCertificationsResourceIT.java b/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASCertificationsResourceIT.java index f54815d..e6890a2 100644 --- a/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASCertificationsResourceIT.java +++ b/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASCertificationsResourceIT.java @@ -24,7 +24,7 @@ import it.cnr.isti.epasmed.security.AuthoritiesConstants; @AutoConfigureMockMvc @WithMockUser(authorities = AuthoritiesConstants.ADMIN) @SpringBootTest(classes = EpasmedApp.class) -@EnabledIf("false") +@EnabledIf("true") public class EPASCertificationsResourceIT { private final Logger log = LoggerFactory.getLogger(getClass()); @@ -59,7 +59,7 @@ public class EPASCertificationsResourceIT { @Test public void getEPASCertificationsByPersonId() throws Exception { - restEPASCertificationsMockMvc.perform(get("/api/epas/certifications/getMonthSituation?id=" + PERSON_DEFAULT_ID + "&year=2021&month=10")) + restEPASCertificationsMockMvc.perform(get("/api/epas/certifications/getMonthSituation?id=" + PERSON_DEFAULT_ID + "&year=2021&month=11")) .andExpect(status().isOk()); } @@ -67,14 +67,14 @@ public class EPASCertificationsResourceIT { public void getEPASCertificationsByPersonFiscalcode() throws Exception { restEPASCertificationsMockMvc .perform( - get("/api/epas/certifications/getMonthSituation?fiscalCode=" + PERSON_DEFAULT_FISCAL_CODE + "&year=2021&month=10")) + get("/api/epas/certifications/getMonthSituation?fiscalCode=" + PERSON_DEFAULT_FISCAL_CODE + "&year=2021&month=11")) .andExpect(status().isOk()); } @Test public void getEPASCertificationsByPersonEmail() throws Exception { restEPASCertificationsMockMvc - .perform(get("/api/epas/certifications/getMonthSituation?email=" + PERSON_DEFAULT_EMAIL + "&year=2021&month=10")) + .perform(get("/api/epas/certifications/getMonthSituation?email=" + PERSON_DEFAULT_EMAIL + "&year=2021&month=11")) .andExpect(status().isOk()); } diff --git a/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASLeavesResourceIT.java b/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASLeavesResourceIT.java index ac44278..df8aedb 100644 --- a/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASLeavesResourceIT.java +++ b/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASLeavesResourceIT.java @@ -24,7 +24,7 @@ import it.cnr.isti.epasmed.security.AuthoritiesConstants; @AutoConfigureMockMvc @WithMockUser(authorities = AuthoritiesConstants.ADMIN) @SpringBootTest(classes = EpasmedApp.class) -@EnabledIf("false") +@EnabledIf("true") public class EPASLeavesResourceIT { private final Logger log = LoggerFactory.getLogger(getClass()); 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..02eec24 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 @@ -46,7 +46,7 @@ import it.cnr.isti.epasmed.web.rest.TestUtil; @AutoConfigureMockMvc @WithMockUser(authorities = AuthoritiesConstants.ADMIN) @SpringBootTest(classes = EpasmedApp.class) -@EnabledIf("false") +@EnabledIf("true") public class EPASPersonsResourceIT { private final Logger log = LoggerFactory.getLogger(getClass()); 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 index 32c22d3..3789bf3 100644 --- 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 @@ -24,7 +24,7 @@ import it.cnr.isti.epasmed.security.AuthoritiesConstants; @AutoConfigureMockMvc @WithMockUser(authorities = AuthoritiesConstants.ADMIN) @SpringBootTest(classes = EpasmedApp.class) -@EnabledIf("false") +@EnabledIf("true") public class EPASTimeCardsResourceIT { private final Logger log = LoggerFactory.getLogger(getClass()); @@ -34,6 +34,12 @@ public class EPASTimeCardsResourceIT { //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"; @Autowired private MockMvc restEPASTimeCardsMockMvc; @@ -51,12 +57,22 @@ public class EPASTimeCardsResourceIT { @Test public void getTimeCardByPersonId() throws Exception { - restEPASTimeCardsMockMvc.perform(get("/api/epas/timecards/show?personId=113&year=2021&month=11")).andExpect(status().isOk()); + restEPASTimeCardsMockMvc.perform(get("/api/epas/timecards/byPerson?id="+PERSON_DEFAULT_ID+"&year=2021&month=11")).andExpect(status().isOk()); + } + + @Test + public void getTimeCardByPersonFiscalCode() throws Exception { + restEPASTimeCardsMockMvc.perform(get("/api/epas/timecards/byPerson?fiscalCode="+PERSON_DEFAULT_FISCAL_CODE+"&year=2021&month=11")).andExpect(status().isOk()); + } + + @Test + public void getTimeCardByPersonEmail() throws Exception { + restEPASTimeCardsMockMvc.perform(get("/api/epas/timecards/byPerson?email="+PERSON_DEFAULT_EMAIL+"&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()); + restEPASTimeCardsMockMvc.perform(get("/api/epas/timecards/byOffice?codeId="+OFFICE_DEFAULT_CODEID+"&year=2021&month=11")).andExpect(status().isOk()); } } diff --git a/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASValidatesResourceIT.java b/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASValidatesResourceIT.java index ad88483..1ad6eaf 100644 --- a/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASValidatesResourceIT.java +++ b/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASValidatesResourceIT.java @@ -30,7 +30,7 @@ import it.cnr.isti.epasmed.security.AuthoritiesConstants; @AutoConfigureMockMvc @WithMockUser(authorities = AuthoritiesConstants.ADMIN) @SpringBootTest(classes = EpasmedApp.class) -@EnabledIf("false") +@EnabledIf("true") public class EPASValidatesResourceIT { private final Logger log = LoggerFactory.getLogger(getClass()); @@ -67,7 +67,7 @@ public class EPASValidatesResourceIT { @Test public void getEPASValidatesByOfficeCodeId() throws Exception { MvcResult result = restEPASValidatesMockMvc.perform(get("/api/epas/validates?officeCodeId="+OFFICE_DEFAULT_CODEID+"&" - + "year=2021&month=10")).andExpect(status().isOk()).andReturn(); + + "year=2021&month=11")).andExpect(status().isOk()).andReturn(); ObjectMapper mapper = new ObjectMapper(); EPASValidates validates = mapper.readValue(result.getResponse().getContentAsString(), new TypeReference() {