1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.kuali.rice.kcb.service.impl; |
17 |
|
|
18 |
|
import java.sql.Timestamp; |
19 |
|
import java.util.ArrayList; |
20 |
|
import java.util.Collection; |
21 |
|
import java.util.HashMap; |
22 |
|
import java.util.Map; |
23 |
|
|
24 |
|
import org.apache.log4j.Logger; |
25 |
|
import org.apache.ojb.broker.query.Criteria; |
26 |
|
import org.kuali.rice.core.util.RiceConstants; |
27 |
|
import org.kuali.rice.kcb.bo.Message; |
28 |
|
import org.kuali.rice.kcb.bo.MessageDelivery; |
29 |
|
import org.kuali.rice.kcb.bo.MessageDeliveryStatus; |
30 |
|
import org.kuali.rice.kcb.service.MessageDeliveryService; |
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
@author |
36 |
|
|
|
|
| 0% |
Uncovered Elements: 51 (51) |
Complexity: 13 |
Complexity Density: 0.36 |
|
37 |
|
public class MessageDeliveryServiceImpl extends BusinessObjectServiceImpl implements MessageDeliveryService { |
38 |
|
private static final Logger LOG = Logger.getLogger(MessageDeliveryServiceImpl.class); |
39 |
|
|
40 |
|
|
41 |
|
@link |
42 |
|
|
43 |
|
|
44 |
|
private int maxProcessAttempts; |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
@param |
49 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
50 |
0
|
public void setMaxProcessAttempts(int maxProcessAttempts) {... |
51 |
0
|
this.maxProcessAttempts = maxProcessAttempts; |
52 |
|
} |
53 |
|
|
54 |
|
|
55 |
|
@see |
56 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
57 |
0
|
public void saveMessageDelivery(MessageDelivery delivery) {... |
58 |
0
|
dao.save(delivery); |
59 |
|
} |
60 |
|
|
61 |
|
|
62 |
|
@see |
63 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
64 |
0
|
public void deleteMessageDelivery(MessageDelivery messageDelivery) {... |
65 |
0
|
dao.delete(messageDelivery); |
66 |
|
} |
67 |
|
|
68 |
|
|
69 |
|
@see |
70 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
0
|
public Collection<MessageDelivery> getAllMessageDeliveries() {... |
72 |
0
|
return dao.findAll(MessageDelivery.class); |
73 |
|
} |
74 |
|
|
75 |
|
|
76 |
|
@see |
77 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
78 |
0
|
public MessageDelivery getMessageDelivery(Long id) {... |
79 |
0
|
Map<String, Object> fields = new HashMap<String, Object>(1); |
80 |
0
|
fields.put(MessageDelivery.ID_FIELD, id); |
81 |
0
|
return (MessageDelivery) dao.findByPrimaryKey(MessageDelivery.class, fields); |
82 |
|
} |
83 |
|
|
84 |
|
|
85 |
|
@see |
86 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0.5 |
|
87 |
0
|
public MessageDelivery getMessageDeliveryByDelivererSystemId(Long id) {... |
88 |
0
|
Criteria criteria = new Criteria(); |
89 |
0
|
criteria.addEqualTo(MessageDelivery.SYSTEMID_FIELD, id); |
90 |
0
|
Collection<MessageDelivery> results = dao.findMatching(MessageDelivery.class, criteria); |
91 |
0
|
if (results == null || results.size() == 0) return null; |
92 |
0
|
if (results.size() > 1) { |
93 |
0
|
throw new RuntimeException("More than one message delivery found with the following delivery system id: " + id); |
94 |
|
} |
95 |
0
|
return results.iterator().next(); |
96 |
|
} |
97 |
|
|
98 |
|
|
99 |
|
@see |
100 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
101 |
0
|
public Collection<MessageDelivery> getMessageDeliveries(Message message) {... |
102 |
0
|
Criteria criteria = new Criteria(); |
103 |
0
|
criteria.addEqualTo(MessageDelivery.MESSAGEID_FIELD, message.getId()); |
104 |
0
|
return dao.findMatching(MessageDelivery.class, criteria); |
105 |
|
} |
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
113 |
0
|
public Collection<MessageDelivery> lockAndTakeMessageDeliveries(MessageDeliveryStatus[] statuses) {... |
114 |
0
|
return lockAndTakeMessageDeliveries(null, statuses); |
115 |
|
} |
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 2 |
Complexity Density: 0.12 |
|
116 |
0
|
public Collection<MessageDelivery> lockAndTakeMessageDeliveries(Long messageId, MessageDeliveryStatus[] statuses) {... |
117 |
0
|
LOG.debug("========>> ENTERING LockAndTakeMessageDeliveries: " + Thread.currentThread()); |
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
0
|
Criteria criteria = new Criteria(); |
123 |
0
|
criteria.addIsNull(MessageDelivery.LOCKED_DATE); |
124 |
0
|
if (messageId != null) { |
125 |
0
|
criteria.addEqualTo(MessageDelivery.MESSAGEID_FIELD, messageId); |
126 |
|
} |
127 |
0
|
criteria.addLessThan(MessageDelivery.PROCESS_COUNT, maxProcessAttempts); |
128 |
0
|
Collection<String> statusCollection = new ArrayList<String>(statuses.length); |
129 |
0
|
for (MessageDeliveryStatus status: statuses) { |
130 |
0
|
statusCollection.add(status.name()); |
131 |
|
} |
132 |
0
|
criteria.addIn(MessageDelivery.DELIVERY_STATUS, statusCollection); |
133 |
|
|
134 |
0
|
Collection<MessageDelivery> messageDeliveries = dao.findMatching(MessageDelivery.class, criteria, true, RiceConstants.NO_WAIT); |
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
0
|
for (MessageDelivery delivery: messageDeliveries) { |
140 |
0
|
LOG.debug("Took: " + delivery); |
141 |
0
|
delivery.setLockedDate(new Timestamp(System.currentTimeMillis())); |
142 |
0
|
dao.save(delivery); |
143 |
|
} |
144 |
|
|
145 |
0
|
LOG.debug("<<======= LEAVING LockAndTakeMessageDeliveries: " + Thread.currentThread()); |
146 |
0
|
return messageDeliveries; |
147 |
|
} |
148 |
|
} |