Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,7 @@ String getPaginatedMessages(Integer page, Integer pageSize, Boolean success, Str

@Authorized(SyncModuleConfig.SYNC_AUDIT_PRIVILEGE)
String getJsonMessage(AuditMessage message) throws APIException, JsonParseException;

@Authorized(SyncModuleConfig.SYNC_AUDIT_PRIVILEGE)
Long getCountOfMessages();
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,9 @@ private <T> String serializeResultsWithAuditMessage(T results) {

return gson.toJson(results);
}

@Override
public Long getCountOfMessages() {
return dao.getCountOfMessages();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import org.openmrs.annotation.OpenmrsProfile;
import org.openmrs.module.sync2.SyncConstants;
import org.openmrs.module.sync2.api.exceptions.SyncValidationException;
import org.openmrs.module.sync2.api.service.SyncAuditService;
import org.openmrs.module.sync2.api.service.SyncConfigurationService;
import org.openmrs.module.sync2.api.utils.ContextUtils;
import org.openmrs.module.sync2.api.validator.Errors;
import org.openmrs.module.sync2.client.reader.LocalFeedReader;
import org.openmrs.module.sync2.client.reader.ParentFeedReader;
import org.openmrs.module.uicommons.util.InfoErrorMessageUtil;
import org.openmrs.ui.framework.UiUtils;
Expand All @@ -29,24 +31,24 @@ public class ManualSyncPullPageController {

public String controller(PageModel model,
@SpringBean("sync2.syncConfigurationService") SyncConfigurationService syncConfigurationService,
@SpringBean("syncAuditService") SyncAuditService syncAuditService,
HttpSession session, UiUtils ui) {
try {
LOGGER.info("Start Parent Feed Reader...");
ParentFeedReader parentFeedReader = ContextUtils.getParentFeedReader();
parentFeedReader.pullAndProcessAllFeeds();
InfoErrorMessageUtil.flashInfoMessage(session, ui.message(SYNC_SUCCESS));
} catch (SyncValidationException e) {
LOGGER.error("Error during reading feeds: ", e);
InfoErrorMessageUtil.flashErrorMessage(session, ui.message(getFirstErrorCode(e.getErrors())));
} catch (Exception e) {
LOGGER.error("Error during reading feeds: ", e);
InfoErrorMessageUtil.flashErrorMessage(session, ui.message(SYNC_FAILURE));
}
LOGGER.info("Start Parent Feed Reader...");
ParentFeedReader parentFeedReader = ContextUtils.getParentFeedReader();
parentFeedReader.pullAndProcessAllFeeds();
Integer lastAuditMsgId = syncAuditService.getCountOfMessages().intValue();
Boolean succes = syncAuditService.getMessageById(lastAuditMsgId).getSuccess();
if (succes) {
InfoErrorMessageUtil.flashInfoMessage(session, ui.message(SYNC_SUCCESS));
} else {
LOGGER.error("Error during reading feeds..");
InfoErrorMessageUtil.flashErrorMessage(session, ui.message(SYNC_FAILURE));
}
return "redirect:/sync2/sync2.page";
}

private String getFirstErrorCode(Errors errors) {
return errors.getErrorsCodes().get(SyncConstants.ZERO);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.openmrs.annotation.OpenmrsProfile;
import org.openmrs.module.sync2.SyncConstants;
import org.openmrs.module.sync2.api.exceptions.SyncValidationException;
import org.openmrs.module.sync2.api.service.SyncAuditService;
import org.openmrs.module.sync2.api.service.SyncConfigurationService;
import org.openmrs.module.sync2.api.utils.ContextUtils;
import org.openmrs.module.sync2.api.validator.Errors;
Expand All @@ -29,24 +30,24 @@ public class ManualSyncPushPageController {

public String controller(PageModel model,
@SpringBean("sync2.syncConfigurationService") SyncConfigurationService syncConfigurationService,
@SpringBean("syncAuditService") SyncAuditService syncAuditService,
HttpSession session, UiUtils ui) {
try {
LOGGER.info("Start Local Feed Reader...");
LocalFeedReader localFeedReader = ContextUtils.getLocalFeedReader();
localFeedReader.readAndPushAllFeeds();
InfoErrorMessageUtil.flashInfoMessage(session, ui.message(SYNC_SUCCESS));
} catch (SyncValidationException e) {
LOGGER.error("Error during pushing objects: ", e);
InfoErrorMessageUtil.flashErrorMessage(session, ui.message(getFirstErrorCode(e.getErrors())));
} catch (Exception e) {
LOGGER.error("Error during pushing objects: ", e);
InfoErrorMessageUtil.flashErrorMessage(session, ui.message(SYNC_FAILURE));
}
LOGGER.info("Start Local Feed Reader...");
LocalFeedReader localFeedReader = ContextUtils.getLocalFeedReader();
localFeedReader.readAndPushAllFeeds();
Integer lastAuditMsgId = syncAuditService.getCountOfMessages().intValue();
Boolean succes = syncAuditService.getMessageById(lastAuditMsgId).getSuccess();
if (succes) {
InfoErrorMessageUtil.flashInfoMessage(session, ui.message(SYNC_SUCCESS));
} else {
LOGGER.error("Error during pushing objects..");
InfoErrorMessageUtil.flashErrorMessage(session, ui.message(SYNC_FAILURE));
}
return "redirect:/sync2/sync2.page";
}

private String getFirstErrorCode(Errors errors) {
return errors.getErrorsCodes().get(SyncConstants.ZERO);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
import org.openmrs.module.sync2.SyncConstants;
import org.openmrs.module.sync2.SyncMessageUtils;
import org.openmrs.module.sync2.api.exceptions.SyncValidationException;
import org.openmrs.module.sync2.api.service.SyncAuditService;
import org.openmrs.module.sync2.api.utils.ContextUtils;
import org.openmrs.module.sync2.api.utils.SyncUtils;
import org.openmrs.module.sync2.api.validator.Errors;
import org.openmrs.module.sync2.client.reader.LocalFeedReader;
import org.openmrs.module.sync2.client.reader.ParentFeedReader;
import org.openmrs.module.uicommons.util.InfoErrorMessageUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -40,6 +43,9 @@ public class Sync2ModuleController {
private static final String PUSH_FAILURE_MESSAGE = "sync2.sync.push.failure";
private static final String PULL_SUCCESS_MESSAGE = "sync2.sync.pull.success";
private static final String PULL_FAILURE_MESSAGE = "sync2.sync.pull.failure";

@Autowired
private SyncAuditService syncAuditService;

/**
* Sets the UI model attributes used to check if the parent instance URI is valid etc.
Expand Down Expand Up @@ -71,18 +77,18 @@ public void manage(ModelMap model,
*/
@RequestMapping(value = "/manualPush")
public String manualPush(ModelMap model) {
try {
LOGGER.info("Start Local Feed Reader...");
LocalFeedReader localFeedReader = ContextUtils.getLocalFeedReader();
localFeedReader.readAndPushAllFeeds();

LOGGER.info("Start Local Feed Reader...");
LocalFeedReader localFeedReader = ContextUtils.getLocalFeedReader();
localFeedReader.readAndPushAllFeeds();
Integer lastAuditMsgId = syncAuditService.getCountOfMessages().intValue();
Boolean succes = syncAuditService.getMessageById(lastAuditMsgId).getSuccess();
if (succes) {
SyncMessageUtils.successMessage(model, PUSH_SUCCESS_MESSAGE);
} catch (SyncValidationException e) {
LOGGER.error("Error during reading feeds: ", e);
SyncMessageUtils.errorMessage(model, getFirstErrorCode(e.getErrors()));
} catch (Exception e) {
LOGGER.error("Error during pushing objects: ", e);
} else {
LOGGER.error("Error during pushing objects..");
SyncMessageUtils.errorMessage(model, PUSH_FAILURE_MESSAGE);
}
}
return "redirect:/module/sync2/sync2.form";
}

Expand All @@ -94,17 +100,16 @@ public String manualPush(ModelMap model) {
*/
@RequestMapping(value = "/manualPull")
public String manualPull(ModelMap model) {
try {
LOGGER.info("Start Parent Feed Reader...");
ParentFeedReader parentFeedReader = ContextUtils.getParentFeedReader();
parentFeedReader.pullAndProcessAllFeeds();

LOGGER.info("Start Parent Feed Reader...");
ParentFeedReader parentFeedReader = ContextUtils.getParentFeedReader();
parentFeedReader.pullAndProcessAllFeeds();
Integer lastAuditMsgId = syncAuditService.getCountOfMessages().intValue();
Boolean succes = syncAuditService.getMessageById(lastAuditMsgId).getSuccess();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, but did you intend to use Boolean success rather than Boolean succes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @ODORA0 , let me correct the naming

if (succes) {
SyncMessageUtils.successMessage(model, PULL_SUCCESS_MESSAGE);
} catch (SyncValidationException e) {
LOGGER.error("Error during reading feeds: ", e);
SyncMessageUtils.errorMessage(model, getFirstErrorCode(e.getErrors()));

} catch (Exception e) {
LOGGER.error("Error during reading feeds: ", e);
} else {
LOGGER.error("Error during reading feeds");
SyncMessageUtils.errorMessage(model, PULL_FAILURE_MESSAGE);
}
return "redirect:/module/sync2/sync2.form";
Expand Down