Advertisement
Guest User

Untitled

a guest
Sep 6th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.42 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. package org.openmrs.module.basicexample.web.controller;
  74.  
  75. import java.util.List;
  76. import org.openmrs.api.context.Context;
  77. import org.openmrs.module.webservices.rest.web.resource.impl.MetadataDelegatingCrudResource;
  78. import org.openmrs.module.basicexample.Item;
  79. import org.openmrs.module.basicexample.api.BasicexampleService;
  80. import org.openmrs.module.webservices.rest.web.RequestContext;
  81. import org.openmrs.module.webservices.rest.web.RestConstants;
  82. import org.openmrs.module.webservices.rest.web.annotation.PropertyGetter;
  83. import org.openmrs.module.webservices.rest.web.annotation.Resource;
  84. import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation;
  85. import org.openmrs.module.webservices.rest.web.representation.FullRepresentation;
  86. import org.openmrs.module.webservices.rest.web.representation.Representation;
  87. import org.openmrs.module.webservices.rest.web.resource.api.PageableResult;
  88. import org.openmrs.module.webservices.rest.web.response.ResponseException;
  89. import org.openmrs.module.webservices.rest.web.resource.impl.DataDelegatingCrudResource;
  90. import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
  91. import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging;
  92.  
  93. /**
  94. * @author levine
  95. */
  96. @Resource(name = RestConstants.VERSION_1 + "/item", supportedClass = Item.class, supportedOpenmrsVersions = { "2.2.*",
  97. "2.3.*","2.4.*" })
  98. public class ItemResource extends DataDelegatingCrudResource<Item> {
  99.  
  100. @Override
  101. public Item getByUniqueId(String string) {
  102. return null;
  103. }
  104.  
  105. public NeedsPaging<Item> doGetAll(RequestContext context) {
  106. return new NeedsPaging<Item>(Context.getService(BasicexampleService.class).getAllItems(), context);
  107. }
  108.  
  109. @Override
  110. protected void delete(Item t, String string, RequestContext rc) throws ResponseException {
  111. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  112. }
  113.  
  114. @Override
  115. public void purge(Item t, RequestContext rc) throws ResponseException {
  116. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  117. }
  118.  
  119. @Override
  120. public DelegatingResourceDescription getRepresentationDescription(Representation r) {
  121. if (r instanceof DefaultRepresentation) {
  122. DelegatingResourceDescription description = new DelegatingResourceDescription();
  123. description.addProperty("uuid");
  124. description.addProperty("description");
  125. description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_FULL);
  126. description.addSelfLink();
  127. return description;
  128. } else if (r instanceof FullRepresentation) {
  129. DelegatingResourceDescription description = new DelegatingResourceDescription();
  130. description.addProperty("uuid");
  131. description.addProperty("description");
  132. description.addSelfLink();
  133. return description;
  134. }
  135. return null;
  136. }
  137.  
  138. @Override
  139. public Item newDelegate() {
  140. return new Item();
  141. }
  142.  
  143. @Override
  144. public Item save(Item t) {
  145. Item item = Context.getService(BasicexampleService.class).saveItem(t);
  146. return item;
  147. }
  148.  
  149. @PropertyGetter("display")
  150. public String getDisplayString(Item item) {
  151. return item.getDescription();
  152. }
  153.  
  154. }
  155.  
  156. package org.openmrs.module.basicexample.web.controller;
  157.  
  158. import org.springframework.stereotype.Controller;
  159. import org.springframework.web.bind.annotation.RequestMapping;
  160. import org.openmrs.module.webservices.rest.web.RestConstants;
  161. import org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceController;
  162.  
  163. /**
  164. * @author levine
  165. */
  166. @Controller
  167. @RequestMapping("/rest/" + RestConstants.VERSION_1 + "/basicexample")
  168. public class BasicexampleResourceController extends MainResourceController {
  169.  
  170. /**
  171. * @see org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController#getNamespace()
  172. */
  173. @Override
  174. public String getNamespace() {
  175. return "v1/basicexample";
  176. }
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement