/** * Get locations that have a specified tag among its child tags. * * @see LocationService#getLocationsByTag(LocationTag) */ @Test public void getLocationsByTag_shouldGetLocationsByTag() { LocationService ls = Context.getLocationService(); assertEquals(1, ls.getLocationsByTag(ls.getLocationTag(1)).size()); assertEquals(2, ls.getLocationsByTag(ls.getLocationTag(3)).size()); assertEquals(4, ls.getLocationsByTag(ls.getLocationTag(4)).size()); }
/** * @see LocationService#getLocationsByTag(LocationTag) */ @Test public void getLocationsByTag_shouldReturnEmptyListWhenNoLocationsHasTheGivenTag() { LocationService ls = Context.getLocationService(); Assert.assertEquals(0, ls.getLocationsByTag(ls.getLocationTagByName("Retired")).size()); }
/** * @see org.openmrs.module.webservices.rest.web.resource.api.SearchHandler#search(org.openmrs.module.webservices.rest.web.RequestContext) */ @Override public PageableResult search(RequestContext context) throws ResponseException { String tag = context.getRequest().getParameter("tag"); List<Location> locations = new ArrayList<Location>(); try { Context.addProxyPrivilege(VIEW_LOCATIONS); //Not using PrivilegeConstants.VIEW_LOCATIONS which was removed in platform 1.11+ Context.addProxyPrivilege("Get Locations"); //1.11+ LocationTag locationTag = Context.getLocationService().getLocationTagByUuid(tag); if (locationTag == null) { locationTag = Context.getLocationService().getLocationTagByName(tag); } if (locationTag != null) { locations = Context.getLocationService().getLocationsByTag(locationTag); } } finally { Context.removeProxyPrivilege(VIEW_LOCATIONS); //Not using PrivilegeConstants.VIEW_LOCATIONS which was removed in platform 1.11+ Context.removeProxyPrivilege("Get Locations"); //1.11+ } return new NeedsPaging<Location>(locations, context); } }
locationsByTag = locationService.getLocationsByTag(locationTag);