incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From danhayw...@apache.org
Subject svn commit: r1200766 - 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 Fri, 11 Nov 2011 08:43:50 GMT
Author: danhaywood
Date: Fri Nov 11 08:43:50 2011
New Revision: 1200766

URL: http://svn.apache.org/viewvc?rev=1200766&view=rev
Log:
ISIS-109: suppress OIDs for transient objects; got RestfulRequest working for POST

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/RestfulRequest.java
    incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domainobjects/ActionResultRepresentation.java
    incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/RestfulRequestQueryParameterTest_valueOf.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/object/DomainObjectResourceTest.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_xrofollowlinks.java
    incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/service/services/DomainServiceResourceTest_services_xrofollowlinks.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/resources/domainobjects/DomainObjectReprRenderer.java
    incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/ResourceContextTest_getArg.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=1200766&r1=1200765&r2=1200766&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
Fri Nov 11 08:43:50 2011
@@ -696,7 +696,11 @@ public class JsonRepresentation {
     /////////////////////////////////////////////////////////////////////////
 
     /**
-     * Convenience to simply downcast.
+     * Convenience to simply "downcast".
+     * 
+     * <p>
+     * In fact, the method creates a new instance of the specified type, which shares the
+     * underlying {@link #jsonNode jsonNode}. 
      */
     public <T extends JsonRepresentation> T as(Class<T> cls) {
         try {
@@ -1041,6 +1045,22 @@ public class JsonRepresentation {
     /////////////////////////////////////////////////////////////////////////
     // helpers
     /////////////////////////////////////////////////////////////////////////
+
+    /**
+     * A reciprocal of the behaviour of the automatic dereferencing of arrays that
+     * occurs when there is only a single instance.
+     * 
+     * @see #toJsonNode(List)
+     */
+    public JsonRepresentation ensureArray() {
+        if(jsonNode.isArray()) {
+            return this;
+        }
+        final JsonRepresentation arrayRepr = JsonRepresentation.newArray();
+        arrayRepr.arrayAdd(jsonNode);
+        return arrayRepr;
+    }
+
 
     private JsonNode getNode(String path) {
         JsonNode jsonNode = this.jsonNode;
@@ -1106,14 +1126,6 @@ public class JsonRepresentation {
         return node == null || node.isMissingNode() || node.isNull();
     }
 
-    private static JsonRepresentation asJsonRepresentation(JSON json) throws JsonParseException,
JsonMappingException, IOException {
-        if(json == JSONNull.getInstance()) {
-            return null;
-        }
-        String jsonStr = json.toString();
-        return JsonMapper.instance().read(jsonStr, JsonRepresentation.class);
-    }
-
     private static String formatExMsg(String pathIfAny, String errorText) {
         StringBuilder buf = new StringBuilder();
         if(pathIfAny != null) {
@@ -1125,7 +1137,6 @@ public class JsonRepresentation {
 
 
 
-
     /////////////////////////////////////////////////////////////////////////
     // toString
     /////////////////////////////////////////////////////////////////////////
@@ -1136,21 +1147,5 @@ public class JsonRepresentation {
     }
 
 
-    /**
-     * A reciprocal of the behaviour of the automatic dereferencing of arrays that
-     * occurs when there is only a single instance.
-     */
-    public JsonRepresentation ensureArray() {
-        if(jsonNode.isArray()) {
-            return this;
-        }
-        final JsonRepresentation arrayRepr = JsonRepresentation.newArray();
-        arrayRepr.arrayAdd(jsonNode);
-        return arrayRepr;
-    }
-
-
-
-
 
 }

Modified: incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/RestfulRequest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/RestfulRequest.java?rev=1200766&r1=1200765&r2=1200766&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/RestfulRequest.java
(original)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/RestfulRequest.java
Fri Nov 11 08:43:50 2011
@@ -61,20 +61,20 @@ public final class RestfulRequest {
         }
     }
     
-    public static class QueryParameter<Q> {
+    public static class RequestParameter<Q> {
 
-        public static QueryParameter<List<List<String>>> FOLLOW_LINKS =
new QueryParameter<List<List<String>>>("x-ro-follow-links", Parser.forListOfListOfStrings(),
Collections.<List<String>>emptyList());
-        public static QueryParameter<Integer> PAGE = new QueryParameter<Integer>("x-ro-page",
Parser.forInteger(), 1);
-        public static QueryParameter<Integer> PAGE_SIZE = new QueryParameter<Integer>("x-ro-page-size",
Parser.forInteger(), 25);
-        public static QueryParameter<List<String>> SORT_BY = new QueryParameter<List<String>>("x-ro-sort-by",
Parser.forListOfStrings(), Collections.<String>emptyList());
-        public static QueryParameter<DomainModel> DOMAIN_MODEL = new QueryParameter<DomainModel>("x-ro-domain-model",
DomainModel.parser(), DomainModel.SIMPLE);
-        public static QueryParameter<Boolean> VALIDATE_ONLY = new QueryParameter<Boolean>("x-ro-validate-only",
Parser.forBoolean(), false);
+        public static RequestParameter<List<List<String>>> FOLLOW_LINKS
= new RequestParameter<List<List<String>>>("x-ro-follow-links", Parser.forListOfListOfStrings(),
Collections.<List<String>>emptyList());
+        public static RequestParameter<Integer> PAGE = new RequestParameter<Integer>("x-ro-page",
Parser.forInteger(), 1);
+        public static RequestParameter<Integer> PAGE_SIZE = new RequestParameter<Integer>("x-ro-page-size",
Parser.forInteger(), 25);
+        public static RequestParameter<List<String>> SORT_BY = new RequestParameter<List<String>>("x-ro-sort-by",
Parser.forListOfStrings(), Collections.<String>emptyList());
+        public static RequestParameter<DomainModel> DOMAIN_MODEL = new RequestParameter<DomainModel>("x-ro-domain-model",
DomainModel.parser(), DomainModel.SIMPLE);
+        public static RequestParameter<Boolean> VALIDATE_ONLY = new RequestParameter<Boolean>("x-ro-validate-only",
Parser.forBoolean(), false);
         
         private final String name;
         private final Parser<Q> parser;
         private final Q defaultValue;
         
-        private QueryParameter(String name, Parser<Q> parser, Q defaultValue) {
+        private RequestParameter(String name, Parser<Q> parser, Q defaultValue) {
             this.name = name;
             this.parser = parser;
             this.defaultValue = defaultValue;
@@ -88,10 +88,6 @@ public final class RestfulRequest {
             return parser;
         }
 
-        public void setValue(ClientRequest clientRequest, Q value) {
-            clientRequest.queryParameter(getName(), parser.asString(value));
-        }
-        
         public Q valueOf(Map<?, ?> parameterMap) {
             if(parameterMap == null) {
                 return defaultValue;
@@ -146,7 +142,7 @@ public final class RestfulRequest {
 
     private final ClientRequest clientRequest;
     private final HttpMethod httpMethod;
-    private final Map<QueryParameter<?>, Object> queryArgs = Maps.newLinkedHashMap();
+    private final Map<RequestParameter<?>, Object> args = Maps.newLinkedHashMap();
     
     public RestfulRequest(ClientRequest clientRequest, HttpMethod httpMethod) {
         this.clientRequest = clientRequest;
@@ -171,24 +167,28 @@ public final class RestfulRequest {
         return this;
     }
 
-    public <Q> RestfulRequest withArg(RestfulRequest.QueryParameter<Q> queryParam,
String argStrFormat, Object... args) {
+    public <Q> RestfulRequest withArg(RestfulRequest.RequestParameter<Q> queryParam,
String argStrFormat, Object... args) {
         String argStr = String.format(argStrFormat, args);
-        final Q arg = queryParam.getParser().valueOf(argStr );
+        final Q arg = queryParam.getParser().valueOf(argStr);
         return withArg(queryParam, arg);
     }
 
-    public <Q> RestfulRequest withArg(RestfulRequest.QueryParameter<Q> queryParam,
Q arg) {
-        queryArgs.put(queryParam, arg);
+    public <Q> RestfulRequest withArg(RestfulRequest.RequestParameter<Q> queryParam,
Q arg) {
+        args.put(queryParam, arg);
         return this;
     }
 
     public RestfulResponse<JsonRepresentation> execute() {
-        try {
-            if(httpMethod == HttpMethod.GET) {
-                setQueryArgs();
-            }
-            if(httpMethod == HttpMethod.POST) {
-                throw new RuntimeException("not yet implemented");
+        try {
+            switch (httpMethod) {
+            case GET:
+            case PUT:
+                setQueryArgs();
+                break;
+            case POST:
+            case DELETE:
+                setBody();
+                break;
             }
 
             Response executeJaxrs = clientRequest.execute();
@@ -198,13 +198,22 @@ public final class RestfulRequest {
         }
     }
 
+
     @SuppressWarnings({"unchecked", "rawtypes"})
     private void setQueryArgs() {
-        for (QueryParameter queryParam : queryArgs.keySet()) {
-            queryParam.setValue(clientRequest, queryArgs.get(queryParam));
+        for (RequestParameter requestParam : args.keySet()) {
+            clientRequest.queryParameter(requestParam.getName(), requestParam.parser.asString(args.get(requestParam)));
         }
     }
 
+    private void setBody() {
+        final JsonRepresentation bodyArgs = JsonRepresentation.newMap();
+        for (RequestParameter<?> requestParam : args.keySet()) {
+            bodyArgs.mapPut(requestParam.getName(), args.get(requestParam));
+        }
+        clientRequest.body(MediaType.APPLICATION_JSON, bodyArgs.toString());
+    }
+
 
     @SuppressWarnings("unchecked")
     public <T extends JsonRepresentation> RestfulResponse<T> executeT() {

Modified: incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domainobjects/ActionResultRepresentation.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/ActionResultRepresentation.java?rev=1200766&r1=1200765&r2=1200766&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domainobjects/ActionResultRepresentation.java
(original)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domainobjects/ActionResultRepresentation.java
Fri Nov 11 08:43:50 2011
@@ -57,7 +57,7 @@ public class ActionResultRepresentation 
     public JsonRepresentation getResult() {
         return getRepresentation("result");
     }
-    
+
     public ResultType getResultType() {
         final String resultType = getString("resulttype");
         return ResultType.lookup(resultType);

Modified: incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/RestfulRequestQueryParameterTest_valueOf.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/RestfulRequestQueryParameterTest_valueOf.java?rev=1200766&r1=1200765&r2=1200766&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/RestfulRequestQueryParameterTest_valueOf.java
(original)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/RestfulRequestQueryParameterTest_valueOf.java
Fri Nov 11 08:43:50 2011
@@ -27,7 +27,7 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.isis.viewer.json.applib.RestfulRequest.QueryParameter;
+import org.apache.isis.viewer.json.applib.RestfulRequest.RequestParameter;
 import org.jmock.Mockery;
 import org.jmock.integration.junit4.JUnit4Mockery;
 import org.jmock.lib.legacy.ClassImposteriser;
@@ -47,7 +47,7 @@ public class RestfulRequestQueryParamete
     
     @Test
     public void mapContainsList() {
-        final QueryParameter<List<List<String>>> queryParameter = RestfulRequest.QueryParameter.FOLLOW_LINKS;
+        final RequestParameter<List<List<String>>> queryParameter = RestfulRequest.RequestParameter.FOLLOW_LINKS;
         parameterMap.put("x-ro-follow-links", new String[]{"a", "b.c"});
         List<List<String>> valueOf = queryParameter.valueOf(parameterMap);
         
@@ -61,7 +61,7 @@ public class RestfulRequestQueryParamete
 
     @Test
     public void mapHasNoKey() {
-        final QueryParameter<List<List<String>>> queryParameter = RestfulRequest.QueryParameter.FOLLOW_LINKS;
+        final RequestParameter<List<List<String>>> queryParameter = RestfulRequest.RequestParameter.FOLLOW_LINKS;
         parameterMap.put("something-else", new String[]{"a", "b.c"});
         List<List<String>> valueOf = queryParameter.valueOf(parameterMap);
         
@@ -70,7 +70,7 @@ public class RestfulRequestQueryParamete
 
     @Test
     public void mapIsEmpty() {
-        final QueryParameter<List<List<String>>> queryParameter = RestfulRequest.QueryParameter.FOLLOW_LINKS;
+        final RequestParameter<List<List<String>>> queryParameter = RestfulRequest.RequestParameter.FOLLOW_LINKS;
         List<List<String>> valueOf = queryParameter.valueOf(parameterMap);
         
         assertThat(valueOf.size(), is(0));
@@ -78,7 +78,7 @@ public class RestfulRequestQueryParamete
 
     @Test
     public void mapIsNull() {
-        final QueryParameter<List<List<String>>> queryParameter = RestfulRequest.QueryParameter.FOLLOW_LINKS;
+        final RequestParameter<List<List<String>>> queryParameter = RestfulRequest.RequestParameter.FOLLOW_LINKS;
         List<List<String>> valueOf = queryParameter.valueOf(null);
         
         assertThat(valueOf.size(), is(0));
@@ -87,7 +87,7 @@ public class RestfulRequestQueryParamete
     @Test
     public void mapContainsCommaSeparatedList() {
         
-        final QueryParameter<List<List<String>>> queryParameter = RestfulRequest.QueryParameter.FOLLOW_LINKS;
+        final RequestParameter<List<List<String>>> queryParameter = RestfulRequest.RequestParameter.FOLLOW_LINKS;
         parameterMap.put("x-ro-follow-links", new String[]{"a,b.c"});
         List<List<String>> valueOf = queryParameter.valueOf(parameterMap);
         
@@ -102,7 +102,7 @@ public class RestfulRequestQueryParamete
     @Test
     public void commaSeparatedListUrlEncoded() throws UnsupportedEncodingException {
         
-        final QueryParameter<List<List<String>>> queryParameter = RestfulRequest.QueryParameter.FOLLOW_LINKS;
+        final RequestParameter<List<List<String>>> queryParameter = RestfulRequest.RequestParameter.FOLLOW_LINKS;
         parameterMap.put("x-ro-follow-links", new String[]{URLEncoder.encode("a,b.c", "UTF-8")});
         List<List<String>> valueOf = queryParameter.valueOf(parameterMap);
         

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=1200766&r1=1200765&r2=1200766&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
Fri Nov 11 08:43:50 2011
@@ -31,7 +31,7 @@ import org.apache.isis.viewer.json.appli
 import org.apache.isis.viewer.json.applib.JsonRepresentation;
 import org.apache.isis.viewer.json.applib.RestfulClient;
 import org.apache.isis.viewer.json.applib.RestfulRequest;
-import org.apache.isis.viewer.json.applib.RestfulRequest.QueryParameter;
+import org.apache.isis.viewer.json.applib.RestfulRequest.RequestParameter;
 import org.apache.isis.viewer.json.applib.RestfulResponse;
 import org.apache.isis.viewer.json.applib.homepage.HomePageRepresentation;
 import org.apache.isis.viewer.json.tck.IsisWebServerRule;
@@ -125,7 +125,7 @@ public class HomePageResourceTest_xrofol
     }
 
     private HomePageRepresentation whenExecuteAndFollowLinksUsing(final String uriTemplate,
final String followLinks) throws JsonParseException, JsonMappingException, IOException {
-        request = client.createRequest(HttpMethod.GET, uriTemplate).withArg(QueryParameter.FOLLOW_LINKS,
followLinks);
+        request = client.createRequest(HttpMethod.GET, uriTemplate).withArg(RequestParameter.FOLLOW_LINKS,
followLinks);
         restfulResponse = request.executeT();
         return restfulResponse.getEntity();
     }

Modified: incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/object/DomainObjectResourceTest.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/object/DomainObjectResourceTest.java?rev=1200766&r1=1200765&r2=1200766&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/object/DomainObjectResourceTest.java
(original)
+++ incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/object/DomainObjectResourceTest.java
Fri Nov 11 08:43:50 2011
@@ -36,18 +36,21 @@ import javax.ws.rs.core.Response.Status.
 import org.apache.isis.runtimes.dflt.webserver.WebServer;
 import org.apache.isis.tck.dom.assocs.ParentEntity;
 import org.apache.isis.tck.dom.scalars.ApplibValuedEntity;
-import org.apache.isis.tck.objstore.dflt.stables.StableEntityRepositoryDefault;
+import org.apache.isis.viewer.json.applib.HttpMethod;
 import org.apache.isis.viewer.json.applib.JsonRepresentation;
 import org.apache.isis.viewer.json.applib.Rel;
 import org.apache.isis.viewer.json.applib.RestfulClient;
+import org.apache.isis.viewer.json.applib.RestfulRequest;
 import org.apache.isis.viewer.json.applib.RestfulResponse;
 import org.apache.isis.viewer.json.applib.blocks.LinkRepresentation;
 import org.apache.isis.viewer.json.applib.blocks.Method;
+import org.apache.isis.viewer.json.applib.domainobjects.ActionResultRepresentation;
 import org.apache.isis.viewer.json.applib.domainobjects.DomainObjectRepresentation;
 import org.apache.isis.viewer.json.applib.domainobjects.DomainObjectResource;
 import org.apache.isis.viewer.json.applib.domainobjects.ObjectActionRepresentation;
 import org.apache.isis.viewer.json.applib.domainobjects.ObjectPropertyRepresentation;
 import org.apache.isis.viewer.json.applib.domainobjects.ScalarValueRepresentation;
+import org.apache.isis.viewer.json.applib.domainobjects.ActionResultRepresentation.ResultType;
 import org.apache.isis.viewer.json.tck.IsisWebServerRule;
 import org.codehaus.jackson.JsonParseException;
 import org.codehaus.jackson.map.JsonMappingException;
@@ -88,7 +91,7 @@ public class DomainObjectResourceTest {
     }
 
     @Test
-    public void domainObjectRepresentationContent_ObjectHeader() throws Exception {
+    public void domainObjectRepresentationForPersistentObject_hasSelfAndOid() throws Exception
{
         
         // given, when
         DomainObjectRepresentation domainObjectRepr = givenDomainObjectRepresentationFor("OID:32");
@@ -106,7 +109,57 @@ public class DomainObjectResourceTest {
         // no icon
         LinkRepresentation selfIcon = domainObjectRepr.getLinkWithRel(Rel.ICON);
         assertThat(selfIcon, is(nullValue()));
-
+    }
+
+    @Test
+    public void domainObjectRepresentationForTransient_hasNoSelf_andHasNoOid() throws Exception
{
+        
+        // given, when
+        final RestfulRequest request = this.client.createRequest(HttpMethod.POST, "services/simples/actions/newTransientEntity/invoke");
+        final RestfulResponse<ActionResultRepresentation> response = request.executeT();
+        final ActionResultRepresentation actionResultRepr = response.getEntity();
+        assertThat(actionResultRepr.getResultType(), is(ResultType.DOMAIN_OBJECT));
+        assertThat(actionResultRepr.getResult(), is(not(nullValue())));
+
+        DomainObjectRepresentation domainObjectRepr = actionResultRepr.getResult().as(DomainObjectRepresentation.class);
+
+        // then
+        LinkRepresentation self = domainObjectRepr.getSelf();
+        assertThat(self, is(nullValue()));
+        
+        assertThat(domainObjectRepr.getOid(), is(nullValue()));
+    }
+
+    @Test
+    public void domainObjectRepresentation_hasTitle() throws Exception {
+        
+        // given, when
+        DomainObjectRepresentation domainObjectRepr = givenDomainObjectRepresentationFor("OID:32");
+
+        // then
+        assertThat(domainObjectRepr.getTitle(), is("parent 5"));
+    }
+
+    @Test
+    public void domainObjectRepresentation_hasDescribedByLink() throws Exception {
+        
+        // given, when
+        DomainObjectRepresentation domainObjectRepr = givenDomainObjectRepresentationFor("OID:32");
+
+        // then
+        assertThat(domainObjectRepr.getLinkWithRel(Rel.DESCRIBEDBY), 
+                isLink().href(matches(".+" + ParentEntity.class.getName())).method(Method.GET).type(MediaType.APPLICATION_JSON_TYPE).typeParameter("profile",
"urn:org.restfulobjects/domaintype"));
+    }
+
+    @Test
+    public void domainObjectRepresentation_noIcon() throws Exception {
+        
+        // given, when
+        DomainObjectRepresentation domainObjectRepr = givenDomainObjectRepresentationFor("OID:32");
+
+        // then 
+        LinkRepresentation selfIcon = domainObjectRepr.getLinkWithRel(Rel.ICON);
+        assertThat(selfIcon, is(nullValue()));
     }
 
     @Ignore("TODO")

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=1200766&r1=1200765&r2=1200766&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
Fri Nov 11 08:43:50 2011
@@ -34,7 +34,7 @@ import org.apache.isis.viewer.json.appli
 import org.apache.isis.viewer.json.applib.JsonRepresentation;
 import org.apache.isis.viewer.json.applib.RestfulClient;
 import org.apache.isis.viewer.json.applib.RestfulRequest;
-import org.apache.isis.viewer.json.applib.RestfulRequest.QueryParameter;
+import org.apache.isis.viewer.json.applib.RestfulRequest.RequestParameter;
 import org.apache.isis.viewer.json.applib.RestfulResponse;
 import org.apache.isis.viewer.json.applib.RestfulResponse.HttpStatusCode;
 import org.apache.isis.viewer.json.applib.blocks.LinkRepresentation;
@@ -244,7 +244,7 @@ public class DomainServiceResourceTest_i
         final String href = givenHrefToService(serviceId);
         
         final RestfulRequest request = 
-                client.createRequest(HttpMethod.GET, href).withArg(QueryParameter.FOLLOW_LINKS,
"members[id=%s].links[rel=details]", actionId);
+                client.createRequest(HttpMethod.GET, href).withArg(RequestParameter.FOLLOW_LINKS,
"members[id=%s].links[rel=details]", actionId);
         final RestfulResponse<DomainObjectRepresentation> restfulResponse = request.executeT();
 
         assertThat(restfulResponse.getStatus(), is(HttpStatusCode.OK));

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=1200766&r1=1200765&r2=1200766&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
Fri Nov 11 08:43:50 2011
@@ -31,7 +31,7 @@ import org.apache.isis.viewer.json.appli
 import org.apache.isis.viewer.json.applib.JsonRepresentation;
 import org.apache.isis.viewer.json.applib.RestfulClient;
 import org.apache.isis.viewer.json.applib.RestfulRequest;
-import org.apache.isis.viewer.json.applib.RestfulRequest.QueryParameter;
+import org.apache.isis.viewer.json.applib.RestfulRequest.RequestParameter;
 import org.apache.isis.viewer.json.applib.RestfulResponse;
 import org.apache.isis.viewer.json.applib.RestfulResponse.HttpStatusCode;
 import org.apache.isis.viewer.json.applib.domainobjects.DomainObjectRepresentation;
@@ -63,7 +63,7 @@ public class DomainServiceResourceTest_s
         final String href = givenHrefToService("simples");
         
         final RestfulRequest request = 
-                client.createRequest(HttpMethod.GET, href).withArg(QueryParameter.FOLLOW_LINKS,
"members[id=%s].links[rel=details]", "list");
+                client.createRequest(HttpMethod.GET, href).withArg(RequestParameter.FOLLOW_LINKS,
"members[id=%s].links[rel=details]", "list");
         final RestfulResponse<DomainObjectRepresentation> restfulResponse = request.executeT();
 
         assertThat(restfulResponse.getStatus(), is(HttpStatusCode.OK));

Modified: incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/service/services/DomainServiceResourceTest_services_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/services/DomainServiceResourceTest_services_xrofollowlinks.java?rev=1200766&r1=1200765&r2=1200766&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/service/services/DomainServiceResourceTest_services_xrofollowlinks.java
(original)
+++ incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/resources/service/services/DomainServiceResourceTest_services_xrofollowlinks.java
Fri Nov 11 08:43:50 2011
@@ -32,7 +32,7 @@ import org.apache.isis.viewer.json.appli
 import org.apache.isis.viewer.json.applib.JsonRepresentation;
 import org.apache.isis.viewer.json.applib.RestfulClient;
 import org.apache.isis.viewer.json.applib.RestfulRequest;
-import org.apache.isis.viewer.json.applib.RestfulRequest.QueryParameter;
+import org.apache.isis.viewer.json.applib.RestfulRequest.RequestParameter;
 import org.apache.isis.viewer.json.applib.RestfulResponse;
 import org.apache.isis.viewer.json.applib.domainobjects.ListRepresentation;
 import org.apache.isis.viewer.json.tck.IsisWebServerRule;
@@ -69,7 +69,7 @@ public class DomainServiceResourceTest_s
         assertThat(repr.getValues().size(), is(greaterThan(0)));
         assertThat(repr.getValues().arrayGet(0), isLink().novalue());
 
-        request = client.createRequest(HttpMethod.GET, "services").withArg(QueryParameter.FOLLOW_LINKS,
"values");
+        request = client.createRequest(HttpMethod.GET, "services").withArg(RequestParameter.FOLLOW_LINKS,
"values");
         restfulResponse = request.executeT();
         repr = restfulResponse.getEntity();
 

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=1200766&r1=1200765&r2=1200766&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
Fri Nov 11 08:43:50 2011
@@ -35,7 +35,7 @@ import org.apache.isis.core.metamodel.ad
 import org.apache.isis.core.metamodel.adapter.oid.stringable.OidStringifier;
 import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession;
 import org.apache.isis.viewer.json.applib.RepresentationType;
-import org.apache.isis.viewer.json.applib.RestfulRequest.QueryParameter;
+import org.apache.isis.viewer.json.applib.RestfulRequest.RequestParameter;
 import org.apache.isis.viewer.json.applib.RestfulResponse.HttpStatusCode;
 
 import com.google.common.base.Predicate;
@@ -98,14 +98,14 @@ public class ResourceContext {
 
     void init(RepresentationType representationType) {
         ensureCompatibleAcceptHeader(representationType);
-        this.followLinks = Collections.unmodifiableList(getArg(QueryParameter.FOLLOW_LINKS));
+        this.followLinks = Collections.unmodifiableList(getArg(RequestParameter.FOLLOW_LINKS));
     }
 
     public HttpHeaders getHttpHeaders() {
         return httpHeaders;
     }
 
-    public <Q> Q getArg(QueryParameter<Q> queryParameter) {
+    public <Q> Q getArg(RequestParameter<Q> queryParameter) {
         return queryParameter.valueOf(getHttpServletRequest().getParameterMap());
     }
 

Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainObjectReprRenderer.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainObjectReprRenderer.java?rev=1200766&r1=1200765&r2=1200766&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainObjectReprRenderer.java
(original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainObjectReprRenderer.java
Fri Nov 11 08:43:50 2011
@@ -89,15 +89,20 @@ public class DomainObjectReprRenderer ex
     public JsonRepresentation render() {
 
         // self
-        if(includesSelf && objectAdapter.isPersistent()) {
-            JsonRepresentation self = linkToBuilder.with(objectAdapter).builder(Rel.SELF).build();
-            getLinks().arrayAdd(self);
+        if (objectAdapter.isPersistent()) {
+            if(includesSelf) {
+                JsonRepresentation self = linkToBuilder.with(objectAdapter).builder(Rel.SELF).build();
+                getLinks().arrayAdd(self);
+            }
+            representation.mapPut("oid", OidUtils.getOidStr(resourceContext, objectAdapter));
         }
 
+        
         // title
         String title = objectAdapter.titleString();
         representation.mapPut("title", title);
-        representation.mapPut("oid", OidUtils.getOidStr(resourceContext, objectAdapter));
+
+        // serviceId
         final boolean isService = objectAdapter.getSpecification().isService();
         if(isService) {
             representation.mapPut("serviceId", ServiceUtil.id(objectAdapter.getObject()));
@@ -106,9 +111,8 @@ public class DomainObjectReprRenderer ex
         // members
         withMembers(objectAdapter);
 
-        // links
-        final JsonRepresentation links = getLinks();
-        links.arrayAdd(
+        // described by
+        getLinks().arrayAdd(
                 DomainTypeReprRenderer.newLinkToBuilder(getResourceContext(), Rel.DESCRIBEDBY,
objectAdapter.getSpecification()).build());
         
         // extensions

Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/ResourceContextTest_getArg.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/ResourceContextTest_getArg.java?rev=1200766&r1=1200765&r2=1200766&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/ResourceContextTest_getArg.java
(original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/ResourceContextTest_getArg.java
Fri Nov 11 08:43:50 2011
@@ -23,7 +23,7 @@ import java.util.Map;
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.isis.viewer.json.applib.RepresentationType;
-import org.apache.isis.viewer.json.applib.RestfulRequest.QueryParameter;
+import org.apache.isis.viewer.json.applib.RestfulRequest.RequestParameter;
 import org.jmock.Expectations;
 import org.jmock.Mockery;
 import org.jmock.integration.junit4.JMock;
@@ -44,13 +44,13 @@ public class ResourceContextTest_getArg 
         }
     };
 
-    private QueryParameter<?> queryParameter;
+    private RequestParameter<?> queryParameter;
 
 
     @Before
     public void setUp() throws Exception {
         httpServletRequest = context.mock(HttpServletRequest.class);
-        queryParameter = context.mock(QueryParameter.class);
+        queryParameter = context.mock(RequestParameter.class);
         
     }
 



Mime
View raw message