Advertisement
suthagar23

TaskResource1_8 1

Aug 8th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.61 KB | None | 0 0
  1. /**
  2. * This Source Code Form is subject to the terms of the Mozilla Public License,
  3. * v. 2.0. If a copy of the MPL was not distributed with this file, You can
  4. * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
  5. * the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
  6. *
  7. * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
  8. * graphic logo is a trademark of OpenMRS Inc.
  9. */
  10. package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8;
  11.  
  12. import org.openmrs.module.webservices.rest.web.annotation.PropertyGetter;
  13. import org.openmrs.module.webservices.rest.web.representation.RefRepresentation;
  14. import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging;
  15. import org.openmrs.scheduler.Schedule;
  16. import org.openmrs.scheduler.TaskDefinition;
  17. import org.openmrs.api.context.Context;
  18. import org.openmrs.module.webservices.rest.web.RequestContext;
  19. import org.openmrs.module.webservices.rest.web.RestConstants;
  20. import org.openmrs.module.webservices.rest.web.annotation.Resource;
  21. import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation;
  22. import org.openmrs.module.webservices.rest.web.representation.FullRepresentation;
  23. import org.openmrs.module.webservices.rest.web.representation.Representation;
  24. import org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingReadableResource;
  25. import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
  26. import org.openmrs.module.webservices.rest.web.response.ResponseException;
  27. import org.openmrs.scheduler.TaskFactory;
  28.  
  29. import java.util.*;
  30.  
  31. /**
  32. * Resource for Encounters, supporting standard CRUD operations
  33. */
  34. @Resource(name = RestConstants.VERSION_1 + "/scheduler", supportedClass = TaskDefinition.class, supportedOpenmrsVersions = {
  35. "1.8.*", "1.9.*", "1.10.*", "1.11.*", "1.12.*", "2.0.*", "2.1.*" })
  36. public class TaskResource1_8 extends BaseDelegatingReadableResource<TaskDefinition> {
  37.  
  38. @Override
  39. public TaskDefinition newDelegate() {
  40. return null;
  41. }
  42.  
  43. @Override
  44. public DelegatingResourceDescription getRepresentationDescription(Representation rep) {
  45. if (rep instanceof DefaultRepresentation) {
  46. DelegatingResourceDescription description = new DelegatingResourceDescription();
  47. description.addProperty("uuid");
  48. description.addProperty("taskClass");
  49. description.addProperty("startTime");
  50. description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_FULL);
  51. return description;
  52. } else if (rep instanceof FullRepresentation) {
  53. DelegatingResourceDescription description = new DelegatingResourceDescription();
  54. description.addProperty("uuid");
  55. description.addProperty("taskClass");
  56. description.addProperty("startTime");
  57. description.addProperty("lastExecutionTime");
  58. description.addProperty("repeatInterval");
  59. description.addProperty("startOnStartup");
  60. description.addProperty("startTimePattern");
  61. description.addProperty("started");
  62. description.addSelfLink();
  63. return description;
  64. } else if (rep instanceof RefRepresentation) {
  65. DelegatingResourceDescription description = new DelegatingResourceDescription();
  66. description.addProperty("uuid");
  67. description.addProperty("taskClass");
  68. return description;
  69. }
  70. return null;
  71. }
  72.  
  73. @Override
  74. public TaskDefinition getByUniqueId(String uniqueId) {
  75. return Context.getSchedulerService().getTaskByName(uniqueId);
  76. }
  77.  
  78. /**
  79. * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doGetAll(org.openmrs.module.webservices.rest.web.RequestContext)
  80. */
  81. @Override
  82. public NeedsPaging<TaskDefinition> doGetAll(RequestContext context) throws ResponseException {
  83. return new NeedsPaging<TaskDefinition>(new ArrayList<TaskDefinition>(Context.getSchedulerService()
  84. .getScheduledTasks()), context);
  85. }
  86.  
  87. @PropertyGetter("uuid")
  88. public static String getUuid(TaskDefinition instance) {
  89. return instance.getUuid();
  90. }
  91.  
  92. @PropertyGetter("display")
  93. public static String getDisplay(TaskDefinition instance) {
  94. return instance.getName();
  95. }
  96.  
  97. // @Override public TaskDefinition getByUniqueId(String uniqueId) {
  98. // return Context.getSchedulerService().getTaskByName(uniqueId);
  99. // }
  100. //
  101. // @Override protected void delete(TaskDefinition delegate, String reason, RequestContext context)
  102. // throws ResponseException {
  103. // Context.getSchedulerService().deleteTask(delegate.getId());
  104. //
  105. // }
  106. //
  107. // @Override public TaskDefinition newDelegate() {
  108. // TaskDefinition task=new TaskDefinition();
  109. // Map<String, String> properties = new HashMap<String, String>();
  110. // task.setProperties(properties);
  111. // task.setRepeatInterval(0L);
  112. // return task;
  113. // }
  114. //
  115. // @Override public TaskDefinition save(TaskDefinition delegate) {
  116. // Context.getSchedulerService().saveTaskDefinition(delegate);
  117. // return Context.getSchedulerService().getTaskByName(delegate.getName());
  118. // }
  119. //
  120. // @Override public void purge(TaskDefinition delegate, RequestContext context) throws ResponseException {
  121. //
  122. // }
  123. //
  124. // @Override public DelegatingResourceDescription getRepresentationDescription(Representation rep) {
  125. // if (rep instanceof DefaultRepresentation) {
  126. // DelegatingResourceDescription description = new DelegatingResourceDescription();
  127. // description.addProperty("uuid");
  128. // description.addProperty("display");
  129. // description.addProperty("encounterDatetime");
  130. // description.addProperty("nextExecutionTime");
  131. // description.addProperty("lastExecutionTime");
  132. // description.addProperty("started");
  133. // description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_FULL);
  134. // return description;
  135. // } else if (rep instanceof FullRepresentation) {
  136. // DelegatingResourceDescription description = new DelegatingResourceDescription();
  137. // description.addProperty("uuid");
  138. // description.addProperty("display");
  139. // description.addProperty("encounterDatetime");
  140. // description.addProperty("secondsUntilNextExecutionTime");
  141. // description.addProperty("repeatInterval");
  142. // description.addProperty("nextExecutionTime");
  143. // description.addProperty("lastExecutionTime");
  144. // description.addProperty("started");
  145. // description.addSelfLink();
  146. // return description;
  147. // }
  148. // return null;
  149. // }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement