diff --git a/bahmnicore-omod/src/main/java/org/bahmni/module/bahmnicore/web/v1_0/search/BahmniConceptSearchByDataTypeHandler.java b/bahmnicore-omod/src/main/java/org/bahmni/module/bahmnicore/web/v1_0/search/BahmniConceptSearchByDataTypeHandler.java index 1a0f4b5b2..af0b2c4f7 100644 --- a/bahmnicore-omod/src/main/java/org/bahmni/module/bahmnicore/web/v1_0/search/BahmniConceptSearchByDataTypeHandler.java +++ b/bahmnicore-omod/src/main/java/org/bahmni/module/bahmnicore/web/v1_0/search/BahmniConceptSearchByDataTypeHandler.java @@ -4,6 +4,7 @@ import org.openmrs.ConceptDatatype; import org.openmrs.ConceptSearchResult; import org.openmrs.api.ConceptService; +import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.resource.api.PageableResult; @@ -12,6 +13,7 @@ import org.openmrs.module.webservices.rest.web.resource.api.SearchQuery; import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; import org.openmrs.module.webservices.rest.web.response.ResponseException; +import org.openmrs.util.LocaleUtility; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component; @@ -19,6 +21,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Locale; @Component public class BahmniConceptSearchByDataTypeHandler implements SearchHandler { @@ -54,8 +57,10 @@ public PageableResult search(RequestContext context) throws ResponseException { List concepts = new ArrayList<>(); + List localeList = getLocales(context); + List conceptsByName = - conceptService.getConcepts(conceptName, null, false, null, null, conceptDatatypes, null, null, context.getStartIndex(), context.getLimit()); + conceptService.getConcepts(conceptName, localeList, false, null, null, conceptDatatypes, null, null, context.getStartIndex(), context.getLimit()); for (ConceptSearchResult csr : conceptsByName) { if (csr.getConcept() != null) @@ -66,4 +71,21 @@ public PageableResult search(RequestContext context) throws ResponseException { } + private List getLocales(RequestContext context) { + String locale = context.getParameter("locale"); + + List localeList = new ArrayList<>(); + + if (locale != null) { + localeList.add(LocaleUtility.fromSpecification(locale)); + } else { + localeList.add(Context.getLocale()); + if (!LocaleUtility.getDefaultLocale().equals(Context.getLocale())) { + localeList.add(LocaleUtility.getDefaultLocale()); + } + } + + return localeList; + } + } diff --git a/bahmnicore-omod/src/test/java/org/bahmni/module/bahmnicore/web/v1_0/search/BahmniConceptSearchByDataTypeHandlerTest.java b/bahmnicore-omod/src/test/java/org/bahmni/module/bahmnicore/web/v1_0/search/BahmniConceptSearchByDataTypeHandlerTest.java index 6458a0a98..bc0bc6f88 100644 --- a/bahmnicore-omod/src/test/java/org/bahmni/module/bahmnicore/web/v1_0/search/BahmniConceptSearchByDataTypeHandlerTest.java +++ b/bahmnicore-omod/src/test/java/org/bahmni/module/bahmnicore/web/v1_0/search/BahmniConceptSearchByDataTypeHandlerTest.java @@ -16,6 +16,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Locale; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; @@ -68,12 +69,15 @@ public void shouldDelegateSearchOfConceptsToConceptService() { ConceptDatatype conceptDatatype = new ConceptDatatype(); conceptDatatype.setId(1); conceptDatatypes.add(conceptDatatype); + List localeList = new ArrayList<>(); + localeList.add(Locale.ENGLISH); when(conceptService.getConceptDatatypeByName(DATA_TYPES)).thenReturn(conceptDatatype); - when(conceptService.getConcepts(NAME, null, false, null, null, conceptDatatypes, + when(conceptService.getConcepts(NAME, localeList, false, null, null, conceptDatatypes, null, null, 0, 10)).thenReturn(conceptSearchResults); when(requestContext.getParameter("name")).thenReturn(NAME); when(requestContext.getParameter("dataTypes")).thenReturn(DATA_TYPES); + when(requestContext.getParameter("locale")).thenReturn(Locale.ENGLISH.toString()); when(requestContext.getLimit()).thenReturn(10); NeedsPaging searchResults = (NeedsPaging) bahmniConceptSearchByDataTypeHandler.search(requestContext);