/** * @see org.openmrs.Attributable#getDisplayString() */ @Override public String getDisplayString() { return getName(); }
/** * @see HibernateAdministrationDAO#validate(Object,Errors) */ @Test public void validate_shouldPassValidationForLocationClassIfFieldLengthsAreCorrect() { Location location = new Location(); location.setName("name"); location.setDescription("description"); location.setAddress1("address1"); location.setAddress2("address2"); location.setAddress3("address3"); location.setAddress4("address4"); location.setAddress5("address5"); location.setAddress6("address6"); location.setCityVillage("cityVillage"); location.setStateProvince("stateProvince"); location.setCountry("country"); location.setPostalCode("postalCode"); location.setLatitude("latitude"); location.setLongitude("longitude"); location.setCountyDistrict("countyDistrict"); location.setRetireReason("retireReason"); Errors errors = new BindException(location, "location"); dao.validate(location, errors); Assert.assertFalse(errors.hasErrors()); }
/** * @see org.openmrs.api.db.LocationDAO#saveLocation(org.openmrs.Location) */ @Override public Location saveLocation(Location location) { if (location.getChildLocations() != null && location.getLocationId() != null) { // hibernate has a problem updating child collections // if the parent object was already saved so we do it // explicitly here for (Location child : location.getChildLocations()) { if (child.getLocationId() == null) { saveLocation(child); } } } sessionFactory.getCurrentSession().saveOrUpdate(location); return 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; }
@Override public void validateDefaultRepresentation() throws Exception { super.validateDefaultRepresentation(); assertPropEquals("name", getObject().getName()); assertPropEquals("description", getObject().getDescription()); assertPropEquals("address1", getObject().getAddress1()); assertPropEquals("address2", getObject().getAddress2()); assertPropEquals("cityVillage", getObject().getCityVillage()); assertPropEquals("stateProvince", getObject().getStateProvince()); assertPropEquals("country", getObject().getCountry()); assertPropEquals("postalCode", getObject().getPostalCode()); assertPropEquals("latitude", getObject().getLatitude()); assertPropEquals("longitude", getObject().getLongitude()); assertPropEquals("countyDistrict", getObject().getCountyDistrict()); assertPropEquals("address3", getObject().getAddress3()); assertPropEquals("address4", getObject().getAddress4()); assertPropEquals("address5", getObject().getAddress5()); assertPropEquals("address6", getObject().getAddress6()); assertPropEquals("address7", getObject().getAddress7()); assertPropEquals("address8", getObject().getAddress8()); assertPropEquals("address9", getObject().getAddress9()); assertPropEquals("address10", getObject().getAddress10()); assertPropEquals("address11", getObject().getAddress11()); assertPropEquals("address12", getObject().getAddress12()); assertPropEquals("address13", getObject().getAddress13()); assertPropEquals("address14", getObject().getAddress14()); assertPropEquals("address15", getObject().getAddress15()); assertPropPresent("tags"); assertPropPresent("attributes"); assertPropPresent("parentLocation");
@Override public void validateDefaultRepresentation() throws Exception { super.validateDefaultRepresentation(); assertPropEquals("name", getObject().getName()); assertPropEquals("description", getObject().getDescription()); assertPropEquals("address1", getObject().getAddress1()); assertPropEquals("address2", getObject().getAddress2()); assertPropEquals("cityVillage", getObject().getCityVillage()); assertPropEquals("stateProvince", getObject().getStateProvince()); assertPropEquals("country", getObject().getCountry()); assertPropEquals("postalCode", getObject().getPostalCode()); assertPropEquals("latitude", getObject().getLatitude()); assertPropEquals("longitude", getObject().getLongitude()); assertPropEquals("countyDistrict", getObject().getCountyDistrict()); assertPropEquals("address3", getObject().getAddress3()); assertPropEquals("address4", getObject().getAddress4()); assertPropEquals("address5", getObject().getAddress5()); assertPropEquals("address6", getObject().getAddress6()); assertPropPresent("tags"); assertPropPresent("attributes"); assertPropPresent("parentLocation"); assertPropPresent("childLocations"); assertPropEquals("retired", getObject().isRetired()); }
MRSFacility convertLocationToFacility(Location savedLocation) { return new OpenMRSFacility(String.valueOf(savedLocation.getId()), savedLocation.getName(), savedLocation.getCountry(), savedLocation.getAddress6(), savedLocation.getCountyDistrict(), savedLocation.getStateProvince()); }
/** * 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)); }
/** * @see RequiredDataAdvice#isOpenmrsObjectCollection(Class<*>,Object) */ @Test public void isOpenmrsObjectCollection_shouldReturnTrueIfClassIsOpenmrsObjectSet() throws Exception { Set<Location> locations = new HashSet<>(); Location location = new Location(); locations.add(location); Assert.assertTrue(RequiredDataAdvice.isOpenmrsObjectCollection(locations)); }
/** * 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()); }
Location location = new Location(); location.setName("parent"); location.setDescription("is the parent"); ls.saveLocation(location); Location childA = new Location(); childA.setName("level A child"); childA.setDescription("is a child"); location.addChildLocation(childA); Location childB = new Location(); childB.setName("level B child"); childB.setDescription("is a child"); childA.addChildLocation(childB); Location newSavedLocation = ls.getLocation(location.getLocationId()); assertNotNull(childA.getLocationId()); assertNotNull(childB.getLocationId()); assertNotNull("newSavedLocation.childLocations must be not null", newSavedLocation.getChildLocations()); assertEquals(1, newSavedLocation.getChildLocations().size()); Location newChildA = newSavedLocation.getChildLocations().iterator().next(); assertTrue("Child location must be the previously created childA", newChildA.equals(childA)); assertNotNull("newSavedLocation.childLocations must be not null", newChildA.getChildLocations());
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.name"); if (location.getRetired() && !StringUtils.hasLength(location.getRetireReason())) { location.setRetired(false); // so that the jsp page displays Location exist = Context.getLocationService().getLocation(location.getName()); if (exist != null && !exist.getRetired() && !OpenmrsUtil.nullSafeEquals(location.getUuid(), exist.getUuid())) { errors.rejectValue("name", "location.duplicate.name"); while (root.getParentLocation() != null) { root = root.getParentLocation(); if (root.equals(location)) { // Have gone in a circle errors.rejectValue("parentLocation", "Location.parentLocation.error"); break;
/** * @see OpenmrsMetadataSaveHandler#handle(OpenmrsMetadata,User,Date,String) */ @Test public void handle_shouldTrimWhitespaceFromName() { String NAME = "the location name"; OpenmrsMetadataSaveHandler handler = new OpenmrsMetadataSaveHandler(); Location loc = new Location(); loc.setName(" " + NAME + " "); handler.handle(loc, null, null, null); Assert.assertEquals(NAME, loc.getName()); }
/** * @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); }
String origName = location.getName(); String origDesc = location.getDescription(); String newDesc = "new desc"; location.setName(newName); location.setDescription(newDesc); Location newestLoc = ls.getLocation(location.getLocationId()); assertTrue("The name should be the same", newestLoc.getName().equals(newName)); assertFalse("The name should be different", origDesc.equals(newDesc)); assertTrue("The name should be the same", newestLoc.getDescription().equals(newDesc));
/** * @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); }
public PersonAddress build() { PersonAddress address = new PersonAddress(); address.setAddress1(addressLine1); if (community != null) { address.setAddress2(community.getName()); } address.setRegion(location.getRegion()); address.setCountyDistrict(location.getCountyDistrict()); address.setStateProvince(location.getStateProvince()); address.setNeighborhoodCell(location.getName()); return address; }
/** * @see LocationValidator#validate(Object,Errors) */ @Test public void validate_shouldPassValidationIfRetiredLocationIsGivenRetiredReason() { Location location = new Location(); location.setName("County General"); location.setDescription("desc"); location.setRetired(true); location.setRetireReason("Because I don't like County General"); Errors errors = new BindException(location, "location"); new LocationValidator().validate(location, errors); Assert.assertFalse(errors.hasErrors()); }
/** * @see OpenmrsMetadataSaveHandler#handle(OpenmrsMetadata,User,Date,String) */ @Test public void handle_shouldTrimWhitespaceFromDescription() { String DESC = "the location desc"; OpenmrsMetadataSaveHandler handler = new OpenmrsMetadataSaveHandler(); Location loc = new Location(); loc.setName("a name"); loc.setDescription(" " + DESC + " "); handler.handle(loc, null, null, null); Assert.assertEquals(DESC, loc.getDescription()); } }