Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8;
- import org.openmrs.scheduler.TaskDefinition;
- import org.openmrs.api.context.Context;
- import org.openmrs.module.webservices.rest.web.RequestContext;
- import org.openmrs.module.webservices.rest.web.RestConstants;
- 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.impl.BaseDelegatingResource;
- import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
- import org.openmrs.module.webservices.rest.web.response.ResponseException;
- import java.util.*;
- /**
- * Resource for Encounters, supporting standard CRUD operations
- */
- @Resource(name = RestConstants.VERSION_1 + "/scheduler", supportedClass = TaskDefinition.class, supportedOpenmrsVersions = "1.8.*")
- public class SchedulerResource1_8 extends BaseDelegatingResource<TaskDefinition> {
- @Override public TaskDefinition getByUniqueId(String uniqueId) {
- return Context.getSchedulerService().getTaskByName(uniqueId);
- }
- @Override protected void delete(TaskDefinition delegate, String reason, RequestContext context)
- throws ResponseException {
- Context.getSchedulerService().deleteTask(delegate.getId());
- }
- @Override public TaskDefinition newDelegate() {
- TaskDefinition task=new TaskDefinition();
- Map<String, String> properties = new HashMap<String, String>();
- task.setProperties(properties);
- task.setRepeatInterval(0L);
- return task;
- }
- @Override public TaskDefinition save(TaskDefinition delegate) {
- Context.getSchedulerService().saveTaskDefinition(delegate);
- return Context.getSchedulerService().getTaskByName(delegate.getName());
- }
- @Override public void purge(TaskDefinition delegate, RequestContext context) throws ResponseException {
- }
- @Override public DelegatingResourceDescription getRepresentationDescription(Representation rep) {
- if (rep instanceof DefaultRepresentation) {
- DelegatingResourceDescription description = new DelegatingResourceDescription();
- description.addProperty("uuid");
- description.addProperty("display");
- description.addProperty("encounterDatetime");
- description.addProperty("nextExecutionTime");
- description.addProperty("lastExecutionTime");
- description.addProperty("started");
- description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_FULL);
- return description;
- } else if (rep instanceof FullRepresentation) {
- DelegatingResourceDescription description = new DelegatingResourceDescription();
- description.addProperty("uuid");
- description.addProperty("display");
- description.addProperty("encounterDatetime");
- description.addProperty("secondsUntilNextExecutionTime");
- description.addProperty("repeatInterval");
- description.addProperty("nextExecutionTime");
- description.addProperty("lastExecutionTime");
- description.addProperty("started");
- description.addSelfLink();
- return description;
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement