Skip to content

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Trunk 4988 #4982

wants to merge 3 commits into from

Conversation

Sanskritii09
Copy link

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. 🚀

…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.
Copy link

@OmarTarekAli OmarTarekAli left a comment

Choose a reason for hiding this comment

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

PR2


/**

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;

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.");
}
}

@atulyadav745
Copy link

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.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants