Skip to content

Commit

Permalink
Adding support for retrieving camunda tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Waldz authored Nov 14, 2016
2 parents c3b6748 + 8f116f2 commit e9c77ba
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
10 changes: 10 additions & 0 deletions client_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@ package go_camunda_client
type CamundaClient interface {
StartProcess(processDefinitionKey string, request interface{}) (Process, error)
GetProcess(processId string) (Process, error)
GetNextTask(processId string) (Task, error)
GetAllTasks(processId string) ([]Task, error)
HandleErrors(errorCallback func(error))
}

type Process interface {
GetId() string
IsEnded() bool
}

type Task interface {
GetId() string
GetName() string
GetTaskDefinitionKey() string
}


29 changes: 27 additions & 2 deletions rest/client_rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func Construct(urlRoot string, username string, password string, httpClient http
func (client *camundaClientRest) StartProcess(processDefinitionKey string, request interface{}) (go_camunda_client.Process, error) {
var process dto.Process

response, err := client.doRequest("POST", "process-definition/key/"+processDefinitionKey+"/start", request)
response, err := client.doRequest("POST", "process-definition/key/" + processDefinitionKey + "/start", request)
if err == nil {
err = client.parseResponseJson(response, &process)
defer response.Body.Close()
Expand All @@ -36,7 +36,7 @@ func (client *camundaClientRest) StartProcess(processDefinitionKey string, reque
func (client *camundaClientRest) GetProcess(processId string) (go_camunda_client.Process, error) {
var process dto.Process

response, err := client.doRequest("GET", "process-instance/"+processId, nil)
response, err := client.doRequest("GET", "process-instance/" + processId, nil)
if err == nil {
err = client.parseResponseJson(response, &process)
defer response.Body.Close()
Expand All @@ -45,6 +45,31 @@ func (client *camundaClientRest) GetProcess(processId string) (go_camunda_client
return process, err
}

func (client camundaClientRest) GetNextTask(processId string) (go_camunda_client.Task, error) {
tasks, err := client.GetAllTasks(processId)
if len(tasks) >= 1 {
return tasks[0], err
}
return nil, err
}

func (client camundaClientRest) GetAllTasks(processId string) ([]go_camunda_client.Task, error) {
var dtoTasks []dto.Task
var tasks []go_camunda_client.Task

response, err := client.doRequest("GET", "task/?processInstanceId=" + processId, nil)
if err == nil {
err = client.parseResponseJson(response, &dtoTasks)
defer response.Body.Close()

tasks = make([]go_camunda_client.Task, len(dtoTasks))
for i := range tasks {
tasks[i] = dtoTasks[i]
}
}
return tasks, err
}

func (client *camundaClientRest) HandleErrors(errorCallback func(error)) {
client.errorCallbacks = append(client.errorCallbacks, errorCallback)
}
Expand Down
19 changes: 19 additions & 0 deletions rest/dto/task.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package dto

type Task struct {
Id string `json:"id"`
Name string `json:"name"`
TaskDefinitionKey string `json:"taskDefinitionKey"`
}

func (task Task) GetId() string {
return task.Id
}

func (task Task) GetName() string {
return task.Name
}

func (task Task) GetTaskDefinitionKey() string {
return task.TaskDefinitionKey
}

0 comments on commit e9c77ba

Please sign in to comment.