/
SyncRetryServiceImpl.java
66 lines (52 loc) · 2.43 KB
/
SyncRetryServiceImpl.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
package org.openmrs.module.sync2.api.impl;
import org.openmrs.api.APIException;
import org.openmrs.module.sync2.api.SyncAuditService;
import org.openmrs.module.sync2.api.SyncConfigurationService;
import org.openmrs.module.sync2.api.SyncPullService;
import org.openmrs.module.sync2.api.SyncPushService;
import org.openmrs.module.sync2.api.SyncRetryService;
import org.openmrs.module.sync2.api.model.audit.AuditMessage;
import org.openmrs.module.sync2.api.utils.SyncUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
import static org.openmrs.module.sync2.SyncConstants.PULL_OPERATION;
import static org.openmrs.module.sync2.SyncConstants.PUSH_OPERATION;
@Component("sync2.SyncRetryService")
public class SyncRetryServiceImpl implements SyncRetryService {
@Autowired
private SyncPullService syncPullService;
@Autowired
private SyncPushService syncPushService;
@Autowired
private SyncAuditService syncAuditService;
@Autowired
private SyncConfigurationService configuration;
@Override
public AuditMessage retryMessage(AuditMessage message) throws APIException {
switch(message.getOperation()) {
case PULL_OPERATION:
return retryPull(message);
case PUSH_OPERATION:
return retryPush(message);
}
return null;
}
private AuditMessage retryPush(AuditMessage message) {
String parentAddress = configuration.getSyncConfiguration().getGeneral().getParentFeedLocation();
Map<String, String> map = new HashMap<>();
map.put(message.getLinkType(), message.getUsedResourceUrl());
message = syncPushService.readDataAndPushToParent(message.getResourceName(), map, parentAddress, message.getAction());
return message;
}
private AuditMessage retryPull(AuditMessage message) {
String parentAddress = configuration.getSyncConfiguration().getGeneral().getParentFeedLocation();
parentAddress = SyncUtils.getBaseUrl(parentAddress);
Map<String, String> map = new HashMap<>();
map.put(message.getLinkType(), message.getUsedResourceUrl());
AuditMessage newMesssage = syncPullService.pullDataFromParentAndSave(message.getResourceName(), map, parentAddress, message.getAction());
syncAuditService.setNextAudit(message, newMesssage);
return newMesssage;
}
}