diff --git a/client_interface.go b/client_interface.go index 4f85404..4f2e6a2 100644 --- a/client_interface.go +++ b/client_interface.go @@ -3,6 +3,8 @@ 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)) } @@ -10,3 +12,11 @@ type Process interface { GetId() string IsEnded() bool } + +type Task interface { + GetId() string + GetName() string + GetTaskDefinitionKey() string +} + + diff --git a/rest/client_rest.go b/rest/client_rest.go index 1241553..ebea99b 100644 --- a/rest/client_rest.go +++ b/rest/client_rest.go @@ -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() @@ -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() @@ -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) } diff --git a/rest/dto/task.go b/rest/dto/task.go new file mode 100644 index 0000000..7453fc3 --- /dev/null +++ b/rest/dto/task.go @@ -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 +} \ No newline at end of file