Skip to content

Commit

Permalink
Create choice helpers
Browse files Browse the repository at this point in the history
In `processingMCP.xml`, a choice can contain a UUID or a string. This commit
provides helpers to consume them without having to deal with parsing elsewhere.
  • Loading branch information
sevein committed Apr 29, 2024
1 parent 601bb3e commit 448d2b1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
17 changes: 4 additions & 13 deletions hack/ccp/internal/controller/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,9 @@ func (p *Package) PreconfiguredChoice(linkID uuid.UUID) (uuid.UUID, error) {
}

var chainID uuid.UUID
li := linkID.String()
for _, choice := range choices {
if choice.AppliesTo == li {
if id, err := uuid.Parse(choice.GoToChain); err != nil {
return uuid.Nil, err
} else {
chainID = id
}
if choice.LinkID() == linkID {
chainID = choice.ChainID()
break
}
}
Expand All @@ -150,12 +145,8 @@ func (p *Package) PreconfiguredChoice(linkID uuid.UUID) (uuid.UUID, error) {
// TODO: allow user to choose the system processing config to use.
if chainID == uuid.Nil {
for _, choice := range workflow.AutomatedConfig.Choices.Choices {
if choice.AppliesTo == li {
if id, err := uuid.Parse(choice.GoToChain); err != nil {
return uuid.Nil, err
} else {
chainID = id
}
if choice.LinkID() == linkID {
chainID = choice.ChainID()
break
}
}
Expand Down
20 changes: 20 additions & 0 deletions hack/ccp/internal/workflow/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"os"
"path/filepath"
"strings"

"github.com/google/uuid"
)

var builtinConfigs = map[string]ProcessingConfig{
Expand Down Expand Up @@ -299,6 +301,24 @@ type Choice struct {
GoToChain string `xml:"goToChain"`
}

func (c Choice) LinkID() uuid.UUID {
if id, err := uuid.Parse(c.AppliesTo); err != nil {
return id
}
return uuid.Nil
}

func (c Choice) ChainID() uuid.UUID {
if id, err := uuid.Parse(c.GoToChain); err != nil {
return id
}
return uuid.Nil
}

func (c Choice) Value() string {
return c.GoToChain
}

type Choices struct {
XMLName xml.Name `xml:"preconfiguredChoices"`
Choices []Choice `xml:"preconfiguredChoice"`
Expand Down

0 comments on commit 448d2b1

Please sign in to comment.