Return-Path: X-Original-To: apmail-incubator-isis-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-isis-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B77797FD9 for ; Tue, 18 Oct 2011 20:22:06 +0000 (UTC) Received: (qmail 74747 invoked by uid 500); 18 Oct 2011 20:22:06 -0000 Delivered-To: apmail-incubator-isis-commits-archive@incubator.apache.org Received: (qmail 74730 invoked by uid 500); 18 Oct 2011 20:22:06 -0000 Mailing-List: contact isis-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: isis-dev@incubator.apache.org Delivered-To: mailing list isis-commits@incubator.apache.org Received: (qmail 74723 invoked by uid 99); 18 Oct 2011 20:22:06 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Oct 2011 20:22:06 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Oct 2011 20:21:58 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 7790E2388847; Tue, 18 Oct 2011 20:21:35 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1185834 - in /incubator/isis/trunk/framework/viewer/json: json-applib/src/main/java/org/apache/isis/viewer/json/applib/ json-applib/src/main/java/org/apache/isis/viewer/json/applib/domainobjects/ json-applib/src/test/java/org/apache/isis/v... Date: Tue, 18 Oct 2011 20:21:34 -0000 To: isis-commits@incubator.apache.org From: danhaywood@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111018202135.7790E2388847@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: danhaywood Date: Tue Oct 18 20:21:33 2011 New Revision: 1185834 URL: http://svn.apache.org/viewvc?rev=1185834&view=rev Log: ISIS-109: enhanced JsonRepresentation to support criteria in path syntax Added: incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/PathNode.java - copied, changed from r1183125, incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/Node.java incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/PathNodeTest_equalsHashcode.java - copied, changed from r1183125, incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/representations/NodeTest_equalsHashcode.java incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/PathNodeTest_parse.java - copied, changed from r1183125, incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/representations/NodeTest_parse.java incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/GraphUtil.java - copied, changed from r1183125, incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/ListUtil.java incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/representations/GraphTest_asGraph.java - copied, changed from r1183125, incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/representations/ListUtilTest_asGraph.java Removed: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/ListUtil.java incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/Node.java incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/representations/ListUtilTest_asGraph.java incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/representations/NodeTest_equalsHashcode.java incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/representations/NodeTest_parse.java Modified: incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/JsonRepresentation.java incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/RepresentationWalker.java incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domainobjects/DomainObjectRepresentation.java incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getRepresentation.java incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_size.java incubator/isis/trunk/framework/viewer/json/json-applib/src/test/resources/org/apache/isis/viewer/json/applib/map.json incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/RepresentationMatchers.java incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/capabilities/CapabilitiesResourceTest_accept.java incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/home/HomePageResourceTest_xrofollowlinks.java incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/service/invoke/DomainServiceResourceTest_invokeAction.java incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/service/serviceId/DomainServiceResourceTest_serviceId_accept.java incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/service/serviceId/DomainServiceResourceTest_serviceId_xrofollowlinks.java incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/user/UserResourceTest_representationAndHeaders.java incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/stories/UserStoryTest.java incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/ResourceContext.java incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/LinkFollower.java Modified: incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/JsonRepresentation.java URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/JsonRepresentation.java?rev=1185834&r1=1185833&r2=1185834&view=diff ============================================================================== --- incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/JsonRepresentation.java (original) +++ incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/JsonRepresentation.java Tue Oct 18 20:21:33 2011 @@ -8,6 +8,7 @@ import java.io.StringReader; import java.lang.reflect.Constructor; import java.math.BigDecimal; import java.math.BigInteger; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Iterator; @@ -29,6 +30,7 @@ import org.codehaus.jackson.JsonParseExc import org.codehaus.jackson.map.JsonMappingException; import org.codehaus.jackson.node.ArrayNode; import org.codehaus.jackson.node.JsonNodeFactory; +import org.codehaus.jackson.node.NullNode; import org.codehaus.jackson.node.ObjectNode; import org.codehaus.jackson.node.POJONode; import org.jdom.Element; @@ -38,6 +40,9 @@ import org.jdom.output.XMLOutputter; import org.jdom.xpath.XPath; import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.collect.Collections2; +import com.google.common.collect.Iterables; import com.google.common.collect.Iterators; import com.google.common.collect.Lists; import com.google.common.collect.Maps; @@ -160,8 +165,11 @@ public class JsonRepresentation { // getRepresentation ///////////////////////////////////////////////////////////////////////// - public JsonRepresentation getRepresentation(String path) { - JsonNode node = getNode(path); + public JsonRepresentation getRepresentation(String pathTemplate, Object... args) { + final String pathStr = String.format(pathTemplate, args); + + JsonNode node = getNode(pathStr); + if (representsNull(node)) { return null; } @@ -185,7 +193,6 @@ public class JsonRepresentation { return !representsNull(node) && node.isArray(); } - public JsonRepresentation getArray(String path) { return getArray(path, getNode(path)); } @@ -686,7 +693,7 @@ public class JsonRepresentation { ///////////////////////////////////////////////////////////////////////// - // xpath support + // path support (with an xpath-like DSL) ///////////////////////////////////////////////////////////////////////// /** @@ -1096,14 +1103,58 @@ public class JsonRepresentation { ///////////////////////////////////////////////////////////////////////// private JsonNode getNode(String path) { - JsonNode node = jsonNode; + JsonNode jsonNode = this.jsonNode; String[] keys = path.split("\\."); for(String key: keys) { - node = node.path(key); + final PathNode pathNode = PathNode.parse(key); + if(!pathNode.getKey().isEmpty()) { + jsonNode = jsonNode.path(pathNode.getKey()); + } else { + // pathNode is criteria only; don't change jsonNode + } + if(jsonNode.isNull()) { + return jsonNode; + } + if(!pathNode.hasCriteria()) { + continue; + } + if (!jsonNode.isArray()) { + return NullNode.getInstance(); + } + jsonNode = matching(jsonNode, pathNode); + if(jsonNode.isNull()) { + return jsonNode; + } + } + return jsonNode; + } + + private JsonNode matching(JsonNode jsonNode, final PathNode pathNode) { + final JsonRepresentation asList = new JsonRepresentation(jsonNode); + final Iterable filtered = Iterables.filter(asList.arrayIterable(JsonNode.class), new Predicate() { + @Override + public boolean apply(JsonNode input) { + return pathNode.matches(new JsonRepresentation(input)); + } + }); + final List matching = Lists.newArrayList(filtered); + return toJsonNode(matching); + } + + private static JsonNode toJsonNode(List matching) { + switch(matching.size()) { + case 0: + return NullNode.getInstance(); + case 1: + return matching.get(0); + default: + final ArrayNode arrayNode = new ArrayNode(JsonNodeFactory.instance); + arrayNode.addAll(matching); + return arrayNode; } - return node; } + private static void checkValue(String path, JsonNode node, String requiredType) { if (node.isValueNode()) { return; @@ -1146,4 +1197,6 @@ public class JsonRepresentation { + + } Copied: incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/PathNode.java (from r1183125, incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/Node.java) URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/PathNode.java?p2=incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/PathNode.java&p1=incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/Node.java&r1=1183125&r2=1185834&rev=1185834&view=diff ============================================================================== --- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/Node.java (original) +++ incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/PathNode.java Tue Oct 18 20:21:33 2011 @@ -1,21 +1,22 @@ -package org.apache.isis.viewer.json.viewer.representations; +package org.apache.isis.viewer.json.applib; import java.util.Collections; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; +import com.google.common.base.Objects; import com.google.common.base.Splitter; import com.google.common.collect.Maps; -class Node { - private static final Pattern NODE = Pattern.compile("^([^\\[]+)(\\[(.+)\\])?$"); +public class PathNode { + private static final Pattern NODE = Pattern.compile("^([^\\[]*)(\\[(.+)\\])?$"); private static final Pattern WHITESPACE = Pattern.compile("\\s+"); private static final Pattern KEY_VALUE = Pattern.compile("^([^=]+)=(.+)$"); - public static final Node NULL = new Node("", Collections.emptyMap()); + public static final PathNode NULL = new PathNode("", Collections.emptyMap()); - public static Node parse(String path) { + public static PathNode parse(String path) { Matcher nodeMatcher = NODE.matcher(path); if(!nodeMatcher.matches()) { return null; @@ -36,12 +37,12 @@ class Node { } } - return new Node(key, criteria); + return new PathNode(key, criteria); } private final String key; private final Map criteria; - private Node(String key, Map criteria) { + private PathNode(String key, Map criteria) { this.key = key; this.criteria = Collections.unmodifiableMap(criteria); } @@ -51,6 +52,25 @@ class Node { public Map getCriteria() { return criteria; } + + public boolean hasCriteria() { + return !getCriteria().isEmpty(); + } + + public boolean matches(JsonRepresentation repr) { + if(!repr.isMap()) { + return false; + } + for(Map.Entry criterium: getCriteria().entrySet()) { + final String requiredValue = criterium.getValue(); + final String actualValue = repr.getString(criterium.getKey()); + if(!Objects.equal(requiredValue, actualValue)) { + return false; + } + } + return true; + } + @Override public int hashCode() { final int prime = 31; @@ -66,7 +86,7 @@ class Node { return false; if (getClass() != obj.getClass()) return false; - Node other = (Node) obj; + PathNode other = (PathNode) obj; if (key == null) { if (other.key != null) return false; Modified: incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/RepresentationWalker.java URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/RepresentationWalker.java?rev=1185834&r1=1185833&r2=1185834&view=diff ============================================================================== --- incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/RepresentationWalker.java (original) +++ incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/RepresentationWalker.java Tue Oct 18 20:21:33 2011 @@ -77,7 +77,11 @@ public class RepresentationWalker { return step; } - public void walk(String key) { + public void walk(String path) { + walk(path, null); + } + + public void walk(String path, JsonRepresentation invokeBody) { Step previousStep = currentStep(); if(previousStep.error!=null) { return; @@ -88,86 +92,86 @@ public class RepresentationWalker { try { entity = jsonResponse.getEntity(); } catch (Exception e) { - addStep(key, null, null, null, "exception: " + e.getMessage(), e); + addStep(path, null, null, null, "exception: " + e.getMessage(), e); return; } Link link; try { - link = entity.getLink(key); + link = entity.getLink(path); } catch (Exception e) { - addStep(key, null, null, null, "exception: " + e.getMessage(), e); + addStep(path, null, null, null, "exception: " + e.getMessage(), e); return; } if(link == null) { - addStep(key, null, null, null, "no such link '" + key + "'", null); + addStep(path, null, null, null, "no such link '" + path + "'", null); return; } Response response; try { - response = restfulClient.follow(link); - } catch (Exception e) { - addStep(key, link, null, null, "failed to follow link: " + e.getMessage(), e); - return; - } - - addStep(key, link, null, RestfulResponse.of(response), null, null); - } - - public void walkXpath(String linkXpath) { - walkXpath(linkXpath, null); - } - - public void walkXpath(String linkXpath, JsonRepresentation invokeBody) { - JsonRepresentation entity = getEntityElseMarkStepInError(); - if(entity == null) { - return; - } - - Link link = null; - try { - JsonRepresentation matching = entity.xpath(linkXpath); - if (matching == null) { - addStep(linkXpath, null, null, null, "no such link '" + linkXpath + "'", null); - return; - } - - link = matching.mapValueAsLink(); - if(link.getHref() == null) { - addStep(linkXpath, link, null, null, "key does not identify a link '" + linkXpath + "'", null); - return; - } - - Response response; if(invokeBody != null) { response = restfulClient.follow(link, invokeBody); } else { response = restfulClient.follow(link); } - addStep(linkXpath, link, null, RestfulResponse.of(response), null, null); - - } catch (RuntimeException e) { - // if xpath fails - addStep(linkXpath, null, null, null, "exception: " + e.getMessage(), e); - return; } catch (Exception e) { - // if follow fails - addStep(linkXpath, link, null, null, "failed to follow link: " + e.getMessage(), e); + addStep(path, link, null, null, "failed to follow link: " + e.getMessage(), e); return; } + + addStep(path, link, null, RestfulResponse.of(response), null, null); } - private JsonRepresentation getEntityElseMarkStepInError() { - try { - return getEntity(); - } catch (Exception e) { - Step previousStep = currentStep(); - previousStep.error = "exception: " + e.getMessage(); - previousStep.exception = e; - return null; - } - } +// public void walkXpath(String path, JsonRepresentation invokeBody) { +// JsonRepresentation entity = getEntityElseMarkStepInError(); +// if(entity == null) { +// return; +// } +// +// Link link = null; +// try { +// JsonRepresentation matching = entity.xpath(path); +// if (matching == null) { +// addStep(path, null, null, null, "no such link '" + path + "'", null); +// return; +// } +// +// link = matching.mapValueAsLink(); +// if(link.getHref() == null) { +// addStep(path, link, null, null, "key does not identify a link '" + path + "'", null); +// return; +// } +// +// Response response; +// if(invokeBody != null) { +// response = restfulClient.follow(link, invokeBody); +// } else { +// response = restfulClient.follow(link); +// } +// addStep(path, link, null, RestfulResponse.of(response), null, null); +// +// } catch (RuntimeException e) { +// // if xpath fails +// addStep(path, null, null, null, "exception: " + e.getMessage(), e); +// return; +// } catch (Exception e) { +// // if follow fails +// addStep(path, link, null, null, "failed to follow link: " + e.getMessage(), e); +// return; +// } +// } +// +// private JsonRepresentation getEntityElseMarkStepInError() { +// try { +// return getEntity(); +// } catch (Exception e) { +// Step previousStep = currentStep(); +// previousStep.error = "exception: " + e.getMessage(); +// previousStep.exception = e; +// return null; +// } +// } /** * The entity returned from the previous walk. Modified: incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domainobjects/DomainObjectRepresentation.java URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domainobjects/DomainObjectRepresentation.java?rev=1185834&r1=1185833&r2=1185834&view=diff ============================================================================== --- incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domainobjects/DomainObjectRepresentation.java (original) +++ incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domainobjects/DomainObjectRepresentation.java Tue Oct 18 20:21:33 2011 @@ -31,11 +31,11 @@ public class DomainObjectRepresentation } public JsonRepresentation getProperties() { - return xpath("/*[memberType='property']"); + return getRepresentation("members[memberType=property]"); } public JsonRepresentation getActions() { - return xpath("/*[memberType='action']"); + return getRepresentation("members[memberType=action]"); } public JsonRepresentation getLinks() { Modified: incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getRepresentation.java URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getRepresentation.java?rev=1185834&r1=1185833&r2=1185834&view=diff ============================================================================== --- incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getRepresentation.java (original) +++ incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getRepresentation.java Tue Oct 18 20:21:33 2011 @@ -63,5 +63,40 @@ public class JsonRepresentationTest_getR assertThat(listRepresentation.isArray(), is(true)); } - + @Test + public void forPath() throws JsonParseException, JsonMappingException, IOException { + JsonRepresentation representation = jsonRepresentation.getRepresentation("aSubMap.aLink"); + assertThat(representation.isMap(), is(true)); + assertThat(representation.getString("href"), is("http://foo/bar")); + } + + @Test + public void forListwithCriteria() throws JsonParseException, JsonMappingException, IOException { + JsonRepresentation representation = jsonRepresentation.getRepresentation("anotherSubMap.aListOfLinks[rel=aRel]"); + assertThat(representation.isLink(), is(true)); + assertThat(representation.asLink().getHref(), is("http://foo/bar")); + } + + @Test + public void forListWithCriteriaMatchingOne() throws JsonParseException, JsonMappingException, IOException { + JsonRepresentation representation = jsonRepresentation.getRepresentation("anotherSubMap.aListOfLinks[rel=multiRel data=someData]"); + assertThat(representation.isLink(), is(true)); + assertThat(representation.asLink().getHref(), is("http://foo/bar/multiRel1")); + } + + @Test + public void forListWithMultipleCriteriaMatchingMultiple() throws JsonParseException, JsonMappingException, IOException { + JsonRepresentation representation = jsonRepresentation.getRepresentation("anotherSubMap.aListOfLinks[rel=multiRel method=GET]"); + assertThat(representation.isArray(), is(true)); + assertThat(representation.size(), is(2)); + } + + @Test + public void whenStartingWithList() throws JsonParseException, JsonMappingException, IOException { + JsonRepresentation listRepresentation = jsonRepresentation.getRepresentation("anotherSubMap.aListOfLinks"); + JsonRepresentation representation = listRepresentation.getRepresentation("[rel=multiRel method=GET]"); + assertThat(representation.isArray(), is(true)); + assertThat(representation.size(), is(2)); + } + } Modified: incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_size.java URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_size.java?rev=1185834&r1=1185833&r2=1185834&view=diff ============================================================================== --- incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_size.java (original) +++ incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_size.java Tue Oct 18 20:21:33 2011 @@ -41,7 +41,7 @@ public class JsonRepresentationTest_size @Test public void size_forNonEmptyMap() throws JsonParseException, JsonMappingException, IOException { jsonRepresentation = new JsonRepresentation(readJson("map.json")); - assertThat(jsonRepresentation.size(), is(14)); + assertThat(jsonRepresentation.size(), is(15)); } @Test Copied: incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/PathNodeTest_equalsHashcode.java (from r1183125, incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/representations/NodeTest_equalsHashcode.java) URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/PathNodeTest_equalsHashcode.java?p2=incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/PathNodeTest_equalsHashcode.java&p1=incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/representations/NodeTest_equalsHashcode.java&r1=1183125&r2=1185834&rev=1185834&view=diff ============================================================================== --- incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/representations/NodeTest_equalsHashcode.java (original) +++ incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/PathNodeTest_equalsHashcode.java Tue Oct 18 20:21:33 2011 @@ -1,38 +1,38 @@ -package org.apache.isis.viewer.json.viewer.representations; +package org.apache.isis.viewer.json.applib; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import org.junit.Test; -public class NodeTest_equalsHashcode { +public class PathNodeTest_equalsHashcode { @Test public void simple() throws Exception { - final Node node = Node.parse("foo"); - final Node node2 = Node.parse("foo"); + final PathNode node = PathNode.parse("foo"); + final PathNode node2 = PathNode.parse("foo"); assertEquals(node, node2); } @Test public void oneCriterium() throws Exception { - final Node node = Node.parse("a[b=c]"); - final Node node2 = Node.parse("a"); + final PathNode node = PathNode.parse("a[b=c]"); + final PathNode node2 = PathNode.parse("a"); assertEquals(node, node2); } @Test public void moreThanOneCriterium() throws Exception { - final Node node = Node.parse("a[b=c d=e]"); - final Node node2 = Node.parse("a"); + final PathNode node = PathNode.parse("a[b=c d=e]"); + final PathNode node2 = PathNode.parse("a"); assertEquals(node, node2); } @Test public void notEqual() throws Exception { - final Node node = Node.parse("a[b=c d=e]"); - final Node node2 = Node.parse("b"); + final PathNode node = PathNode.parse("a[b=c d=e]"); + final PathNode node2 = PathNode.parse("b"); assertFalse(node.equals(node2)); } Copied: incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/PathNodeTest_parse.java (from r1183125, incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/representations/NodeTest_parse.java) URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/PathNodeTest_parse.java?p2=incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/PathNodeTest_parse.java&p1=incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/representations/NodeTest_parse.java&r1=1183125&r2=1185834&rev=1185834&view=diff ============================================================================== --- incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/representations/NodeTest_parse.java (original) +++ incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/PathNodeTest_parse.java Tue Oct 18 20:21:33 2011 @@ -1,4 +1,4 @@ -package org.apache.isis.viewer.json.viewer.representations; +package org.apache.isis.viewer.json.applib; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; @@ -7,19 +7,19 @@ import java.util.Map; import org.junit.Test; -public class NodeTest_parse { +public class PathNodeTest_parse { @Test public void simple() throws Exception { - final Node node = Node.parse("foo"); + final PathNode node = PathNode.parse("foo"); assertThat(node.getKey(), is("foo")); assertThat(node.getCriteria().isEmpty(), is(true)); } @Test public void oneCriterium() throws Exception { - final Node node = Node.parse("foo[bar=coz]"); + final PathNode node = PathNode.parse("foo[bar=coz]"); assertThat(node.getKey(), is("foo")); final Map criteria = node.getCriteria(); assertThat(criteria.isEmpty(), is(false)); @@ -29,7 +29,7 @@ public class NodeTest_parse { @Test public void moreThanOneCriterium() throws Exception { - final Node node = Node.parse("foo[bar=coz dat=ein]"); + final PathNode node = PathNode.parse("foo[bar=coz dat=ein]"); assertThat(node.getKey(), is("foo")); final Map criteria = node.getCriteria(); assertThat(criteria.isEmpty(), is(false)); @@ -40,7 +40,7 @@ public class NodeTest_parse { @Test public void whiteSpace() throws Exception { - final Node node = Node.parse("foo[bar=coz\tdat=ein]"); + final PathNode node = PathNode.parse("foo[bar=coz\tdat=ein]"); assertThat(node.getKey(), is("foo")); final Map criteria = node.getCriteria(); assertThat(criteria.isEmpty(), is(false)); Modified: incubator/isis/trunk/framework/viewer/json/json-applib/src/test/resources/org/apache/isis/viewer/json/applib/map.json URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/test/resources/org/apache/isis/viewer/json/applib/map.json?rev=1185834&r1=1185833&r2=1185834&view=diff ============================================================================== --- incubator/isis/trunk/framework/viewer/json/json-applib/src/test/resources/org/apache/isis/viewer/json/applib/map.json (original) +++ incubator/isis/trunk/framework/viewer/json/json-applib/src/test/resources/org/apache/isis/viewer/json/applib/map.json Tue Oct 18 20:21:33 2011 @@ -29,5 +29,34 @@ }, "aSubList": [ "a", "b", "c" - ] + ], + "anotherSubMap": { + "aListOfLinks": [ + { + "href": "http://foo/bar", + "method": "GET", + "rel": "aRel" + }, + { + "href": "http://foo/bar/otherRel", + "method": "GET", + "rel": "otherRel" + }, + { + "href": "http://foo/bar/multiRel1", + "method": "GET", + "rel": "multiRel", + "data": "someData" + }, + { + "href": "http://foo/bar/multiRel2", + "method": "GET", + "rel": "multiRel", + "data": "someOtherData" + } + ], + "aMap": "aValue", + "anEmptyList": [ + ] + } } Modified: incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/RepresentationMatchers.java URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/RepresentationMatchers.java?rev=1185834&r1=1185833&r2=1185834&view=diff ============================================================================== --- incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/RepresentationMatchers.java (original) +++ incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/RepresentationMatchers.java Tue Oct 18 20:21:33 2011 @@ -11,7 +11,6 @@ import org.apache.isis.viewer.json.appli import org.apache.isis.viewer.json.applib.RestfulResponse.HttpStatusCode; import org.apache.isis.viewer.json.applib.blocks.Link; import org.apache.isis.viewer.json.applib.blocks.Method; -import org.apache.isis.viewer.json.tck.RepresentationMatchers.AbstractMatcherBuilder; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; Modified: incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/capabilities/CapabilitiesResourceTest_accept.java URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/capabilities/CapabilitiesResourceTest_accept.java?rev=1185834&r1=1185833&r2=1185834&view=diff ============================================================================== --- incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/capabilities/CapabilitiesResourceTest_accept.java (original) +++ incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/capabilities/CapabilitiesResourceTest_accept.java Tue Oct 18 20:21:33 2011 @@ -13,7 +13,6 @@ import org.apache.isis.viewer.json.appli import org.apache.isis.viewer.json.applib.RestfulResponse; import org.apache.isis.viewer.json.applib.RestfulResponse.HttpStatusCode; import org.apache.isis.viewer.json.applib.capabilities.CapabilitiesRepresentation; -import org.apache.isis.viewer.json.applib.homepage.HomePageRepresentation; import org.apache.isis.viewer.json.tck.IsisWebServerRule; import org.junit.Before; import org.junit.Rule; Modified: incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/home/HomePageResourceTest_xrofollowlinks.java URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/home/HomePageResourceTest_xrofollowlinks.java?rev=1185834&r1=1185833&r2=1185834&view=diff ============================================================================== --- incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/home/HomePageResourceTest_xrofollowlinks.java (original) +++ incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/home/HomePageResourceTest_xrofollowlinks.java Tue Oct 18 20:21:33 2011 @@ -73,15 +73,15 @@ public class HomePageResourceTest_xrofol JsonRepresentation service; - service = serviceLinkList.xpath("/e[key='%s']", "simples"); - assertThat(service.getRepresentation("e"), isMap()); - assertThat(service.getString("e.key"), is("simples")); - assertThat(service.getRepresentation("e.value"), is(not(nullValue()))); - - service = serviceLinkList.xpath("/e[key='%s']", "applibValuedEntities"); - assertThat(service.getRepresentation("e"), isMap()); - assertThat(service.getString("e.key"), is("applibValuedEntities")); - assertThat(service.getRepresentation("e.value"), is(not(nullValue()))); + service = serviceLinkList.getRepresentation("[key=%s]", "simples"); + assertThat(service, isMap()); + assertThat(service.getString("key"), is("simples")); + assertThat(service.getRepresentation("value"), is(not(nullValue()))); + + service = serviceLinkList.getRepresentation("[key=%s]", "applibValuedEntities"); + assertThat(service, isMap()); + assertThat(service.getString("key"), is("applibValuedEntities")); + assertThat(service.getRepresentation("value"), is(not(nullValue()))); } @Test @@ -97,13 +97,13 @@ public class HomePageResourceTest_xrofol JsonRepresentation service; - service = serviceLinkList.xpath("/e[key='%s']", "simples"); - assertThat(service.getRepresentation("e"), isMap()); - assertThat(service.getString("e.key"), is("simples")); - assertThat(service.getRepresentation("e.value"), is(not(nullValue()))); + service = serviceLinkList.getRepresentation("[key=%s]", "simples"); + assertThat(service, isMap()); + assertThat(service.getString("key"), is("simples")); + assertThat(service.getRepresentation("value"), is(not(nullValue()))); - service = serviceLinkList.xpath("/e[key='%s']", "applibValuedEntities"); - assertThat(service.getRepresentation("e.value"), is(nullValue())); + service = serviceLinkList.getRepresentation("[key=%s]", "applibValuedEntities"); + assertThat(service.getRepresentation("value"), is(nullValue())); } private HomePageRepresentation whenExecuteWith(final String uriTemplate, final String followLinks) throws JsonParseException, JsonMappingException, IOException { Modified: incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/service/invoke/DomainServiceResourceTest_invokeAction.java URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/service/invoke/DomainServiceResourceTest_invokeAction.java?rev=1185834&r1=1185833&r2=1185834&view=diff ============================================================================== --- incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/service/invoke/DomainServiceResourceTest_invokeAction.java (original) +++ incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/service/invoke/DomainServiceResourceTest_invokeAction.java Tue Oct 18 20:21:33 2011 @@ -9,7 +9,6 @@ import java.io.IOException; import javax.ws.rs.core.Response; -import org.apache.isis.applib.annotation.Ignore; import org.apache.isis.runtimes.dflt.webserver.WebServer; import org.apache.isis.viewer.json.applib.HttpMethod; import org.apache.isis.viewer.json.applib.JsonRepresentation; @@ -37,6 +36,8 @@ public class DomainServiceResourceTest_i public IsisWebServerRule webServerRule = new IsisWebServerRule(); private RestfulClient client; + + @SuppressWarnings("unused") private DomainServiceResource resource; @Before @@ -94,8 +95,8 @@ public class DomainServiceResourceTest_i RestfulResponse restfulResponse = RestfulResponse.ofT(response); final DomainObjectRepresentation objectRepr = restfulResponse.getEntity(); - assertThat(objectRepr.xpath("//members/e[propertyId='%s']/value", "name").getString("value"), is("New Name")); - assertThat(objectRepr.xpath("//members/e[propertyId='%s']/value", "flag").getBoolean("value"), is(true)); + assertThat(objectRepr.getRepresentation("members[propertyId=%s].value", "name").asString(), is("New Name")); + assertThat(objectRepr.getRepresentation("members[propertyId=%s].value", "flag").asBoolean(), is(true)); } @org.junit.Ignore("up to here") @@ -124,8 +125,8 @@ public class DomainServiceResourceTest_i RestfulResponse restfulResponse = RestfulResponse.ofT(response); final DomainObjectRepresentation objectRepr = restfulResponse.getEntity(); - assertThat(objectRepr.xpath("//members/e[propertyId='%s']/value", "name").getString("value"), is("New Name")); - assertThat(objectRepr.xpath("//members/e[propertyId='%s']/value", "flag").getBoolean("value"), is(true)); + assertThat(objectRepr.getRepresentation("members[propertyId=%s].value", "name").asString(), is("New Name")); + assertThat(objectRepr.getRepresentation("members[propertyId=%s].value", "flag").asBoolean(), is(true)); } @@ -139,8 +140,8 @@ public class DomainServiceResourceTest_i assertThat(restfulResponse.getStatus(), is(HttpStatusCode.OK)); final DomainObjectRepresentation repr = restfulResponse.getEntity(); - JsonRepresentation actionLinkRepr = repr.xpath("/members/e[actionId='%s']", actionId); - return actionLinkRepr.getRepresentation("e.details.value"); + JsonRepresentation actionLinkRepr = repr.getRepresentation("members[actionId=%s]", actionId); + return actionLinkRepr.getRepresentation("details.value"); } @@ -149,7 +150,7 @@ public class DomainServiceResourceTest_i final Response response = resource.services(); final ListRepresentation services = RestfulResponse.ofT(response).getEntity(); - return services.xpath("//*[key='%s']", serviceId).getLink("e").getHref(); + return services.getRepresentation("values[key=%s]", serviceId).asLink().getHref(); } } Modified: incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/service/serviceId/DomainServiceResourceTest_serviceId_accept.java URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/service/serviceId/DomainServiceResourceTest_serviceId_accept.java?rev=1185834&r1=1185833&r2=1185834&view=diff ============================================================================== --- incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/service/serviceId/DomainServiceResourceTest_serviceId_accept.java (original) +++ incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/service/serviceId/DomainServiceResourceTest_serviceId_accept.java Tue Oct 18 20:21:33 2011 @@ -18,11 +18,9 @@ import org.apache.isis.viewer.json.appli import org.apache.isis.viewer.json.applib.domainobjects.DomainObjectRepresentation; import org.apache.isis.viewer.json.applib.domainobjects.DomainServiceResource; import org.apache.isis.viewer.json.applib.domainobjects.ListRepresentation; -import org.apache.isis.viewer.json.applib.homepage.HomePageRepresentation; import org.apache.isis.viewer.json.tck.IsisWebServerRule; import org.codehaus.jackson.JsonParseException; import org.codehaus.jackson.map.JsonMappingException; -import org.jboss.resteasy.spi.Link; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -81,7 +79,7 @@ public class DomainServiceResourceTest_s final Response response = resource.services(); final ListRepresentation services = RestfulResponse.ofT(response).getEntity(); - final String href = services.xpath("//*[key='%s']", "simples").getLink("e").getHref(); + final String href = services.getRepresentation("values.[key=%s]", "simples").asLink().getHref(); return href; } Modified: incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/service/serviceId/DomainServiceResourceTest_serviceId_xrofollowlinks.java URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/service/serviceId/DomainServiceResourceTest_serviceId_xrofollowlinks.java?rev=1185834&r1=1185833&r2=1185834&view=diff ============================================================================== --- incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/service/serviceId/DomainServiceResourceTest_serviceId_xrofollowlinks.java (original) +++ incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/service/serviceId/DomainServiceResourceTest_serviceId_xrofollowlinks.java Tue Oct 18 20:21:33 2011 @@ -56,13 +56,13 @@ public class DomainServiceResourceTest_s JsonRepresentation actionRepr; - actionRepr = membersList.xpath("/e[actionId='%s']", "list"); - assertThat(actionRepr.getRepresentation("e.details"), is(not(nullValue()))); - assertThat(actionRepr.getRepresentation("e.details.value"), is(not(nullValue()))); // followed + actionRepr = membersList.getRepresentation("[actionId=%s]", "list"); + assertThat(actionRepr.getRepresentation("details"), is(not(nullValue()))); + assertThat(actionRepr.getRepresentation("details.value"), is(not(nullValue()))); // followed - actionRepr = membersList.xpath("/e[actionId='%s']", "newTransientEntity"); - assertThat(actionRepr.getRepresentation("e.details"), is(not(nullValue()))); - assertThat(actionRepr.getRepresentation("e.details.value"), is(nullValue())); // not followed + actionRepr = membersList.getRepresentation("[actionId=%s]", "newTransientEntity"); + assertThat(actionRepr.getRepresentation("details"), is(not(nullValue()))); + assertThat(actionRepr.getRepresentation("details.value"), is(nullValue())); // not followed } @@ -71,7 +71,7 @@ public class DomainServiceResourceTest_s final Response response = resource.services(); final ListRepresentation services = RestfulResponse.ofT(response).getEntity(); - return services.xpath("//*[key='%s']", serviceId).getLink("e").getHref(); + return services.getRepresentation("values[key=%s]", serviceId).asLink().getHref(); } Modified: incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/user/UserResourceTest_representationAndHeaders.java URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/user/UserResourceTest_representationAndHeaders.java?rev=1185834&r1=1185833&r2=1185834&view=diff ============================================================================== --- incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/user/UserResourceTest_representationAndHeaders.java (original) +++ incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/user/UserResourceTest_representationAndHeaders.java Tue Oct 18 20:21:33 2011 @@ -34,7 +34,6 @@ import org.apache.isis.viewer.json.tck.I import org.codehaus.jackson.JsonParseException; import org.codehaus.jackson.map.JsonMappingException; import org.junit.Before; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; Modified: incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/stories/UserStoryTest.java URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/stories/UserStoryTest.java?rev=1185834&r1=1185833&r2=1185834&view=diff ============================================================================== --- incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/stories/UserStoryTest.java (original) +++ incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/stories/UserStoryTest.java Tue Oct 18 20:21:33 2011 @@ -46,15 +46,15 @@ public class UserStoryTest { walker.walk("services"); // and when locate the ApplibValues repo and walk the its 'object' link - walker.walkXpath("/*[title='ApplibValues']/link[rel='object']"); + walker.walk("values[title=ApplibValues].links[rel=object]"); // and when locate the AppLibValues repo's "newEntity" action and walk to its details - walker.walkXpath("/newEntity[memberType='action']/details"); + walker.walk("values[memberType=action].details"); // and when find the invoke body for the "newEntity" action and then walk the action using the body JsonRepresentation newEntityActionDetails = walker.getEntity(); JsonRepresentation newEntityActionInvokeBody = newEntityActionDetails.getArray("invoke.body"); - walker.walkXpath("/invoke", newEntityActionInvokeBody); + walker.walk("invoke", newEntityActionInvokeBody); // and when walk the link to the returned object walker.walk("link"); Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/ResourceContext.java URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/ResourceContext.java?rev=1185834&r1=1185833&r2=1185834&view=diff ============================================================================== --- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/ResourceContext.java (original) +++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/ResourceContext.java Tue Oct 18 20:21:33 2011 @@ -18,9 +18,7 @@ */ package org.apache.isis.viewer.json.viewer; -import java.util.ArrayList; import java.util.Collections; -import java.util.Iterator; import java.util.List; import javax.servlet.http.HttpServletRequest; Copied: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/GraphUtil.java (from r1183125, incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/ListUtil.java) URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/GraphUtil.java?p2=incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/GraphUtil.java&p1=incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/ListUtil.java&r1=1183125&r2=1185834&rev=1185834&view=diff ============================================================================== --- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/ListUtil.java (original) +++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/GraphUtil.java Tue Oct 18 20:21:33 2011 @@ -4,31 +4,33 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import org.apache.isis.viewer.json.applib.PathNode; + import com.google.common.collect.Maps; @SuppressWarnings({"rawtypes","unchecked"}) -public final class ListUtil { +public final class GraphUtil { - private ListUtil(){} + private GraphUtil(){} - public final static Map asGraph(List> links) { + public final static Map asGraph(List> links) { if(links == null) { return Collections.emptyMap(); } - final Map map = Maps.newHashMap(); + final Map map = Maps.newHashMap(); for (List link : links) { - ListUtil.mergeInto(link, map); + GraphUtil.mergeInto(link, map); } return map; } - private static void mergeInto(List list, Map map) { + private static void mergeInto(List list, Map map) { if(list.size() == 0) { return; } final String str = list.get(0); - final Node node = Node.parse(str); - Map submap = map.get(node); + final PathNode node = PathNode.parse(str); + Map submap = map.get(node); if(submap == null) { submap = Maps.newHashMap(); map.put(node, submap); Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/LinkFollower.java URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/LinkFollower.java?rev=1185834&r1=1185833&r2=1185834&view=diff ============================================================================== --- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/LinkFollower.java (original) +++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/LinkFollower.java Tue Oct 18 20:21:33 2011 @@ -6,17 +6,17 @@ import java.util.Map; import java.util.Set; import org.apache.isis.viewer.json.applib.JsonRepresentation; - -import com.google.common.base.Objects; +import org.apache.isis.viewer.json.applib.PathNode; @SuppressWarnings({"rawtypes","unchecked"}) public final class LinkFollower { + public final static LinkFollower create(List> links) { - final Map graph = ListUtil.asGraph(links); - return new LinkFollower(graph, Mode.FOLLOWING, Node.NULL); + final Map graph = GraphUtil.asGraph(links); + return new LinkFollower(graph, Mode.FOLLOWING, PathNode.NULL); } private enum Mode { @@ -24,11 +24,11 @@ public final class LinkFollower { TERMINATED; } - private final Map graph; + private final Map graph; private Mode mode; - private final Node root; + private final PathNode root; - private LinkFollower(Map graph, Mode mode, Node root) { + private LinkFollower(Map graph, Mode mode, PathNode root) { this.graph = graph; this.mode = mode; this.root = root; @@ -39,16 +39,16 @@ public final class LinkFollower { */ public LinkFollower follow(String path) { if(path == null) { - return terminated(Node.NULL); + return terminated(PathNode.NULL); } if(mode == Mode.TERMINATED) { return terminated(this.root); } - Node node = Node.parse(path); + PathNode node = PathNode.parse(path); if(mode == Mode.FOLLOWING) { - Map remaining = graph.get(node); + Map remaining = graph.get(node); if(remaining != null) { - Node key = findKey(node); + PathNode key = findKey(node); return new LinkFollower(remaining, Mode.FOLLOWING, key); } else { return terminated(node); @@ -59,11 +59,11 @@ public final class LinkFollower { /** * somewhat bizarre, but we have to find the actual node that is in the graph; - * the one we matching on doesn't match on the {@link Node#getCriteria()} map. + * the one we matching on doesn't match on the {@link PathNode#getCriteria()} map. */ - private Node findKey(Node node) { - final Set keySet = graph.keySet(); - for(Node key: keySet) { + private PathNode findKey(PathNode node) { + final Set keySet = graph.keySet(); + for(PathNode key: keySet) { if(key.equals(node)) { return key; } @@ -72,7 +72,7 @@ public final class LinkFollower { return node; } - private static LinkFollower terminated(Node node) { + private static LinkFollower terminated(PathNode node) { return new LinkFollower(null, Mode.TERMINATED, node); } @@ -98,14 +98,8 @@ public final class LinkFollower { if(!isFollowing()) { return false; } - for(Map.Entry criterium: root.getCriteria().entrySet()) { - final String requiredValue = criterium.getValue(); - final String actualValue = map.getString(criterium.getKey()); - if(!Objects.equal(requiredValue, actualValue)) { - return false; - } - } - return true; + return root == null || root.matches(map); } + } Copied: incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/representations/GraphTest_asGraph.java (from r1183125, incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/representations/ListUtilTest_asGraph.java) URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/representations/GraphTest_asGraph.java?p2=incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/representations/GraphTest_asGraph.java&p1=incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/representations/ListUtilTest_asGraph.java&r1=1183125&r2=1185834&rev=1185834&view=diff ============================================================================== --- incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/representations/ListUtilTest_asGraph.java (original) +++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/representations/GraphTest_asGraph.java Tue Oct 18 20:21:33 2011 @@ -7,46 +7,47 @@ import java.util.List; import java.util.Map; import org.apache.isis.viewer.json.applib.Parser; +import org.apache.isis.viewer.json.applib.PathNode; import org.junit.Test; @SuppressWarnings({"rawtypes", "unchecked"}) -public class ListUtilTest_asGraph { +public class GraphTest_asGraph { @Test public void simple() throws Exception { List> links = asListOfLists("a.b.c,a.b.d,d.b,e,e"); - final Map root = ListUtil.asGraph(links); + final Map root = GraphUtil.asGraph(links); assertThat(root.size(), is(3)); - Map nodeA = root.get(Node.parse("a")); + Map nodeA = root.get(PathNode.parse("a")); assertThat(nodeA.size(), is(1)); - Map nodeAB = nodeA.get(Node.parse("b")); + Map nodeAB = nodeA.get(PathNode.parse("b")); assertThat(nodeAB.size(), is(2)); - Map nodeABC = nodeAB.get(Node.parse("c")); + Map nodeABC = nodeAB.get(PathNode.parse("c")); assertThat(nodeABC.size(), is(0)); - Map nodeABD = nodeAB.get(Node.parse("d")); + Map nodeABD = nodeAB.get(PathNode.parse("d")); assertThat(nodeABD.size(), is(0)); - Map nodeD = root.get(Node.parse("d")); + Map nodeD = root.get(PathNode.parse("d")); assertThat(nodeD.size(), is(1)); - Map nodeDB = nodeD.get(Node.parse("b")); + Map nodeDB = nodeD.get(PathNode.parse("b")); assertThat(nodeDB.size(), is(0)); - Map nodeE = root.get(Node.parse("e")); + Map nodeE = root.get(PathNode.parse("e")); assertThat(nodeE.size(), is(0)); } @Test public void empty() throws Exception { List> links = asListOfLists(""); - final Map root = ListUtil.asGraph(links); + final Map root = GraphUtil.asGraph(links); assertThat(root.size(), is(0)); } @Test public void whenNull() throws Exception { - final Map root = ListUtil.asGraph(null); + final Map root = GraphUtil.asGraph(null); assertThat(root.size(), is(0)); }