diff --git a/src/integration/persistence-jpa/integration/src/main/java/org/geoserver/acl/integration/jpa/repository/AdminRuleRepositoryJpaAdaptor.java b/src/integration/persistence-jpa/integration/src/main/java/org/geoserver/acl/integration/jpa/repository/AdminRuleRepositoryJpaAdaptor.java index 0911912..c788651 100644 --- a/src/integration/persistence-jpa/integration/src/main/java/org/geoserver/acl/integration/jpa/repository/AdminRuleRepositoryJpaAdaptor.java +++ b/src/integration/persistence-jpa/integration/src/main/java/org/geoserver/acl/integration/jpa/repository/AdminRuleRepositoryJpaAdaptor.java @@ -131,7 +131,7 @@ private org.geoserver.acl.domain.rules.InsertPosition map(InsertPosition positio @Override public Optional findById(@NonNull String id) { - return jparepo.findById(decodeId(id).longValue()).map(modelMapper::toModel); + return jparepo.findById(decodeId(id)).map(modelMapper::toModel); } @Override @@ -142,8 +142,7 @@ public int count() { @Override public int count(AdminRuleFilter filter) { Optional predicate = queryMapper.toPredicate(filter); - if (predicate.isEmpty()) return (int) jparepo.count(predicate.get()); - return (int) jparepo.count(); + return predicate.map(jparepo::count).map(Long::intValue).orElseGet(this::count); } @Override @@ -222,13 +221,11 @@ public Stream findAll(@NonNull RuleQuery query) { private CloseableIterator queryOrderByPriority( Predicate predicate) { - CloseableIterator iterator = - new JPAQuery(em) - .from(QAdminRule.adminRule) - .where(predicate) - .orderBy(new OrderSpecifier<>(Order.ASC, QAdminRule.adminRule.priority)) - .iterate(); - return iterator; + return new JPAQuery(em) + .from(QAdminRule.adminRule) + .where(predicate) + .orderBy(new OrderSpecifier<>(Order.ASC, QAdminRule.adminRule.priority)) + .iterate(); } private Stream stream( @@ -242,9 +239,7 @@ private java.util.function.Predicate filterByAddress( if (filter.isEmpty()) return r -> true; IPAddressRangeFilter ipFilter = filter.get().getSourceAddress(); - return rule -> { - return ipFilter.test(rule.getIdentifier().getAddressRange()); - }; + return rule -> ipFilter.test(rule.getIdentifier().getAddressRange()); } @Override @@ -284,7 +279,7 @@ public boolean deleteById(@NonNull String id) { private org.geoserver.acl.jpa.model.AdminRule getOrThrowIAE(@NonNull String ruleId) { org.geoserver.acl.jpa.model.AdminRule rule; try { - rule = jparepo.getReferenceById(decodeId(ruleId).longValue()); + rule = jparepo.getReferenceById(decodeId(ruleId)); } catch (EntityNotFoundException e) { throw new NoSuchElementException("AdminRule " + ruleId + " does not exist"); }