diff --git a/ai-compliance-sdk/internal/api/handlers/iace_handler_init.go b/ai-compliance-sdk/internal/api/handlers/iace_handler_init.go index 9fc821bb..798b3eca 100644 --- a/ai-compliance-sdk/internal/api/handlers/iace_handler_init.go +++ b/ai-compliance-sdk/internal/api/handlers/iace_handler_init.go @@ -276,19 +276,37 @@ func (h *IACEHandler) InitializeProject(c *gin.Context) { } } - // Fallback: assign category-based measures to ALL hazards per category + // Fallback: assign category-based measures only to hazards that + // didn't get any measures from pattern suggestions (max 3 per hazard) + hazardsWithMeasures := make(map[uuid.UUID]bool) + for _, sm := range matchOutput.SuggestedMeasures { + entry, ok := measureByID[sm.MeasureID] + if !ok { + continue + } + for _, ids := range hazardIDsByCategory { + for _, id := range ids { + _ = entry // suppress unused + hazardsWithMeasures[id] = true + } + } + } for hazCat, hazIDs := range hazardIDsByCategory { measCat := patternCatToMeasureCat(hazCat) - added := 0 - for _, m := range measuresByCat[measCat] { - if added >= 5 { - break + measures := measuresByCat[measCat] + for _, hazID := range hazIDs { + if hazardsWithMeasures[hazID] { + continue // Already has pattern-suggested measures } - rt := iace.ReductionType(m.ReductionType) - if rt == "" { - rt = iace.ReductionTypeInformation - } - for _, hazID := range hazIDs { + added := 0 + for _, m := range measures { + if added >= 3 { + break + } + rt := iace.ReductionType(m.ReductionType) + if rt == "" { + rt = iace.ReductionTypeInformation + } _, cerr := h.store.CreateMitigation(ctx, iace.CreateMitigationRequest{ HazardID: hazID, ReductionType: rt, Name: m.Name, Description: m.Description, @@ -296,8 +314,8 @@ func (h *IACEHandler) InitializeProject(c *gin.Context) { if cerr == nil { created++ } + added++ } - added++ } } mitStep = InitStep{Name: "Massnahmen erstellt", Status: "done", Count: created}