/
step_WithParent.go
46 lines (34 loc) · 1.42 KB
/
step_WithParent.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
package builder
import (
"io"
"github.com/EmissarySocial/emissary/model"
"github.com/EmissarySocial/emissary/model/step"
"github.com/benpate/derp"
)
// StepWithParent represents an action-step that can update the data.DataMap custom data stored in a Stream
type StepWithParent struct {
SubSteps []step.Step
}
func (step StepWithParent) Get(builder Builder, buffer io.Writer) PipelineBehavior {
return nil
}
// Post executes the subSteps on the parent Stream
func (step StepWithParent) Post(builder Builder, buffer io.Writer) PipelineBehavior {
const location = "build.StepWithParent.Post"
var parent model.Stream
factory := builder.factory()
streamBuilder := builder.(*Stream)
if err := factory.Stream().LoadByID(streamBuilder._stream.ParentID, &parent); err != nil {
return Halt().WithError(derp.Wrap(err, location, "Error listing parent"))
}
// Make a builder with the new parent stream
// TODO: LOW: Is "view" really the best action to use here??
parentStream, err := NewStreamWithoutTemplate(streamBuilder.factory(), streamBuilder.request(), streamBuilder.response(), &parent, "")
if err != nil {
return Halt().WithError(derp.Wrap(err, location, "Error creating builder for parent"))
}
// Execute the POST build pipeline on the parent
result := Pipeline(step.SubSteps).Post(factory, &parentStream, buffer)
result.Error = derp.Wrap(result.Error, location, "Error executing steps for parent")
return UseResult(result)
}