@Test public void testConstrainResponse_ResourceEntity_TargetRel() { AgEntity<Tr> entityTr = metadata.getAgEntity(Tr.class); AgEntity<Ts> entityTs = metadata.getAgEntity(Ts.class); AgEntity<Tv> entityTv = metadata.getAgEntity(Tv.class); Constraint<Tr> constraint = Constraint.excludeAll(Tr.class).attributes("a", "b") .path("rts", Constraint.excludeAll(Ts.class).attributes("n", "m")) .path("rts.rtt", Constraint.excludeAll(Tt.class).attributes("p", "r")) .path("rtu", Constraint.excludeAll(Tu.class).attributes("k", "l")); ResourceEntity<Tr> tr = new RootResourceEntity<>(entityTr, null); ResourceEntityUtils. appendAttribute(tr, "c"); ResourceEntityUtils.appendAttribute(tr, "b"); NestedResourceEntity<Ts> ts = new NestedResourceEntity<>(entityTs, null, tr, entityTr.getRelationship("rts")); ResourceEntityUtils.appendAttribute(ts, "m"); ResourceEntityUtils.appendAttribute(ts, "z"); tr.getChildren().put("rts", ts); NestedResourceEntity<Tv> tv = new NestedResourceEntity<>(entityTv, null, tr, entityTr.getRelationship("rtv")); ResourceEntityUtils.appendAttribute(tv, "p"); ResourceEntityUtils.appendAttribute(tv, "z"); tr.getChildren().put("rtv", tv); constraintsHandler.constrainResponse(tr, null, constraint); assertEquals(1, tr.getAttributes().size()); assertTrue(tr.getAttributes().containsKey("b")); assertEquals(1, tr.getChildren().size()); ResourceEntity<?> mergedTs = tr.getChildren().get("rts"); assertNotNull(mergedTs); assertTrue(mergedTs.getChildren().isEmpty()); assertEquals(1, mergedTs.getAttributes().size()); assertTrue(mergedTs.getAttributes().containsKey("m")); }
@Override public <T> void constrainResponse(ResourceEntity<T> entity, SizeConstraints sizeConstraints, Constraint<T> c) { if (sizeConstraints != null) { applySizeConstraintsForRead(entity, sizeConstraints); } if (!treeConstraintsHandler.constrainResponse(entity, c)) { entityConstraintHandler.constrainResponse(entity); } }
ConstraintsHandler implements IConstraintsHandler { @Override public <T> void constrainResponse(ResourceEntity<T> entity, SizeConstraints sizeConstraints, Constraint<T> c) { if (sizeConstraints != null) { applySizeConstraintsForRead(entity, sizeConstraints); } if (!treeConstraintsHandler.constrainResponse(entity, c)) { entityConstraintHandler.constrainResponse(entity); } } }
ConstraintsHandler implements IConstraintsHandler { @Override public <T> void constrainResponse(ResourceEntity<T> entity, SizeConstraints sizeConstraints, Constraint<T> c) { if (sizeConstraints != null) { applySizeConstraintsForRead(entity, sizeConstraints); } if (!treeConstraintsHandler.constrainResponse(entity, c)) { entityConstraintHandler.constrainResponse(entity); } } ConstraintsHandler(
            @Inject(DEFAULT_READ_CONSTRAINTS_LIST) List<EntityConstraint> readConstraints,
            @Inject(DEFAULT_WRITE_CONSTRAINTS_LIST) List<EntityConstraint> writeConstraints
    ); }
ConstraintsHandler implements IConstraintsHandler { @Override public <T> void constrainResponse(ResourceEntity<T> entity, SizeConstraints sizeConstraints, Constraint<T> c) { if (sizeConstraints != null) { applySizeConstraintsForRead(entity, sizeConstraints); } if (!treeConstraintsHandler.constrainResponse(entity, c)) { entityConstraintHandler.constrainResponse(entity); } } ConstraintsHandler(
            @Inject(DEFAULT_READ_CONSTRAINTS_LIST) List<EntityConstraint> readConstraints,
            @Inject(DEFAULT_WRITE_CONSTRAINTS_LIST) List<EntityConstraint> writeConstraints
    ); @Override void constrainUpdate(UpdateContext<T> context, Constraint<T> c); @Override void constrainResponse(ResourceEntity<T> entity, SizeConstraints sizeConstraints, Constraint<T> c); }
ConstraintsHandler implements IConstraintsHandler { @Override public <T> void constrainResponse(ResourceEntity<T> entity, SizeConstraints sizeConstraints, Constraint<T> c) { if (sizeConstraints != null) { applySizeConstraintsForRead(entity, sizeConstraints); } if (!treeConstraintsHandler.constrainResponse(entity, c)) { entityConstraintHandler.constrainResponse(entity); } } ConstraintsHandler(
            @Inject(DEFAULT_READ_CONSTRAINTS_LIST) List<EntityConstraint> readConstraints,
            @Inject(DEFAULT_WRITE_CONSTRAINTS_LIST) List<EntityConstraint> writeConstraints
    ); @Override void constrainUpdate(UpdateContext<T> context, Constraint<T> c); @Override void constrainResponse(ResourceEntity<T> entity, SizeConstraints sizeConstraints, Constraint<T> c); static final String DEFAULT_READ_CONSTRAINTS_LIST; static final String DEFAULT_WRITE_CONSTRAINTS_LIST; }