Advertisement
Guest User

Untitled

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