Skip to content

Commit c45d626

Browse files
authored
[REST API] Renamed "type" to "ruleType" and created a CreateRule type (#4746)
* Renamed "type" to "ruleType" in REST API and created a CreateRule type * Fix artifact page (ruleType change)
1 parent 1fb5ff7 commit c45d626

File tree

45 files changed

+824
-678
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+824
-678
lines changed

app/src/main/java/io/apicurio/registry/rest/v3/AdminResourceImpl.java

+15-14
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import io.apicurio.registry.rest.MissingRequiredParameterException;
1717
import io.apicurio.registry.rest.v3.beans.ArtifactTypeInfo;
1818
import io.apicurio.registry.rest.v3.beans.ConfigurationProperty;
19+
import io.apicurio.registry.rest.v3.beans.CreateRule;
1920
import io.apicurio.registry.rest.v3.beans.DownloadRef;
2021
import io.apicurio.registry.rest.v3.beans.RoleMapping;
2122
import io.apicurio.registry.rest.v3.beans.RoleMappingSearchResults;
@@ -154,22 +155,22 @@ public List<RuleType> listGlobalRules() {
154155
}
155156

156157
/**
157-
* @see io.apicurio.registry.rest.v3.AdminResource#createGlobalRule(io.apicurio.registry.rest.v3.beans.Rule)
158+
* @see io.apicurio.registry.rest.v3.AdminResource#createGlobalRule(CreateRule)
158159
*/
159160
@Override
160161
@Audited(extractParameters = {"0", KEY_RULE})
161162
@Authorized(style=AuthorizedStyle.None, level=AuthorizedLevel.Admin)
162-
public void createGlobalRule(Rule data) {
163-
RuleType type = data.getType();
164-
requireParameter("type", type);
163+
public void createGlobalRule(CreateRule data) {
164+
RuleType ruleType = data.getRuleType();
165+
requireParameter("ruleType", ruleType);
165166

166167
if (data.getConfig() == null || data.getConfig().isEmpty()) {
167168
throw new MissingRequiredParameterException("Config");
168169
}
169170

170171
RuleConfigurationDto configDto = new RuleConfigurationDto();
171172
configDto.setConfiguration(data.getConfig());
172-
storage.createGlobalRule(data.getType(), configDto);
173+
storage.createGlobalRule(data.getRuleType(), configDto);
173174
}
174175

175176
/**
@@ -187,19 +188,19 @@ public void deleteAllGlobalRules() {
187188
*/
188189
@Override
189190
@Authorized(style=AuthorizedStyle.None, level=AuthorizedLevel.Read)
190-
public Rule getGlobalRuleConfig(RuleType rule) {
191+
public Rule getGlobalRuleConfig(RuleType ruleType) {
191192
RuleConfigurationDto dto;
192193
try {
193-
dto = storage.getGlobalRule(rule);
194+
dto = storage.getGlobalRule(ruleType);
194195
} catch (RuleNotFoundException ruleNotFoundException) {
195196
// Check if the rule exists in the default global rules
196-
dto = rulesProperties.getDefaultGlobalRuleConfiguration(rule);
197+
dto = rulesProperties.getDefaultGlobalRuleConfiguration(ruleType);
197198
if (dto == null) {
198199
throw ruleNotFoundException;
199200
}
200201
}
201202
Rule ruleBean = new Rule();
202-
ruleBean.setType(rule);
203+
ruleBean.setRuleType(ruleType);
203204
ruleBean.setConfig(dto.getConfiguration());
204205
return ruleBean;
205206
}
@@ -210,22 +211,22 @@ public Rule getGlobalRuleConfig(RuleType rule) {
210211
@Override
211212
@Audited(extractParameters = {"0", KEY_RULE_TYPE, "1", KEY_RULE})
212213
@Authorized(style=AuthorizedStyle.None, level=AuthorizedLevel.Admin)
213-
public Rule updateGlobalRuleConfig(RuleType rule, Rule data) {
214+
public Rule updateGlobalRuleConfig(RuleType ruleType, Rule data) {
214215
RuleConfigurationDto configDto = new RuleConfigurationDto();
215216
configDto.setConfiguration(data.getConfig());
216217
try {
217-
storage.updateGlobalRule(rule, configDto);
218+
storage.updateGlobalRule(ruleType, configDto);
218219
} catch (RuleNotFoundException ruleNotFoundException) {
219220
// This global rule doesn't exist in artifactStore - if the rule exists in the default
220221
// global rules, override the default by creating a new global rule
221-
if (rulesProperties.isDefaultGlobalRuleConfigured(rule)) {
222-
storage.createGlobalRule(rule, configDto);
222+
if (rulesProperties.isDefaultGlobalRuleConfigured(ruleType)) {
223+
storage.createGlobalRule(ruleType, configDto);
223224
} else {
224225
throw ruleNotFoundException;
225226
}
226227
}
227228
Rule ruleBean = new Rule();
228-
ruleBean.setType(rule);
229+
ruleBean.setRuleType(ruleType);
229230
ruleBean.setConfig(data.getConfig());
230231
return ruleBean;
231232
}

app/src/main/java/io/apicurio/registry/rest/v3/GroupsResourceImpl.java

+16-15
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import io.apicurio.registry.rest.v3.beans.CreateArtifact;
2929
import io.apicurio.registry.rest.v3.beans.CreateArtifactResponse;
3030
import io.apicurio.registry.rest.v3.beans.CreateGroup;
31+
import io.apicurio.registry.rest.v3.beans.CreateRule;
3132
import io.apicurio.registry.rest.v3.beans.CreateVersion;
3233
import io.apicurio.registry.rest.v3.beans.EditableArtifactMetaData;
3334
import io.apicurio.registry.rest.v3.beans.EditableGroupMetaData;
@@ -300,17 +301,16 @@ public List<RuleType> listArtifactRules(String groupId, String artifactId) {
300301
}
301302

302303
/**
303-
* @see io.apicurio.registry.rest.v3.GroupsResource#createArtifactRule(java.lang.String, java.lang.String, io.apicurio.registry.rest.v3.beans.Rule)
304+
* @see io.apicurio.registry.rest.v3.GroupsResource#createArtifactRule(String, String, CreateRule)
304305
*/
305306
@Override
306307
@Audited(extractParameters = {"0", KEY_GROUP_ID, "1", KEY_ARTIFACT_ID, "2", KEY_RULE})
307308
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
308-
public void createArtifactRule(String groupId, String artifactId, Rule data) {
309+
public void createArtifactRule(String groupId, String artifactId, CreateRule data) {
309310
requireParameter("groupId", groupId);
310311
requireParameter("artifactId", artifactId);
311-
312-
RuleType type = data.getType();
313-
requireParameter("type", type);
312+
requireParameter("ruleType", data.getRuleType());
313+
requireParameter("config", data.getConfig());
314314

315315
if (data.getConfig() == null || data.getConfig().isEmpty()) {
316316
throw new MissingRequiredParameterException("Config");
@@ -323,7 +323,7 @@ public void createArtifactRule(String groupId, String artifactId, Rule data) {
323323
throw new ArtifactNotFoundException(groupId, artifactId);
324324
}
325325

326-
storage.createArtifactRule(new GroupId(groupId).getRawGroupIdWithNull(), artifactId, data.getType(), config);
326+
storage.createArtifactRule(new GroupId(groupId).getRawGroupIdWithNull(), artifactId, data.getRuleType(), config);
327327
}
328328

329329
/**
@@ -344,33 +344,34 @@ public void deleteArtifactRules(String groupId, String artifactId) {
344344
*/
345345
@Override
346346
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Read)
347-
public Rule getArtifactRuleConfig(String groupId, String artifactId, RuleType rule) {
347+
public Rule getArtifactRuleConfig(String groupId, String artifactId, RuleType ruleType) {
348348
requireParameter("groupId", groupId);
349349
requireParameter("artifactId", artifactId);
350-
requireParameter("rule", rule);
350+
requireParameter("ruleType", ruleType);
351351

352-
RuleConfigurationDto dto = storage.getArtifactRule(new GroupId(groupId).getRawGroupIdWithNull(), artifactId, rule);
352+
RuleConfigurationDto dto = storage.getArtifactRule(new GroupId(groupId).getRawGroupIdWithNull(), artifactId, ruleType);
353353
Rule rval = new Rule();
354354
rval.setConfig(dto.getConfiguration());
355-
rval.setType(rule);
355+
rval.setRuleType(ruleType);
356356
return rval;
357357
}
358358

359359
/**
360-
* @see io.apicurio.registry.rest.v3.GroupsResource#updateArtifactRuleConfig(java.lang.String, java.lang.String, io.apicurio.registry.types.RuleType, io.apicurio.registry.rest.v3.beans.Rule)
360+
* @see io.apicurio.registry.rest.v3.GroupsResource#updateArtifactRuleConfig(String, String, RuleType, Rule)
361361
*/
362362
@Override
363363
@Audited(extractParameters = {"0", KEY_GROUP_ID, "1", KEY_ARTIFACT_ID, "2", KEY_RULE_TYPE, "3", KEY_RULE})
364364
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
365-
public Rule updateArtifactRuleConfig(String groupId, String artifactId, RuleType rule, Rule data) {
365+
public Rule updateArtifactRuleConfig(String groupId, String artifactId, RuleType ruleType, Rule data) {
366366
requireParameter("groupId", groupId);
367367
requireParameter("artifactId", artifactId);
368-
requireParameter("rule", rule);
368+
requireParameter("ruleType", ruleType);
369+
requireParameter("config", data.getConfig());
369370

370371
RuleConfigurationDto dto = new RuleConfigurationDto(data.getConfig());
371-
storage.updateArtifactRule(new GroupId(groupId).getRawGroupIdWithNull(), artifactId, rule, dto);
372+
storage.updateArtifactRule(new GroupId(groupId).getRawGroupIdWithNull(), artifactId, ruleType, dto);
372373
Rule rval = new Rule();
373-
rval.setType(rule);
374+
rval.setRuleType(ruleType);
374375
rval.setConfig(data.getConfig());
375376
return rval;
376377
}

app/src/test/java/io/apicurio/registry/AbstractResourceTestBase.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -242,33 +242,33 @@ protected Long createArtifactVersion(String groupId, String artifactId, String c
242242
}
243243

244244
protected void createArtifactRule(String groupId, String artifactId, RuleType ruleType, String ruleConfig) {
245-
var rule = new io.apicurio.registry.rest.client.models.Rule();
246-
rule.setConfig(ruleConfig);
247-
rule.setType(io.apicurio.registry.rest.client.models.RuleType.forValue(ruleType.value()));
245+
var createRule = new io.apicurio.registry.rest.client.models.CreateRule();
246+
createRule.setConfig(ruleConfig);
247+
createRule.setRuleType(io.apicurio.registry.rest.client.models.RuleType.forValue(ruleType.value()));
248248

249249
clientV3
250250
.groups()
251251
.byGroupId(groupId)
252252
.artifacts()
253253
.byArtifactId(artifactId)
254254
.rules()
255-
.post(rule);
255+
.post(createRule);
256256
}
257257

258258
protected io.apicurio.registry.rest.client.models.Rule createGlobalRule(RuleType ruleType, String ruleConfig) {
259-
var rule = new io.apicurio.registry.rest.client.models.Rule();
260-
rule.setConfig(ruleConfig);
261-
rule.setType(io.apicurio.registry.rest.client.models.RuleType.forValue(ruleType.value()));
259+
var createRule = new io.apicurio.registry.rest.client.models.CreateRule();
260+
createRule.setConfig(ruleConfig);
261+
createRule.setRuleType(io.apicurio.registry.rest.client.models.RuleType.forValue(ruleType.value()));
262262

263263
clientV3
264264
.admin()
265265
.rules()
266-
.post(rule);
266+
.post(createRule);
267267
// TODO: verify this get
268268
return clientV3
269269
.admin()
270270
.rules()
271-
.byRule(ruleType.value())
271+
.byRuleType(ruleType.value())
272272
.get();
273273
}
274274

app/src/test/java/io/apicurio/registry/auth/AuthTestLocalRoles.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import io.apicurio.registry.model.GroupId;
66
import io.apicurio.registry.rest.client.RegistryClient;
77
import io.apicurio.registry.rest.client.models.CreateArtifact;
8+
import io.apicurio.registry.rest.client.models.CreateRule;
89
import io.apicurio.registry.rest.client.models.RoleMapping;
910
import io.apicurio.registry.rest.client.models.RoleType;
10-
import io.apicurio.registry.rest.client.models.Rule;
1111
import io.apicurio.registry.rest.client.models.RuleType;
1212
import io.apicurio.registry.rest.client.models.UpdateRole;
1313
import io.apicurio.registry.rules.validity.ValidityLevel;
@@ -56,12 +56,12 @@ protected RegistryClient createRestClientV3() {
5656
return new RegistryClient(adapter);
5757
}
5858

59-
private static final Rule rule = new Rule();
59+
private static final CreateRule createRule = new CreateRule();
6060
private static final CreateArtifact createArtifact;
6161

6262
static {
63-
rule.setConfig(ValidityLevel.FULL.name());
64-
rule.setType(RuleType.VALIDITY);
63+
createRule.setConfig(ValidityLevel.FULL.name());
64+
createRule.setRuleType(RuleType.VALIDITY);
6565
createArtifact = TestUtils.clientCreateArtifact(AuthTestLocalRoles.class.getSimpleName(), ArtifactType.AVRO, TEST_CONTENT, ContentTypes.APPLICATION_JSON);
6666
}
6767

@@ -92,7 +92,7 @@ public void testLocalRoles() throws Exception {
9292
assertForbidden(exception2);
9393

9494
var exception3 = Assertions.assertThrows(Exception.class, () -> {
95-
client.admin().rules().post(rule);
95+
client.admin().rules().post(createRule);
9696
});
9797
assertForbidden(exception3);
9898

@@ -115,7 +115,7 @@ public void testLocalRoles() throws Exception {
115115
});
116116
assertForbidden(exception4);
117117
var exception5 = Assertions.assertThrows(Exception.class, () -> {
118-
client.admin().rules().post(rule);
118+
client.admin().rules().post(createRule);
119119
});
120120
assertForbidden(exception5);
121121

@@ -140,7 +140,7 @@ public void testLocalRoles() throws Exception {
140140
config.headers.add("X-Registry-ArtifactId", getClass().getSimpleName());
141141
});
142142
var exception6 = Assertions.assertThrows(Exception.class, () -> {
143-
client.admin().rules().post(rule);
143+
client.admin().rules().post(createRule);
144144
});
145145
assertForbidden(exception6);
146146

@@ -162,7 +162,7 @@ public void testLocalRoles() throws Exception {
162162
.byGroupId(UUID.randomUUID().toString())
163163
.artifacts()
164164
.post(createArtifact);
165-
client.admin().rules().post(rule);
165+
client.admin().rules().post(createRule);
166166

167167
// Now delete the role mapping
168168
clientAdmin

app/src/test/java/io/apicurio/registry/auth/AuthTestNoRoles.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import io.apicurio.registry.model.GroupId;
77
import io.apicurio.registry.rest.client.RegistryClient;
88
import io.apicurio.registry.rest.client.models.CreateArtifact;
9+
import io.apicurio.registry.rest.client.models.CreateRule;
910
import io.apicurio.registry.rest.client.models.CreateVersion;
10-
import io.apicurio.registry.rest.client.models.Rule;
1111
import io.apicurio.registry.rest.client.models.RuleType;
1212
import io.apicurio.registry.rest.client.models.VersionContent;
1313
import io.apicurio.registry.rules.validity.ValidityLevel;
@@ -91,12 +91,12 @@ public void testAdminRole() throws Exception {
9191
);
9292
assertNotNull(client.groups().byGroupId(groupId).artifacts().byArtifactId(artifactId).get());
9393

94-
Rule ruleConfig = new Rule();
95-
ruleConfig.setType(RuleType.VALIDITY);
96-
ruleConfig.setConfig(ValidityLevel.NONE.name());
94+
CreateRule createRule = new CreateRule();
95+
createRule.setRuleType(RuleType.VALIDITY);
96+
createRule.setConfig(ValidityLevel.NONE.name());
9797

98-
client.groups().byGroupId(groupId).artifacts().byArtifactId(artifactId).rules().post(ruleConfig);
99-
client.admin().rules().post(ruleConfig);
98+
client.groups().byGroupId(groupId).artifacts().byArtifactId(artifactId).rules().post(createRule);
99+
client.admin().rules().post(createRule);
100100
} finally {
101101
client.groups().byGroupId(groupId).artifacts().byArtifactId(artifactId).delete();
102102
}

app/src/test/java/io/apicurio/registry/auth/AuthTestProfileBasicClientCredentials.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import io.apicurio.registry.model.GroupId;
77
import io.apicurio.registry.rest.client.RegistryClient;
88
import io.apicurio.registry.rest.client.models.CreateArtifact;
9+
import io.apicurio.registry.rest.client.models.CreateRule;
910
import io.apicurio.registry.rest.client.models.CreateVersion;
10-
import io.apicurio.registry.rest.client.models.Rule;
1111
import io.apicurio.registry.rest.client.models.RuleType;
1212
import io.apicurio.registry.rest.client.models.VersionContent;
1313
import io.apicurio.registry.rules.validity.ValidityLevel;
@@ -92,12 +92,12 @@ public void testBasicAuthClientCredentials() throws Exception {
9292
);
9393
assertNotNull(client.groups().byGroupId(groupId).artifacts().byArtifactId(artifactId).get());
9494

95-
Rule ruleConfig = new Rule();
96-
ruleConfig.setType(RuleType.VALIDITY);
97-
ruleConfig.setConfig(ValidityLevel.NONE.name());
95+
CreateRule createRule = new CreateRule();
96+
createRule.setRuleType(RuleType.VALIDITY);
97+
createRule.setConfig(ValidityLevel.NONE.name());
9898

99-
client.groups().byGroupId(groupId).artifacts().byArtifactId(artifactId).rules().post(ruleConfig);
100-
client.admin().rules().post(ruleConfig);
99+
client.groups().byGroupId(groupId).artifacts().byArtifactId(artifactId).rules().post(createRule);
100+
client.admin().rules().post(createRule);
101101
} finally {
102102
client.groups().byGroupId(groupId).artifacts().byArtifactId(artifactId).delete();
103103
}

app/src/test/java/io/apicurio/registry/auth/BasicAuthWithPropertiesTest.java

+15-15
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import io.apicurio.registry.rest.client.RegistryClient;
66
import io.apicurio.registry.rest.client.models.ArtifactMetaData;
77
import io.apicurio.registry.rest.client.models.CreateArtifact;
8+
import io.apicurio.registry.rest.client.models.CreateRule;
89
import io.apicurio.registry.rest.client.models.EditableArtifactMetaData;
9-
import io.apicurio.registry.rest.client.models.Rule;
1010
import io.apicurio.registry.rest.client.models.RuleType;
1111
import io.apicurio.registry.rest.client.models.UserInfo;
1212
import io.apicurio.registry.rest.client.models.VersionMetaData;
@@ -135,13 +135,13 @@ public void testDevRole() throws Exception {
135135

136136
assertTrue(client.groups().byGroupId(groupId).artifacts().byArtifactId(artifactId).versions().byVersionExpression("branch=latest").content().get().readAllBytes().length > 0);
137137

138-
Rule ruleConfig = new Rule();
139-
ruleConfig.setType(RuleType.VALIDITY);
140-
ruleConfig.setConfig(ValidityLevel.NONE.name());
141-
client.groups().byGroupId(groupId).artifacts().byArtifactId(artifactId).rules().post(ruleConfig);
138+
CreateRule createRule = new CreateRule();
139+
createRule.setRuleType(RuleType.VALIDITY);
140+
createRule.setConfig(ValidityLevel.NONE.name());
141+
client.groups().byGroupId(groupId).artifacts().byArtifactId(artifactId).rules().post(createRule);
142142

143143
var exception = Assertions.assertThrows(Exception.class, () -> {
144-
client.admin().rules().post(ruleConfig);
144+
client.admin().rules().post(createRule);
145145
});
146146
assertForbidden(exception);
147147

@@ -171,12 +171,12 @@ public void testAdminRole() throws Exception {
171171

172172
assertTrue(client.groups().byGroupId(groupId).artifacts().byArtifactId(artifactId).versions().byVersionExpression("branch=latest").content().get().readAllBytes().length > 0);
173173

174-
Rule ruleConfig = new Rule();
175-
ruleConfig.setType(RuleType.VALIDITY);
176-
ruleConfig.setConfig(ValidityLevel.NONE.name());
177-
client.groups().byGroupId(groupId).artifacts().byArtifactId(artifactId).rules().post(ruleConfig);
174+
CreateRule createRule = new CreateRule();
175+
createRule.setRuleType(RuleType.VALIDITY);
176+
createRule.setConfig(ValidityLevel.NONE.name());
177+
client.groups().byGroupId(groupId).artifacts().byArtifactId(artifactId).rules().post(createRule);
178178

179-
client.admin().rules().post(ruleConfig);
179+
client.admin().rules().post(createRule);
180180

181181
UserInfo userInfo = client.users().me().get();
182182
assertNotNull(userInfo);
@@ -222,10 +222,10 @@ public void testOwnerOnlyAuthorization() throws Exception {
222222
clientDev.groups().byGroupId(groupId).artifacts().post(createArtifact);
223223

224224
// And the Admin user will modify it (allowed because it's the Admin user)
225-
Rule rule = new Rule();
226-
rule.setType(RuleType.COMPATIBILITY);
227-
rule.setConfig(CompatibilityLevel.BACKWARD.name());
228-
clientAdmin.groups().byGroupId(groupId).artifacts().byArtifactId(artifactId2).rules().post(rule);
225+
CreateRule createRule = new CreateRule();
226+
createRule.setRuleType(RuleType.COMPATIBILITY);
227+
createRule.setConfig(CompatibilityLevel.BACKWARD.name());
228+
clientAdmin.groups().byGroupId(groupId).artifacts().byArtifactId(artifactId2).rules().post(createRule);
229229
}
230230

231231
@Test

0 commit comments

Comments
 (0)