rave-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jc...@apache.org
Subject svn commit: r1153220 - in /incubator/rave/trunk/rave-portal/src: main/java/org/apache/rave/portal/model/ main/java/org/apache/rave/portal/service/impl/ test/java/org/apache/rave/portal/service/
Date Tue, 02 Aug 2011 17:51:57 GMT
Author: jcian
Date: Tue Aug  2 17:51:56 2011
New Revision: 1153220

URL: http://svn.apache.org/viewvc?rev=1153220&view=rev
Log:
Checking in work in progress for RAVE-151 (generating encrypted security tokens server side).
 To facilitate generating security tokens for RegionWidgets I really need a mechanism for
getting the "owner" of a given RegionWidget -- and the simplest way to do that is to go ahead
and add the back-reference JPA relationships to parent entities so that we can just walk the
tree back up from the RegionWidget --> Region --> Page --> Owner.  This commit adds
the additional JPA relationship annotations to do that, and also adds the Jackson annotations
required to work around the circular references that occur without them during serialization
to json.  

https://issues.apache.org/jira/browse/RAVE-151

Modified:
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/Page.java
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/Region.java
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/RegionWidget.java
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/Widget.java
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultPageService.java
    incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/PageServiceTest.java

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/Page.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/Page.java?rev=1153220&r1=1153219&r2=1153220&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/Page.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/Page.java
Tue Aug  2 17:51:56 2011
@@ -19,6 +19,7 @@
 package org.apache.rave.portal.model;
 
 import org.apache.rave.persistence.BasicEntity;
+import org.codehaus.jackson.annotate.JsonManagedReference;
 
 import javax.persistence.*;
 import java.util.List;
@@ -57,6 +58,14 @@ public class Page implements BasicEntity
     @JoinColumn(name="page_id")
     private List<Region> regions;
 
+    public Page() {
+    }
+
+    public Page(Long id, User owner) {
+        this.id = id;
+        this.owner = owner;
+    }
+
     /**
      * Gets the persistence unique identifier
      *
@@ -128,6 +137,7 @@ public class Page implements BasicEntity
      *
      * @return Valid list of {@link Region}s
      */
+    @JsonManagedReference
     public List<Region> getRegions() {
         return regions;
     }

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/Region.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/Region.java?rev=1153220&r1=1153219&r2=1153220&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/Region.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/Region.java
Tue Aug  2 17:51:56 2011
@@ -19,6 +19,8 @@
 package org.apache.rave.portal.model;
 
 import org.apache.rave.persistence.BasicEntity;
+import org.codehaus.jackson.annotate.JsonBackReference;
+import org.codehaus.jackson.annotate.JsonManagedReference;
 
 import javax.persistence.*;
 import java.util.List;
@@ -35,11 +37,27 @@ public class Region implements BasicEnti
     @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "regionIdSeq")
     private Long id;
 
+    @ManyToOne
+    @JoinColumn(name = "page_id")
+    private Page page;
+
     @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
     @OrderBy("renderOrder")
     @JoinColumn(name = "region_id")
     private List<RegionWidget> regionWidgets;
 
+    public Region() {
+    }
+
+    public Region(Long id) {
+        this.id = id;
+    }
+
+    public Region(Long id, Page page) {
+        this.id = id;
+        this.page = page;
+    }
+
     /**
      * Gets the persistence unique identifier
      *
@@ -54,10 +72,25 @@ public class Region implements BasicEnti
     }
 
     /**
+     * Gets the associated page
+     *
+     * @return the associated page
+     */
+    @JsonBackReference
+    public Page getPage() {
+        return page;
+    }
+
+    public void setPage(Page page) {
+        this.page = page;
+    }
+
+    /**
      * Gets the ordered list of widget instances for the region
      *
      * @return Valid list
      */
+    @JsonManagedReference
     public List<RegionWidget> getRegionWidgets() {
         return regionWidgets;
     }

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/RegionWidget.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/RegionWidget.java?rev=1153220&r1=1153219&r2=1153220&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/RegionWidget.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/RegionWidget.java
Tue Aug  2 17:51:56 2011
@@ -19,6 +19,7 @@
 package org.apache.rave.portal.model;
 
 import org.apache.rave.persistence.BasicEntity;
+import org.codehaus.jackson.annotate.JsonBackReference;
 
 import javax.persistence.*;
 import java.util.List;
@@ -39,6 +40,10 @@ public class RegionWidget implements Bas
     @JoinColumn(name = "widget_id")
     private Widget widget;
 
+    @ManyToOne
+    @JoinColumn(name = "region_id")
+    private Region region;
+
     @Basic
     @Column(name = "render_position")
     private String renderPosition;
@@ -51,10 +56,6 @@ public class RegionWidget implements Bas
     @Column(name = "collapsed")
     private boolean collapsed;
 
-    @Basic
-    @Column(name="region_id")
-    private long regionId;
-
     @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
     @JoinColumn(name = "region_widget_id", referencedColumnName = "id")
     private List<RegionWidgetPreference> preferences;
@@ -71,6 +72,12 @@ public class RegionWidget implements Bas
         this.renderOrder = renderOrder;
     }
 
+    public RegionWidget(Long id, Widget widget, Region region) {
+        this.id = id;
+        this.widget = widget;
+        this.region = region;
+    }
+
     /**
      * Gets the persistence unique identifier
      *
@@ -98,6 +105,20 @@ public class RegionWidget implements Bas
     }
 
     /**
+     * Gets the associated region
+     *
+     * @return the region
+     */
+    @JsonBackReference
+    public Region getRegion() {
+        return region;
+    }
+
+    public void setRegion(Region region) {
+        this.region = region;
+    }
+
+    /**
      * Gets the render position of this widget.  When the widget instance is being displayed
on a "desktop" type view
      * (single region where the user can drag and drop widgets to a particular X and Y coordinate
within that region)
      * this value might be an X and Y coordinate of the upper left hand corner of the widget.
 It will be up to the
@@ -128,18 +149,6 @@ public class RegionWidget implements Bas
     }
 
     /**
-     * Gets the id of the associated region
-     * @return region's id
-     */
-    public long getRegionId() {
-        return regionId;
-    }
-
-    public void setRegionId(long regionId) {
-        this.regionId = regionId;
-    }
-
-    /**
      * Gets whether or not to render the gadget in collapsed mode
      *
      * @return true if render collapsed; false otherwise

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/Widget.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/Widget.java?rev=1153220&r1=1153219&r2=1153220&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/Widget.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/Widget.java
Tue Aug  2 17:51:56 2011
@@ -62,6 +62,14 @@ public class Widget implements BasicEnti
     @Basic @Column(name = "description")
     private String description;
 
+    public Widget() {
+    }
+
+    public Widget(Long id, String url) {
+        this.id = id;
+        this.url = url;
+    }
+
     /**
      * Gets the persistence unique identifier
      *
@@ -85,7 +93,6 @@ public class Widget implements BasicEnti
 //
 // }
 
-
     public String getScreenshotUrl() {
         return screenshotUrl;
     }

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultPageService.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultPageService.java?rev=1153220&r1=1153219&r2=1153220&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultPageService.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultPageService.java
Tue Aug  2 17:51:56 2011
@@ -73,7 +73,7 @@ public class DefaultPageService implemen
     public Region removeWidgetFromPage(long regionWidgetId) {
         RegionWidget widget = getFromRepository(regionWidgetId, regionWidgetRepository);
         regionWidgetRepository.delete(widget);
-        return getFromRepository(widget.getRegionId(), regionRepository);
+        return getFromRepository(widget.getRegion().getId(), regionRepository);
     }
 
     @Override

Modified: incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/PageServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/PageServiceTest.java?rev=1153220&r1=1153219&r2=1153220&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/PageServiceTest.java
(original)
+++ incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/PageServiceTest.java
Tue Aug  2 17:51:56 2011
@@ -237,7 +237,7 @@ public class PageServiceTest {
         long WIDGET_ID = 1L;
         long REGION_ID = 2L;
         RegionWidget widget = new RegionWidget(WIDGET_ID);
-        widget.setRegionId(REGION_ID);
+        widget.setRegion(new Region(REGION_ID));
         Region region = new Region();
 
         expect(regionWidgetRepository.get(WIDGET_ID)).andReturn(widget);



Mime
View raw message