-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostIOSNotification.java
More file actions
115 lines (89 loc) · 3.75 KB
/
Copy pathPostIOSNotification.java
File metadata and controls
115 lines (89 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package com.app;
import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.commons.io.FileUtils;
import com.cisco.brmspega.servlet.StoreIOSDeviceToken;
import com.notnoop.apns.APNS;
import com.notnoop.apns.ApnsService;
import com.notnoop.apns.ApnsServiceBuilder;
import com.notnoop.apns.PayloadBuilder;
public class PostIOSNotification {
public String sendNotification(String sType,String lifeCycle,String domain,String sr_id) throws IOException {
// TODO Auto-generated method stub
String message = "Failed";
String payload = null;
String notificationBody;
/*ApnsService service = APNS.newService().withCert("/CiscoJars/ibpmcertificate.p12", "cisco123")
.withSandboxDestination()
.build();*/
ApnsService service = APNS.newService().withCert("/opt/brms/shared/brmsclient.jks", "password")
.withSandboxDestination()
.build();
if (sType != null && sType.equalsIgnoreCase("mon") && domain != null) {
if ( lifeCycle != null && lifeCycle.equalsIgnoreCase("prod")) {
notificationBody = "TESTING :: Cisco IBPM Mon Notification. Domain(s):" + domain +" are down.";
} else {
notificationBody = "TESTING :: Cisco IBPM Mon Notification."+ lifeCycle + "-Domain(s):" + domain +" are down.";
}
payload = APNS.newPayload().alertBody(notificationBody)
.badge(1)
.customField("Identifier", "monitor")
.build();
} else if (sType != null && sType.equalsIgnoreCase("status") && domain != null && sr_id != null ) {
notificationBody = "Cisco IBPM Status Notification. Domain:" + domain +" SR_ID:" +sr_id;
payload = APNS.newPayload().alertBody(notificationBody)
.badge(1)
.customField("Identifier", "status")
.customField("Domain", domain)
.customField("sr_id", sr_id)
.build();
}
List<String> tokenList = new ArrayList<String>();
//StoreIOSDeviceToken getIOSToken = new StoreIOSDeviceToken();
//List<String> tokenList = getIOSToken.iosDeviceTokenList;
//tokenList.add("59f9b03cbcf269449e0994aaf449f9505ff658cd557271f79b739fd729e21103");
//tokenList.add("dc09fe83c5f68ace0d97491e100f170473199cfa7dba2417180b65fe9ac3b76e");
//String token = "59f9b03cbcf269449e0994aaf449f9505ff658cd557271f79b739fd729e21103";
tokenList = get_device_token_list();
if (payload != null && !tokenList.isEmpty()) {
for (String token : tokenList) {
service.push(token, payload);
message = "success";
}
service.testConnection();
Map<String, Date> inactiveDevices = service.getInactiveDevices();
for (String deviceToken : inactiveDevices.keySet()) {
Date inactiveAsOf = inactiveDevices.get(deviceToken);
System.out.println(deviceToken);
System.out.println(inactiveAsOf);
}
}
return message;
}
public List<String> get_device_token_list() throws IOException {
List<String> deviceTokeList = new ArrayList<String>();
String folderLoc = "/opt/brms/shared/scripts";//PropertyLoader.getInstance().getProperty("monitor_config_base");
File token_lists_file = new File(folderLoc+"/ios_device_token_list.txt");
List<String> deviceTokenEntries = null;
if (token_lists_file.exists()) {
deviceTokenEntries = FileUtils.readLines(token_lists_file);
if(!deviceTokenEntries.isEmpty()) {
for (String token : deviceTokenEntries) {
if (null == token || token.trim().equalsIgnoreCase("")) {
continue;
} else {
System.out.println("Device token read from file is: "+token);
deviceTokeList.add(token);
}
}
}
}
return deviceTokeList;
}
}