Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This Source Code Form is subject to the terms of the Mozilla Public License,
- * v. 2.0. If a copy of the MPL was not distributed with this file, You can
- * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
- * the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
- *
- * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
- * graphic logo is a trademark of OpenMRS Inc.
- */
- package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8;
- import org.openmrs.module.webservices.rest.web.annotation.PropertyGetter;
- import org.openmrs.module.webservices.rest.web.representation.RefRepresentation;
- import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging;
- import org.openmrs.scheduler.Schedule;
- 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.BaseDelegatingReadableResource;
- import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
- import org.openmrs.module.webservices.rest.web.response.ResponseException;
- import org.openmrs.scheduler.TaskFactory;
- import java.util.*;
- /**
- * Resource for Encounters, supporting standard CRUD operations
- */
- @Resource(name = RestConstants.VERSION_1 + "/scheduler", supportedClass = TaskDefinition.class, supportedOpenmrsVersions = {
- "1.8.*", "1.9.*", "1.10.*", "1.11.*", "1.12.*", "2.0.*", "2.1.*" })
- public class TaskResource1_8 extends BaseDelegatingReadableResource<TaskDefinition> {
- @Override
- public TaskDefinition newDelegate() {
- return null;
- }
- @Override
- public DelegatingResourceDescription getRepresentationDescription(Representation rep) {
- if (rep instanceof DefaultRepresentation) {
- DelegatingResourceDescription description = new DelegatingResourceDescription();
- description.addProperty("uuid");
- description.addProperty("taskClass");
- description.addProperty("startTime");
- description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_FULL);
- return description;
- } else if (rep instanceof FullRepresentation) {
- DelegatingResourceDescription description = new DelegatingResourceDescription();
- description.addProperty("uuid");
- description.addProperty("taskClass");
- description.addProperty("startTime");
- description.addProperty("lastExecutionTime");
- description.addProperty("repeatInterval");
- description.addProperty("startOnStartup");
- description.addProperty("startTimePattern");
- description.addProperty("started");
- description.addSelfLink();
- return description;
- } else if (rep instanceof RefRepresentation) {
- DelegatingResourceDescription description = new DelegatingResourceDescription();
- description.addProperty("uuid");
- description.addProperty("taskClass");
- return description;
- }
- return null;
- }
- @Override
- public TaskDefinition getByUniqueId(String uniqueId) {
- return Context.getSchedulerService().getTaskByName(uniqueId);
- }
- /**
- * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doGetAll(org.openmrs.module.webservices.rest.web.RequestContext)
- */
- @Override
- public NeedsPaging<TaskDefinition> doGetAll(RequestContext context) throws ResponseException {
- return new NeedsPaging<TaskDefinition>(new ArrayList<TaskDefinition>(Context.getSchedulerService()
- .getScheduledTasks()), context);
- }
- @PropertyGetter("uuid")
- public static String getUuid(TaskDefinition instance) {
- return instance.getUuid();
- }
- @PropertyGetter("display")
- public static String getDisplay(TaskDefinition instance) {
- return instance.getName();
- }
- // @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