farndt
(Franziska Arndt)
September 2, 2019, 9:47pm
1
I’m currently writing unit tests for org.openmrs.api.ProgramWorkflowService and a few questions have come up. This is one:
Why is Context.getProgramWorkflowService() used instead of this ? Like in
public Program getProgram(String name) {
return Context.getProgramWorkflowService().getProgramByName(name);
}
Shouldn’t
Context.getProgramWorkflowService()
just return the instance of ProgramWorkflowServiceImpl already in use? (And if it is a different one why would that be necessary?)
Why not
public Program getProgram(String name) {
return this.getProgramByName(name);
}
?
gcliff
(CLIFF GITA)
September 3, 2019, 1:20am
2
Context is used to authenticate to the database and obtain services in order to interact with the system…
/**
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.api.context;
import org.aopalliance.aop.Advice;
import org.apache.commons.lang3.StringUtils;
import org.openmrs.Allergen;
import org.openmrs.GlobalProperty;
import org.openmrs.PersonName;
import org.openmrs.Privilege;
import org.openmrs.Role;
import org.openmrs.User;
import org.openmrs.api.APIException;
This file has been truncated. show original
herbert24
(Herbert Yiga)
September 3, 2019, 7:13am
3
Context helps you to access the api hence making the service available!!
dkayiwa
(Daniel Kayiwa)
September 23, 2019, 12:33pm
4
@farndt the recommended way is NOT to call the method directly within the same service, but rather to call Context.getXXXService.method(), which then calls the method on the proxy, rather than the target itself. That way, the AOP around the method is applied. https://wiki.openmrs.org/display/docs/OpenMRS+AOP
1 Like