/** * @see org.openmrs.api.LocationService#unretireLocationTag(org.openmrs.LocationTag) */ @Override public LocationTag unretireLocationTag(LocationTag tag) throws APIException { tag.setRetired(false); tag.setRetireReason(null); tag.setRetiredBy(null); tag.setDateRetired(null); return Context.getLocationService().saveLocationTag(tag); }
/** * @see org.openmrs.api.LocationService#retireLocationTag(LocationTag, String) */ @Override public LocationTag retireLocationTag(LocationTag tag, String reason) throws APIException { if (tag.getRetired()) { return tag; } else { if (reason == null) { throw new APIException("Location.retired.reason.required", (Object[]) null); } tag.setRetired(true); tag.setRetireReason(reason); tag.setRetiredBy(Context.getAuthenticatedUser()); tag.setDateRetired(new Date()); return Context.getLocationService().saveLocationTag(tag); } }
/** * @see LocationService#saveLocationTag(LocationTag) */ @Test public void saveLocationTag_shouldReturnSavedObject() { LocationTag locationTag = new LocationTag("Some tag name", "Some description"); LocationTag savedLocationTag = Context.getLocationService().saveLocationTag(locationTag); Assert.assertEquals(locationTag, savedLocationTag); }
/** * @see LocationService#saveLocationTag(LocationTag) */ @Test(expected = APIException.class) public void saveLocationTag_shouldThrowExceptionIfTagNameIsNull() { LocationTag tag = new LocationTag(); tag.setName(null); tag.setDescription("desc"); Context.getLocationService().saveLocationTag(tag); }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#save(java.lang.Object) */ @Override public LocationTag save(LocationTag delegate) { return service().saveLocationTag(delegate); }
/** * Test to make sure that a simple save to a new location tag gets persisted to the database * * @see LocationService#saveLocationTag(LocationTag) */ @Test public void saveLocationTag_shouldCreateLocationTagSuccessfully() { LocationTag tag = new LocationTag(); tag.setName("testing"); tag.setDescription("desc"); LocationService ls = Context.getLocationService(); ls.saveLocationTag(tag); LocationTag newSavedTag = ls.getLocationTag(tag.getLocationTagId()); assertNotNull("The saved tag should have an id now", tag.getLocationTagId()); assertNotNull("We should get back a tag", newSavedTag); assertTrue("The created tag needs to equal the pojo location", tag.equals(newSavedTag)); }
/** * should set audit info if any item in the location tag is edited * * @see LocationService#saveLocationTag(LocationTag) */ @Test public void saveLocationTag_shouldSetAuditInfoIfAnyItemInTheLocationTagIsEdited() { LocationService ls = Context.getLocationService(); LocationTag tag = ls.getLocationTag(1); Assert.assertNull(tag.getDateChanged()); Assert.assertNull(tag.getChangedBy()); tag.setName("testing"); tag.setDescription("desc"); LocationTag editedTag = Context.getLocationService().saveLocationTag(tag); Context.flushSession(); Assert.assertNotNull(editedTag.getDateChanged()); Assert.assertNotNull(editedTag.getChangedBy()); }