Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.openmrs.module.basicexample;
- import org.openmrs.BaseOpenmrsData;
- import org.openmrs.User;
- import javax.persistence.Basic;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.Id;
- import javax.persistence.JoinColumn;
- import javax.persistence.ManyToOne;
- import javax.persistence.Table;
- /**
- * Please note that a corresponding table schema must be created in liquibase.xml.
- */
- //Uncomment 2 lines below if you want to make the Item class persistable, see also BasicexampleDaoTest and liquibase.xml
- @Entity(name = "basicexample.Item")
- @Table(name = "basicexample_item")
- public class Item extends BaseOpenmrsData {
- @Id
- @GeneratedValue
- @Column(name = "basicexample_item_id")
- private Integer id;
- @ManyToOne
- @JoinColumn(name = "owner")
- private User owner;
- @Basic
- @Column(name = "description", length = 255)
- private String description;
- @Override
- public Integer getId() {
- return id;
- }
- @Override
- public void setId(Integer id) {
- this.id = id;
- }
- @Override
- public String getUuid() {
- return super.getUuid();
- }
- @Override
- public void setUuid(String uuid) {
- super.setUuid(uuid);
- }
- public User getOwner() {
- return owner;
- }
- public void setOwner(User owner) {
- this.owner = owner;
- }
- public String getDescription() {
- return description;
- }
- public void setDescription(String description) {
- this.description = description;
- }
- }
- package org.openmrs.module.basicexample.web.controller;
- import java.util.List;
- import org.openmrs.api.context.Context;
- import org.openmrs.module.webservices.rest.web.resource.impl.MetadataDelegatingCrudResource;
- import org.openmrs.module.basicexample.Item;
- import org.openmrs.module.basicexample.api.BasicexampleService;
- 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 + "/item", supportedClass = Item.class, supportedOpenmrsVersions = { "2.2.*",
- "2.3.*","2.4.*" })
- public class ItemResource extends DataDelegatingCrudResource<Item> {
- @Override
- public Item getByUniqueId(String string) {
- return null;
- }
- public NeedsPaging<Item> doGetAll(RequestContext context) {
- return new NeedsPaging<Item>(Context.getService(BasicexampleService.class).getAllItems(), context);
- }
- @Override
- protected void delete(Item 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(Item 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 Item newDelegate() {
- return new Item();
- }
- @Override
- public Item save(Item t) {
- Item item = Context.getService(BasicexampleService.class).saveItem(t);
- return item;
- }
- @PropertyGetter("display")
- public String getDisplayString(Item item) {
- return item.getDescription();
- }
- }
- package org.openmrs.module.basicexample.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 + "/basicexample")
- public class BasicexampleResourceController extends MainResourceController {
- /**
- * @see org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController#getNamespace()
- */
- @Override
- public String getNamespace() {
- return "v1/basicexample";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement