-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Trunk 4988 #4982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Trunk 4988 #4982
Conversation
…ributing to a larger task involving ElasticSearch integration.
- Updated the ObsServiceTest#saveObs_shouldVoidOnlyOldObsWhenAllObsEditedAndNewObsAdded test to mitigate dependence on system time. - Enhanced reliability and accuracy of the test to ensure consistent pass results.
- Updated `setMessageService` to correctly assign the `messageService` instance. - Ensured proper dependency injection with `@Autowired`. - Refactored code to improve maintainability and consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR2
|
||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static MessageService getMessageService() {
MessageService ms = getServiceContext().getMessageService();
try {
if (ms.getMessagePreparator() == null) {
ms.setMessagePreparator(getMessagePreparator());
}
if (ms.getMessageSender() == null) {
ms.setMessageSender(getMessageSender());
}
validateMessageService(ms);
return ms;
} catch (Exception e) {
Logger.getLogger(YourClassName.class.getName()).log(Level.SEVERE, "Error initializing message service", e);
throw new RuntimeException("Error initializing message service", e);
}
}
private static MessagePreparator getMessagePreparator() {
return new MessagePreparator();
}
private static MessageSender getMessageSender() {
return new MessageSender();
}
private static void validateMessageService(MessageService ms) {
if (ms == null) {
throw new IllegalArgumentException("MessageService cannot be null.");
}
}
if (ms.getMessagePreparator() == null) { | ||
ms.setMessagePreparator(getMessagePreparator()); | ||
} | ||
private static MessageService messageService; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static MessageService getMessageService() {
MessageService ms = getServiceContext().getMessageService();
try {
if (ms.getMessagePreparator() == null) {
ms.setMessagePreparator(getMessagePreparator());
}
if (ms.getMessageSender() == null) {
ms.setMessageSender(getMessageSender());
}
validateMessageService(ms);
return ms;
} catch (Exception e) {
Logger.getLogger(YourClassName.class.getName()).log(Level.SEVERE, "Error initializing message service", e);
throw new RuntimeException("Error initializing message service", e);
}
}
private static MessagePreparator getMessagePreparator() {
return new MessagePreparator();
}
private static MessageSender getMessageSender() {
return new MessageSender();
}
private static void validateMessageService(MessageService ms) {
if (ms == null) {
throw new IllegalArgumentException("MessageService cannot be null.");
}
}
Hey @Sanskritii09 , I would suggest you to please go through OpenMRS contribution Guidelines once, to have a better understanding on how a PR should look like. |
Title:
Fix MessageService Injection Issue in Context Class
Description:
This PR resolves an issue with the MessageService dependency injection in the Context class. The following changes were made:
Ensured proper assignment of messageService using @Autowired.
Refactored setter method to maintain consistency.
Improved code readability and maintainability.
Testing:
Verified that the MessageService is correctly injected and accessible.
Checked for potential issues related to static fields and Spring’s dependency injection.
Please review and let me know if any further modifications are required. 🚀