REST Implementation for Scheduler in Legacy UI Module

I am working on RESTWS-674 ticket to implement REST for Scheduler in LegacyUI module.

In the dashboard, Scheduler contains a list of task definitions. Here I wanted to follow two classes from OpenMRS Core

Here I am going to expose this following details through the REST serveices,

TaskDefinition - GET /rest/v1/taskdefinition/

  1. uuid
  2. name
  3. descriptio
  4. taskClass
  5. startTime
  6. lastExecutionTime
  7. repeatInterval
  8. startOnStartup
  9. started
  10. properties

@dkayiwa Is it ok with the implementation ?

Looks like a good start! :slight_smile:

I don’t think Schedule is really part of the public API, in fact don’t think it’s used anywhere, I’d say just ignore it.

@wyclif Here I wanted to implement Manage Scheduler functionalities in OWA, So I need to implement REST services for TaskDefinitions to complete that task.

@dkayiwa Can you review it please

You need to add some tests.

@dkayiwa I have added some test cases, but getting some errors. Can you take a look at here, Test class : https://pastebin.com/nTZXv2fQ Error trace : https://pastebin.com/XP7KHCPr

When you fetch that task with getTaskByName, does it actually exist?

Yah, I can get it through the REST Request, But can’t through the Test Case

You can mock it, or else add a test dataset https://wiki.openmrs.org/display/docs/Unit+Testing+with+Database+Data

Finally, I have implemented two resources for this purpose and all are working as expected :slight_smile:

TaskDefinition - /openmrs/ws/rest/v1/taskdefinition

  • GET - return all the registered tasks

  • POST - Create new definition

  • POST/{taskName} - update the task definition

TaskAction - /openmrs/ws/rest/v1/taskaction

  • POST - post the action, task information to do Action types : SCHEDULETASK, SHUTDOWNTASK, RESCHEDULETASK, RESCHEDULEALLTASK, DELETE, ONSTARTUP, ONSHUTDOWN Post Body : {“action” : “scheduletask”, “tasks” : [“sample”], “allTasks” : true }

cc : @dkayiwa

@dkayiwa I have updated the PR but failed in Travis.

I could get success with my local project but Travis check was failed. Can you please take a look on this error?

https://travis-ci.org/openmrs/openmrs-module-webservices.rest/builds/269501880?utm_source=github_status&utm_medium=notification

Did you look at the failure log?

@dkayiwa It showed me the COMPILATION ERROR in the Travis check. But I can compile and build it locally without any errors.

[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /home/travis/build/openmrs/openmrs-module-webservices.rest/omod1.8/src/main/java
/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/TaskActionResource1_8.java:[35,8] org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.TaskActionResource1_8 
is not abstract and does not override abstract method getCREATEModel(org.openmrs.module.webservices.rest.web.representation.Representation) in
org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler

Did you pull the latest upstream changes into your local version?

@dkayiwa

Yah, with in a short time, the code has been changed in the master due to the other PRs :joy:. Thanks for the advice!

Now It is working without any problem :smiley:

@suthagar23 do you have a real example of the post payload for the TaskAction ?