/** * @see org.openmrs.api.LocationService#unretireLocation(org.openmrs.Location) */ @Override public Location unretireLocation(Location location) throws APIException { location.setRetired(false); return Context.getLocationService().saveLocation(location); }
location.setName("name"); location.setDescription("is a location"); ls.saveLocation(location); ls.saveLocation(location);
la1b.setValue("admin@facility.com"); location1.addAttribute(la1b); Context.getLocationService().saveLocation(location1); la2.setValue("0123456789"); location2.addAttribute(la2); Context.getLocationService().saveLocation(location2);
/** * @see org.openmrs.api.LocationService#retireLocation(Location, String) */ @Override public Location retireLocation(Location location, String reason) throws APIException { location.setRetired(true); location.setRetireReason(reason); return Context.getLocationService().saveLocation(location); }
/** * Takes XML like: <something> <location name="Cerca-la-Source"/> </something> returns the * number of locations added * * @deprecated since 2.2.0 migrate the method to your code base if needed */ @Deprecated public static int importLocations(Document document) { int ret = 0; LocationService ls = Context.getLocationService(); List<Node> toAdd = new ArrayList<>(); findNodesNamed(document, "location", toAdd); for (Node node : toAdd) { Element e = (Element) node; String name = e.getAttribute("name"); if (name == null || name.length() == 0) { throw new IllegalArgumentException("each <location /> element must define a name attribute"); } if (ls.getLocation(name) != null) { continue; } Location location = new Location(); location.setName(name); ls.saveLocation(location); ++ret; } return ret; }
/** * @see LocationService#saveLocation(Location) */ @Test(expected = APIException.class) public void saveLocation_shouldThrowAPIExceptionIfLocationHasNoName() { Location location = new Location(); Context.getLocationService().saveLocation(location); }
/** * You should be able to remove a tag from a location. * * @see LocationService#saveLocation(Location) */ @Test public void saveLocation_shouldRemoveLocationTagFromLocation() { LocationService ls = Context.getLocationService(); // Loading location with exactly 3 tags from the initialData.xml file Location location = ls.getLocation(1); // Removing a tag location.removeTag(location.getTags().iterator().next()); ls.saveLocation(location); Location newSavedLocation = ls.getLocation(location.getLocationId()); // Saved location should have 2 tag now assertEquals(2, newSavedLocation.getTags().size()); }
/** * You should be able to remove a child location from a location. * * @see LocationService#saveLocation(Location) */ @Test public void saveLocation_shouldRemoveChildLocationFromLocation() { LocationService ls = Context.getLocationService(); // Retrieving a location with initially 2 child locations Location location = ls.getLocation(1); // Removing a child location.removeChildLocation(location.getChildLocations().iterator().next()); ls.saveLocation(location); Location newSavedLocation = ls.getLocation(location.getLocationId()); // Saved location should have 1 child locations now assertEquals(1, newSavedLocation.getChildLocations().size()); }
/** * @see LocationService#saveLocation(Location) */ @Test public void saveLocation_shouldReturnSavedObject() { Location location = new Location(); location.setName("Some name"); location.setDescription("Some description"); Location savedLocation = Context.getLocationService().saveLocation(location); Assert.assertEquals(location, savedLocation); }
/** * You should be able to add a transient tag with an existing tag name. * * @see LocationService#saveLocation(Location) */ @Test public void saveLocation_shouldOverwriteTransientTagIfTagWithSameNameExists() { LocationService ls = Context.getLocationService(); // First, create a new Location Location location = new Location(); location.setName("name"); location.setDescription("is a location"); // Add a transient tag with an existing name location.addTag(new LocationTag("General Hospital", null)); ls.saveLocation(location); Location newSavedLocation = ls.getLocation(location.getLocationId()); // Saved parent location should have exactly 1 tag assertEquals(1, newSavedLocation.getTags().size()); // Tag must be overwritten with tag with locationTagId == 1 assertNotNull("Location tag should have an ID now", newSavedLocation.getTags().iterator().next().getLocationTagId()); assertEquals(1, newSavedLocation.getTags().iterator().next().getLocationTagId().intValue()); }
/** * @see LocationService#saveLocation(Location) */ @Test(expected = APIException.class) public void saveLocation_shouldThrowAPIExceptionIfTransientTagIsNotFound() { LocationTag tagWithoutName = new LocationTag("some random tag name", "a nonexistant tag"); Location location = new Location(); location.setName("Some name"); location.setDescription("Some description"); location.addTag(tagWithoutName); Context.getLocationService().saveLocation(location); }
/** * @see LocationService#saveLocationTag(LocationTag) */ @Test(expected = APIException.class) public void saveLocationTag_shouldThrowAPIExceptionIfTagHasNoName() { LocationTag tagWithoutName = new LocationTag(); Location location = new Location(); location.setName("Some name"); location.setDescription("Some description"); location.addTag(tagWithoutName); Context.getLocationService().saveLocation(location); }
ls.saveLocation(location);
/** * should set audit info if any item in the location is edited * * @see LocationService#saveLocation(Location) */ @Test public void saveLocation_shouldSetAuditInfoIfAnyItemInTheLocationIsEdited() { LocationService ls = Context.getLocationService(); Location location = ls.getLocation(1); Assert.assertNotNull(location); Assert.assertNull(location.getDateChanged()); Assert.assertNull(location.getChangedBy()); location.setName("edited name"); ls.saveLocation(location); Location editedLocation = Context.getLocationService().saveLocation(location); Context.flushSession(); Assert.assertNotNull(editedLocation.getDateChanged()); Assert.assertNotNull(editedLocation.getChangedBy()); }
/** * @see DelegatingCrudResource#save(java.lang.Object) */ @Override public Location save(Location location) { return Context.getLocationService().saveLocation(location); }
location.setName("parent"); location.setDescription("is the parent"); ls.saveLocation(location); childA.addChildLocation(childB); ls.saveLocation(location);
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#delete(java.lang.Object, * java.lang.String, org.openmrs.module.webservices.rest.web.RequestContext) */ @Override protected void delete(LocationAttribute delegate, String reason, RequestContext context) throws ResponseException { delegate.setVoided(true); delegate.setVoidReason(reason); Context.getLocationService().saveLocation(delegate.getLocation()); }
/** * Test to make sure that a simple save to a new location gets persisted to the database * * @see LocationService#saveLocation(Location) */ @Test public void saveLocation_shouldCreateLocationSuccessfully() { Location location = new Location(); location.setName("testing"); location.setDescription("desc"); location.setAddress1("123"); location.setAddress1("456"); location.setCityVillage("city"); location.setStateProvince("state"); location.setCountry("country"); location.setPostalCode("post"); location.setLatitude("lat"); location.setLongitude("lon"); LocationService ls = Context.getLocationService(); ls.saveLocation(location); Location newSavedLocation = ls.getLocation(location.getLocationId()); assertNotNull("The saved location should have an id now", location.getLocationId()); assertNotNull("We should get back a location", newSavedLocation); assertTrue("The created location needs to equal the pojo location", location.equals(newSavedLocation)); }
@Test public void shouldIncludeTheListOfChildLocations() throws Exception { Location location = service.getLocationByUuid(getUuid()); Assert.assertEquals(0, location.getChildLocations().size()); location.addChildLocation(service.getLocation(2)); service.saveLocation(location); MockHttpServletRequest httpReq = request(RequestMethod.GET, getURI() + "/" + getUuid()); httpReq.addParameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, RestConstants.REPRESENTATION_FULL); SimpleObject result = deserialize(handle(httpReq)); Assert.assertEquals(1, ((Collection) PropertyUtils.getProperty(result, "childLocations")).size()); }
@Test public void shouldIncludeTheParentLocation() throws Exception { Location location = service.getLocationByUuid(getUuid()); location.setParentLocation(service.getLocation(2)); service.saveLocation(location); MockHttpServletRequest httpReq = request(RequestMethod.GET, getURI() + "/" + getUuid()); httpReq.addParameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, RestConstants.REPRESENTATION_FULL); SimpleObject result = deserialize(handle(httpReq)); Assert.assertNotNull(result); Assert.assertNotNull(PropertyUtils.getProperty(result, "parentLocation")); }