Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from areklalo/SYNCT-30
SYNCT-30: The logic for retry messages
- Loading branch information
Showing
21 changed files
with
264 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
api/src/main/java/org/openmrs/module/sync2/api/SyncPullService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package org.openmrs.module.sync2.api; | ||
|
||
import org.openmrs.module.sync2.api.model.audit.AuditMessage; | ||
|
||
import java.util.Map; | ||
|
||
public interface SyncPullService { | ||
|
||
void pullDataFromParentAndSave(String category, Map<String, String> resourceLinks, String address, String action); | ||
AuditMessage pullDataFromParentAndSave(String category, Map<String, String> resourceLinks, String address, String action); | ||
} |
4 changes: 3 additions & 1 deletion
4
api/src/main/java/org/openmrs/module/sync2/api/SyncPushService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package org.openmrs.module.sync2.api; | ||
|
||
import org.openmrs.module.sync2.api.model.audit.AuditMessage; | ||
|
||
import java.util.Map; | ||
|
||
public interface SyncPushService { | ||
|
||
void readDataAndPushToParent(String category, Map<String, String> resourceLinks, String address, String action); | ||
AuditMessage readDataAndPushToParent(String category, Map<String, String> resourceLinks, String address, String action); | ||
} |
12 changes: 12 additions & 0 deletions
12
api/src/main/java/org/openmrs/module/sync2/api/SyncRetryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.openmrs.module.sync2.api; | ||
|
||
import org.openmrs.annotation.Authorized; | ||
import org.openmrs.api.APIException; | ||
import org.openmrs.module.sync2.SyncModuleConfig; | ||
import org.openmrs.module.sync2.api.model.audit.AuditMessage; | ||
|
||
public interface SyncRetryService { | ||
|
||
@Authorized(SyncModuleConfig.SYNC_AUDIT_PRIVILEGE) | ||
AuditMessage retryMessage(AuditMessage message) throws APIException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
api/src/main/java/org/openmrs/module/sync2/api/impl/SyncRetryServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
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(); | ||
parentAddress = SyncUtils.getBaseUrl(parentAddress); | ||
|
||
Map<String, String> map = new HashMap<>(); | ||
map.put(message.getLinkType(), message.getUsedResourceUrl()); | ||
|
||
AuditMessage newMesssage = syncPushService.readDataAndPushToParent(message.getResourceName(), map, parentAddress, message.getAction()); | ||
syncAuditService.setNextAudit(message, newMesssage); | ||
return newMesssage; | ||
} | ||
|
||
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; | ||
} | ||
} |
Oops, something went wrong.