+ * {@inheritDoc}
+ */
+ @Override
+ public AppRelatedPushClient reload(final String appId, final AppRelatedPushClient oldAppRelatedPushClient) throws Exception {
+ final AppCredentialsEntity credentials = appCredentialsRepository.findFirstByAppId(appId).orElse(null);
+ if (credentials == null) {
+ logger.warn("AppCredentials does not exist anymore for app: {}", appId);
+ return null;
+ }
+
+ final LocalDateTime lastUpdatedInDb = credentials.getTimestampLastUpdated();
+ final LocalDateTime lastUpdatedInCache = oldAppRelatedPushClient.getAppCredentials().getTimestampLastUpdated();
+ if (Objects.equals(lastUpdatedInCache, lastUpdatedInDb)) {
+ logger.debug("LastUpdated is same for app: {}", appId);
+ return oldAppRelatedPushClient;
+ }
+
+ logger.debug("LastUpdated differs for app: {}", appId);
+ return createPushClient(credentials);
+ }
+
+ @Override
+ public AppRelatedPushClient load(final String appId) throws Exception {
+ final AppCredentialsEntity credentials = appCredentialsRepository.findFirstByAppId(appId).orElse(null);
+ if (credentials == null) {
+ logger.warn("AppCredentials does not exist for app: {}", appId);
+ return null;
+ }
+
+ return createPushClient(credentials);
+ }
+
+ private AppRelatedPushClient createPushClient(final AppCredentialsEntity credentials) throws PushServerException {
+ logger.info("Creating APNS, FCM, and HMS clients for app: {}", credentials.getAppId());
+
+ final AppRelatedPushClient pushClient = new AppRelatedPushClient();
+ pushClient.setAppCredentials(credentials);
+
+ if (credentials.getIosPrivateKey() != null) {
+ final ApnsClient apnsClient = pushSendingWorker.prepareApnsClient(credentials);
+ pushClient.setApnsClient(apnsClient);
+ }
+
+ if (credentials.getAndroidPrivateKey() != null) {
+ final FcmClient fcmClient = pushSendingWorker.prepareFcmClient(credentials.getAndroidProjectId(), credentials.getAndroidPrivateKey());
+ pushClient.setFcmClient(fcmClient);
+ }
+
+ if (credentials.getHmsClientId() != null) {
+ final HmsClient hmsClient = pushSendingWorker.prepareHmsClient(credentials);
+ pushClient.setHmsClient(hmsClient);
+ }
+
+ return pushClient;
+ }
+}
diff --git a/powerauth-push-server/src/main/java/io/getlime/push/service/PushMessageSenderService.java b/powerauth-push-server/src/main/java/io/getlime/push/service/PushMessageSenderService.java
index 77b8e21bc..7bda96d9e 100644
--- a/powerauth-push-server/src/main/java/io/getlime/push/service/PushMessageSenderService.java
+++ b/powerauth-push-server/src/main/java/io/getlime/push/service/PushMessageSenderService.java
@@ -16,7 +16,7 @@
package io.getlime.push.service;
-import com.eatthepath.pushy.apns.ApnsClient;
+import com.github.benmanes.caffeine.cache.LoadingCache;
import io.getlime.push.configuration.PushServiceConfiguration;
import io.getlime.push.errorhandling.exceptions.PushServerException;
import io.getlime.push.model.entity.*;
@@ -30,12 +30,8 @@
import io.getlime.push.repository.model.Platform;
import io.getlime.push.repository.model.PushDeviceRegistrationEntity;
import io.getlime.push.repository.model.PushMessageEntity;
-import io.getlime.push.service.batch.storage.AppCredentialStorageMap;
-import io.getlime.push.service.fcm.FcmClient;
-import io.getlime.push.service.hms.HmsClient;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;
@@ -46,42 +42,18 @@
*
* @author Petr Dvorak, petr@wultra.com
*/
+@Slf4j
+@AllArgsConstructor
@Service
public class PushMessageSenderService {
- private static final Logger logger = LoggerFactory.getLogger(PushMessageSenderService.class);
-
private final PushSendingWorker pushSendingWorker;
private final AppCredentialsRepository appCredentialsRepository;
private final PushDeviceRepository pushDeviceRepository;
private final PushMessageDAO pushMessageDAO;
- private final AppCredentialStorageMap appRelatedPushClientMap;
+ private final LoadingCache