Skip to content

Commit

Permalink
Merge pull request #65 from groldan/feature/delete_all_api
Browse files Browse the repository at this point in the history
New API to delete all rules
  • Loading branch information
groldan committed Apr 17, 2024
2 parents 15e481f + b9bcc81 commit 69fd84e
Show file tree
Hide file tree
Showing 17 changed files with 3,194 additions and 2,403 deletions.
5,488 changes: 3,085 additions & 2,403 deletions docs/api/index.html

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@ public interface AdminRuleAdminService {
int count(AdminRuleFilter filter);

boolean exists(String id);

int deleteAll();
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ public boolean delete(@NonNull String id) {
return deleted;
}

@Override
public int deleteAll() {
return repository.deleteAll();
}

@Override
public Stream<AdminRule> getAll() {
return repository.findAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ public interface AdminRuleRepository {

boolean deleteById(String id);

int deleteAll();

Optional<AdminRule> findOneByPriority(long priority);
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ public boolean deleteById(String id) {
return rules.removeIf(r -> r.getId().equals(id));
}

@Override
public int deleteAll() {
int count = rules.size();
rules.clear();
return count;
}

@Override
public Optional<AdminRule> findOneByPriority(long priority) {
return rules.stream().filter(r -> r.getPriority() == priority).findFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,6 @@ public interface RuleAdminService {
* RuleIdentifier#getLayer() layer} set
*/
Set<String> getAllowedStyles(String ruleId);

int deleteAll();
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ public boolean delete(@NonNull String id) {
return deleted;
}

@Override
public int deleteAll() {
return ruleRepository.deleteAll();
}

@Override
public Stream<Rule> getAll() {
return ruleRepository.findAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public interface RuleRepository {

boolean deleteById(String id);

int deleteAll();

int count();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ public boolean deleteById(@NonNull String id) {
return rules.removeIf(r -> id.equals(r.getId()));
}

@Override
public int deleteAll() {
int count = rules.size();
layerDetails.clear();
rules.clear();
return count;
}

@Override
public int count() {
return rules.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,26 @@ void testCreateRule_insertPosition_FromEnd(TestInfo testInfo) {
r2.withPriority(5)));
}

@Test
void testDeleteAll() {
ruleAdminService.insert(Rule.allow().withPriority(10).withLayer("L1"));
ruleAdminService.insert(
Rule.limit().withPriority(11).withLayer("L2").withRuleLimits(sampleLimits()));

Rule r3 = ruleAdminService.insert(Rule.allow().withPriority(12).withLayer("L2"));
ruleAdminService.setLayerDetails(r3.getId(), sampleDetails(0));
ruleAdminService.setAllowedStyles(r3.getId(), Set.of("style1", "style2", "style3"));

final int expected = 3;
assertThat(ruleAdminService.count()).isEqualTo(expected);

int ret = ruleAdminService.deleteAll();
assertThat(ret).isEqualTo(expected);
assertThat(ruleAdminService.deleteAll()).isZero();

assertThat(ruleAdminService.getAll()).isEmpty();
}

@Test
void testDeleteRuleById() {
Rule r1 = ruleAdminService.insert(Rule.allow().withPriority(10).withLayer("L1"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ public boolean deleteById(@NonNull String id) {
}
}

@Override
public int deleteAll() {
return apiClient.deleteAllAdminRules();
}

@Override
public Optional<AdminRule> findOneByPriority(long priority) {
org.geoserver.acl.api.model.AdminRule found;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public boolean deleteById(@NonNull String id) {
return true;
}

@Override
public int deleteAll() {
return apiClient.deleteAllRules();
}

@Override
public int count() {
return apiClient.countAllRules();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ public ResponseEntity<Void> deleteRuleById(@NonNull String id) {
return ResponseEntity.status(status).build();
}

@Override
@IsAdmin
public ResponseEntity<Integer> deleteAllRules() {
return ResponseEntity.ok(service.deleteAll());
}

@Override
public ResponseEntity<List<Rule>> getRules(Integer limit, String nextCursor) {
return query(RuleQuery.of(limit, nextCursor));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ public class WorkspaceAdminRulesApiImpl implements WorkspaceAdminRulesApiDelegat
return ResponseEntity.status(deleted ? OK : NOT_FOUND).build();
}

@Override
@IsAdmin
public ResponseEntity<Integer> deleteAllAdminRules() {
return ResponseEntity.ok(service.deleteAll());
}

public @Override ResponseEntity<Boolean> adminRuleExistsById(@NonNull String id) {
return ResponseEntity.ok(service.exists(id));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,14 @@ public boolean deleteById(@NonNull String id) {
return 1 == jparepo.deleteById(decodeId(id).longValue());
}

@Override
@TransactionRequired
public int deleteAll() {
int count = count();
jparepo.deleteAll();
return count;
}

private org.geoserver.acl.jpa.model.AdminRule getOrThrowIAE(@NonNull String ruleId) {
org.geoserver.acl.jpa.model.AdminRule rule;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,14 @@ public boolean deleteById(@NonNull String id) {
return true;
}

@Override
@TransactionRequired
public int deleteAll() {
int count = count();
jparepo.deleteAll();
return count;
}

@Override
public boolean existsById(@NonNull String id) {
return jparepo.existsById(decodeId(id));
Expand Down
18 changes: 18 additions & 0 deletions src/openapi/acl-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ paths:
schema:
type: string
description: Error reason, including offending property names
delete:
operationId: deleteAllRules
description: Atomically deletes all data rules and return the number of rules removed
tags:
- DataRules
responses:
'200':
$ref: '#/components/responses/Count'

/rules/query:
post:
Expand Down Expand Up @@ -356,6 +364,15 @@ paths:
responses:
'201':
$ref: '#/components/responses/AdminRule'
delete:
operationId: deleteAllAdminRules
description: Atomically deletes all admin rules and return the number of rules removed
tags:
- WorkspaceAdminRules
responses:
'200':
$ref: '#/components/responses/Count'

/adminrules/query:
post:
parameters:
Expand Down Expand Up @@ -402,6 +419,7 @@ paths:
responses:
'200':
$ref: '#/components/responses/Count'

/adminrules/query/one/priority/{priority}:
get:
operationId: findOneAdminRuleByPriority
Expand Down

0 comments on commit 69fd84e

Please sign in to comment.