From 26635cbcf901ba09a400e97f95013ee543657b59 Mon Sep 17 00:00:00 2001 From: Andrus Adamchik Date: Sun, 10 Oct 2021 11:18:44 +0300 Subject: [PATCH] internal refactoring/cleanup, no change --- .../runtime/constraints/ConstraintsHandler.java | 16 ++++++++-------- .../constraints/RequestConstraintsHandler.java | 12 ++---------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/agrest-engine/src/main/java/io/agrest/runtime/constraints/ConstraintsHandler.java b/agrest-engine/src/main/java/io/agrest/runtime/constraints/ConstraintsHandler.java index ae7d9c7ec..159faee7c 100644 --- a/agrest-engine/src/main/java/io/agrest/runtime/constraints/ConstraintsHandler.java +++ b/agrest-engine/src/main/java/io/agrest/runtime/constraints/ConstraintsHandler.java @@ -24,23 +24,23 @@ public class ConstraintsHandler implements IConstraintsHandler { private static final Logger LOGGER = LoggerFactory.getLogger(ConstraintsHandler.class); - private RequestConstraintsHandler treeConstraintsHandler; - private EntityConstraintHandler entityConstraintHandler; + private RequestConstraintsHandler requestConstraintHandler; + private EntityConstraintHandler modelConstraintHandler; public ConstraintsHandler( @Inject(DEFAULT_READ_CONSTRAINTS_LIST) List readConstraints, @Inject(DEFAULT_WRITE_CONSTRAINTS_LIST) List writeConstraints ) { - this.treeConstraintsHandler = new RequestConstraintsHandler(); - this.entityConstraintHandler = new EntityConstraintHandler(readConstraints, writeConstraints); + this.requestConstraintHandler = new RequestConstraintsHandler(); + this.modelConstraintHandler = new EntityConstraintHandler(readConstraints, writeConstraints); } @Override public void constrainUpdate(UpdateContext context, Constraint c) { - if (!treeConstraintsHandler.constrainUpdate(context, c)) { - entityConstraintHandler.constrainUpdate(context); + if (!requestConstraintHandler.constrainUpdate(context, c)) { + modelConstraintHandler.constrainUpdate(context); } } @@ -51,8 +51,8 @@ public void constrainResponse(ResourceEntity entity, SizeConstraints size applySizeConstraintsForRead(entity, sizeConstraints); } - if (!treeConstraintsHandler.constrainResponse(entity, c)) { - entityConstraintHandler.constrainResponse(entity); + if (!requestConstraintHandler.constrainResponse(entity, c)) { + modelConstraintHandler.constrainResponse(entity); } } diff --git a/agrest-engine/src/main/java/io/agrest/runtime/constraints/RequestConstraintsHandler.java b/agrest-engine/src/main/java/io/agrest/runtime/constraints/RequestConstraintsHandler.java index 252ee2ad9..ed56b95e2 100644 --- a/agrest-engine/src/main/java/io/agrest/runtime/constraints/RequestConstraintsHandler.java +++ b/agrest-engine/src/main/java/io/agrest/runtime/constraints/RequestConstraintsHandler.java @@ -28,12 +28,6 @@ class RequestConstraintsHandler { boolean constrainResponse(ResourceEntity resourceEntity, Constraint c) { - // Null entity means we don't need to worry about unauthorized - // attributes and relationships - if (resourceEntity == null) { - return true; - } - if (c == null) { return false; } @@ -73,8 +67,7 @@ private void applyForWrite(UpdateContext context, ConstrainedAgEntity constra Entry e = it.next(); if (!constraints.hasAttribute(e.getKey())) { - // do not report default properties, as this wasn't a - // client's fault it go there.. + // do not report default properties, as this wasn't a client's fault it go there.. if (!context.getEntity().isDefaultAttribute(e.getKey())) { LOGGER.info("Attribute not allowed, removing: {} for id {}", e.getKey(), u.getId()); } @@ -106,8 +99,7 @@ private void applyForRead(ResourceEntity target, ConstrainedAgEntity constrai AgAttribute a = ait.next(); if (!constraints.hasAttribute(a.getName())) { - // do not report default properties, as this wasn't a client's - // fault it go there.. + // do not report default properties, as this wasn't a client's fault it go there if (!target.isDefaultAttribute(a.getName())) { LOGGER.info("Attribute not allowed, removing: {}", a.getName()); }