Skip to content

Commit 68c8c26

Browse files
author
Dimitar Hadzhiev
committed
extend client API calls
1 parent 58764dd commit 68c8c26

File tree

5 files changed

+84
-11
lines changed

5 files changed

+84
-11
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,8 @@
2424
# Output of the go coverage tool, specifically when used with LiteIDE
2525
*.out
2626

27+
# Tests
28+
/tests/
29+
2730
# Dependency directories (remove the comment below to include it)
28-
# vendor/
31+
# /vendor/

camunda.go

Lines changed: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func GetProcessDefinitionXMLByTenant(ctx context.Context, key, tenantId string)
215215
// StartProcessDefinition instantiates a given process definition. Process variables and business
216216
// key may be supplied in the request body.
217217
func StartProcessDefinition(ctx context.Context, id string, trigger *ProcessInstanceTrigger) (*ProcessInstance, error) {
218-
var reader *bytes.Reader
218+
var reader io.Reader
219219

220220
var uri string
221221
var payload []byte
@@ -249,7 +249,7 @@ exec:
249249
// StartProcessDefinitionByKey instantiates a given process definition. Process variables and business
250250
// key may be supplied in the request body. Starts the latest version of the process definition which belongs to no tenant.
251251
func StartProcessDefinitionByKey(ctx context.Context, key string, trigger *ProcessInstanceTrigger) (*ProcessInstance, error) {
252-
var reader *bytes.Reader
252+
var reader io.Reader
253253

254254
var uri string
255255
var payload []byte
@@ -283,7 +283,7 @@ exec:
283283
// StartProcessDefinitionByTenant instantiates a given process definition. Process variables and business
284284
// key may be supplied in the request body. Starts the latest version of the process definition for tenant
285285
func StartProcessDefinitionByTenant(ctx context.Context, key, tenantId string, trigger *ProcessInstanceTrigger) (*ProcessInstance, error) {
286-
var reader *bytes.Reader
286+
var reader io.Reader
287287

288288
var uri string
289289
var payload []byte
@@ -314,6 +314,30 @@ exec:
314314
return result, nil
315315
}
316316

317+
// GetProcessInstances queries for process instances that fulfill given parameters. Parameters may be
318+
// static as well as dynamic runtime properties of process instances. The size of the result set can
319+
// be retrieved by using the GetProcessInstancesCount method.
320+
func GetProcessInstances(ctx context.Context, tenantId string) ([]*ProcessInstance, error) {
321+
var uri string
322+
var err error
323+
324+
result := make([]*ProcessInstance, 0)
325+
326+
uri = fmt.Sprintf("%s/%s/process-instance?tenantIdIn=%s", url, path, tenantId)
327+
err = client.send(ctx, uri, http.MethodGet, "application/json", nil, &result)
328+
329+
if err != nil {
330+
return nil, err
331+
}
332+
333+
return result, err
334+
}
335+
336+
// GetProcessInstancesCount ...
337+
func GetProcessInstancesCount(ctx context.Context) {
338+
339+
}
340+
317341
// GetTasks queries for tasks that fulfill a given filter. The size of the result set can be retrieved
318342
// by using the GetTasksCount method.
319343
func GetTasks(ctx context.Context, processInstanceId string) ([]*Task, error) {
@@ -424,17 +448,27 @@ func UnclaimTask(ctx context.Context, id string) error {
424448

425449
// CompleteTask completes a task and updates process variables.
426450
func CompleteTask(ctx context.Context, id string, variables map[string]*Variable) error {
451+
var reader io.Reader
452+
427453
var uri string
454+
var payload []byte
428455
var err error
429456

430-
payload, err := json.Marshal(&map[string]interface{}{"variables": variables})
457+
if variables == nil {
458+
goto exec
459+
}
460+
461+
payload, err = json.Marshal(&map[string]interface{}{"variables": variables})
431462

432463
if err != nil {
433464
return err
434465
}
435466

467+
reader = bytes.NewReader(payload)
468+
469+
exec:
436470
uri = fmt.Sprintf("%s/%s/task/%s/complete", url, path, id)
437-
err = client.send(ctx, uri, http.MethodPost, "application/json", bytes.NewReader(payload), nil)
471+
err = client.send(ctx, uri, http.MethodPost, "application/json", reader, nil)
438472

439473
return err
440474
}
@@ -444,21 +478,54 @@ func CompleteTask(ctx context.Context, id string, variables map[string]*Variable
444478
// can be sent back to the owner. Can only be executed when the task has been delegated. The assignee
445479
// will be set to the owner, who performed the delegation.
446480
func ResolveTask(ctx context.Context, id string, variables map[string]*Variable) error {
481+
var reader io.Reader
482+
447483
var uri string
484+
var payload []byte
448485
var err error
449486

450-
payload, err := json.Marshal(&map[string]interface{}{"variables": variables})
487+
if variables == nil {
488+
goto exec
489+
}
490+
491+
payload, err = json.Marshal(&map[string]interface{}{"variables": variables})
451492

452493
if err != nil {
453494
return err
454495
}
455496

497+
reader = bytes.NewReader(payload)
498+
499+
exec:
456500
uri = fmt.Sprintf("%s/%s/task/%s/resolve", url, path, id)
457-
err = client.send(ctx, uri, http.MethodPost, "application/json", bytes.NewReader(payload), nil)
501+
err = client.send(ctx, uri, http.MethodPost, "application/json", reader, nil)
458502

459503
return err
460504
}
461505

506+
// GetTenants query for a list of tenants using a list of parameters. The size of the result
507+
// set can be retrieved by using the GetTenantsCount method.
508+
func GetTenants(ctx context.Context) ([]*Tenant, error) {
509+
var uri string
510+
var err error
511+
512+
result := make([]*Tenant, 0)
513+
514+
uri = fmt.Sprintf("%s/%s/tenant", url, path)
515+
err = client.send(ctx, uri, http.MethodGet, "application/json", nil, &result)
516+
517+
if err != nil {
518+
return nil, err
519+
}
520+
521+
return result, err
522+
}
523+
524+
// GetTenantsCount ...
525+
func GetTenantsCount(ctx context.Context) {
526+
527+
}
528+
462529
// GetTenant retrieves a Tenant.
463530
func GetTenant(ctx context.Context, id string) (*Tenant, error) {
464531
var uri string

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ go 1.16
44

55
require (
66
github.com/dimchansky/utfbom v1.1.1
7+
github.com/golang/glog v1.0.0
78
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
github.com/dimchansky/utfbom v1.1.1 h1:vV6w1AhK4VMnhBno/TPVCoK9U/LP0PkLCS9tbxHdi/U=
22
github.com/dimchansky/utfbom v1.1.1/go.mod h1:SxdoEBH5qIqFocHMyGOXVAybYJdr71b1Q/j0mACtrfE=
3+
github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ=
4+
github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4=

models.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,16 +340,16 @@ type Task struct {
340340
Priority int `json:"priority,omitempty"`
341341

342342
// The id of the process definition the task belongs to.
343-
ProcessDefinitionId int `json:"processDefinitionId,omitempty"`
343+
ProcessDefinitionId string `json:"processDefinitionId,omitempty"`
344344

345345
// The id of the process instance the task belongs to.
346-
ProcessInstanceId bool `json:"processInstanceId,omitempty"`
346+
ProcessInstanceId string `json:"processInstanceId,omitempty"`
347347

348348
// The id of the case execution the task belongs to.
349349
CaseExecutionId string `json:"caseExecutionId,omitempty"`
350350

351351
// The id of the case definition the task belongs to.
352-
CaseDefinitionId int `json:"caseDefinitionId,omitempty"`
352+
CaseDefinitionId string `json:"caseDefinitionId,omitempty"`
353353

354354
// The id of the case instance the task belongs to.
355355
CaseInstanceId string `json:"caseInstanceId,omitempty"`

0 commit comments

Comments
 (0)