Skip to content

Commit

Permalink
Filter nested unwritable attributes from updates #637
Browse files Browse the repository at this point in the history
refactoring ConstraintsHandler for maintainability
  • Loading branch information
andrus committed Jun 29, 2023
1 parent 500cb7a commit b8be475
Show file tree
Hide file tree
Showing 13 changed files with 277 additions and 282 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import io.agrest.RootResourceEntity;
import io.agrest.cayenne.persister.ICayennePersister;
import io.agrest.cayenne.processor.CayenneProcessor;
import io.agrest.runtime.constraints.IConstraintsHandler;
import io.agrest.runtime.processor.select.stage.SelectApplyServerParamsStage;
import io.agrest.runtime.constraints.SelectConstraints;
import io.agrest.runtime.processor.select.SelectContext;
import io.agrest.runtime.processor.select.stage.SelectApplyServerParamsStage;
import org.apache.cayenne.di.Inject;
import org.apache.cayenne.map.EntityResolver;

Expand All @@ -18,9 +18,9 @@ public class CayenneSelectApplyServerParamsStage extends SelectApplyServerParams
private final EntityResolver entityResolver;

public CayenneSelectApplyServerParamsStage(
@Inject IConstraintsHandler constraintsHandler,
@Inject SelectConstraints constraints,
@Inject ICayennePersister persister) {
super(constraintsHandler);
super(constraints);
this.entityResolver = persister.entityResolver();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package io.agrest.cayenne.processor.update.stage;

import io.agrest.AgException;
import io.agrest.runtime.EntityParent;
import io.agrest.EntityUpdate;
import io.agrest.RelatedResourceEntity;
import io.agrest.ResourceEntity;
import io.agrest.RootResourceEntity;
import io.agrest.cayenne.path.IPathResolver;
import io.agrest.cayenne.path.PathOps;
Expand All @@ -15,7 +13,8 @@
import io.agrest.meta.AgIdPart;
import io.agrest.meta.AgRelationship;
import io.agrest.processor.ProcessorOutcome;
import io.agrest.runtime.constraints.IConstraintsHandler;
import io.agrest.runtime.EntityParent;
import io.agrest.runtime.constraints.UpdateConstraints;
import io.agrest.runtime.processor.update.UpdateContext;
import io.agrest.runtime.processor.update.stage.UpdateApplyServerParamsStage;
import org.apache.cayenne.di.Inject;
Expand All @@ -39,17 +38,17 @@
*/
public class CayenneUpdateApplyServerParamsStage extends UpdateApplyServerParamsStage {

private final IConstraintsHandler constraintsHandler;
private final UpdateConstraints constraints;
private final EntityResolver entityResolver;
private final IPathResolver pathResolver;

public CayenneUpdateApplyServerParamsStage(
@Inject IPathResolver pathResolver,
@Inject IConstraintsHandler constraintsHandler,
@Inject UpdateConstraints constraints,
@Inject ICayennePersister persister) {

this.pathResolver = pathResolver;
this.constraintsHandler = constraintsHandler;
this.constraints = constraints;
this.entityResolver = persister.entityResolver();
}

Expand All @@ -61,8 +60,6 @@ public ProcessorOutcome execute(UpdateContext<?> context) {

protected <T> void doExecute(UpdateContext<T> context) {

ResourceEntity<T> entity = context.getEntity();

// this creates a new EntityUpdate if there's no request payload, but the context ID is present,
// so execute it unconditionally
fillIdsFromExplicitContextId(context);
Expand All @@ -73,11 +70,7 @@ protected <T> void doExecute(UpdateContext<T> context) {
fillIdsFromParentId(context);
}

constraintsHandler.constrainUpdate(context);

// apply read constraints
// TODO: should we only care about response constraints after the commit?
constraintsHandler.constrainResponse(entity);
constraints.apply(context);

tagRootEntity(context.getEntity());
}
Expand Down
11 changes: 6 additions & 5 deletions agrest-engine/src/main/java/io/agrest/runtime/AgCoreModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
import io.agrest.encoder.ValueEncodersProvider;
import io.agrest.meta.AgEntityOverlay;
import io.agrest.meta.AgSchema;
import io.agrest.runtime.constraints.ConstraintsHandler;
import io.agrest.runtime.constraints.IConstraintsHandler;
import io.agrest.runtime.constraints.SelectConstraints;
import io.agrest.runtime.constraints.UpdateConstraints;
import io.agrest.runtime.encoder.EncodablePropertyFactory;
import io.agrest.runtime.encoder.EncoderFactory;
import io.agrest.runtime.encoder.IEncodablePropertyFactory;
Expand Down Expand Up @@ -100,18 +100,18 @@
import io.agrest.runtime.processor.update.stage.UpdateMergeChangesStage;
import io.agrest.runtime.processor.update.stage.UpdateParseRequestStage;
import io.agrest.runtime.processor.update.stage.UpdateStartStage;
import io.agrest.runtime.protocol.UpdateRequestParser;
import io.agrest.runtime.protocol.ExcludeParser;
import io.agrest.runtime.protocol.ExpParser;
import io.agrest.runtime.protocol.IUpdateRequestParser;
import io.agrest.runtime.protocol.IExcludeParser;
import io.agrest.runtime.protocol.IExpParser;
import io.agrest.runtime.protocol.IIncludeParser;
import io.agrest.runtime.protocol.ISizeParser;
import io.agrest.runtime.protocol.ISortParser;
import io.agrest.runtime.protocol.IUpdateRequestParser;
import io.agrest.runtime.protocol.IncludeParser;
import io.agrest.runtime.protocol.SizeParser;
import io.agrest.runtime.protocol.SortParser;
import io.agrest.runtime.protocol.UpdateRequestParser;
import io.agrest.runtime.request.DefaultRequestBuilderFactory;
import io.agrest.runtime.request.IAgRequestBuilderFactory;
import io.agrest.runtime.semantics.IRelationshipMapper;
Expand Down Expand Up @@ -268,7 +268,8 @@ public void configure(Binder binder) {
binder.bind(EncoderFactory.class).to(EncoderFactory.class);
binder.bind(IRelationshipMapper.class).to(RelationshipMapper.class);
binder.bind(AgSchema.class).toProvider(LazySchemaProvider.class);
binder.bind(IConstraintsHandler.class).to(ConstraintsHandler.class);
binder.bind(SelectConstraints.class).to(SelectConstraints.class);
binder.bind(UpdateConstraints.class).to(UpdateConstraints.class);

binder.bind(IJacksonService.class).toProvider(JacksonServiceProvider.class);

Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit b8be475

Please sign in to comment.