Skip to content

Commit

Permalink
internal refactoring/cleanup, no change
Browse files Browse the repository at this point in the history
  • Loading branch information
andrus committed Oct 10, 2021
1 parent 7123899 commit 26635cb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<EntityConstraint> readConstraints,
@Inject(DEFAULT_WRITE_CONSTRAINTS_LIST) List<EntityConstraint> writeConstraints
) {

this.treeConstraintsHandler = new RequestConstraintsHandler();
this.entityConstraintHandler = new EntityConstraintHandler(readConstraints, writeConstraints);
this.requestConstraintHandler = new RequestConstraintsHandler();
this.modelConstraintHandler = new EntityConstraintHandler(readConstraints, writeConstraints);
}

@Override
public <T> void constrainUpdate(UpdateContext<T> context, Constraint<T> c) {

if (!treeConstraintsHandler.constrainUpdate(context, c)) {
entityConstraintHandler.constrainUpdate(context);
if (!requestConstraintHandler.constrainUpdate(context, c)) {
modelConstraintHandler.constrainUpdate(context);
}
}

Expand All @@ -51,8 +51,8 @@ public <T> void constrainResponse(ResourceEntity<T> entity, SizeConstraints size
applySizeConstraintsForRead(entity, sizeConstraints);
}

if (!treeConstraintsHandler.constrainResponse(entity, c)) {
entityConstraintHandler.constrainResponse(entity);
if (!requestConstraintHandler.constrainResponse(entity, c)) {
modelConstraintHandler.constrainResponse(entity);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ class RequestConstraintsHandler {

<T> boolean constrainResponse(ResourceEntity<T> resourceEntity, Constraint<T> 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;
}
Expand Down Expand Up @@ -73,8 +67,7 @@ private void applyForWrite(UpdateContext<?> context, ConstrainedAgEntity constra
Entry<String, Object> 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());
}
Expand Down Expand Up @@ -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());
}
Expand Down

0 comments on commit 26635cb

Please sign in to comment.