rave-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfrank...@apache.org
Subject svn commit: r1171703 - in /incubator/rave/trunk/rave-portal/src: main/java/org/apache/rave/portal/web/api/rest/PageApi.java test/java/org/apache/rave/portal/web/api/rest/PageApiTest.java
Date Fri, 16 Sep 2011 18:21:58 GMT
Author: mfranklin
Date: Fri Sep 16 18:21:58 2011
New Revision: 1171703

URL: http://svn.apache.org/viewvc?rev=1171703&view=rev
Log:
Updated to support reduced "export" output (Supports RAVE-256)

Modified:
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rest/PageApi.java
    incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rest/PageApiTest.java

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rest/PageApi.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rest/PageApi.java?rev=1171703&r1=1171702&r2=1171703&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rest/PageApi.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rest/PageApi.java
Fri Sep 16 18:21:58 2011
@@ -19,6 +19,8 @@
 package org.apache.rave.portal.web.api.rest;
 
 import org.apache.rave.portal.model.Page;
+import org.apache.rave.portal.model.Region;
+import org.apache.rave.portal.model.RegionWidget;
 import org.apache.rave.portal.service.PageService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -58,10 +60,14 @@ public class PageApi {
 
     @ResponseBody
     @RequestMapping(value = "{pageId}", method = RequestMethod.GET)
-    public Page getPage(@PathVariable long pageId) {
-        return pageService.getPage(pageId);
+    public Page getPage(@PathVariable long pageId, @RequestParam(required=false) boolean
export) {
+        Page page = pageService.getPage(pageId);
+        if(export) {
+            modifyForExport(page);
+        }
+        return page;
     }
-    
+
     // TODO RAVE-240 - when we implement security we can implement different exception
     //        handlers for different errors (unauthorized, resource not found, etc)
     @ExceptionHandler(Exception.class)
@@ -71,4 +77,17 @@ public class PageApi {
         response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
         return ClassUtils.getShortName(ex.getClass());
     }
+
+    private static void modifyForExport(Page page) {
+        page.setOwner(null);
+        for(Region r : page.getRegions()){
+            modifyForExport(r);
+        }
+    }
+
+    private static void modifyForExport(Region r) {
+        for(RegionWidget w : r.getRegionWidgets()) {
+            w.setPreferences(null);
+        }
+    }
 }
\ No newline at end of file

Modified: incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rest/PageApiTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rest/PageApiTest.java?rev=1171703&r1=1171702&r2=1171703&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rest/PageApiTest.java
(original)
+++ incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rest/PageApiTest.java
Fri Sep 16 18:21:58 2011
@@ -18,7 +18,7 @@
  */
 package org.apache.rave.portal.web.api.rest;
 
-import org.apache.rave.portal.model.Page;
+import org.apache.rave.portal.model.*;
 import org.springframework.util.ClassUtils;
 import org.springframework.mock.web.MockHttpServletRequest;
 import org.springframework.http.HttpStatus;
@@ -26,6 +26,9 @@ import org.springframework.mock.web.Mock
 import org.apache.rave.portal.service.PageService;
 import org.junit.Before;
 import org.junit.Test;
+
+import java.util.ArrayList;
+
 import static org.junit.Assert.*;
 import static org.easymock.EasyMock.*;
 import static org.hamcrest.CoreMatchers.*;
@@ -56,8 +59,30 @@ public class PageApiTest {    
         expect(pageService.getPage(PAGE_ID)).andReturn(p).once();
         replay(pageService);
 
-        Page returned = pageApi.getPage(PAGE_ID);
+        Page returned = pageApi.getPage(PAGE_ID, false);
+        assertThat(returned, is(sameInstance(p)));
+    }
+
+    @Test
+    public void getPage_validId_export() {
+        Page p = new Page();
+        p.setRegions(new ArrayList<Region>());
+        p.setOwner(new User());
+        Region region = new Region();
+        region.setRegionWidgets(new ArrayList<RegionWidget>());
+        RegionWidget w = new RegionWidget();
+        w.setPreferences(new ArrayList<RegionWidgetPreference>());
+        w.getPreferences().add(new RegionWidgetPreference());
+        region.getRegionWidgets().add(w);
+        p.getRegions().add(region);
+
+        expect(pageService.getPage(PAGE_ID)).andReturn(p).once();
+        replay(pageService);
+
+        Page returned = pageApi.getPage(PAGE_ID, true);
         assertThat(returned, is(sameInstance(p)));
+        assertThat(returned.getOwner(), is(nullValue()));
+        assertThat(returned.getRegions().get(0).getRegionWidgets().get(0).getPreferences(),
is(nullValue()));
     }
     
     @Test



Mime
View raw message