Advertisement
Guest User

Untitled

a guest
Mar 1st, 2013
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 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.customdatatype.datatype;
  15.  
  16. import org.apache.commons.lang.StringUtils;
  17. import org.openmrs.Provider;
  18. import org.openmrs.api.context.Context;
  19. import org.openmrs.customdatatype.SerializingCustomDatatype;
  20. import org.springframework.stereotype.Component;
  21.  
  22. /**
  23. * Datatype for Provider, represented by org.openmrs.Provider.
  24. * @since 1.9
  25. */
  26. @Component
  27. public class ProviderDatatype extends SerializingCustomDatatype<Provider> {
  28.  
  29. /**
  30. * @see org.openmrs.customdatatype.SerializingCustomDatatype#serialize(java.lang.Object)
  31. */
  32. @Override
  33. public String serialize(Provider typedValue) {
  34. if (typedValue == null)
  35. return null;
  36. return typedValue.getUuid();
  37. }
  38.  
  39. /**
  40. * @see org.openmrs.customdatatype.SerializingCustomDatatype#deserialize(java.lang.String)
  41. */
  42. @Override
  43. public Provider deserialize(String serializedValue) {
  44. if (StringUtils.isEmpty(serializedValue))
  45. return null;
  46. return Context.getProviderService().getProviderByUuid(serializedValue);
  47. }
  48. }
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55. /**
  56. * The contents of this file are subject to the OpenMRS Public License
  57. * Version 1.0 (the "License"); you may not use this file except in
  58. * compliance with the License. You may obtain a copy of the License at
  59. * http://license.openmrs.org
  60. *
  61. * Software distributed under the License is distributed on an "AS IS"
  62. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  63. * License for the specific language governing rights and limitations
  64. * under the License.
  65. *
  66. * Copyright (C) OpenMRS, LLC. All Rights Reserved.
  67. */
  68. package org.openmrs.web.attribute.handler;
  69.  
  70. import java.util.HashMap;
  71. import java.util.Map;
  72.  
  73. import javax.servlet.http.HttpServletRequest;
  74.  
  75. import org.apache.commons.lang.StringUtils;
  76. import org.openmrs.Provider;
  77. import org.openmrs.api.context.Context;
  78. import org.openmrs.customdatatype.CustomDatatype;
  79. import org.openmrs.customdatatype.InvalidCustomValueException;
  80. import org.openmrs.customdatatype.datatype.ProviderDatatype;
  81. import org.openmrs.messagesource.MessageSourceService;
  82. import org.springframework.stereotype.Component;
  83.  
  84. /**
  85. * Handler for the Provider custom datatype
  86. */
  87. @Component
  88. public class ProviderDatatypeHandler implements FieldGenDatatypeHandler<ProviderDatatype, Provider> {
  89.  
  90. /**
  91. * @see org.openmrs.customdatatype.CustomDatatypeHandler#setHandlerConfiguration(java.lang.String)
  92. */
  93. @Override
  94. public void setHandlerConfiguration(String arg0) {
  95. // not used
  96. }
  97.  
  98. /**
  99. * @see org.openmrs.web.attribute.handler.FieldGenDatatypeHandler#getWidgetName()
  100. */
  101. @Override
  102. public String getWidgetName() {
  103. return "provider";
  104. }
  105.  
  106. /**
  107. * @see org.openmrs.web.attribute.handler.FieldGenDatatypeHandler#getWidgetConfiguration()
  108. */
  109. @Override
  110. public Map<String, Object> getWidgetConfiguration() {
  111. return null;
  112. }
  113.  
  114. /**
  115. * @see org.openmrs.web.attribute.handler.FieldGenDatatypeHandler#getValue(org.openmrs.customdatatype.CustomDatatype, javax.servlet.http.HttpServletRequest, java.lang.String)
  116. */
  117. @Override
  118. public Provider getValue(ProviderDatatype datatype, HttpServletRequest request,
  119. String formFieldName) throws InvalidCustomValueException {
  120. String result = request.getParameter(formFieldName);
  121. if (StringUtils.isBlank(result))
  122. return null;
  123. try {
  124. return Context.getProviderService().getProviderByUuid(result);
  125. }
  126. catch (Exception e) {
  127. throw new InvalidCustomValueException("Invalid provider: " + result);
  128. }
  129. }
  130.  
  131. /**
  132. * @see org.openmrs.web.attribute.handler.HtmlDisplayableDatatypeHandler#toHtmlSummary(org.openmrs.customdatatype.CustomDatatype, java.lang.String)
  133. */
  134. @Override
  135. public CustomDatatype.Summary toHtmlSummary(CustomDatatype<Provider> datatype, String valueReference) {
  136. return new CustomDatatype.Summary(valueReference, true);
  137. }
  138.  
  139. /**
  140. * @see org.openmrs.web.attribute.handler.HtmlDisplayableDatatypeHandler#toHtml(org.openmrs.customdatatype.CustomDatatype, java.lang.String)
  141. */
  142. @Override
  143. public String toHtml(CustomDatatype<Provider> datatype, String valueReference) {
  144. return valueReference;
  145. }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement