Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.45 KB | None | 0 0
  1. package org.openmrs.module.basicexample;
  2.  
  3. import org.openmrs.BaseOpenmrsData;
  4. import org.openmrs.User;
  5.  
  6. import javax.persistence.Basic;
  7. import javax.persistence.Column;
  8. import javax.persistence.Entity;
  9. import javax.persistence.GeneratedValue;
  10. import javax.persistence.Id;
  11. import javax.persistence.JoinColumn;
  12. import javax.persistence.ManyToOne;
  13. import javax.persistence.Table;
  14.  
  15. /**
  16. * Please note that a corresponding table schema must be created in liquibase.xml.
  17. */
  18. //Uncomment 2 lines below if you want to make the Item class persistable, see also BasicexampleDaoTest and liquibase.xml
  19. @Entity(name = "basicexample.Item")
  20. @Table(name = "basicexample_item")
  21. public class Item extends BaseOpenmrsData {
  22.  
  23. @Id
  24. @GeneratedValue
  25. @Column(name = "basicexample_item_id")
  26. private Integer id;
  27.  
  28. @ManyToOne
  29. @JoinColumn(name = "owner")
  30. private User owner;
  31.  
  32. @Basic
  33. @Column(name = "description", length = 255)
  34. private String description;
  35.  
  36. @Override
  37. public Integer getId() {
  38. return id;
  39. }
  40.  
  41. @Override
  42. public void setId(Integer id) {
  43. this.id = id;
  44. }
  45.  
  46. @Override
  47. public String getUuid() {
  48. return super.getUuid();
  49. }
  50.  
  51. @Override
  52. public void setUuid(String uuid) {
  53. super.setUuid(uuid);
  54. }
  55.  
  56. public User getOwner() {
  57. return owner;
  58. }
  59.  
  60. public void setOwner(User owner) {
  61. this.owner = owner;
  62. }
  63.  
  64. public String getDescription() {
  65. return description;
  66. }
  67.  
  68. public void setDescription(String description) {
  69. this.description = description;
  70. }
  71. }
  72.  
  73.  
  74.  
  75. package org.openmrs.module.basicexample.web.controller;
  76.  
  77. import org.springframework.stereotype.Controller;
  78. import org.springframework.web.bind.annotation.RequestMapping;
  79. import org.openmrs.module.webservices.rest.web.RestConstants;
  80. import org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceController;
  81.  
  82. /**
  83. * @author levine
  84. */
  85. @Controller
  86. @RequestMapping("/rest/" + RestConstants.VERSION_1 + "/basicexample")
  87. public class BasicexampleResourceController extends MainResourceController {
  88.  
  89. /**
  90. * @see org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController#getNamespace()
  91. */
  92. @Override
  93. public String getNamespace() {
  94. return "v1/basicexample";
  95. }
  96. }
  97.  
  98.  
  99. package org.openmrs.module.basicexample.web.controller;
  100.  
  101. import java.util.List;
  102. import org.openmrs.api.context.Context;
  103. import org.openmrs.module.webservices.rest.web.resource.impl.MetadataDelegatingCrudResource;
  104. import org.openmrs.module.basicexample.Item;
  105. import org.openmrs.module.basicexample.api.BasicexampleService;
  106. import org.openmrs.module.webservices.rest.web.RequestContext;
  107. import org.openmrs.module.webservices.rest.web.RestConstants;
  108. import org.openmrs.module.webservices.rest.web.annotation.PropertyGetter;
  109. import org.openmrs.module.webservices.rest.web.annotation.Resource;
  110. import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation;
  111. import org.openmrs.module.webservices.rest.web.representation.FullRepresentation;
  112. import org.openmrs.module.webservices.rest.web.representation.Representation;
  113. import org.openmrs.module.webservices.rest.web.resource.api.PageableResult;
  114. import org.openmrs.module.webservices.rest.web.response.ResponseException;
  115. import org.openmrs.module.webservices.rest.web.resource.impl.DataDelegatingCrudResource;
  116. import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
  117. import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging;
  118.  
  119. /**
  120. * @author levine
  121. */
  122. @Resource(name = RestConstants.VERSION_1 + "/basicexample/item", supportedClass = Item.class, supportedOpenmrsVersions = {
  123. "2.2.*", "2.3.*", "2.4.*" })
  124. public class BasicexampleResource extends DataDelegatingCrudResource<Item> {
  125.  
  126. @Override
  127. public Item getByUniqueId(String string) {
  128. return null;
  129. }
  130.  
  131. public NeedsPaging<Item> doGetAll(RequestContext context) {
  132. return new NeedsPaging<Item>(Context.getService(BasicexampleService.class).getAllItems(), context);
  133. }
  134.  
  135. @Override
  136. protected void delete(Item t, String string, RequestContext rc) throws ResponseException {
  137. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  138. }
  139.  
  140. @Override
  141. public void purge(Item t, RequestContext rc) throws ResponseException {
  142. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  143. }
  144.  
  145. @Override
  146. public DelegatingResourceDescription getRepresentationDescription(Representation r) {
  147. if (r instanceof DefaultRepresentation) {
  148. DelegatingResourceDescription description = new DelegatingResourceDescription();
  149. description.addProperty("uuid");
  150. description.addProperty("description");
  151. description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_FULL);
  152. description.addSelfLink();
  153. return description;
  154. } else if (r instanceof FullRepresentation) {
  155. DelegatingResourceDescription description = new DelegatingResourceDescription();
  156. description.addProperty("uuid");
  157. description.addProperty("description");
  158. description.addSelfLink();
  159. return description;
  160. }
  161. return null;
  162. }
  163.  
  164. @Override
  165. public Item newDelegate() {
  166. return new Item();
  167. }
  168.  
  169. @Override
  170. public Item save(Item t) {
  171. Item item = Context.getService(BasicexampleService.class).saveItem(t);
  172. return item;
  173. }
  174.  
  175. @PropertyGetter("display")
  176. public String getDisplayString(Item item) {
  177. return item.getDescription();
  178. }
  179.  
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement