-
Notifications
You must be signed in to change notification settings - Fork 27
/
NotificationItemRepository.java
88 lines (78 loc) · 3.65 KB
/
NotificationItemRepository.java
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
/*
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Hybris Extension
*
* Copyright (c) 2017 Adyen B.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*/
package com.adyen.v6.repository;
import com.adyen.v6.model.NotificationItemModel;
import de.hybris.platform.servicelayer.search.FlexibleSearchQuery;
import org.apache.log4j.Logger;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* Repository class for NotificationItems
*/
public class NotificationItemRepository extends AbstractRepository {
private static final Logger LOG = Logger.getLogger(NotificationItemRepository.class);
public List<NotificationItemModel> getNonProcessedNotifications() {
//Select the non-processed notifications
final FlexibleSearchQuery selectNonProcessedNotificationsQuery = new FlexibleSearchQuery(
"SELECT {pk} FROM {" + NotificationItemModel._TYPECODE + "}"
+ " WHERE {" + NotificationItemModel.PROCESSEDAT + "} IS NULL ORDER BY {pk} ASC LIMIT 1000"
);
LOG.debug("Querying notification items");
final List<NotificationItemModel> nonProcessedNotifications = flexibleSearchService
.search(selectNonProcessedNotificationsQuery)
.getResult()
.stream()
.map(element->(NotificationItemModel) element)
.collect(Collectors.toList());
LOG.debug(nonProcessedNotifications.size() + " items found ");
return nonProcessedNotifications;
}
/**
* Checks if the notification is already processed
*
* @param pspReference Notification psp reference
* @param eventCode Notification eventCode
* @param success Notification success
* @return true|false
*/
public boolean notificationProcessed(String pspReference, String eventCode, boolean success) {
final Map queryParams = new HashMap();
queryParams.put("pspReference", pspReference);
queryParams.put("eventCode", eventCode);
queryParams.put("success", success);
final FlexibleSearchQuery selectNonProcessedNotificationsQuery = new FlexibleSearchQuery(
"SELECT {pk} FROM {" + NotificationItemModel._TYPECODE + "}"
+ " WHERE {" + NotificationItemModel.PSPREFERENCE + "} = ?pspReference"
+ " AND {" + NotificationItemModel.EVENTCODE + "} = ?eventCode"
+ " AND {" + NotificationItemModel.SUCCESS + "} = ?success"
+ " AND {" + NotificationItemModel.PROCESSEDAT + "} IS NOT NULL",
queryParams
);
LOG.debug("Checking if notification already exists");
int count = flexibleSearchService
.search(selectNonProcessedNotificationsQuery)
.getCount();
LOG.debug(count + " items found ");
return (count > 0);
}
}