Skip to content

Commit 9d958cc

Browse files
committed
Encapsulate resource handler map by adding a getter method instead of making it public
1 parent 828f71e commit 9d958cc

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SwaggerGenerationUtil.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import java.util.Set;
4242
import java.util.UUID;
4343

44-
import static org.openmrs.module.webservices.rest.web.api.impl.RestServiceImpl.resourcesBySupportedClasses;
4544
import static org.openmrs.module.webservices.rest.web.representation.Representation.DEFAULT;
4645
import static org.openmrs.module.webservices.rest.web.representation.Representation.FULL;
4746
import static org.openmrs.module.webservices.rest.web.representation.Representation.REF;
@@ -404,9 +403,10 @@ public static Class<?> getGenericType(Class<?> resourceHandlerClass) {
404403
* @param resourceClass the resource class e.g. PatientIdentifier
405404
*/
406405
public static org.openmrs.module.webservices.rest.web.resource.api.Resource getResourceHandlerForSupportedClass(Class<?> resourceClass) {
407-
if (resourcesBySupportedClasses == null) {
406+
if (Context.getService(RestService.class).getResource(resourceClass) == null) {
408407
Context.getService(RestService.class).initialize();
409408
}
410-
return resourcesBySupportedClasses.get(resourceClass);
409+
return Context.getService(RestService.class).getResource(resourceClass);
411410
}
411+
412412
}

omod-common/src/main/java/org/openmrs/module/webservices/rest/web/api/RestService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ public interface RestService {
7878
* Initializes all Resources and Search handlers for use; called after module startup
7979
*/
8080
public void initialize();
81+
82+
/**
83+
* Retrieves the resource handler for the given supported class.
84+
*
85+
* @param resourceClass the class for which to get the resource handler
86+
* @return the corresponding Resource handler, or {@code null} if none exists
87+
*/
88+
public Resource getResource(Class<?> resourceClass);
8189

8290
/**
8391
* Returns all search handlers.

omod-common/src/main/java/org/openmrs/module/webservices/rest/web/api/impl/RestServiceImpl.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
public class RestServiceImpl implements RestService {
4949

5050
volatile Map<String, ResourceDefinition> resourceDefinitionsByNames;
51-
52-
public static volatile Map<Class<?>, Resource> resourcesBySupportedClasses;
51+
52+
static volatile Map<Class<?>, Resource> resourcesBySupportedClasses;
5353

5454
private volatile Map<CompositeSearchHandlerKeyValue, Set<SearchHandler>> searchHandlersByParameter;
5555

@@ -78,7 +78,11 @@ public OpenmrsClassScanner getOpenmrsClassScanner() {
7878
public void setOpenmrsClassScanner(OpenmrsClassScanner openmrsClassScanner) {
7979
this.openmrsClassScanner = openmrsClassScanner;
8080
}
81-
81+
82+
public Resource getResource(Class<?> resourceClass) {
83+
return resourcesBySupportedClasses.get(resourceClass);
84+
}
85+
8286
public RestServiceImpl() {
8387
}
8488

0 commit comments

Comments
 (0)