public LocationMock(Location loc) { setAddress1(loc.getAddress1()); setAddress2(loc.getAddress2()); setChangedBy(loc.getChangedBy()); setChildLocations(loc.getChildLocations(true)); setCityVillage(loc.getCityVillage()); setCountry(loc.getCountry()); setCountyDistrict(loc.getCountyDistrict()); setCreator(loc.getCreator()); setDateChanged(loc.getDateChanged()); setDateCreated(loc.getDateCreated()); setDateRetired(loc.getDateRetired()); setDescription(loc.getDescription()); setId(loc.getId()); setLatitude(loc.getLatitude()); setLongitude(loc.getLongitude()); setName(loc.getName()); setNeighborhoodCell(loc.getNeighborhoodCell()); setParentLocation(loc.getParentLocation()); setPostalCode(loc.getPostalCode()); setRegion(loc.getRegion()); setRetired(loc.getRetired()); setRetiredBy(loc.getRetiredBy()); setRetireReason(loc.getRetireReason()); setStateProvince(loc.getStateProvince()); setSubregion(loc.getSubregion()); setTags(loc.getTags()); setTownshipDivision(loc.getTownshipDivision()); setUuid(loc.getUuid()); }
/** * The onSubmit function receives the form/command object that was modified by the input form and * saves it to the db * * @see * org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse, java.lang.Object, * org.springframework.validation.BindException) * @should retire location * @should not retire location if reason is empty */ protected ModelAndView onSubmit( HttpServletRequest request, HttpServletResponse response, Object obj, BindException errors) throws Exception { HttpSession httpSession = request.getSession(); String view = getFormView(); if (Context.isAuthenticated()) { try { Location location = (Location) obj; WebAttributeUtil.handleSubmittedAttributesForType( location, errors, LocationAttribute.class, request, Context.getLocationService().getAllLocationAttributeTypes()); if (errors.hasErrors()) { return showForm(request, response, errors); } LocationService locationService = Context.getLocationService(); // if the user was editing the location if (request.getParameter("saveLocation") != null) { locationService.saveLocation(location); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Location.saved"); } // the 'retire this location' button was clicked else if (request.getParameter("retireLocation") != null) { locationService.retireLocation(location, location.getRetireReason()); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Location.retired"); } // the 'unretire this location' button was clicked else if (request.getParameter("unretireLocation") != null) { locationService.unretireLocation(location); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Location.unretired"); } } catch (APIException e) { log.error("Error while saving location: " + obj, e); httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, e.getMessage()); return showForm(request, response, errors); } view = getSuccessView(); } return new ModelAndView(new RedirectView(view)); }