Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.openmrs.module.basicmod;
- import java.io.Serializable;
- import org.openmrs.BaseOpenmrsData;
- public class DbTestItem extends BaseOpenmrsData implements Serializable {
- private static final long serialVersionUID = 1L;
- private int id;
- private String description;
- public String getDescription() {
- return description;
- }
- public void setDescription(String description) {
- this.description = description;
- }
- public Integer getId() {
- return id;
- }
- /**
- * The primary key for this DbTestItem. If this is null, the database will generate the integer
- * primary key because we marked the DbTestItem.id column to auto_increment. <br/>
- * <br/>
- *
- * @see org.openmrs.OpenmrsObject#setId(java.lang.Integer)
- */
- public void setId(Integer id) {
- this.id = id;
- }
- }
- package org.openmrs.module.basicmod.web.controller;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.openmrs.module.webservices.rest.web.RestConstants;
- import org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceController;
- /**
- * @author levine
- */
- @Controller
- @RequestMapping("/rest/" + RestConstants.VERSION_1 + "/basicmod")
- public class BasicmodResourceController extends MainResourceController {
- /**
- * @see org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController#getNamespace()
- */
- @Override
- public String getNamespace() {
- return "v1/basicmod";
- }
- }
- package org.openmrs.module.basicmod.web.controller;
- import java.util.List;
- import org.openmrs.api.context.Context;
- import org.openmrs.module.basicmod.DbTestItem;
- import org.openmrs.module.basicmod.api.DbTestItemService;
- import org.openmrs.module.webservices.rest.web.resource.impl.MetadataDelegatingCrudResource;
- import org.openmrs.module.webservices.rest.web.RequestContext;
- import org.openmrs.module.webservices.rest.web.RestConstants;
- import org.openmrs.module.webservices.rest.web.annotation.PropertyGetter;
- import org.openmrs.module.webservices.rest.web.annotation.Resource;
- import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation;
- import org.openmrs.module.webservices.rest.web.representation.FullRepresentation;
- import org.openmrs.module.webservices.rest.web.representation.Representation;
- import org.openmrs.module.webservices.rest.web.resource.api.PageableResult;
- import org.openmrs.module.webservices.rest.web.response.ResponseException;
- import org.openmrs.module.webservices.rest.web.resource.impl.DataDelegatingCrudResource;
- import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
- import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging;
- /**
- * @author levine
- */
- @Resource(name = RestConstants.VERSION_1 + "/dbTestItem", supportedClass = DbTestItem.class, supportedOpenmrsVersions = {
- "2.0.*", "2.1.*", "2.2.*", "2.3.*", "2.4.*" })
- public class BasicmodResource extends DataDelegatingCrudResource<DbTestItem> {
- public DbTestItem get() {
- System.out.println("****************GET: ");
- List<DbTestItem> its = Context.getService(DbTestItemService.class).getAllDbTestItems();
- if (its != null) {
- if (!its.isEmpty()) {
- return its.get(0);
- }
- }
- DbTestItem it = new DbTestItem();
- it.setDescription("my description");
- return it;
- }
- public NeedsPaging<DbTestItem> doGetAll(RequestContext context) {
- System.out.println("****************doGetAll: " + context);
- return new NeedsPaging<DbTestItem>(Context.getService(DbTestItemService.class).getAllDbTestItems(), context);
- }
- @Override
- public DbTestItem getByUniqueId(String string) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- @Override
- protected void delete(DbTestItem t, String string, RequestContext rc) throws ResponseException {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- @Override
- public void purge(DbTestItem t, RequestContext rc) throws ResponseException {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- @Override
- public DelegatingResourceDescription getRepresentationDescription(Representation r) {
- if (r instanceof DefaultRepresentation) {
- DelegatingResourceDescription description = new DelegatingResourceDescription();
- //description.addProperty("uuid");
- description.addProperty("description");
- description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_FULL);
- description.addSelfLink();
- return description;
- } else if (r instanceof FullRepresentation) {
- DelegatingResourceDescription description = new DelegatingResourceDescription();
- //description.addProperty("uuid");
- description.addProperty("description");
- description.addSelfLink();
- return description;
- }
- return null;
- }
- @Override
- public DbTestItem newDelegate() {
- System.out.println("****************newDelegate: ");
- return new DbTestItem();
- }
- @Override
- public DbTestItem save(DbTestItem t) {
- System.out.println("****************SAVE: " + t);
- DbTestItem item = Context.getService(DbTestItemService.class).saveDbTestItem(t);
- System.out.println("****************ITEM SAVED: ");
- return item;
- }
- @PropertyGetter("display")
- public String getDisplayString(DbTestItem item) {
- return item.getDescription();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement