@Override protected LocationTag getObjectByUuid(String uuid) { return Context.getLocationService().getLocationTagByUuid(uuid); } }
/** * @see LocationService#getLocationTagByUuid(String) */ @Test public void getLocationTagByUuid_shouldFindObjectGivenValidUuid() { Assert.assertEquals(Integer.valueOf(3), Context.getLocationService().getLocationTagByUuid( "0d0eaea2-47ed-11df-bc8b-001e378eb67e").getLocationTagId()); }
/** * @see LocationService#getLocationTagByUuid(String) */ @Test public void getLocationTagByUuid_shouldReturnNullIfNoObjectFoundWithGivenUuid() { Assert.assertNull(Context.getLocationService().getLocationTagByUuid("ffffffff-47ed-11df-bc8b-001e378eb67e")); }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getByUniqueId(java.lang.String) */ @Override public LocationTag getByUniqueId(String uniqueId) { return service().getLocationTagByUuid(uniqueId); }
/** * @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); } }
LocationTag locationTag = locationService.getLocationTagByUuid(tagUuid); locationsByTag = locationService.getLocationsByTag(locationTag);
@Test public void shouldUpdateLocationTag() throws Exception { final String editedName = "Location Tag edited"; String json = "{ \"name\":\"" + editedName + "\" }"; MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); req.setContent(json.getBytes()); handle(req); LocationTag editedLocationTag = service.getLocationTagByUuid(getUuid()); Assert.assertNotNull(editedLocationTag); Assert.assertEquals(editedName, editedLocationTag.getName()); }