@@ -87,28 +87,8 @@ func (impl *QualifierMappingServiceImpl) DeleteAllByIds(qualifierMappingIds []in
87
87
88
88
func (impl * QualifierMappingServiceImpl ) CreateMappingsForSelections (tx * pg.Tx , userId int32 , resourceMappingSelections []* ResourceMappingSelection ) ([]* ResourceMappingSelection , error ) {
89
89
90
- resourceKeyMap := impl .devtronResourceSearchableKeyService .GetAllSearchableKeyNameIdMap ()
91
-
92
- parentMappings := make ([]* QualifierMapping , 0 )
93
- childrenMappings := make ([]* QualifierMapping , 0 )
94
- parentMappingsMap := make (map [string ]* QualifierMapping )
95
-
96
- mappingsToSelection := make (map [* QualifierMapping ]* ResourceMappingSelection )
97
- for _ , selection := range resourceMappingSelections {
98
-
99
- var parent * QualifierMapping
100
- children := make ([]* QualifierMapping , 0 )
101
- if selection .QualifierSelector .isCompound () {
102
- parent , children = GetQualifierMappingsForCompoundQualifier (selection , resourceKeyMap , userId )
103
- parentMappingsMap [parent .CompositeKey ] = parent
104
- } else {
105
- intValue , stringValue := GetValuesFromSelectionIdentifier (selection .QualifierSelector , selection .SelectionIdentifier )
106
- parent = selection .toResourceMapping (selection .QualifierSelector , resourceKeyMap , intValue , stringValue , "" , userId )
107
- }
108
- mappingsToSelection [parent ] = selection
109
- parentMappings = append (parentMappings , parent )
110
- childrenMappings = append (childrenMappings , children ... )
111
- }
90
+ parentMappings , childrenMappings , mappingsToSelection , parentMappingsMap := getParentAndChildrenMappingForCreation (resourceMappingSelections ,
91
+ impl .devtronResourceSearchableKeyService .GetAllSearchableKeyNameIdMap (), userId )
112
92
113
93
if len (parentMappings ) > 0 {
114
94
_ , err := impl .qualifierMappingRepository .CreateQualifierMappings (parentMappings , tx )
@@ -141,6 +121,32 @@ func (impl *QualifierMappingServiceImpl) CreateMappingsForSelections(tx *pg.Tx,
141
121
return maps .Values (mappingsToSelection ), nil
142
122
}
143
123
124
+ func getParentAndChildrenMappingForCreation (resourceMappingSelections []* ResourceMappingSelection , resourceKeyMap map [bean.DevtronResourceSearchableKeyName ]int ,
125
+ userId int32 ) ([]* QualifierMapping , []* QualifierMapping , map [* QualifierMapping ]* ResourceMappingSelection , map [string ]* QualifierMapping ) {
126
+
127
+ parentMappings := make ([]* QualifierMapping , 0 )
128
+ childrenMappings := make ([]* QualifierMapping , 0 )
129
+ parentMappingsMap := make (map [string ]* QualifierMapping )
130
+
131
+ mappingsToSelection := make (map [* QualifierMapping ]* ResourceMappingSelection )
132
+ for _ , selection := range resourceMappingSelections {
133
+
134
+ var parent * QualifierMapping
135
+ children := make ([]* QualifierMapping , 0 )
136
+ if selection .QualifierSelector .isCompound () {
137
+ parent , children = GetQualifierMappingsForCompoundQualifier (selection , resourceKeyMap , userId )
138
+ parentMappingsMap [parent .CompositeKey ] = parent
139
+ } else {
140
+ intValue , stringValue := GetValuesFromSelectionIdentifier (selection .QualifierSelector , selection .SelectionIdentifier )
141
+ parent = selection .toResourceMapping (selection .QualifierSelector , resourceKeyMap , intValue , stringValue , "" , userId )
142
+ }
143
+ mappingsToSelection [parent ] = selection
144
+ parentMappings = append (parentMappings , parent )
145
+ childrenMappings = append (childrenMappings , children ... )
146
+ }
147
+ return parentMappings , childrenMappings , mappingsToSelection , parentMappingsMap
148
+ }
149
+
144
150
func (impl * QualifierMappingServiceImpl ) CreateMappings (tx * pg.Tx , userId int32 , resourceType ResourceType , resourceIds []int , qualifierSelector QualifierSelector , selectionIdentifiers []* SelectionIdentifier ) error {
145
151
mappings := make ([]* ResourceMappingSelection , 0 )
146
152
for _ , id := range resourceIds {
0 commit comments