Advertisement
Guest User

Untitled

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