/
actions.go
101 lines (81 loc) · 3.57 KB
/
actions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* _ _
*__ _____ __ ___ ___ __ _| |_ ___
*\ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
* \ V V / __/ (_| |\ V /| | (_| | || __/
* \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
*
* Copyright © 2016 - 2019 Weaviate. All rights reserved.
* LICENSE: https://github.com/creativesoftwarefdn/weaviate/blob/develop/LICENSE.md
* DESIGN & CONCEPT: Bob van Luijt (@bobvanluijt)
* CONTACT: hello@creativesoftwarefdn.org
*/
package janusgraph
import (
"context"
"github.com/go-openapi/strfmt"
"fmt"
"github.com/creativesoftwarefdn/weaviate/database/schema"
"github.com/creativesoftwarefdn/weaviate/database/schema/kind"
connutils "github.com/creativesoftwarefdn/weaviate/database/utils"
"github.com/creativesoftwarefdn/weaviate/models"
batchmodels "github.com/creativesoftwarefdn/weaviate/restapi/batch/models"
)
func (j *Janusgraph) AddAction(ctx context.Context, action *models.Action, UUID strfmt.UUID) error {
sanitizedClassName := schema.AssertValidClassName(action.AtClass)
return j.addClass(kind.ACTION_KIND, sanitizedClassName, UUID, action.AtContext, action.CreationTimeUnix, action.LastUpdateTimeUnix, action.Schema)
}
func (j *Janusgraph) AddActionsBatch(ctx context.Context, actions batchmodels.Actions) error {
return j.addActionsBatch(actions)
}
func (j *Janusgraph) GetAction(ctx context.Context, UUID strfmt.UUID, actionResponse *models.ActionGetResponse) error {
return j.getClass(kind.ACTION_KIND, UUID,
&actionResponse.AtClass,
&actionResponse.AtContext,
&actionResponse.ActionID,
&actionResponse.CreationTimeUnix,
&actionResponse.LastUpdateTimeUnix,
&actionResponse.Schema)
}
func (j *Janusgraph) GetActions(ctx context.Context, UUIDs []strfmt.UUID, response *models.ActionsListResponse) error {
// TODO gh-612: Optimize query to perform just _one_ JanusGraph lookup
response.TotalResults = 0
response.Actions = make([]*models.ActionGetResponse, 0)
for _, uuid := range UUIDs {
var action_response models.ActionGetResponse
err := j.GetAction(ctx, uuid, &action_response)
if err == nil {
response.TotalResults += 1
response.Actions = append(response.Actions, &action_response)
} else {
return fmt.Errorf("%s: action with UUID '%v' not found", connutils.StaticActionNotFound, uuid)
}
}
return nil
}
func (j *Janusgraph) ListActions(ctx context.Context, first int, offset int, wheres []*connutils.WhereQuery, response *models.ActionsListResponse) error {
response.TotalResults = 0
response.Actions = make([]*models.ActionGetResponse, 0)
return j.listClass(kind.ACTION_KIND, nil, first, offset, nil, func(uuid strfmt.UUID) {
var action_response models.ActionGetResponse
err := j.GetAction(ctx, uuid, &action_response)
if err == nil {
response.TotalResults += 1
response.Actions = append(response.Actions, &action_response)
} else {
// Silently ignorre the potentially removed actions.
}
})
}
func (j *Janusgraph) UpdateAction(ctx context.Context, action *models.Action, UUID strfmt.UUID) error {
sanitizedClassName := schema.AssertValidClassName(action.AtClass)
return j.updateClass(kind.ACTION_KIND, sanitizedClassName, UUID, action.AtContext, action.LastUpdateTimeUnix, action.Schema)
}
func (j *Janusgraph) DeleteAction(ctx context.Context, action *models.Action, UUID strfmt.UUID) error {
return j.deleteClass(kind.ACTION_KIND, UUID)
}
func (j *Janusgraph) HistoryAction(ctx context.Context, UUID strfmt.UUID, history *models.ActionHistory) error {
return nil
}
func (j *Janusgraph) MoveToHistoryAction(ctx context.Context, action *models.Action, UUID strfmt.UUID, deleted bool) error {
return nil
}