aboutsummaryrefslogtreecommitdiff
path: root/juick-notifications/src/main/java/com/juick/components/CleanUp.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-12-15 10:34:18 +0300
committerGravatar Vitaly Takmazov2016-12-16 10:52:35 +0300
commitc83e39441243b7db8293f1c161ee203faaf360ef (patch)
treeaa9ce18953e6f0fd69deeb47b69f1d0de8e2fe55 /juick-notifications/src/main/java/com/juick/components/CleanUp.java
parent9ac4c8209b9699e78d0d5cd0753e2fe8edbec559 (diff)
juick-notifications: RestService and GCM cleanup
Diffstat (limited to 'juick-notifications/src/main/java/com/juick/components/CleanUp.java')
-rw-r--r--juick-notifications/src/main/java/com/juick/components/CleanUp.java25
1 files changed, 9 insertions, 16 deletions
diff --git a/juick-notifications/src/main/java/com/juick/components/CleanUp.java b/juick-notifications/src/main/java/com/juick/components/CleanUp.java
index c78b3f77..7b800fec 100644
--- a/juick-notifications/src/main/java/com/juick/components/CleanUp.java
+++ b/juick-notifications/src/main/java/com/juick/components/CleanUp.java
@@ -1,17 +1,11 @@
package com.juick.components;
-import com.juick.TokensList;
+import com.juick.components.service.TokenService;
import com.notnoop.apns.ApnsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.ParameterizedTypeReference;
-import org.springframework.http.HttpEntity;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
-import org.springframework.web.client.RestTemplate;
import javax.inject.Inject;
import java.util.ArrayList;
@@ -28,7 +22,10 @@ public class CleanUp {
@Inject
ApnsService apns;
@Inject
- RestTemplate rest;
+ TokenService tokenService;
+
+ @Inject
+ Notifications push;
@Scheduled(fixedRate = 600000)
public void cleanupTokens() {
@@ -37,16 +34,12 @@ public class CleanUp {
int count = devices.size();
if (count > 0) {
logger.info("{} tokens to delete", count);
- TokensList list = new TokensList();
- list.setType("apns");
- list.setTokens(new ArrayList<>(devices));
- HttpHeaders headers = new HttpHeaders();
- headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
- rest.exchange("http://api.juick.com/notifications",
- HttpMethod.DELETE, new HttpEntity<>(list, headers), new ParameterizedTypeReference<Void>() {
- });
+ tokenService.deleteTokens("apns", new ArrayList<>(devices));
} else {
logger.info("No APNS tokens to delete");
}
+ logger.debug("initializing GCM tokens cleanup: {} tokens", push.getInvalidGCMTokens().size());
+ tokenService.deleteTokens("gcm", push.getInvalidGCMTokens());
+ push.cleanupGCMTokens();
}
}