Advertisement
Guest User

Untitled

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