isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From danhayw...@apache.org
Subject svn commit: r1179398 [2/2] - in /incubator/isis/trunk/framework/viewer/json: json-applib/src/main/java/org/apache/isis/viewer/json/applib/ json-applib/src/test/java/org/apache/isis/viewer/json/applib/ json-tck/src/test/java/org/apache/isis/viewer/json/...
Date Wed, 05 Oct 2011 19:47:18 GMT
Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/home/HomePageReprRenderer.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/home/HomePageReprRenderer.java?rev=1179398&r1=1179397&r2=1179398&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/home/HomePageReprRenderer.java
(original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/home/HomePageReprRenderer.java
Wed Oct  5 19:47:17 2011
@@ -5,14 +5,15 @@ import java.util.List;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
 import org.apache.isis.viewer.json.applib.JsonRepresentation;
 import org.apache.isis.viewer.json.applib.RepresentationType;
-import org.apache.isis.viewer.json.applib.RestfulRequest.QueryParameter;
 import org.apache.isis.viewer.json.viewer.ResourceContext;
+import org.apache.isis.viewer.json.viewer.representations.PathFollower;
 import org.apache.isis.viewer.json.viewer.representations.LinkBuilder;
 import org.apache.isis.viewer.json.viewer.representations.RendererFactory;
 import org.apache.isis.viewer.json.viewer.representations.RendererFactoryRegistry;
 import org.apache.isis.viewer.json.viewer.representations.ReprRenderer;
 import org.apache.isis.viewer.json.viewer.representations.ReprRendererAbstract;
 import org.apache.isis.viewer.json.viewer.representations.ReprRendererFactoryAbstract;
+import org.apache.isis.viewer.json.viewer.resources.capabilities.CapabilitiesReprRenderer;
 import org.apache.isis.viewer.json.viewer.resources.domainobjects.DomainServiceLinkToBuilder;
 import org.apache.isis.viewer.json.viewer.resources.domainobjects.ListReprRenderer;
 import org.apache.isis.viewer.json.viewer.resources.user.UserReprRenderer;
@@ -25,13 +26,13 @@ public class HomePageReprRenderer extend
         }
 
         @Override
-        public ReprRenderer<?, ?> newRenderer(ResourceContext resourceContext, JsonRepresentation
representation) {
-            return new HomePageReprRenderer(resourceContext, getRepresentationType(), representation);
+        public ReprRenderer<?, ?> newRenderer(ResourceContext resourceContext, PathFollower
pathFollower, JsonRepresentation representation) {
+            return new HomePageReprRenderer(resourceContext, pathFollower, getRepresentationType(),
representation);
         }
     }
 
-    private HomePageReprRenderer(ResourceContext resourceContext, RepresentationType representationType,
JsonRepresentation representation) {
-        super(resourceContext, representationType, representation);
+    private HomePageReprRenderer(ResourceContext resourceContext, PathFollower pathFollower,
RepresentationType representationType, JsonRepresentation representation) {
+        super(resourceContext, pathFollower, representationType, representation);
     }
 
     @Override
@@ -44,7 +45,7 @@ public class HomePageReprRenderer extend
         
         // self
         if(includesSelf) {
-            withSelf("");
+            putLinkToSelf(representation);
         }
 
         // user
@@ -59,48 +60,71 @@ public class HomePageReprRenderer extend
         // links and extensions
         representation.mapPut("links", JsonRepresentation.newArray());
         representation.mapPut("extensions", JsonRepresentation.newMap());
-        
+
         return representation;
     }
 
+    private void putLinkToSelf(JsonRepresentation representation) {
+        final LinkBuilder linkBuilder = LinkBuilder.newBuilder(resourceContext, "self", getRepresentationType(),
"");
+
+        final PathFollower pathFollower = getPathFollower().follow("self");
+        if(!pathFollower.isTerminated()) {
+
+            final RendererFactory factory = RendererFactoryRegistry.instance.find(RepresentationType.HOME_PAGE);
+            final HomePageReprRenderer renderer = (HomePageReprRenderer) factory.newRenderer(getResourceContext(),
pathFollower, JsonRepresentation.newMap());
+            
+            linkBuilder.withValue(renderer.render());
+        }
+        representation.mapPut("self", linkBuilder.build());
+    }
+
     private void putLinkToCapabilities(final JsonRepresentation representation) {
-        representation.mapPut("capabilities", 
-                LinkBuilder.newBuilder(getResourceContext(), "capabilities", RepresentationType.CAPABILITIES,
"capabilities").build());
+        final LinkBuilder linkBuilder = LinkBuilder.newBuilder(getResourceContext(), "capabilities",
RepresentationType.CAPABILITIES, "capabilities");
+        
+        final PathFollower pathFollower = getPathFollower().follow("capabilities");
+        if(!pathFollower.isTerminated()) {
+
+            final RendererFactory factory = RendererFactoryRegistry.instance.find(RepresentationType.CAPABILITIES);
+            final CapabilitiesReprRenderer renderer = (CapabilitiesReprRenderer) factory.newRenderer(getResourceContext(),
pathFollower, JsonRepresentation.newMap());
+            
+            linkBuilder.withValue(renderer.render());
+        }
+        
+        representation.mapPut("capabilities", linkBuilder.build());
     }
 
     private void putLinkToServices(JsonRepresentation representation) {
 
-        final LinkBuilder servicesLinkBuilder = 
+        final LinkBuilder linkBuilder = 
                 LinkBuilder.newBuilder(getResourceContext(), "services", RepresentationType.LIST,
"services");
         
-        final List<String> followLinks = getResourceContext().getArg(QueryParameter.FOLLOW_LINKS);
-        if(followLinks.contains("services")) {
+        final PathFollower pathFollower = getPathFollower().follow("services");
+        if(!pathFollower.isTerminated()) {
             
             final List<ObjectAdapter> serviceAdapters = getResourceContext().getPersistenceSession().getServices();
 
             final RendererFactory factory = RendererFactoryRegistry.instance.find(RepresentationType.LIST);
             
-            final ListReprRenderer renderer = (ListReprRenderer) factory.newRenderer(getResourceContext(),
JsonRepresentation.newMap());
+            final ListReprRenderer renderer = (ListReprRenderer) factory.newRenderer(getResourceContext(),
pathFollower, JsonRepresentation.newMap());
             renderer.usingLinkToBuilder(new DomainServiceLinkToBuilder())
                     .withSelf("services")
                     .with(serviceAdapters);
             
-            servicesLinkBuilder.withValue(renderer.render());
+            linkBuilder.withValue(renderer.render());
         }
         
-        representation.mapPut("services", servicesLinkBuilder.build());
+        representation.mapPut("services", linkBuilder.build());
     }
 
     private void putLinkToUser(JsonRepresentation representation) {
         final LinkBuilder userLinkBuilder = 
                 LinkBuilder.newBuilder(getResourceContext(), "user", RepresentationType.USER,
"user");
         
-        final List<String> followLinks = getResourceContext().getArg(QueryParameter.FOLLOW_LINKS);
-        if(followLinks.contains("user")) {
-            
+        final PathFollower pathFollower = getPathFollower().follow("user");
+        if(!pathFollower.isTerminated()) {
             final RendererFactory factory = RendererFactoryRegistry.instance.find(RepresentationType.USER);
             final UserReprRenderer renderer = 
-                    (UserReprRenderer) factory.newRenderer(getResourceContext(), JsonRepresentation.newMap());
+                    (UserReprRenderer) factory.newRenderer(getResourceContext(), pathFollower,
JsonRepresentation.newMap());
             renderer.with(getResourceContext().getAuthenticationSession());
             
             userLinkBuilder.withValue(renderer.render());

Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/home/HomePageResourceServerside.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/home/HomePageResourceServerside.java?rev=1179398&r1=1179397&r2=1179398&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/home/HomePageResourceServerside.java
(original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/home/HomePageResourceServerside.java
Wed Oct  5 19:47:17 2011
@@ -19,8 +19,6 @@
 package org.apache.isis.viewer.json.viewer.resources.home;
 
 
-import java.util.List;
-
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.Response;
@@ -28,8 +26,6 @@ import javax.ws.rs.core.Response;
 import org.apache.isis.viewer.json.applib.JsonRepresentation;
 import org.apache.isis.viewer.json.applib.RepresentationType;
 import org.apache.isis.viewer.json.applib.RestfulMediaType;
-import org.apache.isis.viewer.json.applib.RestfulRequest.Header;
-import org.apache.isis.viewer.json.applib.RestfulRequest.QueryParameter;
 import org.apache.isis.viewer.json.applib.homepage.HomePageResource;
 import org.apache.isis.viewer.json.viewer.representations.RendererFactory;
 import org.apache.isis.viewer.json.viewer.resources.ResourceAbstract;
@@ -46,15 +42,12 @@ public class HomePageResourceServerside 
         RepresentationType representationType = RepresentationType.HOME_PAGE;
         init(representationType);
         
-        //final List<List<String>> arg = getResourceContext().getArg(QueryParameter.FOLLOW_LINKS);
-        
         final RendererFactory factory = rendererFactoryRegistry.find(representationType);
         final HomePageReprRenderer renderer = 
-                (HomePageReprRenderer) factory.newRenderer(getResourceContext(), JsonRepresentation.newMap());
+                (HomePageReprRenderer) factory.newRenderer(getResourceContext(), null, JsonRepresentation.newMap());
         renderer.includesSelf();
 
         return responseOfOk(Caching.ONE_DAY, renderer).build();
     }
 
-
 }
\ No newline at end of file

Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/user/UserReprRenderer.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/user/UserReprRenderer.java?rev=1179398&r1=1179397&r2=1179398&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/user/UserReprRenderer.java
(original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/user/UserReprRenderer.java
Wed Oct  5 19:47:17 2011
@@ -20,6 +20,7 @@ import org.apache.isis.core.commons.auth
 import org.apache.isis.viewer.json.applib.JsonRepresentation;
 import org.apache.isis.viewer.json.applib.RepresentationType;
 import org.apache.isis.viewer.json.viewer.ResourceContext;
+import org.apache.isis.viewer.json.viewer.representations.PathFollower;
 import org.apache.isis.viewer.json.viewer.representations.ReprRenderer;
 import org.apache.isis.viewer.json.viewer.representations.ReprRendererAbstract;
 import org.apache.isis.viewer.json.viewer.representations.ReprRendererFactoryAbstract;
@@ -33,13 +34,13 @@ public class UserReprRenderer extends Re
         }
 
         @Override
-        public ReprRenderer<?, ?> newRenderer(ResourceContext resourceContext, JsonRepresentation
representation) {
-            return new UserReprRenderer(resourceContext, getRepresentationType(), representation);
+        public ReprRenderer<?, ?> newRenderer(ResourceContext resourceContext, PathFollower
pathFollower, JsonRepresentation representation) {
+            return new UserReprRenderer(resourceContext, pathFollower, getRepresentationType(),
representation);
         }
     }
     
-    private UserReprRenderer(ResourceContext resourceContext, RepresentationType representationType,
JsonRepresentation representation) {
-        super(resourceContext, representationType, representation);
+    private UserReprRenderer(ResourceContext resourceContext, PathFollower pathFollower,
RepresentationType representationType, JsonRepresentation representation) {
+        super(resourceContext, pathFollower, representationType, representation);
     }
 
     @Override

Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/user/UserResourceServerside.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/user/UserResourceServerside.java?rev=1179398&r1=1179397&r2=1179398&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/user/UserResourceServerside.java
(original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/user/UserResourceServerside.java
Wed Oct  5 19:47:17 2011
@@ -39,7 +39,7 @@ public class UserResourceServerside exte
 
         final RendererFactory factory = rendererFactoryRegistry.find(user);
         final UserReprRenderer renderer = 
-                (UserReprRenderer) factory.newRenderer(getResourceContext(), JsonRepresentation.newMap());
+                (UserReprRenderer) factory.newRenderer(getResourceContext(), null, JsonRepresentation.newMap());
         renderer.includesSelf()
                 .with(getAuthenticationSession());
 

Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/ResourceContextTest_ensureCompatibleAcceptHeader.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_ensureCompatibleAcceptHeader.java?rev=1179398&r1=1179397&r2=1179398&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/ResourceContextTest_ensureCompatibleAcceptHeader.java
(original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/ResourceContextTest_ensureCompatibleAcceptHeader.java
Wed Oct  5 19:47:17 2011
@@ -1,17 +1,14 @@
 package org.apache.isis.viewer.json.viewer;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
-import java.util.Map;
 
+import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
 
 import org.apache.isis.viewer.json.applib.RepresentationType;
-import org.apache.isis.viewer.json.viewer.util.MapUtils;
 import org.jmock.Expectations;
 import org.jmock.Mockery;
 import org.jmock.integration.junit4.JUnit4Mockery;
@@ -21,64 +18,84 @@ import org.junit.Test;
 public class ResourceContextTest_ensureCompatibleAcceptHeader {
 
     private HttpHeaders httpHeaders;
-    private ResourceContext resourceContext;
+    private HttpServletRequest httpServletRequest;
 
     private Mockery context = new JUnit4Mockery();
 
     @Before
     public void setUp() throws Exception {
         httpHeaders = context.mock(HttpHeaders.class);
-        resourceContext = new ResourceContext(httpHeaders, null, null, null, null, null,
null, null, null, null, null);
+        httpServletRequest = context.mock(HttpServletRequest.class);
+        context.checking(new Expectations() {
+            {
+                allowing(httpServletRequest).getParameterMap();
+                will(returnValue(Collections.emptyMap()));
+            }
+        });
     }
 
     @Test
     public void noop() throws Exception {
-        givenHttpHeadersGetAcceptableMediaTypesReturns(Arrays.<MediaType>asList(RepresentationType.HOME_PAGE.getMediaType()));
-        resourceContext.ensureCompatibleAcceptHeader(null);
+        final RepresentationType representationType = RepresentationType.HOME_PAGE;
+        givenHttpHeadersGetAcceptableMediaTypesReturns(Arrays.<MediaType>asList(representationType.getMediaType()));
+        
+        instantiateResourceContext(representationType);
     }
 
     @Test
     public void happyCase() throws Exception {
-        final RepresentationType homePage = RepresentationType.HOME_PAGE;
-        givenHttpHeadersGetAcceptableMediaTypesReturns(Arrays.<MediaType>asList(homePage.getMediaType()));
-        resourceContext.ensureCompatibleAcceptHeader(homePage);
+        final RepresentationType representationType = RepresentationType.HOME_PAGE;
+        givenHttpHeadersGetAcceptableMediaTypesReturns(Arrays.<MediaType>asList(representationType.getMediaType()));
+        
+        instantiateResourceContext(representationType);
     }
 
     @Test
     public void acceptGenericAndProduceGeneric() throws Exception {
+        RepresentationType representationType = RepresentationType.GENERIC;
         givenHttpHeadersGetAcceptableMediaTypesReturns(Arrays.<MediaType>asList(MediaType.APPLICATION_JSON_TYPE));
-        resourceContext.ensureCompatibleAcceptHeader(RepresentationType.GENERIC);
+        
+        instantiateResourceContext(representationType);
     }
 
     @Test
     public void acceptGenericAndProduceSpecific() throws Exception {
-        final RepresentationType homePage = RepresentationType.HOME_PAGE;
+        final RepresentationType representationType = RepresentationType.HOME_PAGE;
         givenHttpHeadersGetAcceptableMediaTypesReturns(Arrays.<MediaType>asList(MediaType.APPLICATION_JSON_TYPE));
-        resourceContext.ensureCompatibleAcceptHeader(homePage);
+        
+        instantiateResourceContext(representationType);
     }
 
     @Test(expected = JsonApplicationException.class)
     public void nonMatching() throws Exception {
+        RepresentationType representationType = RepresentationType.HOME_PAGE;
         givenHttpHeadersGetAcceptableMediaTypesReturns(Arrays.<MediaType>asList(MediaType.APPLICATION_ATOM_XML_TYPE));
-        resourceContext.ensureCompatibleAcceptHeader(RepresentationType.HOME_PAGE);
+        
+        instantiateResourceContext(representationType);
     }
 
     @Test(expected = JsonApplicationException.class)
     public void nonMatchingProfile() throws Exception {
+        RepresentationType representationType = RepresentationType.HOME_PAGE;
         givenHttpHeadersGetAcceptableMediaTypesReturns(Arrays.<MediaType>asList(RepresentationType.USER.getMediaType()));
-        resourceContext.ensureCompatibleAcceptHeader(RepresentationType.HOME_PAGE);
+        
+        instantiateResourceContext(representationType);
     }
 
     @Test(expected = JsonApplicationException.class)
     public void nonMatchingProfile_ignoreGeneric() throws Exception {
+        RepresentationType representationType = RepresentationType.HOME_PAGE;
         givenHttpHeadersGetAcceptableMediaTypesReturns(Arrays.<MediaType>asList(RepresentationType.USER.getMediaType(),
MediaType.APPLICATION_JSON_TYPE));
-        resourceContext.ensureCompatibleAcceptHeader(RepresentationType.HOME_PAGE);
+
+        instantiateResourceContext(representationType);
     }
 
     @Test(expected = JsonApplicationException.class)
     public void emptyList() throws Exception {
+        RepresentationType representationType = RepresentationType.HOME_PAGE;
         givenHttpHeadersGetAcceptableMediaTypesReturns(Arrays.<MediaType>asList());
-        resourceContext.ensureCompatibleAcceptHeader(RepresentationType.HOME_PAGE);
+
+        instantiateResourceContext(representationType);
     }
 
     private void givenHttpHeadersGetAcceptableMediaTypesReturns(final List<MediaType>
mediaTypes) {
@@ -89,4 +106,10 @@ public class ResourceContextTest_ensureC
             }
         });
     }
+
+    private ResourceContext instantiateResourceContext(final RepresentationType representationType)
{
+        return new ResourceContext(representationType, httpHeaders, null, null, httpServletRequest,
null, null, null, null, null, null, null);
+    }
+
+
 }

Added: 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=1179398&view=auto
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/ResourceContextTest_getArg.java
(added)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/ResourceContextTest_getArg.java
Wed Oct  5 19:47:17 2011
@@ -0,0 +1,58 @@
+package org.apache.isis.viewer.json.viewer;
+
+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.jmock.Expectations;
+import org.jmock.Mockery;
+import org.jmock.integration.junit4.JMock;
+import org.jmock.integration.junit4.JUnit4Mockery;
+import org.jmock.lib.legacy.ClassImposteriser;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(JMock.class)
+public class ResourceContextTest_getArg {
+
+    private HttpServletRequest httpServletRequest;
+    
+    private ResourceContext resourceContext;
+    private Mockery context = new JUnit4Mockery() {{
+            setImposteriser(ClassImposteriser.INSTANCE);
+        }
+    };
+
+    private QueryParameter<?> queryParameter;
+
+
+    @Before
+    public void setUp() throws Exception {
+        httpServletRequest = context.mock(HttpServletRequest.class);
+        queryParameter = context.mock(QueryParameter.class);
+        
+    }
+
+    @Test
+    public void delegatesToQueryParam() throws Exception {
+        final Map<?, ?> parameterMap = context.mock(Map.class);
+        context.checking(new Expectations() {
+            {
+                one(httpServletRequest).getParameterMap();
+                will(returnValue(parameterMap));
+                one(queryParameter).valueOf(parameterMap);
+            }
+        });
+        resourceContext = new ResourceContext(null, null, null, null, httpServletRequest,
null, null, null, null, null, null, null) {
+            @Override
+            void init(RepresentationType representationType) {
+                //
+            }
+        };
+        resourceContext.getArg(queryParameter);
+    }
+
+}



Mime
View raw message