From 5c2372bc9c3bd5ac085c587f394d6f5bec7dbea7 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Thu, 16 Dec 2021 18:01:51 +0100 Subject: [PATCH] Updated Orario support --- .../sistemainformativo/model/SIOrario.java | 3 +- .../repository/SIMasterLogRepository.java | 7 +- .../repository/SIOrarioRepository.java | 6 +- .../service/SIMasterLogService.java | 12 +-- .../it/cnr/isti/epasmed/sync/SyncService.java | 77 +++++++++++++++---- .../web/rest/{ => sync}/SyncResource.java | 2 +- .../rest/epas/EPASStampingsResourceIT.java | 6 +- .../epas/EPASWorkingTimeTypesResourceIT.java | 12 +-- .../epasmed/web/rest/sync/SyncResourceIT.java | 12 ++- 9 files changed, 94 insertions(+), 43 deletions(-) rename src/main/java/it/cnr/isti/epasmed/web/rest/{ => sync}/SyncResource.java (98%) diff --git a/src/main/java/it/cnr/isti/epasmed/sistemainformativo/model/SIOrario.java b/src/main/java/it/cnr/isti/epasmed/sistemainformativo/model/SIOrario.java index f9944a3..b81a812 100644 --- a/src/main/java/it/cnr/isti/epasmed/sistemainformativo/model/SIOrario.java +++ b/src/main/java/it/cnr/isti/epasmed/sistemainformativo/model/SIOrario.java @@ -15,7 +15,8 @@ public class SIOrario implements Serializable { private static final long serialVersionUID = 1L; private Long id; private String descrizione; - private String flag; + private Boolean orizontale; + private Boolean disabled; private Timestamp data_mod; private String flag_del; private Long id_flusso; 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 83a4bb3..210d3f6 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 @@ -74,8 +74,11 @@ public class SIMasterLogRepository { public Long startFluxWrites() throws Exception { logger.info("Iniziato Flusso in scrittura"); - jdbcTemplate.update("INSERT INTO master_log (codice_flusso, tabelle, operazione, data_inizio_oper) \"\n" - + " + \"VALUES ('epas','cartellini, cartellini_rendicontazioni, festivita, pers_orario, lavoro_fuori_sede','S',current_timestamp)"); + jdbcTemplate.update("INSERT INTO master_log (codice_flusso, tabelle, operazione, data_inizio_oper)" + + " VALUES ('epas','epas_cartellini, epas_cartellini_rendicontazioni, epas_festivita," + + " epas_orario, epas_pers_orario," + + " epas_lavoro_fuori_sede'," + + " 'S',current_timestamp)"); logger.info("Flusso in scrittura aperto"); String query = "SELECT id_flusso FROM master_log" + " WHERE codice_flusso='epas' AND operazione='S'" diff --git a/src/main/java/it/cnr/isti/epasmed/sistemainformativo/repository/SIOrarioRepository.java b/src/main/java/it/cnr/isti/epasmed/sistemainformativo/repository/SIOrarioRepository.java index 3c2b57d..a324afc 100644 --- a/src/main/java/it/cnr/isti/epasmed/sistemainformativo/repository/SIOrarioRepository.java +++ b/src/main/java/it/cnr/isti/epasmed/sistemainformativo/repository/SIOrarioRepository.java @@ -26,10 +26,10 @@ public class SIOrarioRepository { public void writeNewFlux(Long fluxId, SIOrario siOrario) { jdbcTemplate.update( - "INSERT INTO epas_orario (id,descrizione,flag,data_mod,flag_del,id_flusso)" - + " VALUES (?,?,?,?,?,?)", + "INSERT INTO epas_orario (id,descrizione,orizontale,disabilitato,data_mod,flag_del,id_flusso)" + + " VALUES (?,?,?,?,?,?,?)", siOrario.getId(), siOrario.getDescrizione(), - siOrario.getFlag(), siOrario.getData_mod(), + siOrario.getOrizontale(), siOrario.getDisabled(), siOrario.getData_mod(), siOrario.getFlag_del(), fluxId); logger.debug("Writed SIOrario: {}", siOrario); } 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 690d53c..a6f2670 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 @@ -15,7 +15,7 @@ import it.cnr.isti.epasmed.sistemainformativo.repository.SIMasterLogRepository; @Transactional("sistemaInformativoTransactionManager") public class SIMasterLogService { - private final Logger log = LoggerFactory.getLogger(SIMasterLogService.class); + private static final Logger logger = LoggerFactory.getLogger(SIMasterLogService.class); private final SIMasterLogRepository masterLogRepository; @@ -26,27 +26,27 @@ public class SIMasterLogService { public Long count() { - log.debug("Request MasterLog count()"); + logger.debug("Request MasterLog count()"); return masterLogRepository.count(); } public void startFluxReads() { - log.debug("Request Start Flux Reads"); + logger.debug("Request Start Flux Reads"); masterLogRepository.startFluxReads(); } public void closeFluxReads(String tabelleLette) throws Exception { - log.debug("Request Close Flux Reads"); + logger.debug("Request Close Flux Reads"); masterLogRepository.closeFluxReads(tabelleLette); } public Long startFluxWrites() throws Exception { - log.debug("Request Start Flux Writes"); + logger.debug("Request Start Flux Writes"); return masterLogRepository.startFluxWrites(); } public void closeFluxWrites(Long fluxId,String tabelleScritte) { - log.debug("Request Close Flux Writes"); + logger.debug("Request Close Flux Writes"); masterLogRepository.closeFluxWrites(fluxId,tabelleScritte); } } \ No newline at end of file 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 fe2e7a0..5e2bb28 100644 --- a/src/main/java/it/cnr/isti/epasmed/sync/SyncService.java +++ b/src/main/java/it/cnr/isti/epasmed/sync/SyncService.java @@ -4,6 +4,8 @@ import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.YearMonth; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; import java.util.Date; import java.util.List; import java.util.Optional; @@ -28,11 +30,13 @@ import it.cnr.isti.epasmed.epas.model.EPASPersonDays; 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.model.EPASWorkingTimeTypes; import it.cnr.isti.epasmed.epas.service.EPASAffiliationsService; import it.cnr.isti.epasmed.epas.service.EPASGroupsService; 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.epas.service.EPASWorkingTimeTypesService; import it.cnr.isti.epasmed.service.TabsSIService; import it.cnr.isti.epasmed.service.TimeCardsReportingService; import it.cnr.isti.epasmed.sistemainformativo.model.SIAnagrafico; @@ -41,6 +45,7 @@ import it.cnr.isti.epasmed.sistemainformativo.model.SICartelliniRendicontazioni; import it.cnr.isti.epasmed.sistemainformativo.model.SIEmail; import it.cnr.isti.epasmed.sistemainformativo.model.SIGruppi; import it.cnr.isti.epasmed.sistemainformativo.model.SIGruppiPers; +import it.cnr.isti.epasmed.sistemainformativo.model.SIOrario; import it.cnr.isti.epasmed.sistemainformativo.model.SITelefoni; import it.cnr.isti.epasmed.sistemainformativo.service.SIAnagraficoService; import it.cnr.isti.epasmed.sistemainformativo.service.SICartelliniRendicontazioniService; @@ -49,6 +54,7 @@ import it.cnr.isti.epasmed.sistemainformativo.service.SIEmailService; import it.cnr.isti.epasmed.sistemainformativo.service.SIGruppiPersService; import it.cnr.isti.epasmed.sistemainformativo.service.SIGruppiService; import it.cnr.isti.epasmed.sistemainformativo.service.SIMasterLogService; +import it.cnr.isti.epasmed.sistemainformativo.service.SIOrarioService; import it.cnr.isti.epasmed.sistemainformativo.service.SITelefoniService; @Service @@ -57,6 +63,8 @@ public class SyncService { private static final String ISTI_OFFICE_CODEID = "225200"; private static final String SI_FLAG_DEL_TRUE = "1"; + private static final String SI_FLAG_DEL_FALSE = "0"; + private static final String SI_RECAPITO_TELEFONICO_UFFICIO = "Ufficio"; @SuppressWarnings("unused") private static final String SI_TIPO_EMAIL_ISTITUZIONALE = "Istituzionale"; @@ -85,6 +93,8 @@ public class SyncService { SICartelliniService siCartelliniService; @Autowired SICartelliniRendicontazioniService siCartelliniRendicontazioniService; + @Autowired + SIOrarioService siOrarioService; @Autowired EPASPersonsService epasPersonsService; @@ -94,6 +104,8 @@ public class SyncService { EPASGroupsService epasGroupsService; @Autowired EPASAffiliationsService epasAffiliationsService; + @Autowired + EPASWorkingTimeTypesService epasWorkingTimeTypesService; EPASTimeCardsService epasTimeCardsService; @Autowired @@ -654,10 +666,8 @@ public class SyncService { } return writeTabs; } - + private void writeData(Long fluxId, List tabsSI) { - // TabsSI caretelliniRendicontazioniTab = null; - // TabsSI cartelliniTab = null; for (TabsSI tab : tabsSI) { logger.info("TabSI: {}", tab); @@ -669,21 +679,21 @@ public class SyncService { switch (tab.getNome()) { case "orario": - syncOrario(fluxId,tab); + syncOrario(fluxId, tab); break; // case "pers_orario": - // syncPersOrario(idFlux,tab); + // syncPersOrario(fluxId,tab); + // break; + // case "cartellini": + // break; + // case "cartellini_rendicontazioni": + // syncCartelliniRendicontazioni(fluxId, tab); // break; - case "cartellini": - break; - case "cartellini_rendicontazioni": - syncCartelliniRendicontazioni(fluxId, tab); - break; // case "lavoro_fuori_sede": - // syncLavoroFuoriSede(idFlux,tab); + // syncLavoroFuoriSede(fluxId,tab); // break; // case "aspettative": - // syncAspettative(idFlux,tab); + // syncAspettative(fluxId,tab); // break; default: break; @@ -698,8 +708,41 @@ public class SyncService { logger.error("Invalid Id Flusso for tab: {}", tab); return; } + LocalDateTime lastUpdate = tab.getLastUpdate(); + LocalDateTime maxLastUpdate = null; - + List eWTTs = epasWorkingTimeTypesService.getListByOfficeCodeId(ISTI_OFFICE_CODEID); + for (EPASWorkingTimeTypes eWTT : eWTTs) { + // "2021-02-03T09:49:05.231072" + DateTimeFormatter formatter = new DateTimeFormatterBuilder().parseCaseInsensitive() + .append(DateTimeFormatter.ISO_LOCAL_DATE_TIME).optionalStart().appendPattern(".SSSSSS") + .optionalEnd().optionalStart().appendZoneOrOffsetId().optionalEnd().toFormatter(); + if (eWTT.getUpdatedAt() != null && !eWTT.getUpdatedAt().isEmpty()) { + LocalDateTime updatedAt = LocalDateTime.parse(eWTT.getUpdatedAt(), formatter); + if (lastUpdate.compareTo(updatedAt) < 0) { + Timestamp dataMod = Timestamp.valueOf(updatedAt); + SIOrario siOrario = new SIOrario(Long.valueOf(eWTT.getId()), eWTT.getDescription(), + Boolean.valueOf(eWTT.getHorizontal()), Boolean.valueOf(eWTT.getDisabled()), dataMod, + SI_FLAG_DEL_FALSE, fluxId); + siOrarioService.writeNewFlux(fluxId, siOrario); + + if (maxLastUpdate == null) { + maxLastUpdate = updatedAt; + } else { + if (maxLastUpdate.compareTo(updatedAt) < 0) { + maxLastUpdate = updatedAt; + } + } + } + } + } + + if (maxLastUpdate != null) { + borario = true; + tab.setIdFlusso(fluxId); + tab.setLastUpdate(maxLastUpdate); + tabsSIService.updateTabsSI(tab); + } } private void syncCartelliniRendicontazioni(Long fluxId, TabsSI tab) { @@ -788,16 +831,16 @@ public class SyncService { SICartelliniRendicontazioni siCartelliniRendicontazioni = new SICartelliniRendicontazioni( timeCardsReporting.getId(), timeCardsReporting.getYear(), timeCardsReporting.getMonth(), - Timestamp.valueOf(timeCardsReporting.getLastUpdate()), "0", fluxId); + Timestamp.valueOf(timeCardsReporting.getLastUpdate()), SI_FLAG_DEL_FALSE, fluxId); siCartelliniRendicontazioniService.writeNewFlux(fluxId, siCartelliniRendicontazioni); logger.info("SICartelliniRendicontazioni Updated"); bcartellini_rendicontazioni = true; - bcartellini=true; + bcartellini = true; tab.setIdFlusso(fluxId); - tab.setLastUpdate(LocalDateTime.now()); + tab.setLastUpdate(timeCardsReporting.getLastUpdate()); tabsSIService.updateTabsSI(tab); - + } } diff --git a/src/main/java/it/cnr/isti/epasmed/web/rest/SyncResource.java b/src/main/java/it/cnr/isti/epasmed/web/rest/sync/SyncResource.java similarity index 98% rename from src/main/java/it/cnr/isti/epasmed/web/rest/SyncResource.java rename to src/main/java/it/cnr/isti/epasmed/web/rest/sync/SyncResource.java index 26cdecc..f1353ca 100644 --- a/src/main/java/it/cnr/isti/epasmed/web/rest/SyncResource.java +++ b/src/main/java/it/cnr/isti/epasmed/web/rest/sync/SyncResource.java @@ -1,4 +1,4 @@ -package it.cnr.isti.epasmed.web.rest; +package it.cnr.isti.epasmed.web.rest.sync; import java.net.URISyntaxException; diff --git a/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASStampingsResourceIT.java b/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASStampingsResourceIT.java index fce8cb1..8793861 100644 --- a/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASStampingsResourceIT.java +++ b/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASStampingsResourceIT.java @@ -114,7 +114,7 @@ public class EPASStampingsResourceIT { logger.info(userDirectory); List istiStampings = null; try (Stream stream = Files - .lines(Paths.get("src/test/resources/it/cnr/isti/epasmed/web/rest/epas/timbratureISTI.csv"))) { + .lines(Paths.get("src/test/resources/it/cnr/isti/epasmed/web/rest/epas/timbratureRapisardaISTI.csv"))) { istiStampings = stream.skip(1).map(istiMapToStampingsDTO).collect(Collectors.toList()); } catch (Exception e) { logger.error(e.getLocalizedMessage(), e); @@ -214,7 +214,7 @@ public class EPASStampingsResourceIT { logger.info(userDirectory); List list = new ArrayList<>(); try (Stream stream = Files - .lines(Paths.get("src/test/resources/it/cnr/isti/epasmed/web/rest/epas/timbratureISTI.csv"))) { + .lines(Paths.get("src/test/resources/it/cnr/isti/epasmed/web/rest/epas/timbratureRapisardaISTI.csv"))) { list = stream.collect(Collectors.toList()); } catch (Exception e) { logger.error(e.getLocalizedMessage(), e); @@ -223,7 +223,7 @@ public class EPASStampingsResourceIT { try { FileWriter writer = new FileWriter( - "src/test/resources/it/cnr/isti/epasmed/web/rest/epas/timbratureISTI2.csv"); + "src/test/resources/it/cnr/isti/epasmed/web/rest/epas/timbratureRapisardaISTI2.csv"); for (String str : list) { writer.write("\""+str+"\"" + System.lineSeparator()); } diff --git a/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASWorkingTimeTypesResourceIT.java b/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASWorkingTimeTypesResourceIT.java index 3371697..7d1d05e 100644 --- a/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASWorkingTimeTypesResourceIT.java +++ b/src/test/java/it/cnr/isti/epasmed/web/rest/epas/EPASWorkingTimeTypesResourceIT.java @@ -36,7 +36,7 @@ import it.cnr.isti.epasmed.security.AuthoritiesConstants; @EnabledIf("false") public class EPASWorkingTimeTypesResourceIT { - private final Logger log = LoggerFactory.getLogger(getClass()); + private static final Logger logger = LoggerFactory.getLogger(EPASWorkingTimeTypesResourceIT.class); //private static final String OFFICE_DEFAULT_ID = "1"; // private static final String OFFICE_DEFAULT_NAME = "ISTI - Pisa"; @@ -52,7 +52,7 @@ public class EPASWorkingTimeTypesResourceIT { @BeforeEach public void initTest() { for (String profileName : environment.getActiveProfiles()) { - log.info("Currently active profile - " + profileName); + logger.info("Currently active profile - " + profileName); } } @@ -64,9 +64,9 @@ public class EPASWorkingTimeTypesResourceIT { EPASWorkingTimeTypes epasWTT = mapper.readValue(result.getResponse().getContentAsString(), new TypeReference() { }); - log.info("EPASWorkingTimeTypes: {}", epasWTT.getDescription()); + logger.info("EPASWorkingTimeTypes: {}", epasWTT.getDescription()); for (EPASWorkingTimeTypeDays d : epasWTT.getWorkingTimeTypeDays()) { - log.info("EPAS WorkingTimeTypeDay: {}", d); + logger.info("EPAS WorkingTimeTypeDay: {}", d); } } @@ -81,9 +81,9 @@ public class EPASWorkingTimeTypesResourceIT { new TypeReference>() { }); - log.info("EPASWorkingTimeTypes: {}", epasWTTList.size()); + logger.info("EPASWorkingTimeTypes: {}", epasWTTList.size()); for (EPASWorkingTimeTypes o : epasWTTList) { - log.info("EPAS WorkingTimeType: {}", o); + logger.info("EPAS WorkingTimeType: {}", o); } } diff --git a/src/test/java/it/cnr/isti/epasmed/web/rest/sync/SyncResourceIT.java b/src/test/java/it/cnr/isti/epasmed/web/rest/sync/SyncResourceIT.java index 75ff306..fb64ad0 100644 --- a/src/test/java/it/cnr/isti/epasmed/web/rest/sync/SyncResourceIT.java +++ b/src/test/java/it/cnr/isti/epasmed/web/rest/sync/SyncResourceIT.java @@ -1,7 +1,6 @@ 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; +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; @@ -18,7 +17,6 @@ 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. @@ -50,7 +48,13 @@ public class SyncResourceIT { @Test public void syncReads() throws Exception { - restSyncMockMvc.perform(post("/api/sync/reads").with(csrf())) + restSyncMockMvc.perform(get("/api/sync/reads")) + .andExpect(status().is2xxSuccessful()); + } + + @Test + public void syncWrites() throws Exception { + restSyncMockMvc.perform(get("/api/sync/writes")) .andExpect(status().is2xxSuccessful()); }