Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions addon/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ type Bucket = binding.Bucket
type BucketContent = binding.BucketContent
type File = binding.File
type Identity = binding.Identity
type Manifest = binding.Manifest
type Platform = binding.Platform
type Proxy = binding.Proxy
type RuleSet = binding.RuleSet
type Setting = binding.Setting
Expand All @@ -79,6 +81,10 @@ type Adapter struct {
Application Application
// Identity API.
Identity Identity
// Manifest
Manifest Manifest
// Platform
Platform Platform
// Proxy API.
Proxy Proxy
// TagCategory API.
Expand Down Expand Up @@ -149,6 +155,7 @@ func newAdapter() (adapter *Adapter) {
Setting: richClient.Setting,
Application: richClient.Application,
Identity: richClient.Identity,
Manifest: richClient.Manifest,
Proxy: richClient.Proxy,
TagCategory: richClient.TagCategory,
Tag: richClient.Tag,
Expand Down
5 changes: 5 additions & 0 deletions api/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,7 @@ type Application struct {
Owner *Ref `json:"owner"`
Contributors []Ref `json:"contributors"`
MigrationWave *Ref `json:"migrationWave" yaml:"migrationWave"`
Platform *Ref `json:"platform"`
Archetypes []Ref `json:"archetypes"`
Assessments []Ref `json:"assessments"`
Assessed bool `json:"assessed"`
Expand Down Expand Up @@ -1189,6 +1190,7 @@ func (r *Application) With(m *model.Application, tags []model.ApplicationTag) {
ref)
}
r.MigrationWave = r.refPtr(m.MigrationWaveID, m.MigrationWave)
r.Platform = r.refPtr(m.PlatformID, m.Platform)
r.Assessments = []Ref{}
for _, a := range m.Assessments {
ref := Ref{}
Expand Down Expand Up @@ -1297,6 +1299,9 @@ func (r *Application) Model() (m *model.Application) {
if r.MigrationWave != nil {
m.MigrationWaveID = &r.MigrationWave.ID
}
if r.Platform != nil {
m.PlatformID = &r.Platform.ID
}

return
}
Expand Down
116 changes: 98 additions & 18 deletions api/archetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ func (h ArchetypeHandler) AddRoutes(e *gin.Engine) {
func (h ArchetypeHandler) Get(ctx *gin.Context) {
m := &model.Archetype{}
id := h.pk(ctx)
db := h.preLoad(h.DB(ctx), clause.Associations)
db := h.preLoad(
h.DB(ctx),
clause.Associations,
"Profiles.Generators")
result := db.First(m, id)
if result.Error != nil {
_ = ctx.Error(result.Error)
Expand Down Expand Up @@ -85,7 +88,10 @@ func (h ArchetypeHandler) Get(ctx *gin.Context) {
// @router /archetypes [get]
func (h ArchetypeHandler) List(ctx *gin.Context) {
var list []model.Archetype
db := h.preLoad(h.DB(ctx), clause.Associations)
db := h.preLoad(
h.DB(ctx),
clause.Associations,
"Profiles.Generators")
result := db.Find(&list)
if result.Error != nil {
_ = ctx.Error(result.Error)
Expand Down Expand Up @@ -162,6 +168,18 @@ func (h ArchetypeHandler) Create(ctx *gin.Context) {
_ = ctx.Error(err)
return
}
err = h.Association(ctx, "Profiles").Owner(true).Replace(m, m.Profiles)
if err != nil {
_ = ctx.Error(err)
return
}
for _, p := range m.Profiles {
err = h.Association(ctx, "Generators").Replace(p, p.Generators)
if err != nil {
_ = ctx.Error(err)
return
}
}

archetypes := []model.Archetype{}
db := h.preLoad(h.DB(ctx), "Tags", "CriteriaTags")
Expand Down Expand Up @@ -258,7 +276,18 @@ func (h ArchetypeHandler) Update(ctx *gin.Context) {
_ = ctx.Error(err)
return
}

err = h.Association(ctx, "Profiles").Owner(true).Replace(m, m.Profiles)
if err != nil {
_ = ctx.Error(err)
return
}
for _, p := range m.Profiles {
err = h.Association(ctx, "Generators").Replace(p, p.Generators)
if err != nil {
_ = ctx.Error(err)
return
}
}
h.Status(ctx, http.StatusNoContent)
}

Expand All @@ -272,13 +301,17 @@ func (h ArchetypeHandler) Update(ctx *gin.Context) {
func (h ArchetypeHandler) AssessmentList(ctx *gin.Context) {
m := &model.Archetype{}
id := h.pk(ctx)
db := h.preLoad(h.DB(ctx), clause.Associations, "Assessments.Stakeholders", "Assessments.StakeholderGroups", "Assessments.Questionnaire")
db := h.preLoad(
h.DB(ctx),
clause.Associations,
"Assessments.Stakeholders",
"Assessments.StakeholderGroups",
"Assessments.Questionnaire")
result := db.First(m, id)
if result.Error != nil {
_ = ctx.Error(result.Error)
return
}

resources := []Assessment{}
for i := range m.Assessments {
r := Assessment{}
Expand Down Expand Up @@ -363,22 +396,57 @@ func (h ArchetypeHandler) AssessmentCreate(ctx *gin.Context) {
h.Respond(ctx, http.StatusCreated, r)
}

// TargetProfile REST resource.
type TargetProfile struct {
Resource `yaml:",inline"`
Name string `json:"name" binding:"required"`
Generators []Ref `json:"generators"`
}

// With updates the resource with the model.
func (r *TargetProfile) With(m *model.TargetProfile) {
r.Resource.With(&m.Model)
r.Name = m.Name
r.Generators = []Ref{}
for _, g := range m.Generators {
ref := Ref{}
ref.With(g.ID, g.Name)
r.Generators = append(r.Generators, ref)
}
}

// Model builds a model from the resource.
func (r *TargetProfile) Model() (m *model.TargetProfile) {
m = &model.TargetProfile{}
m.ID = r.ID
m.Name = r.Name
for _, ref := range r.Generators {
g := model.Generator{}
g.ID = ref.ID
m.Generators = append(
m.Generators,
g)
}
return
}

// Archetype REST resource.
type Archetype struct {
Resource `yaml:",inline"`
Name string `json:"name" yaml:"name"`
Description string `json:"description" yaml:"description"`
Comments string `json:"comments" yaml:"comments"`
Tags []TagRef `json:"tags" yaml:"tags"`
Criteria []TagRef `json:"criteria" yaml:"criteria"`
Stakeholders []Ref `json:"stakeholders" yaml:"stakeholders"`
StakeholderGroups []Ref `json:"stakeholderGroups" yaml:"stakeholderGroups"`
Applications []Ref `json:"applications" yaml:"applications"`
Assessments []Ref `json:"assessments" yaml:"assessments"`
Assessed bool `json:"assessed"`
Risk string `json:"risk"`
Confidence int `json:"confidence"`
Review *Ref `json:"review"`
Name string `json:"name" yaml:"name"`
Description string `json:"description" yaml:"description"`
Comments string `json:"comments" yaml:"comments"`
Tags []TagRef `json:"tags" yaml:"tags"`
Criteria []TagRef `json:"criteria" yaml:"criteria"`
Stakeholders []Ref `json:"stakeholders" yaml:"stakeholders"`
StakeholderGroups []Ref `json:"stakeholderGroups" yaml:"stakeholderGroups"`
Applications []Ref `json:"applications" yaml:"applications"`
Assessments []Ref `json:"assessments" yaml:"assessments"`
Assessed bool `json:"assessed"`
Risk string `json:"risk"`
Confidence int `json:"confidence"`
Review *Ref `json:"review"`
Profiles []TargetProfile `json:"profiles" yaml:",omitempty"`
}

// With updates the resource with the model.
Expand Down Expand Up @@ -417,6 +485,12 @@ func (r *Archetype) With(m *model.Archetype) {
r.Review = ref
}
r.Risk = assessment.RiskUnassessed
r.Profiles = []TargetProfile{}
for _, p := range m.Profiles {
pr := TargetProfile{}
pr.With(&p)
r.Profiles = append(r.Profiles, pr)
}
}

// WithResolver uses an ArchetypeResolver to update the resource with
Expand Down Expand Up @@ -488,6 +562,12 @@ func (r *Archetype) Model() (m *model.Archetype) {
},
})
}
for _, p := range r.Profiles {
pm := p.Model()
m.Profiles = append(
m.Profiles,
*pm)
}

return
}
Loading
Loading