Advertisement
suthagar23

SchedulerResource1_8 1

Aug 8th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8;
  2.  
  3. import org.openmrs.scheduler.TaskDefinition;
  4. import org.openmrs.api.context.Context;
  5. import org.openmrs.module.webservices.rest.web.RequestContext;
  6. import org.openmrs.module.webservices.rest.web.RestConstants;
  7. import org.openmrs.module.webservices.rest.web.annotation.Resource;
  8. import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation;
  9. import org.openmrs.module.webservices.rest.web.representation.FullRepresentation;
  10. import org.openmrs.module.webservices.rest.web.representation.Representation;
  11. import org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource;
  12. import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
  13. import org.openmrs.module.webservices.rest.web.response.ResponseException;
  14.  
  15. import java.util.*;
  16.  
  17. /**
  18. * Resource for Encounters, supporting standard CRUD operations
  19. */
  20. @Resource(name = RestConstants.VERSION_1 + "/scheduler", supportedClass = TaskDefinition.class, supportedOpenmrsVersions = "1.8.*")
  21. public class SchedulerResource1_8 extends BaseDelegatingResource<TaskDefinition> {
  22.  
  23. @Override public TaskDefinition getByUniqueId(String uniqueId) {
  24. return Context.getSchedulerService().getTaskByName(uniqueId);
  25. }
  26.  
  27. @Override protected void delete(TaskDefinition delegate, String reason, RequestContext context)
  28. throws ResponseException {
  29. Context.getSchedulerService().deleteTask(delegate.getId());
  30.  
  31. }
  32.  
  33. @Override public TaskDefinition newDelegate() {
  34. TaskDefinition task=new TaskDefinition();
  35. Map<String, String> properties = new HashMap<String, String>();
  36. task.setProperties(properties);
  37. task.setRepeatInterval(0L);
  38. return task;
  39. }
  40.  
  41. @Override public TaskDefinition save(TaskDefinition delegate) {
  42. Context.getSchedulerService().saveTaskDefinition(delegate);
  43. return Context.getSchedulerService().getTaskByName(delegate.getName());
  44. }
  45.  
  46. @Override public void purge(TaskDefinition delegate, RequestContext context) throws ResponseException {
  47.  
  48. }
  49.  
  50. @Override public DelegatingResourceDescription getRepresentationDescription(Representation rep) {
  51. if (rep instanceof DefaultRepresentation) {
  52. DelegatingResourceDescription description = new DelegatingResourceDescription();
  53. description.addProperty("uuid");
  54. description.addProperty("display");
  55. description.addProperty("encounterDatetime");
  56. description.addProperty("nextExecutionTime");
  57. description.addProperty("lastExecutionTime");
  58. description.addProperty("started");
  59. description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_FULL);
  60. return description;
  61. } else if (rep instanceof FullRepresentation) {
  62. DelegatingResourceDescription description = new DelegatingResourceDescription();
  63. description.addProperty("uuid");
  64. description.addProperty("display");
  65. description.addProperty("encounterDatetime");
  66. description.addProperty("secondsUntilNextExecutionTime");
  67. description.addProperty("repeatInterval");
  68. description.addProperty("nextExecutionTime");
  69. description.addProperty("lastExecutionTime");
  70. description.addProperty("started");
  71. description.addSelfLink();
  72. return description;
  73. }
  74. return null;
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement