Advertisement
Guest User

Untitled

a guest
Dec 11th, 2012
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. /**
  2. * The contents of this file are subject to the OpenMRS Public License
  3. * Version 1.0 (the "License"); you may not use this file except in
  4. * compliance with the License. You may obtain a copy of the License at
  5. * http://license.openmrs.org
  6. *
  7. * Software distributed under the License is distributed on an "AS IS"
  8. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  9. * License for the specific language governing rights and limitations
  10. * under the License.
  11. *
  12. * Copyright (C) OpenMRS, LLC. All Rights Reserved.
  13. */
  14. package org.openmrs.module.appointment.web;
  15.  
  16. import java.beans.PropertyEditorSupport;
  17.  
  18. import org.apache.commons.logging.Log;
  19. import org.apache.commons.logging.LogFactory;
  20. import org.openmrs.api.context.Context;
  21. import org.openmrs.module.appointment.TimeSlot;
  22. import org.openmrs.module.appointment.api.AppointmentService;
  23. import org.springframework.util.StringUtils;
  24.  
  25. public class TimeSlotEditor extends PropertyEditorSupport {
  26.  
  27. private Log log = LogFactory.getLog(this.getClass());
  28.  
  29. public TimeSlotEditor() {
  30. }
  31.  
  32. /**
  33. * @should set using id
  34. * @should set using uuid
  35. */
  36. public void setAsText(String text) throws IllegalArgumentException {
  37. AppointmentService as = Context.getService(AppointmentService.class);
  38. if (StringUtils.hasText(text)) {
  39. try {
  40. setValue(as.getTimeSlot(Integer.valueOf(text)));
  41. }
  42. catch (Exception ex) {
  43. TimeSlot ts = as.getTimeSlotByUuid(text);
  44. setValue(ts);
  45. if (ts == null) {
  46. log.error("Error setting text: " + text, ex);
  47. throw new IllegalArgumentException("TimeSlot not found: " + ex.getMessage());
  48. }
  49. }
  50. } else {
  51. setValue(null);
  52. }
  53. }
  54.  
  55. public String getAsText() {
  56. TimeSlot t = (TimeSlot) getValue();
  57. if (t == null) {
  58. return "";
  59. } else {
  60. return t.getTimeSlotId().toString();
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement