SHARE
TWEET

Untitled

a guest Sep 17th, 2019 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package org.openmrs.module.basicmod;
  2.  
  3. import java.io.Serializable;
  4. import org.openmrs.BaseOpenmrsData;
  5.  
  6. public class DbTestItem extends BaseOpenmrsData implements Serializable {
  7.    
  8.     private static final long serialVersionUID = 1L;
  9.    
  10.     private int id;
  11.    
  12.     private String description;
  13.    
  14.     public String getDescription() {
  15.         return description;
  16.     }
  17.    
  18.     public void setDescription(String description) {
  19.         this.description = description;
  20.     }
  21.    
  22.     public Integer getId() {
  23.         return id;
  24.     }
  25.    
  26.     /**
  27.      * The primary key for this DbTestItem. If this is null, the database will generate the integer
  28.      * primary key because we marked the DbTestItem.id column to auto_increment. <br/>
  29.      * <br/>
  30.      *
  31.      * @see org.openmrs.OpenmrsObject#setId(java.lang.Integer)
  32.      */
  33.     public void setId(Integer id) {
  34.         this.id = id;
  35.     }
  36.    
  37. }
  38.  
  39.  
  40. package org.openmrs.module.basicmod.web.controller;
  41.  
  42. import org.springframework.stereotype.Controller;
  43. import org.springframework.web.bind.annotation.RequestMapping;
  44. import org.openmrs.module.webservices.rest.web.RestConstants;
  45. import org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceController;
  46.  
  47. /**
  48.  * @author levine
  49.  */
  50. @Controller
  51. @RequestMapping("/rest/" + RestConstants.VERSION_1 + "/basicmod")
  52. public class BasicmodResourceController extends MainResourceController {
  53.    
  54.     /**
  55.      * @see org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController#getNamespace()
  56.      */
  57.     @Override
  58.     public String getNamespace() {
  59.         return "v1/basicmod";
  60.     }
  61. }
  62.  
  63.  
  64.  
  65. package org.openmrs.module.basicmod.web.controller;
  66.  
  67. import java.util.List;
  68. import org.openmrs.api.context.Context;
  69. import org.openmrs.module.basicmod.DbTestItem;
  70. import org.openmrs.module.basicmod.api.DbTestItemService;
  71. import org.openmrs.module.webservices.rest.web.resource.impl.MetadataDelegatingCrudResource;
  72. import org.openmrs.module.webservices.rest.web.RequestContext;
  73. import org.openmrs.module.webservices.rest.web.RestConstants;
  74. import org.openmrs.module.webservices.rest.web.annotation.PropertyGetter;
  75. import org.openmrs.module.webservices.rest.web.annotation.Resource;
  76. import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation;
  77. import org.openmrs.module.webservices.rest.web.representation.FullRepresentation;
  78. import org.openmrs.module.webservices.rest.web.representation.Representation;
  79. import org.openmrs.module.webservices.rest.web.resource.api.PageableResult;
  80. import org.openmrs.module.webservices.rest.web.response.ResponseException;
  81. import org.openmrs.module.webservices.rest.web.resource.impl.DataDelegatingCrudResource;
  82. import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
  83. import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging;
  84.  
  85. /**
  86.  * @author levine
  87.  */
  88. @Resource(name = RestConstants.VERSION_1 + "/dbTestItem", supportedClass = DbTestItem.class, supportedOpenmrsVersions = {
  89.         "2.0.*", "2.1.*", "2.2.*", "2.3.*", "2.4.*" })
  90. public class BasicmodResource extends DataDelegatingCrudResource<DbTestItem> {
  91.    
  92.     public DbTestItem get() {
  93.         System.out.println("****************GET: ");
  94.         List<DbTestItem> its = Context.getService(DbTestItemService.class).getAllDbTestItems();
  95.         if (its != null) {
  96.             if (!its.isEmpty()) {
  97.                 return its.get(0);
  98.             }
  99.         }
  100.         DbTestItem it = new DbTestItem();
  101.         it.setDescription("my description");
  102.         return it;
  103.     }
  104.    
  105.     public NeedsPaging<DbTestItem> doGetAll(RequestContext context) {
  106.         System.out.println("****************doGetAll: " + context);
  107.         return new NeedsPaging<DbTestItem>(Context.getService(DbTestItemService.class).getAllDbTestItems(), context);
  108.     }
  109.    
  110.     @Override
  111.     public DbTestItem getByUniqueId(String string) {
  112.         throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  113.     }
  114.    
  115.     @Override
  116.     protected void delete(DbTestItem t, String string, RequestContext rc) throws ResponseException {
  117.         throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  118.     }
  119.    
  120.     @Override
  121.     public void purge(DbTestItem t, RequestContext rc) throws ResponseException {
  122.         throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  123.     }
  124.    
  125.     @Override
  126.     public DelegatingResourceDescription getRepresentationDescription(Representation r) {
  127.         if (r instanceof DefaultRepresentation) {
  128.             DelegatingResourceDescription description = new DelegatingResourceDescription();
  129.             //description.addProperty("uuid");
  130.             description.addProperty("description");
  131.             description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_FULL);
  132.             description.addSelfLink();
  133.             return description;
  134.         } else if (r instanceof FullRepresentation) {
  135.             DelegatingResourceDescription description = new DelegatingResourceDescription();
  136.             //description.addProperty("uuid");
  137.             description.addProperty("description");
  138.             description.addSelfLink();
  139.             return description;
  140.         }
  141.         return null;
  142.     }
  143.    
  144.     @Override
  145.     public DbTestItem newDelegate() {
  146.         System.out.println("****************newDelegate: ");
  147.         return new DbTestItem();
  148.     }
  149.    
  150.     @Override
  151.     public DbTestItem save(DbTestItem t) {
  152.         System.out.println("****************SAVE: " + t);
  153.         DbTestItem item = Context.getService(DbTestItemService.class).saveDbTestItem(t);
  154.         System.out.println("****************ITEM SAVED: ");
  155.         return item;
  156.     }
  157.    
  158.     @PropertyGetter("display")
  159.     public String getDisplayString(DbTestItem item) {
  160.         return item.getDescription();
  161.     }
  162.    
  163. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top