private void addDetailsLinkIfPersistent() { if (!objectAdapter.representsPersistent()) { return; } final JsonRepresentation link = linkTo.memberBuilder(Rel.DETAILS, objectMemberType, objectMember).build(); getLinks().arrayAdd(link); final LinkFollowSpecs membersLinkFollower = getLinkFollowSpecs(); final LinkFollowSpecs detailsLinkFollower = membersLinkFollower.follow("links"); // create a temporary map that looks the same as the member map we'll be following final JsonRepresentation memberMap = JsonRepresentation.newMap(); memberMap.mapPut(getMemberId(), this.representation); if (membersLinkFollower.matches(memberMap) && detailsLinkFollower.matches(link)) { followDetailsLink(link); } return; }
@Test public void example_of_eager_loading_of_collection() throws Exception { final List<List<String>> links = asListOfLists("members[children].value"); final LinkFollowSpecs linkFollower = LinkFollowSpecs.create(links); LinkFollowSpecs followMembers = linkFollower.follow("members[children]"); assertThat(followMembers.isFollowing(), is(true)); assertThat(followMembers.isTerminated(), is(false)); assertThat(followMembers.follow("value").isFollowing(), is(true)); assertThat(followMembers.follow("value").isTerminated(), is(false)); }
final String path = String.format(pathTemplate, args); if (path == null) { return terminated(); return terminated(); return new LinkFollowSpecs(remainingPathSpecs, Mode.FOLLOWING, firstSpecs); return terminated(); return terminated();
@Test public void follow_withSingleMapCriteria() throws Exception { final List<List<String>> links = asListOfLists("a[x].b.c"); final LinkFollowSpecs linkFollower = LinkFollowSpecs.create(links); assertThat(linkFollower.follow("x").isFollowing(), is(false)); final LinkFollowSpecs followA = linkFollower.follow("a"); assertThat(followA.isFollowing(), is(true)); assertThat(followA.matches(JsonRepresentation.newMap("x", "y")), is(true)); assertThat(followA.matches(JsonRepresentation.newMap("x", "z")), is(true)); assertThat(followA.matches(JsonRepresentation.newMap()), is(false)); assertThat(followA.matches(JsonRepresentation.newMap("p", "z")), is(false)); }
@Override public JsonRepresentation render() { renderMemberContent(); final LinkFollowSpecs followValue = getLinkFollowSpecs().follow("value"); addValue(followValue); putDisabledReasonIfDisabled(); if (mode.isStandalone() || mode.isMutated()) { addChoices(); addExtensionsIsisProprietaryChangedObjects(); } return representation; }
private void addValue(final LinkFollowSpecs linkFollower) { final ObjectAdapter valueAdapter = objectMember.get(objectAdapter, getInteractionInitiatedBy()); if (valueAdapter == null) { return; } final LinkFollowSpecs followHref = linkFollower.follow("href"); boolean eagerlyRender = rendererContext.honorUiHints() && renderEagerly(valueAdapter) || !followHref.isTerminated(); final CollectionFacet facet = CollectionFacetUtils.getCollectionFacetFromSpec(valueAdapter); final List<JsonRepresentation> list = Lists.newArrayList(); for (final ObjectAdapter elementAdapter : facet.iterable(valueAdapter)) { final LinkBuilder valueLinkBuilder = DomainObjectReprRenderer.newLinkToBuilder(rendererContext, Rel.VALUE, elementAdapter); if(eagerlyRender) { final DomainObjectReprRenderer renderer = new DomainObjectReprRenderer(getRendererContext(), followHref, JsonRepresentation.newMap() ); renderer.with(elementAdapter); if(mode.isEventSerialization()) { renderer.asEventSerialization(); } valueLinkBuilder.withValue(renderer.render()); } list.add(valueLinkBuilder.build()); } representation.mapPut("value", list); }
private LinkFollowSpecs asProvidedElseCreate(final LinkFollowSpecs linkFollower) { if (linkFollower != null) { return linkFollower; } return LinkFollowSpecs.create(rendererContext.getFollowLinks()); }
/** * Ensure that every key present in the provided map matches the criterium. * * <p> * Any keys in the criterium are ignored (these were matched on during the * {@link #follow(String, Object...)} call). */ public boolean matches(final JsonRepresentation jsonRepr) { if (!isFollowing()) { return false; } if(criteriaSpecs == null) { return true; } for (PathNode criteriaSpec : criteriaSpecs) { if(criteriaSpec.matches(jsonRepr)) { return true; } } return false; }
boolean eagerlyRender = (renderFacet != null && renderFacet.value() == Type.EAGERLY && rendererContext.canEagerlyRender(valueAdapter)) || (linkFollower != null && !linkFollower.isTerminated());
private static LinkFollowSpecs terminated() { return new LinkFollowSpecs(Collections.<List<PathNode>>emptyList(), Mode.TERMINATED, Collections.<PathNode>emptyList()); }
@Test public void follow_withSingleListCriteria() throws Exception { final List<List<String>> links = asListOfLists("a[x=y].b.c"); final LinkFollowSpecs linkFollower = LinkFollowSpecs.create(links); assertThat(linkFollower.follow("x").isFollowing(), is(false)); final LinkFollowSpecs followA = linkFollower.follow("a"); assertThat(followA.isFollowing(), is(true)); assertThat(followA.matches(JsonRepresentation.newMap("x", "y")), is(true)); assertThat(followA.matches(JsonRepresentation.newMap()), is(false)); assertThat(followA.matches(JsonRepresentation.newMap("x", "z")), is(false)); }
private void addActions(final ObjectAdapter objectAdapter, final List<ObjectAction> actions, final JsonRepresentation members) { for (final ObjectAction action : actions) { final Consent visibility = action.isVisible(objectAdapter, getInteractionInitiatedBy(), rendererContext.getWhere()); if (!visibility.isAllowed()) { continue; } final LinkFollowSpecs linkFollowSpecs = getLinkFollowSpecs().follow("members["+action.getId()+"]"); final ObjectActionReprRenderer renderer = new ObjectActionReprRenderer(getRendererContext(), linkFollowSpecs, action.getId(), JsonRepresentation.newMap()); renderer.with(new ObjectAndAction(objectAdapter, action)).usingLinkTo(linkToBuilder); members.mapPut(action.getId(), renderer.render()); } }
@Override public JsonRepresentation render() { if(representation == null) { return null; } renderMemberContent(); final LinkFollowSpecs followValue = getLinkFollowSpecs().follow("value"); boolean eagerlyRender = rendererContext.honorUiHints() && renderEagerly() || !followValue.isTerminated(); if ((mode.isInline() && eagerlyRender) || mode.isStandalone() || mode.isMutated() || mode.isEventSerialization() || !objectAdapter.representsPersistent()) { addValue(followValue); } if(!mode.isEventSerialization()) { putDisabledReasonIfDisabled(); } if (mode.isStandalone() || mode.isMutated()) { addExtensionsIsisProprietaryChangedObjects(); } return representation; }
private LinkFollowSpecs asProvidedElseCreate(final LinkFollowSpecs linkFollower) { if (linkFollower != null) { return linkFollower; } return LinkFollowSpecs.create(rendererContext.getFollowLinks()); }
/** * Ensure that every key present in the provided map matches the criterium. * * <p> * Any keys in the criterium are ignored (these were matched on during the * {@link #follow(String, Object...)} call). */ public boolean matches(final JsonRepresentation jsonRepr) { if (!isFollowing()) { return false; } if(criteriaSpecs == null) { return true; } for (PathNode criteriaSpec : criteriaSpecs) { if(criteriaSpec.matches(jsonRepr)) { return true; } } return false; }
private static LinkFollowSpecs terminated() { return new LinkFollowSpecs(Collections.<List<PathNode>>emptyList(), Mode.TERMINATED, Collections.<PathNode>emptyList()); }
private void addDetailsLinkIfPersistent() { if (!objectAdapter.representsPersistent()) { return; } final JsonRepresentation link = linkTo.memberBuilder(Rel.DETAILS, objectMemberType, objectMember).build(); getLinks().arrayAdd(link); final LinkFollowSpecs membersLinkFollower = getLinkFollowSpecs(); final LinkFollowSpecs detailsLinkFollower = membersLinkFollower.follow("links"); // create a temporary map that looks the same as the member map we'll be following final JsonRepresentation memberMap = JsonRepresentation.newMap(); memberMap.mapPut(getMemberId(), representation); if (membersLinkFollower.matches(memberMap) && detailsLinkFollower.matches(link)) { followDetailsLink(link); } return; }
@Test public void notMatching() throws Exception { final List<List<String>> links = asListOfLists("a.b.c"); final LinkFollowSpecs linkFollower = LinkFollowSpecs.create(links); assertThat(linkFollower.follow("x").isFollowing(), is(false)); assertThat(linkFollower.follow("x").isTerminated(), is(true)); }