19
19
20
20
import io .apicurio .registry .content .ContentHandle ;
21
21
import io .apicurio .registry .rest .v2 .beans .ArtifactReference ;
22
+ import io .apicurio .registry .content .canon .ContentCanonicalizer ;
22
23
import io .apicurio .registry .storage .RegistryStorage ;
23
24
import io .apicurio .registry .storage .dto .LazyContentList ;
24
25
import io .apicurio .registry .storage .dto .RuleConfigurationDto ;
25
26
import io .apicurio .registry .storage .dto .StoredArtifactDto ;
26
27
import io .apicurio .registry .types .Current ;
27
28
import io .apicurio .registry .types .RuleType ;
29
+ import io .apicurio .registry .types .provider .ArtifactTypeUtilProvider ;
30
+ import io .apicurio .registry .types .provider .ArtifactTypeUtilProviderFactory ;
28
31
29
32
import jakarta .enterprise .context .ApplicationScoped ;
30
33
import jakarta .inject .Inject ;
34
+
31
35
import java .util .Collections ;
32
36
import java .util .List ;
33
37
import java .util .Map ;
@@ -52,13 +56,16 @@ public class RulesServiceImpl implements RulesService {
52
56
@ Inject
53
57
RulesProperties rulesProperties ;
54
58
59
+ @ Inject
60
+ ArtifactTypeUtilProviderFactory providerFactory ;
61
+
55
62
/**
56
63
* @see io.apicurio.registry.rules.RulesService#applyRules(java.lang.String, java.lang.String, java.lang.String, io.apicurio.registry.content.ContentHandle, io.apicurio.registry.rules.RuleApplicationType, java.util.List, java.util.Map)
57
64
*/
58
65
@ Override
59
66
public void applyRules (String groupId , String artifactId , String artifactType , ContentHandle artifactContent ,
60
- RuleApplicationType ruleApplicationType , List <ArtifactReference > references ,
61
- Map <String , ContentHandle > resolvedReferences ) throws RuleViolationException {
67
+ RuleApplicationType ruleApplicationType , List <ArtifactReference > references ,
68
+ Map <String , ContentHandle > resolvedReferences ) throws RuleViolationException {
62
69
@ SuppressWarnings ("unchecked" )
63
70
List <RuleType > rules = Collections .EMPTY_LIST ;
64
71
if (ruleApplicationType == RuleApplicationType .UPDATE ) {
@@ -75,20 +82,20 @@ public void applyRules(String groupId, String artifactId, String artifactType, C
75
82
}
76
83
77
84
private void applyGlobalAndArtifactRules (String groupId , String artifactId , String artifactType ,
78
- List <ContentHandle > currentArtifactContent , ContentHandle updatedArtifactContent ,
79
- List <RuleType > artifactRules , List <ArtifactReference > references , Map <String , ContentHandle > resolvedReferences ) {
85
+ List <ContentHandle > currentArtifactContent , ContentHandle updatedArtifactContent ,
86
+ List <RuleType > artifactRules , List <ArtifactReference > references , Map <String , ContentHandle > resolvedReferences ) {
80
87
81
88
Map <RuleType , RuleConfigurationDto > globalOrArtifactRulesMap = artifactRules .stream ()
82
- .collect (Collectors .toMap (ruleType -> ruleType , ruleType -> storage .getArtifactRule (groupId , artifactId , ruleType )));
89
+ .collect (Collectors .toMap (ruleType -> ruleType , ruleType -> storage .getArtifactRule (groupId , artifactId , ruleType )));
83
90
84
91
if (globalOrArtifactRulesMap .isEmpty ()) {
85
92
List <RuleType > globalRules = storage .getGlobalRules ();
86
93
globalOrArtifactRulesMap = globalRules .stream ()
87
- .collect (Collectors .toMap (ruleType -> ruleType , storage ::getGlobalRule ));
94
+ .collect (Collectors .toMap (ruleType -> ruleType , storage ::getGlobalRule ));
88
95
89
96
// Add any default global rules to the map (after filtering out any global rules from artifactStore)
90
- Map <RuleType , RuleConfigurationDto > filteredDefaultGlobalRulesMap = rulesProperties .getFilteredDefaultGlobalRules (globalRules ).stream ()
91
- .collect (Collectors .toMap (ruleType -> ruleType , rulesProperties ::getDefaultGlobalRuleConfiguration ));
97
+ Map <RuleType , RuleConfigurationDto > filteredDefaultGlobalRulesMap = rulesProperties .getFilteredDefaultGlobalRules (globalRules ).stream ()
98
+ .collect (Collectors .toMap (ruleType -> ruleType , rulesProperties ::getDefaultGlobalRuleConfiguration ));
92
99
globalOrArtifactRulesMap .putAll (filteredDefaultGlobalRulesMap );
93
100
}
94
101
@@ -107,34 +114,25 @@ private void applyGlobalAndArtifactRules(String groupId, String artifactId, Stri
107
114
*/
108
115
@ Override
109
116
public void applyRule (String groupId , String artifactId , String artifactType , ContentHandle artifactContent ,
110
- RuleType ruleType , String ruleConfiguration , RuleApplicationType ruleApplicationType ,
111
- List <ArtifactReference > references , Map <String , ContentHandle > resolvedReferences )
117
+ RuleType ruleType , String ruleConfiguration , RuleApplicationType ruleApplicationType ,
118
+ List <ArtifactReference > references , Map <String , ContentHandle > resolvedReferences )
112
119
throws RuleViolationException {
113
120
LazyContentList currentContent = null ;
114
121
if (ruleApplicationType == RuleApplicationType .UPDATE ) {
115
122
currentContent = new LazyContentList (storage , storage .getEnabledArtifactContentIds (groupId , artifactId ));
116
123
}
117
- applyRule (groupId , artifactId , artifactType , currentContent , artifactContent , ruleType , ruleConfiguration ,
124
+ applyRule (groupId , artifactId , artifactType , currentContent , artifactContent , ruleType , ruleConfiguration ,
118
125
references , resolvedReferences );
119
126
}
120
127
121
128
/**
122
129
* Applies a single rule. Throws an exception if the rule is violated.
123
- * @param groupId
124
- * @param artifactId
125
- * @param artifactType
126
- * @param currentContent
127
- * @param updatedContent
128
- * @param ruleType
129
- * @param ruleConfiguration
130
- * @param references
131
- * @param resolvedReferences
132
130
*/
133
131
private void applyRule (String groupId , String artifactId , String artifactType , List <ContentHandle > currentContent ,
134
- ContentHandle updatedContent , RuleType ruleType , String ruleConfiguration ,
132
+ ContentHandle updatedContent , RuleType ruleType , String ruleConfiguration ,
135
133
List <ArtifactReference > references , Map <String , ContentHandle > resolvedReferences ) {
136
134
RuleExecutor executor = factory .createExecutor (ruleType );
137
- RuleContext context = new RuleContext (groupId , artifactId , artifactType , ruleConfiguration , currentContent ,
135
+ RuleContext context = new RuleContext (groupId , artifactId , artifactType , ruleConfiguration , currentContent ,
138
136
updatedContent , references , resolvedReferences );
139
137
executor .execute (context );
140
138
}
@@ -143,11 +141,23 @@ private void applyRule(String groupId, String artifactId, String artifactType, L
143
141
* @see io.apicurio.registry.rules.RulesService#applyRules(java.lang.String, java.lang.String, java.lang.String, java.lang.String, io.apicurio.registry.content.ContentHandle, java.util.List, java.util.Map)
144
142
*/
145
143
@ Override
146
- public void applyRules (String groupId , String artifactId , String artifactVersion , String artifactType ,
147
- ContentHandle updatedContent , List <ArtifactReference > references ,
148
- Map <String , ContentHandle > resolvedReferences ) throws RuleViolationException {
144
+ public void applyRules (String groupId , String artifactId , String artifactVersion , String artifactType ,
145
+ ContentHandle updatedContent , List <ArtifactReference > references ,
146
+ Map <String , ContentHandle > resolvedReferences ) throws RuleViolationException {
149
147
StoredArtifactDto versionContent = storage .getArtifactVersion (groupId , artifactId , artifactVersion );
150
148
applyGlobalAndArtifactRules (groupId , artifactId , artifactType , Collections .singletonList (versionContent .getContent ()),
151
149
updatedContent , storage .getArtifactRules (groupId , artifactId ), references , resolvedReferences );
152
150
}
151
+
152
+ @ Override
153
+ public void applyRulesCompat (String groupId , String artifactId , String artifactVersion , String artifactType ,
154
+ ContentHandle updatedContent , List <ArtifactReference > references ,
155
+ Map <String , ContentHandle > resolvedReferences ) throws RuleViolationException {
156
+ ArtifactTypeUtilProvider artifactTypeProvider = providerFactory .getArtifactTypeProvider (artifactType );
157
+ ContentCanonicalizer contentCanonicalizer = artifactTypeProvider .getContentCanonicalizer ();
158
+ StoredArtifactDto versionContent = storage .getArtifactVersion (groupId , artifactId , artifactVersion );
159
+ applyGlobalAndArtifactRules (groupId , artifactId , artifactType ,
160
+ Collections .singletonList (contentCanonicalizer .canonicalize (versionContent .getContent (), Map .of ())),
161
+ updatedContent , storage .getArtifactRules (groupId , artifactId ), references , resolvedReferences );
162
+ }
153
163
}
0 commit comments