public Message generateUnsubscribeE vent Creating db connection DBClas

 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
public Message generateUnsubscribeEvent() {
// Creating db connection
DBClass db = new DBClass();
// Getting subscriptions
List<Integer> subscriptions = db.getSubscriptions();
// Going throw the list and delete every subscription with id
Id id = new Id();
for (int item : subscriptions) {
id.setId(item);
unsubscribe(id);
}
// Closing database connection
db.close();
// Creating response message
Message message = new Message();
if (subscriptions.size() > 0) {
message.setMessage("You successfully unsubscribed from "
+ subscriptions.size() + " subscriptions");
} else {
message.setMessage("You have no subscriptions to unsubscribe...");
}
// Debugging message
System.out.println(message.getMessage());
// Returning message
return message;
}