Refactor pkg/dal implementation
* Reworked errors to not brick the system (things keep track of issues. * Reworked internal state management -- keeping invalid things present, cleanning up the code, utilizing issues. * Cleanup/improve error messages
This commit is contained in:
+47
-3
@@ -5,8 +5,10 @@ type (
|
||||
|
||||
// ModelDiff defines one identified missmatch between two models
|
||||
ModelDiff struct {
|
||||
Type modelDiffType
|
||||
Type modelDiffType
|
||||
// Original will be nil when a new attribute is being added
|
||||
Original *Attribute
|
||||
// Asserted will be nil wen an existing attribute is being removed
|
||||
Asserted *Attribute
|
||||
}
|
||||
|
||||
@@ -14,8 +16,9 @@ type (
|
||||
)
|
||||
|
||||
const (
|
||||
AttributeMissing modelDiffType = "attributeMissing"
|
||||
AttributeTypeMissmatch modelDiffType = "typeMissmatch"
|
||||
AttributeMissing modelDiffType = "attributeMissing"
|
||||
AttributeTypeMissmatch modelDiffType = "typeMissmatch"
|
||||
AttributeSensitivityMissmatch modelDiffType = "sensitivityMissmatch"
|
||||
)
|
||||
|
||||
// Diff calculates the diff between models a and b where a is used as base
|
||||
@@ -34,6 +37,21 @@ func (a *Model) Diff(b *Model) (out ModelDiffSet) {
|
||||
}
|
||||
}
|
||||
|
||||
aIndex := make(map[string]struct {
|
||||
found bool
|
||||
attr *Attribute
|
||||
})
|
||||
for _, _attr := range a.Attributes {
|
||||
attr := _attr
|
||||
aIndex[attr.Ident] = struct {
|
||||
found bool
|
||||
attr *Attribute
|
||||
}{
|
||||
attr: attr,
|
||||
}
|
||||
}
|
||||
|
||||
// Deleted and update ones
|
||||
for _, _attrA := range a.Attributes {
|
||||
attrA := _attrA
|
||||
|
||||
@@ -55,6 +73,32 @@ func (a *Model) Diff(b *Model) (out ModelDiffSet) {
|
||||
Asserted: attrBAux.attr,
|
||||
})
|
||||
}
|
||||
|
||||
// Other stuff
|
||||
// @todo improve; for now it'll do
|
||||
if attrA.SensitivityLevel != attrBAux.attr.SensitivityLevel {
|
||||
out = append(out, &ModelDiff{
|
||||
Type: AttributeSensitivityMissmatch,
|
||||
Original: attrA,
|
||||
Asserted: attrBAux.attr,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// New
|
||||
for _, _attrB := range b.Attributes {
|
||||
attrB := _attrB
|
||||
|
||||
// Missmatches
|
||||
_, ok := aIndex[attrB.Ident]
|
||||
if !ok {
|
||||
out = append(out, &ModelDiff{
|
||||
Type: AttributeMissing,
|
||||
Original: nil,
|
||||
Asserted: attrB,
|
||||
})
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user