@@ -34,13 +34,14 @@ type QualifierMappingService interface {
34
34
CreateQualifierMappings (qualifierMappings []* QualifierMapping , tx * pg.Tx ) ([]* QualifierMapping , error )
35
35
GetQualifierMappings (resourceType ResourceType , scope * Scope , resourceIds []int ) ([]* QualifierMapping , error )
36
36
DeleteAllQualifierMappings (resourceType ResourceType , auditLog sql.AuditLog , tx * pg.Tx ) error
37
- DeleteByIdentifierKeyValue (resourceType ResourceType , identifierKey int , identifierValue int , auditLog sql.AuditLog , tx * pg.Tx ) error
37
+ DeleteByIdentifierKeyAndValue (resourceType ResourceType , identifierKey int , identifierValue int , qualifierId int , auditLog sql.AuditLog , tx * pg.Tx ) error
38
38
DeleteAllByIds (qualifierMappingIds []int , userId int32 , tx * pg.Tx ) error
39
39
DeleteResourceMappingsForScopes (tx * pg.Tx , userId int32 , resourceType ResourceType , qualifierSelector QualifierSelector , scopes []* SelectionIdentifier ) error
40
40
CreateMappingsForSelections (tx * pg.Tx , userId int32 , resourceMappingSelections []* ResourceMappingSelection ) ([]* ResourceMappingSelection , error )
41
41
CreateMappings (tx * pg.Tx , userId int32 , resourceType ResourceType , resourceIds []int , qualifierSelector QualifierSelector , selectionIdentifiers []* SelectionIdentifier ) error
42
42
GetResourceMappingsForSelections (resourceType ResourceType , qualifierSelector QualifierSelector , selectionIdentifiers []* SelectionIdentifier ) ([]ResourceQualifierMappings , error )
43
43
GetResourceMappingsForResources (resourceType ResourceType , resourceIds []int , qualifierSelector QualifierSelector ) ([]ResourceQualifierMappings , error )
44
+ QualifierMappingServiceEnt
44
45
}
45
46
46
47
type QualifierMappingServiceImpl struct {
@@ -57,24 +58,24 @@ func NewQualifierMappingServiceImpl(logger *zap.SugaredLogger, qualifierMappingR
57
58
}, nil
58
59
}
59
60
60
- func (impl QualifierMappingServiceImpl ) CreateQualifierMappings (qualifierMappings []* QualifierMapping , tx * pg.Tx ) ([]* QualifierMapping , error ) {
61
+ func (impl * QualifierMappingServiceImpl ) CreateQualifierMappings (qualifierMappings []* QualifierMapping , tx * pg.Tx ) ([]* QualifierMapping , error ) {
61
62
return impl .qualifierMappingRepository .CreateQualifierMappings (qualifierMappings , tx )
62
63
}
63
64
64
- func (impl QualifierMappingServiceImpl ) GetQualifierMappings (resourceType ResourceType , scope * Scope , resourceIds []int ) ([]* QualifierMapping , error ) {
65
+ func (impl * QualifierMappingServiceImpl ) GetQualifierMappings (resourceType ResourceType , scope * Scope , resourceIds []int ) ([]* QualifierMapping , error ) {
65
66
searchableKeyNameIdMap := impl .devtronResourceSearchableKeyService .GetAllSearchableKeyNameIdMap ()
66
67
return impl .qualifierMappingRepository .GetQualifierMappings (resourceType , scope , searchableKeyNameIdMap , resourceIds )
67
68
}
68
69
69
- func (impl QualifierMappingServiceImpl ) DeleteAllQualifierMappings (resourceType ResourceType , auditLog sql.AuditLog , tx * pg.Tx ) error {
70
+ func (impl * QualifierMappingServiceImpl ) DeleteAllQualifierMappings (resourceType ResourceType , auditLog sql.AuditLog , tx * pg.Tx ) error {
70
71
return impl .qualifierMappingRepository .DeleteAllQualifierMappings (resourceType , auditLog , tx )
71
72
}
72
73
73
- func (impl QualifierMappingServiceImpl ) DeleteByIdentifierKeyValue (resourceType ResourceType , identifierKey int , identifierValue int , auditLog sql.AuditLog , tx * pg.Tx ) error {
74
+ func (impl * QualifierMappingServiceImpl ) DeleteByIdentifierKeyAndValue (resourceType ResourceType , identifierKey int , identifierValue int , qualifierId int , auditLog sql.AuditLog , tx * pg.Tx ) error {
74
75
return impl .qualifierMappingRepository .DeleteByResourceTypeIdentifierKeyAndValue (resourceType , identifierKey , identifierValue , auditLog , tx )
75
76
}
76
77
77
- func (impl QualifierMappingServiceImpl ) DeleteAllByIds (qualifierMappingIds []int , userId int32 , tx * pg.Tx ) error {
78
+ func (impl * QualifierMappingServiceImpl ) DeleteAllByIds (qualifierMappingIds []int , userId int32 , tx * pg.Tx ) error {
78
79
auditLog := sql.AuditLog {
79
80
CreatedOn : time .Now (),
80
81
CreatedBy : userId ,
@@ -84,30 +85,10 @@ func (impl QualifierMappingServiceImpl) DeleteAllByIds(qualifierMappingIds []int
84
85
return impl .qualifierMappingRepository .DeleteAllByIds (qualifierMappingIds , auditLog , tx )
85
86
}
86
87
87
- func (impl QualifierMappingServiceImpl ) CreateMappingsForSelections (tx * pg.Tx , userId int32 , resourceMappingSelections []* ResourceMappingSelection ) ([]* ResourceMappingSelection , error ) {
88
+ func (impl * QualifierMappingServiceImpl ) CreateMappingsForSelections (tx * pg.Tx , userId int32 , resourceMappingSelections []* ResourceMappingSelection ) ([]* ResourceMappingSelection , error ) {
88
89
89
- resourceKeyMap := impl .devtronResourceSearchableKeyService .GetAllSearchableKeyNameIdMap ()
90
-
91
- parentMappings := make ([]* QualifierMapping , 0 )
92
- childrenMappings := make ([]* QualifierMapping , 0 )
93
- parentMappingsMap := make (map [string ]* QualifierMapping )
94
-
95
- mappingsToSelection := make (map [* QualifierMapping ]* ResourceMappingSelection )
96
- for _ , selection := range resourceMappingSelections {
97
-
98
- var parent * QualifierMapping
99
- children := make ([]* QualifierMapping , 0 )
100
- if selection .QualifierSelector .isCompound () {
101
- parent , children = GetQualifierMappingsForCompoundQualifier (selection , resourceKeyMap , userId )
102
- parentMappingsMap [parent .CompositeKey ] = parent
103
- } else {
104
- intValue , stringValue := GetValuesFromSelectionIdentifier (selection .QualifierSelector , selection .SelectionIdentifier )
105
- parent = selection .toResourceMapping (selection .QualifierSelector , resourceKeyMap , intValue , stringValue , "" , userId )
106
- }
107
- mappingsToSelection [parent ] = selection
108
- parentMappings = append (parentMappings , parent )
109
- childrenMappings = append (childrenMappings , children ... )
110
- }
90
+ parentMappings , childrenMappings , mappingsToSelection , parentMappingsMap := getParentAndChildrenMappingForCreation (resourceMappingSelections ,
91
+ impl .devtronResourceSearchableKeyService .GetAllSearchableKeyNameIdMap (), userId )
111
92
112
93
if len (parentMappings ) > 0 {
113
94
_ , err := impl .qualifierMappingRepository .CreateQualifierMappings (parentMappings , tx )
@@ -140,7 +121,33 @@ func (impl QualifierMappingServiceImpl) CreateMappingsForSelections(tx *pg.Tx, u
140
121
return maps .Values (mappingsToSelection ), nil
141
122
}
142
123
143
- func (impl QualifierMappingServiceImpl ) CreateMappings (tx * pg.Tx , userId int32 , resourceType ResourceType , resourceIds []int , qualifierSelector QualifierSelector , selectionIdentifiers []* SelectionIdentifier ) error {
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
+
150
+ func (impl * QualifierMappingServiceImpl ) CreateMappings (tx * pg.Tx , userId int32 , resourceType ResourceType , resourceIds []int , qualifierSelector QualifierSelector , selectionIdentifiers []* SelectionIdentifier ) error {
144
151
mappings := make ([]* ResourceMappingSelection , 0 )
145
152
for _ , id := range resourceIds {
146
153
for _ , selectionIdentifier := range selectionIdentifiers {
@@ -157,7 +164,7 @@ func (impl QualifierMappingServiceImpl) CreateMappings(tx *pg.Tx, userId int32,
157
164
return err
158
165
}
159
166
160
- func ( impl * QualifierMappingServiceImpl ) filterAndGroupMappings (mappings []* QualifierMapping , selector QualifierSelector , composites mapset.Set ) [][]* QualifierMapping {
167
+ func filterAndGroupMappings (mappings []* QualifierMapping , selector QualifierSelector , composites mapset.Set ) [][]* QualifierMapping {
161
168
162
169
numQualifiers := GetNumOfChildQualifiers (selector .toQualifier ())
163
170
parentIdToChildMappings := make (map [int ][]* QualifierMapping )
@@ -197,7 +204,7 @@ func (impl *QualifierMappingServiceImpl) filterAndGroupMappings(mappings []*Qual
197
204
return groupedMappings
198
205
}
199
206
200
- func (impl QualifierMappingServiceImpl ) getAppEnvIdentifierFromGroup (group []* QualifierMapping ) * SelectionIdentifier {
207
+ func (impl * QualifierMappingServiceImpl ) getAppEnvIdentifierFromGroup (group []* QualifierMapping ) * SelectionIdentifier {
201
208
resourceKeyToName := impl .devtronResourceSearchableKeyService .GetAllSearchableKeyIdNameMap ()
202
209
var appId , envId int
203
210
var appName , envName string
@@ -213,7 +220,7 @@ func (impl QualifierMappingServiceImpl) getAppEnvIdentifierFromGroup(group []*Qu
213
220
return getSelectionIdentifierForAppEnv (appId , envId , getIdentifierNamesForAppEnv (envName , appName ))
214
221
}
215
222
216
- func (impl QualifierMappingServiceImpl ) getSelectionIdentifierForAppEnvSelector (mappingGroups [][]* QualifierMapping ) map [int ][]* SelectionIdentifier {
223
+ func (impl * QualifierMappingServiceImpl ) getSelectionIdentifierForAppEnvSelector (mappingGroups [][]* QualifierMapping ) map [int ][]* SelectionIdentifier {
217
224
218
225
resourceIdToIdentifier := make (map [int ][]* SelectionIdentifier )
219
226
for _ , group := range mappingGroups {
@@ -229,7 +236,7 @@ func (impl QualifierMappingServiceImpl) getSelectionIdentifierForAppEnvSelector(
229
236
return resourceIdToIdentifier
230
237
}
231
238
232
- func (impl QualifierMappingServiceImpl ) DeleteResourceMappingsForScopes (tx * pg.Tx , userId int32 , resourceType ResourceType , qualifierSelector QualifierSelector , scopes []* SelectionIdentifier ) error {
239
+ func (impl * QualifierMappingServiceImpl ) DeleteResourceMappingsForScopes (tx * pg.Tx , userId int32 , resourceType ResourceType , qualifierSelector QualifierSelector , scopes []* SelectionIdentifier ) error {
233
240
if qualifierSelector != ApplicationEnvironmentSelector {
234
241
return fmt .Errorf ("selector currently not implemented" )
235
242
}
@@ -256,7 +263,7 @@ func (impl QualifierMappingServiceImpl) DeleteResourceMappingsForScopes(tx *pg.T
256
263
257
264
}
258
265
259
- func (impl QualifierMappingServiceImpl ) GetResourceMappingsForSelections (resourceType ResourceType , qualifierSelector QualifierSelector , selectionIdentifiers []* SelectionIdentifier ) ([]ResourceQualifierMappings , error ) {
266
+ func (impl * QualifierMappingServiceImpl ) GetResourceMappingsForSelections (resourceType ResourceType , qualifierSelector QualifierSelector , selectionIdentifiers []* SelectionIdentifier ) ([]ResourceQualifierMappings , error ) {
260
267
if qualifierSelector != ApplicationEnvironmentSelector {
261
268
return nil , fmt .Errorf ("selector currently not implemented" )
262
269
}
@@ -278,7 +285,7 @@ func (impl QualifierMappingServiceImpl) GetResourceMappingsForSelections(resourc
278
285
279
286
return impl .processMappings (resourceType , mappings , qualifierSelector , getCompositeStringsAppEnvSelection (selectionIdentifiers ))
280
287
}
281
- func (impl QualifierMappingServiceImpl ) GetResourceMappingsForResources (resourceType ResourceType , resourceIds []int , qualifierSelector QualifierSelector ) ([]ResourceQualifierMappings , error ) {
288
+ func (impl * QualifierMappingServiceImpl ) GetResourceMappingsForResources (resourceType ResourceType , resourceIds []int , qualifierSelector QualifierSelector ) ([]ResourceQualifierMappings , error ) {
282
289
mappings , err := impl .qualifierMappingRepository .GetMappingsByResourceTypeAndIdsAndQualifierId (resourceType , resourceIds , int (qualifierSelector .toQualifier ()))
283
290
if err != nil {
284
291
return nil , err
@@ -287,8 +294,8 @@ func (impl QualifierMappingServiceImpl) GetResourceMappingsForResources(resource
287
294
return impl .processMappings (resourceType , mappings , qualifierSelector , mapset .NewSet ())
288
295
}
289
296
290
- func (impl QualifierMappingServiceImpl ) processMappings (resourceType ResourceType , mappings []* QualifierMapping , qualifierSelector QualifierSelector , composites mapset.Set ) ([]ResourceQualifierMappings , error ) {
291
- groups := impl . filterAndGroupMappings (mappings , qualifierSelector , composites )
297
+ func (impl * QualifierMappingServiceImpl ) processMappings (resourceType ResourceType , mappings []* QualifierMapping , qualifierSelector QualifierSelector , composites mapset.Set ) ([]ResourceQualifierMappings , error ) {
298
+ groups := filterAndGroupMappings (mappings , qualifierSelector , composites )
292
299
if qualifierSelector != ApplicationEnvironmentSelector {
293
300
return nil , fmt .Errorf ("selector currently not implemented" )
294
301
}
0 commit comments