diff --git a/src/main/java/it/gov/pagopa/node/cfgsync/service/ApiConfigCacheService.java b/src/main/java/it/gov/pagopa/node/cfgsync/service/ApiConfigCacheService.java index 73c96a1..4d6b4b4 100644 --- a/src/main/java/it/gov/pagopa/node/cfgsync/service/ApiConfigCacheService.java +++ b/src/main/java/it/gov/pagopa/node/cfgsync/service/ApiConfigCacheService.java @@ -42,8 +42,8 @@ public class ApiConfigCacheService extends CommonCacheService { private final ApiConfigCacheClient apiConfigCacheClient; - @Autowired - private PagoPACachePostgreRepository pagoPACachePostgreRepository; + @Autowired(required = false) + private Optional pagoPACachePostgreRepository; @Autowired(required = false) private Optional nexiCachePostgreRepository; @Autowired(required = false) @@ -98,8 +98,8 @@ public Map forceCacheUpdate() { ConfigCache configCache = composeCache(cacheId, ZonedDateTime.parse(cacheTimestamp).toLocalDateTime(), cacheVersion, response.body().asInputStream().readAllBytes()); try { - if( pagopaPostgreCacheEnabled ) { - pagoPACachePostgreRepository.save(configCache); + if( pagopaPostgreCacheEnabled && pagoPACachePostgreRepository.isPresent() ) { + pagoPACachePostgreRepository.get().save(configCache); syncStatusMap.put(pagopaPostgreServiceIdentifier, SyncStatusEnum.done); } else { syncStatusMap.put(pagopaPostgreServiceIdentifier, SyncStatusEnum.disabled); @@ -107,24 +107,24 @@ public Map forceCacheUpdate() { } catch(Exception ex) { syncStatusMap.put(pagopaPostgreServiceIdentifier, SyncStatusEnum.error); } -// try { -// if (nexiPostgreCacheEnabled) { -// nexiCachePostgreRepository.save(configCache); -// } else { -// syncStatusMap.put(nexiPostgreServiceIdentifier, SyncStatusEnum.disabled); -// } -// } catch(Exception ex) { -// syncStatusMap.put(nexiPostgreServiceIdentifier, SyncStatusEnum.error); -// } -// try { -// if( nexiOracleCacheEnabled ) { -// nexiCacheOracleRepository.save(configCache); -// } else { -// syncStatusMap.put(nexiOracleServiceIdentifier, SyncStatusEnum.disabled); -// } -// } catch(Exception ex) { -// syncStatusMap.put(nexiOracleServiceIdentifier, SyncStatusEnum.error); -// } + try { + if ( nexiPostgreCacheEnabled && nexiCachePostgreRepository.isPresent() ) { + nexiCachePostgreRepository.get().save(configCache); + } else { + syncStatusMap.put(nexiPostgreServiceIdentifier, SyncStatusEnum.disabled); + } + } catch(Exception ex) { + syncStatusMap.put(nexiPostgreServiceIdentifier, SyncStatusEnum.error); + } + try { + if( nexiOracleCacheEnabled && nexiCacheOracleRepository.isPresent() ) { + nexiCacheOracleRepository.get().save(configCache); + } else { + syncStatusMap.put(nexiOracleServiceIdentifier, SyncStatusEnum.disabled); + } + } catch(Exception ex) { + syncStatusMap.put(nexiOracleServiceIdentifier, SyncStatusEnum.error); + } } catch (FeignException.GatewayTimeout e) { log.error("SyncService api-config-cache get cache error: Gateway timeout", e); throw new AppException(AppError.INTERNAL_SERVER_ERROR); diff --git a/src/main/java/it/gov/pagopa/node/cfgsync/service/StandInManagerService.java b/src/main/java/it/gov/pagopa/node/cfgsync/service/StandInManagerService.java index 2acd316..7e014f6 100644 --- a/src/main/java/it/gov/pagopa/node/cfgsync/service/StandInManagerService.java +++ b/src/main/java/it/gov/pagopa/node/cfgsync/service/StandInManagerService.java @@ -87,7 +87,7 @@ public Map forceStandIn() { List stationsEntities = stations.getStations().stream().map(StandInStations::new).collect(Collectors.toList()); try { - if (pagopaPostgreStandInEnabled) { + if ( pagopaPostgreStandInEnabled && pagoPAStandInPostgreRepository.isPresent() ) { pagoPAStandInPostgreRepository.get().deleteAll(); pagoPAStandInPostgreRepository.get().saveAll(stationsEntities); syncStatusMap.put(pagopaPostgreServiceIdentifier, SyncStatusEnum.done); @@ -97,28 +97,28 @@ public Map forceStandIn() { } catch(Exception ex) { syncStatusMap.put(pagopaPostgreServiceIdentifier, SyncStatusEnum.error); } -// try { -// if (nexiPostgreStandInEnabled) { -// nexiStandInPostgreRepository.deleteAll(); -// nexiStandInPostgreRepository.saveAll(stationsEntities); -// syncStatusMap.put(nexiPostgreServiceIdentifier, SyncStatusEnum.done); -// } else { -// syncStatusMap.put(nexiPostgreServiceIdentifier, SyncStatusEnum.disabled); -// } -// } catch(Exception ex) { -// syncStatusMap.put(nexiPostgreServiceIdentifier, SyncStatusEnum.error); -// } -// try { -// if( nexiOracleStandInEnabled ) { -// nexiStandInOracleRepository.deleteAll(); -// nexiStandInOracleRepository.saveAll(stationsEntities); -// syncStatusMap.put(nexiOracleServiceIdentifier, SyncStatusEnum.done); -// } else { -// syncStatusMap.put(nexiOracleServiceIdentifier, SyncStatusEnum.disabled); -// } -// } catch(Exception ex) { -// syncStatusMap.put(nexiOracleServiceIdentifier, SyncStatusEnum.error); -// } + try { + if ( nexiPostgreStandInEnabled && nexiStandInPostgreRepository.isPresent() ) { + nexiStandInPostgreRepository.get().deleteAll(); + nexiStandInPostgreRepository.get().saveAll(stationsEntities); + syncStatusMap.put(nexiPostgreServiceIdentifier, SyncStatusEnum.done); + } else { + syncStatusMap.put(nexiPostgreServiceIdentifier, SyncStatusEnum.disabled); + } + } catch(Exception ex) { + syncStatusMap.put(nexiPostgreServiceIdentifier, SyncStatusEnum.error); + } + try { + if( nexiOracleStandInEnabled && nexiStandInOracleRepository.isPresent() ) { + nexiStandInOracleRepository.get().deleteAll(); + nexiStandInOracleRepository.get().saveAll(stationsEntities); + syncStatusMap.put(nexiOracleServiceIdentifier, SyncStatusEnum.done); + } else { + syncStatusMap.put(nexiOracleServiceIdentifier, SyncStatusEnum.disabled); + } + } catch(Exception ex) { + syncStatusMap.put(nexiOracleServiceIdentifier, SyncStatusEnum.error); + } } catch (FeignException.GatewayTimeout e) { log.error("SyncService stand-in-manager get stations error: Gateway timeout", e); throw new AppException(AppError.INTERNAL_SERVER_ERROR);